-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Compiler hang with incomplete struct literal at end of file #103451
Comments
@rustbot claim |
I can not reproduce it with latest code, did I missed anything? cat@LAPTOP-V6U0QKD4:~/code/rust$ cat hang.rs
struct R { }
struct S {
x: [u8; R
cat@LAPTOP-V6U0QKD4:~/code/rust$ rustc -vV
rustc 1.66.0-nightly (7fcf850d7 2022-10-23)
binary: rustc
commit-hash: 7fcf850d7942804990a1d2e3fe036622a0fe4c74
commit-date: 2022-10-23
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
cat@LAPTOP-V6U0QKD4:~/code/rust$ rustc hang.rs
error: this file contains an unclosed delimiter
--> hang.rs:4:15
|
3 | struct S {
| - unclosed delimiter
4 | x: [u8; R
| - ^
| |
| unclosed delimiter
error[E0423]: expected value, found struct `R`
--> hang.rs:4:13
|
1 | struct R { }
| ------------ `R` defined here
...
4 | x: [u8; R
| ^ help: use struct literal syntax instead: `R {}`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0423`. |
Great cactch @jruderman Confirmed the error is only triggered by commit: The root cause is I changed the edge corner case in // Ensure indexes are also not malformed.
if start_index > end_index || end_index > source_len - 1 {
debug!("find_width_of_character_at_span: source indexes are malformed");
return 0; // Previous version is `return 1`
} We think So, there is a loop in previous
Lucky, my another PR #101908 merged at last day, this PR refactored this function: |
Verif, I no longer get a hang after rollup 9be2f35 Do you want to add one or two of these as tests? |
Yes, we'd better add a testcase for it. I'm thinking whether we sould |
This testcase seems not easy to be added: struct R { }
struct S {
x: [u8; R //~ ERROR this file contains an unclosed delimiter
//~| ERROR expected value If so, the trigger point will do not exist, 😂 |
@rustbot label -I-prioritize |
There's an alternative kind of annotation for patterns that should work for this case: |
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
…-hang, r=jackh726,wesleywiser Avoid possible infinite loop when next_point reaching the end of file Fixes rust-lang#103451 If we return a span with `lo` = `hi`, `span_to_snippet` will always get `Ok("")`, which may introduce infinite loop if we don't care. This PR make `find_width_of_character_at_span` return `width` with 1, so that `span_to_snippet` will get an `Err`.
This malformed code (playground) hangs the compiler:
Found by fuzzing with a modified fuzz-rustc.
The bug's edges
R
must be defined as a named-field struct (not a tuple struct or unit struct), although it can have 0 fields.R
must be the last token to produce the hang:Where it hangs
If I understand mj.sample.txt correctly, the hang occurs in LateResolutionVisitor, with
try_lookup_name_relaxed
never finishing (while calling various functions such assmart_resolve_context_dependent_help
andspan_to_snippet
)Additional example
This also hangs. I'm guessing it's the same bug.
Version
rustc --version --verbose
:Regression
Bisected with:
timeout.sh
@rustbot label +regression-from-stable-to-nightly +I-hang
The text was updated successfully, but these errors were encountered: