Closed
Description
For generic types, the prelude collision lint can produce suggestions that do not compile:
Code:
struct Generic<T>(T);
trait Hey { fn from_iter(_: i32) -> Self; }
impl Hey for Generic<i32> { fn from_iter(x: i32) -> Self { Self(x) } }
impl std::iter::FromIterator<i32> for Generic<i32> { fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self { todo!() } }
fn main() {
Generic::from_iter(1);
}
Suggestion from the prelude collision lint:
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
--> src/main.rs:10:5
|
10 | Generic::from_iter(1);
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic as Hey>::from_iter`
|
= note: `-W rust-2021-prelude-collisions` implied by `-W rust-2021-compatibility`
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021!
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
Error after applying the suggestion:
error[E0107]: missing generics for struct `Generic`
--> src/main.rs:10:6
|
10 | <Generic as Hey>::from_iter(1);
| ^^^^^^^ expected 1 generic argument
|