Use typeck_results to avoid duplicate ast_ty_to_ty call

This commit is contained in:
Michael Goulet 2022-07-16 22:34:22 +00:00
parent 7210e46dc6
commit d672fea64a
10 changed files with 27 additions and 45 deletions

View File

@ -1791,19 +1791,11 @@ fn point_at_type_arg_instead_of_call_if_possible(
.flat_map(|a| a.args.iter()) .flat_map(|a| a.args.iter())
{ {
if let hir::GenericArg::Type(hir_ty) = &arg { if let hir::GenericArg::Type(hir_ty) = &arg {
if let hir::TyKind::Path(hir::QPath::TypeRelative(..)) = let ty = self.resolve_vars_if_possible(
&hir_ty.kind self.typeck_results.borrow().node_type(hir_ty.hir_id),
{ );
// Avoid ICE with associated types. As this is best if ty == predicate.self_ty() {
// effort only, it's ok to ignore the case. It error.obligation.cause.span = hir_ty.span;
// 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;
}
} }
} }
} }

View File

@ -91,10 +91,10 @@ LL | fn assert_copy<T:Copy>() { }
| ^^^^ required by this bound in `assert_copy` | ^^^^ required by this bound in `assert_copy`
error[E0277]: the trait bound `Box<dyn Dummy>: Copy` is not satisfied 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>>(); 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` note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18 --> $DIR/kindck-copy.rs:5:18
@ -103,10 +103,10 @@ LL | fn assert_copy<T:Copy>() { }
| ^^^^ required by this bound in `assert_copy` | ^^^^ required by this bound in `assert_copy`
error[E0277]: the trait bound `Box<dyn Dummy + Send>: Copy` is not satisfied 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>>(); 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` note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18 --> $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 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>(); 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` = help: the trait `UnwindSafe` is not implemented for `&mut i32`
= note: `UnwindSafe` is implemented for `&i32`, but not 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() { fn main() {
size_of_copy::<dyn Misc + Copy>(); 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 only auto traits can be used as additional traits in a trait object
//~| ERROR the trait bound `dyn Misc: Copy` is not satisfied //~| 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 {}` = 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> = 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 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>(); 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` note: required by a bound in `size_of_copy`
--> $DIR/issue-32963.rs:5:20 --> $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>() } LL | fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
| ^^^^ required by this bound in `size_of_copy` | ^^^^ 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. Some errors have detailed explanations: E0225, E0277.
For more information about an error, try `rustc --explain E0225`. 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` | ^ required by this bound in `std::mem::size_of`
error[E0277]: the size for values of type `[&U]` cannot be known at compilation time 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]>(); 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]` = help: the trait `Sized` is not implemented for `[&U]`
note: required by a bound in `std::mem::size_of` 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 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>(); 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` = help: the trait `Send` is not implemented for `<T as Trait>::AssocType`
note: required by a bound in `is_send` 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 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)>(); 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` note: required by a bound in `eq`
--> $DIR/unboxed-closure-sugar-default.rs:14:40 --> $DIR/unboxed-closure-sugar-default.rs:14:40

View File

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

View File

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