Skip to content

Commit 654b7b5

Browse files
committed
increment depth of nested obligations
1 parent 0b45675 commit 654b7b5

15 files changed

+70
-72
lines changed

compiler/rustc_trait_selection/src/traits/effects.rs

-8
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ fn match_candidate<'tcx>(
106106

107107
more_nested(selcx, &mut nested);
108108

109-
for nested in &mut nested {
110-
nested.set_depth_from_parent(obligation.recursion_depth);
111-
}
112-
113109
Ok(nested)
114110
}
115111

@@ -378,10 +374,6 @@ fn evaluate_host_effect_from_selection_candiate<'tcx>(
378374
}),
379375
);
380376

381-
for nested in &mut nested {
382-
nested.set_depth_from_parent(obligation.recursion_depth);
383-
}
384-
385377
Ok(nested)
386378
}
387379
_ => Err(EvaluationFailure::NoSolution),

compiler/rustc_trait_selection/src/traits/fulfill.rs

+36-20
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,15 @@ struct FulfillProcessor<'a, 'tcx> {
225225
selcx: SelectionContext<'a, 'tcx>,
226226
}
227227

228-
fn mk_pending<'tcx>(os: PredicateObligations<'tcx>) -> PendingPredicateObligations<'tcx> {
228+
fn mk_pending<'tcx>(
229+
parent: &PredicateObligation<'tcx>,
230+
os: PredicateObligations<'tcx>,
231+
) -> PendingPredicateObligations<'tcx> {
229232
os.into_iter()
230-
.map(|o| PendingPredicateObligation { obligation: o, stalled_on: vec![] })
233+
.map(|mut o| {
234+
o.set_depth_from_parent(parent.recursion_depth);
235+
PendingPredicateObligation { obligation: o, stalled_on: vec![] }
236+
})
231237
.collect()
232238
}
233239

@@ -341,7 +347,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
341347
);
342348
if predicate != obligation.predicate {
343349
obligations.push(obligation.with(infcx.tcx, predicate));
344-
return ProcessResult::Changed(mk_pending(obligations));
350+
return ProcessResult::Changed(mk_pending(obligation, obligations));
345351
}
346352
}
347353
let binder = obligation.predicate.kind();
@@ -385,7 +391,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
385391
let mut obligations = PredicateObligations::with_capacity(1);
386392
obligations.push(obligation.with(infcx.tcx, pred));
387393

388-
ProcessResult::Changed(mk_pending(obligations))
394+
ProcessResult::Changed(mk_pending(obligation, obligations))
389395
}
390396
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
391397
ty::PredicateKind::NormalizesTo(..) => {
@@ -410,6 +416,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
410416
let host_obligation = obligation.with(infcx.tcx, data);
411417

412418
self.process_host_obligation(
419+
obligation,
413420
host_obligation,
414421
&mut pending_obligation.stalled_on,
415422
)
@@ -486,7 +493,10 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
486493
// `<lhs_ty as Add<rhs_ty>>::Output` when this is an `Expr` representing
487494
// `lhs + rhs`.
488495
ty::ConstKind::Expr(_) => {
489-
return ProcessResult::Changed(mk_pending(PredicateObligations::new()));
496+
return ProcessResult::Changed(mk_pending(
497+
obligation,
498+
PredicateObligations::new(),
499+
));
490500
}
491501
ty::ConstKind::Placeholder(_) => {
492502
bug!("placeholder const {:?} in old solver", ct)
@@ -503,7 +513,10 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
503513
ct_ty,
504514
ty,
505515
) {
506-
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
516+
Ok(inf_ok) => ProcessResult::Changed(mk_pending(
517+
obligation,
518+
inf_ok.into_obligations(),
519+
)),
507520
Err(_) => ProcessResult::Error(FulfillmentErrorCode::Select(
508521
SelectionError::ConstArgHasWrongType { ct, ct_ty, expected_ty: ty },
509522
)),
@@ -537,7 +550,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
537550
vec![TyOrConstInferVar::maybe_from_generic_arg(arg).unwrap()];
538551
ProcessResult::Unchanged
539552
}
540-
Some(os) => ProcessResult::Changed(mk_pending(os)),
553+
Some(os) => ProcessResult::Changed(mk_pending(obligation, os)),
541554
}
542555
}
543556

@@ -553,11 +566,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
553566
vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
554567
ProcessResult::Unchanged
555568
}
556-
Ok(Ok(mut ok)) => {
557-
for subobligation in &mut ok.obligations {
558-
subobligation.set_depth_from_parent(obligation.recursion_depth);
559-
}
560-
ProcessResult::Changed(mk_pending(ok.obligations))
569+
Ok(Ok(ok)) => {
570+
ProcessResult::Changed(mk_pending(obligation, ok.obligations))
561571
}
562572
Ok(Err(err)) => {
563573
let expected_found = if subtype.a_is_expected {
@@ -582,7 +592,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
582592
vec![TyOrConstInferVar::Ty(a), TyOrConstInferVar::Ty(b)];
583593
ProcessResult::Unchanged
584594
}
585-
Ok(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
595+
Ok(Ok(ok)) => {
596+
ProcessResult::Changed(mk_pending(obligation, ok.obligations))
597+
}
586598
Ok(Err(err)) => {
587599
let expected_found = ExpectedFound::new(coerce.b, coerce.a);
588600
ProcessResult::Error(FulfillmentErrorCode::Subtype(expected_found, err))
@@ -645,6 +657,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
645657
)
646658
{
647659
return ProcessResult::Changed(mk_pending(
660+
obligation,
648661
new_obligations.into_obligations(),
649662
));
650663
}
@@ -659,6 +672,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
659672
.eq(DefineOpaqueTypes::Yes, c1, c2)
660673
{
661674
return ProcessResult::Changed(mk_pending(
675+
obligation,
662676
new_obligations.into_obligations(),
663677
));
664678
}
@@ -704,9 +718,10 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
704718
c1,
705719
c2,
706720
) {
707-
Ok(inf_ok) => {
708-
ProcessResult::Changed(mk_pending(inf_ok.into_obligations()))
709-
}
721+
Ok(inf_ok) => ProcessResult::Changed(mk_pending(
722+
obligation,
723+
inf_ok.into_obligations(),
724+
)),
710725
Err(err) => {
711726
ProcessResult::Error(FulfillmentErrorCode::ConstEquate(
712727
ExpectedFound::new(c1, c2),
@@ -790,7 +805,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
790805
match self.selcx.poly_select(&trait_obligation) {
791806
Ok(Some(impl_source)) => {
792807
debug!("selecting trait at depth {} yielded Ok(Some)", obligation.recursion_depth);
793-
ProcessResult::Changed(mk_pending(impl_source.nested_obligations()))
808+
ProcessResult::Changed(mk_pending(obligation, impl_source.nested_obligations()))
794809
}
795810
Ok(None) => {
796811
debug!("selecting trait at depth {} yielded Ok(None)", obligation.recursion_depth);
@@ -854,7 +869,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
854869
}
855870

856871
match project::poly_project_and_unify_term(&mut self.selcx, &project_obligation) {
857-
ProjectAndUnifyResult::Holds(os) => ProcessResult::Changed(mk_pending(os)),
872+
ProjectAndUnifyResult::Holds(os) => ProcessResult::Changed(mk_pending(obligation, os)),
858873
ProjectAndUnifyResult::FailedNormalization => {
859874
stalled_on.clear();
860875
stalled_on.extend(args_infer_vars(
@@ -868,7 +883,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
868883
let mut obligations = PredicateObligations::with_capacity(1);
869884
obligations.push(project_obligation.with(tcx, project_obligation.predicate));
870885

871-
ProcessResult::Changed(mk_pending(obligations))
886+
ProcessResult::Changed(mk_pending(obligation, obligations))
872887
}
873888
ProjectAndUnifyResult::MismatchedProjectionTypes(e) => {
874889
ProcessResult::Error(FulfillmentErrorCode::Project(e))
@@ -878,11 +893,12 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
878893

879894
fn process_host_obligation(
880895
&mut self,
896+
obligation: &PredicateObligation<'tcx>,
881897
host_obligation: HostEffectObligation<'tcx>,
882898
stalled_on: &mut Vec<TyOrConstInferVar>,
883899
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
884900
match effects::evaluate_host_effect_obligation(&mut self.selcx, &host_obligation) {
885-
Ok(nested) => ProcessResult::Changed(mk_pending(nested)),
901+
Ok(nested) => ProcessResult::Changed(mk_pending(obligation, nested)),
886902
Err(effects::EvaluationFailure::Ambiguous) => {
887903
stalled_on.clear();
888904
stalled_on.extend(args_infer_vars(

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
3939
obligation: &PolyTraitObligation<'tcx>,
4040
candidate: SelectionCandidate<'tcx>,
4141
) -> Result<Selection<'tcx>, SelectionError<'tcx>> {
42-
let mut impl_src = match candidate {
42+
Ok(match candidate {
4343
SizedCandidate { has_nested } => {
4444
let data = self.confirm_builtin_candidate(obligation, has_nested);
4545
ImplSource::Builtin(BuiltinImplSource::Misc, data)
@@ -139,15 +139,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
139139
BikeshedGuaranteedNoDropCandidate => {
140140
self.confirm_bikeshed_guaranteed_no_drop_candidate(obligation)
141141
}
142-
};
143-
144-
// The obligations returned by confirmation are recursively evaluated
145-
// so we need to make sure they have the correct depth.
146-
for subobligation in impl_src.borrow_nested_obligations_mut() {
147-
subobligation.set_depth_from_parent(obligation.recursion_depth);
148-
}
149-
150-
Ok(impl_src)
142+
})
151143
}
152144

153145
fn confirm_projection_candidate(

tests/ui/infinite/infinite-autoderef.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow assigning `Box<_>` to `_`
2-
--> $DIR/infinite-autoderef.rs:16:13
2+
--> $DIR/infinite-autoderef.rs:16:22
33
|
44
LL | x = Box::new(x);
5-
| ^^^^^^^^^^^
5+
| ^
66

77
error: aborting due to 1 previous error
88

tests/ui/occurs-check-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ fn main() {
44
let g;
55

66
g = f;
7-
f = Box::new(g);
87
//~^ ERROR overflow assigning `Box<_>` to `_`
8+
f = Box::new(g);
99
}

tests/ui/occurs-check-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow assigning `Box<_>` to `_`
2-
--> $DIR/occurs-check-2.rs:7:9
2+
--> $DIR/occurs-check-2.rs:6:9
33
|
4-
LL | f = Box::new(g);
5-
| ^^^^^^^^^^^
4+
LL | g = f;
5+
| ^
66

77
error: aborting due to 1 previous error
88

tests/ui/occurs-check-3.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow assigning `Clam<_>` to `_`
2-
--> $DIR/occurs-check-3.rs:6:9
2+
--> $DIR/occurs-check-3.rs:6:17
33
|
44
LL | c = Clam::A(c);
5-
| ^^^^^^^^^^
5+
| ^
66

77
error: aborting due to 1 previous error
88

tests/ui/occurs-check.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0275]: overflow assigning `Box<_>` to `_`
2-
--> $DIR/occurs-check.rs:3:9
2+
--> $DIR/occurs-check.rs:3:18
33
|
44
LL | f = Box::new(f);
5-
| ^^^^^^^^^^^
5+
| ^
66

77
error: aborting due to 1 previous error
88

tests/ui/traits/mutual-recursion-issue-75860.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0275]: overflow assigning `_` to `Option<_>`
22
--> $DIR/mutual-recursion-issue-75860.rs:9:33
33
|
44
LL | let left = |o_a: Option<_>| o_a.unwrap();
5-
| ^^^
5+
| ^^^^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#![feature(type_alias_impl_trait)]
2-
//@ known-bug: #109268
32

43
type Foo = impl Fn() -> Foo;
54

5+
#[define_opaque(Foo)]
66
fn crash(x: Foo) -> Foo {
7+
//~^ ERROR overflow evaluating the requirement `<Foo as FnOnce<()>>::Output == Foo`
78
x
89
}
910

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
error: unconstrained opaque type
2-
--> $DIR/type-alias-impl-trait-with-cycle-error-1.rs:4:12
1+
error[E0275]: overflow evaluating the requirement `<Foo as FnOnce<()>>::Output == Foo`
2+
--> $DIR/type-alias-impl-trait-with-cycle-error-1.rs:6:21
33
|
4-
LL | type Foo = impl Fn() -> Foo;
5-
| ^^^^^^^^^^^^^^^^
6-
|
7-
= note: `Foo` must be used in combination with a concrete type within the same crate
4+
LL | fn crash(x: Foo) -> Foo {
5+
| ^^^
86

97
error: aborting due to 1 previous error
108

9+
For more information about this error, try `rustc --explain E0275`.

tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#![feature(type_alias_impl_trait)]
2-
//@ known-bug: #109268
32

43
pub trait Bar<T> {
54
type Item;
65
}
76

87
type Foo = impl Bar<Foo, Item = Foo>;
9-
8+
#[define_opaque(Foo)]
109
fn crash(x: Foo) -> Foo {
10+
//~^ ERROR overflow evaluating the requirement `<Foo as Bar<Foo>>::Item == Foo`
1111
x
1212
}
1313

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
error: unconstrained opaque type
2-
--> $DIR/type-alias-impl-trait-with-cycle-error-2.rs:8:12
1+
error[E0275]: overflow evaluating the requirement `<Foo as Bar<Foo>>::Item == Foo`
2+
--> $DIR/type-alias-impl-trait-with-cycle-error-2.rs:9:21
33
|
4-
LL | type Foo = impl Bar<Foo, Item = Foo>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: `Foo` must be used in combination with a concrete type within the same crate
4+
LL | fn crash(x: Foo) -> Foo {
5+
| ^^^
86

97
error: aborting due to 1 previous error
108

9+
For more information about this error, try `rustc --explain E0275`.

tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-3.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![feature(type_alias_impl_trait)]
2-
//@ known-bug: #109268
32

43
type Foo<'a> = impl Fn() -> Foo<'a>;
5-
4+
#[define_opaque(Foo)]
65
fn crash<'a>(_: &'a (), x: Foo<'a>) -> Foo<'a> {
6+
//~^ ERROR overflow evaluating the requirement `<Foo<'_> as FnOnce<()>>::Output == Foo<'a>`
77
x
88
}
99

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
error: unconstrained opaque type
2-
--> $DIR/type-alias-impl-trait-with-cycle-error-3.rs:4:16
1+
error[E0275]: overflow evaluating the requirement `<Foo<'_> as FnOnce<()>>::Output == Foo<'a>`
2+
--> $DIR/type-alias-impl-trait-with-cycle-error-3.rs:5:40
33
|
4-
LL | type Foo<'a> = impl Fn() -> Foo<'a>;
5-
| ^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: `Foo` must be used in combination with a concrete type within the same crate
4+
LL | fn crash<'a>(_: &'a (), x: Foo<'a>) -> Foo<'a> {
5+
| ^^^^^^^
86

97
error: aborting due to 1 previous error
108

9+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)