@@ -26,8 +26,8 @@ use rustc_lint::{LateContext, LateLintPass};
2626use rustc_middle:: mir:: { Rvalue , StatementKind } ;
2727use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
2828use rustc_middle:: ty:: {
29- self , Binder , BoundVariableKind , Clause , EarlyBinder , FnSig , GenericArgKind , List , ParamEnv , ParamTy ,
30- PredicateKind , ProjectionPredicate , Ty , TyCtxt , TypeVisitableExt , TypeckResults ,
29+ self , Binder , BoundVariableKind , ClauseKind , EarlyBinder , FnSig , GenericArgKind , List , ParamEnv , ParamTy ,
30+ ProjectionPredicate , Ty , TyCtxt , TypeVisitableExt , TypeckResults ,
3131} ;
3232use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
3333use rustc_span:: { symbol:: sym, Span , Symbol } ;
@@ -357,15 +357,17 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
357357 // start auto-deref.
358358 // 4. If the chain of non-user-defined derefs ends with a mutable re-borrow, and re-borrow
359359 // adjustments will not be inserted automatically, then leave one further reference to avoid
360- // moving a mutable borrow.
361- // e.g.
362- // fn foo<T>(x: &mut Option<&mut T>, y: &mut T) {
363- // let x = match x {
364- // // Removing the borrow will cause `x` to be moved
365- // Some(x) => &mut *x,
366- // None => y
367- // };
368- // }
360+ // moving a mutable borrow. e.g.
361+ //
362+ // ```rust
363+ // fn foo<T>(x: &mut Option<&mut T>, y: &mut T) {
364+ // let x = match x {
365+ // // Removing the borrow will cause `x` to be moved
366+ // Some(x) => &mut *x,
367+ // None => y
368+ // };
369+ // }
370+ // ```
369371 let deref_msg =
370372 "this expression creates a reference which is immediately dereferenced by the compiler" ;
371373 let borrow_msg = "this expression borrows a value the compiler would automatically borrow" ;
@@ -1135,7 +1137,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11351137 let projection_predicates = predicates
11361138 . iter ( )
11371139 . filter_map ( |predicate| {
1138- if let PredicateKind :: Clause ( Clause :: Projection ( projection_predicate) ) = predicate. kind ( ) . skip_binder ( ) {
1140+ if let ClauseKind :: Projection ( projection_predicate) = predicate. kind ( ) . skip_binder ( ) {
11391141 Some ( projection_predicate)
11401142 } else {
11411143 None
@@ -1149,7 +1151,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
11491151 if predicates
11501152 . iter ( )
11511153 . filter_map ( |predicate| {
1152- if let PredicateKind :: Clause ( Clause :: Trait ( trait_predicate) ) = predicate. kind ( ) . skip_binder ( )
1154+ if let ClauseKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
11531155 && trait_predicate. trait_ref . self_ty ( ) == param_ty. to_ty ( cx. tcx )
11541156 {
11551157 Some ( trait_predicate. trait_ref . def_id )
@@ -1211,7 +1213,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
12111213 }
12121214
12131215 predicates. iter ( ) . all ( |predicate| {
1214- if let PredicateKind :: Clause ( Clause :: Trait ( trait_predicate) ) = predicate. kind ( ) . skip_binder ( )
1216+ if let ClauseKind :: Trait ( trait_predicate) = predicate. kind ( ) . skip_binder ( )
12151217 && cx. tcx . is_diagnostic_item ( sym:: IntoIterator , trait_predicate. trait_ref . def_id )
12161218 && let ty:: Param ( param_ty) = trait_predicate. self_ty ( ) . kind ( )
12171219 && let GenericArgKind :: Type ( ty) = substs_with_referent_ty[ param_ty. index as usize ] . unpack ( )
@@ -1426,6 +1428,7 @@ fn ty_auto_deref_stability<'tcx>(
14261428 continue ;
14271429 } ,
14281430 ty:: Param ( _) => TyPosition :: new_deref_stable_for_result ( precedence, ty) ,
1431+ ty:: Alias ( ty:: Weak , _) => unreachable ! ( "should have been normalized away above" ) ,
14291432 ty:: Alias ( ty:: Inherent , _) => unreachable ! ( "inherent projection should have been normalized away above" ) ,
14301433 ty:: Alias ( ty:: Projection , _) if ty. has_non_region_param ( ) => {
14311434 TyPosition :: new_deref_stable_for_result ( precedence, ty)
0 commit comments