Skip to content

Commit 042464f

Browse files
committed
Fix tests and bootstrap
1 parent 2bdf723 commit 042464f

20 files changed

+182
-63
lines changed

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
11701170
// This also instantiates nested instances of `impl Trait`.
11711171
let predicate = self.instantiate_opaque_types_in_map(&predicate);
11721172

1173-
let cause =
1174-
traits::ObligationCause::new(span, self.body_id, traits::MiscObligation);
1173+
let cause = traits::ObligationCause::new(span, self.body_id, traits::MiscObligation);
11751174

11761175
// Require that the predicate holds for the concrete type.
11771176
debug!("instantiate_opaque_types: predicate={:?}", predicate);

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,27 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
241241
traits::ObligationCause::new(self.span, self.body_id, code)
242242
}
243243

244-
fn normalize(&mut self) -> Vec<traits::PredicateObligation<'tcx>> {
244+
fn normalize(mut self) -> Vec<traits::PredicateObligation<'tcx>> {
245245
let cause = self.cause(traits::MiscObligation);
246246
let infcx = &mut self.infcx;
247247
let param_env = self.param_env;
248248
let mut obligations = Vec::with_capacity(self.out.len());
249-
for pred in &self.out {
250-
assert!(!pred.has_escaping_bound_vars());
249+
for mut obligation in self.out {
250+
assert!(!obligation.has_escaping_bound_vars());
251251
let mut selcx = traits::SelectionContext::new(infcx);
252252
let i = obligations.len();
253-
let value =
254-
traits::normalize_to(&mut selcx, param_env, cause.clone(), pred, &mut obligations);
255-
obligations.insert(i, value);
253+
// Don't normalize the whole obligation, the param env is either
254+
// already normalized, or we're currently normalizing the
255+
// param_env. Either way we should only normalize the predicate.
256+
let normalized_predicate = traits::normalize_to(
257+
&mut selcx,
258+
param_env,
259+
cause.clone(),
260+
&obligation.predicate,
261+
&mut obligations,
262+
);
263+
obligation.predicate = normalized_predicate;
264+
obligations.insert(i, obligation);
256265
}
257266
obligations
258267
}

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ pub fn check_type_bounds<'tcx>(
12561256
);
12571257
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
12581258

1259+
inh.register_predicates(obligations);
12591260
inh.register_predicate(obligation);
12601261
}
12611262

compiler/rustc_typeck/src/collect.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,10 +1787,22 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
17871787
}) => {
17881788
if impl_trait_fn.is_some() {
17891789
// return-position impl trait
1790-
// TODO: Investigate why we have this special case?
1790+
//
1791+
// We don't inherit predicates from the parent here:
1792+
// If we have, say `fn f<'a, T: 'a>() -> impl Sized {}`
1793+
// then the return type is `f::<'static, T>::{{opaque}}`.
1794+
//
1795+
// If we inherited the predicates of `f` then we would
1796+
// require that `T: 'static` to show that the return
1797+
// type is well-formed.
1798+
//
1799+
// The only way to have something with this opaque type
1800+
// is from the return type of the containing function,
1801+
// which will ensure that the function's predicates
1802+
// hold.
17911803
return ty::GenericPredicates { parent: None, predicates: &[] };
17921804
} else {
1793-
// type alias impl trait
1805+
// type-alias impl trait
17941806
generics
17951807
}
17961808
}

src/test/incremental/issue-54242.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// revisions: rpass cfail
22

3-
trait Tr {
3+
trait Tr where Self::Arr: Sized {
44
type Arr;
55

66
const C: usize = 0;

src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- // MIR for `id_try` before SimplifyArmIdentity
22
+ // MIR for `id_try` after SimplifyArmIdentity
3-
3+
44
fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
55
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
66
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
@@ -42,7 +42,7 @@
4242
scope 6 {
4343
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
4444
}
45-
45+
4646
bb0: {
4747
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
4848
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@@ -53,7 +53,7 @@
5353
_5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5454
switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5555
}
56-
56+
5757
bb1: {
5858
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
5959
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@@ -69,11 +69,11 @@
6969
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
7070
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7171
}
72-
72+
7373
bb2: {
7474
unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
7575
}
76-
76+
7777
bb3: {
7878
- StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
7979
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
@@ -94,9 +94,9 @@
9494
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
9595
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
9696
}
97-
97+
9898
bb4: {
9999
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
100100
}
101101
}
102-
102+

src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
- // MIR for `id_try` before SimplifyBranchSame
22
+ // MIR for `id_try` after SimplifyBranchSame
3-
3+
44
fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
55
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
66
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
@@ -37,7 +37,7 @@
3737
scope 6 {
3838
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
3939
}
40-
40+
4141
bb0: {
4242
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
4343
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@@ -49,28 +49,28 @@
4949
- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5050
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
5151
}
52-
52+
5353
bb1: {
5454
_0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
5555
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
5656
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
5757
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
5858
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
5959
}
60-
60+
6161
bb2: {
6262
- unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
6363
- }
64-
-
64+
-
6565
- bb3: {
6666
- _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
6767
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
6868
- StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
6969
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7070
- }
71-
-
71+
-
7272
- bb4: {
7373
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
7474
}
7575
}
76-
76+

src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626
scope 8 {
2727
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
28-
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
28+
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
2929
}
3030
}
3131
}

src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
scope 8 {
3030
- debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
3131
+ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
32-
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
32+
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
3333
}
3434
}
3535
}

src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i
2424
}
2525
scope 8 {
2626
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
27-
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
27+
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
2828
}
2929
}
3030
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Minimized case from typenum that didn't compile because:
2+
// - We tried to normalize the ParamEnv of the second impl
3+
// - This requires trying to normalize `GrEq<Self, Square<Square<U>>>`
4+
// - This requires proving `Square<Square<U>>: Sized` so that the first impl
5+
// applies
6+
// - This requires Providing `Square<Square<U>>` is well-formed, so that we
7+
// can use the `Sized` bound on `Mul::Output`
8+
// - This requires proving `Square<U>: Mul`
9+
// - But first we tried normalizing the whole obligation, including the
10+
// ParamEnv, which leads to a cycle error.
11+
12+
// check-pass
13+
14+
trait PrivateSquareRoot {}
15+
16+
pub trait Mul<Rhs = Self> {
17+
type Output;
18+
}
19+
20+
pub trait IsGreaterOrEqual<Rhs> {
21+
type Output;
22+
}
23+
24+
pub type Square<A> = <A as Mul>::Output;
25+
pub type GrEq<A, B> = <A as IsGreaterOrEqual<B>>::Output;
26+
27+
impl<A, B> IsGreaterOrEqual<B> for A {
28+
type Output = ();
29+
}
30+
31+
impl<U> PrivateSquareRoot for U
32+
where
33+
U: Mul,
34+
Square<U>: Mul,
35+
GrEq<Self, Square<Square<U>>>: Sized,
36+
{
37+
}
38+
39+
fn main() {}

src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-linelength
12
// compile-flags: -Zsave-analysis
23
// This is also a regression test for #69415 and the above flag is needed.
34

0 commit comments

Comments
 (0)