11//! Error Reporting for `impl` items that do not match the obligations from their `trait`.
22
3+ use crate :: errors:: { ConsiderBorrowingParamHelp , RelationshipHelp , TraitImplDiff } ;
34use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
45use crate :: infer:: lexical_region_resolve:: RegionResolutionError ;
56use crate :: infer:: Subtype ;
67use crate :: traits:: ObligationCauseCode :: CompareImplItemObligation ;
7- use rustc_errors:: { ErrorGuaranteed , MultiSpan } ;
8+ use rustc_errors:: ErrorGuaranteed ;
89use rustc_hir as hir;
910use rustc_hir:: def:: Res ;
1011use rustc_hir:: def_id:: DefId ;
@@ -51,10 +52,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5152 trait_def_id : DefId ,
5253 ) -> ErrorGuaranteed {
5354 let trait_sp = self . tcx ( ) . def_span ( trait_def_id) ;
54- let mut err = self
55- . tcx ( )
56- . sess
57- . struct_span_err ( sp, "`impl` item signature doesn't match `trait` item signature" ) ;
5855
5956 // Mark all unnamed regions in the type with a number.
6057 // This diagnostic is called in response to lifetime errors, so be informative.
@@ -91,9 +88,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9188 let found =
9289 self . cx . extract_inference_diagnostics_data ( found. into ( ) , Some ( found_highlight) ) . name ;
9390
94- err. span_label ( sp, & format ! ( "found `{}`" , found) ) ;
95- err. span_label ( trait_sp, & format ! ( "expected `{}`" , expected) ) ;
96-
9791 // Get the span of all the used type parameters in the method.
9892 let assoc_item = self . tcx ( ) . associated_item ( trait_def_id) ;
9993 let mut visitor = TypeParamSpanVisitor { tcx : self . tcx ( ) , types : vec ! [ ] } ;
@@ -110,26 +104,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
110104 }
111105 _ => { }
112106 }
113- let mut type_param_span: MultiSpan = visitor. types . to_vec ( ) . into ( ) ;
114- for & span in & visitor. types {
115- type_param_span
116- . push_span_label ( span, "consider borrowing this type parameter in the trait" ) ;
117- }
118107
119- err. note ( & format ! ( "expected `{}`\n found `{}`" , expected, found) ) ;
120-
121- err. span_help (
122- type_param_span,
123- "the lifetime requirements from the `impl` do not correspond to the requirements in \
124- the `trait`",
125- ) ;
126- if visitor. types . is_empty ( ) {
127- err. help (
128- "verify the lifetime relationships in the `trait` and `impl` between the `self` \
129- argument, the other inputs and its output",
130- ) ;
131- }
132- err. emit ( )
108+ let diag = TraitImplDiff {
109+ sp,
110+ trait_sp,
111+ note : ( ) ,
112+ param_help : ConsiderBorrowingParamHelp { spans : visitor. types . to_vec ( ) } ,
113+ rel_help : visitor. types . is_empty ( ) . then_some ( RelationshipHelp ) ,
114+ expected,
115+ found,
116+ } ;
117+
118+ self . tcx ( ) . sess . emit_err ( diag)
133119 }
134120}
135121
0 commit comments