Skip to content

Commit ee98dc8

Browse files
restore spans for issue-50480
1 parent 8ba7436 commit ee98dc8

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

compiler/rustc_trait_selection/src/traits/misc.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,21 @@ pub fn can_type_implement_copy<'tcx>(
5050
continue;
5151
}
5252
let span = tcx.def_span(field.did);
53+
// FIXME(compiler-errors): This gives us better spans for bad
54+
// projection types like in issue-50480.
55+
// If the ADT has substs, point to the cause we are given.
56+
// If it does not, then this field probably doesn't normalize
57+
// to begin with, and point to the bad field's span instead.
58+
let cause = if field
59+
.ty(tcx, traits::InternalSubsts::identity_for_item(tcx, adt.did))
60+
.has_param_types_or_consts()
61+
{
62+
cause.clone()
63+
} else {
64+
ObligationCause::dummy_with_span(span)
65+
};
5366
let ctx = traits::FulfillmentContext::new();
54-
match traits::fully_normalize(&infcx, ctx, cause.clone(), param_env, ty) {
67+
match traits::fully_normalize(&infcx, ctx, cause, param_env, ty) {
5568
Ok(ty) => {
5669
if !infcx.type_is_copy_modulo_regions(param_env, ty, span) {
5770
infringing.push(field);

src/test/ui/issues/issue-50480.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#[derive(Clone, Copy)]
22
//~^ ERROR the trait `Copy` may not be implemented for this type
3-
//~| ERROR `i32` is not an iterator
43
struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
54
//~^ ERROR cannot find type `NotDefined` in this scope
65
//~| ERROR cannot find type `NotDefined` in this scope
76
//~| ERROR cannot find type `N` in this scope
87
//~| ERROR cannot find type `N` in this scope
8+
//~| ERROR `i32` is not an iterator
99

1010
#[derive(Clone, Copy)]
1111
//~^ ERROR the trait `Copy` may not be implemented for this type
12-
//~| ERROR `i32` is not an iterator
1312
struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
1413
//~^ ERROR cannot find type `NotDefined` in this scope
1514
//~| ERROR cannot find type `N` in this scope
15+
//~| ERROR `i32` is not an iterator
1616

1717
fn main() {}

src/test/ui/issues/issue-50480.stderr

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error[E0412]: cannot find type `N` in this scope
2-
--> $DIR/issue-50480.rs:4:12
2+
--> $DIR/issue-50480.rs:3:12
33
|
44
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
55
| -^ not found in this scope
66
| |
77
| help: you might be missing a type parameter: `<N>`
88

99
error[E0412]: cannot find type `NotDefined` in this scope
10-
--> $DIR/issue-50480.rs:4:15
10+
--> $DIR/issue-50480.rs:3:15
1111
|
1212
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
1313
| ^^^^^^^^^^ not found in this scope
1414

1515
error[E0412]: cannot find type `N` in this scope
16-
--> $DIR/issue-50480.rs:4:12
16+
--> $DIR/issue-50480.rs:3:12
1717
|
1818
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
1919
| -^ not found in this scope
2020
| |
2121
| help: you might be missing a type parameter: `<N>`
2222

2323
error[E0412]: cannot find type `NotDefined` in this scope
24-
--> $DIR/issue-50480.rs:4:15
24+
--> $DIR/issue-50480.rs:3:15
2525
|
2626
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
2727
| - ^^^^^^^^^^ not found in this scope
2828
| |
2929
| help: you might be missing a type parameter: `<NotDefined>`
3030

3131
error[E0412]: cannot find type `N` in this scope
32-
--> $DIR/issue-50480.rs:13:18
32+
--> $DIR/issue-50480.rs:12:18
3333
|
3434
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
3535
| - ^
@@ -46,27 +46,26 @@ LL | struct Bar<T, N>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, Strin
4646
| +++
4747

4848
error[E0412]: cannot find type `NotDefined` in this scope
49-
--> $DIR/issue-50480.rs:13:21
49+
--> $DIR/issue-50480.rs:12:21
5050
|
5151
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
5252
| ^^^^^^^^^^ not found in this scope
5353

5454
error[E0277]: `i32` is not an iterator
55-
--> $DIR/issue-50480.rs:1:17
55+
--> $DIR/issue-50480.rs:3:27
5656
|
57-
LL | #[derive(Clone, Copy)]
58-
| ^^^^ `i32` is not an iterator
57+
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
58+
| ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator
5959
|
6060
= help: the trait `Iterator` is not implemented for `i32`
6161
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
62-
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
6362

6463
error[E0204]: the trait `Copy` may not be implemented for this type
6564
--> $DIR/issue-50480.rs:1:17
6665
|
6766
LL | #[derive(Clone, Copy)]
6867
| ^^^^
69-
...
68+
LL |
7069
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
7170
| -------- ------ this field does not implement `Copy`
7271
| |
@@ -75,21 +74,20 @@ LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
7574
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
7675

7776
error[E0277]: `i32` is not an iterator
78-
--> $DIR/issue-50480.rs:10:17
77+
--> $DIR/issue-50480.rs:12:33
7978
|
80-
LL | #[derive(Clone, Copy)]
81-
| ^^^^ `i32` is not an iterator
79+
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
80+
| ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator
8281
|
8382
= help: the trait `Iterator` is not implemented for `i32`
8483
= note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
85-
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
8684

8785
error[E0204]: the trait `Copy` may not be implemented for this type
8886
--> $DIR/issue-50480.rs:10:17
8987
|
9088
LL | #[derive(Clone, Copy)]
9189
| ^^^^
92-
...
90+
LL |
9391
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
9492
| -------- ------ this field does not implement `Copy`
9593
| |

0 commit comments

Comments
 (0)