Closed
Description
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
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
derive(Pod)
should work forrepr(c)
structs with generics fields where all fields have the same type Lokathor/bytemuck#75Noratrieb commentedon Nov 13, 2021
@rustbot claim
Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…
Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…
Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…
Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…
Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…
Rollup merge of rust-lang#90884 - Nilstrieb:fix-span-trivial-trait-bo…
6 remaining items