Skip to content

Commit 25396cf

Browse files
committed
Auto merge of rust-lang#153139 - JonathanBrouwer:rollup-QZ4yuaa, r=JonathanBrouwer
Rollup of 2 pull requests Successful merges: - rust-lang#153055 ( Revert "Also duplicate `#[expect]` attribute in `#[derive]`-ed code") - rust-lang#153095 (Revert "rustc_expand: improve diagnostics for non-repeatable metavars")
2 parents bb779a9 + 3e1566d commit 25396cf

15 files changed

+45
-252
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ impl<'a> TraitDef<'a> {
540540
.filter(|a| {
541541
a.has_any_name(&[
542542
sym::allow,
543-
sym::expect,
544543
sym::warn,
545544
sym::deny,
546545
sym::forbid,

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,7 @@ impl<'cx> MacroExpanderResult<'cx> {
277277
// Emit the SEMICOLON_IN_EXPRESSIONS_FROM_MACROS deprecation lint.
278278
let is_local = true;
279279

280-
let parser = ParserAnyMacro::from_tts(
281-
cx,
282-
tts,
283-
site_span,
284-
arm_span,
285-
is_local,
286-
macro_ident,
287-
vec![],
288-
vec![],
289-
);
280+
let parser = ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, is_local, macro_ident);
290281
ExpandResult::Ready(Box::new(parser))
291282
}
292283
}

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,11 @@ impl<'dcx> CollectTrackerAndEmitter<'dcx, '_> {
222222

223223
pub(super) fn emit_frag_parse_err(
224224
mut e: Diag<'_>,
225-
parser: &mut Parser<'_>,
225+
parser: &Parser<'_>,
226226
orig_parser: &mut Parser<'_>,
227227
site_span: Span,
228228
arm_span: Span,
229229
kind: AstFragmentKind,
230-
bindings: Vec<Ident>,
231-
matched_rule_bindings: Vec<Ident>,
232230
) -> ErrorGuaranteed {
233231
// FIXME(davidtwco): avoid depending on the error message text
234232
if parser.token == token::Eof
@@ -287,54 +285,6 @@ pub(super) fn emit_frag_parse_err(
287285
},
288286
_ => annotate_err_with_kind(&mut e, kind, site_span),
289287
};
290-
291-
let matched_rule_bindings_names: Vec<_> =
292-
matched_rule_bindings.iter().map(|bind| bind.name).collect();
293-
let bindings_name: Vec<_> = bindings.iter().map(|bind| bind.name).collect();
294-
if parser.token.kind == token::Dollar {
295-
parser.bump();
296-
if let token::Ident(name, _) = parser.token.kind {
297-
if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(
298-
&matched_rule_bindings_names[..],
299-
name,
300-
None,
301-
) {
302-
e.span_suggestion_verbose(
303-
parser.token.span,
304-
"there is a macro metavariable with similar name",
305-
format!("{matched_name}"),
306-
Applicability::MaybeIncorrect,
307-
);
308-
} else if bindings_name.contains(&name) {
309-
e.span_label(
310-
parser.token.span,
311-
format!(
312-
"there is an macro metavariable with this name in another macro matcher"
313-
),
314-
);
315-
} else if let Some(matched_name) =
316-
rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None)
317-
{
318-
e.span_suggestion_verbose(
319-
parser.token.span,
320-
"there is a macro metavariable with a similar name in another macro matcher",
321-
format!("{matched_name}"),
322-
Applicability::MaybeIncorrect,
323-
);
324-
} else {
325-
let msg = matched_rule_bindings_names
326-
.iter()
327-
.map(|sym| format!("${}", sym))
328-
.collect::<Vec<_>>()
329-
.join(", ");
330-
331-
e.span_label(parser.token.span, format!("macro metavariable not found"));
332-
if !matched_rule_bindings_names.is_empty() {
333-
e.note(format!("available metavariable names are: {msg}"));
334-
}
335-
}
336-
}
337-
}
338288
e.emit()
339289
}
340290

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ pub(crate) struct ParserAnyMacro<'a> {
5555
arm_span: Span,
5656
/// Whether or not this macro is defined in the current crate
5757
is_local: bool,
58-
bindings: Vec<Ident>,
59-
matched_rule_bindings: Vec<Ident>,
6058
}
6159

6260
impl<'a> ParserAnyMacro<'a> {
@@ -69,22 +67,13 @@ impl<'a> ParserAnyMacro<'a> {
6967
arm_span,
7068
is_trailing_mac,
7169
is_local,
72-
bindings,
73-
matched_rule_bindings,
7470
} = *self;
7571
let snapshot = &mut parser.create_snapshot_for_diagnostic();
7672
let fragment = match parse_ast_fragment(parser, kind) {
7773
Ok(f) => f,
7874
Err(err) => {
7975
let guar = diagnostics::emit_frag_parse_err(
80-
err,
81-
parser,
82-
snapshot,
83-
site_span,
84-
arm_span,
85-
kind,
86-
bindings,
87-
matched_rule_bindings,
76+
err, parser, snapshot, site_span, arm_span, kind,
8877
);
8978
return kind.dummy(site_span, guar);
9079
}
@@ -119,9 +108,6 @@ impl<'a> ParserAnyMacro<'a> {
119108
arm_span: Span,
120109
is_local: bool,
121110
macro_ident: Ident,
122-
// bindings and lhs is for diagnostics
123-
bindings: Vec<Ident>,
124-
matched_rule_bindings: Vec<Ident>,
125111
) -> Self {
126112
Self {
127113
parser: Parser::new(&cx.sess.psess, tts, None),
@@ -135,8 +121,6 @@ impl<'a> ParserAnyMacro<'a> {
135121
is_trailing_mac: cx.current_expansion.is_trailing_mac,
136122
arm_span,
137123
is_local,
138-
bindings,
139-
matched_rule_bindings,
140124
}
141125
}
142126
}
@@ -375,7 +359,7 @@ fn expand_macro<'cx>(
375359

376360
match try_success_result {
377361
Ok((rule_index, rule, named_matches)) => {
378-
let MacroRule::Func { lhs, rhs, .. } = rule else {
362+
let MacroRule::Func { rhs, .. } = rule else {
379363
panic!("try_match_macro returned non-func rule");
380364
};
381365
let mbe::TokenTree::Delimited(rhs_span, _, rhs) = rhs else {
@@ -403,32 +387,8 @@ fn expand_macro<'cx>(
403387
cx.resolver.record_macro_rule_usage(node_id, rule_index);
404388
}
405389

406-
let mut bindings = vec![];
407-
for rule in rules {
408-
let MacroRule::Func { lhs, .. } = rule else { continue };
409-
for param in lhs {
410-
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
411-
bindings.push(*bind);
412-
}
413-
}
414-
415-
let mut matched_rule_bindings = vec![];
416-
for param in lhs {
417-
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
418-
matched_rule_bindings.push(*bind);
419-
}
420-
421390
// Let the context choose how to interpret the result. Weird, but useful for X-macros.
422-
Box::new(ParserAnyMacro::from_tts(
423-
cx,
424-
tts,
425-
sp,
426-
arm_span,
427-
is_local,
428-
name,
429-
bindings,
430-
matched_rule_bindings,
431-
))
391+
Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, is_local, name))
432392
}
433393
Err(CanRetry::No(guar)) => {
434394
debug!("Will not retry matching as an error was emitted already");

tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
2+
//
13
// Make sure we produce the unfulfilled expectation lint if neither the struct or the
24
// derived code fulfilled it.
35

46
//@ check-pass
57

68
#[expect(unexpected_cfgs)]
79
//~^ WARN this lint expectation is unfulfilled
8-
//~^^ WARN this lint expectation is unfulfilled
10+
//FIXME ~^^ WARN this lint expectation is unfulfilled
911
#[derive(Debug)]
1012
pub struct MyStruct {
1113
pub t_ref: i64,
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
warning: this lint expectation is unfulfilled
2-
--> $DIR/derive-expect-issue-150553-3.rs:6:10
2+
--> $DIR/derive-expect-issue-150553-3.rs:8:10
33
|
44
LL | #[expect(unexpected_cfgs)]
55
| ^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(unfulfilled_lint_expectations)]` on by default
88

9-
warning: this lint expectation is unfulfilled
10-
--> $DIR/derive-expect-issue-150553-3.rs:6:10
11-
|
12-
LL | #[expect(unexpected_cfgs)]
13-
| ^^^^^^^^^^^^^^^
14-
|
15-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
16-
17-
warning: 2 warnings emitted
9+
warning: 1 warning emitted
1810

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This test makes sure that expended items with derives don't interfear with lint expectations.
2+
//
3+
// See <https://github.com/rust-lang/rust/issues/153036> for some context.
4+
5+
//@ check-pass
6+
7+
#[derive(Clone, Debug)]
8+
#[expect(unused)]
9+
pub struct LoggingArgs {
10+
#[cfg(false)]
11+
x: i32,
12+
y: i32,
13+
}
14+
15+
fn main() {}

tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
2+
//
13
// Make sure we properly copy the `#[expect]` attr to the derived code and that no
24
// unfulfilled expectations are trigerred.
35
//
46
// See <https://github.com/rust-lang/rust/issues/150553> for rational.
57

6-
//@ check-pass
8+
//@ check-fail
79

810
#![deny(redundant_lifetimes)]
911

@@ -12,6 +14,7 @@ use std::fmt::Debug;
1214
#[derive(Debug)]
1315
#[expect(redundant_lifetimes)]
1416
pub struct RefWrapper<'a, T>
17+
//~^ ERROR redundant_lifetimes
1518
where
1619
'a: 'static,
1720
T: Debug,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: unnecessary lifetime parameter `'a`
2+
--> $DIR/derive-expect-issue-150553.rs:16:23
3+
|
4+
LL | pub struct RefWrapper<'a, T>
5+
| ^^
6+
|
7+
= note: you can use the `'static` lifetime directly, in place of `'a`
8+
note: the lint level is defined here
9+
--> $DIR/derive-expect-issue-150553.rs:10:9
10+
|
11+
LL | #![deny(redundant_lifetimes)]
12+
| ^^^^^^^^^^^^^^^^^^^
13+
14+
error: aborting due to 1 previous error
15+

tests/ui/macros/issue-6596-1.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@ error: expected expression, found `$`
22
--> $DIR/issue-6596-1.rs:3:9
33
|
44
LL | $nonexistent
5-
| ^-----------
6-
| ||
7-
| |macro metavariable not found
8-
| expected expression
5+
| ^^^^^^^^^^^^ expected expression
96
...
107
LL | e!(foo);
118
| ------- in this macro invocation
129
|
13-
= note: available metavariable names are: $inp
1410
= note: this error originates in the macro `e` (in Nightly builds, run with -Z macro-backtrace for more info)
1511

1612
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)