Skip to content

Compiler hang with incomplete struct literal at end of file #103451

Closed

Description

This malformed code (playground) hangs the compiler:

struct R { }

struct S {
    x: [u8; R

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:
    • No opening brace (note that braces are required for literals of named-field structs)
    • No closing delimiters
    • Not even a comment

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 as smart_resolve_context_dependent_help and span_to_snippet)

Additional example

This also hangs. I'm guessing it's the same bug.

struct R { }

fn f() {
    R

Version

rustc --version --verbose:

rustc 1.66.0-nightly (6e95b6da8 2022-10-22)
binary: rustc
commit-hash: 6e95b6da885f42a4e1314595089fa4295e329d11
commit-date: 2022-10-22
host: x86_64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.2

Regression

Bisected with:

cargo-bisect-rustc --start=2022-10-03 --end=nightly-2022-10-23 --preserve --script=./timeout.sh
timeout.sh

#!/bin/bash

# This script is wrong in several ways:
# - It will try to kill processes that might no longer exist
# - It may leave an orphan rustc process after the bisect (because it only kills the shell, not rustc)
# But it seems to be good enough for bisection to work

killall rustc
outershell=$$
(sleep 5; kill $outershell) &
rustc src/main.rs
true

@rustbot label +regression-from-stable-to-nightly +I-hang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions