Skip to content

Commit 702aba1

Browse files
committed
Auto merge of #146873 - Zalathar:rollup-u87iupw, r=Zalathar
Rollup of 10 pull requests Successful merges: - #145411 (regression test for Cow<[u8]> layout) - #146317 (Add panic=immediate-abort) - #146397 (std_detect on Darwin AArch64: update features) - #146594 (bootstrap: Don't force -static for musl targets in cc-rs) - #146652 (Port `feature` to the new attribute system) - #146791 (emit attribute for readonly non-pure inline assembly) - #146831 (Support ctr and lr as clobber-only registers in PowerPC inline assembly) - #146838 (Introduce "wrapper" helpers to rustdoc) - #146846 (btree InternalNode::new safety comments) - #146858 (Make mips64el-unknown-linux-muslabi64 link dynamically) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9f32ccf + 6335498 commit 702aba1

File tree

123 files changed

+1832
-898
lines changed

Some content is hidden

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

123 files changed

+1832
-898
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,6 +3409,7 @@ dependencies = [
34093409
"rustc_errors",
34103410
"rustc_feature",
34113411
"rustc_fluent_macro",
3412+
"rustc_hir",
34123413
"rustc_macros",
34133414
"rustc_session",
34143415
"rustc_span",

compiler/rustc_ast_passes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1414
rustc_errors = { path = "../rustc_errors" }
1515
rustc_feature = { path = "../rustc_feature" }
1616
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
17+
rustc_hir = { path = "../rustc_hir" }
1718
rustc_macros = { path = "../rustc_macros" }
1819
rustc_session = { path = "../rustc_session" }
1920
rustc_span = { path = "../rustc_span" }

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{NodeId, PatKind, attr, token};
4+
use rustc_attr_parsing::AttributeParser;
45
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features};
6+
use rustc_hir::Attribute;
7+
use rustc_hir::attrs::AttributeKind;
58
use rustc_session::Session;
69
use rustc_session::parse::{feature_err, feature_warn};
710
use rustc_span::source_map::Spanned;
8-
use rustc_span::{Span, Symbol, sym};
11+
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
912
use thin_vec::ThinVec;
1013

1114
use crate::errors;
@@ -587,17 +590,27 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
587590
return;
588591
}
589592
let mut errored = false;
590-
for attr in krate.attrs.iter().filter(|attr| attr.has_name(sym::feature)) {
593+
594+
if let Some(Attribute::Parsed(AttributeKind::Feature(feature_idents, first_span))) =
595+
AttributeParser::parse_limited(
596+
sess,
597+
&krate.attrs,
598+
sym::feature,
599+
DUMMY_SP,
600+
krate.id,
601+
Some(&features),
602+
)
603+
{
591604
// `feature(...)` used on non-nightly. This is definitely an error.
592605
let mut err = errors::FeatureOnNonNightly {
593-
span: attr.span,
606+
span: first_span,
594607
channel: option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)"),
595608
stable_features: vec![],
596609
sugg: None,
597610
};
598611

599612
let mut all_stable = true;
600-
for ident in attr.meta_item_list().into_iter().flatten().flat_map(|nested| nested.ident()) {
613+
for ident in feature_idents {
601614
let name = ident.name;
602615
let stable_since = features
603616
.enabled_lang_features()
@@ -612,7 +625,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
612625
}
613626
}
614627
if all_stable {
615-
err.sugg = Some(attr.span);
628+
err.sugg = Some(first_span);
616629
}
617630
sess.dcx().emit_err(err);
618631
errored = true;

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,7 @@ attr_parsing_whole_archive_needs_static =
259259
attr_parsing_limit_invalid =
260260
`limit` must be a non-negative integer
261261
.label = {$error_str}
262+
263+
attr_parsing_feature_single_word =
264+
rust features are always a single identifier, not paths with multiple segments
265+
.help = did you maybe mean `{$first_segment}`?

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::num::IntErrorKind;
33
use rustc_hir::limit::Limit;
44

55
use super::prelude::*;
6-
use crate::session_diagnostics::LimitInvalid;
6+
use crate::session_diagnostics::{FeatureExpectedSingleWord, LimitInvalid};
77

88
impl<S: Stage> AcceptContext<'_, '_, S> {
99
fn parse_limit_int(&self, nv: &NameValueParser) -> Option<Limit> {
@@ -183,3 +183,55 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcCoherenceIsCoreParser {
183183
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
184184
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcCoherenceIsCore;
185185
}
186+
187+
pub(crate) struct FeatureParser;
188+
189+
impl<S: Stage> CombineAttributeParser<S> for FeatureParser {
190+
const PATH: &[Symbol] = &[sym::feature];
191+
type Item = Ident;
192+
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Feature;
193+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::CrateLevel;
194+
const TEMPLATE: AttributeTemplate = template!(List: &["feature1, feature2, ..."]);
195+
196+
fn extend<'c>(
197+
cx: &'c mut AcceptContext<'_, '_, S>,
198+
args: &'c ArgParser<'_>,
199+
) -> impl IntoIterator<Item = Self::Item> + 'c {
200+
let ArgParser::List(list) = args else {
201+
cx.expected_list(cx.attr_span);
202+
return Vec::new();
203+
};
204+
205+
if list.is_empty() {
206+
cx.warn_empty_attribute(cx.attr_span);
207+
}
208+
209+
let mut res = Vec::new();
210+
211+
for elem in list.mixed() {
212+
let Some(elem) = elem.meta_item() else {
213+
cx.expected_identifier(elem.span());
214+
continue;
215+
};
216+
if let Err(arg_span) = elem.args().no_args() {
217+
cx.expected_no_args(arg_span);
218+
continue;
219+
}
220+
221+
let path = elem.path();
222+
let Some(ident) = path.word() else {
223+
let first_segment = elem.path().segments().next().expect("at least one segment");
224+
cx.emit_err(FeatureExpectedSingleWord {
225+
span: path.span(),
226+
first_segment_span: first_segment.span,
227+
first_segment: first_segment.name,
228+
});
229+
continue;
230+
};
231+
232+
res.push(ident);
233+
}
234+
235+
res
236+
}
237+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use crate::attributes::codegen_attrs::{
2525
};
2626
use crate::attributes::confusables::ConfusablesParser;
2727
use crate::attributes::crate_level::{
28-
CrateNameParser, MoveSizeLimitParser, NoCoreParser, NoStdParser, PatternComplexityLimitParser,
29-
RecursionLimitParser, RustcCoherenceIsCoreParser, TypeLengthLimitParser,
28+
CrateNameParser, FeatureParser, MoveSizeLimitParser, NoCoreParser, NoStdParser,
29+
PatternComplexityLimitParser, RecursionLimitParser, RustcCoherenceIsCoreParser,
30+
TypeLengthLimitParser,
3031
};
3132
use crate::attributes::deprecation::DeprecationParser;
3233
use crate::attributes::dummy::DummyParser;
@@ -163,6 +164,7 @@ attribute_parsers!(
163164
// tidy-alphabetical-start
164165
Combine<AllowConstFnUnstableParser>,
165166
Combine<AllowInternalUnstableParser>,
167+
Combine<FeatureParser>,
166168
Combine<ForceTargetFeatureParser>,
167169
Combine<LinkParser>,
168170
Combine<ReprParser>,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,14 @@ pub(crate) struct LimitInvalid<'a> {
968968
pub value_span: Span,
969969
pub error_str: &'a str,
970970
}
971+
972+
#[derive(Diagnostic)]
973+
#[diag(attr_parsing_feature_single_word)]
974+
pub(crate) struct FeatureExpectedSingleWord {
975+
#[primary_span]
976+
pub span: Span,
977+
978+
#[help]
979+
pub first_segment_span: Span,
980+
pub first_segment: Symbol,
981+
}

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ pub fn inject(
6363

6464
if sess.is_test_crate() {
6565
let panic_strategy = match (panic_strategy, sess.opts.unstable_opts.panic_abort_tests) {
66-
(PanicStrategy::Abort, true) => PanicStrategy::Abort,
67-
(PanicStrategy::Abort, false) => {
66+
(PanicStrategy::Abort | PanicStrategy::ImmediateAbort, true) => panic_strategy,
67+
(PanicStrategy::Abort | PanicStrategy::ImmediateAbort, false) => {
6868
if panic_strategy == platform_panic_strategy {
6969
// Silently allow compiling with panic=abort on these platforms,
7070
// but with old behavior (abort if a test fails).
@@ -287,10 +287,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> Box<ast::Item> {
287287
let ecx = &cx.ext_cx;
288288
let test_ident = Ident::new(sym::test, sp);
289289

290-
let runner_name = match cx.panic_strategy {
291-
PanicStrategy::Unwind => "test_main_static",
292-
PanicStrategy::Abort => "test_main_static_abort",
293-
};
290+
let runner_name =
291+
if cx.panic_strategy.unwinds() { "test_main_static" } else { "test_main_static_abort" };
294292

295293
// test::test_main_static(...)
296294
let mut test_runner = cx.test_runner.clone().unwrap_or_else(|| {

compiler/rustc_codegen_gcc/src/asm.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,12 @@ fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
698698
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
699699
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
700700
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
701-
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
702-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
701+
InlineAsmRegClass::PowerPC(
702+
PowerPCInlineAsmRegClass::cr
703+
| PowerPCInlineAsmRegClass::ctr
704+
| PowerPCInlineAsmRegClass::lr
705+
| PowerPCInlineAsmRegClass::xer,
706+
) => {
703707
unreachable!("clobber-only")
704708
}
705709
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
@@ -777,8 +781,12 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
777781
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => {
778782
cx.type_vector(cx.type_i32(), 4)
779783
}
780-
InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
781-
| InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
784+
InlineAsmRegClass::PowerPC(
785+
PowerPCInlineAsmRegClass::cr
786+
| PowerPCInlineAsmRegClass::ctr
787+
| PowerPCInlineAsmRegClass::lr
788+
| PowerPCInlineAsmRegClass::xer,
789+
) => {
782790
unreachable!("clobber-only")
783791
}
784792
InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => cx.type_i32(),

compiler/rustc_codegen_gcc/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use rustc_middle::mir::mono::Visibility;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_session::config::DebugInfo;
1717
use rustc_span::Symbol;
18+
use rustc_target::spec::RelocModel;
1819
#[cfg(feature = "master")]
1920
use rustc_target::spec::SymbolVisibility;
20-
use rustc_target::spec::{PanicStrategy, RelocModel};
2121

2222
use crate::builder::Builder;
2323
use crate::context::CodegenCx;
@@ -101,7 +101,7 @@ pub fn compile_codegen_unit(
101101
// Instantiate monomorphizations without filling out definitions yet...
102102
let context = new_context(tcx);
103103

104-
if tcx.sess.panic_strategy() == PanicStrategy::Unwind {
104+
if tcx.sess.panic_strategy().unwinds() {
105105
context.add_command_line_option("-fexceptions");
106106
context.add_driver_option("-fexceptions");
107107
}

0 commit comments

Comments
 (0)