Skip to content

rustc nightly hangs with cross-crate trait bound issue involving pub use crate or extern crate self #149092

@Deewiant

Description

@Deewiant

rustc 1.93.0-nightly (3d461af2a 2025-11-18) hangs without producing any output instead of producing an error about an unsatisfied trait bound. The case involves at least two crates, I haven't been able to reduce it further. Here's a short shell script that sets it up by creating the crates in the current directory:

cargo new --bin user
cargo new --lib library
(cd user && cargo add --path ../library)

cat > user/src/main.rs <<EOF
fn assert_binread<T: library::BinRead>() {}
fn main() {
    assert_binread::<()>();
}
EOF

cat > library/src/lib.rs <<EOF
pub trait BinRead {}
pub struct PosValue<T> {
    pub t: T,
}
impl<T: BinRead> BinRead for PosValue<T> {}
pub use crate as library;
EOF

Running those commands and then cd user && cargo +nightly check, I observe a hang on:

    Building [=============>               ] 1/2: user(bin)

Whereas with cargo check on 1.91.1 stable it produces the expected error immediately:

error[E0277]: the trait bound `(): BinRead` is not satisfied
 --> src/main.rs:3:22
  |
3 |     assert_binread::<()>();
  |                      ^^ the trait `BinRead` is not implemented for `()`
  |
  = help: the trait `BinRead` is implemented for `PosValue<T>`
note: required by a bound in `assert_binread`
 --> src/main.rs:1:22
  |
1 | fn assert_binread<T: library::BinRead>() {}
  |                      ^^^^^^^^^^^^^^^^ required by this bound in `assert_binread`

I looked at the open I-hang issues and this does not seem to match any of them. I also tried setting RUSTFLAGS=-Znext-solver=globally (as many of them are marked as "fixed-by-next-solver") but the hang still reproduces.

The library crate here was reduced from binrw 0.15.0. It uses extern crate self as binrw similarly to the pub use crate as library here — to hazard a guess, maybe that causes some kind of infinite loop related to name resolution.

Meta

rustc +nightly --version --verbose:

rustc 1.93.0-nightly (3d461af2a 2025-11-18)
binary: rustc
commit-hash: 3d461af2a23456a2676aadb13b4253c87bdfe28d
commit-date: 2025-11-18
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

RUSTFLAGS=-Ztime-passes cargo +nightly check output:

    Checking library v0.1.0 (/path/to/library)
time:   0.000; rss:   36MB ->   37MB (   +1MB)  parse_crate
time:   0.000; rss:   43MB ->   43MB (   +0MB)  crate_injection
time:   0.003; rss:   43MB ->   53MB (  +10MB)  expand_crate
time:   0.004; rss:   43MB ->   53MB (  +10MB)  macro_expand_crate
time:   0.000; rss:   53MB ->   53MB (   +0MB)  AST_validation
time:   0.000; rss:   53MB ->   54MB (   +0MB)  finalize_macro_resolutions
time:   0.000; rss:   54MB ->   54MB (   +1MB)  late_resolve_crate
time:   0.000; rss:   54MB ->   54MB (   +0MB)  resolve_check_unused
time:   0.001; rss:   53MB ->   54MB (   +1MB)  resolve_crate
time:   0.000; rss:   54MB ->   55MB (   +0MB)  write_dep_info
time:   0.000; rss:   55MB ->   55MB (   +0MB)  complete_gated_feature_checking
time:   0.000; rss:   56MB ->   57MB (   +0MB)  looking_for_entry_point
time:   0.000; rss:   56MB ->   57MB (   +0MB)  misc_checking_1
time:   0.000; rss:   57MB ->   57MB (   +0MB)  coherence_checking
time:   0.000; rss:   57MB ->   57MB (   +0MB)  type_check_crate
time:   0.000; rss:   58MB ->   58MB (   +0MB)  lint_checking
time:   0.002; rss:   57MB ->   58MB (   +1MB)  misc_checking_3
time:   0.000; rss:   58MB ->   58MB (   +0MB)  generate_crate_metadata
time:   0.000; rss:   58MB ->   59MB (   +1MB)  codegen_crate
time:   0.000; rss:   59MB ->   60MB (   +0MB)  encode_query_results
time:   0.000; rss:   59MB ->   60MB (   +0MB)  incr_comp_serialize_result_cache
time:   0.003; rss:   59MB ->   60MB (   +1MB)  incr_comp_persist_result_cache
time:   0.003; rss:   59MB ->   60MB (   +1MB)  serialize_dep_graph
time:   0.028; rss:   28MB ->   49MB (  +21MB)  total
    Checking user v0.1.0 (/path/to/user)
time:   0.000; rss:   36MB ->   37MB (   +1MB)  parse_crate
time:   0.000; rss:   43MB ->   43MB (   +0MB)  crate_injection
time:   0.003; rss:   43MB ->   53MB (  +10MB)  expand_crate
time:   0.003; rss:   43MB ->   53MB (  +10MB)  macro_expand_crate
time:   0.000; rss:   53MB ->   53MB (   +0MB)  AST_validation
time:   0.000; rss:   53MB ->   53MB (   +0MB)  finalize_macro_resolutions
time:   0.000; rss:   53MB ->   54MB (   +0MB)  late_resolve_crate
time:   0.000; rss:   54MB ->   54MB (   +0MB)  resolve_check_unused
time:   0.001; rss:   53MB ->   54MB (   +1MB)  resolve_crate
time:   0.000; rss:   54MB ->   54MB (   +0MB)  write_dep_info
time:   0.000; rss:   54MB ->   54MB (   +0MB)  complete_gated_feature_checking
time:   0.000; rss:   56MB ->   56MB (   +0MB)  looking_for_entry_point
time:   0.001; rss:   56MB ->   57MB (   +1MB)  misc_checking_1
time:   0.001; rss:   57MB ->   62MB (   +4MB)  coherence_checking
    Building [=============>               ] 1/2: user(bin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions