Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
LukasKalbertodt opened this issue Nov 13, 2021 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@LukasKalbertodt
Copy link
Member

LukasKalbertodt commented Nov 13, 2021

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

@LukasKalbertodt LukasKalbertodt added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 13, 2021
@Noratrieb
Copy link
Member

@rustbot claim

Noratrieb added a commit to Noratrieb/rust that referenced this issue Nov 14, 2021
The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 15, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 15, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2021
…und, r=estebank

Fix span for non-satisfied trivial trait bounds

The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before.
Now they only reference the obligation itself (`String: Copy`)

Address rust-lang#90869
@Noratrieb
Copy link
Member

It's fixed now and soon coming to a nightly near you :)

@Noratrieb
Copy link
Member

@LukasKalbertodt the issue wasn't linked to the PR, so you'll have to close it manually

@LukasKalbertodt
Copy link
Member Author

Oh, true. Thanks for solving this so quickly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants