X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcheck%2Fmethod%2Fsuggest.rs;h=2320a29e6d823a8c362fcd82638c0b4ae3a5c482;hb=4e8d4bdf4b5f185a6096c29147dff7d2d3daa7d7;hp=73e35f0171aa773b21358c50652487073c8887e4;hpb=7e717e99be6d3418d44ec510e142484db12fd757;p=rust.git diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 73e35f0171a..2320a29e6d8 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -6,7 +6,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, Res}; -use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; +use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_hir::intravisit; use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, Node, QPath}; @@ -579,6 +579,7 @@ fn report_function( } let mut restrict_type_params = false; + let mut unsatisfied_bounds = false; if !unsatisfied_predicates.is_empty() { let def_span = |def_id| { self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id)) @@ -739,6 +740,7 @@ trait bound{s}", err.note(&format!( "the following trait bounds were not satisfied:\n{bound_list}" )); + unsatisfied_bounds = true; } } @@ -752,6 +754,7 @@ trait bound{s}", source, out_of_scope_traits, &unsatisfied_predicates, + unsatisfied_bounds, ); } @@ -984,9 +987,10 @@ fn suggest_traits_to_import( source: SelfSource<'tcx>, valid_out_of_scope_traits: Vec, unsatisfied_predicates: &[(ty::Predicate<'tcx>, Option>)], + unsatisfied_bounds: bool, ) { let mut alt_rcvr_sugg = false; - if let SelfSource::MethodCall(rcvr) = source { + if let (SelfSource::MethodCall(rcvr), false) = (source, unsatisfied_bounds) { debug!(?span, ?item_name, ?rcvr_ty, ?rcvr); let skippable = [ self.tcx.lang_items().clone_trait(), @@ -1436,11 +1440,11 @@ fn cmp(&self, other: &TraitInfo) -> Ordering { /// Retrieves all traits in this crate and any dependent crates. pub fn all_traits(tcx: TyCtxt<'_>) -> Vec { - tcx.all_traits(LOCAL_CRATE).iter().map(|&def_id| TraitInfo { def_id }).collect() + tcx.all_traits(()).iter().map(|&def_id| TraitInfo { def_id }).collect() } /// Computes all traits in this crate and any dependent crates. -fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec { +fn compute_all_traits(tcx: TyCtxt<'_>, (): ()) -> &[DefId] { use hir::itemlikevisit; let mut traits = vec![]; @@ -1499,14 +1503,11 @@ fn handle_external_res( handle_external_res(tcx, &mut traits, &mut external_mods, Res::Def(DefKind::Mod, def_id)); } - traits + tcx.arena.alloc_from_iter(traits) } pub fn provide(providers: &mut ty::query::Providers) { - providers.all_traits = |tcx, cnum| { - assert_eq!(cnum, LOCAL_CRATE); - &tcx.arena.alloc(compute_all_traits(tcx))[..] - } + providers.all_traits = compute_all_traits; } struct UsePlacementFinder<'tcx> {