|
1 | 1 | use crate::errors::{
|
2 | 2 | note_and_explain, FullfillReqLifetime, LfBoundNotSatisfied, OutlivesBound, OutlivesContent,
|
3 |
| - RefLongerThanData, RegionOriginNote, |
| 3 | + RefLongerThanData, RegionOriginNote, WhereClauseSuggestions, |
4 | 4 | };
|
5 | 5 | use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
|
6 | 6 | use crate::infer::{self, SubregionOrigin};
|
7 | 7 | use rustc_errors::{
|
8 |
| - fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, |
9 |
| - IntoDiagnostic, |
| 8 | + fluent, AddToDiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic, |
10 | 9 | };
|
11 | 10 | use rustc_hir::def_id::{DefId, LocalDefId};
|
12 | 11 | use rustc_middle::traits::ObligationCauseCode;
|
@@ -325,22 +324,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
325 | 324 |
|
326 | 325 | let Some(generics) = self.tcx.hir().get_generics(impl_item_def_id) else { return; };
|
327 | 326 |
|
328 |
| - if trait_predicates.is_empty() { |
329 |
| - err.span_suggestion_verbose( |
330 |
| - generics.where_clause_span, |
331 |
| - "remove the `where` clause", |
332 |
| - String::new(), |
333 |
| - Applicability::MachineApplicable, |
334 |
| - ); |
| 327 | + let suggestion = if trait_predicates.is_empty() { |
| 328 | + WhereClauseSuggestions::Remove { span: generics.where_clause_span } |
335 | 329 | } else {
|
336 | 330 | let space = if generics.where_clause_span.is_empty() { " " } else { "" };
|
337 |
| - err.span_suggestion_verbose( |
338 |
| - generics.where_clause_span, |
339 |
| - "copy the `where` clause predicates from the trait", |
340 |
| - format!("{space}where {}", trait_predicates.join(", ")), |
341 |
| - Applicability::MachineApplicable, |
342 |
| - ); |
343 |
| - } |
| 331 | + WhereClauseSuggestions::CopyPredicates { |
| 332 | + span: generics.where_clause_span, |
| 333 | + space, |
| 334 | + trait_predicates: trait_predicates.join(", "), |
| 335 | + } |
| 336 | + }; |
| 337 | + err.subdiagnostic(suggestion); |
344 | 338 | }
|
345 | 339 |
|
346 | 340 | pub(super) fn report_placeholder_failure(
|
|
0 commit comments