-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
instantiate_value_path: on SelfCtor
, avoid unconstrained tyvars
#69340
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
fn main() {} | ||
|
||
struct S0<T>(T); | ||
impl<T> S0<T> { | ||
const C: S0<u8> = Self(0); | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
|
||
fn foo() { | ||
Self(0); | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
|
||
// Testing normalization. | ||
trait Fun { | ||
type Out; | ||
} | ||
impl<T> Fun for S0<T> { | ||
type Out = Self; | ||
} | ||
trait Foo<T> { | ||
fn foo(); | ||
} | ||
impl<T> Foo<T> for <S0<T> as Fun>::Out { | ||
fn foo() { | ||
Self(0); //~ ERROR mismatched types | ||
} | ||
} | ||
|
||
struct S1<T, U>(T, U); | ||
impl<T> S1<T, u8> { | ||
const C: S1<u8, u8> = Self(0, 1); | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} | ||
|
||
struct S2<T>(T); | ||
impl<T> S2<T> { | ||
fn map<U>(x: U) -> S2<U> { | ||
Self(x) | ||
//~^ ERROR mismatched types | ||
//~| ERROR mismatched types | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:5:28 | ||
| | ||
LL | impl<T> S0<T> { | ||
| - this type parameter | ||
LL | const C: S0<u8> = Self(0); | ||
| ^ expected type parameter `T`, found integer | ||
| | ||
= note: expected type parameter `T` | ||
found type `{integer}` | ||
= help: type parameters must be constrained to match other types | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:5:23 | ||
| | ||
LL | impl<T> S0<T> { | ||
| - this type parameter | ||
LL | const C: S0<u8> = Self(0); | ||
| ^^^^^^^ expected `u8`, found type parameter `T` | ||
| | ||
= note: expected struct `S0<u8>` | ||
found struct `S0<T>` | ||
= help: type parameters must be constrained to match other types | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:10:14 | ||
| | ||
LL | impl<T> S0<T> { | ||
| - this type parameter | ||
... | ||
LL | Self(0); | ||
| ^ expected type parameter `T`, found integer | ||
| | ||
= note: expected type parameter `T` | ||
found type `{integer}` | ||
= help: type parameters must be constrained to match other types | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:27:14 | ||
| | ||
LL | impl<T> Foo<T> for <S0<T> as Fun>::Out { | ||
| - this type parameter | ||
LL | fn foo() { | ||
LL | Self(0); | ||
| ^ expected type parameter `T`, found integer | ||
| | ||
= note: expected type parameter `T` | ||
found type `{integer}` | ||
= help: type parameters must be constrained to match other types | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:33:32 | ||
| | ||
LL | impl<T> S1<T, u8> { | ||
| - this type parameter | ||
LL | const C: S1<u8, u8> = Self(0, 1); | ||
| ^ expected type parameter `T`, found integer | ||
| | ||
= note: expected type parameter `T` | ||
found type `{integer}` | ||
= help: type parameters must be constrained to match other types | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:33:27 | ||
| | ||
LL | impl<T> S1<T, u8> { | ||
| - this type parameter | ||
LL | const C: S1<u8, u8> = Self(0, 1); | ||
| ^^^^^^^^^^ expected `u8`, found type parameter `T` | ||
| | ||
= note: expected struct `S1<u8, _>` | ||
found struct `S1<T, _>` | ||
= help: type parameters must be constrained to match other types | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:41:14 | ||
| | ||
LL | impl<T> S2<T> { | ||
| - expected type parameter | ||
LL | fn map<U>(x: U) -> S2<U> { | ||
| - found type parameter | ||
LL | Self(x) | ||
| ^ expected type parameter `T`, found type parameter `U` | ||
| | ||
= note: expected type parameter `T` | ||
found type parameter `U` | ||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-69306.rs:41:9 | ||
| | ||
LL | impl<T> S2<T> { | ||
| - found type parameter | ||
LL | fn map<U>(x: U) -> S2<U> { | ||
| - ----- expected `S2<U>` because of return type | ||
| | | ||
| expected type parameter | ||
LL | Self(x) | ||
| ^^^^^^^ expected type parameter `U`, found type parameter `T` | ||
| | ||
= note: expected struct `S2<U>` | ||
found struct `S2<T>` | ||
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I see, the
.ty
should've been a big warning flag (the other field is...substs
).Can you also change the call sites in
check::method::suggest
to just usetcx.type_of(impl_def_id)
?(EDIT: okay that wouldn't do the same thing, but I'm curious if that's necessary or if it actually makes things worse?)
And then maybe inline
impl_self_ty
into the only remaining use site (which is incheck::method::confirm
?).If
impl_self_ty
was used more widely incheck::method
I'd suggest renaming it toinstantiate_impl_self_ty
and make it private tocheck::method
. But it's not, so might as well get rid of it before this happens again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer not dealing with it in this PR. I've filed #69489 for the follow-up.