Skip to content

Commit 5a670b6

Browse files
committed
Address review comments
1 parent 1b5ec3f commit 5a670b6

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

compiler/rustc_lint/src/lints.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,12 @@ pub(crate) enum NonUpperCaseGlobalSub {
13591359
#[primary_span]
13601360
span: Span,
13611361
},
1362-
#[suggestion(lint_suggestion, code = "{replace}", applicability = "machine-applicable")]
1362+
#[suggestion(lint_suggestion, code = "{replace}")]
13631363
Suggestion {
13641364
#[primary_span]
13651365
span: Span,
1366+
#[applicability]
1367+
applicability: Applicability,
13661368
replace: String,
13671369
},
13681370
}

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use rustc_abi::ExternAbi;
22
use rustc_attr_data_structures::{AttributeKind, ReprAttr};
33
use rustc_attr_parsing::AttributeParser;
4+
use rustc_errors::Applicability;
45
use rustc_hir::def::{DefKind, Res};
6+
use rustc_hir::def_id::DefId;
57
use rustc_hir::intravisit::{FnKind, Visitor};
68
use rustc_hir::{AttrArgs, AttrItem, Attribute, GenericParamKind, PatExprKind, PatKind};
79
use rustc_middle::hir::nested_filter::All;
@@ -498,14 +500,22 @@ impl NonUpperCaseGlobals {
498500
// We cannot provide meaningful suggestions
499501
// if the characters are in the category of "Lowercase Letter".
500502
let sub = if *name != uc {
501-
NonUpperCaseGlobalSub::Suggestion { span: ident.span, replace: uc.clone() }
503+
NonUpperCaseGlobalSub::Suggestion {
504+
span: ident.span,
505+
replace: uc.clone(),
506+
applicability: if did.is_some() {
507+
Applicability::MachineApplicable
508+
} else {
509+
Applicability::MaybeIncorrect
510+
},
511+
}
502512
} else {
503513
NonUpperCaseGlobalSub::Label { span: ident.span }
504514
};
505515

506516
struct UsageCollector<'a, 'tcx> {
507517
cx: &'tcx LateContext<'a>,
508-
did: LocalDefId,
518+
did: DefId,
509519
collected: Vec<Span>,
510520
}
511521

@@ -522,7 +532,7 @@ impl NonUpperCaseGlobals {
522532
_id: rustc_hir::HirId,
523533
) -> Self::Result {
524534
for seg in path.segments {
525-
if seg.res.opt_def_id() == Some(self.did.to_def_id()) {
535+
if seg.res.opt_def_id() == Some(self.did) {
526536
self.collected.push(seg.ident.span);
527537
}
528538
}
@@ -535,7 +545,8 @@ impl NonUpperCaseGlobals {
535545
let usages = if let Some(did) = did
536546
&& *name != uc
537547
{
538-
let mut usage_collector = UsageCollector { cx, did, collected: Vec::new() };
548+
let mut usage_collector =
549+
UsageCollector { cx, did: did.to_def_id(), collected: Vec::new() };
539550
cx.tcx.hir_walk_toplevel_module(&mut usage_collector);
540551
usage_collector
541552
.collected

tests/ui/lint/lint-non-uppercase-usages.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const MY_STATIC: u32 = 0;
1515
const LOL: u32 = MY_STATIC + 0;
1616
//~^ SUGGESTION MY_STATIC
1717

18+
mod my_mod {
19+
const INSIDE_MOD: u32 = super::MY_STATIC + 0;
20+
//~^ SUGGESTION MY_STATIC
21+
}
22+
1823
thread_local! {
1924
static FOO_FOO: Cell<usize> = unreachable!();
2025
//~^ WARN constant `fooFOO` should have an upper case name

tests/ui/lint/lint-non-uppercase-usages.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const my_static: u32 = 0;
1515
const LOL: u32 = my_static + 0;
1616
//~^ SUGGESTION MY_STATIC
1717

18+
mod my_mod {
19+
const INSIDE_MOD: u32 = super::my_static + 0;
20+
//~^ SUGGESTION MY_STATIC
21+
}
22+
1823
thread_local! {
1924
static fooFOO: Cell<usize> = unreachable!();
2025
//~^ WARN constant `fooFOO` should have an upper case name

tests/ui/lint/lint-non-uppercase-usages.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL + const MY_STATIC: u32 = 0;
1212
|
1313

1414
warning: constant `fooFOO` should have an upper case name
15-
--> $DIR/lint-non-uppercase-usages.rs:19:12
15+
--> $DIR/lint-non-uppercase-usages.rs:24:12
1616
|
1717
LL | static fooFOO: Cell<usize> = unreachable!();
1818
| ^^^^^^
@@ -24,7 +24,7 @@ LL + static FOO_FOO: Cell<usize> = unreachable!();
2424
|
2525

2626
warning: const parameter `foo` should have an upper case name
27-
--> $DIR/lint-non-uppercase-usages.rs:24:14
27+
--> $DIR/lint-non-uppercase-usages.rs:29:14
2828
|
2929
LL | fn foo<const foo: u32>() {
3030
| ^^^

0 commit comments

Comments
 (0)