@@ -82,57 +82,71 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
82
82
note_obligation_cause ( infcx, obligation) ;
83
83
}
84
84
SelectionError :: Unimplemented => {
85
- match obligation. predicate {
86
- ty:: Predicate :: Trait ( ref trait_predicate) => {
87
- let trait_predicate =
88
- infcx. resolve_type_vars_if_possible ( trait_predicate) ;
89
- if !trait_predicate. references_error ( ) {
90
- let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
91
- infcx. tcx . sess . span_err (
92
- obligation. cause . span ,
93
- format ! (
94
- "the trait `{}` is not implemented for the type `{}`" ,
95
- trait_ref. user_string( infcx. tcx) ,
96
- trait_ref. self_ty( ) . user_string( infcx. tcx) ) . as_slice ( ) ) ;
97
- }
98
- }
99
-
100
- ty:: Predicate :: Equate ( ref predicate) => {
101
- let predicate = infcx. resolve_type_vars_if_possible ( predicate) ;
102
- let err = infcx. equality_predicate ( obligation. cause . span ,
103
- & predicate) . unwrap_err ( ) ;
85
+ match & obligation. cause . code {
86
+ & ObligationCauseCode :: CompareImplMethodObligation => {
104
87
infcx. tcx . sess . span_err (
105
88
obligation. cause . span ,
106
89
format ! (
107
- "the requirement `{}` is not satisfied (`{}`)" ,
108
- predicate . user_string ( infcx . tcx ) ,
109
- ty :: type_err_to_str ( infcx. tcx, & err ) ) . as_slice ( ) ) ;
90
+ "the requirement `{}` appears on the impl \
91
+ method but not on the corresponding trait method" ,
92
+ obligation . predicate . user_string ( infcx. tcx) ) . as_slice ( ) ) ;
110
93
}
94
+ _ => {
95
+ match obligation. predicate {
96
+ ty:: Predicate :: Trait ( ref trait_predicate) => {
97
+ let trait_predicate =
98
+ infcx. resolve_type_vars_if_possible ( trait_predicate) ;
99
+ if !trait_predicate. references_error ( ) {
100
+ let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
101
+ infcx. tcx . sess . span_err (
102
+ obligation. cause . span ,
103
+ format ! (
104
+ "the trait `{}` is not implemented for the type `{}`" ,
105
+ trait_ref. user_string( infcx. tcx) ,
106
+ trait_ref. self_ty( ) . user_string( infcx. tcx) ) . as_slice ( ) ) ;
107
+ }
108
+ }
111
109
112
- ty:: Predicate :: RegionOutlives ( ref predicate) => {
113
- let predicate = infcx. resolve_type_vars_if_possible ( predicate) ;
114
- let err = infcx. region_outlives_predicate ( obligation. cause . span ,
115
- & predicate) . unwrap_err ( ) ;
116
- infcx. tcx . sess . span_err (
117
- obligation. cause . span ,
118
- format ! (
119
- "the requirement `{}` is not satisfied (`{}`)" ,
120
- predicate. user_string( infcx. tcx) ,
121
- ty:: type_err_to_str( infcx. tcx, & err) ) . as_slice ( ) ) ;
122
- }
110
+ ty:: Predicate :: Equate ( ref predicate) => {
111
+ let predicate = infcx. resolve_type_vars_if_possible ( predicate) ;
112
+ let err = infcx. equality_predicate ( obligation. cause . span ,
113
+ & predicate) . unwrap_err ( ) ;
123
114
124
- ty:: Predicate :: Projection ( ..) |
125
- ty:: Predicate :: TypeOutlives ( ..) => {
126
- let predicate =
127
- infcx. resolve_type_vars_if_possible ( & obligation. predicate ) ;
128
- infcx. tcx . sess . span_err (
129
- obligation. cause . span ,
130
- format ! (
131
- "the requirement `{}` is not satisfied" ,
132
- predicate. user_string( infcx. tcx) ) . as_slice ( ) ) ;
115
+ infcx. tcx . sess . span_err (
116
+ obligation. cause . span ,
117
+ format ! (
118
+ "the requirement `{}` is not satisfied (`{}`)" ,
119
+ predicate. user_string( infcx. tcx) ,
120
+ ty:: type_err_to_str( infcx. tcx, & err) ) . as_slice ( ) ) ;
121
+ }
122
+
123
+ ty:: Predicate :: RegionOutlives ( ref predicate) => {
124
+ let predicate = infcx. resolve_type_vars_if_possible ( predicate) ;
125
+ let err = infcx. region_outlives_predicate ( obligation. cause . span ,
126
+ & predicate) . unwrap_err ( ) ;
127
+ infcx. tcx . sess . span_err (
128
+ obligation. cause . span ,
129
+ format ! (
130
+ "the requirement `{}` is not satisfied (`{}`)" ,
131
+ predicate. user_string( infcx. tcx) ,
132
+ ty:: type_err_to_str( infcx. tcx, & err) ) . as_slice ( ) ) ;
133
+ }
134
+
135
+ ty:: Predicate :: Projection ( ..) |
136
+ ty:: Predicate :: TypeOutlives ( ..) => {
137
+ let predicate =
138
+ infcx. resolve_type_vars_if_possible ( & obligation. predicate ) ;
139
+ infcx. tcx . sess . span_err (
140
+ obligation. cause . span ,
141
+ format ! (
142
+ "the requirement `{}` is not satisfied" ,
143
+ predicate. user_string( infcx. tcx) ) . as_slice ( ) ) ;
144
+ }
145
+ }
133
146
}
134
147
}
135
148
}
149
+
136
150
OutputTypeParameterMismatch ( ref expected_trait_ref, ref actual_trait_ref, ref e) => {
137
151
let expected_trait_ref = infcx. resolve_type_vars_if_possible ( & * expected_trait_ref) ;
138
152
let actual_trait_ref = infcx. resolve_type_vars_if_possible ( & * actual_trait_ref) ;
@@ -242,7 +256,7 @@ fn note_obligation_cause<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
242
256
}
243
257
244
258
fn note_obligation_cause_code < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > ,
245
- _predicate : & ty:: Predicate < ' tcx > ,
259
+ predicate : & ty:: Predicate < ' tcx > ,
246
260
cause_span : Span ,
247
261
cause_code : & ObligationCauseCode < ' tcx > )
248
262
{
@@ -329,6 +343,11 @@ fn note_obligation_cause_code<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
329
343
let parent_predicate = parent_trait_ref. as_predicate ( ) ;
330
344
note_obligation_cause_code ( infcx, & parent_predicate, cause_span, & * data. parent_code ) ;
331
345
}
346
+ ObligationCauseCode :: CompareImplMethodObligation => {
347
+ span_note ! ( tcx. sess, cause_span,
348
+ "the requirement `{}` appears on the impl method but not on the corresponding trait method" ,
349
+ predicate. user_string( infcx. tcx) ) ;
350
+ }
332
351
}
333
352
}
334
353
0 commit comments