Auto merge of #74735 - Aaron1011:fix/wf-impl-self-type, r=estebank

Use the proper span when WF-checking an impl self type
This commit is contained in:
bors 2020-07-26 03:03:19 +00:00
commit a4dd850720
7 changed files with 43 additions and 12 deletions

View File

@ -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),
)

View File

@ -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

View File

@ -52,7 +52,7 @@ 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`
@ -60,7 +60,7 @@ LL | trait NonObjectSafe1: 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

View File

@ -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`
|

View File

@ -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`
|

View File

@ -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() {}

View File

@ -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`.