Skip to content

Commit a5094fc

Browse files
committed
Collect mod item types in parallel, just like wfcheck
1 parent fbe7943 commit a5094fc

5 files changed

+83
-6
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+25-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ mod type_of;
5555
// Main entry point
5656

5757
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
58-
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CollectItemTypesVisitor { tcx });
58+
let items = tcx.hir_module_items(module_def_id);
59+
let hir = tcx.hir();
60+
let _ = items.par_items(|item| Ok(CollectItemTypesVisitor { tcx }.visit_item(hir.item(item))));
61+
let _ = items.par_trait_items(|item| {
62+
Ok(CollectItemTypesVisitor { tcx }.visit_trait_item(hir.trait_item(item)))
63+
});
64+
let _ = items.par_impl_items(|item| {
65+
Ok(CollectItemTypesVisitor { tcx }.visit_impl_item(hir.impl_item(item)))
66+
});
67+
let _ = items.par_foreign_items(|item| {
68+
Ok(CollectItemTypesVisitor { tcx }.visit_foreign_item(hir.foreign_item(item)))
69+
});
5970
}
6071

6172
pub fn provide(providers: &mut Providers) {
@@ -1025,7 +1036,19 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
10251036

10261037
let is_anonymous = item.ident.name == kw::Empty;
10271038
let repr = if is_anonymous {
1028-
tcx.adt_def(tcx.local_parent(def_id)).repr()
1039+
let mut def_id = def_id;
1040+
loop {
1041+
def_id = tcx.local_parent(def_id);
1042+
if let Node::Item(_) = tcx.hir_node_by_def_id(def_id) {
1043+
break;
1044+
} else {
1045+
tcx.dcx().span_delayed_bug(
1046+
tcx.def_span(def_id),
1047+
"invalid anonymous adt position, already got rejected in ast validation",
1048+
);
1049+
}
1050+
}
1051+
tcx.adt_def(def_id).repr()
10291052
} else {
10301053
tcx.repr_options_of_def(def_id)
10311054
};

tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.rs

+2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ impl<'a, T> Struct<T> for Trait<'a, T> {}
1515

1616
impl<'a, T> Enum<T> for Trait<'a, T> {}
1717
//~^ ERROR expected trait, found enum `Enum`
18+
//~| ERROR trait objects must include the `dyn` keyword
1819

1920
impl<'a, T> Union<T> for Trait<'a, T> {}
2021
//~^ ERROR expected trait, found union `Union`
22+
//~| ERROR trait objects must include the `dyn` keyword
2123

2224
fn main() {}

tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr

+24-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LL | impl<'a, T> Trait<'a, T> for Enum<T> {}
2121
| ~~~~~~~~~~~~ ~~~~~~~
2222

2323
error[E0404]: expected trait, found union `Union`
24-
--> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:19:13
24+
--> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:20:13
2525
|
2626
LL | impl<'a, T> Union<T> for Trait<'a, T> {}
2727
| ^^^^^^^^ not a trait
@@ -42,7 +42,29 @@ help: add `dyn` keyword before this trait
4242
LL | impl<'a, T> Struct<T> for dyn Trait<'a, T> {}
4343
| +++
4444

45-
error: aborting due to 4 previous errors
45+
error[E0782]: trait objects must include the `dyn` keyword
46+
--> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:16:25
47+
|
48+
LL | impl<'a, T> Enum<T> for Trait<'a, T> {}
49+
| ^^^^^^^^^^^^
50+
|
51+
help: add `dyn` keyword before this trait
52+
|
53+
LL | impl<'a, T> Enum<T> for dyn Trait<'a, T> {}
54+
| +++
55+
56+
error[E0782]: trait objects must include the `dyn` keyword
57+
--> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:20:26
58+
|
59+
LL | impl<'a, T> Union<T> for Trait<'a, T> {}
60+
| ^^^^^^^^^^^^
61+
|
62+
help: add `dyn` keyword before this trait
63+
|
64+
LL | impl<'a, T> Union<T> for dyn Trait<'a, T> {}
65+
| +++
66+
67+
error: aborting due to 6 previous errors
4668

4769
Some errors have detailed explanations: E0404, E0782.
4870
For more information about an error, try `rustc --explain E0404`.

tests/ui/suggestions/suggest-swapping-self-ty-and-trait.rs

+4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ impl<'a, T> Struct<T> for Trait<'a, T> {}
1414

1515
impl<'a, T> Enum<T> for Trait<'a, T> {}
1616
//~^ ERROR expected trait, found enum `Enum`
17+
//~| WARNING trait objects without an explicit `dyn` are deprecated
18+
//~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
1719

1820
impl<'a, T> Union<T> for Trait<'a, T> {}
1921
//~^ ERROR expected trait, found union `Union`
22+
//~| WARNING trait objects without an explicit `dyn` are deprecated
23+
//~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
2024

2125
fn main() {}

tests/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr

+28-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LL | impl<'a, T> Trait<'a, T> for Enum<T> {}
2121
| ~~~~~~~~~~~~ ~~~~~~~
2222

2323
error[E0404]: expected trait, found union `Union`
24-
--> $DIR/suggest-swapping-self-ty-and-trait.rs:18:13
24+
--> $DIR/suggest-swapping-self-ty-and-trait.rs:20:13
2525
|
2626
LL | impl<'a, T> Union<T> for Trait<'a, T> {}
2727
| ^^^^^^^^ not a trait
@@ -45,6 +45,32 @@ help: if this is an object-safe trait, use `dyn`
4545
LL | impl<'a, T> Struct<T> for dyn Trait<'a, T> {}
4646
| +++
4747

48-
error: aborting due to 3 previous errors; 1 warning emitted
48+
warning: trait objects without an explicit `dyn` are deprecated
49+
--> $DIR/suggest-swapping-self-ty-and-trait.rs:15:25
50+
|
51+
LL | impl<'a, T> Enum<T> for Trait<'a, T> {}
52+
| ^^^^^^^^^^^^
53+
|
54+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
55+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
56+
help: if this is an object-safe trait, use `dyn`
57+
|
58+
LL | impl<'a, T> Enum<T> for dyn Trait<'a, T> {}
59+
| +++
60+
61+
warning: trait objects without an explicit `dyn` are deprecated
62+
--> $DIR/suggest-swapping-self-ty-and-trait.rs:20:26
63+
|
64+
LL | impl<'a, T> Union<T> for Trait<'a, T> {}
65+
| ^^^^^^^^^^^^
66+
|
67+
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
68+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
69+
help: if this is an object-safe trait, use `dyn`
70+
|
71+
LL | impl<'a, T> Union<T> for dyn Trait<'a, T> {}
72+
| +++
73+
74+
error: aborting due to 3 previous errors; 3 warnings emitted
4975

5076
For more information about this error, try `rustc --explain E0404`.

0 commit comments

Comments
 (0)