diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 4258896deec70..f9c26dc1173f2 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -2415,7 +2415,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } } - let lint_ambiguous = match probes[0].0.kind { + let lint_ambiguous = match child_candidate.kind { TraitCandidate(_, lint) => lint, _ => false, }; diff --git a/tests/ui/methods/supertrait-shadowing/ambiguous-glob-imported-subtrait.rs b/tests/ui/methods/supertrait-shadowing/ambiguous-glob-imported-subtrait.rs new file mode 100644 index 0000000000000..856a7b7d3122b --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/ambiguous-glob-imported-subtrait.rs @@ -0,0 +1,38 @@ +//@ check-fail +//@ normalize-stderr: "error: aborting due to 1 previous error\n\n" -> "error: aborting due to 1 previous error\n" + +#![feature(supertrait_item_shadowing)] +#![deny(ambiguous_glob_imported_traits)] +#![allow(dead_code, unused_imports)] + +trait DefaultPolicy { + fn allow_action(&self) -> bool { + false + } +} + +mod first_policy { + pub trait Role: crate::DefaultPolicy { + fn allow_action(&self) -> bool { + true + } + } + + impl crate::DefaultPolicy for u8 {} + impl Role for u8 {} +} + +mod second_policy { + pub trait Role: crate::DefaultPolicy { + fn audit_only(&self) {} + } +} + +use first_policy::*; +use second_policy::*; + +fn main() { + assert!(0u8.allow_action()); + //~^ ERROR Use of ambiguously glob imported trait `Role` + //~| WARN this was previously accepted by the compiler but is being phased out +} diff --git a/tests/ui/methods/supertrait-shadowing/ambiguous-glob-imported-subtrait.stderr b/tests/ui/methods/supertrait-shadowing/ambiguous-glob-imported-subtrait.stderr new file mode 100644 index 0000000000000..8ae3ab7e8ea0b --- /dev/null +++ b/tests/ui/methods/supertrait-shadowing/ambiguous-glob-imported-subtrait.stderr @@ -0,0 +1,19 @@ +error: Use of ambiguously glob imported trait `Role` + --> $DIR/ambiguous-glob-imported-subtrait.rs:35:17 + | +LL | use first_policy::*; + | ------------ `Role` imported ambiguously here +... +LL | assert!(0u8.allow_action()); + | ^^^^^^^^^^^^ + | + = help: Import `Role` explicitly + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #147992 +note: the lint level is defined here + --> $DIR/ambiguous-glob-imported-subtrait.rs:5:9 + | +LL | #![deny(ambiguous_glob_imported_traits)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error