Skip to content

Commit 4fb5f9a

Browse files
committed
Auto merge of #144075 - matthiaskrgr:rollup-3dkpclw, r=matthiaskrgr
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) - #143293 (fix `-Zsanitizer=kcfi` on `#[naked]` functions) - #143719 (Emit warning when there is no space between `-o` and arg) - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - #143891 (Port `#[coverage]` to the new attribute system) - #143967 (constify `Option` methods) - #144008 (Fix false positive double negations with macro invocation) - #144010 (Boostrap: add warning on `optimize = false`) - #144034 (tests: Test line number in debuginfo for diverging function calls) - #144049 (rustc-dev-guide subtree update) - #144056 (Copy GCC sources into the build directory even outside CI) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e466296 + d2aa754 commit 4fb5f9a

File tree

86 files changed

+1369
-1851
lines changed

Some content is hidden

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

86 files changed

+1369
-1851
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_codegen_cranelift/src/driver/aot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ fn codegen_cgu_content(
530530
for (mono_item, item_data) in mono_items {
531531
match mono_item {
532532
MonoItem::Fn(instance) => {
533-
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED)
534-
{
533+
let flags = tcx.codegen_instance_attrs(instance.def).flags;
534+
if flags.contains(CodegenFnAttrFlags::NAKED) {
535535
rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm(
536536
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
537537
instance,

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn codegen_and_compile_fn<'tcx>(
127127
module: &mut dyn Module,
128128
instance: Instance<'tcx>,
129129
) {
130-
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
130+
if tcx.codegen_instance_attrs(instance.def).flags.contains(CodegenFnAttrFlags::NAKED) {
131131
tcx.dcx()
132132
.span_fatal(tcx.def_span(instance.def_id()), "Naked asm is not supported in JIT mode");
133133
}

compiler/rustc_codegen_cranelift/src/driver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn predefine_mono_items<'tcx>(
3535
is_compiler_builtins,
3636
);
3737
let is_naked = tcx
38-
.codegen_fn_attrs(instance.def_id())
38+
.codegen_instance_attrs(instance.def)
3939
.flags
4040
.contains(CodegenFnAttrFlags::NAKED);
4141
module

compiler/rustc_codegen_gcc/src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
8787
#[cfg_attr(not(feature = "master"), allow(unused_variables))] func: Function<'gcc>,
8888
instance: ty::Instance<'tcx>,
8989
) {
90-
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
90+
let codegen_fn_attrs = cx.tcx.codegen_instance_attrs(instance.def);
9191

9292
#[cfg(feature = "master")]
9393
{

compiler/rustc_codegen_gcc/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
105105
let is_hidden = if is_generic {
106106
// This is a monomorphization of a generic function.
107107
if !(cx.tcx.sess.opts.share_generics()
108-
|| tcx.codegen_fn_attrs(instance_def_id).inline
108+
|| tcx.codegen_instance_attrs(instance.def).inline
109109
== rustc_attr_data_structures::InlineAttr::Never)
110110
{
111111
// When not sharing generics, all instances are in the same

0 commit comments

Comments
 (0)