Skip to content

Commit 07c92de

Browse files
committed
Rename lint and cleanup implementation
1 parent 1ebf192 commit 07c92de

File tree

10 files changed

+28
-31
lines changed

10 files changed

+28
-31
lines changed

compiler/rustc_expand/src/base.rs

-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ pub trait TTMacroExpander {
347347
ecx: &'cx mut ExtCtxt<'_>,
348348
span: Span,
349349
input: TokenStream,
350-
nearest_parent: NodeId,
351350
) -> Box<dyn MacResult + 'cx>;
352351
}
353352

@@ -363,7 +362,6 @@ where
363362
ecx: &'cx mut ExtCtxt<'_>,
364363
span: Span,
365364
input: TokenStream,
366-
_nearest_parent: NodeId,
367365
) -> Box<dyn MacResult + 'cx> {
368366
self(ecx, span, input)
369367
}

compiler/rustc_expand/src/expand.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
721721
SyntaxExtensionKind::LegacyBang(expander) => {
722722
let prev = self.cx.current_expansion.prior_type_ascription;
723723
self.cx.current_expansion.prior_type_ascription = mac.prior_type_ascription;
724-
// FIXME - this is imprecise. We should try to lint as close to the macro call
725-
// as possible (we cannot take attributes from the macro call itself).
726-
let nearest_parent = self.cx.resolver.lint_node_id(invoc.expansion_data.id);
727-
let tok_result =
728-
expander.expand(self.cx, span, mac.args.inner_tokens(), nearest_parent);
724+
let tok_result = expander.expand(self.cx, span, mac.args.inner_tokens());
729725
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
730726
result
731727
} else {

compiler/rustc_expand/src/mbe/macro_rules.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_data_structures::fx::FxHashMap;
1818
use rustc_data_structures::sync::Lrc;
1919
use rustc_errors::{Applicability, DiagnosticBuilder};
2020
use rustc_feature::Features;
21-
use rustc_lint_defs::builtin::MACRO_TRAILING_SEMICOLON;
21+
use rustc_lint_defs::builtin::SEMICOLON_IN_EXPRESSIONS_FROM_MACROS;
2222
use rustc_parse::parser::Parser;
2323
use rustc_session::parse::ParseSess;
2424
use rustc_session::Session;
@@ -39,7 +39,7 @@ crate struct ParserAnyMacro<'a> {
3939
site_span: Span,
4040
/// The ident of the macro we're parsing
4141
macro_ident: Ident,
42-
nearest_parent: NodeId,
42+
lint_node_id: NodeId,
4343
arm_span: Span,
4444
}
4545

@@ -113,7 +113,7 @@ fn emit_frag_parse_err(
113113

114114
impl<'a> ParserAnyMacro<'a> {
115115
crate fn make(mut self: Box<ParserAnyMacro<'a>>, kind: AstFragmentKind) -> AstFragment {
116-
let ParserAnyMacro { site_span, macro_ident, ref mut parser, nearest_parent, arm_span } =
116+
let ParserAnyMacro { site_span, macro_ident, ref mut parser, lint_node_id, arm_span } =
117117
*self;
118118
let snapshot = &mut parser.clone();
119119
let fragment = match parse_ast_fragment(parser, kind) {
@@ -129,9 +129,9 @@ impl<'a> ParserAnyMacro<'a> {
129129
// but `m!()` is allowed in expression positions (cf. issue #34706).
130130
if kind == AstFragmentKind::Expr && parser.token == token::Semi {
131131
parser.sess.buffer_lint(
132-
MACRO_TRAILING_SEMICOLON,
132+
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
133133
parser.token.span,
134-
nearest_parent,
134+
lint_node_id,
135135
"trailing semicolon in macro used in expression position",
136136
);
137137
parser.bump();
@@ -159,7 +159,6 @@ impl TTMacroExpander for MacroRulesMacroExpander {
159159
cx: &'cx mut ExtCtxt<'_>,
160160
sp: Span,
161161
input: TokenStream,
162-
nearest_parent: NodeId,
163162
) -> Box<dyn MacResult + 'cx> {
164163
if !self.valid {
165164
return DummyResult::any(sp);
@@ -171,7 +170,6 @@ impl TTMacroExpander for MacroRulesMacroExpander {
171170
self.name,
172171
self.transparency,
173172
input,
174-
nearest_parent,
175173
&self.lhses,
176174
&self.rhses,
177175
)
@@ -199,7 +197,6 @@ fn generic_extension<'cx>(
199197
name: Ident,
200198
transparency: Transparency,
201199
arg: TokenStream,
202-
nearest_parent: NodeId,
203200
lhses: &[mbe::TokenTree],
204201
rhses: &[mbe::TokenTree],
205202
) -> Box<dyn MacResult + 'cx> {
@@ -289,6 +286,7 @@ fn generic_extension<'cx>(
289286

290287
let mut p = Parser::new(sess, tts, false, None);
291288
p.last_type_ascription = cx.current_expansion.prior_type_ascription;
289+
let lint_node_id = cx.resolver.lint_node_id(cx.current_expansion.id);
292290

293291
// Let the context choose how to interpret the result.
294292
// Weird, but useful for X-macros.
@@ -300,7 +298,7 @@ fn generic_extension<'cx>(
300298
// macro leaves unparsed tokens.
301299
site_span: sp,
302300
macro_ident: name,
303-
nearest_parent,
301+
lint_node_id,
304302
arm_span,
305303
});
306304
}

compiler/rustc_lint_defs/src/builtin.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2835,13 +2835,14 @@ declare_lint! {
28352835
}
28362836

28372837
declare_lint! {
2838-
/// The `macro_trailing_semicolon` lint detects trailing semicolons
2838+
/// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
28392839
/// in macro bodies when the macro is invoked in expression position.
28402840
/// This was previous accepted, but is being phased out.
28412841
///
28422842
/// ### Example
28432843
///
2844-
/// ```rust
2844+
/// ```rust,compile-fail
2845+
/// #![deny(semicolon_in_expressions_from_macros)]
28452846
/// macro_rules! foo {
28462847
/// () => { true; }
28472848
/// }
@@ -2854,6 +2855,8 @@ declare_lint! {
28542855
/// }
28552856
/// ```
28562857
///
2858+
/// {{produces}}
2859+
///
28572860
/// ### Explanation
28582861
///
28592862
/// Previous, Rust ignored trailing semicolon in a macro
@@ -2868,7 +2871,7 @@ declare_lint! {
28682871
///
28692872
/// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
28702873
/// [future-incompatible]: ../index.md#future-incompatible-lints
2871-
pub MACRO_TRAILING_SEMICOLON,
2874+
pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
28722875
Allow,
28732876
"trailing semicolon in macro body used as expression",
28742877
@future_incompatible = FutureIncompatibleInfo {
@@ -2964,7 +2967,7 @@ declare_lint_pass! {
29642967
USELESS_DEPRECATED,
29652968
UNSUPPORTED_NAKED_FUNCTIONS,
29662969
MISSING_ABI,
2967-
MACRO_TRAILING_SEMICOLON,
2970+
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
29682971
]
29692972
}
29702973

compiler/rustc_resolve/src/macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ impl<'a> ResolverExpand for Resolver<'a> {
344344
}
345345

346346
fn lint_node_id(&mut self, expn_id: ExpnId) -> NodeId {
347+
// FIXME - make this more precise. This currently returns the NodeId of the
348+
// nearest closing item - we should try to return the closest parent of the ExpnId
347349
self.invocation_parents
348350
.get(&expn_id)
349351
.map_or(ast::CRATE_NODE_ID, |id| self.def_id_to_node_id[*id])

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ def build_bootstrap(self):
833833
target_linker = self.get_toml("linker", build_section)
834834
if target_linker is not None:
835835
env["RUSTFLAGS"] += " -C linker=" + target_linker
836-
# cfg(bootstrap): Add `-Wmacro_trailing_semicolon` after the next beta bump
836+
# cfg(bootstrap): Add `-Wsemicolon_in_expressions_from_macros` after the next beta bump
837837
env["RUSTFLAGS"] += " -Wrust_2018_idioms -Wunused_lifetimes"
838838
if self.get_toml("deny-warnings", "rust") != "false":
839839
env["RUSTFLAGS"] += " -Dwarnings"

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ impl<'a> Builder<'a> {
12541254
// This is currently disabled for the stage1 libstd, since build scripts
12551255
// will end up using the bootstrap compiler (which doesn't yet support this lint)
12561256
if compiler.stage != 0 && mode != Mode::Std {
1257-
lint_flags.push("-Wmacro_trailing_semicolon");
1257+
lint_flags.push("-Wsemicolon_in_expressions_from_macros");
12581258
}
12591259

12601260
if self.config.deny_warnings {

src/test/ui/lint/macro-trailing-semicolon/macro-trailing-semicolon.rs renamed to src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
#![warn(macro_trailing_semicolon)]
2+
#![warn(semicolon_in_expressions_from_macros)]
33

44
#[allow(dead_code)]
55
macro_rules! foo {
@@ -13,17 +13,17 @@ macro_rules! foo {
1313

1414
fn main() {
1515
// This `allow` doesn't work
16-
#[allow(macro_trailing_semicolon)]
16+
#[allow(semicolon_in_expressions_from_macros)]
1717
let _ = {
1818
foo!(first)
1919
};
2020

2121
// This 'allow' doesn't work either
22-
#[allow(macro_trailing_semicolon)]
22+
#[allow(semicolon_in_expressions_from_macros)]
2323
let _ = foo!(second);
2424

2525
// But this 'allow' does
26-
#[allow(macro_trailing_semicolon)]
26+
#[allow(semicolon_in_expressions_from_macros)]
2727
fn inner() {
2828
let _ = foo!(third);
2929
}

src/test/ui/lint/macro-trailing-semicolon/macro-trailing-semicolon.stderr renamed to src/test/ui/lint/semicolon-in-expressions-from-macros/semicolon-in-expressions-from-macros.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: trailing semicolon in macro used in expression position
2-
--> $DIR/macro-trailing-semicolon.rs:7:13
2+
--> $DIR/semicolon-in-expressions-from-macros.rs:7:13
33
|
44
LL | true;
55
| ^
@@ -8,16 +8,16 @@ LL | foo!(first)
88
| ----------- in this macro invocation
99
|
1010
note: the lint level is defined here
11-
--> $DIR/macro-trailing-semicolon.rs:2:9
11+
--> $DIR/semicolon-in-expressions-from-macros.rs:2:9
1212
|
13-
LL | #![warn(macro_trailing_semicolon)]
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^
13+
LL | #![warn(semicolon_in_expressions_from_macros)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1616
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
1717
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1818

1919
warning: trailing semicolon in macro used in expression position
20-
--> $DIR/macro-trailing-semicolon.rs:7:13
20+
--> $DIR/semicolon-in-expressions-from-macros.rs:7:13
2121
|
2222
LL | true;
2323
| ^

0 commit comments

Comments
 (0)