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 associated types are incorrectly substituted #107468

Closed
fmease opened this issue Jan 30, 2023 · 2 comments · Fixed by #105961
Closed

Inherent associated types are incorrectly substituted #107468

fmease opened this issue Jan 30, 2023 · 2 comments · Fixed by #105961
Assignees
Labels
C-bug Category: This is a bug. F-inherent_associated_types `#![feature(inherent_associated_types)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Jan 30, 2023

The following code should compile since for Subj<(i32,)> one has T == i32 and thus Subj::Un == i32. However, the current implementation incorrectly substitutes T with (i32,) leading to a compile error after encountering the let-statement.

#![feature(inherent_associated_types)]
#![allow(incomplete_features)]

struct Subj<T>(T);

impl<T> Subj<(T,)> {
    type Un = T;
}

fn main() {
    let _: Subj::<(i32,)>::Un = 0i32;
}
error[E0308]: mismatched types
  --> src/main.rs:11:33
   |
11 |     let _: Subj::<(i32,)>::Un = 0i32;
   |            ------------------   ^^^^ expected tuple, found `i32`
   |            |
   |            expected due to this
   |
   = note: expected tuple `(i32,)`
               found type `i32`
help: use a trailing comma to create a tuple with one element
   |
11 |     let _: Subj::<(i32,)>::Un = (0i32,);
   |                                 +    ++

For comparison, the analogous program involving inherent associated functions successfully compiles:

struct Subj<T>(T);

impl<T: Default> Subj<(T,)> {
    fn un() -> T { T::default() }
}

fn main() {
    let _: i32 = Subj::<(i32,)>::un();
}

@rustbot label T-compiler requires-nightly F-inherent_associated_types
@rustbot claim

@fmease fmease added the C-bug Category: This is a bug. label Jan 30, 2023
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-inherent_associated_types `#![feature(inherent_associated_types)]` requires-nightly This issue requires a nightly compiler in some way. labels Jan 30, 2023
@compiler-errors
Copy link
Member

same root cause, please add this as a test when you fix this @fmease:

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b267739cce2e6be9f50bb4bf0c3dbd85

@fmease
Copy link
Member Author

fmease commented Jan 30, 2023

#105305 related

@bors bors closed this as completed in 7b55296 Feb 20, 2023
@fmease fmease changed the title Inherent associated type projections are incorrectly substituted Inherent associated types are incorrectly substituted Jun 24, 2023
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)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants