Skip to content
New issue

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

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

Already on GitHub? # to your account

Tracking issue for future-incompatbility lint ambiguous_associated_items #57644

Open
2 of 3 tasks
petrochenkov opened this issue Jan 15, 2019 · 1 comment
Open
2 of 3 tasks
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@petrochenkov
Copy link
Contributor

petrochenkov commented Jan 15, 2019

What is this lint about

With variants being resolved as inherent associated items (rust-lang/rfcs#2338) code like this become ambiguous:

enum E {
    V
}

trait Tr {
    type V;
    fn f() -> Self::V;
}

impl Tr for E {
    type V = u8;
    fn f() -> Self::V { 0 } // `Self::V` in type namespace may refer to both variant and associated type
}

This is not a problem right now, because variants cannot be used in type positions, but it may become a problem in the future if rust-lang/rfcs#2593 is accepted.
So this lints warns against cases like this and recommends to rewrite them as <Self as Tr>::V.

How to fix this warning/error

Explicitly disambiguate in favor of associated types from traits: <Type as Trait>::Ambiguous.

Current status

@petrochenkov petrochenkov added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-future-incompatibility Category: Future-incompatibility lints labels Jan 15, 2019
kennytm added a commit to kennytm/rust that referenced this issue May 2, 2019
Make deprecation lint `ambiguous_associated_items` deny-by-default

As requested by r? @Centril

cc rust-lang#57644
Centril added a commit to Centril/rust that referenced this issue May 2, 2019
Make deprecation lint `ambiguous_associated_items` deny-by-default

As requested by r? @Centril

cc rust-lang#57644
Centril added a commit to Centril/rust that referenced this issue May 3, 2019
Make deprecation lint `ambiguous_associated_items` deny-by-default

As requested by r? @Centril

cc rust-lang#57644
illicitonion pushed a commit to illicitonion/num_enum that referenced this issue Jun 30, 2019
Hello,

my enum looks like that:

```rust
#[derive(IntoPrimitive, TryFromPrimitive, Copy, Clone, PartialEq, Debug)]
#[repr(u8)]
pub enum BasicTokenNoPrefix {
    EndOfTokenisedLine = 0,
    StatementSeparator = 1,

    [...]
    Error,
    [...]
}
```

and I obtain this compilation error when using it:

```
error: ambiguous associated item
 --> src/basic/tokens.rs:7:10
  |
7 | #[derive(IntoPrimitive, TryFromPrimitive, Copy, Clone, PartialEq, Debug)]
  |          ^^^^^^^^^^^^^^^^
  |
  = note: #[deny(ambiguous_associated_items)] on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #57644 <rust-lang/rust#57644>
note: `Error` could refer to variant defined here
 --> src/basic/tokens.rs:145:5
  |
14|     Error,
  |     ^^^^^
note: `Error` could also refer to associated type defined here
```


This patch allows to fix this issue.
@mkpankov
Copy link
Contributor

Self::V in type namespace may refer to both variant and associated type

How is a variant present in type namespace? Syntactically only type is possible in that position, a function can't return a variant of an enum.

tylerwhall added a commit to tylerwhall/strum that referenced this issue Nov 18, 2021
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.

Example:

```rust
pub enum Test {
    Error,
}
```

error: ambiguous associated item
   --> src/lib.rs:3:10
    |
3   | #[derive(EnumString)]
    |          ^^^^^^^^^^
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
tylerwhall added a commit to tylerwhall/strum that referenced this issue Nov 18, 2021
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.

Example:

```rust
pub enum Test {
    Error,
}
```

error: ambiguous associated item
   --> src/lib.rs:3:10
    |
3   | #[derive(EnumString)]
    |          ^^^^^^^^^^
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
tylerwhall added a commit to tylerwhall/strum that referenced this issue Nov 18, 2021
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.

Example:

```rust
#[derive(EnumString)]
pub enum Test {
    Error,
}
```

error: ambiguous associated item
   --> src/lib.rs:3:10
    |
3   | #[derive(EnumString)]
    |          ^^^^^^^^^^
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
tylerwhall added a commit to tylerwhall/strum that referenced this issue Nov 18, 2021
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.

Example:

```rust
#[derive(EnumString)]
pub enum Test {
    Error,
}
```

error: ambiguous associated item
   --> src/lib.rs:3:10
    |
3   | #[derive(EnumString)]
    |          ^^^^^^^^^^
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
tylerwhall added a commit to tylerwhall/strum that referenced this issue Nov 19, 2021
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.

Example:

```rust
pub enum Test {
    Error,
}
```

error: ambiguous associated item
   --> src/lib.rs:3:10
    |
3   | #[derive(EnumString)]
    |          ^^^^^^^^^^
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
Peternator7 pushed a commit to Peternator7/strum that referenced this issue Nov 19, 2021
The addition of TryFrom<&str> for EnumString breaks for enums that have
a variant called "Error". Rewrite as <Self as Trait> where associated
types are used as the return type for trait functions.

Example:

```rust
pub enum Test {
    Error,
}
```

error: ambiguous associated item
   --> src/lib.rs:3:10
    |
3   | #[derive(EnumString)]
    |          ^^^^^^^^^^
    |
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
hunts pushed a commit to hunts/capnproto-rust that referenced this issue Jan 30, 2023
This was previously accepted by the compiler but is being
phased out; it will become a hard error in a future release!

See also: rust-lang/rust#57644
hunts added a commit to hunts/capnproto-rust that referenced this issue Jan 30, 2023
This was previously accepted by the compiler but is being
phased out; it will become a hard error in a future release!

See also: rust-lang/rust#57644
hunts added a commit to hunts/capnproto-rust that referenced this issue Jan 30, 2023
This was previously accepted by the compiler but is being
phased out; it will become a hard error in a future release!

See also: rust-lang/rust#57644
hunts added a commit to hunts/capnproto-rust that referenced this issue Jan 30, 2023
This was previously accepted by the compiler but is being
phased out; it will become a hard error in a future release!

See also: rust-lang/rust#57644
caspermeijn added a commit to caspermeijn/prost that referenced this issue Jul 9, 2024
The generated code uses `Self::Error` to refer to `::prost::UnknownEnumValue`, but the term `Error` is not unique when an enum variant is called `Error`. Use the full type name to resolve the ambiguity.

The compiler reported:
```
error: ambiguous associated item
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:2:68
    |
2   | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
    |                                                                    ^^^^^^^^^^^^^^^^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
note: `Error` could refer to the variant defined here
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:10:5
    |
10  |     Error = 4,
    |     ^^^^^
note: `Error` could also refer to the associated type defined here
   --> /home/ircdev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:682:5
    |
682 |     type Error;
    |     ^^^^^^^^^^
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = note: this error originates in the derive macro `::prost::Enumeration` (in Nightly builds, run with -Z macro-backtrace for more info)
```
github-merge-queue bot pushed a commit to tokio-rs/prost that referenced this issue Jul 9, 2024
The generated code uses `Self::Error` to refer to `::prost::UnknownEnumValue`, but the term `Error` is not unique when an enum variant is called `Error`. Use the full type name to resolve the ambiguity.

The compiler reported:
```
error: ambiguous associated item
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:2:68
    |
2   | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
    |                                                                    ^^^^^^^^^^^^^^^^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #57644 <rust-lang/rust#57644>
note: `Error` could refer to the variant defined here
   --> /home/ircdev/src/prost/target/debug/build/tests-no-std-e27db7197924752f/out/enum_keyword_variant.rs:10:5
    |
10  |     Error = 4,
    |     ^^^^^
note: `Error` could also refer to the associated type defined here
   --> /home/ircdev/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:682:5
    |
682 |     type Error;
    |     ^^^^^^^^^^
    = note: `#[deny(ambiguous_associated_items)]` on by default
    = note: this error originates in the derive macro `::prost::Enumeration` (in Nightly builds, run with -Z macro-backtrace for more info)
```
@fmease fmease changed the title Tracking issue for ambiguous_associated_items compatibility lint Tracking issue for future-incompatbility lint ambiguous_associated_items Sep 14, 2024
@fmease fmease added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC A-associated-items Area: Associated items (types, constants & functions) labels Sep 14, 2024
LilyFoote added a commit to PyO3/pyo3 that referenced this issue Nov 21, 2024
LilyFoote added a commit to PyO3/pyo3 that referenced this issue Nov 22, 2024
LilyFoote added a commit to PyO3/pyo3 that referenced this issue Nov 22, 2024
LilyFoote added a commit to PyO3/pyo3 that referenced this issue Nov 23, 2024
This uses the fix described in rust-lang/rust#57644

Also apply fix to `#[derive(IntoPyObject)]`.
LilyFoote added a commit to PyO3/pyo3 that referenced this issue Nov 23, 2024
This uses the fix described in rust-lang/rust#57644

Also apply fix to `#[derive(IntoPyObject)]`.
github-merge-queue bot pushed a commit to PyO3/pyo3 that referenced this issue Nov 23, 2024
* Add test for ambiguous associated item

The `#[pyclass]` macro implements `IntoPyObject` for the annotated enum.
When the enum has any of `Error`, `Output` or `Target` as members, this
clashes with the associated types of `IntoPyObject`.

This also happens when deriving `IntoPyObject` directly.

* Fix #4723: ambiguous associated item in #[pyclass]

This uses the fix described in rust-lang/rust#57644

Also apply fix to `#[derive(IntoPyObject)]`.
davidhewitt pushed a commit to PyO3/pyo3 that referenced this issue Nov 25, 2024
* Add test for ambiguous associated item

The `#[pyclass]` macro implements `IntoPyObject` for the annotated enum.
When the enum has any of `Error`, `Output` or `Target` as members, this
clashes with the associated types of `IntoPyObject`.

This also happens when deriving `IntoPyObject` directly.

* Fix #4723: ambiguous associated item in #[pyclass]

This uses the fix described in rust-lang/rust#57644

Also apply fix to `#[derive(IntoPyObject)]`.
davidhewitt pushed a commit to PyO3/pyo3 that referenced this issue Nov 25, 2024
* Add test for ambiguous associated item

The `#[pyclass]` macro implements `IntoPyObject` for the annotated enum.
When the enum has any of `Error`, `Output` or `Target` as members, this
clashes with the associated types of `IntoPyObject`.

This also happens when deriving `IntoPyObject` directly.

* Fix #4723: ambiguous associated item in #[pyclass]

This uses the fix described in rust-lang/rust#57644

Also apply fix to `#[derive(IntoPyObject)]`.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

No branches or pull requests

3 participants