Tweak highlighting when trait is available for different type
When printing ``` = help: the trait `chumsky::private::ParserSealed<'_, &'a str, ((), ()), chumsky::extra::Full<EmptyErr, (), ()>>` is implemented for `Then<Ignored<chumsky::combinator::Filter<chumsky::primitive::Any<&str, chumsky::extra::Full<EmptyErr, (), ()>>, {closure@src/main.rs:9:17: 9:27}>, char>, chumsky::combinator::Map<impl CSTParser<'a, O>, O, {closure@src/main.rs:11:24: 11:27}>, (), (), chumsky::extra::Full<EmptyErr, (), ()>>` = help: for that trait implementation, expected `((), ())`, found `()` ``` Highlight only the `expected` and `found` types, instead of the full type in the first `help`.
This commit is contained in:
parent
24ac777a64
commit
aa82fd6d1d
@ -1835,6 +1835,7 @@ pub(super) fn report_similar_impl_candidates(
|
||||
if impl_trait_ref.references_error() {
|
||||
return false;
|
||||
}
|
||||
let self_ty = impl_trait_ref.self_ty().to_string();
|
||||
err.highlighted_help(vec![
|
||||
StringPart::normal(format!(
|
||||
"the trait `{}` ",
|
||||
@ -1842,16 +1843,24 @@ pub(super) fn report_similar_impl_candidates(
|
||||
)),
|
||||
StringPart::highlighted("is"),
|
||||
StringPart::normal(" implemented for `"),
|
||||
StringPart::highlighted(impl_trait_ref.self_ty().to_string()),
|
||||
if let [TypeError::Sorts(_)] = &terrs[..] {
|
||||
StringPart::normal(self_ty)
|
||||
} else {
|
||||
StringPart::highlighted(self_ty)
|
||||
},
|
||||
StringPart::normal("`"),
|
||||
]);
|
||||
|
||||
if let [TypeError::Sorts(exp_found)] = &terrs[..] {
|
||||
let exp_found = self.resolve_vars_if_possible(*exp_found);
|
||||
err.help(format!(
|
||||
"for that trait implementation, expected `{}`, found `{}`",
|
||||
exp_found.expected, exp_found.found
|
||||
));
|
||||
err.highlighted_help(vec![
|
||||
StringPart::normal("for that trait implementation, "),
|
||||
StringPart::normal("expected `"),
|
||||
StringPart::highlighted(exp_found.expected.to_string()),
|
||||
StringPart::normal("`, found `"),
|
||||
StringPart::highlighted(exp_found.found.to_string()),
|
||||
StringPart::normal("`"),
|
||||
]);
|
||||
}
|
||||
|
||||
true
|
||||
|
@ -33,9 +33,9 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="118px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">|</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="136px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: the trait `Bar<()>` </tspan><tspan class="fg-magenta bold">is</tspan><tspan> implemented for `</tspan><tspan class="fg-magenta bold">Struct</tspan><tspan>`</tspan>
|
||||
<tspan x="10px" y="136px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: the trait `Bar<()>` </tspan><tspan class="fg-magenta bold">is</tspan><tspan> implemented for `Struct`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="154px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: for that trait implementation, expected `()`, found `i32`</tspan>
|
||||
<tspan x="10px" y="154px"><tspan> </tspan><tspan class="fg-ansi256-012 bold">= </tspan><tspan class="bold">help</tspan><tspan>: for that trait implementation, expected `</tspan><tspan class="fg-magenta bold">()</tspan><tspan>`, found `</tspan><tspan class="fg-magenta bold">i32</tspan><tspan>`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="172px"><tspan class="fg-ansi256-010 bold">note</tspan><tspan>: required for `Struct` to implement `Foo<i32>`</tspan>
|
||||
</tspan>
|
||||
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in New Issue
Block a user