@@ -10,8 +10,8 @@ use rustc_hir::{
10
10
def:: { CtorOf , DefKind , Res } ,
11
11
def_id:: LocalDefId ,
12
12
intravisit:: { walk_inf, walk_ty, Visitor } ,
13
- Expr , ExprKind , FnRetTy , FnSig , GenericArg , HirId , Impl , ImplItemKind , Item , ItemKind , Pat , PatKind , Path , QPath ,
14
- TyKind ,
13
+ Expr , ExprKind , FnRetTy , FnSig , GenericArg , GenericParam , GenericParamKind , HirId , Impl , ImplItemKind , Item ,
14
+ ItemKind , Pat , PatKind , Path , QPath , Ty , TyKind ,
15
15
} ;
16
16
use rustc_hir_analysis:: hir_ty_to_ty;
17
17
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
96
96
// avoid linting on nested items, we push `StackItem::NoCheck` on the stack to signal, that
97
97
// we're in an `impl` or nested item, that we don't want to lint
98
98
let stack_item = if_chain ! {
99
- if let ItemKind :: Impl ( Impl { self_ty, .. } ) = item. kind;
99
+ if let ItemKind :: Impl ( Impl { self_ty, generics , .. } ) = item. kind;
100
100
if let TyKind :: Path ( QPath :: Resolved ( _, item_path) ) = self_ty. kind;
101
101
let parameters = & item_path. segments. last( ) . expect( SEGMENTS_MSG ) . args;
102
102
if parameters. as_ref( ) . map_or( true , |params| {
@@ -105,10 +105,17 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
105
105
if !item. span. from_expansion( ) ;
106
106
if !is_from_proc_macro( cx, item) ; // expensive, should be last check
107
107
then {
108
+ // Self cannot be used inside const generic parameters
109
+ let types_to_skip = generics. params. iter( ) . filter_map( |param| {
110
+ match param {
111
+ GenericParam { kind: GenericParamKind :: Const { ty: Ty { hir_id, ..} , ..} , ..} => Some ( * hir_id) ,
112
+ _ => None ,
113
+ }
114
+ } ) . chain( std:: iter:: once( self_ty. hir_id) ) . collect( ) ;
108
115
StackItem :: Check {
109
116
impl_id: item. owner_id. def_id,
110
117
in_body: 0 ,
111
- types_to_skip: std :: iter :: once ( self_ty . hir_id ) . collect ( ) ,
118
+ types_to_skip,
112
119
}
113
120
} else {
114
121
StackItem :: NoCheck
0 commit comments