Skip to content

Commit 21a13b8

Browse files
committed
Auto merge of #147151 - Zalathar:rollup-w81rn0j, r=Zalathar
Rollup of 5 pull requests Successful merges: - #146653 (improve diagnostics for empty attributes) - #146987 (impl Ord for params and use unstable sort) - #147101 (Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library ) - #147123 (Fix removed version numbers of `doc_auto_cfg` and `doc_cfg_hide`) - #147149 (add joboet to library review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 128b36a + 82db672 commit 21a13b8

File tree

30 files changed

+71
-53
lines changed

30 files changed

+71
-53
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ impl PartialEq<Symbol> for Path {
114114
impl PartialEq<&[Symbol]> for Path {
115115
#[inline]
116116
fn eq(&self, names: &&[Symbol]) -> bool {
117-
self.segments.len() == names.len()
118-
&& self.segments.iter().zip(names.iter()).all(|(s1, s2)| s1 == s2)
117+
self.segments.iter().eq(*names)
119118
}
120119
}
121120

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(associated_type_defaults)]
1616
#![feature(box_patterns)]
1717
#![feature(if_let_guard)]
18+
#![feature(iter_order_by)]
1819
#![feature(macro_metavar_expr)]
1920
#![feature(rustdoc_internals)]
2021
#![recursion_limit = "256"]

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ impl TokenTree {
4848
match (self, other) {
4949
(TokenTree::Token(token, _), TokenTree::Token(token2, _)) => token.kind == token2.kind,
5050
(TokenTree::Delimited(.., delim, tts), TokenTree::Delimited(.., delim2, tts2)) => {
51-
delim == delim2
52-
&& tts.len() == tts2.len()
53-
&& tts.iter().zip(tts2.iter()).all(|(a, b)| a.eq_unspanned(b))
51+
delim == delim2 && tts.iter().eq_by(tts2.iter(), |a, b| a.eq_unspanned(b))
5452
}
5553
_ => false,
5654
}

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ attr_parsing_deprecated_item_suggestion =
88
99
attr_parsing_empty_attribute =
1010
unused attribute
11-
.suggestion = remove this attribute
11+
.suggestion = {$valid_without_list ->
12+
[true] remove these parentheses
13+
*[other] remove this attribute
14+
}
15+
.note = {$valid_without_list ->
16+
[true] using `{$attr_path}` with an empty list is equivalent to not using a list at all
17+
*[other] using `{$attr_path}` with an empty list has no effect
18+
}
19+
1220
1321
attr_parsing_invalid_target = `#[{$name}]` attribute cannot be used on {$target}
1422
.help = `#[{$name}]` can {$only}be applied to {$applied}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,12 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
597597
}
598598

599599
pub(crate) fn warn_empty_attribute(&mut self, span: Span) {
600-
self.emit_lint(AttributeLintKind::EmptyAttribute { first_span: span }, span);
600+
let attr_path = self.attr_path.clone();
601+
let valid_without_list = self.template.word;
602+
self.emit_lint(
603+
AttributeLintKind::EmptyAttribute { first_span: span, attr_path, valid_without_list },
604+
span,
605+
);
601606
}
602607
}
603608

compiler/rustc_attr_parsing/src/lints.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ pub fn emit_attribute_lint<L: LintEmitter>(lint: &AttributeLint<L::Id>, lint_emi
4343
),
4444
},
4545
),
46-
AttributeLintKind::EmptyAttribute { first_span } => lint_emitter.emit_node_span_lint(
47-
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
48-
*id,
49-
*first_span,
50-
session_diagnostics::EmptyAttributeList { attr_span: *first_span },
51-
),
46+
AttributeLintKind::EmptyAttribute { first_span, attr_path, valid_without_list } => {
47+
lint_emitter.emit_node_span_lint(
48+
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
49+
*id,
50+
*first_span,
51+
session_diagnostics::EmptyAttributeList {
52+
attr_span: *first_span,
53+
attr_path: attr_path.clone(),
54+
valid_without_list: *valid_without_list,
55+
},
56+
)
57+
}
5258
AttributeLintKind::InvalidTarget { name, target, applied, only } => lint_emitter
5359
.emit_node_span_lint(
5460
// This check is here because `deprecated` had its own lint group and removing this would be a breaking change

compiler/rustc_attr_parsing/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a> PathParser<'a> {
4949
}
5050

5151
pub fn segments_is(&self, segments: &[Symbol]) -> bool {
52-
self.len() == segments.len() && self.segments().zip(segments).all(|(a, b)| a.name == *b)
52+
self.segments().map(|segment| &segment.name).eq(segments)
5353
}
5454

5555
pub fn word(&self) -> Option<Ident> {

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,12 @@ pub(crate) struct EmptyConfusables {
503503

504504
#[derive(LintDiagnostic)]
505505
#[diag(attr_parsing_empty_attribute)]
506+
#[note]
506507
pub(crate) struct EmptyAttributeList {
507508
#[suggestion(code = "", applicability = "machine-applicable")]
508509
pub attr_span: Span,
510+
pub attr_path: AttrPath,
511+
pub valid_without_list: bool,
509512
}
510513

511514
#[derive(LintDiagnostic)]

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ mod llvm_enzyme {
377377
(ast::AttrKind::Normal(a), ast::AttrKind::Normal(b)) => {
378378
let a = &a.item.path;
379379
let b = &b.item.path;
380-
a.segments.len() == b.segments.len()
381-
&& a.segments.iter().zip(b.segments.iter()).all(|(a, b)| a.ident == b.ident)
380+
a.segments.iter().eq_by(&b.segments, |a, b| a.ident == b.ident)
382381
}
383382
_ => false,
384383
}

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -356,21 +356,14 @@ fn contains_maybe_sized_bound(bounds: &[GenericBound]) -> bool {
356356
bounds.iter().any(is_maybe_sized_bound)
357357
}
358358

359-
fn path_segment_is_exact_match(path_segments: &[ast::PathSegment], syms: &[Symbol]) -> bool {
360-
path_segments.iter().zip(syms).all(|(segment, &symbol)| segment.ident.name == symbol)
361-
}
362-
363359
fn is_sized_marker(path: &ast::Path) -> bool {
364360
const CORE_UNSIZE: [Symbol; 3] = [sym::core, sym::marker, sym::Sized];
365361
const STD_UNSIZE: [Symbol; 3] = [sym::std, sym::marker, sym::Sized];
366-
if path.segments.len() == 4 && path.is_global() {
367-
path_segment_is_exact_match(&path.segments[1..], &CORE_UNSIZE)
368-
|| path_segment_is_exact_match(&path.segments[1..], &STD_UNSIZE)
369-
} else if path.segments.len() == 3 {
370-
path_segment_is_exact_match(&path.segments, &CORE_UNSIZE)
371-
|| path_segment_is_exact_match(&path.segments, &STD_UNSIZE)
362+
let segments = || path.segments.iter().map(|segment| segment.ident.name);
363+
if path.is_global() {
364+
segments().skip(1).eq(CORE_UNSIZE) || segments().skip(1).eq(STD_UNSIZE)
372365
} else {
373-
*path == sym::Sized
366+
segments().eq(CORE_UNSIZE) || segments().eq(STD_UNSIZE) || *path == sym::Sized
374367
}
375368
}
376369

0 commit comments

Comments
 (0)