Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RalfJung opened this issue Nov 19, 2021 · 3 comments · Fixed by #91298
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked.

Comments

@RalfJung
Copy link
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

@shepmaster
Copy link
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
Copy link
Member

camelid commented Nov 19, 2021

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

@shepmaster shepmaster added A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Nov 19, 2021
@shepmaster
Copy link
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::*;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^

@shepmaster shepmaster 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 Nov 19, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 1, 2021
…l, r=cjgillot

Improve error message for `E0659` if the source is not available

Fixes rust-lang#91028. The fix is similar to those in rust-lang#89233 and rust-lang#87088. With this change, instead of the dangling
```
note: `Option` could also refer to the enum defined here
```
I get
```
note: `Option` could also refer to an enum from prelude
```
If the standard library source code _is_ available, the output does not change.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 1, 2021
…l, r=cjgillot

Improve error message for `E0659` if the source is not available

Fixes rust-lang#91028. The fix is similar to those in rust-lang#89233 and rust-lang#87088. With this change, instead of the dangling
```
note: `Option` could also refer to the enum defined here
```
I get
```
note: `Option` could also refer to an enum from prelude
```
If the standard library source code _is_ available, the output does not change.
@bors bors closed this as completed in c09c16c Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants