Skip to content

Commit d672fea

Browse files
Use typeck_results to avoid duplicate ast_ty_to_ty call
1 parent 7210e46 commit d672fea

10 files changed

+27
-45
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -1791,19 +1791,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17911791
.flat_map(|a| a.args.iter())
17921792
{
17931793
if let hir::GenericArg::Type(hir_ty) = &arg {
1794-
if let hir::TyKind::Path(hir::QPath::TypeRelative(..)) =
1795-
&hir_ty.kind
1796-
{
1797-
// Avoid ICE with associated types. As this is best
1798-
// effort only, it's ok to ignore the case. It
1799-
// would trigger in `is_send::<T::AssocType>();`
1800-
// from `typeck-default-trait-impl-assoc-type.rs`.
1801-
} else {
1802-
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, hir_ty);
1803-
let ty = self.resolve_vars_if_possible(ty);
1804-
if ty == predicate.self_ty() {
1805-
error.obligation.cause.span = hir_ty.span;
1806-
}
1794+
let ty = self.resolve_vars_if_possible(
1795+
self.typeck_results.borrow().node_type(hir_ty.hir_id),
1796+
);
1797+
if ty == predicate.self_ty() {
1798+
error.obligation.cause.span = hir_ty.span;
18071799
}
18081800
}
18091801
}

src/test/ui/kindck/kindck-copy.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ LL | fn assert_copy<T:Copy>() { }
9191
| ^^^^ required by this bound in `assert_copy`
9292

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

105105
error[E0277]: the trait bound `Box<dyn Dummy + Send>: Copy` is not satisfied
106-
--> $DIR/kindck-copy.rs:43:5
106+
--> $DIR/kindck-copy.rs:43:19
107107
|
108108
LL | assert_copy::<Box<dyn Dummy + Send>>();
109-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
109+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
110110
|
111111
note: required by a bound in `assert_copy`
112112
--> $DIR/kindck-copy.rs:5:18

src/test/ui/not-panic/not-panic-safe.stderr

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

src/test/ui/traits/issue-32963.rs

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

src/test/ui/traits/issue-32963.stderr

+3-14
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,19 @@ LL | size_of_copy::<dyn Misc + Copy>();
99
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Misc + Copy {}`
1010
= 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>
1111

12-
error[E0225]: only auto traits can be used as additional traits in a trait object
13-
--> $DIR/issue-32963.rs:8:31
14-
|
15-
LL | size_of_copy::<dyn Misc + Copy>();
16-
| ---- ^^^^ additional non-auto trait
17-
| |
18-
| first non-auto trait
19-
|
20-
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Misc + Copy {}`
21-
= 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>
22-
2312
error[E0277]: the trait bound `dyn Misc: Copy` is not satisfied
24-
--> $DIR/issue-32963.rs:8:5
13+
--> $DIR/issue-32963.rs:8:20
2514
|
2615
LL | size_of_copy::<dyn Misc + Copy>();
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `dyn Misc`
16+
| ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `dyn Misc`
2817
|
2918
note: required by a bound in `size_of_copy`
3019
--> $DIR/issue-32963.rs:5:20
3120
|
3221
LL | fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
3322
| ^^^^ required by this bound in `size_of_copy`
3423

35-
error: aborting due to 3 previous errors
24+
error: aborting due to 2 previous errors
3625

3726
Some errors have detailed explanations: E0225, E0277.
3827
For more information about an error, try `rustc --explain E0225`.

src/test/ui/traits/suggest-where-clause.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ LL | pub const fn size_of<T>() -> usize {
8585
| ^ required by this bound in `std::mem::size_of`
8686

8787
error[E0277]: the size for values of type `[&U]` cannot be known at compilation time
88-
--> $DIR/suggest-where-clause.rs:31:5
88+
--> $DIR/suggest-where-clause.rs:31:20
8989
|
9090
LL | mem::size_of::<[&U]>();
91-
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
91+
| ^^^^ doesn't have a size known at compile-time
9292
|
9393
= help: the trait `Sized` is not implemented for `[&U]`
9494
note: required by a bound in `std::mem::size_of`

src/test/ui/typeck/typeck-default-trait-impl-assoc-type.stderr

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

src/test/ui/unboxed-closures/unboxed-closure-sugar-default.stderr

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

src/test/ui/unboxed-closures/unboxed-closure-sugar-equiv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn test<'a,'b>() {
4242
// Errors expected:
4343
eq::< dyn Foo<(),Output=()>,
4444
dyn Foo(char) >();
45-
//~^^ ERROR E0277
45+
//~^ ERROR E0277
4646
}
4747

4848
fn main() { }

src/test/ui/unboxed-closures/unboxed-closure-sugar-equiv.stderr

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

0 commit comments

Comments
 (0)