X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_borrowck%2Fsrc%2Ftype_check%2Fmod.rs;h=4b905c23e156a069939798ea253be7aaeb8be9a1;hb=7907385999b4a83d37ed31d334f3ed9ca02983a1;hp=ece801716b2dbacc6715dc87e2d37113304fce63;hpb=db61452b7a2ec92d90f4faebfa679c54ad3e1ab0;p=rust.git diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index ece801716b2..4b905c23e15 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -37,18 +37,13 @@ use rustc_span::def_id::CRATE_DEF_ID; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::VariantIdx; -use rustc_trait_selection::infer::InferCtxtExt as _; -use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; use rustc_trait_selection::traits::query::type_op; use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints; use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; use rustc_trait_selection::traits::query::Fallible; -use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligation}; +use rustc_trait_selection::traits::PredicateObligation; -use rustc_const_eval::transform::{ - check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression, -}; use rustc_mir_dataflow::impls::MaybeInitializedPlaces; use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::ResultsCursor; @@ -976,7 +971,7 @@ pub enum Locations { /// things like the type of the return slot. Consider this /// example: /// - /// ``` + /// ```compile_fail,E0515 /// fn foo<'a>(x: &'a u32) -> &'a u32 { /// let y = 22; /// return &y; // error @@ -1141,6 +1136,7 @@ fn push_region_constraints( Some(self.implicit_region_bound), self.param_env, locations, + locations.span(self.body), category, &mut self.borrowck_context.constraints, ) @@ -1867,41 +1863,17 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L Operand::Move(place) => { // Make sure that repeated elements implement `Copy`. let span = body.source_info(location).span; - let ty = operand.ty(body, tcx); - if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) { - let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env); - let is_const_fn = - is_const_fn_in_array_repeat_expression(&ccx, &place, &body); - - debug!("check_rvalue: is_const_fn={:?}", is_const_fn); - - let def_id = body.source.def_id().expect_local(); - let obligation = traits::Obligation::new( - ObligationCause::new( - span, - self.tcx().hir().local_def_id_to_hir_id(def_id), - traits::ObligationCauseCode::RepeatElementCopy { - is_const_fn, - }, - ), - self.param_env, - ty::Binder::dummy(ty::TraitRef::new( - self.tcx().require_lang_item( - LangItem::Copy, - Some(self.last_span), - ), - tcx.mk_substs_trait(ty, &[]), - )) - .without_const() - .to_predicate(self.tcx()), - ); - self.infcx.report_selection_error( - obligation.clone(), - &obligation, - &traits::SelectionError::Unimplemented, - false, - ); - } + let ty = place.ty(body, tcx).ty; + let trait_ref = ty::TraitRef::new( + tcx.require_lang_item(LangItem::Copy, Some(span)), + tcx.mk_substs_trait(ty, &[]), + ); + + self.prove_trait_ref( + trait_ref, + Locations::Single(location), + ConstraintCategory::CopyBound, + ); } } } @@ -2401,6 +2373,7 @@ fn add_reborrow_constraint( sup: ref_region.to_region_vid(), sub: borrow_region.to_region_vid(), locations: location.to_locations(), + span: location.to_locations().span(body), category, variance_info: ty::VarianceDiagInfo::default(), });