Skip to content

Commit 836bc69

Browse files
authored
Rollup merge of #120132 - oli-obk:helpful_tidy, r=Mark-Simulacrum
Teach tidy about line/col information for malformed features This makes it significantly easier to find the specific feature, since you can now just click it in the command line of your IDE
2 parents 177d513 + 50b4ca6 commit 836bc69

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/tools/tidy/src/features.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::ffi::OsStr;
1515
use std::fmt;
1616
use std::fs;
1717
use std::num::NonZeroU32;
18-
use std::path::Path;
18+
use std::path::{Path, PathBuf};
1919

2020
use regex::Regex;
2121

@@ -52,6 +52,8 @@ pub struct Feature {
5252
pub since: Option<Version>,
5353
pub has_gate_test: bool,
5454
pub tracking_issue: Option<NonZeroU32>,
55+
pub file: PathBuf,
56+
pub line: usize,
5557
}
5658
impl Feature {
5759
fn tracking_issue_display(&self) -> impl fmt::Display {
@@ -184,23 +186,25 @@ pub fn check(
184186
.chain(lib_features.iter().map(|feat| (feat, "lib")));
185187
for ((feature_name, feature), kind) in all_features_iter {
186188
let since = if let Some(since) = feature.since { since } else { continue };
189+
let file = feature.file.display();
190+
let line = feature.line;
187191
if since > version && since != Version::CurrentPlaceholder {
188192
tidy_error!(
189193
bad,
190-
"The stabilization version {since} of {kind} feature `{feature_name}` is newer than the current {version}"
194+
"{file}:{line}: The stabilization version {since} of {kind} feature `{feature_name}` is newer than the current {version}"
191195
);
192196
}
193197
if channel == "nightly" && since == version {
194198
tidy_error!(
195199
bad,
196-
"The stabilization version {since} of {kind} feature `{feature_name}` is written out but should be {}",
200+
"{file}:{line}: The stabilization version {since} of {kind} feature `{feature_name}` is written out but should be {}",
197201
version::VERSION_PLACEHOLDER
198202
);
199203
}
200204
if channel != "nightly" && since == Version::CurrentPlaceholder {
201205
tidy_error!(
202206
bad,
203-
"The placeholder use of {kind} feature `{feature_name}` is not allowed on the {channel} channel",
207+
"{file}:{line}: The placeholder use of {kind} feature `{feature_name}` is not allowed on the {channel} channel",
204208
);
205209
}
206210
}
@@ -433,7 +437,14 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
433437
);
434438
}
435439
Entry::Vacant(e) => {
436-
e.insert(Feature { level, since, has_gate_test: false, tracking_issue });
440+
e.insert(Feature {
441+
level,
442+
since,
443+
has_gate_test: false,
444+
tracking_issue,
445+
file: path.to_path_buf(),
446+
line: line_number,
447+
});
437448
}
438449
}
439450
}
@@ -559,6 +570,8 @@ fn map_lib_features(
559570
since: None,
560571
has_gate_test: false,
561572
tracking_issue: find_attr_val(line, "issue").and_then(handle_issue_none),
573+
file: file.to_path_buf(),
574+
line: i + 1,
562575
};
563576
mf(Ok((feature_name, feature)), file, i + 1);
564577
continue;
@@ -588,7 +601,14 @@ fn map_lib_features(
588601
};
589602
let tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
590603

591-
let feature = Feature { level, since, has_gate_test: false, tracking_issue };
604+
let feature = Feature {
605+
level,
606+
since,
607+
has_gate_test: false,
608+
tracking_issue,
609+
file: file.to_path_buf(),
610+
line: i + 1,
611+
};
592612
if line.contains(']') {
593613
mf(Ok((feature_name, feature)), file, i + 1);
594614
} else {

0 commit comments

Comments
 (0)