Skip to content

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

Closed
@LukasKalbertodt

Description

@LukasKalbertodt

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

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

Issue actions