Skip to content

Commit ad772a0

Browse files
committed
refactor: replace @default symbols with constants
1 parent 44671e2 commit ad772a0

File tree

7 files changed

+26
-32
lines changed

7 files changed

+26
-32
lines changed

bevy_lint/src/lints/cargo.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use rustc_span::Symbol;
99

1010
declare_bevy_lint_pass! {
1111
pub(crate) Cargo => [DUPLICATE_BEVY_DEPENDENCIES],
12-
@default = {
13-
bevy: Symbol = Symbol::intern("bevy"),
14-
},
1512
}
1613

1714
impl LateLintPass<'_> for Cargo {
@@ -34,7 +31,7 @@ impl LateLintPass<'_> for Cargo {
3431
.exec()
3532
{
3633
Ok(metadata) => {
37-
super::nursery::duplicate_bevy_dependencies::check(cx, &metadata, self.bevy);
34+
super::nursery::duplicate_bevy_dependencies::check(cx, &metadata);
3835
}
3936
Err(e) => {
4037
cx.tcx

bevy_lint/src/lints/nursery/duplicate_bevy_dependencies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
6363
use std::{collections::BTreeMap, ops::Range, path::Path, sync::Arc};
6464

65-
use crate::declare_bevy_lint;
65+
use crate::{declare_bevy_lint, sym};
6666
use cargo_metadata::{
6767
Metadata, Resolve,
6868
semver::{Prerelease, Version, VersionReq},
@@ -98,9 +98,9 @@ fn toml_span(range: Range<usize>, file: &SourceFile) -> Span {
9898
)
9999
}
100100

101-
pub(crate) fn check(cx: &LateContext<'_>, metadata: &Metadata, bevy_symbol: Symbol) {
101+
pub(crate) fn check(cx: &LateContext<'_>, metadata: &Metadata) {
102102
// no reason to continue the check if there is only one instance of `bevy` required
103-
if find_crates(cx.tcx, bevy_symbol).len() == 1 {
103+
if find_crates(cx.tcx, sym::bevy).len() == 1 {
104104
return;
105105
}
106106

bevy_lint/src/lints/pedantic/main_return_without_appexit.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! }
3434
//! ```
3535
36-
use crate::{declare_bevy_lint, declare_bevy_lint_pass, utils::hir_parse::MethodCall};
36+
use crate::{declare_bevy_lint, declare_bevy_lint_pass, sym, utils::hir_parse::MethodCall};
3737
use clippy_utils::{
3838
diagnostics::span_lint_hir_and_then, is_entrypoint_fn, is_expr_used_or_unified,
3939
ty::match_type, visitors::for_each_expr,
@@ -52,9 +52,6 @@ declare_bevy_lint! {
5252

5353
declare_bevy_lint_pass! {
5454
pub(crate) MainReturnWithoutAppExit => [MAIN_RETURN_WITHOUT_APPEXIT],
55-
@default = {
56-
run: Symbol = Symbol::intern("run"),
57-
},
5855
}
5956

6057
impl<'tcx> LateLintPass<'tcx> for MainReturnWithoutAppExit {
@@ -89,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for MainReturnWithoutAppExit {
8986
receiver,
9087
..
9188
}) = MethodCall::try_from(cx, expr)
92-
&& method_path.ident.name == self.run
89+
&& method_path.ident.name == sym::run
9390
&& !expr.span.in_external_macro(cx.tcx.sess.source_map())
9491
{
9592
// Get the type of `src` for `src.run()`. We peel away all references because

bevy_lint/src/lints/suspicious/insert_event_resource.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
//! ```
4141
4242
use crate::{
43-
declare_bevy_lint, declare_bevy_lint_pass,
44-
utils::hir_parse::{MethodCall, generic_args_snippet, span_args},
43+
declare_bevy_lint, declare_bevy_lint_pass, sym, utils::hir_parse::{generic_args_snippet, span_args, MethodCall}
4544
};
4645
use clippy_utils::{
4746
diagnostics::span_lint_and_sugg,
@@ -63,10 +62,6 @@ declare_bevy_lint! {
6362

6463
declare_bevy_lint_pass! {
6564
pub(crate) InsertEventResource => [INSERT_EVENT_RESOURCE],
66-
@default = {
67-
insert_resource: Symbol = Symbol::intern("insert_resource"),
68-
init_resource: Symbol = Symbol::intern("init_resource"),
69-
},
7065
}
7166

7267
const HELP_MESSAGE: &str = "inserting an `Events` resource does not fully setup that event";
@@ -95,10 +90,10 @@ impl<'tcx> LateLintPass<'tcx> for InsertEventResource {
9590
// If the method is `App::insert_resource()` or `App::init_resource()`, check it with
9691
// its corresponding function.
9792
match method_call.method_path.ident.name {
98-
symbol if symbol == self.insert_resource => {
93+
symbol if symbol == sym::insert_resource => {
9994
check_insert_resource(cx, &method_call);
10095
}
101-
symbol if symbol == self.init_resource => {
96+
symbol if symbol == sym::init_resource => {
10297
check_init_resource(cx, &method_call);
10398
}
10499
_ => {}

bevy_lint/src/lints/suspicious/insert_unit_bundle.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use rustc_lint::{LateContext, LateLintPass};
5757
use rustc_middle::ty::{Ty, TyKind};
5858
use rustc_span::Symbol;
5959

60-
use crate::{declare_bevy_lint, declare_bevy_lint_pass, utils::hir_parse::MethodCall};
60+
use crate::{declare_bevy_lint, declare_bevy_lint_pass, sym, utils::hir_parse::MethodCall};
6161

6262
declare_bevy_lint! {
6363
pub(crate) INSERT_UNIT_BUNDLE,
@@ -67,9 +67,6 @@ declare_bevy_lint! {
6767

6868
declare_bevy_lint_pass! {
6969
pub(crate) InsertUnitBundle => [INSERT_UNIT_BUNDLE],
70-
@default = {
71-
spawn: Symbol = Symbol::intern("spawn"),
72-
},
7370
}
7471

7572
impl<'tcx> LateLintPass<'tcx> for InsertUnitBundle {
@@ -92,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for InsertUnitBundle {
9289
// we skip it.
9390
if !(span.in_external_macro(cx.tcx.sess.source_map())
9491
|| match_type(cx, src_ty, &crate::paths::COMMANDS)
95-
&& method_path.ident.name == self.spawn)
92+
&& method_path.ident.name == sym::spawn)
9693
{
9794
return;
9895
}

bevy_lint/src/lints/suspicious/iter_current_update_events.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_hir::Expr;
4343
use rustc_lint::{LateContext, LateLintPass};
4444
use rustc_span::Symbol;
4545

46-
use crate::{declare_bevy_lint, declare_bevy_lint_pass, utils::hir_parse::MethodCall};
46+
use crate::{declare_bevy_lint, declare_bevy_lint_pass, sym, utils::hir_parse::MethodCall};
4747

4848
declare_bevy_lint! {
4949
pub(crate) ITER_CURRENT_UPDATE_EVENTS,
@@ -53,10 +53,6 @@ declare_bevy_lint! {
5353

5454
declare_bevy_lint_pass! {
5555
pub(crate) IterCurrentUpdateEvents => [ITER_CURRENT_UPDATE_EVENTS],
56-
57-
@default = {
58-
iter_current_update_events: Symbol = Symbol::intern("iter_current_update_events"),
59-
},
6056
}
6157

6258
impl<'tcx> LateLintPass<'tcx> for IterCurrentUpdateEvents {
@@ -91,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for IterCurrentUpdateEvents {
9187
return;
9288
}
9389

94-
if method_call.method_path.ident.name == self.iter_current_update_events {
90+
if method_call.method_path.ident.name == sym::iter_current_update_events {
9591
span_lint_and_help(
9692
cx,
9793
ITER_CURRENT_UPDATE_EVENTS,

bevy_lint/src/sym.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
//! are used in the linter. The only exception to this is the [`EXTRA_SYMBOLS`] constant, which
66
//! contains a complete ordered list of all symbols to be pre-interned.
77
8+
#![allow(
9+
non_upper_case_globals,
10+
reason = "Symbol constants are named as-is so it is easy to see what strings they represent."
11+
)]
12+
813
use rustc_span::{Symbol, symbol::PREDEFINED_SYMBOLS_COUNT};
914

1015
/// A helper used by [`declare_bevy_symbols!`] to extract its input.
@@ -53,4 +58,11 @@ macro_rules! declare_bevy_symbols {
5358
};
5459
}
5560

56-
declare_bevy_symbols! {}
61+
declare_bevy_symbols! {
62+
bevy,
63+
init_resource,
64+
insert_resource,
65+
iter_current_update_events,
66+
spawn,
67+
run,
68+
}

0 commit comments

Comments
 (0)