Skip to content

Commit 321a89b

Browse files
committed
Auto merge of #145043 - Zalathar:rollup-3dbvdrm, r=Zalathar
Rollup of 19 pull requests Successful merges: - #137831 (Tweak auto trait errors) - #138689 (add nvptx_target_feature) - #140267 (implement continue_ok and break_ok for ControlFlow) - #143028 (emit `StorageLive` and schedule `StorageDead` for `let`-`else`'s bindings after matching) - #143764 (lower pattern bindings in the order they're written and base drop order on primary bindings' order) - #143808 (Port `#[should_panic]` to the new attribute parsing infrastructure ) - #143906 (Miri: non-deterministic floating point operations in `foreign_items`) - #143929 (Mark all deprecation lints in name resolution as deny-by-default and report-in-deps) - #144133 (Stabilize const TypeId::of) - #144369 (Upgrade semicolon_in_expressions_from_macros from warn to deny) - #144439 (Introduce ModernIdent type to unify macro 2.0 hygiene handling) - #144473 (Address libunwind.a inconsistency issues in the bootstrap program) - #144601 (Allow `cargo fix` to partially apply `mismatched_lifetime_syntaxes`) - #144650 (Additional tce tests) - #144659 (bootstrap: refactor mingw dist and fix gnullvm) - #144682 (Stabilize `strict_overflow_ops`) - #145026 (Update books) - #145033 (Reimplement `print_region` in `type_name.rs`.) - #145040 (rustc-dev-guide subtree update) Failed merges: - #143857 (Port #[macro_export] to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cd43430 + bd8e7fd commit 321a89b

File tree

138 files changed

+2276
-1066
lines changed

Some content is hidden

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

138 files changed

+2276
-1066
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ast_passes_auto_generic = auto traits cannot have generic parameters
4040
4141
ast_passes_auto_items = auto traits cannot have associated items
4242
.label = {ast_passes_auto_items}
43-
.suggestion = remove these associated items
43+
.suggestion = remove the associated items
4444
4545
ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
4646
.label = {ast_passes_auto_super_lifetime}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,19 +699,23 @@ impl<'a> AstValidator<'a> {
699699
}
700700
}
701701

702-
fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
702+
fn deny_super_traits(&self, bounds: &GenericBounds, ident: Span) {
703703
if let [.., last] = &bounds[..] {
704-
let span = ident_span.shrink_to_hi().to(last.span());
705-
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
704+
let span = bounds.iter().map(|b| b.span()).collect();
705+
let removal = ident.shrink_to_hi().to(last.span());
706+
self.dcx().emit_err(errors::AutoTraitBounds { span, removal, ident });
706707
}
707708
}
708709

709-
fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
710+
fn deny_where_clause(&self, where_clause: &WhereClause, ident: Span) {
710711
if !where_clause.predicates.is_empty() {
711712
// FIXME: The current diagnostic is misleading since it only talks about
712713
// super trait and lifetime bounds while we should just say “bounds”.
713-
self.dcx()
714-
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
714+
self.dcx().emit_err(errors::AutoTraitBounds {
715+
span: vec![where_clause.span],
716+
removal: where_clause.span,
717+
ident,
718+
});
715719
}
716720
}
717721

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub(crate) struct ModuleNonAscii {
344344
#[diag(ast_passes_auto_generic, code = E0567)]
345345
pub(crate) struct AutoTraitGeneric {
346346
#[primary_span]
347-
#[suggestion(code = "", applicability = "machine-applicable")]
347+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
348348
pub span: Span,
349349
#[label]
350350
pub ident: Span,
@@ -354,8 +354,9 @@ pub(crate) struct AutoTraitGeneric {
354354
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
355355
pub(crate) struct AutoTraitBounds {
356356
#[primary_span]
357-
#[suggestion(code = "", applicability = "machine-applicable")]
358-
pub span: Span,
357+
pub span: Vec<Span>,
358+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
359+
pub removal: Span,
359360
#[label]
360361
pub ident: Span,
361362
}
@@ -365,7 +366,7 @@ pub(crate) struct AutoTraitBounds {
365366
pub(crate) struct AutoTraitItems {
366367
#[primary_span]
367368
pub spans: Vec<Span>,
368-
#[suggestion(code = "", applicability = "machine-applicable")]
369+
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
369370
pub total: Span,
370371
#[label]
371372
pub ident: Span,

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,55 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
4444
})
4545
}
4646
}
47+
48+
pub(crate) struct ShouldPanicParser;
49+
50+
impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser {
51+
const PATH: &[Symbol] = &[sym::should_panic];
52+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
53+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
54+
const TEMPLATE: AttributeTemplate =
55+
template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason");
56+
57+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
58+
Some(AttributeKind::ShouldPanic {
59+
span: cx.attr_span,
60+
reason: match args {
61+
ArgParser::NoArgs => None,
62+
ArgParser::NameValue(name_value) => {
63+
let Some(str_value) = name_value.value_as_str() else {
64+
cx.expected_string_literal(
65+
name_value.value_span,
66+
Some(name_value.value_as_lit()),
67+
);
68+
return None;
69+
};
70+
Some(str_value)
71+
}
72+
ArgParser::List(list) => {
73+
let Some(single) = list.single() else {
74+
cx.expected_single_argument(list.span);
75+
return None;
76+
};
77+
let Some(single) = single.meta_item() else {
78+
cx.expected_name_value(single.span(), Some(sym::expected));
79+
return None;
80+
};
81+
if !single.path().word_is(sym::expected) {
82+
cx.expected_specific_argument_strings(list.span, vec!["expected"]);
83+
return None;
84+
}
85+
let Some(nv) = single.args().name_value() else {
86+
cx.expected_name_value(single.span(), Some(sym::expected));
87+
return None;
88+
};
89+
let Some(expected) = nv.value_as_str() else {
90+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
91+
return None;
92+
};
93+
Some(expected)
94+
}
95+
},
96+
})
97+
}
98+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::attributes::semantics::MayDangleParser;
5050
use crate::attributes::stability::{
5151
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
5252
};
53-
use crate::attributes::test_attrs::IgnoreParser;
53+
use crate::attributes::test_attrs::{IgnoreParser, ShouldPanicParser};
5454
use crate::attributes::traits::{
5555
AllowIncoherentImplParser, CoherenceIsCoreParser, CoinductiveParser, ConstTraitParser,
5656
DenyExplicitImplParser, DoNotImplementViaObjectParser, FundamentalParser, MarkerParser,
@@ -174,6 +174,7 @@ attribute_parsers!(
174174
Single<RustcLayoutScalarValidRangeEnd>,
175175
Single<RustcLayoutScalarValidRangeStart>,
176176
Single<RustcObjectLifetimeDefaultParser>,
177+
Single<ShouldPanicParser>,
177178
Single<SkipDuringMethodDispatchParser>,
178179
Single<TransparencyParser>,
179180
Single<WithoutArgs<AllowIncoherentImplParser>>,

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use std::assert_matches::assert_matches;
55
use std::iter;
66

77
use rustc_ast::ptr::P;
8-
use rustc_ast::{self as ast, GenericParamKind, attr, join_path_idents};
8+
use rustc_ast::{self as ast, GenericParamKind, HasNodeId, attr, join_path_idents};
99
use rustc_ast_pretty::pprust;
10+
use rustc_attr_parsing::AttributeParser;
1011
use rustc_errors::{Applicability, Diag, Level};
1112
use rustc_expand::base::*;
13+
use rustc_hir::Attribute;
14+
use rustc_hir::attrs::AttributeKind;
1215
use rustc_span::{ErrorGuaranteed, FileNameDisplayPreference, Ident, Span, Symbol, sym};
1316
use thin_vec::{ThinVec, thin_vec};
1417
use tracing::debug;
@@ -473,39 +476,19 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
473476
}
474477

475478
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
476-
match attr::find_by_name(&i.attrs, sym::should_panic) {
477-
Some(attr) => {
478-
match attr.meta_item_list() {
479-
// Handle #[should_panic(expected = "foo")]
480-
Some(list) => {
481-
let msg = list
482-
.iter()
483-
.find(|mi| mi.has_name(sym::expected))
484-
.and_then(|mi| mi.meta_item())
485-
.and_then(|mi| mi.value_str());
486-
if list.len() != 1 || msg.is_none() {
487-
cx.dcx()
488-
.struct_span_warn(
489-
attr.span,
490-
"argument must be of the form: \
491-
`expected = \"error message\"`",
492-
)
493-
.with_note(
494-
"errors in this attribute were erroneously \
495-
allowed and will become a hard error in a \
496-
future release",
497-
)
498-
.emit();
499-
ShouldPanic::Yes(None)
500-
} else {
501-
ShouldPanic::Yes(msg)
502-
}
503-
}
504-
// Handle #[should_panic] and #[should_panic = "expected"]
505-
None => ShouldPanic::Yes(attr.value_str()),
506-
}
507-
}
508-
None => ShouldPanic::No,
479+
if let Some(Attribute::Parsed(AttributeKind::ShouldPanic { reason, .. })) =
480+
AttributeParser::parse_limited(
481+
cx.sess,
482+
&i.attrs,
483+
sym::should_panic,
484+
i.span,
485+
i.node_id(),
486+
None,
487+
)
488+
{
489+
ShouldPanic::Yes(reason)
490+
} else {
491+
ShouldPanic::No
509492
}
510493
}
511494

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
262262
// Filter out features that are not supported by the current LLVM version
263263
("aarch64", "fpmr") => None, // only existed in 18
264264
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
265+
// NVPTX targets added in LLVM 20
266+
("nvptx64", "sm_100") if get_version().0 < 20 => None,
267+
("nvptx64", "sm_100a") if get_version().0 < 20 => None,
268+
("nvptx64", "sm_101") if get_version().0 < 20 => None,
269+
("nvptx64", "sm_101a") if get_version().0 < 20 => None,
270+
("nvptx64", "sm_120") if get_version().0 < 20 => None,
271+
("nvptx64", "sm_120a") if get_version().0 < 20 => None,
272+
("nvptx64", "ptx86") if get_version().0 < 20 => None,
273+
("nvptx64", "ptx87") if get_version().0 < 20 => None,
265274
// Filter out features that are not supported by the current LLVM version
266275
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq")
267276
if get_version().0 < 20 =>
@@ -324,15 +333,12 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
324333
///
325334
/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled outside codegen.
326335
pub(crate) fn target_config(sess: &Session) -> TargetConfig {
327-
// Add base features for the target.
328-
// We do *not* add the -Ctarget-features there, and instead duplicate the logic for that below.
329-
// The reason is that if LLVM considers a feature implied but we do not, we don't want that to
330-
// show up in `cfg`. That way, `cfg` is entirely under our control -- except for the handling of
331-
// the target CPU, that is still expanded to target features (with all their implied features)
332-
// by LLVM.
333336
let target_machine = create_informational_target_machine(sess, true);
334337

335338
let (unstable_target_features, target_features) = cfg_target_feature(sess, |feature| {
339+
// This closure determines whether the target CPU has the feature according to LLVM. We do
340+
// *not* consider the `-Ctarget-feature`s here, as that will be handled later in
341+
// `cfg_target_feature`.
336342
if let Some(feat) = to_llvm_features(sess, feature) {
337343
// All the LLVM features this expands to must be enabled.
338344
for llvm_feature in feat {

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ fn parse_rust_feature_flag<'a>(
197197
/// 2nd component of the return value, respectively).
198198
///
199199
/// `target_base_has_feature` should check whether the given feature (a Rust feature name!) is
200-
/// enabled in the "base" target machine, i.e., without applying `-Ctarget-feature`.
200+
/// enabled in the "base" target machine, i.e., without applying `-Ctarget-feature`. Note that LLVM
201+
/// may consider features to be implied that we do not and vice-versa. We want `cfg` to be entirely
202+
/// consistent with Rust feature implications, and thus only consult LLVM to expand the target CPU
203+
/// to target features.
201204
///
202205
/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled elsewhere.
203206
pub fn cfg_target_feature(
@@ -211,7 +214,15 @@ pub fn cfg_target_feature(
211214
.rust_target_features()
212215
.iter()
213216
.filter(|(feature, _, _)| target_base_has_feature(feature))
214-
.map(|(feature, _, _)| Symbol::intern(feature))
217+
.flat_map(|(base_feature, _, _)| {
218+
// Expand the direct base feature into all transitively-implied features. Note that we
219+
// cannot simply use the `implied` field of the tuple since that only contains
220+
// directly-implied features.
221+
//
222+
// Iteration order is irrelevant because we're collecting into an `UnordSet`.
223+
#[allow(rustc::potential_query_instability)]
224+
sess.target.implied_target_features(base_feature).into_iter().map(|f| Symbol::intern(f))
225+
})
215226
.collect();
216227

217228
// Add enabled and remove disabled features.

compiler/rustc_const_eval/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
33
#![allow(rustc::diagnostic_outside_of_impl)]
4+
#![cfg_attr(bootstrap, feature(strict_overflow_ops))]
45
#![doc(rust_logo)]
56
#![feature(array_try_map)]
67
#![feature(assert_matches)]
@@ -10,7 +11,6 @@
1011
#![feature(never_type)]
1112
#![feature(rustdoc_internals)]
1213
#![feature(slice_ptr_get)]
13-
#![feature(strict_overflow_ops)]
1414
#![feature(trait_alias)]
1515
#![feature(try_blocks)]
1616
#![feature(unqualified_local_imports)]

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
1818
}
1919

2020
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
21-
unreachable!(); // because `<Self As PrettyPrinter>::should_print_region` returns false
21+
// This is reachable (via `pretty_print_dyn_existential`) even though
22+
// `<Self As PrettyPrinter>::should_print_region` returns false. See #144994.
23+
Ok(())
2224
}
2325

2426
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {

0 commit comments

Comments
 (0)