Skip to content

Commit a1e8d54

Browse files
committed
Move more work into decorate functions.
1 parent 62f7804 commit a1e8d54

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

src/librustc_lint/nonstandard_style.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ impl NonCamelCaseTypes {
107107
let name = &ident.name.as_str();
108108

109109
if !is_camel_case(name) {
110-
let msg = format!("{} `{}` should have an upper camel case name", sort, name);
111110
cx.struct_span_lint(NON_CAMEL_CASE_TYPES, ident.span, |lint| {
111+
let msg = format!("{} `{}` should have an upper camel case name", sort, name);
112112
lint.build(&msg)
113113
.span_suggestion(
114114
ident.span,
@@ -227,8 +227,8 @@ impl NonSnakeCase {
227227
if !is_snake_case(name) {
228228
let sc = NonSnakeCase::to_snake_case(name);
229229

230-
let msg = format!("{} `{}` should have a snake case name", sort, name);
231230
cx.struct_span_lint(NON_SNAKE_CASE, ident.span, |lint| {
231+
let msg = format!("{} `{}` should have a snake case name", sort, name);
232232
let mut err = lint.build(&msg);
233233
// We have a valid span in almost all cases, but we don't have one when linting a crate
234234
// name provided via the command line.
@@ -389,11 +389,9 @@ declare_lint_pass!(NonUpperCaseGlobals => [NON_UPPER_CASE_GLOBALS]);
389389
impl NonUpperCaseGlobals {
390390
fn check_upper_case(cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
391391
let name = &ident.name.as_str();
392-
393392
if name.chars().any(|c| c.is_lowercase()) {
394-
let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
395-
396393
cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, |lint| {
394+
let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
397395
lint.build(&format!("{} `{}` should have an upper case name", sort, name))
398396
.span_suggestion(
399397
ident.span,

src/librustc_lint/types.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ fn report_bin_hex_error(
151151
negative: bool,
152152
) {
153153
let size = layout::Integer::from_attr(&cx.tcx, ty).size();
154-
let (t, actually) = match ty {
155-
attr::IntType::SignedInt(t) => {
156-
let actually = sign_extend(val, size) as i128;
157-
(t.name_str(), actually.to_string())
158-
}
159-
attr::IntType::UnsignedInt(t) => {
160-
let actually = truncate(val, size);
161-
(t.name_str(), actually.to_string())
162-
}
163-
};
164154
cx.struct_span_lint(OVERFLOWING_LITERALS, expr.span, |lint| {
155+
let (t, actually) = match ty {
156+
attr::IntType::SignedInt(t) => {
157+
let actually = sign_extend(val, size) as i128;
158+
(t.name_str(), actually.to_string())
159+
}
160+
attr::IntType::UnsignedInt(t) => {
161+
let actually = truncate(val, size);
162+
(t.name_str(), actually.to_string())
163+
}
164+
};
165165
let mut err = lint.build(&format!("literal out of range for {}", t));
166166
err.note(&format!(
167167
"the literal `{}` (decimal `{}`) does not fit into \

src/librustc_typeck/check_unused.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,15 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
123123
// We do this in any edition.
124124
if extern_crate.warn_if_unused {
125125
if let Some(&span) = unused_extern_crates.get(&extern_crate.def_id) {
126-
let msg = "unused extern crate";
127-
128-
// Removal suggestion span needs to include attributes (Issue #54400)
129-
let span_with_attrs = tcx
130-
.get_attrs(extern_crate.def_id)
131-
.iter()
132-
.map(|attr| attr.span)
133-
.fold(span, |acc, attr_span| acc.to(attr_span));
134-
135126
tcx.struct_span_lint_hir(lint, id, span, |lint| {
136-
lint.build(msg)
127+
// Removal suggestion span needs to include attributes (Issue #54400)
128+
let span_with_attrs = tcx
129+
.get_attrs(extern_crate.def_id)
130+
.iter()
131+
.map(|attr| attr.span)
132+
.fold(span, |acc, attr_span| acc.to(attr_span));
133+
134+
lint.build("unused extern crate")
137135
.span_suggestion_short(
138136
span_with_attrs,
139137
"remove it",
@@ -172,14 +170,14 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
172170
if !tcx.get_attrs(extern_crate.def_id).is_empty() {
173171
continue;
174172
}
175-
176-
// Otherwise, we can convert it into a `use` of some kind.
177-
let base_replacement = match extern_crate.orig_name {
178-
Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name),
179-
None => format!("use {};", item.ident.name),
180-
};
181-
let replacement = visibility_qualified(&item.vis, base_replacement);
182173
tcx.struct_span_lint_hir(lint, id, extern_crate.span, |lint| {
174+
// Otherwise, we can convert it into a `use` of some kind.
175+
let base_replacement = match extern_crate.orig_name {
176+
Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name),
177+
None => format!("use {};", item.ident.name),
178+
};
179+
180+
let replacement = visibility_qualified(&item.vis, base_replacement);
183181
let msg = "`extern crate` is not idiomatic in the new edition";
184182
let help = format!("convert it to a `{}`", visibility_qualified(&item.vis, "use"));
185183

0 commit comments

Comments
 (0)