Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inherent assoc tys resolve with subtyping not equality #109789

Closed
BoxyUwU opened this issue Mar 30, 2023 · 2 comments · Fixed by #109410
Closed

inherent assoc tys resolve with subtyping not equality #109789

BoxyUwU opened this issue Mar 30, 2023 · 2 comments · Fixed by #109410
Assignees
Labels
C-bug Category: This is a bug. F-inherent_associated_types `#![feature(inherent_associated_types)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 30, 2023

I tried this code:

#![feature(inherent_associated_types)]

struct Foo<T>(T);

impl Foo<fn(&'static ())> {
    type Assoc = u32;
}

trait Other {}
impl Other for u32 {}

fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}

I expected to see this happen: It not to compile as Foo<for<'a> fn(&'a ())> has no inherent impl defined on it

Instead, this happened: it compiled

Meta

playground's nightly:

Build using the Nightly version: 1.70.0-nightly
(2023-03-29 17c11672167827b0dd92)
@BoxyUwU BoxyUwU added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. F-inherent_associated_types `#![feature(inherent_associated_types)]` T-types Relevant to the types team, which will review and decide on the PR/issue. labels Mar 30, 2023
@fmease
Copy link
Member

fmease commented Mar 30, 2023

Fixed in #109410, although the error message is not as nice since we don't try to prettify it (yet). That can be done at some point later though, IMO. The trait analog results in:

error: implementation of `Mid` is not general enough
  --> src/main.rs:17:11
   |
17 | fn bar(_: <Foo<for<'a> fn(&'a ())> as Mid>::Assoc) {}
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Mid` is not general enough
   |
   = note: `Foo<for<'a> fn(&'a ())>` must implement `Mid`
   = note: ...but `Mid` is actually implemented for the type `Foo<fn(&'static ())>`

while the IAT one leads to the following error(s) in #109410:

error[E0308]: mismatched types
  --> tests/ui/associated-inherent-types/issue-109789.rs:17:1
   |
17 | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected struct `Foo<fn(&'static ())>`
              found struct `Foo<for<'a> fn(&'a ())>`

error[E0308]: mismatched types
  --> tests/ui/associated-inherent-types/issue-109789.rs:17:11
   |
17 | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected struct `Foo<fn(&'static ())>`
              found struct `Foo<for<'a> fn(&'a ())>`

I should definitely fix the duplication of the diagnostic (albeit harmless).
As mentioned before, we spruce up the region error for traits. This is done in try_report_trait_placeholder_mismatch. If I disable this logic (by modifying it to always return None), the trait analog yields almost the same error message as #109410:

error[E0308]: mismatched types
  --> analog.rs:17:11
   |
17 | fn bar(_: <Foo<for<'a> fn(&'a ())> as Mid>::Assoc) {}
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
   |
   = note: expected trait `<Foo<for<'a> fn(&'a ())> as Mid>`
              found trait `<Foo<fn(&'static ())> as Mid>`

Edit: Well, on a closer look, expected/found is swapped, hmm.

@rustbot claim

@fmease
Copy link
Member

fmease commented Mar 31, 2023

Regression test added.

@bors bors closed this as completed in 29ac429 May 8, 2023
flip1995 pushed a commit to flip1995/rust that referenced this issue May 20, 2023
…compiler-errors

Introduce `AliasKind::Inherent` for inherent associated types

Allows us to check (possibly generic) inherent associated types for well-formedness.
Type inference now also works properly.

Follow-up to rust-lang#105961. Supersedes rust-lang#108430.
Fixes rust-lang#106722.
Fixes rust-lang#108957.
Fixes rust-lang#109768.
Fixes rust-lang#109789.
Fixes rust-lang#109790.

~Not to be merged before rust-lang#108860 (`AliasKind::Weak`).~

CC `@jackh726`
r? `@compiler-errors`

`@rustbot` label T-types F-inherent_associated_types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-inherent_associated_types `#![feature(inherent_associated_types)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants