Skip to content

Commit

Permalink
Auto merge of #74735 - Aaron1011:fix/wf-impl-self-type, r=estebank
Browse files Browse the repository at this point in the history
Use the proper span when WF-checking an impl self type
  • Loading branch information
bors committed Jul 26, 2020
2 parents 8e5489c + 116ad51 commit a4dd850
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/librustc_trait_selection/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,21 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
trait_ref
.substs
.iter()
.filter(|arg| {
.enumerate()
.filter(|(_, arg)| {
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
})
.filter(|arg| !arg.has_escaping_bound_vars())
.map(|arg| {
.filter(|(_, arg)| !arg.has_escaping_bound_vars())
.map(|(i, arg)| {
let mut new_cause = cause.clone();
// The first subst is the self ty - use the correct span for it.
if i == 0 {
if let Some(hir::ItemKind::Impl { self_ty, .. }) = item.map(|i| &i.kind) {
new_cause.make_mut().span = self_ty.span;
}
}
traits::Obligation::new(
cause.clone(),
new_cause,
param_env,
ty::PredicateKind::WellFormed(arg).to_predicate(tcx),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:6
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:7:24
|
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
| ------------- ---- ...because method `eq` references the `Self` type in this parameter
| |
| this trait cannot be made into an object...
LL | impl NotObjectSafe for dyn NotObjectSafe { }
| ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
| ^^^^^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
|
= help: consider moving `eq` to another trait

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
= help: consider moving `foo` to another trait

error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:6
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:16
|
LL | trait NonObjectSafe1: Sized {}
| -------------- ----- ...because it requires `Self: Sized`
| |
| this trait cannot be made into an object...
...
LL | impl Trait for dyn NonObjectSafe1 {}
| ^^^^^ the trait `NonObjectSafe1` cannot be made into an object
| ^^^^^^^^^^^^^^^^^^ the trait `NonObjectSafe1` cannot be made into an object

error: aborting due to 5 previous errors

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-21837.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `T: Bound` is not satisfied
--> $DIR/issue-21837.rs:8:9
--> $DIR/issue-21837.rs:8:20
|
LL | pub struct Foo<T: Bound>(T);
| ----- required by this bound in `Foo`
...
LL | impl<T> Trait2 for Foo<T> {}
| ^^^^^^ the trait `Bound` is not implemented for `T`
| ^^^^^^ the trait `Bound` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/unsized/unsized-trait-impl-self-type.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized-trait-impl-self-type.rs:10:17
--> $DIR/unsized-trait-impl-self-type.rs:10:27
|
LL | struct S5<Y>(Y);
| - required by this bound in `S5`
LL |
LL | impl<X: ?Sized> T3<X> for S5<X> {
| - ^^^^^ doesn't have a size known at compile-time
| - ^^^^^ doesn't have a size known at compile-time
| |
| this type parameter needs to be `std::marker::Sized`
|
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/wf/wf-impl-self-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Tests that we point at the proper location for an error
// involving the self-type of an impl

trait Foo {}
impl Foo for Option<[u8]> {} //~ ERROR the size for

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/wf/wf-impl-self-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/wf-impl-self-type.rs:5:14
|
LL | impl Foo for Option<[u8]> {}
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
|
::: $SRC_DIR/libcore/option.rs:LL:COL
|
LL | pub enum Option<T> {
| - required by this bound in `std::option::Option`
|
= help: the trait `std::marker::Sized` is not implemented for `[u8]`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit a4dd850

Please sign in to comment.