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

Confusing not trait error message #10361

Closed
klutzy opened this issue Nov 8, 2013 · 4 comments
Closed

Confusing not trait error message #10361

klutzy opened this issue Nov 8, 2013 · 4 comments

Comments

@klutzy
Copy link
Contributor

klutzy commented Nov 8, 2013

use t::T;
mod t {
    pub trait T {}
}

struct S;

impl T for S {}

impl T {} // oops

fn main() {}
a.rs:8:5: 8:6 error: T is not a trait
a.rs:8 impl T for S {}
            ^

This should show better error message. If trait T is not in mod, rustc prints "duplicate definition of module T".

@klutzy
Copy link
Contributor Author

klutzy commented Nov 8, 2013

If S is completely omitted, rustc prints found value name used as a type: DefMod(syntax::ast::DefId{crate: 0, node: 10}). This also looks bad.

@jdm
Copy link
Contributor

jdm commented Nov 9, 2013

That's covered in #8767.

@steveklabnik
Copy link
Member

Just tried this out, the error is identical today.

@steveklabnik
Copy link
Member

This error is much better:

hello.rs:10:1: 10:10 error: inherent implementations are only allowed on types defined in the current module [E0257]
hello.rs:10 impl T {} // oops
            ^~~~~~~~~
hello.rs:1:5: 1:9 note: import from other module here
hello.rs:1 use t::T;
               ^~~~

I'm going to consider this one closed.

Jarcho pushed a commit to Jarcho/rust that referenced this issue Feb 26, 2023
Stop bytes_nth from suggesting code that does not compile

Fixes rust-lang#10151

As discussed in the issue, this PR changes the lint in 2 ways

1. Replace `bytes().nth(n).unwrap()` with `as_bytes()[n]`
2. Replace other `bytes().nth(n)` with `as_bytes().get(n).copied()`

---

changelog: Stop bytes_nth from suggesting code that does not compile in some cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants