Skip to content

Commit 6672a04

Browse files
committedFeb 26, 2020
instantiate_value_path: .impl_self_ty -> .type_of
1 parent 892cb14 commit 6672a04

File tree

3 files changed

+162
-4
lines changed

3 files changed

+162
-4
lines changed
 

‎src/librustc_typeck/check/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5446,9 +5446,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
54465446
.unwrap_or(false);
54475447

54485448
let (res, self_ctor_substs) = if let Res::SelfCtor(impl_def_id) = res {
5449-
let ty = self.impl_self_ty(span, impl_def_id).ty;
5450-
let adt_def = ty.ty_adt_def();
5451-
5449+
let ty = self.normalize_ty(span, tcx.at(span).type_of(impl_def_id));
54525450
match ty.kind {
54535451
ty::Adt(adt_def, substs) if adt_def.has_ctor() => {
54545452
let variant = adt_def.non_enum_variant();
@@ -5463,7 +5461,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
54635461
span,
54645462
"the `Self` constructor can only be used with tuple or unit structs",
54655463
);
5466-
if let Some(adt_def) = adt_def {
5464+
if let Some(adt_def) = ty.ty_adt_def() {
54675465
match adt_def.adt_kind() {
54685466
AdtKind::Enum => {
54695467
err.help("did you mean to use one of the enum's variants?");

‎src/test/ui/issues/issue-69306.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
fn main() {}
2+
3+
struct S0<T>(T);
4+
impl<T> S0<T> {
5+
const C: S0<u8> = Self(0);
6+
//~^ ERROR mismatched types
7+
//~| ERROR mismatched types
8+
9+
fn foo() {
10+
Self(0);
11+
//~^ ERROR mismatched types
12+
}
13+
}
14+
15+
// Testing normalization.
16+
trait Fun {
17+
type Out;
18+
}
19+
impl<T> Fun for S0<T> {
20+
type Out = Self;
21+
}
22+
trait Foo<T> {
23+
fn foo();
24+
}
25+
impl<T> Foo<T> for <S0<T> as Fun>::Out {
26+
fn foo() {
27+
Self(0); //~ ERROR mismatched types
28+
}
29+
}
30+
31+
struct S1<T, U>(T, U);
32+
impl<T> S1<T, u8> {
33+
const C: S1<u8, u8> = Self(0, 1);
34+
//~^ ERROR mismatched types
35+
//~| ERROR mismatched types
36+
}
37+
38+
struct S2<T>(T);
39+
impl<T> S2<T> {
40+
fn map<U>(x: U) -> S2<U> {
41+
Self(x)
42+
//~^ ERROR mismatched types
43+
//~| ERROR mismatched types
44+
}
45+
}

‎src/test/ui/issues/issue-69306.stderr

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-69306.rs:5:28
3+
|
4+
LL | impl<T> S0<T> {
5+
| - this type parameter
6+
LL | const C: S0<u8> = Self(0);
7+
| ^ expected type parameter `T`, found integer
8+
|
9+
= note: expected type parameter `T`
10+
found type `{integer}`
11+
= help: type parameters must be constrained to match other types
12+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
13+
14+
error[E0308]: mismatched types
15+
--> $DIR/issue-69306.rs:5:23
16+
|
17+
LL | impl<T> S0<T> {
18+
| - this type parameter
19+
LL | const C: S0<u8> = Self(0);
20+
| ^^^^^^^ expected `u8`, found type parameter `T`
21+
|
22+
= note: expected struct `S0<u8>`
23+
found struct `S0<T>`
24+
= help: type parameters must be constrained to match other types
25+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/issue-69306.rs:10:14
29+
|
30+
LL | impl<T> S0<T> {
31+
| - this type parameter
32+
...
33+
LL | Self(0);
34+
| ^ expected type parameter `T`, found integer
35+
|
36+
= note: expected type parameter `T`
37+
found type `{integer}`
38+
= help: type parameters must be constrained to match other types
39+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
40+
41+
error[E0308]: mismatched types
42+
--> $DIR/issue-69306.rs:27:14
43+
|
44+
LL | impl<T> Foo<T> for <S0<T> as Fun>::Out {
45+
| - this type parameter
46+
LL | fn foo() {
47+
LL | Self(0);
48+
| ^ expected type parameter `T`, found integer
49+
|
50+
= note: expected type parameter `T`
51+
found type `{integer}`
52+
= help: type parameters must be constrained to match other types
53+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
54+
55+
error[E0308]: mismatched types
56+
--> $DIR/issue-69306.rs:33:32
57+
|
58+
LL | impl<T> S1<T, u8> {
59+
| - this type parameter
60+
LL | const C: S1<u8, u8> = Self(0, 1);
61+
| ^ expected type parameter `T`, found integer
62+
|
63+
= note: expected type parameter `T`
64+
found type `{integer}`
65+
= help: type parameters must be constrained to match other types
66+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
67+
68+
error[E0308]: mismatched types
69+
--> $DIR/issue-69306.rs:33:27
70+
|
71+
LL | impl<T> S1<T, u8> {
72+
| - this type parameter
73+
LL | const C: S1<u8, u8> = Self(0, 1);
74+
| ^^^^^^^^^^ expected `u8`, found type parameter `T`
75+
|
76+
= note: expected struct `S1<u8, _>`
77+
found struct `S1<T, _>`
78+
= help: type parameters must be constrained to match other types
79+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
80+
81+
error[E0308]: mismatched types
82+
--> $DIR/issue-69306.rs:41:14
83+
|
84+
LL | impl<T> S2<T> {
85+
| - expected type parameter
86+
LL | fn map<U>(x: U) -> S2<U> {
87+
| - found type parameter
88+
LL | Self(x)
89+
| ^ expected type parameter `T`, found type parameter `U`
90+
|
91+
= note: expected type parameter `T`
92+
found type parameter `U`
93+
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
94+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
95+
96+
error[E0308]: mismatched types
97+
--> $DIR/issue-69306.rs:41:9
98+
|
99+
LL | impl<T> S2<T> {
100+
| - found type parameter
101+
LL | fn map<U>(x: U) -> S2<U> {
102+
| - ----- expected `S2<U>` because of return type
103+
| |
104+
| expected type parameter
105+
LL | Self(x)
106+
| ^^^^^^^ expected type parameter `U`, found type parameter `T`
107+
|
108+
= note: expected struct `S2<U>`
109+
found struct `S2<T>`
110+
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
111+
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
112+
113+
error: aborting due to 8 previous errors
114+
115+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)
Please sign in to comment.