Skip to content

Non-sense help when type parameter from outer function is used #51303

Closed
@nagisa

Description

@nagisa

Code

struct A;

impl A {
    fn banana(&mut self) {
        fn peach(this: &Self) {
            
        }
    }
}

Error

error[E0401]: can't use type parameters from outer function
 --> src/main.rs:9:25
  |
7 | impl A {
  | ---- `Self` type implicitely declared here, on the `impl`
8 |     fn banana(&mut self) {
9 |         fn peach(this: &Self) {
  |            -----        ^^^^ use of type variable from outer function
  |            |
  |            help: try using a local type parameter instead: `peach<Self>`

It seems that the help message is trying to suggest to introduce a local type parameter, but is worded rather poorly, as if suggesting to use a peach<Self> (e.g. this: &peach<Self>?).

Perhaps rewording the help message to explicitly say "introduce" rather than "use" would be better, but even then Self is a keyword, and cannot be introduced as a local generic parameter anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions