Skip to content

Commit f6a53b4

Browse files
committed
Review comments
1 parent eba1027 commit f6a53b4

File tree

15 files changed

+34
-31
lines changed

15 files changed

+34
-31
lines changed

compiler/rustc_infer/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Elaborator<'tcx> {
126126
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
127127
let tcx = self.visited.tcx;
128128

129-
let bound_predicate = obligation.predicate.bound_atom(tcx);
129+
let bound_predicate = obligation.predicate.bound_atom();
130130
match bound_predicate.skip_binder() {
131131
ty::PredicateAtom::Trait(data, _) => {
132132
// Get predicates declared on the trait.

compiler/rustc_middle/src/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1058,11 +1058,11 @@ impl<'tcx> Predicate<'tcx> {
10581058

10591059
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
10601060
/// `Atom`, then it is not allowed to contain escaping bound vars.
1061-
pub fn bound_atom(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
1061+
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
10621062
match self.kind() {
10631063
&PredicateKind::ForAll(binder) => binder,
10641064
&PredicateKind::Atom(atom) => {
1065-
assert!(!atom.has_escaping_bound_vars());
1065+
debug_assert!(!atom.has_escaping_bound_vars());
10661066
Binder::dummy(atom)
10671067
}
10681068
}

compiler/rustc_middle/src/ty/sty.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,11 @@ impl<T> Binder<T> {
10061006
/// current `Binder`. This should not be used if the new value *changes*
10071007
/// the bound variables. Note: the (old or new) value itself does not
10081008
/// necessarily need to *name* all the bound variables.
1009+
///
1010+
/// This currently doesn't do anything different than `bind`, because we
1011+
/// don't actually track bound vars. However, semantically, it is different
1012+
/// because bound vars aren't allowed to change here, whereas they are
1013+
/// in `bind`. This may be (debug) asserted in the future.
10091014
pub fn rebind<U>(&self, value: U) -> Binder<U> {
10101015
Binder(value)
10111016
}

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl AutoTraitFinder<'tcx> {
642642
// We check this by calling is_of_param on the relevant types
643643
// from the various possible predicates
644644

645-
let bound_predicate = predicate.bound_atom(select.infcx().tcx);
645+
let bound_predicate = predicate.bound_atom();
646646
match bound_predicate.skip_binder() {
647647
ty::PredicateAtom::Trait(p, _) => {
648648
if self.is_param_no_infer(p.trait_ref.substs)

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
255255
return;
256256
}
257257

258-
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
258+
let bound_predicate = obligation.predicate.bound_atom();
259259
match bound_predicate.skip_binder() {
260260
ty::PredicateAtom::Trait(trait_predicate, _) => {
261261
let trait_predicate = bound_predicate.rebind(trait_predicate);
@@ -1079,7 +1079,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
10791079
}
10801080

10811081
// FIXME: It should be possible to deal with `ForAll` in a cleaner way.
1082-
let bound_error = error.bound_atom(self.tcx);
1082+
let bound_error = error.bound_atom();
10831083
let (cond, error) = match (cond.skip_binders(), bound_error.skip_binder()) {
10841084
(ty::PredicateAtom::Trait(..), ty::PredicateAtom::Trait(error, _)) => {
10851085
(cond, bound_error.rebind(error))
@@ -1091,7 +1091,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
10911091
};
10921092

10931093
for obligation in super::elaborate_predicates(self.tcx, std::iter::once(cond)) {
1094-
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
1094+
let bound_predicate = obligation.predicate.bound_atom();
10951095
if let ty::PredicateAtom::Trait(implication, _) = bound_predicate.skip_binder() {
10961096
let error = error.to_poly_trait_ref();
10971097
let implication = bound_predicate.rebind(implication.trait_ref);
@@ -1172,7 +1172,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
11721172
//
11731173
// this can fail if the problem was higher-ranked, in which
11741174
// cause I have no idea for a good error message.
1175-
let bound_predicate = predicate.bound_atom(self.tcx);
1175+
let bound_predicate = predicate.bound_atom();
11761176
if let ty::PredicateAtom::Projection(data) = bound_predicate.skip_binder() {
11771177
let mut selcx = SelectionContext::new(self);
11781178
let (data, _) = self.replace_bound_vars_with_fresh_vars(
@@ -1459,7 +1459,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14591459
return;
14601460
}
14611461

1462-
let bound_predicate = predicate.bound_atom(self.tcx);
1462+
let bound_predicate = predicate.bound_atom();
14631463
let mut err = match bound_predicate.skip_binder() {
14641464
ty::PredicateAtom::Trait(data, _) => {
14651465
let self_ty = data.trait_ref.self_ty();

compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ fn prune_cache_value_obligations<'a, 'tcx>(
623623
.obligations
624624
.iter()
625625
.filter(|obligation| {
626-
let bound_predicate = obligation.predicate.bound_atom(infcx.tcx);
626+
let bound_predicate = obligation.predicate.bound_atom();
627627
match bound_predicate.skip_binder() {
628628
// We found a `T: Foo<X = U>` predicate, let's check
629629
// if `U` references any unresolved type
@@ -908,7 +908,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
908908
let infcx = selcx.infcx();
909909
for predicate in env_predicates {
910910
debug!(?predicate);
911-
let bound_predicate = predicate.bound_atom(infcx.tcx);
911+
let bound_predicate = predicate.bound_atom();
912912
if let ty::PredicateAtom::Projection(data) = predicate.skip_binders() {
913913
let data = bound_predicate.rebind(data);
914914
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
449449
}
450450

451451
let result = ensure_sufficient_stack(|| {
452-
let bound_predicate =
453-
obligation.predicate.bound_atom_with_opt_escaping(self.infcx().tcx);
452+
let bound_predicate = obligation.predicate.bound_atom();
454453
match bound_predicate.skip_binder() {
455454
ty::PredicateAtom::Trait(t, _) => {
456455
let t = bound_predicate.rebind(t);
@@ -1176,7 +1175,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11761175
.iter()
11771176
.enumerate()
11781177
.filter_map(|(idx, bound)| {
1179-
let bound_predicate = bound.bound_atom(self.infcx.tcx);
1178+
let bound_predicate = bound.bound_atom();
11801179
if let ty::PredicateAtom::Trait(pred, _) = bound_predicate.skip_binder() {
11811180
let bound = bound_predicate.rebind(pred.trait_ref);
11821181
if self.infcx.probe(|_| {
@@ -1568,7 +1567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15681567

15691568
use self::BuiltinImplConditions::{Ambiguous, None, Where};
15701569

1571-
match self_ty.kind() {
1570+
match *self_ty.kind() {
15721571
ty::Infer(ty::IntVar(_))
15731572
| ty::Infer(ty::FloatVar(_))
15741573
| ty::FnDef(..)
@@ -1597,7 +1596,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15971596

15981597
ty::Array(element_ty, _) => {
15991598
// (*) binder moved here
1600-
Where(obligation.predicate.rebind(vec![*element_ty]))
1599+
Where(obligation.predicate.rebind(vec![element_ty]))
16011600
}
16021601

16031602
ty::Tuple(tys) => {

compiler/rustc_typeck/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10951095
obligation.predicate
10961096
);
10971097

1098-
let bound_predicate = obligation.predicate.bound_atom(tcx);
1098+
let bound_predicate = obligation.predicate.bound_atom();
10991099
match bound_predicate.skip_binder() {
11001100
ty::PredicateAtom::Trait(pred, _) => {
11011101
let pred = bound_predicate.rebind(pred);

compiler/rustc_typeck/src/check/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
192192
obligation.predicate
193193
);
194194

195-
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
195+
let bound_predicate = obligation.predicate.bound_atom();
196196
if let ty::PredicateAtom::Projection(proj_predicate) =
197197
obligation.predicate.skip_binders()
198198
{

compiler/rustc_typeck/src/check/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
583583
while !queue.is_empty() {
584584
let obligation = queue.remove(0);
585585
debug!("coerce_unsized resolve step: {:?}", obligation);
586-
let bound_predicate = obligation.predicate.bound_atom(self.tcx);
586+
let bound_predicate = obligation.predicate.bound_atom();
587587
let trait_pred = match bound_predicate.skip_binder() {
588588
ty::PredicateAtom::Trait(trait_pred, _)
589589
if traits.contains(&trait_pred.def_id()) =>

compiler/rustc_typeck/src/check/dropck.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
226226
// could be extended easily also to the other `Predicate`.
227227
let predicate_matches_closure = |p: Predicate<'tcx>| {
228228
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
229-
let bound_predicate = predicate.bound_atom(tcx);
230-
let bound_p = p.bound_atom(tcx);
231-
match (predicate.skip_binders(), p.skip_binders()) {
229+
let predicate = predicate.bound_atom();
230+
let p = p.bound_atom();
231+
match (predicate.skip_binder(), p.skip_binder()) {
232232
(ty::PredicateAtom::Trait(a, _), ty::PredicateAtom::Trait(b, _)) => {
233-
relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok()
233+
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
234234
}
235235
(ty::PredicateAtom::Projection(a), ty::PredicateAtom::Projection(b)) => {
236-
relator.relate(bound_predicate.rebind(a), bound_p.rebind(b)).is_ok()
236+
relator.relate(predicate.rebind(a), p.rebind(b)).is_ok()
237237
}
238238
_ => predicate == p,
239239
}

compiler/rustc_typeck/src/check/method/probe.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
796796
// FIXME: do we want to commit to this behavior for param bounds?
797797
debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty);
798798

799-
let tcx = self.tcx;
800799
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
801-
let bound_predicate = predicate.bound_atom(tcx);
800+
let bound_predicate = predicate.bound_atom();
802801
match bound_predicate.skip_binder() {
803802
ty::PredicateAtom::Trait(trait_predicate, _) => {
804-
match trait_predicate.trait_ref.self_ty().kind() {
805-
ty::Param(ref p) if *p == param_ty => {
803+
match *trait_predicate.trait_ref.self_ty().kind() {
804+
ty::Param(p) if p == param_ty => {
806805
Some(bound_predicate.rebind(trait_predicate.trait_ref))
807806
}
808807
_ => None,

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
637637
}
638638
};
639639
let mut format_pred = |pred: ty::Predicate<'tcx>| {
640-
let bound_predicate = pred.bound_atom(tcx);
640+
let bound_predicate = pred.bound_atom();
641641
match bound_predicate.skip_binder() {
642642
ty::PredicateAtom::Projection(pred) => {
643643
let pred = bound_predicate.rebind(pred);

compiler/rustc_typeck/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ fn bounds_from_generic_predicates<'tcx>(
850850
let mut projections = vec![];
851851
for (predicate, _) in predicates.predicates {
852852
debug!("predicate {:?}", predicate);
853-
let bound_predicate = predicate.bound_atom(tcx);
853+
let bound_predicate = predicate.bound_atom();
854854
match bound_predicate.skip_binder() {
855855
ty::PredicateAtom::Trait(trait_predicate, _) => {
856856
let entry = types.entry(trait_predicate.self_ty()).or_default();

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
315315
tcx: TyCtxt<'tcx>,
316316
pred: ty::Predicate<'tcx>,
317317
) -> FxHashSet<GenericParamDef> {
318-
let bound_predicate = pred.bound_atom(tcx);
318+
let bound_predicate = pred.bound_atom();
319319
let regions = match bound_predicate.skip_binder() {
320320
ty::PredicateAtom::Trait(poly_trait_pred, _) => {
321321
tcx.collect_referenced_late_bound_regions(&bound_predicate.rebind(poly_trait_pred))

0 commit comments

Comments
 (0)