@@ -20,6 +20,7 @@ use rustc::util::nodemap::{FxHashSet, FxHashMap};
20
20
use rustc:: middle:: lang_items;
21
21
22
22
use syntax:: ast;
23
+ use syntax:: feature_gate:: { self , GateIssue } ;
23
24
use syntax_pos:: Span ;
24
25
use errors:: DiagnosticBuilder ;
25
26
@@ -481,18 +482,26 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
481
482
if let Ok ( InferOk { obligations, value : ( ) } ) = eq ( self_ty, potential_self_ty) {
482
483
fcx. register_predicates ( obligations) ;
483
484
autoderef. finalize ( ) ;
484
- break ;
485
+ break
485
486
}
486
487
487
488
} else {
488
- span_err ! ( fcx. tcx. sess, span, E0307 , "invalid `self` type: {:?}" , self_arg_ty) ;
489
- return ;
489
+ fcx. tcx . sess . diagnostic ( ) . mut_span_err ( span, & format ! ( "invalid `self` type: {:?}" , self_arg_ty) )
490
+ . note ( & format ! ( "type must be `{:?}` or a type that dereferences to it`" , self_ty) )
491
+ . help ( "consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`" )
492
+ . code ( "E0307" . into ( ) )
493
+ . emit ( ) ;
494
+ return
490
495
}
491
496
}
492
497
493
498
if let ExplicitSelf :: Other = ExplicitSelf :: determine ( fcx, fcx. param_env , self_ty, self_arg_ty) {
494
499
if !fcx. tcx . sess . features . borrow ( ) . arbitrary_self_types {
495
- fcx. tcx . sess . span_err ( span, "Arbitrary `self` types are experimental" ) ;
500
+ feature_gate:: feature_err ( & fcx. tcx . sess . parse_sess , "arbitrary_self_types" , span,
501
+ GateIssue :: Language , "arbitrary `self` types are unstable" )
502
+ . help ( "consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`" )
503
+ . emit ( ) ;
504
+ return
496
505
}
497
506
}
498
507
}
0 commit comments