-
Notifications
You must be signed in to change notification settings - Fork 13.3k
suggest doubling recursion limit in more situations #39655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that the recursion limit can be changed and that the compiler | ||
// suggests a fix. In this case, we have deeply nested types that will | ||
// fail the `Send` check by overflow when the recursion limit is set | ||
// very low. | ||
|
||
#![allow(dead_code)] | ||
#![recursion_limit="10"] | ||
|
||
macro_rules! link { | ||
($id:ident, $t:ty) => { | ||
enum $id { $id($t) } | ||
} | ||
} | ||
|
||
link! { A, B } | ||
link! { B, C } | ||
link! { C, D } | ||
link! { D, E } | ||
link! { E, F } | ||
link! { F, G } | ||
link! { G, H } | ||
link! { H, I } | ||
link! { I, J } | ||
link! { J, K } | ||
link! { K, L } | ||
link! { L, M } | ||
link! { M, N } | ||
|
||
enum N { N(usize) } | ||
|
||
fn is_send<T:Send>() { } | ||
|
||
fn main() { | ||
is_send::<A>(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0275]: overflow evaluating the requirement `K: std::marker::Send` | ||
--> $DIR/recursion_limit.rs:44:5 | ||
| | ||
44 | is_send::<A>(); | ||
| ^^^^^^^^^^^^ | ||
| | ||
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate | ||
= note: required because it appears within the type `J` | ||
= note: required because it appears within the type `I` | ||
= note: required because it appears within the type `H` | ||
= note: required because it appears within the type `G` | ||
= note: required because it appears within the type `F` | ||
= note: required because it appears within the type `E` | ||
= note: required because it appears within the type `D` | ||
= note: required because it appears within the type `C` | ||
= note: required because it appears within the type `B` | ||
= note: required because it appears within the type `A` | ||
= note: required by `is_send` | ||
|
||
error: aborting due to previous error | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that the recursion limit can be changed and that the compiler | ||
// suggests a fix. In this case, we have a long chain of Deref impls | ||
// which will cause an overflow during the autoderef loop. | ||
|
||
#![allow(dead_code)] | ||
#![recursion_limit="10"] | ||
|
||
macro_rules! link { | ||
($outer:ident, $inner:ident) => { | ||
struct $outer($inner); | ||
|
||
impl $outer { | ||
fn new() -> $outer { | ||
$outer($inner::new()) | ||
} | ||
} | ||
|
||
impl std::ops::Deref for $outer { | ||
type Target = $inner; | ||
|
||
fn deref(&self) -> &$inner { | ||
&self.0 | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct Bottom; | ||
impl Bottom { | ||
fn new() -> Bottom { | ||
Bottom | ||
} | ||
} | ||
|
||
link!(Top, A); | ||
link!(A, B); | ||
link!(B, C); | ||
link!(C, D); | ||
link!(D, E); | ||
link!(E, F); | ||
link!(F, G); | ||
link!(G, H); | ||
link!(H, I); | ||
link!(I, J); | ||
link!(J, K); | ||
link!(K, Bottom); | ||
|
||
fn main() { | ||
let t = Top::new(); | ||
let x: &Bottom = &t; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0055]: reached the recursion limit while auto-dereferencing I | ||
--> $DIR/recursion_limit_deref.rs:60:22 | ||
| | ||
60 | let x: &Bottom = &t; | ||
| ^^ deref recursion limit reached | ||
| | ||
= help: consider adding a `#[recursion_limit="20"]` attribute to your crate | ||
|
||
error[E0055]: reached the recursion limit while auto-dereferencing I | ||
| | ||
= help: consider adding a `#[recursion_limit="20"]` attribute to your crate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This duplicate error shouldn't be here and yet it is. cc #38940 @jseyfried |
||
|
||
error[E0308]: mismatched types | ||
--> $DIR/recursion_limit_deref.rs:60:22 | ||
| | ||
60 | let x: &Bottom = &t; | ||
| ^^ expected struct `Bottom`, found struct `Top` | ||
| | ||
= note: expected type `&Bottom` | ||
found type `&Top` | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that the recursion limit can be changed and that the compiler | ||
// suggests a fix. In this case, we have a recursing macro that will | ||
// overflow if the number of arguments surpasses the recursion limit. | ||
|
||
#![allow(dead_code)] | ||
#![recursion_limit="10"] | ||
|
||
macro_rules! recurse { | ||
() => { }; | ||
($t:tt $($tail:tt)*) => { recurse!($($tail)*) }; | ||
} | ||
|
||
fn main() { | ||
recurse!(0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: recursion limit reached while expanding the macro `recurse` | ||
--> $DIR/recursion_limit_macro.rs:20:31 | ||
| | ||
20 | ($t:tt $($tail:tt)*) => { recurse!($($tail)*) }; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
24 | recurse!(0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9); | ||
| -------------------------------------------------- in this macro invocation | ||
| | ||
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should factor this code into some sort of helper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it'd also be nice to make this into an error code ("recursion limit reached") with a note giving the specific details. That way, we could give an extended error description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should I put the helper and diagnostic code? Note that the PR is split across libsyntax and librustc_typeck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Can we only put diagnostic codes into rustc crates? I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are diagnostic codes in libsyntax. Can I define it there and use the same one from librustc_typeck?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh. I think we should improve this, but it's not that big a deal.