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;
/// 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
Some(self.implicit_region_bound),
self.param_env,
locations,
+ locations.span(self.body),
category,
&mut self.borrowck_context.constraints,
)
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,
+ );
}
}
}
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(),
});