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

Weird help message suggest to place use randomly, when a macro is called in scope #42548

Closed
kennytm opened this issue Jun 8, 2017 · 3 comments · Fixed by #43929
Closed

Weird help message suggest to place use randomly, when a macro is called in scope #42548

kennytm opened this issue Jun 8, 2017 · 3 comments · Fixed by #43929
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@kennytm
Copy link
Member

kennytm commented Jun 8, 2017

Repro case (1.19.0-beta.1 as well as nightly):

macro_rules! y {
    () => {}
}
mod m {
    pub const A: i32 = 0;
}
fn main() {
    y!();
    let _ = A;
}

When running it in nightly, it produces a weird error message:

error[E0425]: cannot find value `A` in this scope
 --> 1.rs:9:13
  |
9 |     let _ = A;
  |             ^ not found in this scope
  |
help: possible candidate is found in another module, you can import it into scope
  | fn main() use m::A;

error: aborting due to previous error(s)
No repro on 1.18 or before
error[E0425]: cannot find value `A` in this scope
 --> <source>:9:13
  |
9 |     let _ = A;
  |             ^ not found in this scope
  |
  = help: possible candidate is found in another module, you can import it into scope:
            `use m::A;`
error: aborting due to previous error
Version
rustc 1.19.0-nightly (f062832b2 2017-06-07)
binary: rustc
commit-hash: f062832b208e94f2f0f26ed7fb5c48c172069fbe
commit-date: 2017-06-07
host: x86_64-apple-darwin
release: 1.19.0-nightly
LLVM version: 4.0
@oli-obk
Copy link
Contributor

oli-obk commented Jun 8, 2017

This is due to #41876

The suggestion placement span is unfortunate. It seems the opening brace belongs to the span of the scope where the import failed. The suggestion should be placed after the opening brace.

I'm not sure why the macro invocation messes up the spans... it works fine without macros

@Mark-Simulacrum
Copy link
Member

@oli-obk Do you know why the suggestion puts fn main() in? I'm worried that new users will find that surprising and odd; perhaps we should revert some part (or all of) #41876 for now?

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 23, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Jun 23, 2017

The issue only occurs with macros or desugarings at the beginning of the function. I plan a general fix to improve the placement, this should simply get fixed in the process

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
bors added a commit that referenced this issue Aug 21, 2017
Improve placement of `use` suggestions

r? @nrc

cc @estebank @Mark-Simulacrum

fixes #42835
fixes #42548
fixes #43769
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-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants