From d6b28f377cedada86c67cedc28fee4c925841a6d Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 8 Jun 2022 17:49:34 +0200 Subject: [PATCH] add test + don't warn on `Res::SelfTy` --- .../infer/error_reporting/need_type_info.rs | 3 ++ .../inference/need_type_info/concrete-impl.rs | 16 +++++++++ .../need_type_info/concrete-impl.stderr | 33 +++++++++++++++++++ .../need_type_info/self-ty-in-path.rs | 13 ++++++++ .../need_type_info/self-ty-in-path.stderr | 14 ++++++++ 5 files changed, 79 insertions(+) create mode 100644 src/test/ui/inference/need_type_info/concrete-impl.rs create mode 100644 src/test/ui/inference/need_type_info/concrete-impl.stderr create mode 100644 src/test/ui/inference/need_type_info/self-ty-in-path.rs create mode 100644 src/test/ui/inference/need_type_info/self-ty-in-path.stderr diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 40b73eb670c..207d2870c5c 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -863,6 +863,9 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { // See the `need_type_info/type-alias.rs` test for // some examples. } + // There cannot be inference variables in the self type, + // so there's nothing for us to do here. + Res::SelfTy { .. } => {} _ => warn!( "unexpected path: def={:?} substs={:?} path={:?}", def, substs, path, diff --git a/src/test/ui/inference/need_type_info/concrete-impl.rs b/src/test/ui/inference/need_type_info/concrete-impl.rs new file mode 100644 index 00000000000..72e0e74f323 --- /dev/null +++ b/src/test/ui/inference/need_type_info/concrete-impl.rs @@ -0,0 +1,16 @@ +trait Ambiguous { + fn method() {} +} + +struct One; +struct Two; +struct Struct; + +impl Ambiguous for Struct {} +impl Ambiguous for Struct {} + +fn main() { + >::method(); + //~^ ERROR type annotations needed + //~| ERROR type annotations needed +} diff --git a/src/test/ui/inference/need_type_info/concrete-impl.stderr b/src/test/ui/inference/need_type_info/concrete-impl.stderr new file mode 100644 index 00000000000..b79d34affa2 --- /dev/null +++ b/src/test/ui/inference/need_type_info/concrete-impl.stderr @@ -0,0 +1,33 @@ +error[E0282]: type annotations needed + --> $DIR/concrete-impl.rs:13:5 + | +LL | >::method(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous` + | +help: consider specifying the generic argument + | +LL | >::method(); + | ~~~~~ + +error[E0283]: type annotations needed + --> $DIR/concrete-impl.rs:13:5 + | +LL | >::method(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `Ambiguous` + | +note: multiple `impl`s satisfying `Struct: Ambiguous<_>` found + --> $DIR/concrete-impl.rs:9:1 + | +LL | impl Ambiguous for Struct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | impl Ambiguous for Struct {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider specifying the generic argument + | +LL | >::method(); + | ~~~~~ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0282, E0283. +For more information about an error, try `rustc --explain E0282`. diff --git a/src/test/ui/inference/need_type_info/self-ty-in-path.rs b/src/test/ui/inference/need_type_info/self-ty-in-path.rs new file mode 100644 index 00000000000..768a8cc3778 --- /dev/null +++ b/src/test/ui/inference/need_type_info/self-ty-in-path.rs @@ -0,0 +1,13 @@ +// Test that we don't ICE when encountering a `Self` in a path. +struct TestErr(T); + +impl TestErr { + fn func_a() {} + + fn func_b() { + Self::func_a(); + //~^ ERROR type annotations needed + } +} + +fn main() {} diff --git a/src/test/ui/inference/need_type_info/self-ty-in-path.stderr b/src/test/ui/inference/need_type_info/self-ty-in-path.stderr new file mode 100644 index 00000000000..04b521dbdb3 --- /dev/null +++ b/src/test/ui/inference/need_type_info/self-ty-in-path.stderr @@ -0,0 +1,14 @@ +error[E0282]: type annotations needed + --> $DIR/self-ty-in-path.rs:8:9 + | +LL | Self::func_a(); + | ^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the associated function `func_a` + | +help: consider specifying the generic argument + | +LL | Self::func_a::(); + | +++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`.