From de3fb8d429a15891deda4640d421bf223cd5843b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 23 Feb 2024 11:07:01 +0000 Subject: [PATCH] Collect mod item types in parallel, just like wfcheck --- compiler/rustc_hir_analysis/src/collect.rs | 13 +++++++- ...swapping-self-ty-and-trait-edition-2021.rs | 2 ++ ...ping-self-ty-and-trait-edition-2021.stderr | 26 ++++++++++++++-- .../suggest-swapping-self-ty-and-trait.rs | 4 +++ .../suggest-swapping-self-ty-and-trait.stderr | 30 +++++++++++++++++-- 5 files changed, 70 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 2cc37651ef5..73138340d78 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -55,7 +55,18 @@ // Main entry point fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { - tcx.hir().visit_item_likes_in_module(module_def_id, &mut CollectItemTypesVisitor { tcx }); + let items = tcx.hir_module_items(module_def_id); + let hir = tcx.hir(); + let _ = items.par_items(|item| Ok(CollectItemTypesVisitor { tcx }.visit_item(hir.item(item)))); + let _ = items.par_trait_items(|item| { + Ok(CollectItemTypesVisitor { tcx }.visit_trait_item(hir.trait_item(item))) + }); + let _ = items.par_impl_items(|item| { + Ok(CollectItemTypesVisitor { tcx }.visit_impl_item(hir.impl_item(item))) + }); + let _ = items.par_foreign_items(|item| { + Ok(CollectItemTypesVisitor { tcx }.visit_foreign_item(hir.foreign_item(item))) + }); } pub fn provide(providers: &mut Providers) { diff --git a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.rs b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.rs index c4384bce3a9..229b6e4b5e7 100644 --- a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.rs +++ b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.rs @@ -15,8 +15,10 @@ impl<'a, T> Struct for Trait<'a, T> {} impl<'a, T> Enum for Trait<'a, T> {} //~^ ERROR expected trait, found enum `Enum` +//~| ERROR trait objects must include the `dyn` keyword impl<'a, T> Union for Trait<'a, T> {} //~^ ERROR expected trait, found union `Union` +//~| ERROR trait objects must include the `dyn` keyword fn main() {} diff --git a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr index 87e71643620..781d67ea995 100644 --- a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr +++ b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait-edition-2021.stderr @@ -21,7 +21,7 @@ LL | impl<'a, T> Trait<'a, T> for Enum {} | ~~~~~~~~~~~~ ~~~~~~~ error[E0404]: expected trait, found union `Union` - --> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:19:13 + --> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:20:13 | LL | impl<'a, T> Union for Trait<'a, T> {} | ^^^^^^^^ not a trait @@ -42,7 +42,29 @@ help: add `dyn` keyword before this trait LL | impl<'a, T> Struct for dyn Trait<'a, T> {} | +++ -error: aborting due to 4 previous errors +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:16:25 + | +LL | impl<'a, T> Enum for Trait<'a, T> {} + | ^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL | impl<'a, T> Enum for dyn Trait<'a, T> {} + | +++ + +error[E0782]: trait objects must include the `dyn` keyword + --> $DIR/suggest-swapping-self-ty-and-trait-edition-2021.rs:20:26 + | +LL | impl<'a, T> Union for Trait<'a, T> {} + | ^^^^^^^^^^^^ + | +help: add `dyn` keyword before this trait + | +LL | impl<'a, T> Union for dyn Trait<'a, T> {} + | +++ + +error: aborting due to 6 previous errors Some errors have detailed explanations: E0404, E0782. For more information about an error, try `rustc --explain E0404`. diff --git a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.rs b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.rs index 947bc2c7965..e20938fd3bd 100644 --- a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.rs +++ b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.rs @@ -14,8 +14,12 @@ impl<'a, T> Struct for Trait<'a, T> {} impl<'a, T> Enum for Trait<'a, T> {} //~^ ERROR expected trait, found enum `Enum` +//~| WARNING trait objects without an explicit `dyn` are deprecated +//~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! impl<'a, T> Union for Trait<'a, T> {} //~^ ERROR expected trait, found union `Union` +//~| WARNING trait objects without an explicit `dyn` are deprecated +//~| WARNING this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! fn main() {} diff --git a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr index 0098814f81e..c538c313b1b 100644 --- a/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr +++ b/tests/ui/suggestions/suggest-swapping-self-ty-and-trait.stderr @@ -21,7 +21,7 @@ LL | impl<'a, T> Trait<'a, T> for Enum {} | ~~~~~~~~~~~~ ~~~~~~~ error[E0404]: expected trait, found union `Union` - --> $DIR/suggest-swapping-self-ty-and-trait.rs:18:13 + --> $DIR/suggest-swapping-self-ty-and-trait.rs:20:13 | LL | impl<'a, T> Union for Trait<'a, T> {} | ^^^^^^^^ not a trait @@ -45,6 +45,32 @@ help: if this is an object-safe trait, use `dyn` LL | impl<'a, T> Struct for dyn Trait<'a, T> {} | +++ -error: aborting due to 3 previous errors; 1 warning emitted +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/suggest-swapping-self-ty-and-trait.rs:15:25 + | +LL | impl<'a, T> Enum for Trait<'a, T> {} + | ^^^^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see +help: if this is an object-safe trait, use `dyn` + | +LL | impl<'a, T> Enum for dyn Trait<'a, T> {} + | +++ + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/suggest-swapping-self-ty-and-trait.rs:20:26 + | +LL | impl<'a, T> Union for Trait<'a, T> {} + | ^^^^^^^^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see +help: if this is an object-safe trait, use `dyn` + | +LL | impl<'a, T> Union for dyn Trait<'a, T> {} + | +++ + +error: aborting due to 3 previous errors; 3 warnings emitted For more information about this error, try `rustc --explain E0404`.