Skip to content

Commit 86dbd71

Browse files
committed
Auto merge of #142750 - jhpratt:rollup-6t1h6wx, r=jhpratt
Rollup of 10 pull requests Successful merges: - #138291 (rewrite `optimize` attribute to use new attribute parsing infrastructure) - #141990 (Implement send_signal for unix child processes) - #142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.) - #142478 (install docs for each target in different directory) - #142571 (Reason about borrowed classes in CopyProp.) - #142668 (vec_deque/fmt/vec tests: remove static mut) - #142687 (Reduce uses of `hir_crate`.) - #142690 (expand: Remove some unnecessary generic parameters) - #142699 (Update books) - #142714 (add comment to `src/bootstrap/build.rs`) Failed merges: - #142502 (rustdoc_json: improve handling of generic args) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 255aa22 + 1f9b14b commit 86dbd71

File tree

58 files changed

+650
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+650
-522
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub enum InstructionSetAttr {
3838
ArmT32,
3939
}
4040

41-
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
41+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, PrintAttribute)]
42+
#[derive(Encodable, Decodable, HashStable_Generic)]
4243
pub enum OptimizeAttr {
4344
/// No `#[optimize(..)]` attribute
4445
#[default]
@@ -229,7 +230,8 @@ pub enum AttributeKind {
229230

230231
/// Represents `#[rustc_macro_transparency]`.
231232
MacroTransparency(Transparency),
232-
233+
/// Represents `#[optimize(size|speed)]`
234+
Optimize(OptimizeAttr, Span),
233235
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
234236
Repr(ThinVec<(ReprAttr, Span)>),
235237

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr};
2+
use rustc_feature::{AttributeTemplate, template};
3+
use rustc_span::sym;
4+
5+
use super::{AttributeOrder, OnDuplicate, SingleAttributeParser};
6+
use crate::context::{AcceptContext, Stage};
7+
use crate::parser::ArgParser;
8+
9+
pub(crate) struct OptimizeParser;
10+
11+
impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
12+
const PATH: &[rustc_span::Symbol] = &[sym::optimize];
13+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
14+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
15+
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
16+
17+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
18+
let Some(list) = args.list() else {
19+
cx.expected_list(cx.attr_span);
20+
return None;
21+
};
22+
23+
let Some(single) = list.single() else {
24+
cx.expected_single_argument(list.span);
25+
return None;
26+
};
27+
28+
let res = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
29+
Some(sym::size) => OptimizeAttr::Size,
30+
Some(sym::speed) => OptimizeAttr::Speed,
31+
Some(sym::none) => OptimizeAttr::DoNotOptimize,
32+
_ => {
33+
cx.expected_specific_argument(single.span(), vec!["size", "speed", "none"]);
34+
OptimizeAttr::Default
35+
}
36+
};
37+
38+
Some(AttributeKind::Optimize(res, cx.attr_span))
39+
}
40+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::session_diagnostics::UnusedMultiple;
2828

2929
pub(crate) mod allow_unstable;
3030
pub(crate) mod cfg;
31+
pub(crate) mod codegen_attrs;
3132
pub(crate) mod confusables;
3233
pub(crate) mod deprecation;
3334
pub(crate) mod inline;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_session::Session;
1515
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
18+
use crate::attributes::codegen_attrs::OptimizeParser;
1819
use crate::attributes::confusables::ConfusablesParser;
1920
use crate::attributes::deprecation::DeprecationParser;
2021
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -108,6 +109,7 @@ attribute_parsers!(
108109
Single<ConstStabilityIndirectParser>,
109110
Single<DeprecationParser>,
110111
Single<InlineParser>,
112+
Single<OptimizeParser>,
111113
Single<RustcForceInlineParser>,
112114
Single<TransparencyParser>,
113115
// tidy-alphabetical-end

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ codegen_ssa_error_writing_def_file =
4848
4949
codegen_ssa_expected_name_value_pair = expected name value pair
5050
51-
codegen_ssa_expected_one_argument = expected one argument
52-
5351
codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`
5452
5553
codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
@@ -86,9 +84,6 @@ codegen_ssa_incorrect_cgu_reuse_type =
8684
8785
codegen_ssa_insufficient_vs_code_product = VS Code is a different product, and is not sufficient.
8886
89-
codegen_ssa_invalid_argument = invalid argument
90-
.help = valid inline arguments are `always` and `never`
91-
9287
codegen_ssa_invalid_instruction_set = invalid instruction set specified
9388
9489
codegen_ssa_invalid_link_ordinal_nargs = incorrect number of arguments to `#[link_ordinal]`

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -455,33 +455,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
455455
codegen_fn_attrs.inline = InlineAttr::Never;
456456
}
457457

458-
codegen_fn_attrs.optimize = attrs.iter().fold(OptimizeAttr::Default, |ia, attr| {
459-
if !attr.has_name(sym::optimize) {
460-
return ia;
461-
}
462-
if attr.is_word() {
463-
tcx.dcx().emit_err(errors::ExpectedOneArgumentOptimize { span: attr.span() });
464-
return ia;
465-
}
466-
let Some(ref items) = attr.meta_item_list() else {
467-
return OptimizeAttr::Default;
468-
};
469-
470-
let [item] = &items[..] else {
471-
tcx.dcx().emit_err(errors::ExpectedOneArgumentOptimize { span: attr.span() });
472-
return OptimizeAttr::Default;
473-
};
474-
if item.has_name(sym::size) {
475-
OptimizeAttr::Size
476-
} else if item.has_name(sym::speed) {
477-
OptimizeAttr::Speed
478-
} else if item.has_name(sym::none) {
479-
OptimizeAttr::DoNotOptimize
480-
} else {
481-
tcx.dcx().emit_err(errors::InvalidArgumentOptimize { span: item.span() });
482-
OptimizeAttr::Default
483-
}
484-
});
458+
codegen_fn_attrs.optimize =
459+
find_attr!(attrs, AttributeKind::Optimize(i, _) => *i).unwrap_or(OptimizeAttr::Default);
485460

486461
// #73631: closures inherit `#[target_feature]` annotations
487462
//

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,6 @@ pub(crate) struct OutOfRangeInteger {
208208
pub span: Span,
209209
}
210210

211-
#[derive(Diagnostic)]
212-
#[diag(codegen_ssa_expected_one_argument, code = E0722)]
213-
pub(crate) struct ExpectedOneArgumentOptimize {
214-
#[primary_span]
215-
pub span: Span,
216-
}
217-
218-
#[derive(Diagnostic)]
219-
#[diag(codegen_ssa_invalid_argument, code = E0722)]
220-
pub(crate) struct InvalidArgumentOptimize {
221-
#[primary_span]
222-
pub span: Span,
223-
}
224-
225211
#[derive(Diagnostic)]
226212
#[diag(codegen_ssa_copy_path_buf)]
227213
pub(crate) struct CopyPathBuf {

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
463463
);
464464
}
465465

466-
fn crate_inject_span(&self) -> Option<Span> {
467-
self.tcx.hir_crate_items(()).definitions().next().and_then(|id| {
468-
self.tcx.crate_level_attribute_injection_span(self.tcx.local_def_id_to_hir_id(id))
469-
})
470-
}
471-
472466
/// Check the const stability of the given item (fn or trait).
473467
fn check_callee_stability(&mut self, def_id: DefId) {
474468
match self.tcx.lookup_const_stability(def_id) {
@@ -543,7 +537,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
543537
feature,
544538
feature_enabled,
545539
safe_to_expose_on_stable: callee_safe_to_expose_on_stable,
546-
suggestion_span: self.crate_inject_span(),
547540
is_function_call: self.tcx.def_kind(def_id) != DefKind::Trait,
548541
});
549542
}
@@ -919,7 +912,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
919912
name: intrinsic.name,
920913
feature,
921914
const_stable_indirect: is_const_stable,
922-
suggestion: self.crate_inject_span(),
923915
});
924916
}
925917
Some(attrs::ConstStability {

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Concrete error types for all operations which may be invalid in a certain const context.
22
33
use hir::{ConstContext, LangItem};
4+
use rustc_errors::Diag;
45
use rustc_errors::codes::*;
5-
use rustc_errors::{Applicability, Diag};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
88
use rustc_infer::infer::TyCtxtInferExt;
@@ -384,7 +384,6 @@ pub(crate) struct CallUnstable {
384384
/// expose on stable.
385385
pub feature_enabled: bool,
386386
pub safe_to_expose_on_stable: bool,
387-
pub suggestion_span: Option<Span>,
388387
/// true if `def_id` is the function we are calling, false if `def_id` is an unstable trait.
389388
pub is_function_call: bool,
390389
}
@@ -412,20 +411,7 @@ impl<'tcx> NonConstOp<'tcx> for CallUnstable {
412411
def_path: ccx.tcx.def_path_str(self.def_id),
413412
})
414413
};
415-
// FIXME: make this translatable
416-
let msg = format!("add `#![feature({})]` to the crate attributes to enable", self.feature);
417-
#[allow(rustc::untranslatable_diagnostic)]
418-
if let Some(span) = self.suggestion_span {
419-
err.span_suggestion_verbose(
420-
span,
421-
msg,
422-
format!("#![feature({})]\n", self.feature),
423-
Applicability::MachineApplicable,
424-
);
425-
} else {
426-
err.help(msg);
427-
}
428-
414+
ccx.tcx.disabled_nightly_features(&mut err, [(String::new(), self.feature)]);
429415
err
430416
}
431417
}
@@ -452,7 +438,6 @@ pub(crate) struct IntrinsicUnstable {
452438
pub name: Symbol,
453439
pub feature: Symbol,
454440
pub const_stable_indirect: bool,
455-
pub suggestion: Option<Span>,
456441
}
457442

458443
impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
@@ -472,8 +457,7 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
472457
span,
473458
name: self.name,
474459
feature: self.feature,
475-
suggestion: self.suggestion,
476-
help: self.suggestion.is_none(),
460+
suggestion: ccx.tcx.crate_level_attribute_injection_span(),
477461
})
478462
}
479463
}

compiler/rustc_const_eval/src/errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ pub(crate) struct UnstableIntrinsic {
136136
code = "#![feature({feature})]\n",
137137
applicability = "machine-applicable"
138138
)]
139-
pub suggestion: Option<Span>,
140-
#[help(const_eval_unstable_intrinsic_suggestion)]
141-
pub help: bool,
139+
pub suggestion: Span,
142140
}
143141

144142
#[derive(Diagnostic)]

compiler/rustc_driver_impl/src/pretty.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
292292
}
293293
HirTree => {
294294
debug!("pretty printing HIR tree");
295-
format!("{:#?}", ex.tcx().hir_crate(()))
295+
ex.tcx()
296+
.hir_crate_items(())
297+
.owners()
298+
.map(|owner| format!("{:#?} => {:#?}\n", owner, ex.tcx().hir_owner_nodes(owner)))
299+
.collect()
296300
}
297301
Mir => {
298302
let mut out = Vec::new();

compiler/rustc_error_codes/src/error_codes/E0722.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
#### Note: this error code is no longer emitted by the compiler
2+
3+
This is because it was too specific to the `optimize` attribute.
4+
Similar diagnostics occur for other attributes too.
5+
The example here will now emit `E0539`
6+
17
The `optimize` attribute was malformed.
28

39
Erroneous code example:
410

5-
```compile_fail,E0722
11+
```compile_fail,E0539
612
#![feature(optimize_attribute)]
713
814
#[optimize(something)] // error: invalid argument

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ E0805: 0805,
686686
// E0707, // multiple elided lifetimes used in arguments of `async fn`
687687
// E0709, // multiple different lifetimes used in arguments of `async fn`
688688
// E0721, // `await` keyword
689+
// E0722, // replaced with a generic attribute input check
689690
// E0723, // unstable feature in `const` context
690691
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
691692
// E0744, // merged into E0728

0 commit comments

Comments
 (0)