@@ -26,8 +26,8 @@ use rustc_lint::{LateContext, LateLintPass};
26
26
use rustc_middle:: mir:: { Rvalue , StatementKind } ;
27
27
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
28
28
use 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 ,
31
31
} ;
32
32
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
33
33
use rustc_span:: { symbol:: sym, Span , Symbol } ;
@@ -357,15 +357,17 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
357
357
// start auto-deref.
358
358
// 4. If the chain of non-user-defined derefs ends with a mutable re-borrow, and re-borrow
359
359
// 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
+ // ```
369
371
let deref_msg =
370
372
"this expression creates a reference which is immediately dereferenced by the compiler" ;
371
373
let borrow_msg = "this expression borrows a value the compiler would automatically borrow" ;
@@ -1135,7 +1137,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
1135
1137
let projection_predicates = predicates
1136
1138
. iter ( )
1137
1139
. 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 ( ) {
1139
1141
Some ( projection_predicate)
1140
1142
} else {
1141
1143
None
@@ -1149,7 +1151,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
1149
1151
if predicates
1150
1152
. iter ( )
1151
1153
. 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 ( )
1153
1155
&& trait_predicate. trait_ref . self_ty ( ) == param_ty. to_ty ( cx. tcx )
1154
1156
{
1155
1157
Some ( trait_predicate. trait_ref . def_id )
@@ -1211,7 +1213,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
1211
1213
}
1212
1214
1213
1215
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 ( )
1215
1217
&& cx. tcx . is_diagnostic_item ( sym:: IntoIterator , trait_predicate. trait_ref . def_id )
1216
1218
&& let ty:: Param ( param_ty) = trait_predicate. self_ty ( ) . kind ( )
1217
1219
&& let GenericArgKind :: Type ( ty) = substs_with_referent_ty[ param_ty. index as usize ] . unpack ( )
@@ -1426,6 +1428,7 @@ fn ty_auto_deref_stability<'tcx>(
1426
1428
continue ;
1427
1429
} ,
1428
1430
ty:: Param ( _) => TyPosition :: new_deref_stable_for_result ( precedence, ty) ,
1431
+ ty:: Alias ( ty:: Weak , _) => unreachable ! ( "should have been normalized away above" ) ,
1429
1432
ty:: Alias ( ty:: Inherent , _) => unreachable ! ( "inherent projection should have been normalized away above" ) ,
1430
1433
ty:: Alias ( ty:: Projection , _) if ty. has_non_region_param ( ) => {
1431
1434
TyPosition :: new_deref_stable_for_result ( precedence, ty)
0 commit comments