diff options
| author | bohan <bohan-zhang@foxmail.com> | 2023-11-04 17:00:33 +0800 |
|---|---|---|
| committer | bohan <bohan-zhang@foxmail.com> | 2023-11-04 22:15:22 +0800 |
| commit | a4768fea3545a799b9c19e65777f6fee7b50a561 (patch) | |
| tree | f41dcba0abcb8cd6704a9d11854e6701238348cd /compiler | |
| parent | 2db26d3d55387930f1b1dfb84810bcde5a787a09 (diff) | |
| download | rust-a4768fea3545a799b9c19e65777f6fee7b50a561.tar.gz rust-a4768fea3545a799b9c19e65777f6fee7b50a561.zip | |
fallback for `construct_generic_bound_failure`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/infer/error_reporting/mod.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index e4be435fded..26d071a0139 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2444,18 +2444,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let suggestion = if has_lifetimes { format!(" + {lt_name}") } else { format!(": {lt_name}") }; suggs.push((sp, suggestion)) - } else { - let generics = self.tcx.hir().get_generics(suggestion_scope).unwrap(); + } else if let Some(generics) = self.tcx.hir().get_generics(suggestion_scope) { let pred = format!("{bound_kind}: {lt_name}"); - let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred,); + let suggestion = format!("{} {}", generics.add_where_or_trailing_comma(), pred); suggs.push((generics.tail_span_for_predicate_suggestion(), suggestion)) + } else { + let consider = format!("{msg} `{bound_kind}: {sub}`..."); + err.help(consider); } - err.multipart_suggestion_verbose( - format!("{msg}"), - suggs, - Applicability::MaybeIncorrect, // Issue #41966 - ); + if !suggs.is_empty() { + err.multipart_suggestion_verbose( + format!("{msg}"), + suggs, + Applicability::MaybeIncorrect, // Issue #41966 + ); + } } err |
