From a6cbd64dae97fc0cf626ad688b285f5a8ecde393 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 24 Oct 2020 09:27:15 +0200 Subject: [PATCH] words --- compiler/rustc_data_structures/src/functor.rs | 2 +- .../src/traits/structural_impls.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 4 +- compiler/rustc_middle/src/macros.rs | 8 +-- .../rustc_middle/src/mir/interpret/error.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 27 ++------- compiler/rustc_middle/src/mir/predecessors.rs | 2 +- .../rustc_middle/src/mir/type_foldable.rs | 13 ++-- .../src/traits/structural_impls.rs | 2 +- compiler/rustc_middle/src/ty/binding.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 60 +++++-------------- compiler/rustc_middle/src/ty/util.rs | 31 ++++++++++ .../src/traits/error_reporting/mod.rs | 6 +- .../src/traits/project.rs | 4 +- .../src/traits/query/dropck_outlives.rs | 2 +- .../src/traits/query/normalize.rs | 6 +- .../src/traits/query/outlives_bounds.rs | 2 +- .../src/traits/query/type_op/mod.rs | 8 +-- .../rustc_typeck/src/check/method/probe.rs | 9 +-- 19 files changed, 87 insertions(+), 105 deletions(-) diff --git a/compiler/rustc_data_structures/src/functor.rs b/compiler/rustc_data_structures/src/functor.rs index 5d3639388f039..fe7a256d2100f 100644 --- a/compiler/rustc_data_structures/src/functor.rs +++ b/compiler/rustc_data_structures/src/functor.rs @@ -22,7 +22,7 @@ impl IdFunctor for Box { unsafe { // SAFETY: The raw pointer points to a valid value of type `T`. let value = ptr::read(raw); - // SAFETY: Convert's `Box` to `Box>` which is the + // SAFETY: Converts `Box` to `Box>` which is the // inverse of `Box::assume_init()` and should be safe. let mut raw: Box> = Box::from_raw(raw.cast()); // SAFETY: Write the mapped value back into the `Box`. diff --git a/compiler/rustc_infer/src/traits/structural_impls.rs b/compiler/rustc_infer/src/traits/structural_impls.rs index f7ae77d77153a..d8a1993b6cb3e 100644 --- a/compiler/rustc_infer/src/traits/structural_impls.rs +++ b/compiler/rustc_infer/src/traits/structural_impls.rs @@ -62,7 +62,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> { impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> { fn super_fold_with>(self, folder: &mut F) -> Self { traits::Obligation { - cause: self.cause.clone(), + cause: self.cause, recursion_depth: self.recursion_depth, predicate: self.predicate.fold_with(folder), param_env: self.param_env.fold_with(folder), diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 947b016a1fc93..6e5f95c452745 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -286,7 +286,7 @@ impl<'tcx, V> Canonical<'tcx, V> { pub type QueryOutlivesConstraint<'tcx> = ty::Binder, Region<'tcx>>>; -CloneTypeFoldableAndLiftImpls! { +TrivialTypeFoldableAndLiftImpls! { for <'tcx> { crate::infer::canonical::Certainty, crate::infer::canonical::CanonicalVarInfo<'tcx>, @@ -294,7 +294,7 @@ CloneTypeFoldableAndLiftImpls! { } } -CloneTypeFoldableImpls! { +TrivialTypeFoldableImpls! { for <'tcx> { crate::infer::canonical::CanonicalVarInfos<'tcx>, } diff --git a/compiler/rustc_middle/src/macros.rs b/compiler/rustc_middle/src/macros.rs index 73aee616e260b..9cb8fd7eb9f70 100644 --- a/compiler/rustc_middle/src/macros.rs +++ b/compiler/rustc_middle/src/macros.rs @@ -48,7 +48,7 @@ macro_rules! CloneLiftImpls { /// Used for types that are `Copy` and which **do not care arena /// allocated data** (i.e., don't need to be folded). #[macro_export] -macro_rules! CloneTypeFoldableImpls { +macro_rules! TrivialTypeFoldableImpls { (for <$tcx:lifetime> { $($ty:ty,)+ }) => { $( impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty { @@ -71,7 +71,7 @@ macro_rules! CloneTypeFoldableImpls { }; ($($ty:ty,)+) => { - CloneTypeFoldableImpls! { + TrivialTypeFoldableImpls! { for <'tcx> { $($ty,)+ } @@ -80,9 +80,9 @@ macro_rules! CloneTypeFoldableImpls { } #[macro_export] -macro_rules! CloneTypeFoldableAndLiftImpls { +macro_rules! TrivialTypeFoldableAndLiftImpls { ($($t:tt)*) => { - CloneTypeFoldableImpls! { $($t)* } + TrivialTypeFoldableImpls! { $($t)* } CloneLiftImpls! { $($t)* } } } diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index e35ff6b996ee0..397d2ffd565b1 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -29,7 +29,7 @@ impl From for ErrorHandled { } } -CloneTypeFoldableAndLiftImpls! { +TrivialTypeFoldableAndLiftImpls! { ErrorHandled, } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index c405170aacf6c..340b151a8ccee 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -742,7 +742,7 @@ pub enum ImplicitSelfKind { None, } -CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, } +TrivialTypeFoldableAndLiftImpls! { BindingForm<'tcx>, } mod binding_form_impl { use crate::ich::StableHashingContext; @@ -2452,29 +2452,14 @@ impl UserTypeProjection { } } -CloneTypeFoldableAndLiftImpls! { ProjectionKind, } +TrivialTypeFoldableAndLiftImpls! { ProjectionKind, } impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection { fn super_fold_with>(self, folder: &mut F) -> Self { - use crate::mir::ProjectionElem::*; - - let base = self.base.fold_with(folder); - let projs: Vec<_> = self - .projs - .iter() - .map(|&elem| match elem { - Deref => Deref, - Field(f, ()) => Field(f, ()), - Index(()) => Index(()), - Downcast(symbol, variantidx) => Downcast(symbol, variantidx), - ConstantIndex { offset, min_length, from_end } => { - ConstantIndex { offset, min_length, from_end } - } - Subslice { from, to, from_end } => Subslice { from, to, from_end }, - }) - .collect(); - - UserTypeProjection { base, projs } + UserTypeProjection { + base: self.base.fold_with(folder), + projs: self.projs.fold_with(folder), + } } fn super_visit_with>(&self, visitor: &mut Vs) -> ControlFlow<()> { diff --git a/compiler/rustc_middle/src/mir/predecessors.rs b/compiler/rustc_middle/src/mir/predecessors.rs index a8b748833556d..fd6bb76dc4384 100644 --- a/compiler/rustc_middle/src/mir/predecessors.rs +++ b/compiler/rustc_middle/src/mir/predecessors.rs @@ -75,6 +75,6 @@ impl HashStable for PredecessorCache { } } -CloneTypeFoldableAndLiftImpls! { +TrivialTypeFoldableAndLiftImpls! { PredecessorCache, } diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 9c66d681ffa90..dca46cb0a99a0 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -4,7 +4,7 @@ use super::*; use crate::ty; use rustc_data_structures::functor::IdFunctor; -CloneTypeFoldableAndLiftImpls! { +TrivialTypeFoldableAndLiftImpls! { BlockTailInfo, MirPhase, SourceInfo, @@ -24,7 +24,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { SwitchInt { discr, switch_ty, targets } => SwitchInt { discr: discr.fold_with(folder), switch_ty: switch_ty.fold_with(folder), - targets: targets.clone(), + targets, }, Drop { place, target, unwind } => { Drop { place: place.fold_with(folder), target, unwind } @@ -42,7 +42,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { drop, }, Call { func, args, destination, cleanup, from_hir_call, fn_span } => { - let dest = destination.as_ref().map(|&(loc, dest)| (loc.fold_with(folder), dest)); + let dest = destination.map(|(loc, dest)| (loc.fold_with(folder), dest)); Call { func: func.fold_with(folder), @@ -63,7 +63,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> { OverflowNeg(op) => OverflowNeg(op.fold_with(folder)), DivisionByZero(op) => DivisionByZero(op.fold_with(folder)), RemainderByZero(op) => RemainderByZero(op.fold_with(folder)), - ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg.clone(), + ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg, }; Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup } } @@ -162,8 +162,7 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn super_fold_with>(self, folder: &mut F) -> Self { - let v = self.iter().map(|t| t.fold_with(folder)).collect::>(); - folder.tcx().intern_place_elems(&v) + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -322,7 +321,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal { impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix { fn super_fold_with>(self, _: &mut F) -> Self { - self.clone() + self } fn super_visit_with>(&self, _: &mut V) -> ControlFlow<()> { ControlFlow::CONTINUE diff --git a/compiler/rustc_middle/src/traits/structural_impls.rs b/compiler/rustc_middle/src/traits/structural_impls.rs index b8f6675b8e219..194e275496e95 100644 --- a/compiler/rustc_middle/src/traits/structural_impls.rs +++ b/compiler/rustc_middle/src/traits/structural_impls.rs @@ -105,7 +105,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx, /////////////////////////////////////////////////////////////////////////// // Lift implementations -CloneTypeFoldableAndLiftImpls! { +TrivialTypeFoldableAndLiftImpls! { super::IfExpressionCause, super::ImplSourceDiscriminantKindData, } diff --git a/compiler/rustc_middle/src/ty/binding.rs b/compiler/rustc_middle/src/ty/binding.rs index 3237147c8ba2f..7ab192daf4b1d 100644 --- a/compiler/rustc_middle/src/ty/binding.rs +++ b/compiler/rustc_middle/src/ty/binding.rs @@ -8,7 +8,7 @@ pub enum BindingMode { BindByValue(Mutability), } -CloneTypeFoldableAndLiftImpls! { BindingMode, } +TrivialTypeFoldableAndLiftImpls! { BindingMode, } impl BindingMode { pub fn convert(ba: BindingAnnotation) -> BindingMode { diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index afafc6f2a07c8..fdadc00dc395a 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -13,7 +13,6 @@ use rustc_hir::def::Namespace; use rustc_hir::def_id::CRATE_DEF_INDEX; use rustc_index::vec::{Idx, IndexVec}; -use smallvec::SmallVec; use std::fmt; use std::ops::ControlFlow; use std::rc::Rc; @@ -275,7 +274,7 @@ impl fmt::Debug for ty::PredicateAtom<'tcx> { // For things that don't carry any arena-allocated data (and are // copy...), just add them to this list. -CloneTypeFoldableAndLiftImpls! { +TrivialTypeFoldableAndLiftImpls! { (), bool, usize, @@ -846,7 +845,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn super_fold_with>(self, folder: &mut F) -> Self { - fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -856,7 +855,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn super_fold_with>(self, folder: &mut F) -> Self { - fold_list(self, folder, |tcx, v| tcx.intern_type_list(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -866,7 +865,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List { fn super_fold_with>(self, folder: &mut F) -> Self { - fold_list(self, folder, |tcx, v| tcx.intern_projs(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -928,25 +927,25 @@ impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> { impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { fn super_fold_with>(self, folder: &mut F) -> Self { - let kind = match self.kind() { + let kind = match *self.kind() { ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)), ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)), ty::Slice(typ) => ty::Slice(typ.fold_with(folder)), - ty::Adt(tid, substs) => ty::Adt(*tid, substs.fold_with(folder)), - ty::Dynamic(ref trait_ty, ref region) => { + ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)), + ty::Dynamic(trait_ty, region) => { ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder)) } ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)), - ty::FnDef(def_id, substs) => ty::FnDef(*def_id, substs.fold_with(folder)), + ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.fold_with(folder)), ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)), - ty::Ref(ref r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), *mutbl), + ty::Ref(r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl), ty::Generator(did, substs, movability) => { - ty::Generator(*did, substs.fold_with(folder), *movability) + ty::Generator(did, substs.fold_with(folder), movability) } ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)), - ty::Closure(did, substs) => ty::Closure(*did, substs.fold_with(folder)), - ty::Projection(ref data) => ty::Projection(data.fold_with(folder)), - ty::Opaque(did, substs) => ty::Opaque(*did, substs.fold_with(folder)), + ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)), + ty::Projection(data) => ty::Projection(data.fold_with(folder)), + ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)), ty::Bool | ty::Char @@ -1060,7 +1059,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> { impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { fn super_fold_with>(self, folder: &mut F) -> Self { - fold_list(self, folder, |tcx, v| tcx.intern_predicates(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v)) } fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow<()> { @@ -1140,34 +1139,3 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> { ControlFlow::CONTINUE } } - -// Does the equivalent of -// ``` -// let v = self.iter().map(|p| p.fold_with(folder)).collect::>(); -// folder.tcx().intern_*(&v) -// ``` -fn fold_list<'tcx, F, T>( - list: &'tcx ty::List, - folder: &mut F, - intern: impl FnOnce(TyCtxt<'tcx>, &[T]) -> &'tcx ty::List, -) -> &'tcx ty::List -where - F: TypeFolder<'tcx>, - T: TypeFoldable<'tcx> + PartialEq + Copy, -{ - let mut iter = list.iter(); - // Look for the first element that changed - if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| { - let new_t = t.fold_with(folder); - if new_t == t { None } else { Some((i, new_t)) } - }) { - // An element changed, prepare to intern the resulting list - let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len()); - new_list.extend_from_slice(&list[..i]); - new_list.push(new_t); - new_list.extend(iter.map(|t| t.fold_with(folder))); - intern(folder.tcx(), &new_list) - } else { - list - } -} diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 6e12694f5a61f..e23c3f5196709 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1130,6 +1130,37 @@ pub fn needs_drop_components( } } +// Does the equivalent of +// ``` +// let v = self.iter().map(|p| p.fold_with(folder)).collect::>(); +// folder.tcx().intern_*(&v) +// ``` +pub fn fold_list<'tcx, F, T>( + list: &'tcx ty::List, + folder: &mut F, + intern: impl FnOnce(TyCtxt<'tcx>, &[T]) -> &'tcx ty::List, +) -> &'tcx ty::List +where + F: TypeFolder<'tcx>, + T: TypeFoldable<'tcx> + PartialEq + Copy, +{ + let mut iter = list.iter(); + // Look for the first element that changed + if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| { + let new_t = t.fold_with(folder); + if new_t == t { None } else { Some((i, new_t)) } + }) { + // An element changed, prepare to intern the resulting list + let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len()); + new_list.extend_from_slice(&list[..i]); + new_list.push(new_t); + new_list.extend(iter.map(|t| t.fold_with(folder))); + intern(folder.tcx(), &new_list) + } else { + list + } +} + #[derive(Copy, Clone, Debug, HashStable, TyEncodable, TyDecodable)] pub struct AlwaysRequiresDrop; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 11c99c7a18470..d429d889fcc15 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -671,9 +671,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { } } - OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => { - let found_trait_ref = self.resolve_vars_if_possible(*found_trait_ref); - let expected_trait_ref = self.resolve_vars_if_possible(*expected_trait_ref); + OutputTypeParameterMismatch(found_trait_ref, expected_trait_ref, _) => { + let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref); + let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref); if expected_trait_ref.self_ty().references_error() { return; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index de700e4a422ef..dead795c6afe7 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -365,7 +365,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { } } - ty::Projection(ref data) if !data.has_escaping_bound_vars() => { + ty::Projection(data) if !data.has_escaping_bound_vars() => { // This is kind of hacky -- we need to be able to // handle normalization within binders because // otherwise we wind up a need to normalize when doing @@ -381,7 +381,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { let normalized_ty = normalize_projection_type( self.selcx, self.param_env, - *data, + data, self.cause.clone(), self.depth, &mut self.obligations, diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index caafd0c5035eb..f05582f061429 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -43,7 +43,7 @@ impl<'cx, 'tcx> AtExt<'tcx> for At<'cx, 'tcx> { let c_ty = self.infcx.canonicalize_query(self.param_env.and(ty), &mut orig_values); let span = self.cause.span; debug!("c_ty = {:?}", c_ty); - if let Ok(result) = &tcx.dropck_outlives(c_ty) { + if let Ok(result) = tcx.dropck_outlives(c_ty) { if result.is_proven() { if let Ok(InferOk { value, obligations }) = self.infcx.instantiate_query_response_and_region_obligations( diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 58ab109c491b0..873d300a5e309 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -145,7 +145,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { } } - ty::Projection(ref data) if !data.has_escaping_bound_vars() => { + ty::Projection(data) if !data.has_escaping_bound_vars() => { // This is kind of hacky -- we need to be able to // handle normalization within binders because // otherwise we wind up a need to normalize when doing @@ -165,7 +165,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // so we cannot canonicalize it. let c_data = self .infcx - .canonicalize_hr_query_hack(self.param_env.and(*data), &mut orig_values); + .canonicalize_hr_query_hack(self.param_env.and(data), &mut orig_values); debug!("QueryNormalizer: c_data = {:#?}", c_data); debug!("QueryNormalizer: orig_values = {:#?}", orig_values); match tcx.normalize_projection_ty(c_data) { @@ -180,7 +180,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { self.cause, self.param_env, &orig_values, - &result, + result, ) { Ok(InferOk { value: result, obligations }) => { debug!("QueryNormalizer: result = {:#?}", result); diff --git a/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs index 8896d0a456940..f5fa52c915d90 100644 --- a/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs @@ -68,7 +68,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { &ObligationCause::misc(span, body_id), param_env, &orig_values, - &result, + result, ); debug!("implied_outlives_bounds for {:?}: {:#?}", ty, result); let result = match result { diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs index e90f61322933f..130ffa1a33aeb 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs @@ -81,16 +81,14 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx { // like the subtype query, which go awry around // `'static` otherwise. let mut canonical_var_values = OriginalQueryValues::default(); - let canonical_self = - infcx.canonicalize_hr_query_hack(query_key.clone(), &mut canonical_var_values); + let old_param_env = query_key.param_env; + let canonical_self = infcx.canonicalize_hr_query_hack(query_key, &mut canonical_var_values); let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?; - let param_env = query_key.param_env; - let InferOk { value, obligations } = infcx .instantiate_nll_query_response_and_region_obligations( &ObligationCause::dummy(), - param_env, + old_param_env, &canonical_var_values, canonical_result, output_query_region_constraints, diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index ed8e4aafb9965..478f8a16169ed 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -1393,18 +1393,19 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // Determine exactly which obligation wasn't met, so // that we can give more context in the error. if !self.predicate_may_hold(obligation) { - let o = - self.resolve_vars_if_possible(obligation.clone()); + let nested_predicate = + self.resolve_vars_if_possible(obligation.predicate); let predicate = self.resolve_vars_if_possible(predicate); - let p = if predicate == o.predicate { + let p = if predicate == nested_predicate { // Avoid "`MyStruct: Foo` which is required by // `MyStruct: Foo`" in E0599. None } else { Some(predicate) }; - possibly_unsatisfied_predicates.push((o.predicate, p)); + possibly_unsatisfied_predicates + .push((nested_predicate, p)); } } }