@@ -84,10 +84,10 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY, UNTRACKED_QUE
84
84
85
85
impl < ' tcx > LateLintPass < ' tcx > for QueryStability {
86
86
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
87
- if let Some ( ( def_id , span, generic_args, _recv, _args) ) =
87
+ if let Some ( ( callee_def_id , span, generic_args, _recv, _args) ) =
88
88
get_callee_span_generic_args_and_args ( cx, expr)
89
89
&& let Ok ( Some ( instance) ) =
90
- ty:: Instance :: try_resolve ( cx. tcx , cx. typing_env ( ) , def_id , generic_args)
90
+ ty:: Instance :: try_resolve ( cx. tcx , cx. typing_env ( ) , callee_def_id , generic_args)
91
91
{
92
92
let def_id = instance. def_id ( ) ;
93
93
if cx. tcx . has_attr ( def_id, sym:: rustc_lint_query_instability) {
@@ -96,6 +96,13 @@ impl<'tcx> LateLintPass<'tcx> for QueryStability {
96
96
span,
97
97
QueryInstability { query : cx. tcx . item_name ( def_id) } ,
98
98
) ;
99
+ } else if has_unstable_into_iter_predicate ( cx, callee_def_id, generic_args) {
100
+ let call_span = span. with_hi ( expr. span . hi ( ) ) ;
101
+ cx. emit_span_lint (
102
+ POTENTIAL_QUERY_INSTABILITY ,
103
+ call_span,
104
+ QueryInstability { query : sym:: into_iter } ,
105
+ ) ;
99
106
}
100
107
if cx. tcx . has_attr ( def_id, sym:: rustc_lint_untracked_query_information) {
101
108
cx. emit_span_lint (
@@ -105,25 +112,19 @@ impl<'tcx> LateLintPass<'tcx> for QueryStability {
105
112
) ;
106
113
}
107
114
}
108
- check_into_iter_stability ( cx, expr) ;
109
115
}
110
116
}
111
117
112
- fn check_into_iter_stability < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
118
+ fn has_unstable_into_iter_predicate < ' tcx > (
119
+ cx : & LateContext < ' tcx > ,
120
+ callee_def_id : DefId ,
121
+ generic_args : GenericArgsRef < ' tcx > ,
122
+ ) -> bool {
113
123
let Some ( into_iterator_def_id) = cx. tcx . get_diagnostic_item ( sym:: IntoIterator ) else {
114
- return ;
124
+ return false ;
115
125
} ;
116
126
let Some ( into_iter_fn_def_id) = cx. tcx . lang_items ( ) . into_iter_fn ( ) else {
117
- return ;
118
- } ;
119
- if expr. span . from_expansion ( ) {
120
- return ;
121
- } ;
122
- // Is `expr` a function or method call?
123
- let Some ( ( callee_def_id, span, generic_args, _recv, _args) ) =
124
- get_callee_span_generic_args_and_args ( cx, expr)
125
- else {
126
- return ;
127
+ return false ;
127
128
} ;
128
129
let predicates = cx. tcx . predicates_of ( callee_def_id) . instantiate ( cx. tcx , generic_args) ;
129
130
for ( predicate, _) in predicates {
@@ -143,16 +144,11 @@ fn check_into_iter_stability<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx
143
144
} ;
144
145
// Does the input type's `IntoIterator` implementation have the
145
146
// `rustc_lint_query_instability` attribute on its `into_iter` method?
146
- if ! cx. tcx . has_attr ( instance. def_id ( ) , sym:: rustc_lint_query_instability) {
147
- return ;
147
+ if cx. tcx . has_attr ( instance. def_id ( ) , sym:: rustc_lint_query_instability) {
148
+ return true ;
148
149
}
149
- let span = span. with_hi ( expr. span . hi ( ) ) ;
150
- cx. emit_span_lint (
151
- POTENTIAL_QUERY_INSTABILITY ,
152
- span,
153
- QueryInstability { query : cx. tcx . item_name ( instance. def_id ( ) ) } ,
154
- ) ;
155
150
}
151
+ false
156
152
}
157
153
158
154
/// Checks whether an expression is a function or method call and, if so, returns its `DefId`,
0 commit comments