Skip to content

Commit df829ad

Browse files
committed
Auto merge of #144071 - fmease:rollup-xt98bx0, r=fmease
Rollup of 15 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) - #143833 (Ban projecting into SIMD types [MCP838]) - #143846 (pass --gc-sections if -Zexport-executable-symbols is enabled and improve tests) - #143879 (parse `const trait Trait`) - #143891 (Port `#[coverage]` to the new attribute system) - #143967 (constify `Option` methods) - #143985 (rustc_public: de-StableMIR-ize) - #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 bf5e6cc + ba0656f commit df829ad

File tree

297 files changed

+2892
-3557
lines changed

Some content is hidden

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

297 files changed

+2892
-3557
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,6 +3690,7 @@ impl Default for FnHeader {
36903690

36913691
#[derive(Clone, Encodable, Decodable, Debug)]
36923692
pub struct Trait {
3693+
pub constness: Const,
36933694
pub safety: Safety,
36943695
pub is_auto: IsAuto,
36953696
pub ident: Ident,

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ macro_rules! common_visitor_and_walkers {
738738
try_visit!(vis.visit_ty(self_ty));
739739
visit_assoc_items(vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() })
740740
}
741-
ItemKind::Trait(box Trait { safety, is_auto: _, ident, generics, bounds, items }) => {
741+
ItemKind::Trait(box Trait { constness, safety, is_auto: _, ident, generics, bounds, items }) => {
742+
try_visit!(visit_constness(vis, constness));
742743
try_visit!(visit_safety(vis, safety));
743744
try_visit!(vis.visit_ident(ident));
744745
try_visit!(vis.visit_generics(generics));

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
417417
items: new_impl_items,
418418
}))
419419
}
420-
ItemKind::Trait(box Trait { is_auto, safety, ident, generics, bounds, items }) => {
420+
ItemKind::Trait(box Trait {
421+
constness,
422+
is_auto,
423+
safety,
424+
ident,
425+
generics,
426+
bounds,
427+
items,
428+
}) => {
429+
let constness = self.lower_constness(*constness);
421430
let ident = self.lower_ident(*ident);
422431
let (generics, (safety, items, bounds)) = self.lower_generics(
423432
generics,
@@ -435,7 +444,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
435444
(safety, items, bounds)
436445
},
437446
);
438-
hir::ItemKind::Trait(*is_auto, safety, ident, generics, bounds, items)
447+
hir::ItemKind::Trait(constness, *is_auto, safety, ident, generics, bounds, items)
439448
}
440449
ItemKind::TraitAlias(ident, generics, bounds) => {
441450
let ident = self.lower_ident(*ident);

compiler/rustc_ast_passes/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ ast_passes_static_without_body =
240240
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
241241
.closure = closures cannot have `[const]` trait bounds
242242
.function = this function is not `const`, so it cannot have `[const]` trait bounds
243-
.trait = this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
243+
.trait = this trait is not `const`, so it cannot have `[const]` trait bounds
244244
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
245245
.impl = inherent impls cannot have `[const]` trait bounds
246-
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `[const]` trait bounds
246+
.trait_assoc_ty = associated types in non-`const` traits cannot have `[const]` trait bounds
247247
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
248248
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
249249
.object = trait objects cannot have `[const]` trait bounds

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ enum SelfSemantic {
4949
}
5050

5151
enum TraitOrTraitImpl {
52-
Trait { span: Span, constness_span: Option<Span> },
52+
Trait { span: Span, constness: Const },
5353
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref_span: Span },
5454
}
5555

5656
impl TraitOrTraitImpl {
5757
fn constness(&self) -> Option<Span> {
5858
match self {
59-
Self::Trait { constness_span: Some(span), .. }
59+
Self::Trait { constness: Const::Yes(span), .. }
6060
| Self::TraitImpl { constness: Const::Yes(span), .. } => Some(*span),
6161
_ => None,
6262
}
@@ -110,15 +110,10 @@ impl<'a> AstValidator<'a> {
110110
self.outer_trait_or_trait_impl = old;
111111
}
112112

113-
fn with_in_trait(
114-
&mut self,
115-
span: Span,
116-
constness_span: Option<Span>,
117-
f: impl FnOnce(&mut Self),
118-
) {
113+
fn with_in_trait(&mut self, span: Span, constness: Const, f: impl FnOnce(&mut Self)) {
119114
let old = mem::replace(
120115
&mut self.outer_trait_or_trait_impl,
121-
Some(TraitOrTraitImpl::Trait { span, constness_span }),
116+
Some(TraitOrTraitImpl::Trait { span, constness }),
122117
);
123118
f(self);
124119
self.outer_trait_or_trait_impl = old;
@@ -273,7 +268,7 @@ impl<'a> AstValidator<'a> {
273268
};
274269

275270
let make_trait_const_sugg = if const_trait_impl
276-
&& let TraitOrTraitImpl::Trait { span, constness_span: None } = parent
271+
&& let TraitOrTraitImpl::Trait { span, constness: ast::Const::No } = parent
277272
{
278273
Some(span.shrink_to_lo())
279274
} else {
@@ -1131,10 +1126,23 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11311126
}
11321127
visit::walk_item(self, item)
11331128
}
1134-
ItemKind::Trait(box Trait { is_auto, generics, ident, bounds, items, .. }) => {
1129+
ItemKind::Trait(box Trait {
1130+
constness,
1131+
is_auto,
1132+
generics,
1133+
ident,
1134+
bounds,
1135+
items,
1136+
..
1137+
}) => {
11351138
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1136-
let is_const_trait =
1139+
// FIXME(const_trait_impl) remove this
1140+
let alt_const_trait_span =
11371141
attr::find_by_name(&item.attrs, sym::const_trait).map(|attr| attr.span);
1142+
let constness = match (*constness, alt_const_trait_span) {
1143+
(Const::Yes(span), _) | (Const::No, Some(span)) => Const::Yes(span),
1144+
(Const::No, None) => Const::No,
1145+
};
11381146
if *is_auto == IsAuto::Yes {
11391147
// Auto traits cannot have generics, super traits nor contain items.
11401148
self.deny_generic_params(generics, ident.span);
@@ -1145,13 +1153,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11451153

11461154
// Equivalent of `visit::walk_item` for `ItemKind::Trait` that inserts a bound
11471155
// context for the supertraits.
1148-
let disallowed =
1149-
is_const_trait.is_none().then(|| TildeConstReason::Trait { span: item.span });
1156+
let disallowed = matches!(constness, ast::Const::No)
1157+
.then(|| TildeConstReason::Trait { span: item.span });
11501158
self.with_tilde_const(disallowed, |this| {
11511159
this.visit_generics(generics);
11521160
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits)
11531161
});
1154-
self.with_in_trait(item.span, is_const_trait, |this| {
1162+
self.with_in_trait(item.span, constness, |this| {
11551163
walk_list!(this, visit_assoc_item, items, AssocCtxt::Trait);
11561164
});
11571165
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ pub(crate) struct ConstBoundTraitObject {
590590
}
591591

592592
// FIXME(const_trait_impl): Consider making the note/reason the message of the diagnostic.
593-
// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` / `#[const_trait]` here).
593+
// FIXME(const_trait_impl): Provide structured suggestions (e.g., add `const` here).
594594
#[derive(Diagnostic)]
595595
#[diag(ast_passes_tilde_const_disallowed)]
596596
pub(crate) struct TildeConstDisallowed {

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'a> State<'a> {
357357
self.bclose(item.span, empty, cb);
358358
}
359359
ast::ItemKind::Trait(box ast::Trait {
360+
constness,
360361
safety,
361362
is_auto,
362363
ident,
@@ -366,6 +367,7 @@ impl<'a> State<'a> {
366367
}) => {
367368
let (cb, ib) = self.head("");
368369
self.print_visibility(&item.vis);
370+
self.print_constness(*constness);
369371
self.print_safety(*safety);
370372
self.print_is_auto(*is_auto);
371373
self.word_nbsp("trait");

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 {

0 commit comments

Comments
 (0)