Skip to content

Don't suggest stuff (that doesn't really exist) from nightly when on stable #149402

@pacak

Description

@pacak

Code

fn foo() {
    let x = Vec::new();
    x.push(Complete::Item { name: "hello" });
}

Current output

Checking repro v0.1.0 (/home/pacak/tmp/repro)
error[E0433]: failed to resolve: use of undeclared type `Complete`
 --> src/lib.rs:3:12
  |
3 |     x.push(Complete::Item { name: "hello" });
  |            ^^^^^^^^ use of undeclared type `Complete`
  |
help: there is an enum variant `core::ops::CoroutineState::Complete` and 1 other; try using the variant's enum
  |
3 -     x.push(Complete::Item { name: "hello" });
3 +     x.push(core::ops::CoroutineState::Item { name: "hello" });
  |
3 -     x.push(Complete::Item { name: "hello" });
3 +     x.push(std::ops::CoroutineState::Item { name: "hello" });
  |

Desired output

Don't mention std::ops::CoroutineState and give up much earlier? Take into account available enum variant names when making a suggestion?

Rationale and extra context

I renamed enum Complete into CompleteRequest, on the next check rustc suggested me to use std::ops::CoroutineState. This is wrong for two reasons:

  1. I'm not using nightly so replacement won't work even if CoroutineState::Item existed
  2. CoroutineState::Item { name ... } doesn't exist
pub enum CoroutineState<Y, R> {
    Yielded(Y),
    Complete(R),
}

Other cases

Rust Version

rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: x86_64-unknown-linux-gnu
release: 1.91.1
LLVM version: 21.1.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions