Skip to content

Commit dfbea5b

Browse files
committed
Auto merge of rust-lang#159966 - JonathanBrouwer:rollup-efqUEIj, r=JonathanBrouwer
Rollup of 28 pull requests Successful merges: - rust-lang#159638 (bootstrap: Split the `Step` trait into multiple traits) - rust-lang#159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations) - rust-lang#159837 (line-tables-only test: check that the line number matches the function name) - rust-lang#159946 (Update Enzyme submodule to imporve llvm-cov) - rust-lang#159962 (miri subtree update) - rust-lang#156570 (tests: extend remap-path-prefix-std to all stdlib rlibs) - rust-lang#159617 (Fix up `#[linkage]` target checking) - rust-lang#159633 (Improve workings of attribute suggestions) - rust-lang#159733 (std: Switch implementations of `thread_local!` for WASI) - rust-lang#159783 (Check unsafe impls on safe EIIs) - rust-lang#159810 (Add tuple never coercion collection regression test) - rust-lang#159826 (Remove redundant `#[rustc_paren_sugar]` feature gate) - rust-lang#159846 (Implement `str::copy_from_str`) - rust-lang#159849 (rustc_parse: Stop returning `Option` from statement parsing) - rust-lang#159853 (Updated expect messages for `CString` struct and method documentation) - rust-lang#159875 (More cleanup in `rustc_attr_parsing`) - rust-lang#159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide) - rust-lang#159891 (Split multiline derives into std/rustc macros) - rust-lang#159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups) - rust-lang#159895 (rustc-dev-guide subtree update) - rust-lang#159902 (Clarify that the expected runtime symbols signature is for the current target only) - rust-lang#159914 (Fix error in diagnostic on_unmatched_args) - rust-lang#159917 (spare capacity mut constification) - rust-lang#159918 (rename abort_unwind → abort_on_unwind) - rust-lang#159927 (Remove sve2 from the ImpliedFeatures of AArch64 v9a.) - rust-lang#159936 (Minor `rustc_ast::ast` doc cleanups) - rust-lang#159945 (Update expect messages in library/core/src/ptr/non_null.rs) - rust-lang#159950 (Add CFI tests for return types and never type)
2 parents dc3f851 + e6a1a8f commit dfbea5b

194 files changed

Lines changed: 2509 additions & 1495 deletions

File tree

Some content is hidden

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

compiler/rustc_ast/src/ast.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub struct PathSegment {
220220
/// `None` means that no parameter list is supplied (`Path`),
221221
/// `Some` means that parameter list is supplied (`Path<X, Y>`)
222222
/// but it can be empty (`Path<>`).
223-
/// `P` is used as a size optimization for the common case with no parameters.
223+
/// `Box` is used as a size optimization for the common case with no parameters.
224224
pub args: Option<Box<GenericArgs>>,
225225
}
226226

@@ -557,9 +557,10 @@ pub struct Crate {
557557
pub is_placeholder: bool,
558558
}
559559

560-
/// A semantic representation of a meta item. A meta item is a slightly
561-
/// restricted form of an attribute -- it can only contain expressions in
562-
/// certain leaf positions, rather than arbitrary token streams -- that is used
560+
/// A semantic representation of a meta item.
561+
///
562+
/// A meta item is a slightly restricted form of an attribute -- it can only contain
563+
/// expressions in certain leaf positions, rather than arbitrary token streams -- that is used
563564
/// for most built-in attributes.
564565
///
565566
/// E.g., `#[test]`, `#[derive(..)]`, `#[rustfmt::skip]` or `#[feature = "foo"]`.
@@ -806,6 +807,7 @@ impl ByRef {
806807
}
807808

808809
/// The mode of a binding (`mut`, `ref mut`, etc).
810+
///
809811
/// Used for both the explicit binding annotations given in the HIR for a binding
810812
/// and the final binding mode that we infer after type inference/match ergonomics.
811813
/// `.0` is the by-reference mode (`ref`, `ref mut`, or by value),
@@ -1184,7 +1186,9 @@ impl UnOp {
11841186
}
11851187
}
11861188

1187-
/// A statement. No `attrs` or `tokens` fields because each `StmtKind` variant
1189+
/// A statement.
1190+
///
1191+
/// No `attrs` or `tokens` fields because each `StmtKind` variant
11881192
/// contains an AST node with those fields. (Except for `StmtKind::Empty`,
11891193
/// which never has attrs or tokens)
11901194
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -1375,6 +1379,8 @@ pub enum UnsafeSource {
13751379
UserProvided,
13761380
}
13771381

1382+
/// An anonymous constant.
1383+
///
13781384
/// A constant (expression) that's not an item or associated item,
13791385
/// but needs its own `DefId` for type-checking, const-eval, etc.
13801386
/// These are usually found nested inside types (e.g., array lengths)
@@ -1962,8 +1968,9 @@ pub enum UnsafeBinderCastKind {
19621968
Unwrap,
19631969
}
19641970

1965-
/// The explicit `Self` type in a "qualified path". The actual
1966-
/// path, including the trait and the associated item, is stored
1971+
/// The explicit `Self` type in a "qualified path".
1972+
///
1973+
/// The actual path, including the trait and the associated item, is stored
19671974
/// separately. `position` represents the index of the associated
19681975
/// item qualified with this `Self` type.
19691976
///
@@ -3503,6 +3510,8 @@ pub struct AttrItem {
35033510
pub span: Span,
35043511
}
35053512

3513+
/// A synthetic attribute.
3514+
///
35063515
/// Synthetic attributes are inserted by the compiler. They cannot be written in source code, and
35073516
/// so cannot be pretty-printed by the AST pretty printer (because its output should be valid Rust
35083517
/// code). They receive special treatment because they must not affect observable language
@@ -3525,7 +3534,7 @@ pub enum SyntheticAttr {
35253534
/// evaluated true or not (or even failed to parse). The `pred` and `attrs` are not recorded
35263535
/// because they are not needed.
35273536
///
3528-
/// The attribute is used by some clippy lints.
3537+
/// The attribute is used by rustdoc to display `doc_cfg` information and by some clippy lints.
35293538
CfgAttrTrace(CfgEntry),
35303539
}
35313540

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
155155
hir::attrs::EiiImpl {
156156
span: self.lower_span(*span),
157157
inner_span: self.lower_span(*inner_span),
158-
impl_marked_unsafe: self.lower_safety(*impl_safety, hir::Safety::Safe).is_unsafe(),
158+
impl_unsafe_span: match *impl_safety {
159+
Safety::Unsafe(span) => Some(self.lower_span(span)),
160+
Safety::Safe(_) | Safety::Default => None,
161+
},
159162
is_default: *is_default,
160163
resolution,
161164
}

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use crate::session_diagnostics::{
2727
ParsedDescription,
2828
};
2929
use crate::{
30-
AttrSuggestionStyle, AttributeParser, AttributeTemplate, check_cfg, parse_version,
31-
session_diagnostics, template,
30+
AttributeParser, AttributeTemplate, check_cfg, parse_version, session_diagnostics, template,
3231
};
3332

3433
pub const CFG_TEMPLATE: AttributeTemplate = template!(
@@ -329,12 +328,12 @@ pub fn parse_cfg_attr(
329328
Ok(r) => return Some(r),
330329
Err(e) => {
331330
let suggestions = CFG_ATTR_TEMPLATE.suggestions(
332-
AttrSuggestionStyle::Attribute(cfg_attr.style),
331+
ParsedDescription::Attribute,
333332
cfg_attr.get_normal_item().unsafety,
334333
sym::cfg_attr,
335334
);
336335
e.with_span_suggestions(
337-
cfg_attr.span,
336+
cfg_attr.get_normal_item().span,
338337
"must be of the form",
339338
suggestions,
340339
Applicability::HasPlaceholders,
@@ -358,15 +357,14 @@ pub fn parse_cfg_attr(
358357

359358
sess.dcx().emit_err(AttributeParseError {
360359
span,
361-
attr_span: cfg_attr.span,
362360
inner_span: cfg_attr.get_normal_item().span,
363361
template: CFG_ATTR_TEMPLATE,
364362
path: AttrPath::from_ast(&cfg_attr.get_normal_item().path, identity),
365363
description: ParsedDescription::Attribute,
366364
reason,
367365
suggestions: session_diagnostics::AttributeParseErrorSuggestions::CreatedByTemplate(
368366
CFG_ATTR_TEMPLATE.suggestions(
369-
AttrSuggestionStyle::Attribute(cfg_attr.style),
367+
ParsedDescription::Attribute,
370368
cfg_attr.get_normal_item().unsafety,
371369
sym::cfg_attr,
372370
),

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl AttributeParser for NakedParser {
305305
if other_attr.word_is(sym::target_feature) {
306306
if !cx.features().naked_functions_target_feature() {
307307
feature_err(
308-
&cx.sess(),
308+
cx.sess(),
309309
sym::naked_functions_target_feature,
310310
other_attr.span(),
311311
"`#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions",
@@ -396,7 +396,7 @@ impl AttributeParser for UsedParser {
396396
Some(sym::compiler) => {
397397
if !cx.features().used_with_arg() {
398398
feature_err(
399-
&cx.sess(),
399+
cx.sess(),
400400
sym::used_with_arg,
401401
cx.attr_span,
402402
"`#[used(compiler)]` is currently unstable",
@@ -408,7 +408,7 @@ impl AttributeParser for UsedParser {
408408
Some(sym::linker) => {
409409
if !cx.features().used_with_arg() {
410410
feature_err(
411-
&cx.sess(),
411+
cx.sess(),
412412
sym::used_with_arg,
413413
cx.attr_span,
414414
"`#[used(linker)]` is currently unstable",
@@ -503,7 +503,7 @@ fn parse_tf_attribute(
503503
let Some(value_str) = cx.expect_string_literal(value) else {
504504
return features;
505505
};
506-
for feature in value_str.as_str().split(",") {
506+
for feature in value_str.as_str().split(',') {
507507
features.push((Symbol::intern(feature), item.span()));
508508
}
509509
}
@@ -602,7 +602,7 @@ impl SingleAttributeParser for InstrumentFnParser {
602602
const STABILITY: AttributeStability = unstable!(instrument_fn);
603603

604604
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
605-
let instrument = match args {
605+
match args {
606606
ArgParser::NameValue(nv) => match nv.value_as_str() {
607607
Some(sym::on) => Some(AttributeKind::InstrumentFn(InstrumentFnAttr::On)),
608608
Some(sym::off) => Some(AttributeKind::InstrumentFn(InstrumentFnAttr::Off)),
@@ -621,8 +621,7 @@ impl SingleAttributeParser for InstrumentFnParser {
621621
cx.adcx().expected_specific_argument_strings(span, &[sym::on, sym::off]);
622622
None
623623
}
624-
};
625-
instrument
624+
}
626625
}
627626
}
628627

@@ -673,14 +672,7 @@ impl SingleAttributeParser for SanitizeParser {
673672
let is_on = match value.value_as_str() {
674673
Some(sym::on) => true,
675674
Some(sym::off) => false,
676-
Some(_) => {
677-
cx.adcx().expected_specific_argument_strings(
678-
value.value_span,
679-
&[sym::on, sym::off],
680-
);
681-
return;
682-
}
683-
None => {
675+
_ => {
684676
cx.adcx().expected_specific_argument_strings(
685677
value.value_span,
686678
&[sym::on, sym::off],
@@ -737,7 +729,6 @@ impl SingleAttributeParser for SanitizeParser {
737729
sym::realtime,
738730
],
739731
);
740-
continue;
741732
}
742733
}
743734
}
@@ -809,9 +800,7 @@ impl SingleAttributeParser for PatchableFunctionEntryParser {
809800
}
810801

811802
for item in meta_item_list.mixed() {
812-
let Some((ident, value)) = cx.expect_name_value(item, item.span(), None) else {
813-
return None;
814-
};
803+
let (ident, value) = cx.expect_name_value(item, item.span(), None)?;
815804

816805
let attrib_to_write = match ident.name {
817806
sym::prefix_nops => {

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn get(
2424
if let Some(value_str) = v.value_as_ident() {
2525
Some(value_str)
2626
} else {
27-
cx.adcx().expected_string_literal(v.value_span, Some(&v.value_as_lit()));
27+
cx.adcx().expected_string_literal(v.value_span, Some(v.value_as_lit()));
2828
None
2929
}
3030
}

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub(crate) enum Mode {
4949
}
5050

5151
impl Mode {
52-
fn as_str(&self) -> &'static str {
52+
fn as_str(self) -> &'static str {
5353
match self {
5454
Self::RustcOnUnimplemented => "rustc_on_unimplemented",
5555
Self::DiagnosticOnUnimplemented => "diagnostic::on_unimplemented",
@@ -61,7 +61,7 @@ impl Mode {
6161
}
6262
}
6363

64-
fn expected_options(&self) -> &'static str {
64+
fn expected_options(self) -> &'static str {
6565
const DEFAULT: &str =
6666
"at least one of the `message`, `note` and `label` options are expected";
6767
const DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS: &str =
@@ -70,33 +70,33 @@ impl Mode {
7070
Self::RustcOnUnimplemented => {
7171
"see <https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented>"
7272
}
73-
Self::DiagnosticOnUnimplemented => DEFAULT,
74-
Self::DiagnosticOnConst => DEFAULT,
75-
Self::DiagnosticOnMove => DEFAULT,
76-
Self::DiagnosticOnUnknown => DEFAULT,
77-
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
73+
Self::DiagnosticOnUnimplemented
74+
| Self::DiagnosticOnConst
75+
| Self::DiagnosticOnMove
76+
| Self::DiagnosticOnUnknown
77+
| Self::DiagnosticOnUnmatchedArgs => DEFAULT,
7878
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_EXPECTED_OPTIONS,
7979
}
8080
}
8181

82-
fn allowed_options(&self) -> &'static str {
82+
fn allowed_options(self) -> &'static str {
8383
const DEFAULT: &str = "only `message`, `note` and `label` are allowed as options";
8484
const DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS: &str =
8585
"only `note` is allowed as option for `diagnostic::on_type_error`";
8686
match self {
8787
Self::RustcOnUnimplemented => {
8888
"see <https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented>"
8989
}
90-
Self::DiagnosticOnUnimplemented => DEFAULT,
91-
Self::DiagnosticOnConst => DEFAULT,
92-
Self::DiagnosticOnMove => DEFAULT,
93-
Self::DiagnosticOnUnknown => DEFAULT,
94-
Self::DiagnosticOnUnmatchedArgs => DEFAULT,
90+
Self::DiagnosticOnUnimplemented
91+
| Self::DiagnosticOnConst
92+
| Self::DiagnosticOnMove
93+
| Self::DiagnosticOnUnknown
94+
| Self::DiagnosticOnUnmatchedArgs => DEFAULT,
9595
Self::DiagnosticOnTypeError => DIAGNOSTIC_ON_TYPE_ERROR_ALLOWED_OPTIONS,
9696
}
9797
}
9898

99-
fn allowed_format_arguments(&self) -> &'static str {
99+
fn allowed_format_arguments(self) -> &'static str {
100100
match self {
101101
Self::RustcOnUnimplemented => {
102102
"see <https://rustc-dev-guide.rust-lang.org/diagnostics.html#rustc_on_unimplemented> for allowed format arguments"
@@ -356,12 +356,11 @@ fn parse_directive_items<'p>(
356356
if is_root {
357357
let items = or_malformed!(item.args().as_list()?);
358358
let mut iter = items.mixed();
359-
let filter: &MetaItemOrLitParser = match iter.next() {
360-
Some(c) => c,
361-
None => {
362-
cx.emit_err(InvalidOnClause::Empty { span });
363-
continue;
364-
}
359+
let filter = if let Some(c) = iter.next() {
360+
c
361+
} else {
362+
cx.emit_err(InvalidOnClause::Empty { span });
363+
continue;
365364
};
366365

367366
let filter = parse_filter(filter);

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unmatched_args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ impl AttributeParser for OnUnmatchedArgsParser {
1717
AttributeStability::Stable, // Unstable, stability checked manually in the parser
1818
|this, cx, args| {
1919
if !cx.features().diagnostic_on_unmatched_args() {
20+
// `UnknownDiagnosticAttribute` is emitted in rustc_resolve/macros.rs
21+
args.ignore_args();
2022
return;
2123
}
2224

compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl AttributeParser for OpaqueParser {
4545
AllowedTargets::AllowListWarnRest(&[Allow(Target::MacroDef)]);
4646

4747
fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option<AttributeKind> {
48-
if let Some(_) = self.attr_span { Some(AttributeKind::Opaque) } else { None }
48+
if self.attr_span.is_some() { Some(AttributeKind::Opaque) } else { None }
4949
}
5050
}
5151

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ impl DocParser {
728728
match args {
729729
ArgParser::NoArgs => {
730730
let suggestions = cx.adcx().suggestions();
731-
let span = cx.attr_span;
731+
let span = cx.inner_span;
732732
cx.emit_lint(
733733
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
734734
IllFormedAttributeInput::new(&suggestions, None, None),

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ impl SingleAttributeParser for InlineParser {
5050
}
5151
_ => {
5252
cx.adcx().expected_specific_argument(l.span(), &[sym::always, sym::never]);
53-
return None;
53+
None
5454
}
5555
}
5656
}
5757
ArgParser::NameValue(_) => {
5858
cx.adcx().warn_ill_formed_attribute_input(ILL_FORMED_ATTRIBUTE_INPUT);
59-
return None;
59+
None
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)