|
1 |
| -use clippy_utils::diagnostics::span_lint_and_help; |
| 1 | +use clippy_utils::diagnostics::span_lint_and_then; |
2 | 2 | use rustc_ast::ast;
|
3 | 3 | use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
4 | 4 | use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
|
@@ -121,17 +121,18 @@ impl EarlyLintPass for ModStyle {
|
121 | 121 | for folder in &folder_segments {
|
122 | 122 | if !mod_folders.contains(folder) {
|
123 | 123 | if let Some((file, path)) = file_map.get(folder) {
|
124 |
| - let mut correct = path.to_path_buf(); |
125 |
| - correct.pop(); |
126 |
| - correct.push(folder); |
127 |
| - correct.push("mod.rs"); |
128 |
| - span_lint_and_help( |
| 124 | + span_lint_and_then( |
129 | 125 | cx,
|
130 | 126 | SELF_NAMED_MODULE_FILES,
|
131 | 127 | Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
|
132 | 128 | format!("`mod.rs` files are required, found `{}`", path.display()),
|
133 |
| - None, |
134 |
| - format!("move `{}` to `{}`", path.display(), correct.display(),), |
| 129 | + |diag| { |
| 130 | + let mut correct = path.to_path_buf(); |
| 131 | + correct.pop(); |
| 132 | + correct.push(folder); |
| 133 | + correct.push("mod.rs"); |
| 134 | + diag.help(format!("move `{}` to `{}`", path.display(), correct.display(),)); |
| 135 | + }, |
135 | 136 | );
|
136 | 137 | }
|
137 | 138 | }
|
@@ -161,17 +162,18 @@ fn process_paths_for_mod_files<'a>(
|
161 | 162 | /// for code-sharing between tests.
|
162 | 163 | fn check_self_named_mod_exists(cx: &EarlyContext<'_>, path: &Path, file: &SourceFile) {
|
163 | 164 | if path.ends_with("mod.rs") && !path.starts_with("tests") {
|
164 |
| - let mut mod_file = path.to_path_buf(); |
165 |
| - mod_file.pop(); |
166 |
| - mod_file.set_extension("rs"); |
167 |
| - |
168 |
| - span_lint_and_help( |
| 165 | + span_lint_and_then( |
169 | 166 | cx,
|
170 | 167 | MOD_MODULE_FILES,
|
171 | 168 | Span::new(file.start_pos, file.start_pos, SyntaxContext::root(), None),
|
172 | 169 | format!("`mod.rs` files are not allowed, found `{}`", path.display()),
|
173 |
| - None, |
174 |
| - format!("move `{}` to `{}`", path.display(), mod_file.display()), |
| 170 | + |diag| { |
| 171 | + let mut mod_file = path.to_path_buf(); |
| 172 | + mod_file.pop(); |
| 173 | + mod_file.set_extension("rs"); |
| 174 | + |
| 175 | + diag.help(format!("move `{}` to `{}`", path.display(), mod_file.display())); |
| 176 | + }, |
175 | 177 | );
|
176 | 178 | }
|
177 | 179 | }
|
0 commit comments