Skip to content

Commit 71b45b9

Browse files
committed
change skip_binder to use T by value
1 parent 1d7ba5f commit 71b45b9

File tree

36 files changed

+78
-83
lines changed

36 files changed

+78
-83
lines changed

src/librustc_infer/infer/canonical/query_response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
302302
// Screen out `'a: 'a` cases -- we skip the binder here but
303303
// only compare the inner values to one another, so they are still at
304304
// consistent binding levels.
305-
let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder();
305+
let ty::OutlivesPredicate(k1, r2) = r_c.skip_binder();
306306
if k1 != r2.into() { Some(r_c) } else { None }
307307
}),
308308
);
@@ -526,7 +526,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
526526
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
527527
unsubstituted_region_constraints.iter().map(move |constraint| {
528528
let constraint = substitute_value(self.tcx, result_subst, constraint);
529-
let &ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
529+
let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
530530

531531
Obligation::new(
532532
cause.clone(),

src/librustc_infer/infer/combine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
496496
where
497497
T: Relate<'tcx>,
498498
{
499-
Ok(ty::Binder::bind(self.relate(*a.skip_binder(), *b.skip_binder())?))
499+
Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
500500
}
501501

502502
fn relate_item_substs(

src/librustc_infer/infer/equate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl TypeRelation<'tcx> for Equate<'combine, 'infcx, 'tcx> {
135135
self.fields.higher_ranked_sub(b, a, self.a_is_expected)
136136
} else {
137137
// Fast path for the common case.
138-
self.relate(*a.skip_binder(), *b.skip_binder())?;
138+
self.relate(a.skip_binder(), b.skip_binder())?;
139139
Ok(a)
140140
}
141141
}

src/librustc_infer/infer/nll_relate/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ where
159159
}
160160
}
161161

162-
// FIXME: consider taking `ty::Binder` directly, without the reference.
163162
fn create_scope(
164163
&mut self,
165-
value: &ty::Binder<impl TypeFoldable<'tcx>>,
164+
value: ty::Binder<impl Relate<'tcx>>,
166165
universally_quantified: UniversallyQuantified,
167166
) -> BoundRegionScope<'tcx> {
168167
let mut scope = BoundRegionScope::default();
@@ -654,8 +653,8 @@ where
654653
// instantiation of B (i.e., B instantiated with
655654
// universals).
656655

657-
let b_scope = self.create_scope(&b, UniversallyQuantified(true));
658-
let a_scope = self.create_scope(&a, UniversallyQuantified(false));
656+
let b_scope = self.create_scope(b, UniversallyQuantified(true));
657+
let a_scope = self.create_scope(a, UniversallyQuantified(false));
659658

660659
debug!("binders: a_scope = {:?} (existential)", a_scope);
661660
debug!("binders: b_scope = {:?} (universal)", b_scope);
@@ -683,7 +682,7 @@ where
683682
// subtyping (i.e., `&'b u32 <: &{P} u32`).
684683
let variance = ::std::mem::replace(&mut self.ambient_variance, ty::Variance::Covariant);
685684

686-
self.relate(*a.skip_binder(), *b.skip_binder())?;
685+
self.relate(a.skip_binder(), b.skip_binder())?;
687686

688687
self.ambient_variance = variance;
689688

@@ -698,8 +697,8 @@ where
698697
// instantiation of B (i.e., B instantiated with
699698
// existentials). Opposite of above.
700699

701-
let a_scope = self.create_scope(&a, UniversallyQuantified(true));
702-
let b_scope = self.create_scope(&b, UniversallyQuantified(false));
700+
let a_scope = self.create_scope(a, UniversallyQuantified(true));
701+
let b_scope = self.create_scope(b, UniversallyQuantified(false));
703702

704703
debug!("binders: a_scope = {:?} (universal)", a_scope);
705704
debug!("binders: b_scope = {:?} (existential)", b_scope);
@@ -712,7 +711,7 @@ where
712711
let variance =
713712
::std::mem::replace(&mut self.ambient_variance, ty::Variance::Contravariant);
714713

715-
self.relate(*a.skip_binder(), *b.skip_binder())?;
714+
self.relate(a.skip_binder(), b.skip_binder())?;
716715

717716
self.ambient_variance = variance;
718717

@@ -1010,7 +1009,7 @@ where
10101009
debug!("TypeGeneralizer::binders(a={:?})", a);
10111010

10121011
self.first_free_index.shift_in(1);
1013-
let result = self.relate(*a.skip_binder(), *a.skip_binder())?;
1012+
let result = self.relate(a.skip_binder(), a.skip_binder())?;
10141013
self.first_free_index.shift_out(1);
10151014
Ok(ty::Binder::bind(result))
10161015
}

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
911911
}
912912
let sig = cx.tables().node_type(expr.hir_id).fn_sig(cx.tcx);
913913
let from = sig.inputs().skip_binder()[0];
914-
let to = *sig.output().skip_binder();
914+
let to = sig.output().skip_binder();
915915
return Some((from, to));
916916
}
917917
None

src/librustc_middle/ich/impls_ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ where
123123
T: HashStable<StableHashingContext<'a>>,
124124
{
125125
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
126-
self.skip_binder().hash_stable(hcx, hasher);
126+
self.as_ref().skip_binder().hash_stable(hcx, hasher);
127127
}
128128
}
129129

src/librustc_middle/ty/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ impl TypeRelation<'tcx> for Match<'tcx> {
118118
where
119119
T: Relate<'tcx>,
120120
{
121-
Ok(ty::Binder::bind(self.relate(*a.skip_binder(), *b.skip_binder())?))
121+
Ok(ty::Binder::bind(self.relate(a.skip_binder(), b.skip_binder())?))
122122
}
123123
}

src/librustc_middle/ty/flags.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ impl FlagComputation {
8888
self.add_substs(substs);
8989
}
9090

91-
&ty::GeneratorWitness(ref ts) => {
91+
&ty::GeneratorWitness(ts) => {
9292
let mut computation = FlagComputation::new();
93-
computation.add_tys(&ts.skip_binder()[..]);
93+
computation.add_tys(ts.skip_binder());
9494
self.add_bound_computation(computation);
9595
}
9696

97-
&ty::Closure(_, ref substs) => {
97+
&ty::Closure(_, substs) => {
9898
self.add_substs(substs);
9999
}
100100

@@ -122,7 +122,7 @@ impl FlagComputation {
122122
self.add_substs(substs);
123123
}
124124

125-
&ty::Projection(ref data) => {
125+
&ty::Projection(data) => {
126126
self.add_flags(TypeFlags::HAS_TY_PROJECTION);
127127
self.add_projection_ty(data);
128128
}
@@ -211,7 +211,7 @@ impl FlagComputation {
211211

212212
self.add_bound_computation(computation);
213213
}
214-
ty::PredicateKind::Projection(projection) => {
214+
&ty::PredicateKind::Projection(projection) => {
215215
let mut computation = FlagComputation::new();
216216
let ty::ProjectionPredicate { projection_ty, ty } = projection.skip_binder();
217217
computation.add_projection_ty(projection_ty);
@@ -298,7 +298,7 @@ impl FlagComputation {
298298
self.add_ty(projection.ty);
299299
}
300300

301-
fn add_projection_ty(&mut self, projection_ty: &ty::ProjectionTy<'_>) {
301+
fn add_projection_ty(&mut self, projection_ty: ty::ProjectionTy<'_>) {
302302
self.add_substs(projection_ty.substs);
303303
}
304304

src/librustc_middle/ty/fold.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl<'tcx> TyCtxt<'tcx> {
336336
{
337337
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
338338
self.outer_index.shift_in(1);
339-
let result = t.skip_binder().visit_with(self);
339+
let result = t.as_ref().skip_binder().visit_with(self);
340340
self.outer_index.shift_out(1);
341341
result
342342
}
@@ -558,7 +558,7 @@ impl<'tcx> TyCtxt<'tcx> {
558558
let fld_c = |bound_ct, ty| {
559559
self.mk_const(ty::Const { val: ty::ConstKind::Bound(ty::INNERMOST, bound_ct), ty })
560560
};
561-
self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c)
561+
self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c)
562562
}
563563

564564
/// Replaces all escaping bound vars. The `fld_r` closure replaces escaping
@@ -617,7 +617,7 @@ impl<'tcx> TyCtxt<'tcx> {
617617
H: FnMut(ty::BoundVar, Ty<'tcx>) -> &'tcx ty::Const<'tcx>,
618618
T: TypeFoldable<'tcx>,
619619
{
620-
self.replace_escaping_bound_vars(value.skip_binder(), fld_r, fld_t, fld_c)
620+
self.replace_escaping_bound_vars(value.as_ref().skip_binder(), fld_r, fld_t, fld_c)
621621
}
622622

623623
/// Replaces any late-bound regions bound in `value` with
@@ -673,7 +673,7 @@ impl<'tcx> TyCtxt<'tcx> {
673673
T: TypeFoldable<'tcx>,
674674
{
675675
let mut collector = LateBoundRegionsCollector::new(just_constraint);
676-
let result = value.skip_binder().visit_with(&mut collector);
676+
let result = value.as_ref().skip_binder().visit_with(&mut collector);
677677
assert!(!result); // should never have stopped early
678678
collector.regions
679679
}

src/librustc_middle/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ impl<'tcx> ty::Instance<'tcx> {
23032303

23042304
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
23052305
sig.map_bound(|sig| tcx.mk_fn_sig(
2306-
iter::once(*env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
2306+
iter::once(env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
23072307
sig.output(),
23082308
sig.c_variadic,
23092309
sig.unsafety,

src/librustc_middle/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub trait PrettyPrinter<'tcx>:
189189
where
190190
T: Print<'tcx, Self, Output = Self, Error = Self::Error> + TypeFoldable<'tcx>,
191191
{
192-
value.skip_binder().print(self)
192+
value.as_ref().skip_binder().print(self)
193193
}
194194

195195
/// Prints comma-separated elements.

src/librustc_middle/ty/structural_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
514514
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for ty::Binder<T> {
515515
type Lifted = ty::Binder<T::Lifted>;
516516
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
517-
tcx.lift(self.skip_binder()).map(ty::Binder::bind)
517+
tcx.lift(self.as_ref().skip_binder()).map(ty::Binder::bind)
518518
}
519519
}
520520

@@ -798,7 +798,7 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
798798
}
799799

800800
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
801-
self.skip_binder().visit_with(visitor)
801+
self.as_ref().skip_binder().visit_with(visitor)
802802
}
803803

804804
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {

src/librustc_middle/ty/sty.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'tcx> ExistentialPredicate<'tcx> {
615615
impl<'tcx> Binder<ExistentialPredicate<'tcx>> {
616616
pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> {
617617
use crate::ty::ToPredicate;
618-
match *self.skip_binder() {
618+
match self.skip_binder() {
619619
ExistentialPredicate::Trait(tr) => {
620620
Binder(tr).with_self_ty(tcx, self_ty).without_const().to_predicate(tcx)
621621
}
@@ -776,7 +776,7 @@ impl<'tcx> PolyTraitRef<'tcx> {
776776

777777
pub fn to_poly_trait_predicate(&self) -> ty::PolyTraitPredicate<'tcx> {
778778
// Note that we preserve binding levels
779-
Binder(ty::TraitPredicate { trait_ref: *self.skip_binder() })
779+
Binder(ty::TraitPredicate { trait_ref: self.skip_binder() })
780780
}
781781
}
782782

@@ -880,8 +880,8 @@ impl<T> Binder<T> {
880880
/// - extracting the `DefId` from a PolyTraitRef;
881881
/// - comparing the self type of a PolyTraitRef to see if it is equal to
882882
/// a type parameter `X`, since the type `X` does not reference any regions
883-
pub fn skip_binder(&self) -> &T {
884-
&self.0
883+
pub fn skip_binder(self) -> T {
884+
self.0
885885
}
886886

887887
pub fn as_ref(&self) -> Binder<&T> {
@@ -916,11 +916,7 @@ impl<T> Binder<T> {
916916
where
917917
T: TypeFoldable<'tcx>,
918918
{
919-
if self.skip_binder().has_escaping_bound_vars() {
920-
None
921-
} else {
922-
Some(self.skip_binder().clone())
923-
}
919+
if self.0.has_escaping_bound_vars() { None } else { Some(self.skip_binder()) }
924920
}
925921

926922
/// Given two things that have the same binder level,
@@ -997,7 +993,7 @@ impl<'tcx> ProjectionTy<'tcx> {
997993
}
998994
}
999995

1000-
#[derive(Clone, Debug, TypeFoldable)]
996+
#[derive(Copy, Clone, Debug, TypeFoldable)]
1001997
pub struct GenSig<'tcx> {
1002998
pub resume_ty: Ty<'tcx>,
1003999
pub yield_ty: Ty<'tcx>,

src/librustc_middle/ty/walk.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
133133
ty::Dynamic(obj, lt) => {
134134
stack.push(lt.into());
135135
stack.extend(obj.iter().rev().flat_map(|predicate| {
136-
let (substs, opt_ty) = match *predicate.skip_binder() {
136+
let (substs, opt_ty) = match predicate.skip_binder() {
137137
ty::ExistentialPredicate::Trait(tr) => (tr.substs, None),
138138
ty::ExistentialPredicate::Projection(p) => (p.substs, Some(p.ty)),
139139
ty::ExistentialPredicate::AutoTrait(_) =>

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19231923

19241924
// We use a mix of the HIR and the Ty types to get information
19251925
// as the HIR doesn't have full types for closure arguments.
1926-
let return_ty = *sig.output().skip_binder();
1926+
let return_ty = sig.output().skip_binder();
19271927
let mut return_span = fn_decl.output.span();
19281928
if let hir::FnRetTy::Return(ty) = &fn_decl.output {
19291929
if let hir::TyKind::Rptr(lifetime, _) = ty.kind {
@@ -1965,7 +1965,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19651965
let argument_ty = sig.inputs().skip_binder().first()?;
19661966

19671967
let return_span = fn_decl.output.span();
1968-
let return_ty = *sig.output().skip_binder();
1968+
let return_ty = sig.output().skip_binder();
19691969

19701970
// We expect the first argument to be a reference.
19711971
match argument_ty.kind {

src/librustc_passes/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl Visitor<'tcx> for ExprVisitor<'tcx> {
422422
let typ = self.tables.node_type(expr.hir_id);
423423
let sig = typ.fn_sig(self.tcx);
424424
let from = sig.inputs().skip_binder()[0];
425-
let to = *sig.output().skip_binder();
425+
let to = sig.output().skip_binder();
426426
self.check_transmute(expr.span, from, to);
427427
}
428428
}

src/librustc_privacy/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ where
9292
for (predicate, _span) in predicates {
9393
match predicate.kind() {
9494
ty::PredicateKind::Trait(poly_predicate, _) => {
95-
let ty::TraitPredicate { trait_ref } = *poly_predicate.skip_binder();
95+
let ty::TraitPredicate { trait_ref } = poly_predicate.skip_binder();
9696
if self.visit_trait(trait_ref) {
9797
return true;
9898
}
9999
}
100100
ty::PredicateKind::Projection(poly_predicate) => {
101101
let ty::ProjectionPredicate { projection_ty, ty } =
102-
*poly_predicate.skip_binder();
102+
poly_predicate.skip_binder();
103103
if ty.visit_with(self) {
104104
return true;
105105
}
@@ -108,7 +108,7 @@ where
108108
}
109109
}
110110
ty::PredicateKind::TypeOutlives(poly_predicate) => {
111-
let ty::OutlivesPredicate(ty, _region) = *poly_predicate.skip_binder();
111+
let ty::OutlivesPredicate(ty, _region) = poly_predicate.skip_binder();
112112
if ty.visit_with(self) {
113113
return true;
114114
}
@@ -175,7 +175,7 @@ where
175175
ty::Dynamic(predicates, ..) => {
176176
// All traits in the list are considered the "primary" part of the type
177177
// and are visited by shallow visitors.
178-
for predicate in *predicates.skip_binder() {
178+
for predicate in predicates.skip_binder() {
179179
let trait_ref = match predicate {
180180
ty::ExistentialPredicate::Trait(trait_ref) => trait_ref,
181181
ty::ExistentialPredicate::Projection(proj) => proj.trait_ref(tcx),
@@ -1270,7 +1270,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
12701270
);
12711271

12721272
for (trait_predicate, _, _) in bounds.trait_bounds {
1273-
if self.visit_trait(*trait_predicate.skip_binder()) {
1273+
if self.visit_trait(trait_predicate.skip_binder()) {
12741274
return;
12751275
}
12761276
}

src/librustc_symbol_mangling/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl SymbolMangler<'tcx> {
219219
lifetime_depths.end += lifetimes;
220220

221221
self.binders.push(BinderLevel { lifetime_depths });
222-
self = print_value(self, value.skip_binder())?;
222+
self = print_value(self, value.as_ref().skip_binder())?;
223223
self.binders.pop();
224224

225225
Ok(self)

src/librustc_trait_selection/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ where
691691
OP: FnMut(ty::Region<'tcx>),
692692
{
693693
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> bool {
694-
t.skip_binder().visit_with(self);
694+
t.as_ref().skip_binder().visit_with(self);
695695
false // keep visiting
696696
}
697697

src/librustc_trait_selection/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15691569
// no need to overload user in such cases
15701570
return;
15711571
}
1572-
let &SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder();
1572+
let SubtypePredicate { a_is_expected: _, a, b } = data.skip_binder();
15731573
// both must be type variables, or the other would've been instantiated
15741574
assert!(a.is_ty_var() && b.is_ty_var());
15751575
self.need_type_info_err(body_id, span, a, ErrorCode::E0282)

0 commit comments

Comments
 (0)