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

bad suggestion line for use statements with a derive #44995

Closed
arielb1 opened this issue Oct 3, 2017 · 5 comments
Closed

bad suggestion line for use statements with a derive #44995

arielb1 opened this issue Oct 3, 2017 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Oct 3, 2017

#[derive(Debug)]
pub struct X;

impl Add for X {} // trigger unused import

fn main() {}

After #44215, this gives the following error message:

error[E0405]: cannot find trait `Add` in this scope
 --> x.rs:4:6
  |
4 | impl Add for X {} // trigger unused import
  |      ^^^ not found in this scope
  |
help: possible candidate is found in another module, you can import it into scope
  |
2 | use std::ops::Add; // <--- LINE 2 HERE
  |

error: cannot continue compilation due to previous error

This suggests placing the use-statement at line 2, which is between the #[derive] and the pub struct X; line, while we want to place the use statement before the #[derive].

cc @oli-obk

@arielb1 arielb1 added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 3, 2017
@arielb1 arielb1 changed the title fix suggestion span for use statements with a derive fix suggestion line for use statements with a derive Oct 3, 2017
@arielb1 arielb1 changed the title fix suggestion line for use statements with a derive bad suggestion line for use statements with a derive Oct 3, 2017
@arielb1
Copy link
Contributor Author

arielb1 commented Oct 3, 2017

This remains after the regression in #44566 was fixed.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 13, 2017

As mentioned in #44566, this is impossible to fix right now, because these attributes do not exist anymore at the lint stage. Solutions are noted in #44215 (comment)

@euclio
Copy link
Contributor

euclio commented Mar 5, 2019

cc #45216.

@programmerjake
Copy link
Member

Can this be given a higher priority, it seems to me like a big gotcha for beginners.

An additional way to fix this might be to track the location where use and similar statements should be inserted in blocks, rather than taking the first token of the first post-expansion item. This avoids the need to keep attributes post-expansion.

@oli-obk oli-obk added the D-papercut Diagnostics: An error or lint that needs small tweaks. label May 31, 2020
@compiler-errors
Copy link
Member

This now suggests the right span.

error[[E0405]](https://doc.rust-lang.org/stable/error-index.html#E0405): cannot find trait `Add` in this scope
 --> src/main.rs:4:6
  |
4 | impl Add for X {} // trigger unused import
  |      ^^^ not found in this scope
  |
help: consider importing one of these items
  |
1 | [use core::ops::Add;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018#)
  |
1 | [use nom::lib::std::ops::Add;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018#)
  |
1 | [use pin_utils::core_reexport::ops::Add;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018#)
  |
1 | [use std::ops::Add;](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018#)
  |

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 C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants