Skip to content

Commit 88fa119

Browse files
committed
Auto merge of #127670 - compiler-errors:no-type-length-limit, r=jackh726
Gate the type length limit check behind a nightly flag Effectively disables the type length limit by introducing a `-Zenforce-type-length-limit` which defaults to **`false`**, since making the length limit actually be enforced ended up having a worse fallout than expected. We still keep the code around, but the type length limit attr is now a noop (except for its usage in some diagnostics code?). r? `@lcnr` -- up to you to decide what team consensus we need here since this reverses an FCP decision. Reopens #125460 (if we decide to reopen it or keep it closed) Effectively reverses the decision FCP'd in #125507 Closes #127346
2 parents a241cf1 + 938ed36 commit 88fa119

17 files changed

+54
-58
lines changed

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,9 @@ impl<'tcx> Instance<'tcx> {
541541
// which means that rustc basically hangs.
542542
//
543543
// Bail out in these cases to avoid that bad user experience.
544-
if !tcx.type_length_limit().value_within_limit(type_length(args)) {
544+
if tcx.sess.opts.unstable_opts.enforce_type_length_limit
545+
&& !tcx.type_length_limit().value_within_limit(type_length(args))
546+
{
545547
return Ok(None);
546548
}
547549

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,8 @@ options! {
17111711
"emit a section containing stack size metadata (default: no)"),
17121712
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
17131713
"emit the bc module with thin LTO info (default: yes)"),
1714+
enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
1715+
"enforce the type length limit when monomorphizing instances in codegen"),
17141716
export_executable_symbols: bool = (false, parse_bool, [TRACKED],
17151717
"export symbols from executables, as if they were dynamic libraries"),
17161718
external_clangrt: bool = (false, parse_bool, [UNTRACKED],

tests/ui/closures/issue-72408-nested-closures-exponential.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ build-fail
1+
//@ check-pass
22

33
// Closures include captured types twice in a type tree.
44
//
@@ -45,7 +45,6 @@ fn main() {
4545

4646
let f = dup(f);
4747
let f = dup(f);
48-
//~^ ERROR reached the type-length limit
4948
let f = dup(f);
5049
let f = dup(f);
5150
let f = dup(f);

tests/ui/closures/issue-72408-nested-closures-exponential.stderr

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/ui/codegen/overflow-during-mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
//~ ERROR overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
12
//@ build-fail
2-
//@ error-pattern: reached the type-length limit while instantiating
33

44
#![recursion_limit = "32"]
55

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error: reached the type-length limit while instantiating `<Filter<Filter<std::array::IntoIter<i32, 11>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, ...> as Iterator>::try_fold::<..., ..., ...>`
2-
--> $SRC_DIR/core/src/iter/adapters/filter.rs:LL:COL
1+
error[E0275]: overflow evaluating the requirement `{closure@$DIR/overflow-during-mono.rs:13:41: 13:44}: Sized`
32
|
4-
= help: consider adding a `#![type_length_limit="20156994"]` attribute to your crate
5-
= note: the full type name has been written to '$TEST_BUILD_DIR/codegen/overflow-during-mono/overflow-during-mono.long-type.txt'
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "64"]` attribute to your crate (`overflow_during_mono`)
4+
= note: required for `Filter<std::array::IntoIter<i32, 11>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>` to implement `Iterator`
5+
= note: 31 redundant requirements hidden
6+
= note: required for `Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<std::array::IntoIter<i32, 11>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>` to implement `Iterator`
7+
= note: required for `Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<Filter<std::array::IntoIter<i32, 11>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>, {closure@$DIR/overflow-during-mono.rs:13:41: 13:44}>` to implement `IntoIterator`
68

79
error: aborting due to 1 previous error
810

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

tests/ui/issues/issue-22638.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl C {
4040
pub fn matches<F: Fn()>(&self, f: &F) {
4141
let &C(ref base) = self;
4242
base.matches(&|| {
43-
//~^ ERROR reached the type-length limit
4443
C(base.clone()).matches(f)
4544
})
4645
}
@@ -53,6 +52,7 @@ impl D {
5352
pub fn matches<F: Fn()>(&self, f: &F) {
5453
let &D(ref a) = self;
5554
a.matches(f)
55+
//~^ ERROR reached the recursion limit while instantiating
5656
}
5757
}
5858

tests/ui/issues/issue-22638.stderr

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
error: reached the type-length limit while instantiating `D::matches::<{closure@$DIR/issue-22638.rs:42:23: 42:25}>`
2-
--> $DIR/issue-22638.rs:42:9
1+
error: reached the recursion limit while instantiating `A::matches::<{closure@$DIR/issue-22638.rs:42:23: 42:25}>`
2+
--> $DIR/issue-22638.rs:54:9
33
|
4-
LL | / base.matches(&|| {
5-
LL | |
6-
LL | | C(base.clone()).matches(f)
7-
LL | | })
8-
| |__________^
4+
LL | a.matches(f)
5+
| ^^^^^^^^^^^^
96
|
10-
= help: consider adding a `#![type_length_limit="30408681"]` attribute to your crate
7+
note: `A::matches` defined here
8+
--> $DIR/issue-22638.rs:13:5
9+
|
10+
LL | pub fn matches<F: Fn()>(&self, f: &F) {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1112

1213
error: aborting due to 1 previous error
1314

tests/ui/issues/issue-37311-type-length-limit/issue-37311.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<T> Foo for T {
1515
#[allow(unconditional_recursion)]
1616
fn recurse(&self) {
1717
(self, self).recurse();
18-
//~^ ERROR reached the type-length limit
18+
//~^ ERROR reached the recursion limit while instantiating
1919
}
2020
}
2121

tests/ui/issues/issue-37311-type-length-limit/issue-37311.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
error: reached the type-length limit while instantiating `<(&(&(..., ...), ...), ...) as Foo>::recurse`
1+
error: reached the recursion limit while instantiating `<(&(&(..., ...), ...), ...) as Foo>::recurse`
22
--> $DIR/issue-37311.rs:17:9
33
|
44
LL | (self, self).recurse();
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: consider adding a `#![type_length_limit="33554429"]` attribute to your crate
7+
note: `<T as Foo>::recurse` defined here
8+
--> $DIR/issue-37311.rs:16:5
9+
|
10+
LL | fn recurse(&self) {
11+
| ^^^^^^^^^^^^^^^^^
812
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-37311-type-length-limit/issue-37311/issue-37311.long-type.txt'
913

1014
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)