Skip to content

Commit

Permalink
restore spans for issue-50480
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 24, 2022
1 parent 8ba7436 commit ee98dc8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
15 changes: 14 additions & 1 deletion compiler/rustc_trait_selection/src/traits/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,21 @@ pub fn can_type_implement_copy<'tcx>(
continue;
}
let span = tcx.def_span(field.did);
// FIXME(compiler-errors): This gives us better spans for bad
// projection types like in issue-50480.
// If the ADT has substs, point to the cause we are given.
// If it does not, then this field probably doesn't normalize
// to begin with, and point to the bad field's span instead.
let cause = if field
.ty(tcx, traits::InternalSubsts::identity_for_item(tcx, adt.did))
.has_param_types_or_consts()
{
cause.clone()
} else {
ObligationCause::dummy_with_span(span)
};
let ctx = traits::FulfillmentContext::new();
match traits::fully_normalize(&infcx, ctx, cause.clone(), param_env, ty) {
match traits::fully_normalize(&infcx, ctx, cause, param_env, ty) {
Ok(ty) => {
if !infcx.type_is_copy_modulo_regions(param_env, ty, span) {
infringing.push(field);
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-50480.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#[derive(Clone, Copy)]
//~^ ERROR the trait `Copy` may not be implemented for this type
//~| ERROR `i32` is not an iterator
struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
//~^ ERROR cannot find type `NotDefined` in this scope
//~| ERROR cannot find type `NotDefined` in this scope
//~| ERROR cannot find type `N` in this scope
//~| ERROR cannot find type `N` in this scope
//~| ERROR `i32` is not an iterator

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

fn main() {}
30 changes: 14 additions & 16 deletions src/test/ui/issues/issue-50480.stderr
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
error[E0412]: cannot find type `N` in this scope
--> $DIR/issue-50480.rs:4:12
--> $DIR/issue-50480.rs:3:12
|
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| -^ not found in this scope
| |
| help: you might be missing a type parameter: `<N>`

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

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

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

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

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

error[E0277]: `i32` is not an iterator
--> $DIR/issue-50480.rs:1:17
--> $DIR/issue-50480.rs:3:27
|
LL | #[derive(Clone, Copy)]
| ^^^^ `i32` is not an iterator
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator
|
= help: the trait `Iterator` is not implemented for `i32`
= 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`
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

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

error[E0277]: `i32` is not an iterator
--> $DIR/issue-50480.rs:10:17
--> $DIR/issue-50480.rs:12:33
|
LL | #[derive(Clone, Copy)]
| ^^^^ `i32` is not an iterator
LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator
|
= help: the trait `Iterator` is not implemented for `i32`
= 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`
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

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

0 comments on commit ee98dc8

Please sign in to comment.