Skip to content

Commit 749a76e

Browse files
authored
Unrolled build for rust-lang#117414
Rollup merge of rust-lang#117414 - compiler-errors:tait-forevert, r=oli-obk Don't normalize to an un-revealed opaque when we hit the recursion limit Currently, we will normalize `Opaque := Option<&Opaque>` to something like `Option<&Option<&Option<&...Opaque>>>`, hitting a limit and bottoming out in an unnormalized opaque after the recursion limit gets hit. Unfortunately, during `layout_of`, we'll simply recurse and try again if the type normalizes to something different than the type: https://github.com/rust-lang/rust/blob/e6e931dda5fffbae0fd87c5b1af753cc95556880/compiler/rustc_ty_utils/src/layout.rs#L58-L60 That means then we'll try to normalize `Option<&Option<&Option<&...Opaque>>>` again, substituting `Opaque` into itself even deeper. Eventually this will get to the point that we're just stack-overflowing on a really deep type before even hitting an opaque again. To fix this, we just bottom out into `ty::Error` instead of the unrevealed opaque type. Fixes rust-lang#117412 r? `@oli-obk`
2 parents 236ac91 + c91f60e commit 749a76e

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

compiler/rustc_trait_selection/src/traits/query/normalize.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,14 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
230230
Reveal::All => {
231231
let args = data.args.try_fold_with(self)?;
232232
let recursion_limit = self.interner().recursion_limit();
233+
233234
if !recursion_limit.value_within_limit(self.anon_depth) {
234-
// A closure or coroutine may have itself as in its upvars.
235-
// This should be checked handled by the recursion check for opaque
236-
// types, but we may end up here before that check can happen.
237-
// In that case, we delay a bug to mark the trip, and continue without
238-
// revealing the opaque.
239-
self.infcx
235+
let guar = self
236+
.infcx
240237
.err_ctxt()
241238
.build_overflow_error(&ty, self.cause.span, true)
242239
.delay_as_bug();
243-
return ty.try_super_fold_with(self);
240+
return Ok(Ty::new_error(self.interner(), guar));
244241
}
245242

246243
let generic_ty = self.interner().type_of(data.def_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type T = impl Copy;
4+
//~^ ERROR cannot resolve opaque type
5+
6+
static STATIC: T = None::<&'static T>;
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0720]: cannot resolve opaque type
2+
--> $DIR/infinite-cycle-involving-weak.rs:3:10
3+
|
4+
LL | type T = impl Copy;
5+
| ^^^^^^^^^ cannot resolve opaque type
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0720`.

0 commit comments

Comments
 (0)