Skip to content

"X is ambiguous" error is missing a span when the standard library source is not available #91028

Closed
@RalfJung

Description

@RalfJung
Member

This code on the playground

pub enum Option<T> {
    /// No value
    None,
    /// Some value `T`
    Some(T),
}

pub use Option::*;

produces the following error

error[E0659]: `Option` is ambiguous
   --> src/lib.rs:8:9
    |
8   | pub use Option::*;
    |         ^^^^^^ ambiguous name
    |
    = note: ambiguous because of multiple potential import sources
note: `Option` could refer to the enum defined here
   --> src/lib.rs:1:1
    |
1   | / pub enum Option<T> {
2   | |     /// No value
3   | |     None,
4   | |     /// Some value `T`
5   | |     Some(T),
6   | | }
    | |_^
    = help: use `crate::Option` to refer to this enum unambiguously
note: `Option` could also refer to the enum defined here

Note how the 2nd note is dangling: no span is shown after it says 'could also refer to the enum defined here'.

I was not able to reproduce this locally, so this might also have to do with something special the playground is doing -- Cc @shepmaster

Activity

shepmaster

shepmaster commented on Nov 19, 2021

@shepmaster
Member

I’d guess it has something to do with the number of crates and their types available by default.

For example, just typing Option by itself says:

error[E0423]: expected value, found enum `Option`
 --> src/main.rs:2:5
  |
2 |     Option;
  |     ^^^^^^
  |
help: you might have meant to use the following enum variant
  |
2 |     std::option::Option::None;
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~
help: the following enum variant is available
  |
2 |     (std::option::Option::Some(/* fields */));
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider importing one of these items instead
  |
1 | use serde::de::Unexpected::Option;
  |
1 | use serde_value::Unexpected::Option;
  |
1 | use serde_value::Value::Option;
  |
camelid

camelid commented on Nov 19, 2021

@camelid
Member

I think the standard library is not always distributed with sources, which sometimes causes weird diagnostics. That could be what's happening here.

added
A-diagnosticsArea: Messages for errors, warnings, and lints
D-confusingDiagnostics: Confusing error or lint that should be reworked.
on Nov 19, 2021
shepmaster

shepmaster commented on Nov 19, 2021

@shepmaster
Member

Yes, the playground uses the minimal profile, which doesn't include the rust-src component.

As an example:

 % cargo +1.56 build
...
note: `Option` could also refer to the enum defined here

% rustup component add --toolchain 1.56 rust-src

% cargo +1.56 build
...
note: `Option` could also refer to the enum defined here
   --> /Users/shep/.rustup/toolchains/1.56-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/prelude/mod.rs:133:13
    |
133 |     pub use core::prelude::rust_2021::*;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
changed the title [-]"X is ambiguous" error looks odd when one of the spans is missing[/-] [+]"X is ambiguous" error is missing a span when the standard library source is not available[/+] on Nov 19, 2021
added 3 commits that reference this issue on Dec 1, 2021

Rollup merge of rust-lang#91298 - FabianWolff:issue-91028-source-avai…

90af5e6

Rollup merge of rust-lang#91298 - FabianWolff:issue-91028-source-avai…

d51eeef

Rollup merge of rust-lang#91298 - FabianWolff:issue-91028-source-avai…

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @shepmaster@RalfJung@camelid

      Issue actions

        "X is ambiguous" error is missing a span when the standard library source is not available · Issue #91028 · rust-lang/rust