Skip to content

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

Closed
@WaffleLapkin

Description

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?

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions