From c10ad0d888df19e7185e15f811fdb011278f3c20 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 6 Aug 2020 22:12:21 +0200 Subject: [PATCH] review --- compiler/rustc_middle/src/mir/mod.rs | 4 ++++ .../rustc_trait_selection/src/traits/fulfill.rs | 11 +++++------ .../rustc_trait_selection/src/traits/select/mod.rs | 13 ++++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 197e8dd5341..3c041bbc0ae 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -197,6 +197,10 @@ pub struct Body<'tcx> { /// let _ = [0; std::mem::size_of::<*mut T>()]; /// } /// ``` + /// + /// **WARNING**: Do not change this flags after the MIR was originally created, even if an optimization + /// removed the last mention of all generic params. We do not want to rely on optimizations and + /// potentially allow things like `[u8; std::mem::size_of::() * 0]` due to this. pub is_polymorphic: bool, predecessor_cache: PredecessorCache, diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 989c6e6dbc2..4818022bf62 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -459,17 +459,16 @@ fn process_obligation( } ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { - const_evaluatable::is_const_evaluatable( + match const_evaluatable::is_const_evaluatable( self.selcx.infcx(), def_id, substs, obligation.param_env, obligation.cause.span, - ) - .map_or_else( - |e| ProcessResult::Error(CodeSelectionError(ConstEvalFailure(e))), - |()| ProcessResult::Changed(vec![]), - ) + ) { + Ok(()) => ProcessResult::Changed(vec![]), + Err(e) => ProcessResult::Error(CodeSelectionError(ConstEvalFailure(e))), + } } ty::PredicateAtom::ConstEquate(c1, c2) => { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 5a1e1eb89a6..7e8e2baa8a1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -543,18 +543,17 @@ fn evaluate_predicate_recursively<'o>( } ty::PredicateAtom::ConstEvaluatable(def_id, substs) => { - const_evaluatable::is_const_evaluatable( + match const_evaluatable::is_const_evaluatable( self.infcx, def_id, substs, obligation.param_env, obligation.cause.span, - ) - .map(|()| EvaluatedToOk) - .or_else(|e| match e { - ErrorHandled::TooGeneric => Ok(EvaluatedToAmbig), - _ => Ok(EvaluatedToErr), - }) + ) { + Ok(()) => Ok(EvaluatedToOk), + Err(ErrorHandled::TooGeneric) => Ok(EvaluatedToAmbig), + Err(_) => Ok(EvaluatedToErr), + } } ty::PredicateAtom::ConstEquate(c1, c2) => {