diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-10-24 00:20:04 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-10-25 18:06:39 +0000 |
| commit | aa82fd6d1dd2f2ac6a44dbfa99e1de779b58428a (patch) | |
| tree | 6082435730875b64e0a659c46f351f66eca7586f /compiler/rustc_trait_selection/src | |
| parent | 24ac777a641c7efc6d2f6e9a69617800314119f5 (diff) | |
| download | rust-aa82fd6d1dd2f2ac6a44dbfa99e1de779b58428a.tar.gz rust-aa82fd6d1dd2f2ac6a44dbfa99e1de779b58428a.zip | |
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`.
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index b7e2ed391cd..1852837d5c7 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1835,6 +1835,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { 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 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { )), 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 |
