diff --git a/src/normalize.rs b/src/normalize.rs index d738203..8171114 100644 --- a/src/normalize.rs +++ b/src/normalize.rs @@ -57,6 +57,7 @@ normalizations! { Unindent, AndOthers, StripLongTypeNameFiles, + UnindentAfterHelp, // New normalization steps are to be inserted here at the end so that any // snapshots saved before your normalization change remain passing. } @@ -139,9 +140,7 @@ fn apply(original: &str, normalization: Normalization, context: Context) -> Stri } } - if normalization >= Unindent { - normalized = unindent(normalized); - } + normalized = unindent(normalized, normalization); trim(normalized) } @@ -494,7 +493,11 @@ enum IndentedLineKind { Other(usize), } -fn unindent(diag: String) -> String { +fn unindent(diag: String, normalization: Normalization) -> String { + if normalization < Unindent { + return diag; + } + let mut normalized = String::new(); let mut lines = diag.lines(); @@ -502,7 +505,7 @@ fn unindent(diag: String) -> String { normalized.push_str(line); normalized.push('\n'); - if indented_line_kind(line) != IndentedLineKind::Heading { + if indented_line_kind(line, normalization) != IndentedLineKind::Heading { continue; } @@ -512,12 +515,12 @@ fn unindent(diag: String) -> String { None => continue, }; - if let IndentedLineKind::Code(indent) = indented_line_kind(next_line) { + if let IndentedLineKind::Code(indent) = indented_line_kind(next_line, normalization) { if next_line[indent + 1..].starts_with("--> ") { let mut lines_in_block = 1; let mut least_indent = indent; while let Some(line) = ahead.next() { - match indented_line_kind(line) { + match indented_line_kind(line, normalization) { IndentedLineKind::Heading => break, IndentedLineKind::Code(indent) => { lines_in_block += 1; @@ -536,7 +539,7 @@ fn unindent(diag: String) -> String { for _ in 0..lines_in_block { let line = lines.next().unwrap(); if let IndentedLineKind::Code(_) | IndentedLineKind::Other(_) = - indented_line_kind(line) + indented_line_kind(line, normalization) { let space = line.find(' ').unwrap(); normalized.push_str(&line[..space]); @@ -553,7 +556,7 @@ fn unindent(diag: String) -> String { normalized } -fn indented_line_kind(line: &str) -> IndentedLineKind { +fn indented_line_kind(line: &str, normalization: Normalization) -> IndentedLineKind { if let Some(heading_len) = if line.starts_with("error") { Some("error".len()) } else if line.starts_with("warning") { @@ -566,7 +569,10 @@ fn indented_line_kind(line: &str) -> IndentedLineKind { } } - if line.starts_with("note:") || line == "..." { + if line.starts_with("note:") + || line == "..." + || normalization >= UnindentAfterHelp && line.starts_with("help:") + { return IndentedLineKind::Note; } diff --git a/src/tests/erased-serde-trait-bound.rs b/src/tests/erased-serde-trait-bound.rs new file mode 100644 index 0000000..a4cc34a --- /dev/null +++ b/src/tests/erased-serde-trait-bound.rs @@ -0,0 +1,43 @@ +test_normalize! {" +error[E0277]: the trait bound `__T: serde::ser::Serialize` is not satisfied + --> src/main.rs:5:1 + | +5 | serialize_trait_object!(MyTrait); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `__T` + | + = note: required for `__T` to implement `erased_serde::Serialize` +note: required by a bound in `require_erased_serialize_impl` + --> /home/david/.cargo/registry/src/index.crates.io-6f17d22bba15001f/erased-serde-0.3.28/src/private.rs:14:17 + | +12 | pub fn require_erased_serialize_impl() + | ----------------------------- required by a bound in this function +13 | where +14 | T: ?Sized + crate::Serialize, + | ^^^^^^^^^^^^^^^^ required by this bound in `require_erased_serialize_impl` + = note: this error originates in the macro `$crate::__internal_serialize_trait_object` which comes from the expansion of the macro `serialize_trait_object` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +5 | serialize_trait_object!(MyTrait + serde::ser::Serialize); + | +++++++++++++++++++++++ +" " +error[E0277]: the trait bound `__T: serde::ser::Serialize` is not satisfied + --> src/main.rs:5:1 + | +5 | serialize_trait_object!(MyTrait); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `serde::ser::Serialize` is not implemented for `__T` + | + = note: required for `__T` to implement `erased_serde::Serialize` +note: required by a bound in `require_erased_serialize_impl` + --> $CARGO/erased-serde-0.3.28/src/private.rs + | + | pub fn require_erased_serialize_impl() + | ----------------------------- required by a bound in this function + | where + | T: ?Sized + crate::Serialize, + | ^^^^^^^^^^^^^^^^ required by this bound in `require_erased_serialize_impl` + = note: this error originates in the macro `$crate::__internal_serialize_trait_object` which comes from the expansion of the macro `serialize_trait_object` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting this bound + | +5 | serialize_trait_object!(MyTrait + serde::ser::Serialize); + | +++++++++++++++++++++++ +"}