Teach tidy about line/col information for malformed features
This commit is contained in:
parent
92d727796b
commit
50b4ca637d
1 changed files with 26 additions and 6 deletions
|
@ -15,7 +15,7 @@ use std::ffi::OsStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ pub struct Feature {
|
||||||
pub since: Option<Version>,
|
pub since: Option<Version>,
|
||||||
pub has_gate_test: bool,
|
pub has_gate_test: bool,
|
||||||
pub tracking_issue: Option<NonZeroU32>,
|
pub tracking_issue: Option<NonZeroU32>,
|
||||||
|
pub file: PathBuf,
|
||||||
|
pub line: usize,
|
||||||
}
|
}
|
||||||
impl Feature {
|
impl Feature {
|
||||||
fn tracking_issue_display(&self) -> impl fmt::Display {
|
fn tracking_issue_display(&self) -> impl fmt::Display {
|
||||||
|
@ -184,23 +186,25 @@ pub fn check(
|
||||||
.chain(lib_features.iter().map(|feat| (feat, "lib")));
|
.chain(lib_features.iter().map(|feat| (feat, "lib")));
|
||||||
for ((feature_name, feature), kind) in all_features_iter {
|
for ((feature_name, feature), kind) in all_features_iter {
|
||||||
let since = if let Some(since) = feature.since { since } else { continue };
|
let since = if let Some(since) = feature.since { since } else { continue };
|
||||||
|
let file = feature.file.display();
|
||||||
|
let line = feature.line;
|
||||||
if since > version && since != Version::CurrentPlaceholder {
|
if since > version && since != Version::CurrentPlaceholder {
|
||||||
tidy_error!(
|
tidy_error!(
|
||||||
bad,
|
bad,
|
||||||
"The stabilization version {since} of {kind} feature `{feature_name}` is newer than the current {version}"
|
"{file}:{line}: The stabilization version {since} of {kind} feature `{feature_name}` is newer than the current {version}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if channel == "nightly" && since == version {
|
if channel == "nightly" && since == version {
|
||||||
tidy_error!(
|
tidy_error!(
|
||||||
bad,
|
bad,
|
||||||
"The stabilization version {since} of {kind} feature `{feature_name}` is written out but should be {}",
|
"{file}:{line}: The stabilization version {since} of {kind} feature `{feature_name}` is written out but should be {}",
|
||||||
version::VERSION_PLACEHOLDER
|
version::VERSION_PLACEHOLDER
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if channel != "nightly" && since == Version::CurrentPlaceholder {
|
if channel != "nightly" && since == Version::CurrentPlaceholder {
|
||||||
tidy_error!(
|
tidy_error!(
|
||||||
bad,
|
bad,
|
||||||
"The placeholder use of {kind} feature `{feature_name}` is not allowed on the {channel} channel",
|
"{file}:{line}: The placeholder use of {kind} feature `{feature_name}` is not allowed on the {channel} channel",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,7 +437,14 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Entry::Vacant(e) => {
|
Entry::Vacant(e) => {
|
||||||
e.insert(Feature { level, since, has_gate_test: false, tracking_issue });
|
e.insert(Feature {
|
||||||
|
level,
|
||||||
|
since,
|
||||||
|
has_gate_test: false,
|
||||||
|
tracking_issue,
|
||||||
|
file: path.to_path_buf(),
|
||||||
|
line: line_number,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -559,6 +570,8 @@ fn map_lib_features(
|
||||||
since: None,
|
since: None,
|
||||||
has_gate_test: false,
|
has_gate_test: false,
|
||||||
tracking_issue: find_attr_val(line, "issue").and_then(handle_issue_none),
|
tracking_issue: find_attr_val(line, "issue").and_then(handle_issue_none),
|
||||||
|
file: file.to_path_buf(),
|
||||||
|
line: i + 1,
|
||||||
};
|
};
|
||||||
mf(Ok((feature_name, feature)), file, i + 1);
|
mf(Ok((feature_name, feature)), file, i + 1);
|
||||||
continue;
|
continue;
|
||||||
|
@ -588,7 +601,14 @@ fn map_lib_features(
|
||||||
};
|
};
|
||||||
let tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
|
let tracking_issue = find_attr_val(line, "issue").and_then(handle_issue_none);
|
||||||
|
|
||||||
let feature = Feature { level, since, has_gate_test: false, tracking_issue };
|
let feature = Feature {
|
||||||
|
level,
|
||||||
|
since,
|
||||||
|
has_gate_test: false,
|
||||||
|
tracking_issue,
|
||||||
|
file: file.to_path_buf(),
|
||||||
|
line: i + 1,
|
||||||
|
};
|
||||||
if line.contains(']') {
|
if line.contains(']') {
|
||||||
mf(Ok((feature_name, feature)), file, i + 1);
|
mf(Ok((feature_name, feature)), file, i + 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue