Skip to content

Extend rustc_on_unimplemented to allow pointing at enclosing function/closure #61709

Closed
@estebank

Description

@estebank

We should extend rustc_on_unimplemented to be able to point at the enclosing scope. With that capability, we could turn the following:

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src/lib.rs:28:31
   |
28 |                     let end = parse_range_u32(end)?;
   |                               ^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `std::ops::RangeInclusive<u32>`
   |
   = help: the trait `std::ops::Try` is not implemented for `std::ops::RangeInclusive<u32>`
   = note: required by `std::ops::Try::from_error`

into something along the lines of

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src/lib.rs:28:31
   |
24 |          .map(|range_spec| {
   |               -
   | ______________|
... |
28 ||                     let end = parse_range_u32(end)?;
   ||                               ^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `std::ops::RangeInclusive<u32>`
... |
48 ||         })
   ||         - this function should return `Result` or `Option` to accept `?`
   ||_________|
   |
   = help: the trait `std::ops::Try` is not implemented for `std::ops::RangeInclusive<u32>`
   = note: required by `std::ops::Try::from_error`

This has caused confusion in the wild.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`P-lowLow priorityT-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