X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcheck%2Fmethod%2Fsuggest.rs;h=2faf40f7293ce3f5e4e1dd8fde8221e8b9fcec83;hb=976348603485b216b0d5314eca674a2b24df4c73;hp=8aa22852a6ffdc35574dd68ec2d63a7b65dae3d5;hpb=0986b2d0e3c5f49de2a318b7ff441be664b8d51c;p=rust.git diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 8aa22852a6f..2faf40f7293 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -9,7 +9,7 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::{ExprKind, Node, QPath}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_middle::ty::fast_reject::{simplify_type, SimplifyParams, StripReferences}; +use rustc_middle::ty::fast_reject::{simplify_type, SimplifyParams}; use rustc_middle::ty::print::with_crate_prefix; use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable}; use rustc_span::lev_distance; @@ -703,7 +703,7 @@ fn report_function( let mut bound_spans = vec![]; let mut collect_type_param_suggestions = - |self_ty: Ty<'tcx>, parent_pred: &ty::Predicate<'tcx>, obligation: &str| { + |self_ty: Ty<'tcx>, parent_pred: ty::Predicate<'tcx>, obligation: &str| { // We don't care about regions here, so it's fine to skip the binder here. if let (ty::Param(_), ty::PredicateKind::Trait(p)) = (self_ty.kind(), parent_pred.kind().skip_binder()) @@ -892,7 +892,7 @@ fn report_function( .filter(|(pred, _, _parent_pred)| !skip_list.contains(&pred)) .filter_map(|(pred, parent_pred, _cause)| { format_pred(*pred).map(|(p, self_ty)| { - collect_type_param_suggestions(self_ty, pred, &p); + collect_type_param_suggestions(self_ty, *pred, &p); match parent_pred { None => format!("`{}`", &p), Some(parent_pred) => match format_pred(*parent_pred) { @@ -900,7 +900,7 @@ fn report_function( Some((parent_p, _)) => { collect_type_param_suggestions( self_ty, - parent_pred, + *parent_pred, &p, ); format!("`{}`\nwhich is required by `{}`", p, parent_p) @@ -1086,8 +1086,8 @@ trait bound{s}", if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() { if needs_mut { let trait_type = self.tcx.mk_ref( - region, - ty::TypeAndMut { ty: t_type, mutbl: mutability.invert() }, + *region, + ty::TypeAndMut { ty: *t_type, mutbl: mutability.invert() }, ); err.note(&format!("you need `{}` instead of `{}`", trait_type, rcvr_ty)); } @@ -1326,7 +1326,7 @@ fn suggest_use_candidates( let additional_newline = if found_use { "" } else { "\n" }; format!( "use {};\n{}", - with_crate_prefix(|| self.tcx.def_path_str(*trait_did)), + with_crate_prefix!(self.tcx.def_path_str(*trait_did)), additional_newline ) }); @@ -1339,7 +1339,7 @@ fn suggest_use_candidates( let additional_newline = if found_use { "" } else { "\n" }; format!( "use {}::*; // trait {}\n{}", - with_crate_prefix(|| self.tcx.def_path_str(*parent_did)), + with_crate_prefix!(self.tcx.def_path_str(*parent_did)), self.tcx.item_name(*trait_did), additional_newline ) @@ -1358,12 +1358,12 @@ fn suggest_use_candidates( msg.push_str(&format!( "\ncandidate #{}: `use {};`", i + 1, - with_crate_prefix(|| self.tcx.def_path_str(*trait_did)) + with_crate_prefix!(self.tcx.def_path_str(*trait_did)) )); } else { msg.push_str(&format!( "\n`use {};`", - with_crate_prefix(|| self.tcx.def_path_str(*trait_did)) + with_crate_prefix!(self.tcx.def_path_str(*trait_did)) )); } } @@ -1376,13 +1376,13 @@ fn suggest_use_candidates( msg.push_str(&format!( "\ncandidate #{}: `use {}::*; // trait {}`", candidates.len() + i + 1, - with_crate_prefix(|| self.tcx.def_path_str(*parent_did)), + with_crate_prefix!(self.tcx.def_path_str(*parent_did)), self.tcx.item_name(*trait_did), )); } else { msg.push_str(&format!( "\n`use {}::*; // trait {}`", - with_crate_prefix(|| self.tcx.def_path_str(*parent_did)), + with_crate_prefix!(self.tcx.def_path_str(*parent_did)), self.tcx.item_name(*trait_did), )); } @@ -1422,7 +1422,7 @@ fn suggest_valid_traits( if let Some(did) = edition_fix { err.note(&format!( "'{}' is included in the prelude starting in Edition 2021", - with_crate_prefix(|| self.tcx.def_path_str(did)) + with_crate_prefix!(self.tcx.def_path_str(did)) )); } @@ -1462,13 +1462,13 @@ fn suggest_traits_to_import( // just this list. for (rcvr_ty, post) in &[ (rcvr_ty, ""), - (self.tcx.mk_mut_ref(&ty::ReErased, rcvr_ty), "&mut "), - (self.tcx.mk_imm_ref(&ty::ReErased, rcvr_ty), "&"), + (self.tcx.mk_mut_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&mut "), + (self.tcx.mk_imm_ref(self.tcx.lifetimes.re_erased, rcvr_ty), "&"), ] { if let Ok(pick) = self.lookup_probe( span, item_name, - rcvr_ty, + *rcvr_ty, rcvr, crate::check::method::probe::ProbeScope::AllTraits, ) { @@ -1487,10 +1487,10 @@ fn suggest_traits_to_import( break; } for (rcvr_ty, pre) in &[ - (self.tcx.mk_lang_item(rcvr_ty, LangItem::OwnedBox), "Box::new"), - (self.tcx.mk_lang_item(rcvr_ty, LangItem::Pin), "Pin::new"), - (self.tcx.mk_diagnostic_item(rcvr_ty, sym::Arc), "Arc::new"), - (self.tcx.mk_diagnostic_item(rcvr_ty, sym::Rc), "Rc::new"), + (self.tcx.mk_lang_item(*rcvr_ty, LangItem::OwnedBox), "Box::new"), + (self.tcx.mk_lang_item(*rcvr_ty, LangItem::Pin), "Pin::new"), + (self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Arc), "Arc::new"), + (self.tcx.mk_diagnostic_item(*rcvr_ty, sym::Rc), "Rc::new"), ] { if let Some(new_rcvr_t) = *rcvr_ty { if let Ok(pick) = self.lookup_probe( @@ -1748,8 +1748,7 @@ fn suggest_traits_to_import( // FIXME: Even though negative bounds are not implemented, we could maybe handle // cases where a positive bound implies a negative impl. (candidates, Vec::new()) - } else if let Some(simp_rcvr_ty) = - simplify_type(self.tcx, rcvr_ty, SimplifyParams::Yes, StripReferences::No) + } else if let Some(simp_rcvr_ty) = simplify_type(self.tcx, rcvr_ty, SimplifyParams::Yes) { let mut potential_candidates = Vec::new(); let mut explicitly_negative = Vec::new(); @@ -1763,12 +1762,8 @@ fn suggest_traits_to_import( }) .any(|imp_did| { let imp = self.tcx.impl_trait_ref(imp_did).unwrap(); - let imp_simp = simplify_type( - self.tcx, - imp.self_ty(), - SimplifyParams::Yes, - StripReferences::No, - ); + let imp_simp = + simplify_type(self.tcx, imp.self_ty(), SimplifyParams::Yes); imp_simp.map_or(false, |s| s == simp_rcvr_ty) }) {