Repository navigation
Compiler hang with incomplete struct literal at end of file #103451
Description
Activity
- addedI-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on Oct 23, 2022 @rustbot claim
Reacted by Michael GouletI 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:
6e95b6da885f42a4e1314595089fa4295e329d11The root cause is I changed the edge corner case in
find_width_of_character_at_span:// 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
next_pointwon't return a span which outside of source file, so0is a valid one, thennext_pointwill always return a valid span, and we getOk("")fromsm.span_to_snippetwhen reaching the end of source.So, there is a loop in previous
followed_by_brace, which will run infinitely loop:sp = sm.next_point(sp); Lucky, my another PR #101908 merged at last day, this PR refactored this function:
518d5eb#diff-2c81e6d8048a31a3ce43f30181aaa037e0ad0076e7aee67792ca993f28c75ac3L1108Verif, 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
return 1infind_width_of_character_at_spanwhen reaching to the end of source, so thatsm.span_to_snippetmay get an error.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
- removedI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}Issue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
on Oct 24, 2022 If so, the trigger point will do not exist
There's an alternative kind of annotation for patterns that should work for this case:
// error-pattern:this file contains an unclosed delimiterReacted by Jesse Ruderman- added 5 commits that reference this issue
on Nov 7, 2022 - added 4 commits that reference this issue
on Nov 8, 2022
This malformed code (playground) hangs the compiler:
Found by fuzzing with a modified fuzz-rustc.
The bug's edges
Rmust be defined as a named-field struct (not a tuple struct or unit struct), although it can have 0 fields.Rmust 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_relaxednever finishing (while calling various functions such assmart_resolve_context_dependent_helpandspan_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