rust-lang / rust-lang/rust

Removing a private ambiguous import can break downstream crates also relying on ambiguous imports

Open
#159,901 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-resolve C-bug needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

I fixed up an ambiguous (private) import in rustc_ast:
https://github.com/rust-lang/rust/compare/main...mejrs:rust:globby

I expected to see this happen: rustc_ast compiles, so I expected the compiler to compile.

rustc_ast_pretty now fails to compile:

 error[E0433]: cannot find module `Ident` in this scope                                                                                                                                                                                                                                                    
   --> compiler\rustc_ast_pretty\src\pprust\state.rs:367:17
    |
367 |             if !Ident::new(*sym, *span).is_reserved() || matches!(is_raw, IdentIsRaw::Yes) =>
    |                 ^^^^^ `Ident` is a variant, not a module

error[E0433]: cannot find module `Ident` in this scope
   --> compiler\rustc_ast_pretty\src\pprust\state.rs:375:17
    |
375 |             if !Ident::new(*sym, *span).is_reserved()
    |                 ^^^^^ `Ident` is a variant, not a module

For more information about this error, try `rustc --explain E0433`. 

Code:

// allowed, no diagnostic emitted
use rustc_span::Ident;

fn space_between...
         use token::*; // also exports an `Ident`

          match .. {
                  // IDENT + `!`: `println!()`, but `if !x { ... }` needs a space after the `if`
                  (Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Bang, .. }, _))
                      if !Ident::new(*sym, *span).is_reserved() || matches!(is_raw, IdentIsRaw::Yes) =>
                  {
                      false
                  }

once fixed, it later breaks rustc_expand:

error[E0559]: variant `rustc_ast::token::TokenKind::Ident` has no field named `sym`                                                                                                                                                                                                                       
   --> compiler\rustc_expand\src\proc_macro_server.rs:235:21
    |
235 |                     sym,
    |                     ^^^ field does not exist
    |
   ::: compiler\rustc_ast\src\token.rs:502:5
    |
502 |     Ident(Symbol, IdentIsRaw),
    |     ----- `rustc_ast::token::TokenKind::Ident` defined here

Notably, rustc_ast_pretty doesn't allow any lints. This should at least emit a (fcw) lint.

Meta

rustc --version --verbose:

current main
Backtrace

<backtrace>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ambiguous-import change across rustc_ast, rustc_ast_pretty, and rustc_expand. Read compiler/rustc_ast_pretty/src/pprust/state.rs and compiler/rustc_expand/src/proc_macro_server.rs, then trace the relevant import and name-resolution diagnostics. Done means the downstream crates no longer fail silently after the private ambiguous import is changed, and an appropriate lint is emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.