Skip to content

Commit c91f60e

Browse files
Don't super-fold types when we hit the recursion limit
1 parent e6e931d commit c91f60e

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)