Skip to content

Commit de031bb

Browse files
committed
Auto merge of #143526 - matthiaskrgr:rollup-pm69g5v, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #143252 (Rewrite empty attribute lint for new attribute parser) - #143492 (Use `object` crate from crates.io to fix windows build error) - #143514 (Organize macro tests a bit more) - #143518 (rustc_builtin_macros: Make sure registered attributes stay sorted) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3c95364 + bff79a7 commit de031bb

File tree

72 files changed

+228
-216
lines changed

Some content is hidden

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

72 files changed

+228
-216
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ pub enum ReprAttr {
6767
ReprSimd,
6868
ReprTransparent,
6969
ReprAlign(Align),
70-
// this one is just so we can emit a lint for it
71-
ReprEmpty,
7270
}
7371
pub use ReprAttr::*;
7472

@@ -304,7 +302,7 @@ pub enum AttributeKind {
304302
PubTransparent(Span),
305303

306304
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
307-
Repr(ThinVec<(ReprAttr, Span)>),
305+
Repr { reprs: ThinVec<(ReprAttr, Span)>, first_span: Span },
308306

309307
/// Represents `#[rustc_layout_scalar_valid_range_end]`.
310308
RustcLayoutScalarValidRangeEnd(Box<u128>, Span),

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl AttributeKind {
4141
Optimize(..) => No,
4242
PassByValue(..) => Yes,
4343
PubTransparent(..) => Yes,
44-
Repr(..) => No,
44+
Repr { .. } => No,
4545
RustcLayoutScalarValidRangeEnd(..) => Yes,
4646
RustcLayoutScalarValidRangeStart(..) => Yes,
4747
RustcObjectLifetimeDefault => No,

compiler/rustc_attr_data_structures/src/lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ pub struct AttributeLint<Id> {
1212
pub enum AttributeLintKind {
1313
UnusedDuplicate { this: Span, other: Span, warning: bool },
1414
IllFormedAttributeInput { suggestions: Vec<String> },
15+
EmptyAttribute { first_span: Span },
1516
}

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ attr_parsing_deprecated_item_suggestion =
66
.help = add `#![feature(deprecated_suggestion)]` to the crate root
77
.note = see #94785 for more details
88
9+
attr_parsing_empty_attribute =
10+
unused attribute
11+
.suggestion = remove this attribute
12+
913
attr_parsing_empty_confusables =
1014
expected at least one confusable name
1115
attr_parsing_expected_one_cfg_pattern =

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
298298
cx.expected_list(cx.attr_span);
299299
return features;
300300
};
301+
if list.is_empty() {
302+
cx.warn_empty_attribute(cx.attr_span);
303+
return features;
304+
}
301305
for item in list.mixed() {
302306
let Some(name_value) = item.meta_item() else {
303307
cx.expected_name_value(item.span(), Some(sym::enable));

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ pub(crate) struct ReprParser;
2323
impl<S: Stage> CombineAttributeParser<S> for ReprParser {
2424
type Item = (ReprAttr, Span);
2525
const PATH: &[Symbol] = &[sym::repr];
26-
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::Repr(items);
26+
const CONVERT: ConvertFn<Self::Item> =
27+
|items, first_span| AttributeKind::Repr { reprs: items, first_span };
2728
// FIXME(jdonszelmann): never used
2829
const TEMPLATE: AttributeTemplate =
2930
template!(List: "C | Rust | align(...) | packed(...) | <integer type> | transparent");
@@ -40,8 +41,8 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser {
4041
};
4142

4243
if list.is_empty() {
43-
// this is so validation can emit a lint
44-
reprs.push((ReprAttr::ReprEmpty, cx.attr_span));
44+
cx.warn_empty_attribute(cx.attr_span);
45+
return reprs;
4546
}
4647

4748
for param in list.mixed() {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ mod private {
165165
#[allow(private_interfaces)]
166166
pub trait Stage: Sized + 'static + Sealed {
167167
type Id: Copy;
168+
const SHOULD_EMIT_LINTS: bool;
168169

169170
fn parsers() -> &'static group_type!(Self);
170171

@@ -175,6 +176,7 @@ pub trait Stage: Sized + 'static + Sealed {
175176
#[allow(private_interfaces)]
176177
impl Stage for Early {
177178
type Id = NodeId;
179+
const SHOULD_EMIT_LINTS: bool = false;
178180

179181
fn parsers() -> &'static group_type!(Self) {
180182
&early::ATTRIBUTE_PARSERS
@@ -188,6 +190,7 @@ impl Stage for Early {
188190
#[allow(private_interfaces)]
189191
impl Stage for Late {
190192
type Id = HirId;
193+
const SHOULD_EMIT_LINTS: bool = true;
191194

192195
fn parsers() -> &'static group_type!(Self) {
193196
&late::ATTRIBUTE_PARSERS
@@ -228,6 +231,9 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
228231
/// must be delayed until after HIR is built. This method will take care of the details of
229232
/// that.
230233
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
234+
if !S::SHOULD_EMIT_LINTS {
235+
return;
236+
}
231237
let id = self.target_id;
232238
(self.emit_lint)(AttributeLint { id, span, kind: lint });
233239
}
@@ -409,6 +415,10 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
409415
},
410416
})
411417
}
418+
419+
pub(crate) fn warn_empty_attribute(&mut self, span: Span) {
420+
self.emit_lint(AttributeLintKind::EmptyAttribute { first_span: span }, span);
421+
}
412422
}
413423

414424
impl<'f, 'sess, S: Stage> Deref for AcceptContext<'f, 'sess, S> {

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<HirId>, lint_emi
2828
},
2929
);
3030
}
31+
AttributeLintKind::EmptyAttribute { first_span } => lint_emitter.emit_node_span_lint(
32+
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
33+
*id,
34+
*first_span,
35+
session_diagnostics::EmptyAttributeList { attr_span: *first_span },
36+
),
3137
}
3238
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ pub(crate) struct EmptyConfusables {
473473
pub span: Span,
474474
}
475475

476+
#[derive(LintDiagnostic)]
477+
#[diag(attr_parsing_empty_attribute)]
478+
pub(crate) struct EmptyAttributeList {
479+
#[suggestion(code = "", applicability = "machine-applicable")]
480+
pub attr_span: Span,
481+
}
482+
476483
#[derive(Diagnostic)]
477484
#[diag(attr_parsing_invalid_alignment_value, code = E0589)]
478485
pub(crate) struct InvalidAlignmentValue {

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'a> TraitDef<'a> {
485485
Annotatable::Item(item) => {
486486
let is_packed = matches!(
487487
AttributeParser::parse_limited(cx.sess, &item.attrs, sym::repr, item.span, item.id),
488-
Some(Attribute::Parsed(AttributeKind::Repr(r))) if r.iter().any(|(x, _)| matches!(x, ReprPacked(..)))
488+
Some(Attribute::Parsed(AttributeKind::Repr { reprs, .. })) if reprs.iter().any(|(x, _)| matches!(x, ReprPacked(..)))
489489
);
490490

491491
let newitem = match &item.kind {

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
108108
}
109109

110110
register_attr! {
111+
// tidy-alphabetical-start
111112
alloc_error_handler: alloc_error_handler::expand,
112113
autodiff_forward: autodiff::expand_forward,
113114
autodiff_reverse: autodiff::expand_reverse,
@@ -120,6 +121,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
120121
global_allocator: global_allocator::expand,
121122
test: test::expand_test,
122123
test_case: test::expand_test_case,
124+
// tidy-alphabetical-end
123125
}
124126

125127
register_derive! {

compiler/rustc_codegen_gcc/Cargo.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ dependencies = [
143143
"libc",
144144
]
145145

146+
[[package]]
147+
name = "object"
148+
version = "0.37.1"
149+
source = "registry+https://github.com/rust-lang/crates.io-index"
150+
checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a"
151+
dependencies = [
152+
"memchr",
153+
]
154+
146155
[[package]]
147156
name = "once_cell"
148157
version = "1.20.2"
@@ -179,6 +188,7 @@ dependencies = [
179188
"boml",
180189
"gccjit",
181190
"lang_tester",
191+
"object",
182192
"tempfile",
183193
]
184194

compiler/rustc_codegen_gcc/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ master = ["gccjit/master"]
2222
default = ["master"]
2323

2424
[dependencies]
25+
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
26+
tempfile = "3.20"
2527
gccjit = "2.7"
2628
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }
2729

@@ -31,7 +33,6 @@ gccjit = "2.7"
3133
[dev-dependencies]
3234
boml = "0.3.1"
3335
lang_tester = "0.8.0"
34-
tempfile = "3.20"
3536

3637
[profile.dev]
3738
# By compiling dependencies with optimizations, performing tests gets much faster.

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
#![deny(clippy::pattern_type_mismatch)]
2727
#![allow(clippy::needless_lifetimes, clippy::uninlined_format_args)]
2828

29-
// Some "regular" crates we want to share with rustc
30-
extern crate object;
29+
// These crates are pulled from the sysroot because they are part of
30+
// rustc's public API, so we need to ensure version compatibility.
3131
extern crate smallvec;
32-
// FIXME(antoyo): clippy bug: remove the #[allow] when it's fixed.
33-
#[allow(unused_extern_crates)]
34-
extern crate tempfile;
3532
#[macro_use]
3633
extern crate tracing;
3734

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
109109

110110
if let hir::Attribute::Parsed(p) = attr {
111111
match p {
112-
AttributeKind::Repr(reprs) => {
112+
AttributeKind::Repr { reprs, first_span: _ } => {
113113
codegen_fn_attrs.alignment = reprs
114114
.iter()
115115
.filter_map(

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,8 +1395,7 @@ fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
13951395
pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
13961396
let repr = def.repr();
13971397
if repr.packed() {
1398-
if let Some(reprs) =
1399-
attrs::find_attr!(tcx.get_all_attrs(def.did()), attrs::AttributeKind::Repr(r) => r)
1398+
if let Some(reprs) = attrs::find_attr!(tcx.get_all_attrs(def.did()), attrs::AttributeKind::Repr { reprs, .. } => reprs)
14001399
{
14011400
for (r, _) in reprs {
14021401
if let ReprPacked(pack) = r
@@ -1619,10 +1618,10 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
16191618
if def.variants().is_empty() {
16201619
attrs::find_attr!(
16211620
tcx.get_all_attrs(def_id),
1622-
attrs::AttributeKind::Repr(rs) => {
1621+
attrs::AttributeKind::Repr { reprs, first_span } => {
16231622
struct_span_code_err!(
16241623
tcx.dcx(),
1625-
rs.first().unwrap().1,
1624+
reprs.first().map(|repr| repr.1).unwrap_or(*first_span),
16261625
E0084,
16271626
"unsupported representation for zero-variant enum"
16281627
)

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
168168
fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) {
169169
let has_repr_c = matches!(
170170
AttributeParser::parse_limited(cx.sess(), &it.attrs, sym::repr, it.span, it.id),
171-
Some(Attribute::Parsed(AttributeKind::Repr(r))) if r.iter().any(|(r, _)| r == &ReprAttr::ReprC)
171+
Some(Attribute::Parsed(AttributeKind::Repr { reprs, ..})) if reprs.iter().any(|(r, _)| r == &ReprAttr::ReprC)
172172
);
173173

174174
if has_repr_c {

compiler/rustc_macros/src/print_attribute.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ fn print_fields(name: &Ident, fields: &Fields) -> (TokenStream, TokenStream, Tok
2121
__p.word_space(",");
2222
}
2323
__p.word(#string_name);
24-
__p.word_space(":");
24+
__p.word(":");
25+
__p.nbsp();
2526
__printed_anything = true;
2627
}
2728
#name.print_attribute(__p);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,8 @@ impl<'tcx> TyCtxt<'tcx> {
15251525
field_shuffle_seed ^= user_seed;
15261526
}
15271527

1528-
if let Some(reprs) = attr::find_attr!(self.get_all_attrs(did), AttributeKind::Repr(r) => r)
1528+
if let Some(reprs) =
1529+
attr::find_attr!(self.get_all_attrs(did), AttributeKind::Repr { reprs, .. } => reprs)
15291530
{
15301531
for (r, _) in reprs {
15311532
flags.insert(match *r {
@@ -1566,10 +1567,6 @@ impl<'tcx> TyCtxt<'tcx> {
15661567
max_align = max_align.max(Some(align));
15671568
ReprFlags::empty()
15681569
}
1569-
attr::ReprEmpty => {
1570-
/* skip these, they're just for diagnostics */
1571-
ReprFlags::empty()
1572-
}
15731570
});
15741571
}
15751572
}

0 commit comments

Comments
 (0)