Skip to content

compiler hangs trying to print an overflow error #83150

Closed
@Neutron3529

Description

@Neutron3529

I tried this code:

fn main(){
  let mut iter=0u8..1;
  println!("begin");
  func(&mut iter)
}
fn func<T:Iterator<Item=u8>>(iter:&mut T){
    if let Some(x)=iter.next(){
        println!("{}",x);
        func(&mut iter.map(|x|x+1))
    }
}

I expected to see this happen:

program either compiled successful or compiler generate an error

Instead, this happened:
rustc eats 100% CPU for several minutes, but nothing generated.
I compile this code using both
rustc testxx.rs -C opt-level=3 -C target-cpu=native -C codegen-units=1 -C lto -o testxx andrustc testxx.rs -C opt-level=0 -o testxx before I began to write this issue, but compiler do not compile even after this issue is submitted.

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (152f66092 2021-02-17)
binary: rustc
commit-hash: 152f6609246558be5e2582e67376194815e6ba0d
commit-date: 2021-02-17
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
Backtrace

(cannot compile)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions