Skip to content

"struct defined here" doesn't show where the struct is defined #89159

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
WaffleLapkin opened this issue Sep 21, 2021 · 2 comments · Fixed by #89233
Closed

"struct defined here" doesn't show where the struct is defined #89159

WaffleLapkin opened this issue Sep 21, 2021 · 2 comments · Fixed by #89233
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

When a struct defined outside of the current crate is used with not enough generics, the note in the error says "struct defined here" but doesn't show where.

Given the following code:

struct S<T>(T);

pub fn f(_: Box, _: S)  {}

The current output is:

error[E0107]: missing generics for struct `Box`
   --> src/lib.rs:3:13
    |
3   | pub fn f(_: Box, _: S)  {}
    |             ^^^ expected at least 1 generic argument
    |
note: struct defined here, with at least 1 generic parameter: `T`
help: add missing generic argument
    |
3   | pub fn f(_: Box<T>, _: S)  {}
    |             ~~~~~~

error[E0107]: missing generics for struct `S`
 --> src/lib.rs:3:21
  |
3 | pub fn f(_: Box, _: S)  {}
  |                     ^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `T`
 --> src/lib.rs:1:8
  |
1 | struct S<T>(T);
  |        ^ -
help: add missing generic argument
  |
3 | pub fn f(_: Box, _: S<T>)  {}
  |                     ~~~~

Ideally, the output should look like this:

error[E0107]: missing generics for struct `Box`
   --> ./test.rs:3:13
    |
3   | pub fn f(_: Box, _: S) {}
    |             ^^^ expected at least 1 generic argument
    |
note: struct defined here, with at least 1 generic parameter: `T`
   --> /.../repos/rust/library/alloc/src/boxed.rs:172:12
    |
172 | pub struct Box<
    |            ^^^
173 |     T: ?Sized,
    |     -
help: add missing generic argument
    |
3   | pub fn f(_: Box<T>, _: S) {}
    |             ~~~~~~

# error for S unchanged

I'm willing to work on this, though I don't have a clue why this is happening (yet). An interesting thing to notice is that the current box error is actually indented more, I suppose it's because Box is located on a 3 digit line (172, currently). So it's like that part of the error is somewhere, but it's lost?

@WaffleLapkin WaffleLapkin added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 21, 2021
@WaffleLapkin
Copy link
Member Author

Hmm, I can't reproduce this locally, but I see this happening on both playground and godbolt. Maybe it's caused by the unavailability of the rust-src component there?

@estebank
Copy link
Contributor

I believe we fall back to def_span for these, which should be available, but if they are not we should be hiding the message. Adding a check for DUMMY_SP might be enough, and if it isn't, then checking for a successful snippet would. It'll be hard to confirm without merging and trying in the playground without a repro case. (We might have some make tests that move the build files around to emulate this case already.)

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 28, 2021
Hide `<...> defined here` note if the source is not available

Fixes rust-lang#89159. Similar to rust-lang#87088.

r? `@estebank`
@bors bors closed this as completed in 3c60e04 Sep 29, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants