@@ -123,6 +123,10 @@ pub enum ResolutionError<'a> {
123
123
UndeclaredAssociatedType ,
124
124
/// error E0407: method is not a member of trait
125
125
MethodNotMemberOfTrait ( Name , & ' a str ) ,
126
+ /// error E0437: type is not a member of trait
127
+ TypeNotMemberOfTrait ( Name , & ' a str ) ,
128
+ /// error E0438: const is not a member of trait
129
+ ConstNotMemberOfTrait ( Name , & ' a str ) ,
126
130
/// error E0408: variable `{}` from pattern #1 is not bound in pattern
127
131
VariableNotBoundInPattern ( Name , usize ) ,
128
132
/// error E0409: variable is bound with different mode in pattern #{} than in pattern #1
@@ -220,6 +224,18 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syn
220
224
method,
221
225
trait_) ;
222
226
} ,
227
+ ResolutionError :: TypeNotMemberOfTrait ( type_, trait_) => {
228
+ span_err ! ( resolver. session, span, E0437 ,
229
+ "type `{}` is not a member of trait `{}`" ,
230
+ type_,
231
+ trait_) ;
232
+ } ,
233
+ ResolutionError :: ConstNotMemberOfTrait ( const_, trait_) => {
234
+ span_err ! ( resolver. session, span, E0438 ,
235
+ "const `{}` is not a member of trait `{}`" ,
236
+ const_,
237
+ trait_) ;
238
+ } ,
223
239
ResolutionError :: VariableNotBoundInPattern ( variable_name, pattern_number) => {
224
240
span_err ! ( resolver. session, span, E0408 ,
225
241
"variable `{}` from pattern #1 is not bound in pattern #{}" ,
@@ -2385,10 +2401,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2385
2401
for impl_item in impl_items {
2386
2402
match impl_item. node {
2387
2403
ConstImplItem ( ..) => {
2388
- // If this is a trait impl, ensure the method
2404
+ // If this is a trait impl, ensure the const
2389
2405
// exists in trait
2390
2406
this. check_trait_item ( impl_item. ident . name ,
2391
- impl_item. span ) ;
2407
+ impl_item. span ,
2408
+ |n, s| ResolutionError :: ConstNotMemberOfTrait ( n, s) ) ;
2392
2409
this. with_constant_rib ( |this| {
2393
2410
visit:: walk_impl_item ( this, impl_item) ;
2394
2411
} ) ;
@@ -2397,7 +2414,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2397
2414
// If this is a trait impl, ensure the method
2398
2415
// exists in trait
2399
2416
this. check_trait_item ( impl_item. ident . name ,
2400
- impl_item. span ) ;
2417
+ impl_item. span ,
2418
+ |n, s| ResolutionError :: MethodNotMemberOfTrait ( n, s) ) ;
2401
2419
2402
2420
// We also need a new scope for the method-
2403
2421
// specific type parameters.
@@ -2410,10 +2428,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2410
2428
} ) ;
2411
2429
}
2412
2430
TypeImplItem ( ref ty) => {
2413
- // If this is a trait impl, ensure the method
2431
+ // If this is a trait impl, ensure the type
2414
2432
// exists in trait
2415
2433
this. check_trait_item ( impl_item. ident . name ,
2416
- impl_item. span ) ;
2434
+ impl_item. span ,
2435
+ |n, s| ResolutionError :: TypeNotMemberOfTrait ( n, s) ) ;
2417
2436
2418
2437
this. visit_ty ( ty) ;
2419
2438
}
@@ -2426,15 +2445,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2426
2445
} ) ;
2427
2446
}
2428
2447
2429
- fn check_trait_item ( & self , name : Name , span : Span ) {
2448
+ fn check_trait_item < F > ( & self , name : Name , span : Span , err : F )
2449
+ where F : FnOnce ( Name , & str ) -> ResolutionError {
2430
2450
// If there is a TraitRef in scope for an impl, then the method must be in the trait.
2431
2451
if let Some ( ( did, ref trait_ref) ) = self . current_trait_ref {
2432
2452
if !self . trait_item_map . contains_key ( & ( name, did) ) {
2433
2453
let path_str = path_names_to_string ( & trait_ref. path , 0 ) ;
2434
2454
resolve_error ( self ,
2435
2455
span,
2436
- ResolutionError :: MethodNotMemberOfTrait ( name,
2437
- & * path_str) ) ;
2456
+ err ( name, & * path_str) ) ;
2438
2457
}
2439
2458
}
2440
2459
}
0 commit comments