Skip to content

Span for "trait bound not satisfied" errors in case of trivial bounds too large #90869

Closed
@LukasKalbertodt

Description

@LukasKalbertodt
Member

Given the following code (Playground):

fn foo() where String: Copy {}

struct Bar;
impl Bar where String: Copy {}

The current output is:

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/lib.rs:1:1
  |
1 | fn foo() where String: Copy {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
  |
  = help: see issue #48214

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/lib.rs:4:1
  |
4 | impl Bar where String: Copy {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
  |
  = help: see issue #48214

Ideally the output should look like:

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/lib.rs:1:1
  |
1 | fn foo() where String: Copy {}
  |                ^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
  |
  = help: see issue #48214

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/lib.rs:4:1
  |
4 | impl Bar where String: Copy {}
  |                ^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
  |
  = help: see issue #48214

The difference is just the span. This is particularly useful for macros which are probably the main producers of trivial bounds. You want the "the trait bound not satisfied" error of emitted code to have a good span. But since rustc currently uses the span of the whole item, that's often not possible.

Related: #48214

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 13, 2021
Noratrieb

Noratrieb commented on Nov 13, 2021

@Noratrieb
Member

@rustbot claim

added 6 commits that reference this issue on Nov 15, 2021

Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…

8f7554b

Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…

0b05174

Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…

c0b9273

Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…

823b756

Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…

51c2c61

Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…

49ed5ca

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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

      Participants

      @LukasKalbertodt@Noratrieb

      Issue actions

        Span for "trait bound not satisfied" errors in case of trivial bounds too large · Issue #90869 · rust-lang/rust