@@ -19,7 +19,6 @@ use hir::def::Def;
19
19
use hir:: def_id:: DefId ;
20
20
use middle:: resolve_lifetime as rl;
21
21
use namespace:: Namespace ;
22
- use rustc:: infer:: InferCtxt ;
23
22
use rustc:: ty:: subst:: { Kind , Subst , Substs } ;
24
23
use rustc:: traits;
25
24
use rustc:: ty:: { self , Ty , TyCtxt , ToPredicate , TypeFoldable } ;
@@ -1415,9 +1414,10 @@ pub enum ExplicitSelf<'tcx> {
1415
1414
impl < ' tcx > ExplicitSelf < ' tcx > {
1416
1415
/// Categorizes an explicit self declaration like `self: SomeType`
1417
1416
/// into either `self`, `&self`, `&mut self`, `Box<self>`, or
1418
- /// `Other` (meaning the arbitrary_self_types feature is used).
1419
- /// We do this here via a combination of pattern matching and
1420
- /// `can_eq`. A more precise check is done in `check_method_receiver()`.
1417
+ /// `Other`.
1418
+ /// This is mainly used to require the arbitrary_self_types feature
1419
+ /// in the case of `Other`, to improve error messages in the common cases,
1420
+ /// and to make `Other` non-object-safe.
1421
1421
///
1422
1422
/// Examples:
1423
1423
///
@@ -1436,21 +1436,19 @@ impl<'tcx> ExplicitSelf<'tcx> {
1436
1436
/// }
1437
1437
/// ```
1438
1438
///
1439
- pub fn determine < ' a , ' gcx > (
1440
- infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
1441
- param_env : ty:: ParamEnv < ' tcx > ,
1442
- self_ty : Ty < ' tcx > ,
1443
- self_arg_ty : Ty < ' tcx >
1439
+ pub fn determine < ' a , ' gcx , P > (
1440
+ self_arg_ty : Ty < ' tcx > ,
1441
+ is_self_ty : P
1444
1442
) -> ExplicitSelf < ' tcx >
1443
+ where
1444
+ P : Fn ( Ty < ' tcx > ) -> bool
1445
1445
{
1446
1446
use self :: ExplicitSelf :: * ;
1447
1447
1448
- let can_eq = |expected, actual| infcx. can_eq ( param_env, expected, actual) . is_ok ( ) ;
1449
-
1450
1448
match self_arg_ty. sty {
1451
- _ if can_eq ( self_arg_ty, self_ty ) => ByValue ,
1452
- ty:: TyRef ( region, ty:: TypeAndMut { ty, mutbl} ) if can_eq ( ty, self_ty ) => ByReference ( region, mutbl) ,
1453
- ty:: TyAdt ( def, _) if def. is_box ( ) && can_eq ( self_arg_ty. boxed_ty ( ) , self_ty ) => ByBox ,
1449
+ _ if is_self_ty ( self_arg_ty) => ByValue ,
1450
+ ty:: TyRef ( region, ty:: TypeAndMut { ty, mutbl} ) if is_self_ty ( ty) => ByReference ( region, mutbl) ,
1451
+ ty:: TyAdt ( def, _) if def. is_box ( ) && is_self_ty ( self_arg_ty. boxed_ty ( ) ) => ByBox ,
1454
1452
_ => Other
1455
1453
}
1456
1454
}
0 commit comments