Skip to content

Commit 7ed1a51

Browse files
committed
Auto merge of rust-lang#131980 - matthiaskrgr:rollup-iy5nw71, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#131814 (`optimize` attribute applied to things other than methods/functions/c…) - rust-lang#131927 (Check for filecheck directives in files marked `skip-filecheck`) - rust-lang#131967 (Remove `lower_mono_bounds`) - rust-lang#131973 (fix(rustdoc-json-types): document rustc-hash feature) - rust-lang#131976 (feat(rustdoc-json-types): mark simple enums as copy) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 662180b + 4b65865 commit 7ed1a51

File tree

15 files changed

+158
-121
lines changed

15 files changed

+158
-121
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tracing::{debug, instrument};
1313

1414
use super::ItemCtxt;
1515
use super::predicates_of::assert_only_contains_predicates_from;
16+
use crate::bounds::Bounds;
1617
use crate::hir_ty_lowering::{HirTyLowerer, PredicateFilter};
1718

1819
/// For associated types we include both bounds written on the type
@@ -36,7 +37,8 @@ fn associated_type_bounds<'tcx>(
3637
);
3738

3839
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
39-
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter);
40+
let mut bounds = Bounds::default();
41+
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
4042
// Associated types are implicitly sized unless a `?Sized` bound is found
4143
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);
4244

@@ -303,7 +305,8 @@ fn opaque_type_bounds<'tcx>(
303305
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
304306
ty::print::with_reduced_queries!({
305307
let icx = ItemCtxt::new(tcx, opaque_def_id);
306-
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter);
308+
let mut bounds = Bounds::default();
309+
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
307310
// Opaque types are implicitly sized unless a `?Sized` bound is found
308311
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);
309312
debug!(?bounds);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
181181
// on a trait we must also consider the bounds that follow the trait's name,
182182
// like `trait Foo: A + B + C`.
183183
if let Some(self_bounds) = is_trait {
184-
let bounds = icx.lowerer().lower_mono_bounds(
184+
let mut bounds = Bounds::default();
185+
icx.lowerer().lower_bounds(
185186
tcx.types.self_param,
186187
self_bounds,
188+
&mut bounds,
189+
ty::List::empty(),
187190
PredicateFilter::All,
188191
);
189192
predicates.extend(bounds.clauses(tcx));
@@ -265,9 +268,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
265268
}
266269

267270
let mut bounds = Bounds::default();
268-
icx.lowerer().lower_poly_bounds(
271+
icx.lowerer().lower_bounds(
269272
ty,
270-
bound_pred.bounds.iter(),
273+
bound_pred.bounds,
271274
&mut bounds,
272275
bound_vars,
273276
PredicateFilter::All,
@@ -626,7 +629,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
626629
bug!("trait_def_id {trait_def_id:?} is not an item");
627630
};
628631

629-
let (generics, bounds) = match item.kind {
632+
let (generics, superbounds) = match item.kind {
630633
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
631634
hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
632635
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
@@ -635,7 +638,8 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
635638
let icx = ItemCtxt::new(tcx, trait_def_id);
636639

637640
let self_param_ty = tcx.types.self_param;
638-
let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter);
641+
let mut bounds = Bounds::default();
642+
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);
639643

640644
let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics(
641645
generics,
@@ -646,7 +650,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
646650

647651
// Combine the two lists to form the complete set of superbounds:
648652
let implied_bounds =
649-
&*tcx.arena.alloc_from_iter(superbounds.clauses(tcx).chain(where_bounds_that_match));
653+
&*tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(where_bounds_that_match));
650654
debug!(?implied_bounds);
651655

652656
// Now require that immediate supertraits are lowered, which will, in
@@ -834,9 +838,9 @@ impl<'tcx> ItemCtxt<'tcx> {
834838
};
835839

836840
let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
837-
self.lowerer().lower_poly_bounds(
841+
self.lowerer().lower_bounds(
838842
bound_ty,
839-
predicate.bounds.iter(),
843+
predicate.bounds,
840844
&mut bounds,
841845
bound_vars,
842846
filter,

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+3-32
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
142142
/// There is an implied binder around `param_ty` and `hir_bounds`.
143143
/// See `lower_poly_trait_ref` for more details.
144144
#[instrument(level = "debug", skip(self, hir_bounds, bounds))]
145-
pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
145+
pub(crate) fn lower_bounds<'hir, I: IntoIterator<Item = &'hir hir::GenericBound<'tcx>>>(
146146
&self,
147147
param_ty: Ty<'tcx>,
148148
hir_bounds: I,
@@ -212,35 +212,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
212212
}
213213
}
214214

215-
/// Lower HIR bounds into `bounds` given the self type `param_ty` and *no* overarching late-bound vars.
216-
///
217-
/// ### Example
218-
///
219-
/// ```ignore (illustrative)
220-
/// fn foo<T: Bar + Baz>() { }
221-
/// // ^ ^^^^^^^^^ hir_bounds
222-
/// // param_ty
223-
/// ```
224-
pub(crate) fn lower_mono_bounds(
225-
&self,
226-
param_ty: Ty<'tcx>,
227-
hir_bounds: &[hir::GenericBound<'tcx>],
228-
predicate_filter: PredicateFilter,
229-
) -> Bounds<'tcx> {
230-
let mut bounds = Bounds::default();
231-
232-
self.lower_poly_bounds(
233-
param_ty,
234-
hir_bounds.iter(),
235-
&mut bounds,
236-
ty::List::empty(),
237-
predicate_filter,
238-
);
239-
debug!(?bounds);
240-
241-
bounds
242-
}
243-
244215
/// Lower an associated item constraint from the HIR into `bounds`.
245216
///
246217
/// ### A Note on Binders
@@ -444,9 +415,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
444415
// parameter to have a skipped binder.
445416
let param_ty =
446417
Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
447-
self.lower_poly_bounds(
418+
self.lower_bounds(
448419
param_ty,
449-
hir_bounds.iter(),
420+
hir_bounds,
450421
bounds,
451422
projection_ty.bound_vars(),
452423
predicate_filter,

compiler/rustc_passes/messages.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ passes_only_has_effect_on =
553553
*[unspecified] (unspecified--this is a compiler bug)
554554
}
555555
556-
passes_optimize_not_fn_or_closure =
557-
attribute should be applied to function or closure
558-
.label = not a function or closure
556+
passes_optimize_invalid_target =
557+
attribute applied to an invalid target
558+
.label = invalid target
559559
560560
passes_outer_crate_level_attr =
561561
crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`

compiler/rustc_passes/src/check_attr.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
124124
}
125125
[sym::inline, ..] => self.check_inline(hir_id, attr, span, target),
126126
[sym::coverage, ..] => self.check_coverage(attr, span, target),
127-
[sym::optimize, ..] => self.check_optimize(hir_id, attr, target),
127+
[sym::optimize, ..] => self.check_optimize(hir_id, attr, span, target),
128128
[sym::no_sanitize, ..] => {
129129
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
130130
}
@@ -433,23 +433,19 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
433433

434434
/// Checks that `#[optimize(..)]` is applied to a function/closure/method,
435435
/// or to an impl block or module.
436-
// FIXME(#128488): this should probably be elevated to an error?
437-
fn check_optimize(&self, hir_id: HirId, attr: &Attribute, target: Target) {
438-
match target {
436+
fn check_optimize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
437+
let is_valid = matches!(
438+
target,
439439
Target::Fn
440-
| Target::Closure
441-
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
442-
| Target::Impl
443-
| Target::Mod => {}
444-
445-
_ => {
446-
self.tcx.emit_node_span_lint(
447-
UNUSED_ATTRIBUTES,
448-
hir_id,
449-
attr.span,
450-
errors::OptimizeNotFnOrClosure,
451-
);
452-
}
440+
| Target::Closure
441+
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent)
442+
);
443+
if !is_valid {
444+
self.dcx().emit_err(errors::OptimizeInvalidTarget {
445+
attr_span: attr.span,
446+
defn_span: span,
447+
on_crate: hir_id == CRATE_HIR_ID,
448+
});
453449
}
454450
}
455451

compiler/rustc_passes/src/errors.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,15 @@ pub(crate) struct CoverageNotFnOrClosure {
7676
pub defn_span: Span,
7777
}
7878

79-
#[derive(LintDiagnostic)]
80-
#[diag(passes_optimize_not_fn_or_closure)]
81-
pub(crate) struct OptimizeNotFnOrClosure;
79+
#[derive(Diagnostic)]
80+
#[diag(passes_optimize_invalid_target)]
81+
pub(crate) struct OptimizeInvalidTarget {
82+
#[primary_span]
83+
pub attr_span: Span,
84+
#[label]
85+
pub defn_span: Span,
86+
pub on_crate: bool,
87+
}
8288

8389
#[derive(Diagnostic)]
8490
#[diag(passes_should_be_applied_to_fn)]

src/rustdoc-json-types/lib.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
//!
33
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
44
//! struct is the root of the JSON blob and all other items are contained within.
5+
//!
6+
//! We expose a `rustc-hash` feature that is disabled by default. This feature switches the
7+
//! [`std::collections::HashMap`] for [`rustc_hash::FxHashMap`] to improve the performance of said
8+
//! `HashMap` in specific situations.
9+
//!
10+
//! `cargo-semver-checks` for example, saw a [-3% improvement][1] when benchmarking using the
11+
//! `aws_sdk_ec2` JSON output (~500MB of JSON). As always, we recommend measuring the impact before
12+
//! turning this feature on, as [`FxHashMap`][2] only concerns itself with hash speed, and may
13+
//! increase the number of collisions.
14+
//!
15+
//! [1]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/rustc-hash.20and.20performance.20of.20rustdoc-types/near/474855731
16+
//! [2]: https://crates.io/crates/rustc-hash
517
618
#[cfg(not(feature = "rustc-hash"))]
719
use std::collections::HashMap;
@@ -305,10 +317,10 @@ pub enum AssocItemConstraintKind {
305317
// FIXME(aDotInTheVoid): Consider making this non-public in rustdoc-types.
306318
pub struct Id(pub u32);
307319

308-
/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any aditional info.
320+
/// The fundamental kind of an item. Unlike [`ItemEnum`], this does not carry any additional info.
309321
///
310322
/// Part of [`ItemSummary`].
311-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
323+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
312324
#[serde(rename_all = "snake_case")]
313325
pub enum ItemKind {
314326
/// A module declaration, e.g. `mod foo;` or `mod foo {}`
@@ -698,7 +710,7 @@ pub enum Abi {
698710
Aapcs { unwind: bool },
699711
/// Can be specified as `extern "win64"`.
700712
Win64 { unwind: bool },
701-
/// Can be specifed as `extern "sysv64"`.
713+
/// Can be specified as `extern "sysv64"`.
702714
SysV64 { unwind: bool },
703715
/// Can be specified as `extern "system"`.
704716
System { unwind: bool },
@@ -892,7 +904,7 @@ pub enum GenericBound {
892904
}
893905

894906
/// A set of modifiers applied to a trait.
895-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
907+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
896908
#[serde(rename_all = "snake_case")]
897909
pub enum TraitBoundModifier {
898910
/// Marks the absence of a modifier.
@@ -996,7 +1008,7 @@ pub enum Type {
9961008
QualifiedPath {
9971009
/// The name of the associated type in the parent type.
9981010
///
999-
/// ```ignore (incomplete expresssion)
1011+
/// ```ignore (incomplete expression)
10001012
/// <core::array::IntoIter<u32, 42> as Iterator>::Item
10011013
/// // ^^^^
10021014
/// ```
@@ -1083,7 +1095,7 @@ pub struct FunctionSignature {
10831095
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10841096
pub struct Trait {
10851097
/// Whether the trait is marked `auto` and is thus implemented automatically
1086-
/// for all aplicable types.
1098+
/// for all applicable types.
10871099
pub is_auto: bool,
10881100
/// Whether the trait is marked as `unsafe`.
10891101
pub is_unsafe: bool,
@@ -1193,7 +1205,7 @@ pub struct ProcMacro {
11931205
}
11941206

11951207
/// The way a [`ProcMacro`] is declared to be used.
1196-
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
1208+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
11971209
#[serde(rename_all = "snake_case")]
11981210
pub enum MacroKind {
11991211
/// A bang macro `foo!()`.

src/tools/miropt-test-tools/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub fn files_for_miropt_test(
129129

130130
out.push(MiroptTestFile { expected_file, from_file, to_file });
131131
}
132+
if !run_filecheck && l.trim_start().starts_with("// CHECK") {
133+
panic!("error: test contains filecheck directive but is marked `skip-filecheck`");
134+
}
132135
}
133136

134137
MiroptTest { run_filecheck, suffix, files: out, passes }

tests/mir-opt/dest-prop/union.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
//! Tests that we can propagate into places that are projections into unions
43
//@ compile-flags: -Zunsound-mir-opts -C debuginfo=full
@@ -8,7 +7,7 @@ fn val() -> u32 {
87

98
// EMIT_MIR union.main.DestinationPropagation.diff
109
fn main() {
11-
// CHECK-LABEL: fn args(
10+
// CHECK-LABEL: fn main(
1211
// CHECK: {{_.*}} = Un { us: const 1_u32 };
1312
union Un {
1413
us: u32,

tests/mir-opt/issues/issue_59352.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// skip-filecheck
21
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
32
// This test is a mirror of codegen/issue-59352.rs.
43
// The LLVM inliner doesn't inline `char::method::is_digit()` and so it doesn't recognize this case

tests/ui/attributes/optimize.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
#![deny(unused_attributes)]
44
#![allow(dead_code)]
55

6-
#[optimize(speed)] //~ ERROR attribute should be applied to function or closure
6+
//@ edition: 2018
7+
8+
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
79
struct F;
810

911
fn invalid() {
10-
#[optimize(speed)] //~ ERROR attribute should be applied to function or closure
12+
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
1113
{
1214
1
1315
};
@@ -16,13 +18,25 @@ fn invalid() {
1618
#[optimize(speed)]
1719
fn valid() {}
1820

19-
#[optimize(speed)]
21+
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
2022
mod valid_module {}
2123

22-
#[optimize(speed)]
24+
#[optimize(speed)] //~ ERROR attribute applied to an invalid target
2325
impl F {}
2426

2527
fn main() {
2628
let _ = #[optimize(speed)]
2729
(|| 1);
2830
}
31+
32+
use std::future::Future;
33+
34+
fn async_block() -> impl Future<Output = ()> {
35+
#[optimize(speed)]
36+
async { }
37+
}
38+
39+
#[optimize(speed)]
40+
async fn async_fn() {
41+
()
42+
}

0 commit comments

Comments
 (0)