diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-04-02 16:14:11 +0200 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-04-23 13:07:21 +0200 |
| commit | f0f7a59eaa2a6c71487373964ffeccf539de5228 (patch) | |
| tree | 1db140fa99cfd10de86c7263555c8ef9e160f77e | |
| parent | 6a3fb269ede7d18de3597cae8d35edbb9b7c6c44 (diff) | |
| download | rust-f0f7a59eaa2a6c71487373964ffeccf539de5228.tar.gz rust-f0f7a59eaa2a6c71487373964ffeccf539de5228.zip | |
Use ConstCx in more places
| -rw-r--r-- | src/librustc_mir/borrow_check/type_check/mod.rs | 16 | ||||
| -rw-r--r-- | src/librustc_mir/transform/check_consts/mod.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/transform/promote_consts.rs | 17 |
3 files changed, 27 insertions, 15 deletions
diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 796efd2bab9..e22a4b92ec5 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -42,7 +42,10 @@ use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations} use crate::dataflow::move_paths::MoveData; use crate::dataflow::MaybeInitializedPlaces; use crate::dataflow::ResultsCursor; -use crate::transform::promote_consts::should_suggest_const_in_array_repeat_expressions_attribute; +use crate::transform::{ + check_consts::ConstCx, + promote_consts::should_suggest_const_in_array_repeat_expressions_attribute, +}; use crate::borrow_check::{ borrow_set::BorrowSet, @@ -1984,14 +1987,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { 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, + self.mir_def_id, + body, + self.param_env, + ); // To determine if `const_in_array_repeat_expressions` feature gate should // be mentioned, need to check if the rvalue is promotable. let should_suggest = should_suggest_const_in_array_repeat_expressions_attribute( - tcx, - self.mir_def_id, - body, - operand, + ccx, operand, ); debug!("check_rvalue: should_suggest={:?}", should_suggest); diff --git a/src/librustc_mir/transform/check_consts/mod.rs b/src/librustc_mir/transform/check_consts/mod.rs index 3812872ff78..a630c56ee97 100644 --- a/src/librustc_mir/transform/check_consts/mod.rs +++ b/src/librustc_mir/transform/check_consts/mod.rs @@ -31,6 +31,15 @@ pub struct ConstCx<'mir, 'tcx> { impl ConstCx<'mir, 'tcx> { pub fn new(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'mir mir::Body<'tcx>) -> Self { let param_env = tcx.param_env(def_id); + Self::new_with_param_env(tcx, def_id, body, param_env) + } + + pub fn new_with_param_env( + tcx: TyCtxt<'tcx>, + def_id: DefId, + body: &'mir mir::Body<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ) -> Self { let const_kind = ConstKind::for_item(tcx, def_id); ConstCx { body, tcx, def_id, param_env, const_kind } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index b11dbef3294..5145ad18f2a 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -1147,22 +1147,19 @@ pub fn promote_candidates<'tcx>( /// Feature attribute should be suggested if `operand` can be promoted and the feature is not /// enabled. crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>( - tcx: TyCtxt<'tcx>, - mir_def_id: DefId, - body: &Body<'tcx>, + ccx: ConstCx<'_, 'tcx>, operand: &Operand<'tcx>, ) -> bool { - let mut rpo = traversal::reverse_postorder(&body); - let (temps, _) = collect_temps_and_candidates(tcx, &body, &mut rpo); - let validator = - Validator { ccx: ConstCx::new(tcx, mir_def_id, body), temps: &temps, explicit: false }; + let mut rpo = traversal::reverse_postorder(&ccx.body); + let (temps, _) = collect_temps_and_candidates(ccx.tcx, &ccx.body, &mut rpo); + let validator = Validator { ccx, temps: &temps, explicit: false }; let should_promote = validator.validate_operand(operand).is_ok(); - let feature_flag = tcx.features().const_in_array_repeat_expressions; + let feature_flag = validator.ccx.tcx.features().const_in_array_repeat_expressions; debug!( - "should_suggest_const_in_array_repeat_expressions_flag: mir_def_id={:?} \ + "should_suggest_const_in_array_repeat_expressions_flag: def_id={:?} \ should_promote={:?} feature_flag={:?}", - mir_def_id, should_promote, feature_flag + validator.ccx.def_id, should_promote, feature_flag ); should_promote && !feature_flag } |
