Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ impl<'a> TraitDef<'a> {
.filter(|a| {
a.has_any_name(&[
sym::allow,
sym::expect,
sym::warn,
sym::deny,
sym::forbid,
Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,7 @@ impl<'cx> MacroExpanderResult<'cx> {
// Emit the SEMICOLON_IN_EXPRESSIONS_FROM_MACROS deprecation lint.
let is_local = true;

let parser = ParserAnyMacro::from_tts(
cx,
tts,
site_span,
arm_span,
is_local,
macro_ident,
vec![],
vec![],
);
let parser = ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, is_local, macro_ident);
ExpandResult::Ready(Box::new(parser))
}
}
Expand Down
52 changes: 1 addition & 51 deletions compiler/rustc_expand/src/mbe/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,11 @@ impl<'dcx> CollectTrackerAndEmitter<'dcx, '_> {

pub(super) fn emit_frag_parse_err(
mut e: Diag<'_>,
parser: &mut Parser<'_>,
parser: &Parser<'_>,
orig_parser: &mut Parser<'_>,
site_span: Span,
arm_span: Span,
kind: AstFragmentKind,
bindings: Vec<Ident>,
matched_rule_bindings: Vec<Ident>,
) -> ErrorGuaranteed {
// FIXME(davidtwco): avoid depending on the error message text
if parser.token == token::Eof
Expand Down Expand Up @@ -287,54 +285,6 @@ pub(super) fn emit_frag_parse_err(
},
_ => annotate_err_with_kind(&mut e, kind, site_span),
};

let matched_rule_bindings_names: Vec<_> =
matched_rule_bindings.iter().map(|bind| bind.name).collect();
let bindings_name: Vec<_> = bindings.iter().map(|bind| bind.name).collect();
if parser.token.kind == token::Dollar {
parser.bump();
if let token::Ident(name, _) = parser.token.kind {
if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(
&matched_rule_bindings_names[..],
name,
None,
) {
e.span_suggestion_verbose(
parser.token.span,
"there is a macro metavariable with similar name",
format!("{matched_name}"),
Applicability::MaybeIncorrect,
);
} else if bindings_name.contains(&name) {
e.span_label(
parser.token.span,
format!(
"there is an macro metavariable with this name in another macro matcher"
),
);
} else if let Some(matched_name) =
rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None)
{
e.span_suggestion_verbose(
parser.token.span,
"there is a macro metavariable with a similar name in another macro matcher",
format!("{matched_name}"),
Applicability::MaybeIncorrect,
);
} else {
let msg = matched_rule_bindings_names
.iter()
.map(|sym| format!("${}", sym))
.collect::<Vec<_>>()
.join(", ");

e.span_label(parser.token.span, format!("macro metavariable not found"));
if !matched_rule_bindings_names.is_empty() {
e.note(format!("available metavariable names are: {msg}"));
}
}
}
}
e.emit()
}

Expand Down
46 changes: 3 additions & 43 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ pub(crate) struct ParserAnyMacro<'a> {
arm_span: Span,
/// Whether or not this macro is defined in the current crate
is_local: bool,
bindings: Vec<Ident>,
matched_rule_bindings: Vec<Ident>,
}

impl<'a> ParserAnyMacro<'a> {
Expand All @@ -69,22 +67,13 @@ impl<'a> ParserAnyMacro<'a> {
arm_span,
is_trailing_mac,
is_local,
bindings,
matched_rule_bindings,
} = *self;
let snapshot = &mut parser.create_snapshot_for_diagnostic();
let fragment = match parse_ast_fragment(parser, kind) {
Ok(f) => f,
Err(err) => {
let guar = diagnostics::emit_frag_parse_err(
err,
parser,
snapshot,
site_span,
arm_span,
kind,
bindings,
matched_rule_bindings,
err, parser, snapshot, site_span, arm_span, kind,
);
return kind.dummy(site_span, guar);
}
Expand Down Expand Up @@ -119,9 +108,6 @@ impl<'a> ParserAnyMacro<'a> {
arm_span: Span,
is_local: bool,
macro_ident: Ident,
// bindings and lhs is for diagnostics
bindings: Vec<Ident>,
matched_rule_bindings: Vec<Ident>,
) -> Self {
Self {
parser: Parser::new(&cx.sess.psess, tts, None),
Expand All @@ -135,8 +121,6 @@ impl<'a> ParserAnyMacro<'a> {
is_trailing_mac: cx.current_expansion.is_trailing_mac,
arm_span,
is_local,
bindings,
matched_rule_bindings,
}
}
}
Expand Down Expand Up @@ -375,7 +359,7 @@ fn expand_macro<'cx>(

match try_success_result {
Ok((rule_index, rule, named_matches)) => {
let MacroRule::Func { lhs, rhs, .. } = rule else {
let MacroRule::Func { rhs, .. } = rule else {
panic!("try_match_macro returned non-func rule");
};
let mbe::TokenTree::Delimited(rhs_span, _, rhs) = rhs else {
Expand Down Expand Up @@ -403,32 +387,8 @@ fn expand_macro<'cx>(
cx.resolver.record_macro_rule_usage(node_id, rule_index);
}

let mut bindings = vec![];
for rule in rules {
let MacroRule::Func { lhs, .. } = rule else { continue };
for param in lhs {
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
bindings.push(*bind);
}
}

let mut matched_rule_bindings = vec![];
for param in lhs {
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
matched_rule_bindings.push(*bind);
}

// Let the context choose how to interpret the result. Weird, but useful for X-macros.
Box::new(ParserAnyMacro::from_tts(
cx,
tts,
sp,
arm_span,
is_local,
name,
bindings,
matched_rule_bindings,
))
Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, is_local, name))
}
Err(CanRetry::No(guar)) => {
debug!("Will not retry matching as an error was emitted already");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
//
// Make sure we produce the unfulfilled expectation lint if neither the struct or the
// derived code fulfilled it.

//@ check-pass

#[expect(unexpected_cfgs)]
//~^ WARN this lint expectation is unfulfilled
//~^^ WARN this lint expectation is unfulfilled
//FIXME ~^^ WARN this lint expectation is unfulfilled
#[derive(Debug)]
pub struct MyStruct {
pub t_ref: i64,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
warning: this lint expectation is unfulfilled
--> $DIR/derive-expect-issue-150553-3.rs:6:10
--> $DIR/derive-expect-issue-150553-3.rs:8:10
|
LL | #[expect(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(unfulfilled_lint_expectations)]` on by default

warning: this lint expectation is unfulfilled
--> $DIR/derive-expect-issue-150553-3.rs:6:10
|
LL | #[expect(unexpected_cfgs)]
| ^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

warning: 2 warnings emitted
warning: 1 warning emitted

15 changes: 15 additions & 0 deletions tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This test makes sure that expended items with derives don't interfear with lint expectations.
//
// See <https://github.com/rust-lang/rust/issues/153036> for some context.

//@ check-pass

#[derive(Clone, Debug)]
#[expect(unused)]
pub struct LoggingArgs {
#[cfg(false)]
x: i32,
y: i32,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// FIXME: Bring back duplication of the `#[expect]` attribute when deriving.
//
// Make sure we properly copy the `#[expect]` attr to the derived code and that no
// unfulfilled expectations are trigerred.
//
// See <https://github.com/rust-lang/rust/issues/150553> for rational.

//@ check-pass
//@ check-fail

#![deny(redundant_lifetimes)]

Expand All @@ -12,6 +14,7 @@ use std::fmt::Debug;
#[derive(Debug)]
#[expect(redundant_lifetimes)]
pub struct RefWrapper<'a, T>
//~^ ERROR redundant_lifetimes
where
'a: 'static,
T: Debug,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: unnecessary lifetime parameter `'a`
--> $DIR/derive-expect-issue-150553.rs:16:23
|
LL | pub struct RefWrapper<'a, T>
| ^^
|
= note: you can use the `'static` lifetime directly, in place of `'a`
note: the lint level is defined here
--> $DIR/derive-expect-issue-150553.rs:10:9
|
LL | #![deny(redundant_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

6 changes: 1 addition & 5 deletions tests/ui/macros/issue-6596-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ error: expected expression, found `$`
--> $DIR/issue-6596-1.rs:3:9
|
LL | $nonexistent
| ^-----------
| ||
| |macro metavariable not found
| expected expression
| ^^^^^^^^^^^^ expected expression
...
LL | e!(foo);
| ------- in this macro invocation
|
= note: available metavariable names are: $inp
= note: this error originates in the macro `e` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error
Expand Down
42 changes: 0 additions & 42 deletions tests/ui/macros/typo-in-norepeat-expr-2.rs

This file was deleted.

46 changes: 0 additions & 46 deletions tests/ui/macros/typo-in-norepeat-expr-2.stderr

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ui/macros/typo-in-norepeat-expr.fixed

This file was deleted.

Loading
Loading