Skip to content

Commit fdcf854

Browse files
committed
tidy: Accommodate rustfmt's preferred layout of stability attributes
Previously tidy would require that the `feature = "name_of_feature"` part of the stability attribute was on the same line as the `#[stable(` / `#[unstable(` opening part of the attribute, and that `)]` was on the same line as the last key-value pair. That didn't work with rustfmt's preferred layout of long attributes, which is like: #[unstable( feature = "c_variadic", reason = "the `c_variadic` feature has not been properly tested on \ all supported platforms", issue = "44930" )]
1 parent 5a1d028 commit fdcf854

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/tools/tidy/src/features.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ fn map_lib_features(base_src_path: &Path,
397397
}
398398

399399
let mut becoming_feature: Option<(&str, Feature)> = None;
400-
for (i, line) in contents.lines().enumerate() {
400+
let mut iter_lines = contents.lines().enumerate().peekable();
401+
while let Some((i, line)) = iter_lines.next() {
401402
macro_rules! err {
402403
($msg:expr) => {{
403404
mf(Err($msg), file, i + 1);
@@ -411,7 +412,7 @@ fn map_lib_features(base_src_path: &Path,
411412
}
412413
if line.ends_with(']') {
413414
mf(Ok((name, f.clone())), file, i + 1);
414-
} else if !line.ends_with(',') && !line.ends_with('\\') {
415+
} else if !line.ends_with(',') && !line.ends_with('\\') && !line.ends_with('"') {
415416
// We need to bail here because we might have missed the
416417
// end of a stability attribute above because the ']'
417418
// might not have been at the end of the line.
@@ -450,7 +451,9 @@ fn map_lib_features(base_src_path: &Path,
450451
} else {
451452
continue;
452453
};
453-
let feature_name = match find_attr_val(line, "feature") {
454+
let feature_name = match find_attr_val(line, "feature")
455+
.or_else(|| iter_lines.peek().and_then(|next| find_attr_val(next.1, "feature")))
456+
{
454457
Some(name) => name,
455458
None => err!("malformed stability attribute: missing `feature` key"),
456459
};

0 commit comments

Comments
 (0)