Skip to content

Commit 0087834

Browse files
committed
[PERF] check if walking the bodies is the expensive part
1 parent 65ab1c7 commit 0087834

File tree

5 files changed

+89
-7
lines changed

5 files changed

+89
-7
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ fn opaque_types_defined_by<'tcx>(
328328
| DefKind::Const
329329
| DefKind::AssocConst
330330
| DefKind::AnonConst => {
331-
collector.collect_taits_declared_in_body();
331+
if tcx.features().type_alias_impl_trait {
332+
collector.collect_taits_declared_in_body();
333+
}
332334
}
333335
DefKind::OpaqueTy
334336
| DefKind::TyAlias

tests/ui/pattern/usefulness/issue-119493-type-error-ice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ fn foo() {
99
type U = impl Copy;
1010
//~^ ERROR `impl Trait` in type aliases is unstable
1111
let foo: U = Foo(());
12+
//~^ ERROR mismatched types
1213
let Foo(()) = foo;
14+
//~^ ERROR mismatched types
1315
}

tests/ui/pattern/usefulness/issue-119493-type-error-ice.stderr

+41-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,45 @@ LL | type U = impl Copy;
2525
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
2626
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2727

28-
error: aborting due to 3 previous errors
28+
error[E0308]: mismatched types
29+
--> $DIR/issue-119493-type-error-ice.rs:11:18
30+
|
31+
LL | type U = impl Copy;
32+
| --------- the expected opaque type
33+
LL |
34+
LL | let foo: U = Foo(());
35+
| - ^^^^^^^ expected opaque type, found `Foo`
36+
| |
37+
| expected due to this
38+
|
39+
= note: expected opaque type `U`
40+
found struct `Foo`
41+
note: this item must have the opaque type in its signature in order to be able to register hidden types
42+
--> $DIR/issue-119493-type-error-ice.rs:3:4
43+
|
44+
LL | fn foo() {
45+
| ^^^
46+
47+
error[E0308]: mismatched types
48+
--> $DIR/issue-119493-type-error-ice.rs:13:9
49+
|
50+
LL | type U = impl Copy;
51+
| --------- the expected opaque type
52+
...
53+
LL | let Foo(()) = foo;
54+
| ^^^^^^^ --- this expression has type `U`
55+
| |
56+
| expected opaque type, found `Foo`
57+
|
58+
= note: expected opaque type `U`
59+
found struct `Foo`
60+
note: this item must have the opaque type in its signature in order to be able to register hidden types
61+
--> $DIR/issue-119493-type-error-ice.rs:3:4
62+
|
63+
LL | fn foo() {
64+
| ^^^
65+
66+
error: aborting due to 5 previous errors
2967

30-
Some errors have detailed explanations: E0412, E0658.
31-
For more information about an error, try `rustc --explain E0412`.
68+
Some errors have detailed explanations: E0308, E0412, E0658.
69+
For more information about an error, try `rustc --explain E0308`.

tests/ui/pattern/usefulness/issue-119778-type-error-ice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ fn foo() {
99
type U = impl Copy;
1010
//~^ ERROR `impl Trait` in type aliases is unstable
1111
let foo: U = Foo(());
12+
//~^ ERROR mismatched types
1213
let Foo(()) = foo;
14+
//~^ ERROR mismatched types
1315
}

tests/ui/pattern/usefulness/issue-119778-type-error-ice.stderr

+41-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,45 @@ LL | type U = impl Copy;
3030
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
3131
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3232

33-
error: aborting due to 3 previous errors
33+
error[E0308]: mismatched types
34+
--> $DIR/issue-119778-type-error-ice.rs:11:18
35+
|
36+
LL | type U = impl Copy;
37+
| --------- the expected opaque type
38+
LL |
39+
LL | let foo: U = Foo(());
40+
| - ^^^^^^^ expected opaque type, found `Foo`
41+
| |
42+
| expected due to this
43+
|
44+
= note: expected opaque type `U`
45+
found struct `Foo`
46+
note: this item must have the opaque type in its signature in order to be able to register hidden types
47+
--> $DIR/issue-119778-type-error-ice.rs:3:4
48+
|
49+
LL | fn foo() {
50+
| ^^^
51+
52+
error[E0308]: mismatched types
53+
--> $DIR/issue-119778-type-error-ice.rs:13:9
54+
|
55+
LL | type U = impl Copy;
56+
| --------- the expected opaque type
57+
...
58+
LL | let Foo(()) = foo;
59+
| ^^^^^^^ --- this expression has type `U`
60+
| |
61+
| expected opaque type, found `Foo`
62+
|
63+
= note: expected opaque type `U`
64+
found struct `Foo`
65+
note: this item must have the opaque type in its signature in order to be able to register hidden types
66+
--> $DIR/issue-119778-type-error-ice.rs:3:4
67+
|
68+
LL | fn foo() {
69+
| ^^^
70+
71+
error: aborting due to 5 previous errors
3472

35-
Some errors have detailed explanations: E0425, E0658.
36-
For more information about an error, try `rustc --explain E0425`.
73+
Some errors have detailed explanations: E0308, E0425, E0658.
74+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)