Skip to content

Elide generic arguments in "no method found" errors if they're irrelevant #81576

Closed
@scottmcm

Description

@scottmcm

Inspired by this question on discord:

no method named extend found for struct Map<std::iter::Chain<Map<Windows<'_, Point>, [closure@src\graphics\slider.rs:39:22: 47:18]>, std::iter::Once<Point>>, [closure@src\graphics\slider.rs:49:22: 49:60]> in the current scope

how does map not have .extend

Repro: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e270ca9a0ae009a8f34af6bc31c0ce90

fn main() {
    let v = vec![1_i32, 2, 3];
    v.iter().map(|x| x * x).extend(std::iter::once(100));
}

Error:

error[E0599]: no method named `extend` found for struct `Map<std::slice::Iter<'_, i32>, [closure@src/main.rs:3:18: 3:27]>` in the current scope
 --> src/main.rs:3:29
  |
3 |     v.iter().map(|x| x * x).extend(std::iter::once(100));
  |                             ^^^^^^ method not found in `Map<std::slice::Iter<'_, i32>, [closure@src/main.rs:3:18: 3:27]>`

It would be nice if rustc could notice that Map<T> never has extend for any T, and use that information to simplify the error message to just

error[E0599]: no method named `extend` found for struct `Map<_>` in the current scope

in order to focus the user better on the relevant part.

Can the name resolution engine do that? (It can for a generic parameter, of course, but then it's only looking at the known trait bounds, which is a little different.)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-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