Rollup merge of #99352 - compiler-errors:tighter-spans-on-generic-call, r=spastorino

Use `typeck_results` to avoid duplicate `ast_ty_to_ty` call

Comes with a bunch of improvements in spans 😍
This commit is contained in:
Matthias Krüger 2022-07-20 18:58:15 +02:00 committed by GitHub
commit 43f6366da4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 45 deletions

View File

@ -1757,19 +1757,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.flat_map(|a| a.args.iter())
{
if let hir::GenericArg::Type(hir_ty) = &arg {
if let hir::TyKind::Path(hir::QPath::TypeRelative(..)) =
&hir_ty.kind
{
// Avoid ICE with associated types. As this is best
// effort only, it's ok to ignore the case. It
// would trigger in `is_send::<T::AssocType>();`
// from `typeck-default-trait-impl-assoc-type.rs`.
} else {
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, hir_ty);
let ty = self.resolve_vars_if_possible(ty);
if ty == predicate.self_ty() {
error.obligation.cause.span = hir_ty.span;
}
let ty = self.resolve_vars_if_possible(
self.typeck_results.borrow().node_type(hir_ty.hir_id),
);
if ty == predicate.self_ty() {
error.obligation.cause.span = hir_ty.span;
}
}
}

View File

@ -91,10 +91,10 @@ LL | fn assert_copy<T:Copy>() { }
| ^^^^ required by this bound in `assert_copy`
error[E0277]: the trait bound `Box<dyn Dummy>: Copy` is not satisfied
--> $DIR/kindck-copy.rs:42:5
--> $DIR/kindck-copy.rs:42:19
|
LL | assert_copy::<Box<dyn Dummy>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy>`
| ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy>`
|
note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18
@ -103,10 +103,10 @@ LL | fn assert_copy<T:Copy>() { }
| ^^^^ required by this bound in `assert_copy`
error[E0277]: the trait bound `Box<dyn Dummy + Send>: Copy` is not satisfied
--> $DIR/kindck-copy.rs:43:5
--> $DIR/kindck-copy.rs:43:19
|
LL | assert_copy::<Box<dyn Dummy + Send>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
|
note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18

View File

@ -1,8 +1,11 @@
error[E0277]: the type `&mut i32` may not be safely transferred across an unwind boundary
--> $DIR/not-panic-safe.rs:8:5
--> $DIR/not-panic-safe.rs:8:14
|
LL | assert::<&mut i32>();
| ^^^^^^^^^^^^^^^^^^ `&mut i32` may not be safely transferred across an unwind boundary
| -^^^^^^^
| |
| `&mut i32` may not be safely transferred across an unwind boundary
| help: consider removing the leading `&`-reference
|
= help: the trait `UnwindSafe` is not implemented for `&mut i32`
= note: `UnwindSafe` is implemented for `&i32`, but not for `&mut i32`

View File

@ -7,6 +7,5 @@ fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
fn main() {
size_of_copy::<dyn Misc + Copy>();
//~^ ERROR only auto traits can be used as additional traits in a trait object
//~| ERROR only auto traits can be used as additional traits in a trait object
//~| ERROR the trait bound `dyn Misc: Copy` is not satisfied
}

View File

@ -9,22 +9,11 @@ LL | size_of_copy::<dyn Misc + Copy>();
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Misc + Copy {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
error[E0225]: only auto traits can be used as additional traits in a trait object
--> $DIR/issue-32963.rs:8:31
|
LL | size_of_copy::<dyn Misc + Copy>();
| ---- ^^^^ additional non-auto trait
| |
| first non-auto trait
|
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Misc + Copy {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
error[E0277]: the trait bound `dyn Misc: Copy` is not satisfied
--> $DIR/issue-32963.rs:8:5
--> $DIR/issue-32963.rs:8:20
|
LL | size_of_copy::<dyn Misc + Copy>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `dyn Misc`
| ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `dyn Misc`
|
note: required by a bound in `size_of_copy`
--> $DIR/issue-32963.rs:5:20
@ -32,7 +21,7 @@ note: required by a bound in `size_of_copy`
LL | fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
| ^^^^ required by this bound in `size_of_copy`
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0225, E0277.
For more information about an error, try `rustc --explain E0225`.

View File

@ -85,10 +85,10 @@ LL | pub const fn size_of<T>() -> usize {
| ^ required by this bound in `std::mem::size_of`
error[E0277]: the size for values of type `[&U]` cannot be known at compilation time
--> $DIR/suggest-where-clause.rs:31:5
--> $DIR/suggest-where-clause.rs:31:20
|
LL | mem::size_of::<[&U]>();
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
| ^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[&U]`
note: required by a bound in `std::mem::size_of`

View File

@ -1,8 +1,8 @@
error[E0277]: `<T as Trait>::AssocType` cannot be sent between threads safely
--> $DIR/typeck-default-trait-impl-assoc-type.rs:11:5
--> $DIR/typeck-default-trait-impl-assoc-type.rs:11:15
|
LL | is_send::<T::AssocType>();
| ^^^^^^^^^^^^^^^^^^^^^^^ `<T as Trait>::AssocType` cannot be sent between threads safely
| ^^^^^^^^^^^^ `<T as Trait>::AssocType` cannot be sent between threads safely
|
= help: the trait `Send` is not implemented for `<T as Trait>::AssocType`
note: required by a bound in `is_send`

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `dyn Foo<(isize,), isize, Output = ()>: Eq<dyn Foo<(isize,), Output = ()>>` is not satisfied
--> $DIR/unboxed-closure-sugar-default.rs:21:5
--> $DIR/unboxed-closure-sugar-default.rs:21:10
|
LL | eq::<dyn Foo<(isize,), isize, Output=()>, dyn Foo(isize)>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq<dyn Foo<(isize,), Output = ()>>` is not implemented for `dyn Foo<(isize,), isize, Output = ()>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq<dyn Foo<(isize,), Output = ()>>` is not implemented for `dyn Foo<(isize,), isize, Output = ()>`
|
note: required by a bound in `eq`
--> $DIR/unboxed-closure-sugar-default.rs:14:40

View File

@ -42,7 +42,7 @@ fn test<'a,'b>() {
// Errors expected:
eq::< dyn Foo<(),Output=()>,
dyn Foo(char) >();
//~^^ ERROR E0277
//~^ ERROR E0277
}
fn main() { }

View File

@ -1,9 +1,8 @@
error[E0277]: the trait bound `dyn Foo<(char,), Output = ()>: Eq<dyn Foo<(), Output = ()>>` is not satisfied
--> $DIR/unboxed-closure-sugar-equiv.rs:43:5
--> $DIR/unboxed-closure-sugar-equiv.rs:44:11
|
LL | / eq::< dyn Foo<(),Output=()>,
LL | | dyn Foo(char) >();
| |_______________________________________________________________________^ the trait `Eq<dyn Foo<(), Output = ()>>` is not implemented for `dyn Foo<(char,), Output = ()>`
LL | dyn Foo(char) >();
| ^^^^^^^^^^^^^ the trait `Eq<dyn Foo<(), Output = ()>>` is not implemented for `dyn Foo<(char,), Output = ()>`
|
note: required by a bound in `eq`
--> $DIR/unboxed-closure-sugar-equiv.rs:16:28