1
1
//! Error Reporting for `impl` items that do not match the obligations from their `trait`.
2
2
3
+ use crate :: errors:: { ConsiderBorrowingParamHelp , RelationshipHelp , TraitImplDiff } ;
3
4
use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
4
5
use crate :: infer:: lexical_region_resolve:: RegionResolutionError ;
5
6
use crate :: infer:: Subtype ;
6
7
use crate :: traits:: ObligationCauseCode :: CompareImplItemObligation ;
7
- use rustc_errors:: { ErrorGuaranteed , MultiSpan } ;
8
+ use rustc_errors:: ErrorGuaranteed ;
8
9
use rustc_hir as hir;
9
10
use rustc_hir:: def:: Res ;
10
11
use rustc_hir:: def_id:: DefId ;
@@ -51,10 +52,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
51
52
trait_def_id : DefId ,
52
53
) -> ErrorGuaranteed {
53
54
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" ) ;
58
55
59
56
// Mark all unnamed regions in the type with a number.
60
57
// This diagnostic is called in response to lifetime errors, so be informative.
@@ -91,9 +88,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
91
88
let found =
92
89
self . cx . extract_inference_diagnostics_data ( found. into ( ) , Some ( found_highlight) ) . name ;
93
90
94
- err. span_label ( sp, & format ! ( "found `{}`" , found) ) ;
95
- err. span_label ( trait_sp, & format ! ( "expected `{}`" , expected) ) ;
96
-
97
91
// Get the span of all the used type parameters in the method.
98
92
let assoc_item = self . tcx ( ) . associated_item ( trait_def_id) ;
99
93
let mut visitor = TypeParamSpanVisitor { tcx : self . tcx ( ) , types : vec ! [ ] } ;
@@ -110,26 +104,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
110
104
}
111
105
_ => { }
112
106
}
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
- }
118
107
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)
133
119
}
134
120
}
135
121
0 commit comments