From ebfe0e4620285f8f91d15ac84dff24cd2c1d6a4c Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sat, 19 Oct 2024 13:20:48 +0000 Subject: [PATCH 1/7] Emit error on `skip-filecheck` test containing filecheck directives --- src/tools/miropt-test-tools/src/lib.rs | 3 +++ tests/mir-opt/dest-prop/union.rs | 3 +-- tests/mir-opt/issues/issue_59352.rs | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tools/miropt-test-tools/src/lib.rs b/src/tools/miropt-test-tools/src/lib.rs index 4317f23a82219..41b53d2ad0e95 100644 --- a/src/tools/miropt-test-tools/src/lib.rs +++ b/src/tools/miropt-test-tools/src/lib.rs @@ -129,6 +129,9 @@ pub fn files_for_miropt_test( out.push(MiroptTestFile { expected_file, from_file, to_file }); } + if !run_filecheck && l.trim_start().starts_with("// CHECK") { + panic!("error: test contains filecheck directive but is marked `skip-filecheck`"); + } } MiroptTest { run_filecheck, suffix, files: out, passes } diff --git a/tests/mir-opt/dest-prop/union.rs b/tests/mir-opt/dest-prop/union.rs index 4e6fb71bf75ec..85eded0998031 100644 --- a/tests/mir-opt/dest-prop/union.rs +++ b/tests/mir-opt/dest-prop/union.rs @@ -1,4 +1,3 @@ -// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY //! Tests that we can propagate into places that are projections into unions //@ compile-flags: -Zunsound-mir-opts -C debuginfo=full @@ -8,7 +7,7 @@ fn val() -> u32 { // EMIT_MIR union.main.DestinationPropagation.diff fn main() { - // CHECK-LABEL: fn args( + // CHECK-LABEL: fn main( // CHECK: {{_.*}} = Un { us: const 1_u32 }; union Un { us: u32, diff --git a/tests/mir-opt/issues/issue_59352.rs b/tests/mir-opt/issues/issue_59352.rs index 5c06b7e56f719..9024dc976e494 100644 --- a/tests/mir-opt/issues/issue_59352.rs +++ b/tests/mir-opt/issues/issue_59352.rs @@ -1,4 +1,3 @@ -// skip-filecheck // EMIT_MIR_FOR_EACH_PANIC_STRATEGY // This test is a mirror of codegen/issue-59352.rs. // The LLVM inliner doesn't inline `char::method::is_digit()` and so it doesn't recognize this case From b922ae07b3e62c7b5ead3b9c8d379e8ae2794004 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 20 Oct 2024 03:01:49 +0000 Subject: [PATCH 2/7] Make LowerPolyBounds take an IntoIterator --- compiler/rustc_hir_analysis/src/collect/predicates_of.rs | 4 ++-- compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 421ba40aa88ce..cdf3cb53e4f4d 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -267,7 +267,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen let mut bounds = Bounds::default(); icx.lowerer().lower_poly_bounds( ty, - bound_pred.bounds.iter(), + bound_pred.bounds, &mut bounds, bound_vars, PredicateFilter::All, @@ -836,7 +836,7 @@ impl<'tcx> ItemCtxt<'tcx> { let bound_vars = self.tcx.late_bound_vars(predicate.hir_id); self.lowerer().lower_poly_bounds( bound_ty, - predicate.bounds.iter(), + predicate.bounds, &mut bounds, bound_vars, filter, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 310f648b980e6..8254e6c7a037c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -142,7 +142,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// There is an implied binder around `param_ty` and `hir_bounds`. /// See `lower_poly_trait_ref` for more details. #[instrument(level = "debug", skip(self, hir_bounds, bounds))] - pub(crate) fn lower_poly_bounds<'hir, I: Iterator>>( + pub(crate) fn lower_poly_bounds<'hir, I: IntoIterator>>( &self, param_ty: Ty<'tcx>, hir_bounds: I, @@ -231,7 +231,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { self.lower_poly_bounds( param_ty, - hir_bounds.iter(), + hir_bounds, &mut bounds, ty::List::empty(), predicate_filter, @@ -446,7 +446,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder()); self.lower_poly_bounds( param_ty, - hir_bounds.iter(), + hir_bounds, bounds, projection_ty.bound_vars(), predicate_filter, From 10b07961a2289a83018c63e70698bd563d75ac00 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 20 Oct 2024 13:39:35 +0000 Subject: [PATCH 3/7] Inline lower_mono_bounds into lower_poly_bounds --- .../src/collect/item_bounds.rs | 7 ++-- .../src/collect/predicates_of.rs | 16 +++++---- .../src/hir_ty_lowering/bounds.rs | 33 ++----------------- 3 files changed, 17 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 4346504450d0b..69ebd3a928a3a 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -13,6 +13,7 @@ use tracing::{debug, instrument}; use super::ItemCtxt; use super::predicates_of::assert_only_contains_predicates_from; +use crate::bounds::Bounds; use crate::hir_ty_lowering::{HirTyLowerer, PredicateFilter}; /// For associated types we include both bounds written on the type @@ -36,7 +37,8 @@ fn associated_type_bounds<'tcx>( ); let icx = ItemCtxt::new(tcx, assoc_item_def_id); - let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter); + let mut bounds = Bounds::default(); + icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter); // Associated types are implicitly sized unless a `?Sized` bound is found icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span); @@ -303,7 +305,8 @@ fn opaque_type_bounds<'tcx>( ) -> &'tcx [(ty::Clause<'tcx>, Span)] { ty::print::with_reduced_queries!({ let icx = ItemCtxt::new(tcx, opaque_def_id); - let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter); + let mut bounds = Bounds::default(); + icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter); // Opaque types are implicitly sized unless a `?Sized` bound is found icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span); debug!(?bounds); diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index cdf3cb53e4f4d..9bd8c70dcfe79 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -181,9 +181,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // on a trait we must also consider the bounds that follow the trait's name, // like `trait Foo: A + B + C`. if let Some(self_bounds) = is_trait { - let bounds = icx.lowerer().lower_mono_bounds( + let mut bounds = Bounds::default(); + icx.lowerer().lower_bounds( tcx.types.self_param, self_bounds, + &mut bounds, + ty::List::empty(), PredicateFilter::All, ); predicates.extend(bounds.clauses(tcx)); @@ -265,7 +268,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen } let mut bounds = Bounds::default(); - icx.lowerer().lower_poly_bounds( + icx.lowerer().lower_bounds( ty, bound_pred.bounds, &mut bounds, @@ -626,7 +629,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( bug!("trait_def_id {trait_def_id:?} is not an item"); }; - let (generics, bounds) = match item.kind { + let (generics, superbounds) = match item.kind { hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits), hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits), _ => span_bug!(item.span, "super_predicates invoked on non-trait"), @@ -635,7 +638,8 @@ pub(super) fn implied_predicates_with_filter<'tcx>( let icx = ItemCtxt::new(tcx, trait_def_id); let self_param_ty = tcx.types.self_param; - let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter); + let mut bounds = Bounds::default(); + icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter); let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics( generics, @@ -646,7 +650,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( // Combine the two lists to form the complete set of superbounds: let implied_bounds = - &*tcx.arena.alloc_from_iter(superbounds.clauses(tcx).chain(where_bounds_that_match)); + &*tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(where_bounds_that_match)); debug!(?implied_bounds); // Now require that immediate supertraits are lowered, which will, in @@ -834,7 +838,7 @@ impl<'tcx> ItemCtxt<'tcx> { }; let bound_vars = self.tcx.late_bound_vars(predicate.hir_id); - self.lowerer().lower_poly_bounds( + self.lowerer().lower_bounds( bound_ty, predicate.bounds, &mut bounds, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 8254e6c7a037c..8605553f7978e 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -142,7 +142,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// There is an implied binder around `param_ty` and `hir_bounds`. /// See `lower_poly_trait_ref` for more details. #[instrument(level = "debug", skip(self, hir_bounds, bounds))] - pub(crate) fn lower_poly_bounds<'hir, I: IntoIterator>>( + pub(crate) fn lower_bounds<'hir, I: IntoIterator>>( &self, param_ty: Ty<'tcx>, hir_bounds: I, @@ -212,35 +212,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } } - /// Lower HIR bounds into `bounds` given the self type `param_ty` and *no* overarching late-bound vars. - /// - /// ### Example - /// - /// ```ignore (illustrative) - /// fn foo() { } - /// // ^ ^^^^^^^^^ hir_bounds - /// // param_ty - /// ``` - pub(crate) fn lower_mono_bounds( - &self, - param_ty: Ty<'tcx>, - hir_bounds: &[hir::GenericBound<'tcx>], - predicate_filter: PredicateFilter, - ) -> Bounds<'tcx> { - let mut bounds = Bounds::default(); - - self.lower_poly_bounds( - param_ty, - hir_bounds, - &mut bounds, - ty::List::empty(), - predicate_filter, - ); - debug!(?bounds); - - bounds - } - /// Lower an associated item constraint from the HIR into `bounds`. /// /// ### A Note on Binders @@ -444,7 +415,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // parameter to have a skipped binder. let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder()); - self.lower_poly_bounds( + self.lower_bounds( param_ty, hir_bounds, bounds, From 080103f1edeea36827a51a9f663cf86638b44cb5 Mon Sep 17 00:00:00 2001 From: ash Date: Sun, 20 Oct 2024 08:34:15 -0600 Subject: [PATCH 4/7] misapplied optimize attribute throws a compilation error (#128488) --- compiler/rustc_passes/messages.ftl | 6 +-- compiler/rustc_passes/src/check_attr.rs | 30 ++++++-------- compiler/rustc_passes/src/errors.rs | 12 ++++-- tests/ui/attributes/optimize.rs | 22 ++++++++-- tests/ui/attributes/optimize.stderr | 38 +++++++++++++----- tests/ui/coroutine/other-attribute-on-gen.rs | 40 +++++++++++++++++++ .../feature-gate-optimize_attribute.rs | 6 --- .../feature-gate-optimize_attribute.stderr | 30 +++----------- 8 files changed, 115 insertions(+), 69 deletions(-) create mode 100644 tests/ui/coroutine/other-attribute-on-gen.rs diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index e5a14f6a15658..3613b7b862d7f 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -553,9 +553,9 @@ passes_only_has_effect_on = *[unspecified] (unspecified--this is a compiler bug) } -passes_optimize_not_fn_or_closure = - attribute should be applied to function or closure - .label = not a function or closure +passes_optimize_invalid_target = + attribute applied to an invalid target + .label = invalid target passes_outer_crate_level_attr = crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]` diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 4516ea94cad71..8b30546d5ccec 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -124,7 +124,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } [sym::inline, ..] => self.check_inline(hir_id, attr, span, target), [sym::coverage, ..] => self.check_coverage(attr, span, target), - [sym::optimize, ..] => self.check_optimize(hir_id, attr, target), + [sym::optimize, ..] => self.check_optimize(hir_id, attr, span, target), [sym::no_sanitize, ..] => { self.check_applied_to_fn_or_method(hir_id, attr, span, target) } @@ -433,23 +433,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> { /// Checks that `#[optimize(..)]` is applied to a function/closure/method, /// or to an impl block or module. - // FIXME(#128488): this should probably be elevated to an error? - fn check_optimize(&self, hir_id: HirId, attr: &Attribute, target: Target) { - match target { + fn check_optimize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) { + let is_valid = matches!( + target, Target::Fn - | Target::Closure - | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) - | Target::Impl - | Target::Mod => {} - - _ => { - self.tcx.emit_node_span_lint( - UNUSED_ATTRIBUTES, - hir_id, - attr.span, - errors::OptimizeNotFnOrClosure, - ); - } + | Target::Closure + | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) + ); + if !is_valid { + self.dcx().emit_err(errors::OptimizeInvalidTarget { + attr_span: attr.span, + defn_span: span, + on_crate: hir_id == CRATE_HIR_ID, + }); } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 6dc3dfba58f06..f01ddbd47efe8 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -76,9 +76,15 @@ pub(crate) struct CoverageNotFnOrClosure { pub defn_span: Span, } -#[derive(LintDiagnostic)] -#[diag(passes_optimize_not_fn_or_closure)] -pub(crate) struct OptimizeNotFnOrClosure; +#[derive(Diagnostic)] +#[diag(passes_optimize_invalid_target)] +pub(crate) struct OptimizeInvalidTarget { + #[primary_span] + pub attr_span: Span, + #[label] + pub defn_span: Span, + pub on_crate: bool, +} #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_fn)] diff --git a/tests/ui/attributes/optimize.rs b/tests/ui/attributes/optimize.rs index b01806165c1f5..7a1cc1be9eec5 100644 --- a/tests/ui/attributes/optimize.rs +++ b/tests/ui/attributes/optimize.rs @@ -3,11 +3,13 @@ #![deny(unused_attributes)] #![allow(dead_code)] -#[optimize(speed)] //~ ERROR attribute should be applied to function or closure +//@ edition: 2018 + +#[optimize(speed)] //~ ERROR attribute applied to an invalid target struct F; fn invalid() { - #[optimize(speed)] //~ ERROR attribute should be applied to function or closure + #[optimize(speed)] //~ ERROR attribute applied to an invalid target { 1 }; @@ -16,13 +18,25 @@ fn invalid() { #[optimize(speed)] fn valid() {} -#[optimize(speed)] +#[optimize(speed)] //~ ERROR attribute applied to an invalid target mod valid_module {} -#[optimize(speed)] +#[optimize(speed)] //~ ERROR attribute applied to an invalid target impl F {} fn main() { let _ = #[optimize(speed)] (|| 1); } + +use std::future::Future; + +fn async_block() -> impl Future { + #[optimize(speed)] + async { } +} + +#[optimize(speed)] +async fn async_fn() { + () +} diff --git a/tests/ui/attributes/optimize.stderr b/tests/ui/attributes/optimize.stderr index 3c445d73c2edb..ad9309d27a5a8 100644 --- a/tests/ui/attributes/optimize.stderr +++ b/tests/ui/attributes/optimize.stderr @@ -1,20 +1,36 @@ -error: attribute should be applied to function or closure - --> $DIR/optimize.rs:6:1 +error: attribute applied to an invalid target + --> $DIR/optimize.rs:8:1 | LL | #[optimize(speed)] | ^^^^^^^^^^^^^^^^^^ +LL | struct F; + | --------- invalid target + +error: attribute applied to an invalid target + --> $DIR/optimize.rs:12:5 | -note: the lint level is defined here - --> $DIR/optimize.rs:3:9 +LL | #[optimize(speed)] + | ^^^^^^^^^^^^^^^^^^ +LL | / { +LL | | 1 +LL | | }; + | |_____- invalid target + +error: attribute applied to an invalid target + --> $DIR/optimize.rs:21:1 | -LL | #![deny(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ +LL | #[optimize(speed)] + | ^^^^^^^^^^^^^^^^^^ +LL | mod valid_module {} + | ------------------- invalid target -error: attribute should be applied to function or closure - --> $DIR/optimize.rs:10:5 +error: attribute applied to an invalid target + --> $DIR/optimize.rs:24:1 | -LL | #[optimize(speed)] - | ^^^^^^^^^^^^^^^^^^ +LL | #[optimize(speed)] + | ^^^^^^^^^^^^^^^^^^ +LL | impl F {} + | --------- invalid target -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors diff --git a/tests/ui/coroutine/other-attribute-on-gen.rs b/tests/ui/coroutine/other-attribute-on-gen.rs new file mode 100644 index 0000000000000..0f26dc6860dd7 --- /dev/null +++ b/tests/ui/coroutine/other-attribute-on-gen.rs @@ -0,0 +1,40 @@ +//@ edition: 2024 +//@ compile-flags: -Zunstable-options +//@ run-pass +#![feature(gen_blocks)] +#![feature(optimize_attribute)] +#![feature(stmt_expr_attributes)] +#![feature(async_iterator)] +#![allow(dead_code)] + +// make sure that other attributes e.g. `optimize` can be applied to gen blocks and functions + +fn main() { } + +fn optimize_gen_block() -> impl Iterator { + #[optimize(speed)] + gen { yield (); } +} + +#[optimize(speed)] +gen fn optimize_gen_fn() -> i32 { + yield 1; + yield 2; + yield 3; +} + +#[optimize(speed)] +async gen fn optimize_async_gen_fn() -> i32 { + yield 1; + yield 2; + yield 3; +} + +use std::async_iter::AsyncIterator; + +pub fn deduce() -> impl AsyncIterator { + #[optimize(size)] + async gen { + yield (); + } +} diff --git a/tests/ui/feature-gates/feature-gate-optimize_attribute.rs b/tests/ui/feature-gates/feature-gate-optimize_attribute.rs index 15aa3a6af4ca9..7f9cada6a47d5 100644 --- a/tests/ui/feature-gates/feature-gate-optimize_attribute.rs +++ b/tests/ui/feature-gates/feature-gate-optimize_attribute.rs @@ -1,8 +1,4 @@ #![crate_type="rlib"] -#![optimize(speed)] //~ ERROR the `#[optimize]` attribute is an experimental feature - -#[optimize(size)] //~ ERROR the `#[optimize]` attribute is an experimental feature -mod module { #[optimize(size)] //~ ERROR the `#[optimize]` attribute is an experimental feature fn size() {} @@ -14,5 +10,3 @@ fn speed() {} //~^ ERROR the `#[optimize]` attribute is an experimental feature //~| ERROR E0722 fn not_known() {} - -} diff --git a/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr b/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr index 609526150ba2e..ca8f4a078f09e 100644 --- a/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr +++ b/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr @@ -1,25 +1,5 @@ error[E0658]: the `#[optimize]` attribute is an experimental feature - --> $DIR/feature-gate-optimize_attribute.rs:2:1 - | -LL | #![optimize(speed)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #54882 for more information - = help: add `#![feature(optimize_attribute)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the `#[optimize]` attribute is an experimental feature - --> $DIR/feature-gate-optimize_attribute.rs:4:1 - | -LL | #[optimize(size)] - | ^^^^^^^^^^^^^^^^^ - | - = note: see issue #54882 for more information - = help: add `#![feature(optimize_attribute)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the `#[optimize]` attribute is an experimental feature - --> $DIR/feature-gate-optimize_attribute.rs:7:1 + --> $DIR/feature-gate-optimize_attribute.rs:3:1 | LL | #[optimize(size)] | ^^^^^^^^^^^^^^^^^ @@ -29,7 +9,7 @@ LL | #[optimize(size)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: the `#[optimize]` attribute is an experimental feature - --> $DIR/feature-gate-optimize_attribute.rs:10:1 + --> $DIR/feature-gate-optimize_attribute.rs:6:1 | LL | #[optimize(speed)] | ^^^^^^^^^^^^^^^^^^ @@ -39,7 +19,7 @@ LL | #[optimize(speed)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: the `#[optimize]` attribute is an experimental feature - --> $DIR/feature-gate-optimize_attribute.rs:13:1 + --> $DIR/feature-gate-optimize_attribute.rs:9:1 | LL | #[optimize(banana)] | ^^^^^^^^^^^^^^^^^^^ @@ -49,12 +29,12 @@ LL | #[optimize(banana)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0722]: invalid argument - --> $DIR/feature-gate-optimize_attribute.rs:13:12 + --> $DIR/feature-gate-optimize_attribute.rs:9:12 | LL | #[optimize(banana)] | ^^^^^^ -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0658, E0722. For more information about an error, try `rustc --explain E0658`. From 880d565df1590b01ba9b7b38145692069d43f4cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 20 Oct 2024 18:28:14 +0200 Subject: [PATCH 5/7] fix(rustdoc-json-types): document rustc-hash feature The `rustc-hash` feature is publicly exposed by the `rustdoc-types`. It is already documented in that crate's README and Cargo.toml, but we might as well add some information to the crate docs themselves c: Follow up to: - #131936 - [rust-lang/rustdoc-types#42][1] [1]: https://github.com/rust-lang/rustdoc-types/pull/42 --- src/rustdoc-json-types/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index c4e142342a85e..33ec59dad5bd3 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -2,6 +2,18 @@ //! //! These types are the public API exposed through the `--output-format json` flag. The [`Crate`] //! struct is the root of the JSON blob and all other items are contained within. +//! +//! We expose a `rustc-hash` feature that is disabled by default. This feature switches the +//! [`std::collections::HashMap`] for [`rustc_hash::FxHashMap`] to improve the performance of said +//! `HashMap` in specific situations. +//! +//! `cargo-semver-checks` for example, saw a [-3% improvement][1] when benchmarking using the +//! `aws_sdk_ec2` JSON output (~500MB of JSON). As always, we recommend measuring the impact before +//! turning this feature on, as [`FxHashMap`][2] only concerns itself with hash speed, and may +//! increase the number of collisions. +//! +//! [1]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/rustc-hash.20and.20performance.20of.20rustdoc-types/near/474855731 +//! [2]: https://crates.io/crates/rustc-hash #[cfg(not(feature = "rustc-hash"))] use std::collections::HashMap; From f04759165241a7c3445a88cb6a2a2ca575d94302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 20 Oct 2024 18:55:49 +0200 Subject: [PATCH 6/7] feat(rustdoc-json-types): mark simple enums as copy Fixes [rust-lang/rustdoc-types#26](https://github.com/rust-lang/rustdoc-types/issues/26) --- src/rustdoc-json-types/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index c4e142342a85e..4d2dd5fe9a5f6 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -308,7 +308,7 @@ pub struct Id(pub u32); /// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info. /// /// Part of [`ItemSummary`]. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum ItemKind { /// A module declaration, e.g. `mod foo;` or `mod foo {}` @@ -892,7 +892,7 @@ pub enum GenericBound { } /// A set of modifiers applied to a trait. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum TraitBoundModifier { /// Marks the absence of a modifier. @@ -1193,7 +1193,7 @@ pub struct ProcMacro { } /// The way a [`ProcMacro`] is declared to be used. -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum MacroKind { /// A bang macro `foo!()`. From afa75f0aa5c90b9ea7d4887f00aed7041104a853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 20 Oct 2024 18:57:17 +0200 Subject: [PATCH 7/7] fix(rustdoc-json-types): typos Typos found some typos in the file, so I fixed them c: --- src/rustdoc-json-types/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 4d2dd5fe9a5f6..7b64edfad7d72 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -305,7 +305,7 @@ pub enum AssocItemConstraintKind { // FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types. pub struct Id(pub u32); -/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info. +/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any additional info. /// /// Part of [`ItemSummary`]. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -698,7 +698,7 @@ pub enum Abi { Aapcs { unwind: bool }, /// Can be specified as `extern "win64"`. Win64 { unwind: bool }, - /// Can be specifed as `extern "sysv64"`. + /// Can be specified as `extern "sysv64"`. SysV64 { unwind: bool }, /// Can be specified as `extern "system"`. System { unwind: bool }, @@ -996,7 +996,7 @@ pub enum Type { QualifiedPath { /// The name of the associated type in the parent type. /// - /// ```ignore (incomplete expresssion) + /// ```ignore (incomplete expression) /// as Iterator>::Item /// // ^^^^ /// ``` @@ -1083,7 +1083,7 @@ pub struct FunctionSignature { #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Trait { /// Whether the trait is marked `auto` and is thus implemented automatically - /// for all aplicable types. + /// for all applicable types. pub is_auto: bool, /// Whether the trait is marked as `unsafe`. pub is_unsafe: bool,