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

rust_2021_prelude_collisions invalid suggestion when trait is glob imported #88471

Closed
ehuss opened this issue Aug 29, 2021 · 0 comments · Fixed by #88497
Closed

rust_2021_prelude_collisions invalid suggestion when trait is glob imported #88471

ehuss opened this issue Aug 29, 2021 · 0 comments · Fixed by #88497
Assignees
Labels
A-edition-2021 Area: The 2021 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 29, 2021

I tried this code:

#![allow(unused)]
#![warn(rust_2021_prelude_collisions)]

pub mod my_try {
    pub trait MyTry: Sized {
        fn try_from<V>(value: V) -> Result<Self, ()>;
    }
}

use my_try::*;

struct Foo;
struct Bar;

impl MyTry for Bar {
    fn try_from<V>(value: V) -> Result<Self, ()> {
        unimplemented!()
    }
}

pub fn foo() {
    let x = Foo;
    let y = Bar::try_from(x);
}

This has the suggestion to replace the code with:

    let y = <Bar as >::try_from(x);

which is invalid syntax. The suggestion should be something like:

    let y = <Bar as MyTry>::try_from(x);

Found in 2021 crater run for:

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (5eacec9ec 2021-08-28)
binary: rustc
commit-hash: 5eacec9ec7e112a0de1011519a57c45586d58414
commit-date: 2021-08-28
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 13.0.0
@ehuss ehuss added C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-edition-2021 Area: The 2021 edition labels Aug 29, 2021
@m-ou-se m-ou-se self-assigned this Aug 30, 2021
@bors bors closed this as completed in db44069 Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2021 Area: The 2021 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants