diff --git a/src/normalize.rs b/src/normalize.rs index 5e95476..8f70ac9 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -58,6 +58,7 @@ normalizations! { AndOthers, StripLongTypeNameFiles, UnindentAfterHelp, + AndOthersVerbose, // New normalization steps are to be inserted here at the end so that any // snapshots saved before your normalization change remain passing. } @@ -130,6 +131,7 @@ fn apply(original: &str, normalization: Normalization, context: Context) -> Stri normalization, context, hide_numbers: 0, + other_types: None, }; for i in 0..lines.len() { if let Some(line) = filter.apply(i) { @@ -150,6 +152,7 @@ struct Filter<'a> { normalization: Normalization, context: Context<'a>, hide_numbers: usize, + other_types: Option, } impl<'a> Filter<'a> { @@ -408,6 +411,32 @@ impl<'a> Filter<'a> { } } + if self.normalization >= AndOthersVerbose { + let trim_start = line.trim_start(); + if trim_start.starts_with("= help: the following types implement trait ") + || trim_start.starts_with("= help: the following other types implement trait ") + { + self.other_types = Some(0); + } else if let Some(count_other_types) = &mut self.other_types { + if indent >= 12 && trim_start != "and $N others" { + *count_other_types += 1; + if *count_other_types == 9 { + if let Some(next) = self.all_lines.get(index + 1) { + let next_trim_start = next.trim_start(); + let next_indent = next.len() - next_trim_start.len(); + if indent == next_indent { + line.replace_range(indent - 2.., "and $N others"); + } + } + } else if *count_other_types > 9 { + return None; + } + } else { + self.other_types = None; + } + } + } + line = line.replace(self.context.krate, "$CRATE"); line = replace_case_insensitive(&line, &self.context.source_dir.to_string_lossy(), "$DIR/"); line = replace_case_insensitive( diff --git a/src/tests/and-others-verbose.rs b/src/tests/and-others-verbose.rs new file mode 100644 index 0000000..9d1ae3c --- /dev/null +++ b/src/tests/and-others-verbose.rs @@ -0,0 +1,150 @@ +test_normalize! {r#" +error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied + --> tests/ui/on_unimplemented.rs:22:23 + | +22 | let _: MyStruct = from_str(""); + | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct` + | + = help: the following other types implement trait `Deserialize<'de>`: + &'a Path + &'a [u8] + &'a str + () + (T,) + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) +note: required by a bound in `from_str` + --> tests/ui/on_unimplemented.rs:13:8 + | +11 | fn from_str<'de, T>(_: &'de str) -> T + | -------- required by a bound in this function +12 | where +13 | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `from_str` + +error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied + --> tests/ui/on_unimplemented.rs:22:23 + | +22 | let _: MyStruct = from_str(""); + | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct` + | + = help: the following other types implement trait `Deserialize<'de>`: + &'a Path + &'a [u8] + &'a str + () + (T,) + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) + (T0, T1, T2, T3, T4) +note: required by a bound in `from_str` + --> tests/ui/on_unimplemented.rs:13:8 + | +11 | fn from_str<'de, T>(_: &'de str) -> T + | -------- required by a bound in this function +12 | where +13 | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `from_str` + +error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied + --> tests/ui/on_unimplemented.rs:22:23 + | +22 | let _: MyStruct = from_str(""); + | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct` + | + = help: the following other types implement trait `Deserialize<'de>`: + &'a Path + &'a [u8] + &'a str + () + (T,) + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) + (T0, T1, T2, T3, T4) + (T0, T1, T2, T3, T4, T5) +note: required by a bound in `from_str` + --> tests/ui/on_unimplemented.rs:13:8 + | +11 | fn from_str<'de, T>(_: &'de str) -> T + | -------- required by a bound in this function +12 | where +13 | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `from_str` +"# r#" +error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied + --> tests/ui/on_unimplemented.rs:22:23 + | +22 | let _: MyStruct = from_str(""); + | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct` + | + = help: the following other types implement trait `Deserialize<'de>`: + &'a Path + &'a [u8] + &'a str + () + (T,) + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) +note: required by a bound in `from_str` + --> tests/ui/on_unimplemented.rs:13:8 + | +11 | fn from_str<'de, T>(_: &'de str) -> T + | -------- required by a bound in this function +12 | where +13 | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `from_str` + +error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied + --> tests/ui/on_unimplemented.rs:22:23 + | +22 | let _: MyStruct = from_str(""); + | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct` + | + = help: the following other types implement trait `Deserialize<'de>`: + &'a Path + &'a [u8] + &'a str + () + (T,) + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) + (T0, T1, T2, T3, T4) +note: required by a bound in `from_str` + --> tests/ui/on_unimplemented.rs:13:8 + | +11 | fn from_str<'de, T>(_: &'de str) -> T + | -------- required by a bound in this function +12 | where +13 | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `from_str` + +error[E0277]: the trait bound `MyStruct: Deserialize<'_>` is not satisfied + --> tests/ui/on_unimplemented.rs:22:23 + | +22 | let _: MyStruct = from_str(""); + | ^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `MyStruct` + | + = help: the following other types implement trait `Deserialize<'de>`: + &'a Path + &'a [u8] + &'a str + () + (T,) + (T0, T1) + (T0, T1, T2) + (T0, T1, T2, T3) + and $N others +note: required by a bound in `from_str` + --> tests/ui/on_unimplemented.rs:13:8 + | +11 | fn from_str<'de, T>(_: &'de str) -> T + | -------- required by a bound in this function +12 | where +13 | T: Deserialize<'de>, + | ^^^^^^^^^^^^^^^^ required by this bound in `from_str` +"#}