diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 02fe8312c4c..47e4e1223ff 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -1047,7 +1047,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - if !alt_rcvr_sugg && self.suggest_valid_traits(err, valid_out_of_scope_traits) { + if self.suggest_valid_traits(err, valid_out_of_scope_traits) { return; } diff --git a/src/test/ui/suggestions/import-trait-for-method-call.stderr b/src/test/ui/suggestions/import-trait-for-method-call.stderr index 8b72e8c922c..b6fc09cc5d0 100644 --- a/src/test/ui/suggestions/import-trait-for-method-call.stderr +++ b/src/test/ui/suggestions/import-trait-for-method-call.stderr @@ -12,6 +12,7 @@ LL | fn finish(&self) -> u64; | the method is available for `Box` here | the method is available for `Box<&mut DefaultHasher>` here | + = help: items from traits can only be used if the trait is in scope help: consider wrapping the receiver expression with the appropriate type | LL | Box::new(h).finish() @@ -20,6 +21,10 @@ help: consider wrapping the receiver expression with the appropriate type | LL | Box::new(&mut h).finish() | ^^^^^^^^^^^^^ ^ +help: the following trait is implemented but not in scope; perhaps add a `use` for it: + | +LL | use std::hash::Hasher; + | error: aborting due to previous error