Skip to content

Commit 0867c64

Browse files
committed
clippy: adopt to the new lint API
1 parent e5ce6d1 commit 0867c64

File tree

2 files changed

+29
-36
lines changed

2 files changed

+29
-36
lines changed

clippy_lints/src/module_style.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ impl EarlyLintPass for ModStyle {
117117
cx.struct_span_lint(
118118
SELF_NAMED_MODULE_FILES,
119119
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
120-
|build| {
121-
let mut lint =
122-
build.build(&format!("`mod.rs` files are required, found `{}`", path.display()));
123-
lint.help(&format!("move `{}` to `{}`", path.display(), correct.display(),));
124-
lint.emit();
120+
format!("`mod.rs` files are required, found `{}`", path.display()),
121+
|lint| {
122+
lint.help(format!(
123+
"move `{}` to `{}`",
124+
path.display(),
125+
correct.display(),
126+
))
125127
},
126128
);
127129
}
@@ -156,11 +158,8 @@ fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &Source
156158
cx.struct_span_lint(
157159
MOD_MODULE_FILES,
158160
Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
159-
|build| {
160-
let mut lint = build.build(&format!("`mod.rs` files are not allowed, found `{}`", path.display()));
161-
lint.help(&format!("move `{}` to `{}`", path.display(), mod_file.display(),));
162-
lint.emit();
163-
},
161+
format!("`mod.rs` files are not allowed, found `{}`", path.display()),
162+
|lint| lint.help(format!("move `{}` to `{}`", path.display(), mod_file.display())),
164163
);
165164
}
166165
}

clippy_utils/src/diagnostics.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
4747
/// | ^^^^^^^^^^^^^^^^^^^^^^^
4848
/// ```
4949
pub fn span_lint<T: LintContext>(cx: &T, lint: &'static Lint, sp: impl Into<MultiSpan>, msg: &str) {
50-
cx.struct_span_lint(lint, sp, |diag| {
51-
let mut diag = diag.build(msg);
52-
docs_link(&mut diag, lint);
53-
diag.emit();
50+
cx.struct_span_lint(lint, sp, msg, |diag| {
51+
docs_link(diag, lint);
52+
diag
5453
});
5554
}
5655

@@ -82,15 +81,14 @@ pub fn span_lint_and_help<'a, T: LintContext>(
8281
help_span: Option<Span>,
8382
help: &str,
8483
) {
85-
cx.struct_span_lint(lint, span, |diag| {
86-
let mut diag = diag.build(msg);
84+
cx.struct_span_lint(lint, span, msg, |diag| {
8785
if let Some(help_span) = help_span {
8886
diag.span_help(help_span, help);
8987
} else {
9088
diag.help(help);
9189
}
92-
docs_link(&mut diag, lint);
93-
diag.emit();
90+
docs_link(diag, lint);
91+
diag
9492
});
9593
}
9694

@@ -125,15 +123,14 @@ pub fn span_lint_and_note<'a, T: LintContext>(
125123
note_span: Option<Span>,
126124
note: &str,
127125
) {
128-
cx.struct_span_lint(lint, span, |diag| {
129-
let mut diag = diag.build(msg);
126+
cx.struct_span_lint(lint, span, msg, |diag| {
130127
if let Some(note_span) = note_span {
131128
diag.span_note(note_span, note);
132129
} else {
133130
diag.note(note);
134131
}
135-
docs_link(&mut diag, lint);
136-
diag.emit();
132+
docs_link(diag, lint);
133+
diag
137134
});
138135
}
139136

@@ -147,19 +144,17 @@ where
147144
S: Into<MultiSpan>,
148145
F: FnOnce(&mut Diagnostic),
149146
{
150-
cx.struct_span_lint(lint, sp, |diag| {
151-
let mut diag = diag.build(msg);
152-
f(&mut diag);
153-
docs_link(&mut diag, lint);
154-
diag.emit();
147+
cx.struct_span_lint(lint, sp, msg, |diag| {
148+
f(diag);
149+
docs_link(diag, lint);
150+
diag
155151
});
156152
}
157153

158154
pub fn span_lint_hir(cx: &LateContext<'_>, lint: &'static Lint, hir_id: HirId, sp: Span, msg: &str) {
159-
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
160-
let mut diag = diag.build(msg);
161-
docs_link(&mut diag, lint);
162-
diag.emit();
155+
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
156+
docs_link(diag, lint);
157+
diag
163158
});
164159
}
165160

@@ -171,11 +166,10 @@ pub fn span_lint_hir_and_then(
171166
msg: &str,
172167
f: impl FnOnce(&mut Diagnostic),
173168
) {
174-
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, |diag| {
175-
let mut diag = diag.build(msg);
176-
f(&mut diag);
177-
docs_link(&mut diag, lint);
178-
diag.emit();
169+
cx.tcx.struct_span_lint_hir(lint, hir_id, sp, msg, |diag| {
170+
f(diag);
171+
docs_link(diag, lint);
172+
diag
179173
});
180174
}
181175

0 commit comments

Comments
 (0)