Skip to content

Commit 30f3706

Browse files
committed
Auto merge of #144101 - jhpratt:rollup-zkqhgwt, r=jhpratt
Rollup of 12 pull requests Successful merges: - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled) - #143271 (Store the type of each GVN value) - #143280 (Remove duplicate error about raw underscore lifetime) - #143649 (Add test for `default_field_values` and `const_default`) - #143699 (Make `AsyncDrop` check that it's being implemented on a local ADT) - #143719 (Emit warning when there is no space between `-o` and arg) - #143833 (Ban projecting into SIMD types [MCP838]) - #143891 (Port `#[coverage]` to the new attribute system) - #143908 (`tests/ui`: A New Order [0/28] ) - #143909 (docs(alloc::fmt): Make type optional, instead of matching empty string) - #143925 (Make slice comparisons const) - #143997 (Use $crate in macros for rustc_public (aka stable_mir)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e466296 + bf6e9b6 commit 30f3706

File tree

149 files changed

+1983
-1902
lines changed

Some content is hidden

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

149 files changed

+1983
-1902
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ pub enum DeprecatedSince {
110110
Err,
111111
}
112112

113+
#[derive(
114+
Copy,
115+
Debug,
116+
Eq,
117+
PartialEq,
118+
Encodable,
119+
Decodable,
120+
Clone,
121+
HashStable_Generic,
122+
PrintAttribute
123+
)]
124+
pub enum CoverageStatus {
125+
On,
126+
Off,
127+
}
128+
113129
impl Deprecation {
114130
/// Whether an item marked with #[deprecated(since = "X")] is currently
115131
/// deprecated (i.e., whether X is not greater than the current rustc
@@ -274,6 +290,9 @@ pub enum AttributeKind {
274290
/// Represents `#[const_trait]`.
275291
ConstTrait(Span),
276292

293+
/// Represents `#[coverage]`.
294+
Coverage(Span, CoverageStatus),
295+
277296
///Represents `#[rustc_deny_explicit_impl]`.
278297
DenyExplicitImpl(Span),
279298

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl AttributeKind {
2828
ConstStability { .. } => Yes,
2929
ConstStabilityIndirect => No,
3030
ConstTrait(..) => No,
31+
Coverage(..) => No,
3132
DenyExplicitImpl(..) => No,
3233
Deprecation { .. } => Yes,
3334
DoNotImplementViaObject(..) => No,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr, UsedBy};
1+
use rustc_attr_data_structures::{AttributeKind, CoverageStatus, OptimizeAttr, UsedBy};
22
use rustc_feature::{AttributeTemplate, template};
33
use rustc_session::parse::feature_err;
44
use rustc_span::{Span, Symbol, sym};
@@ -52,6 +52,45 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
5252
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
5353
}
5454

55+
pub(crate) struct CoverageParser;
56+
57+
impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
58+
const PATH: &[Symbol] = &[sym::coverage];
59+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
60+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
61+
const TEMPLATE: AttributeTemplate = template!(OneOf: &[sym::off, sym::on]);
62+
63+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
64+
let Some(args) = args.list() else {
65+
cx.expected_specific_argument_and_list(cx.attr_span, vec!["on", "off"]);
66+
return None;
67+
};
68+
69+
let Some(arg) = args.single() else {
70+
cx.expected_single_argument(args.span);
71+
return None;
72+
};
73+
74+
let fail_incorrect_argument = |span| cx.expected_specific_argument(span, vec!["on", "off"]);
75+
76+
let Some(arg) = arg.meta_item() else {
77+
fail_incorrect_argument(args.span);
78+
return None;
79+
};
80+
81+
let status = match arg.path().word_sym() {
82+
Some(sym::off) => CoverageStatus::Off,
83+
Some(sym::on) => CoverageStatus::On,
84+
None | Some(_) => {
85+
fail_incorrect_argument(arg.span());
86+
return None;
87+
}
88+
};
89+
90+
Some(AttributeKind::Coverage(cx.attr_span, status))
91+
}
92+
}
93+
5594
pub(crate) struct ExportNameParser;
5695

5796
impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ use crate::attributes::allow_unstable::{
1717
AllowConstFnUnstableParser, AllowInternalUnstableParser, UnstableFeatureBoundParser,
1818
};
1919
use crate::attributes::codegen_attrs::{
20-
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OmitGdbPrettyPrinterSectionParser,
21-
OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
20+
ColdParser, CoverageParser, ExportNameParser, NakedParser, NoMangleParser,
21+
OmitGdbPrettyPrinterSectionParser, OptimizeParser, TargetFeatureParser, TrackCallerParser,
22+
UsedParser,
2223
};
2324
use crate::attributes::confusables::ConfusablesParser;
2425
use crate::attributes::deprecation::DeprecationParser;
@@ -139,6 +140,7 @@ attribute_parsers!(
139140
// tidy-alphabetical-end
140141

141142
// tidy-alphabetical-start
143+
Single<CoverageParser>,
142144
Single<DeprecationParser>,
143145
Single<DummyParser>,
144146
Single<ExportNameParser>,
@@ -452,6 +454,25 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
452454
reason: AttributeParseErrorReason::ExpectedSpecificArgument {
453455
possibilities,
454456
strings: false,
457+
list: false,
458+
},
459+
})
460+
}
461+
462+
pub(crate) fn expected_specific_argument_and_list(
463+
&self,
464+
span: Span,
465+
possibilities: Vec<&'static str>,
466+
) -> ErrorGuaranteed {
467+
self.emit_err(AttributeParseError {
468+
span,
469+
attr_span: self.attr_span,
470+
template: self.template.clone(),
471+
attribute: self.attr_path.clone(),
472+
reason: AttributeParseErrorReason::ExpectedSpecificArgument {
473+
possibilities,
474+
strings: false,
475+
list: true,
455476
},
456477
})
457478
}
@@ -469,6 +490,7 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
469490
reason: AttributeParseErrorReason::ExpectedSpecificArgument {
470491
possibilities,
471492
strings: true,
493+
list: false,
472494
},
473495
})
474496
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,22 @@ pub(crate) struct LinkOrdinalOutOfRange {
533533

534534
pub(crate) enum AttributeParseErrorReason {
535535
ExpectedNoArgs,
536-
ExpectedStringLiteral { byte_string: Option<Span> },
536+
ExpectedStringLiteral {
537+
byte_string: Option<Span>,
538+
},
537539
ExpectedIntegerLiteral,
538540
ExpectedAtLeastOneArgument,
539541
ExpectedSingleArgument,
540542
ExpectedList,
541543
UnexpectedLiteral,
542544
ExpectedNameValue(Option<Symbol>),
543545
DuplicateKey(Symbol),
544-
ExpectedSpecificArgument { possibilities: Vec<&'static str>, strings: bool },
546+
ExpectedSpecificArgument {
547+
possibilities: Vec<&'static str>,
548+
strings: bool,
549+
/// Should we tell the user to write a list when they didn't?
550+
list: bool,
551+
},
545552
}
546553

547554
pub(crate) struct AttributeParseError {
@@ -615,7 +622,11 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
615622
format!("expected this to be of the form `{name} = \"...\"`"),
616623
);
617624
}
618-
AttributeParseErrorReason::ExpectedSpecificArgument { possibilities, strings } => {
625+
AttributeParseErrorReason::ExpectedSpecificArgument {
626+
possibilities,
627+
strings,
628+
list: false,
629+
} => {
619630
let quote = if strings { '"' } else { '`' };
620631
match possibilities.as_slice() {
621632
&[] => {}
@@ -641,6 +652,38 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
641652
}
642653
}
643654
}
655+
AttributeParseErrorReason::ExpectedSpecificArgument {
656+
possibilities,
657+
strings,
658+
list: true,
659+
} => {
660+
let quote = if strings { '"' } else { '`' };
661+
match possibilities.as_slice() {
662+
&[] => {}
663+
&[x] => {
664+
diag.span_label(
665+
self.span,
666+
format!(
667+
"this attribute is only valid with {quote}{x}{quote} as an argument"
668+
),
669+
);
670+
}
671+
[first, second] => {
672+
diag.span_label(self.span, format!("this attribute is only valid with either {quote}{first}{quote} or {quote}{second}{quote} as an argument"));
673+
}
674+
[first @ .., second_to_last, last] => {
675+
let mut res = String::new();
676+
for i in first {
677+
res.push_str(&format!("{quote}{i}{quote}, "));
678+
}
679+
res.push_str(&format!(
680+
"{quote}{second_to_last}{quote} or {quote}{last}{quote}"
681+
));
682+
683+
diag.span_label(self.span, format!("this attribute is only valid with one of the following arguments: {res}"));
684+
}
685+
}
686+
}
644687
}
645688

646689
let suggestions = self.template.suggestions(false, &name);

compiler/rustc_builtin_macros/src/deriving/bounds.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) fn expand_deriving_copy(
2323
methods: Vec::new(),
2424
associated_types: Vec::new(),
2525
is_const,
26+
is_staged_api_crate: cx.ecfg.features.staged_api(),
2627
};
2728

2829
trait_def.expand(cx, mitem, item, push);
@@ -46,6 +47,7 @@ pub(crate) fn expand_deriving_const_param_ty(
4647
methods: Vec::new(),
4748
associated_types: Vec::new(),
4849
is_const,
50+
is_staged_api_crate: cx.ecfg.features.staged_api(),
4951
};
5052

5153
trait_def.expand(cx, mitem, item, push);
@@ -60,6 +62,7 @@ pub(crate) fn expand_deriving_const_param_ty(
6062
methods: Vec::new(),
6163
associated_types: Vec::new(),
6264
is_const,
65+
is_staged_api_crate: cx.ecfg.features.staged_api(),
6366
};
6467

6568
trait_def.expand(cx, mitem, item, push);
@@ -83,6 +86,7 @@ pub(crate) fn expand_deriving_unsized_const_param_ty(
8386
methods: Vec::new(),
8487
associated_types: Vec::new(),
8588
is_const,
89+
is_staged_api_crate: cx.ecfg.features.staged_api(),
8690
};
8791

8892
trait_def.expand(cx, mitem, item, push);

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub(crate) fn expand_deriving_clone(
8787
}],
8888
associated_types: Vec::new(),
8989
is_const,
90+
is_staged_api_crate: cx.ecfg.features.staged_api(),
9091
};
9192

9293
trait_def.expand_ext(cx, mitem, item, push, is_simple)

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub(crate) fn expand_deriving_eq(
4343
}],
4444
associated_types: Vec::new(),
4545
is_const,
46+
is_staged_api_crate: cx.ecfg.features.staged_api(),
4647
};
4748
trait_def.expand_ext(cx, mitem, item, push, true)
4849
}

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub(crate) fn expand_deriving_ord(
3434
}],
3535
associated_types: Vec::new(),
3636
is_const,
37+
is_staged_api_crate: cx.ecfg.features.staged_api(),
3738
};
3839

3940
trait_def.expand(cx, mitem, item, push)

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) fn expand_deriving_partial_eq(
3030
methods: Vec::new(),
3131
associated_types: Vec::new(),
3232
is_const: false,
33+
is_staged_api_crate: cx.ecfg.features.staged_api(),
3334
};
3435
structural_trait_def.expand(cx, mitem, item, push);
3536

@@ -58,6 +59,7 @@ pub(crate) fn expand_deriving_partial_eq(
5859
methods,
5960
associated_types: Vec::new(),
6061
is_const,
62+
is_staged_api_crate: cx.ecfg.features.staged_api(),
6163
};
6264
trait_def.expand(cx, mitem, item, push)
6365
}

0 commit comments

Comments
 (0)