Skip to content

Commit a6cbd64

Browse files
committed
words
1 parent 80acfea commit a6cbd64

File tree

19 files changed

+87
-105
lines changed

19 files changed

+87
-105
lines changed

compiler/rustc_data_structures/src/functor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<T> IdFunctor for Box<T> {
2222
unsafe {
2323
// SAFETY: The raw pointer points to a valid value of type `T`.
2424
let value = ptr::read(raw);
25-
// SAFETY: Convert's `Box<T>` to `Box<MaybeUninit<T>>` which is the
25+
// SAFETY: Converts `Box<T>` to `Box<MaybeUninit<T>>` which is the
2626
// inverse of `Box::assume_init()` and should be safe.
2727
let mut raw: Box<mem::MaybeUninit<T>> = Box::from_raw(raw.cast());
2828
// SAFETY: Write the mapped value back into the `Box`.

compiler/rustc_infer/src/traits/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
6262
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O> {
6363
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
6464
traits::Obligation {
65-
cause: self.cause.clone(),
65+
cause: self.cause,
6666
recursion_depth: self.recursion_depth,
6767
predicate: self.predicate.fold_with(folder),
6868
param_env: self.param_env.fold_with(folder),

compiler/rustc_middle/src/infer/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ impl<'tcx, V> Canonical<'tcx, V> {
286286
pub type QueryOutlivesConstraint<'tcx> =
287287
ty::Binder<ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>>;
288288

289-
CloneTypeFoldableAndLiftImpls! {
289+
TrivialTypeFoldableAndLiftImpls! {
290290
for <'tcx> {
291291
crate::infer::canonical::Certainty,
292292
crate::infer::canonical::CanonicalVarInfo<'tcx>,
293293
crate::infer::canonical::CanonicalVarKind<'tcx>,
294294
}
295295
}
296296

297-
CloneTypeFoldableImpls! {
297+
TrivialTypeFoldableImpls! {
298298
for <'tcx> {
299299
crate::infer::canonical::CanonicalVarInfos<'tcx>,
300300
}

compiler/rustc_middle/src/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ macro_rules! CloneLiftImpls {
4848
/// Used for types that are `Copy` and which **do not care arena
4949
/// allocated data** (i.e., don't need to be folded).
5050
#[macro_export]
51-
macro_rules! CloneTypeFoldableImpls {
51+
macro_rules! TrivialTypeFoldableImpls {
5252
(for <$tcx:lifetime> { $($ty:ty,)+ }) => {
5353
$(
5454
impl<$tcx> $crate::ty::fold::TypeFoldable<$tcx> for $ty {
@@ -71,7 +71,7 @@ macro_rules! CloneTypeFoldableImpls {
7171
};
7272

7373
($($ty:ty,)+) => {
74-
CloneTypeFoldableImpls! {
74+
TrivialTypeFoldableImpls! {
7575
for <'tcx> {
7676
$($ty,)+
7777
}
@@ -80,9 +80,9 @@ macro_rules! CloneTypeFoldableImpls {
8080
}
8181

8282
#[macro_export]
83-
macro_rules! CloneTypeFoldableAndLiftImpls {
83+
macro_rules! TrivialTypeFoldableAndLiftImpls {
8484
($($t:tt)*) => {
85-
CloneTypeFoldableImpls! { $($t)* }
85+
TrivialTypeFoldableImpls! { $($t)* }
8686
CloneLiftImpls! { $($t)* }
8787
}
8888
}

compiler/rustc_middle/src/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl From<ErrorReported> for ErrorHandled {
2929
}
3030
}
3131

32-
CloneTypeFoldableAndLiftImpls! {
32+
TrivialTypeFoldableAndLiftImpls! {
3333
ErrorHandled,
3434
}
3535

compiler/rustc_middle/src/mir/mod.rs

+6-21
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ pub enum ImplicitSelfKind {
742742
None,
743743
}
744744

745-
CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
745+
TrivialTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
746746

747747
mod binding_form_impl {
748748
use crate::ich::StableHashingContext;
@@ -2452,29 +2452,14 @@ impl UserTypeProjection {
24522452
}
24532453
}
24542454

2455-
CloneTypeFoldableAndLiftImpls! { ProjectionKind, }
2455+
TrivialTypeFoldableAndLiftImpls! { ProjectionKind, }
24562456

24572457
impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection {
24582458
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
2459-
use crate::mir::ProjectionElem::*;
2460-
2461-
let base = self.base.fold_with(folder);
2462-
let projs: Vec<_> = self
2463-
.projs
2464-
.iter()
2465-
.map(|&elem| match elem {
2466-
Deref => Deref,
2467-
Field(f, ()) => Field(f, ()),
2468-
Index(()) => Index(()),
2469-
Downcast(symbol, variantidx) => Downcast(symbol, variantidx),
2470-
ConstantIndex { offset, min_length, from_end } => {
2471-
ConstantIndex { offset, min_length, from_end }
2472-
}
2473-
Subslice { from, to, from_end } => Subslice { from, to, from_end },
2474-
})
2475-
.collect();
2476-
2477-
UserTypeProjection { base, projs }
2459+
UserTypeProjection {
2460+
base: self.base.fold_with(folder),
2461+
projs: self.projs.fold_with(folder),
2462+
}
24782463
}
24792464

24802465
fn super_visit_with<Vs: TypeVisitor<'tcx>>(&self, visitor: &mut Vs) -> ControlFlow<()> {

compiler/rustc_middle/src/mir/predecessors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ impl<CTX> HashStable<CTX> for PredecessorCache {
7575
}
7676
}
7777

78-
CloneTypeFoldableAndLiftImpls! {
78+
TrivialTypeFoldableAndLiftImpls! {
7979
PredecessorCache,
8080
}

compiler/rustc_middle/src/mir/type_foldable.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44
use crate::ty;
55
use rustc_data_structures::functor::IdFunctor;
66

7-
CloneTypeFoldableAndLiftImpls! {
7+
TrivialTypeFoldableAndLiftImpls! {
88
BlockTailInfo,
99
MirPhase,
1010
SourceInfo,
@@ -24,7 +24,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
2424
SwitchInt { discr, switch_ty, targets } => SwitchInt {
2525
discr: discr.fold_with(folder),
2626
switch_ty: switch_ty.fold_with(folder),
27-
targets: targets.clone(),
27+
targets,
2828
},
2929
Drop { place, target, unwind } => {
3030
Drop { place: place.fold_with(folder), target, unwind }
@@ -42,7 +42,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
4242
drop,
4343
},
4444
Call { func, args, destination, cleanup, from_hir_call, fn_span } => {
45-
let dest = destination.as_ref().map(|&(loc, dest)| (loc.fold_with(folder), dest));
45+
let dest = destination.map(|(loc, dest)| (loc.fold_with(folder), dest));
4646

4747
Call {
4848
func: func.fold_with(folder),
@@ -63,7 +63,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
6363
OverflowNeg(op) => OverflowNeg(op.fold_with(folder)),
6464
DivisionByZero(op) => DivisionByZero(op.fold_with(folder)),
6565
RemainderByZero(op) => RemainderByZero(op.fold_with(folder)),
66-
ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg.clone(),
66+
ResumedAfterReturn(_) | ResumedAfterPanic(_) => msg,
6767
};
6868
Assert { cond: cond.fold_with(folder), expected, msg, target, cleanup }
6969
}
@@ -162,8 +162,7 @@ impl<'tcx> TypeFoldable<'tcx> for Place<'tcx> {
162162

163163
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
164164
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
165-
let v = self.iter().map(|t| t.fold_with(folder)).collect::<Vec<_>>();
166-
folder.tcx().intern_place_elems(&v)
165+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v))
167166
}
168167

169168
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@@ -322,7 +321,7 @@ impl<'tcx> TypeFoldable<'tcx> for GeneratorSavedLocal {
322321

323322
impl<'tcx, R: Idx, C: Idx> TypeFoldable<'tcx> for BitMatrix<R, C> {
324323
fn super_fold_with<F: TypeFolder<'tcx>>(self, _: &mut F) -> Self {
325-
self.clone()
324+
self
326325
}
327326
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, _: &mut V) -> ControlFlow<()> {
328327
ControlFlow::CONTINUE

compiler/rustc_middle/src/traits/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSourceTraitAliasData<'tcx,
105105
///////////////////////////////////////////////////////////////////////////
106106
// Lift implementations
107107

108-
CloneTypeFoldableAndLiftImpls! {
108+
TrivialTypeFoldableAndLiftImpls! {
109109
super::IfExpressionCause,
110110
super::ImplSourceDiscriminantKindData,
111111
}

compiler/rustc_middle/src/ty/binding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub enum BindingMode {
88
BindByValue(Mutability),
99
}
1010

11-
CloneTypeFoldableAndLiftImpls! { BindingMode, }
11+
TrivialTypeFoldableAndLiftImpls! { BindingMode, }
1212

1313
impl BindingMode {
1414
pub fn convert(ba: BindingAnnotation) -> BindingMode {

compiler/rustc_middle/src/ty/structural_impls.rs

+14-46
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::def::Namespace;
1313
use rustc_hir::def_id::CRATE_DEF_INDEX;
1414
use rustc_index::vec::{Idx, IndexVec};
1515

16-
use smallvec::SmallVec;
1716
use std::fmt;
1817
use std::ops::ControlFlow;
1918
use std::rc::Rc;
@@ -275,7 +274,7 @@ impl fmt::Debug for ty::PredicateAtom<'tcx> {
275274
// For things that don't carry any arena-allocated data (and are
276275
// copy...), just add them to this list.
277276

278-
CloneTypeFoldableAndLiftImpls! {
277+
TrivialTypeFoldableAndLiftImpls! {
279278
(),
280279
bool,
281280
usize,
@@ -846,7 +845,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
846845

847846
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
848847
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
849-
fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v))
848+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_existential_predicates(v))
850849
}
851850

852851
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@@ -856,7 +855,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>>
856855

857856
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
858857
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
859-
fold_list(self, folder, |tcx, v| tcx.intern_type_list(v))
858+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v))
860859
}
861860

862861
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@@ -866,7 +865,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
866865

867866
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ProjectionKind> {
868867
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
869-
fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
868+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v))
870869
}
871870

872871
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@@ -928,25 +927,25 @@ impl<'tcx> TypeFoldable<'tcx> for interpret::GlobalId<'tcx> {
928927

929928
impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
930929
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
931-
let kind = match self.kind() {
930+
let kind = match *self.kind() {
932931
ty::RawPtr(tm) => ty::RawPtr(tm.fold_with(folder)),
933932
ty::Array(typ, sz) => ty::Array(typ.fold_with(folder), sz.fold_with(folder)),
934933
ty::Slice(typ) => ty::Slice(typ.fold_with(folder)),
935-
ty::Adt(tid, substs) => ty::Adt(*tid, substs.fold_with(folder)),
936-
ty::Dynamic(ref trait_ty, ref region) => {
934+
ty::Adt(tid, substs) => ty::Adt(tid, substs.fold_with(folder)),
935+
ty::Dynamic(trait_ty, region) => {
937936
ty::Dynamic(trait_ty.fold_with(folder), region.fold_with(folder))
938937
}
939938
ty::Tuple(ts) => ty::Tuple(ts.fold_with(folder)),
940-
ty::FnDef(def_id, substs) => ty::FnDef(*def_id, substs.fold_with(folder)),
939+
ty::FnDef(def_id, substs) => ty::FnDef(def_id, substs.fold_with(folder)),
941940
ty::FnPtr(f) => ty::FnPtr(f.fold_with(folder)),
942-
ty::Ref(ref r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), *mutbl),
941+
ty::Ref(r, ty, mutbl) => ty::Ref(r.fold_with(folder), ty.fold_with(folder), mutbl),
943942
ty::Generator(did, substs, movability) => {
944-
ty::Generator(*did, substs.fold_with(folder), *movability)
943+
ty::Generator(did, substs.fold_with(folder), movability)
945944
}
946945
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
947-
ty::Closure(did, substs) => ty::Closure(*did, substs.fold_with(folder)),
948-
ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
949-
ty::Opaque(did, substs) => ty::Opaque(*did, substs.fold_with(folder)),
946+
ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
947+
ty::Projection(data) => ty::Projection(data.fold_with(folder)),
948+
ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
950949

951950
ty::Bool
952951
| ty::Char
@@ -1060,7 +1059,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
10601059

10611060
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
10621061
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
1063-
fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
1062+
ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v))
10641063
}
10651064

10661065
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<()> {
@@ -1140,34 +1139,3 @@ impl<'tcx> TypeFoldable<'tcx> for InferConst<'tcx> {
11401139
ControlFlow::CONTINUE
11411140
}
11421141
}
1143-
1144-
// Does the equivalent of
1145-
// ```
1146-
// let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1147-
// folder.tcx().intern_*(&v)
1148-
// ```
1149-
fn fold_list<'tcx, F, T>(
1150-
list: &'tcx ty::List<T>,
1151-
folder: &mut F,
1152-
intern: impl FnOnce(TyCtxt<'tcx>, &[T]) -> &'tcx ty::List<T>,
1153-
) -> &'tcx ty::List<T>
1154-
where
1155-
F: TypeFolder<'tcx>,
1156-
T: TypeFoldable<'tcx> + PartialEq + Copy,
1157-
{
1158-
let mut iter = list.iter();
1159-
// Look for the first element that changed
1160-
if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| {
1161-
let new_t = t.fold_with(folder);
1162-
if new_t == t { None } else { Some((i, new_t)) }
1163-
}) {
1164-
// An element changed, prepare to intern the resulting list
1165-
let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len());
1166-
new_list.extend_from_slice(&list[..i]);
1167-
new_list.push(new_t);
1168-
new_list.extend(iter.map(|t| t.fold_with(folder)));
1169-
intern(folder.tcx(), &new_list)
1170-
} else {
1171-
list
1172-
}
1173-
}

compiler/rustc_middle/src/ty/util.rs

+31
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,37 @@ pub fn needs_drop_components(
11301130
}
11311131
}
11321132

1133+
// Does the equivalent of
1134+
// ```
1135+
// let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1136+
// folder.tcx().intern_*(&v)
1137+
// ```
1138+
pub fn fold_list<'tcx, F, T>(
1139+
list: &'tcx ty::List<T>,
1140+
folder: &mut F,
1141+
intern: impl FnOnce(TyCtxt<'tcx>, &[T]) -> &'tcx ty::List<T>,
1142+
) -> &'tcx ty::List<T>
1143+
where
1144+
F: TypeFolder<'tcx>,
1145+
T: TypeFoldable<'tcx> + PartialEq + Copy,
1146+
{
1147+
let mut iter = list.iter();
1148+
// Look for the first element that changed
1149+
if let Some((i, new_t)) = iter.by_ref().enumerate().find_map(|(i, t)| {
1150+
let new_t = t.fold_with(folder);
1151+
if new_t == t { None } else { Some((i, new_t)) }
1152+
}) {
1153+
// An element changed, prepare to intern the resulting list
1154+
let mut new_list = SmallVec::<[_; 8]>::with_capacity(list.len());
1155+
new_list.extend_from_slice(&list[..i]);
1156+
new_list.push(new_t);
1157+
new_list.extend(iter.map(|t| t.fold_with(folder)));
1158+
intern(folder.tcx(), &new_list)
1159+
} else {
1160+
list
1161+
}
1162+
}
1163+
11331164
#[derive(Copy, Clone, Debug, HashStable, TyEncodable, TyDecodable)]
11341165
pub struct AlwaysRequiresDrop;
11351166

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
671671
}
672672
}
673673

674-
OutputTypeParameterMismatch(ref found_trait_ref, ref expected_trait_ref, _) => {
675-
let found_trait_ref = self.resolve_vars_if_possible(*found_trait_ref);
676-
let expected_trait_ref = self.resolve_vars_if_possible(*expected_trait_ref);
674+
OutputTypeParameterMismatch(found_trait_ref, expected_trait_ref, _) => {
675+
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
676+
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
677677

678678
if expected_trait_ref.self_ty().references_error() {
679679
return;

compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
365365
}
366366
}
367367

368-
ty::Projection(ref data) if !data.has_escaping_bound_vars() => {
368+
ty::Projection(data) if !data.has_escaping_bound_vars() => {
369369
// This is kind of hacky -- we need to be able to
370370
// handle normalization within binders because
371371
// 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> {
381381
let normalized_ty = normalize_projection_type(
382382
self.selcx,
383383
self.param_env,
384-
*data,
384+
data,
385385
self.cause.clone(),
386386
self.depth,
387387
&mut self.obligations,

0 commit comments

Comments
 (0)