Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2589fe0

Browse files
committed
Emit the usages suggestions as multipart suggestions
1 parent 6fcb3f3 commit 2589fe0

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

‎compiler/rustc_lint/src/lints.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ pub(crate) struct NonUpperCaseGlobal<'a> {
13491349
#[subdiagnostic]
13501350
pub sub: NonUpperCaseGlobalSub,
13511351
#[subdiagnostic]
1352-
pub usages: Vec<NonUpperCaseGlobalSub>,
1352+
pub usages: Option<NonUpperCaseGlobalSubUsages>,
13531353
}
13541354

13551355
#[derive(Subdiagnostic)]
@@ -1367,6 +1367,23 @@ pub(crate) enum NonUpperCaseGlobalSub {
13671367
},
13681368
}
13691369

1370+
pub(crate) struct NonUpperCaseGlobalSubUsages {
1371+
pub(crate) spans: Vec<Span>,
1372+
pub(crate) replace: String,
1373+
}
1374+
1375+
impl Subdiagnostic for NonUpperCaseGlobalSubUsages {
1376+
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
1377+
if !self.spans.is_empty() {
1378+
diag.multipart_suggestion_verbose(
1379+
crate::fluent_generated::_subdiag::suggestion,
1380+
self.spans.into_iter().map(|sp| (sp, self.replace.clone())).collect(),
1381+
Applicability::MaybeIncorrect,
1382+
);
1383+
}
1384+
}
1385+
}
1386+
13701387
// noop_method_call.rs
13711388
#[derive(LintDiagnostic)]
13721389
#[diag(lint_noop_method_call)]

‎compiler/rustc_lint/src/nonstandard_style.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use {rustc_ast as ast, rustc_hir as hir};
1414

1515
use crate::lints::{
1616
NonCamelCaseType, NonCamelCaseTypeSub, NonSnakeCaseDiag, NonSnakeCaseDiagSub,
17-
NonUpperCaseGlobal, NonUpperCaseGlobalSub,
17+
NonUpperCaseGlobal, NonUpperCaseGlobalSub,NonUpperCaseGlobalSubUsages,
1818
};
1919
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
2020

@@ -534,9 +534,12 @@ impl NonUpperCaseGlobals {
534534
let usages = if let Some(did) = did {
535535
let mut usage_collector = UsageCollector { cx, did, collected: Vec::new() };
536536
cx.tcx.hir_walk_toplevel_module(&mut usage_collector);
537-
usage_collector.collected.into_iter().map(|span| sub(span)).collect()
537+
Some(NonUpperCaseGlobalSubUsages {
538+
spans: usage_collector.collected,
539+
replace: uc.clone(),
540+
})
538541
} else {
539-
vec![]
542+
None
540543
};
541544

542545
cx.emit_span_lint(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
// Checks that the `non_upper_case_globals` emits suggestions for usages as well
22
// <https://github.com/rust-lang/rust/issues/124061>
33

44
//@ check-pass

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ LL + const MY_STATIC: u32 = 0;
1212
|
1313
help: convert the identifier to upper case
1414
|
15-
LL - const LOL: u32 = my_static + 0;
16-
LL + const LOL: u32 = MY_STATIC + 0;
17-
|
18-
help: convert the identifier to upper case
19-
|
20-
LL - let _a = crate::my_static;
21-
LL + let _a = crate::MY_STATIC;
15+
LL ~ const LOL: u32 = MY_STATIC + 0;
16+
LL |
17+
...
18+
LL | fn main() {
19+
LL ~ let _a = crate::MY_STATIC;
2220
|
2321

2422
warning: constant `fooFOO` should have an upper case name
@@ -34,13 +32,9 @@ LL + static FOO_FOO: Cell<usize> = unreachable!();
3432
|
3533
help: convert the identifier to upper case
3634
|
37-
LL - fooFOO.set(9);
38-
LL + FOO_FOO.set(9);
39-
|
40-
help: convert the identifier to upper case
41-
|
42-
LL - println!("{}", fooFOO.get());
43-
LL + println!("{}", FOO_FOO.get());
35+
LL ~ FOO_FOO.set(9);
36+
LL |
37+
LL ~ println!("{}", FOO_FOO.get());
4438
|
4539

4640
warning: const parameter `foo` should have an upper case name

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /