Skip to content

Commit d6b28f3

Browse files
committed
add test + don't warn on Res::SelfTy
1 parent b7ab477 commit d6b28f3

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+3
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
863863
// See the `need_type_info/type-alias.rs` test for
864864
// some examples.
865865
}
866+
// There cannot be inference variables in the self type,
867+
// so there's nothing for us to do here.
868+
Res::SelfTy { .. } => {}
866869
_ => warn!(
867870
"unexpected path: def={:?} substs={:?} path={:?}",
868871
def, substs, path,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Ambiguous<A> {
2+
fn method() {}
3+
}
4+
5+
struct One;
6+
struct Two;
7+
struct Struct;
8+
9+
impl Ambiguous<One> for Struct {}
10+
impl Ambiguous<Two> for Struct {}
11+
12+
fn main() {
13+
<Struct as Ambiguous<_>>::method();
14+
//~^ ERROR type annotations needed
15+
//~| ERROR type annotations needed
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/concrete-impl.rs:13:5
3+
|
4+
LL | <Struct as Ambiguous<_>>::method();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | <Struct as Ambiguous::<_>>::method();
10+
| ~~~~~
11+
12+
error[E0283]: type annotations needed
13+
--> $DIR/concrete-impl.rs:13:5
14+
|
15+
LL | <Struct as Ambiguous<_>>::method();
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous`
17+
|
18+
note: multiple `impl`s satisfying `Struct: Ambiguous<_>` found
19+
--> $DIR/concrete-impl.rs:9:1
20+
|
21+
LL | impl Ambiguous<One> for Struct {}
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
LL | impl Ambiguous<Two> for Struct {}
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
help: consider specifying the generic argument
26+
|
27+
LL | <Struct as Ambiguous::<_>>::method();
28+
| ~~~~~
29+
30+
error: aborting due to 2 previous errors
31+
32+
Some errors have detailed explanations: E0282, E0283.
33+
For more information about an error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test that we don't ICE when encountering a `Self` in a path.
2+
struct TestErr<T>(T);
3+
4+
impl<T> TestErr<T> {
5+
fn func_a<U>() {}
6+
7+
fn func_b() {
8+
Self::func_a();
9+
//~^ ERROR type annotations needed
10+
}
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/self-ty-in-path.rs:8:9
3+
|
4+
LL | Self::func_a();
5+
| ^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the associated function `func_a`
6+
|
7+
help: consider specifying the generic argument
8+
|
9+
LL | Self::func_a::<U>();
10+
| +++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)