Skip to content

Commit

Permalink
Merge pull request #198 from mejrs/master
Browse files Browse the repository at this point in the history
Normalize "and x others"
  • Loading branch information
dtolnay authored Oct 8, 2022
2 parents 3900615 + ea3f207 commit cc4351f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub fn diagnostics(output: &str, context: Context) -> Variations {
RelativeToDir,
LinesOutsideInputFile,
Unindent,
AndOther,
]
.iter()
.map(|normalization| apply(&output, *normalization, context))
Expand Down Expand Up @@ -100,6 +101,7 @@ enum Normalization {
RelativeToDir,
LinesOutsideInputFile,
Unindent,
AndOther,
// New normalization steps are to be inserted here at the end so that any
// snapshots saved before your normalization change remain passing.
}
Expand Down Expand Up @@ -350,6 +352,15 @@ impl<'a> Filter<'a> {
"$WORKSPACE/",
);

if self.normalization >= AndOther {
// Replace any "and 123 others" with "and $COUNT others"
if line.trim_start().starts_with("and") && line.trim_end().ends_with("others") {
let start = line.find("and").unwrap() + 4;
let end = line.find("others").unwrap() - 1;
line.replace_range(start..end, "$COUNT");
}
}

Some(line)
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ fn test() {
t.pass("tests/ui/run-pass-9.rs");
t.compile_fail("tests/ui/compile-fail-2.rs");
t.compile_fail("tests/ui/compile-fail-3.rs");
t.compile_fail("tests/ui/normalize_and_x_others.rs");
}
3 changes: 3 additions & 0 deletions tests/ui/normalize_and_x_others.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
let _x = 42_u8 >> "bar";
}
17 changes: 17 additions & 0 deletions tests/ui/normalize_and_x_others.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0277]: no implementation for `u8 >> &str`
--> tests/ui/normalize_and_x_others.rs:2:20
|
2 | let _x = 42_u8 >> "bar";
| ^^ no implementation for `u8 >> &str`
|
= help: the trait `Shr<&str>` is not implemented for `u8`
= help: the following other types implement trait `Shr<Rhs>`:
<&'a i128 as Shr<i128>>
<&'a i128 as Shr<i16>>
<&'a i128 as Shr<i32>>
<&'a i128 as Shr<i64>>
<&'a i128 as Shr<i8>>
<&'a i128 as Shr<isize>>
<&'a i128 as Shr<u128>>
<&'a i128 as Shr<u16>>
and $COUNT others

0 comments on commit cc4351f

Please sign in to comment.