diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_borrowck/src/type_check/mod.rs | 37 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/bounds.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_monomorphize/src/collector.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_monomorphize/src/lib.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/project.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/confirmation.rs | 19 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/wf.rs | 3 |
10 files changed, 51 insertions, 66 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 750d57b9c8c..5bf371290ba 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -547,11 +547,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context { let tcx = self.tcx(); - let trait_ref = tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Copy, Some(self.last_span)), - place_ty.ty, - [], - ); + let trait_ref = tcx.at(self.last_span).mk_trait_ref(LangItem::Copy, place_ty.ty, []); // To have a `Copy` operand, the type `T` of the // value must be `Copy`. Note that we prove that `T: Copy`, @@ -1274,11 +1270,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.check_rvalue(body, rv, location); if !self.unsized_feature_enabled() { - let trait_ref = tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Sized, Some(self.last_span)), - place_ty, - [], - ); + let trait_ref = + tcx.at(self.last_span).mk_trait_ref(LangItem::Sized, place_ty, []); self.prove_trait_ref( trait_ref, location.to_locations(), @@ -1842,6 +1835,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { #[instrument(skip(self, body), level = "debug")] fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { let tcx = self.tcx(); + let span = body.source_info(location).span; match rvalue { Rvalue::Aggregate(ak, ops) => { @@ -1865,13 +1859,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } Operand::Move(place) => { // Make sure that repeated elements implement `Copy`. - let span = body.source_info(location).span; let ty = place.ty(body, tcx).ty; - let trait_ref = tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Copy, Some(span)), - ty, - [], - ); + let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Copy, ty, []); self.prove_trait_ref( trait_ref, @@ -1884,11 +1873,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } &Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => { - let trait_ref = tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Sized, Some(self.last_span)), - ty, - [], - ); + let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, ty, []); self.prove_trait_ref( trait_ref, @@ -1900,11 +1885,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { Rvalue::ShallowInitBox(operand, ty) => { self.check_operand(operand, location); - let trait_ref = tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Sized, Some(self.last_span)), - *ty, - [], - ); + let trait_ref = tcx.at(span).mk_trait_ref(LangItem::Sized, *ty, []); self.prove_trait_ref( trait_ref, @@ -2001,8 +1982,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { CastKind::Pointer(PointerCast::Unsize) => { let &ty = ty; - let trait_ref = tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::CoerceUnsized, Some(self.last_span)), + let trait_ref = tcx.at(span).mk_trait_ref( + LangItem::CoerceUnsized, op.ty(body, tcx), [ty.into()], ); diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 4f1878a3f25..6dcada67ca4 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -153,14 +153,12 @@ impl Qualif for NeedsNonConstDrop { return false; } - let destruct = cx.tcx.require_lang_item(LangItem::Destruct, None); - let obligation = Obligation::new( cx.tcx, - ObligationCause::dummy(), + ObligationCause::dummy_with_span(cx.body.span), cx.param_env, ty::Binder::dummy(ty::TraitPredicate { - trait_ref: cx.tcx.mk_trait_ref(destruct, ty, []), + trait_ref: cx.tcx.at(cx.body.span).mk_trait_ref(LangItem::Destruct, ty, []), constness: ty::BoundConstness::ConstIfConst, polarity: ty::ImplPolarity::Positive, }), diff --git a/compiler/rustc_hir_analysis/src/bounds.rs b/compiler/rustc_hir_analysis/src/bounds.rs index 17cdbdb70fb..0f9311f4b7e 100644 --- a/compiler/rustc_hir_analysis/src/bounds.rs +++ b/compiler/rustc_hir_analysis/src/bounds.rs @@ -60,10 +60,10 @@ impl<'tcx> Bounds<'tcx> { { // If it could be sized, and is, add the `Sized` predicate. let sized_predicate = self.implicitly_sized.and_then(|span| { - tcx.lang_items().sized_trait().map(move |sized| { - let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized, param_ty, [])); - (trait_ref.without_const().to_predicate(tcx), span) - }) + // FIXME: use tcx.at(span).mk_trait_ref(LangItem::Sized) here? This may make no-core code harder to write. + let sized = tcx.lang_items().sized_trait()?; + let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(sized, param_ty, [])); + Some((trait_ref.without_const().to_predicate(tcx), span)) }); let region_preds = self.region_bounds.iter().map(move |&(region_bound, span)| { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 1538d0a1bbb..724e6261365 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1722,7 +1722,7 @@ fn receiver_is_valid<'tcx>( // The first type is `receiver_ty`, which we know its not equal to `self_ty`; skip it. autoderef.next(); - let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, None); + let receiver_trait_def_id = tcx.require_lang_item(LangItem::Receiver, Some(span)); // Keep dereferencing `receiver_ty` until we get to `self_ty`. loop { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index c43447ae05d..73e07dcd592 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2990,6 +2990,16 @@ impl<'tcx> TyCtxtAt<'tcx> { pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> { self.tcx.ty_error_with_message(self.span, msg) } + + pub fn mk_trait_ref( + self, + trait_lang_item: LangItem, + self_ty: Ty<'tcx>, + rest: impl IntoIterator<Item = ty::GenericArg<'tcx>, IntoIter: ExactSizeIterator>, + ) -> ty::TraitRef<'tcx> { + let trait_def_id = self.require_lang_item(trait_lang_item, Some(self.span)); + self.tcx.mk_trait_ref(trait_def_id, self_ty, rest) + } } /// Parameter attributes that can only be determined by examining the body of a function instead diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index d74893bf0f0..559ce227454 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -187,6 +187,7 @@ use rustc_middle::mir::visit::Visitor as MirVisitor; use rustc_middle::mir::{self, Local, Location}; use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCast}; use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_middle::ty::query::TyCtxtAt; use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::{ self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitable, VtblEntry, @@ -688,7 +689,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { let source_ty = operand.ty(self.body, self.tcx); let source_ty = self.monomorphize(source_ty); let (source_ty, target_ty) = - find_vtable_types_for_unsizing(self.tcx, source_ty, target_ty); + find_vtable_types_for_unsizing(self.tcx.at(span), source_ty, target_ty); // This could also be a different Unsize instruction, like // from a fixed sized array to a slice. But we are only // interested in things that produce a vtable. @@ -1053,14 +1054,14 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) -> /// Finally, there is also the case of custom unsizing coercions, e.g., for /// smart pointers such as `Rc` and `Arc`. fn find_vtable_types_for_unsizing<'tcx>( - tcx: TyCtxt<'tcx>, + tcx: TyCtxtAt<'tcx>, source_ty: Ty<'tcx>, target_ty: Ty<'tcx>, ) -> (Ty<'tcx>, Ty<'tcx>) { let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| { let param_env = ty::ParamEnv::reveal_all(); let type_has_metadata = |ty: Ty<'tcx>| -> bool { - if ty.is_sized(tcx, param_env) { + if ty.is_sized(tcx.tcx, param_env) { return false; } let tail = tcx.struct_tail_erasing_lifetimes(ty, param_env); @@ -1104,8 +1105,8 @@ fn find_vtable_types_for_unsizing<'tcx>( find_vtable_types_for_unsizing( tcx, - source_fields[coerce_index].ty(tcx, source_substs), - target_fields[coerce_index].ty(tcx, target_substs), + source_fields[coerce_index].ty(*tcx, source_substs), + target_fields[coerce_index].ty(*tcx, target_substs), ) } _ => bug!( diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index 8eb489bb596..616620edc09 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -13,8 +13,8 @@ extern crate rustc_middle; use rustc_hir::lang_items::LangItem; use rustc_middle::traits; use rustc_middle::ty::adjustment::CustomCoerceUnsized; -use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::query::{Providers, TyCtxtAt}; +use rustc_middle::ty::{self, Ty}; mod collector; mod errors; @@ -23,13 +23,12 @@ mod polymorphize; mod util; fn custom_coerce_unsize_info<'tcx>( - tcx: TyCtxt<'tcx>, + tcx: TyCtxtAt<'tcx>, source_ty: Ty<'tcx>, target_ty: Ty<'tcx>, ) -> CustomCoerceUnsized { - let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None); - - let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(def_id, source_ty, [target_ty.into()])); + let trait_ref = + ty::Binder::dummy(tcx.mk_trait_ref(LangItem::CoerceUnsized, source_ty, [target_ty.into()])); match tcx.codegen_select_candidate((ty::ParamEnv::reveal_all(), trait_ref)) { Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData { diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index b8fe4c86405..4b1e8f18e34 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1710,8 +1710,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( if selcx.infcx().predicate_must_hold_modulo_regions( &obligation.with( selcx.tcx(), - ty::Binder::dummy(selcx.tcx().mk_trait_ref( - selcx.tcx().require_lang_item(LangItem::Sized, None), + ty::Binder::dummy(selcx.tcx().at(obligation.cause.span).mk_trait_ref( + LangItem::Sized, self_ty, [], )) .without_const(), @@ -1966,8 +1966,8 @@ fn confirm_pointee_candidate<'cx, 'tcx>( ) }); if check_is_sized { - let sized_predicate = ty::Binder::dummy(tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Sized, None), + let sized_predicate = ty::Binder::dummy(tcx.at(obligation.cause.span).mk_trait_ref( + LangItem::Sized, self_ty, [], )) @@ -1976,7 +1976,7 @@ fn confirm_pointee_candidate<'cx, 'tcx>( } let substs = tcx.mk_substs([self_ty.into()].iter()); - let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None); + let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, Some(obligation.cause.span)); let predicate = ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { substs, item_def_id: metadata_def_id }, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 32683eb9822..19d69e9dfaa 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -632,8 +632,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { output_ty, &mut nested, ); - let tr = ty::Binder::dummy(self.tcx().mk_trait_ref( - self.tcx().require_lang_item(LangItem::Sized, None), + let tr = ty::Binder::dummy(self.tcx().at(cause.span).mk_trait_ref( + LangItem::Sized, output_ty, [], )); @@ -997,11 +997,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ); // We can only make objects from sized types. - let tr = ty::Binder::dummy(tcx.mk_trait_ref( - tcx.require_lang_item(LangItem::Sized, None), - source, - [], - )); + let tr = + ty::Binder::dummy(tcx.at(cause.span).mk_trait_ref(LangItem::Sized, source, [])); nested.push(predicate_to_obligation(tr.without_const().to_predicate(tcx))); // If the type is `Foo + 'a`, ensure that the type @@ -1255,8 +1252,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { cause.clone(), obligation.recursion_depth + 1, self_ty.rebind(ty::TraitPredicate { - trait_ref: self.tcx().mk_trait_ref( - self.tcx().require_lang_item(LangItem::Destruct, None), + trait_ref: self.tcx().at(cause.span).mk_trait_ref( + LangItem::Destruct, nested_ty, [], ), @@ -1280,8 +1277,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // or it's an ADT (and we need to check for a custom impl during selection) _ => { let predicate = self_ty.rebind(ty::TraitPredicate { - trait_ref: self.tcx().mk_trait_ref( - self.tcx().require_lang_item(LangItem::Destruct, None), + trait_ref: self.tcx().at(cause.span).mk_trait_ref( + LangItem::Destruct, nested_ty, [], ), diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 378e6738795..de72c6618d4 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -421,8 +421,7 @@ impl<'tcx> WfPredicates<'tcx> { fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) { if !subty.has_escaping_bound_vars() { let cause = self.cause(cause); - let trait_ref = - self.tcx.mk_trait_ref(self.tcx.require_lang_item(LangItem::Sized, None), subty, []); + let trait_ref = self.tcx.at(cause.span).mk_trait_ref(LangItem::Sized, subty, []); self.out.push(traits::Obligation::with_depth( self.tcx, cause, |
