@@ -115,6 +115,9 @@ fn check_into_iter_stability<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx
115115 let Some ( into_iterator_def_id) = cx. tcx . get_diagnostic_item ( sym:: IntoIterator ) else {
116116 return ;
117117 } ;
118+ let Some ( into_iter_fn_def_id) = cx. tcx . lang_items ( ) . into_iter_fn ( ) else {
119+ return ;
120+ } ;
118121 if expr. span . from_expansion ( ) {
119122 return ;
120123 } ;
@@ -135,43 +138,30 @@ fn check_into_iter_stability<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx
135138 if trait_ref. def_id != into_iterator_def_id {
136139 continue ;
137140 }
138- let self_ty = generic_args[ param_index as usize ] . expect_ty ( ) ;
139- let Some ( self_ty_adt_def) = self_ty. peel_refs ( ) . ty_adt_def ( ) else {
141+ let self_ty_generic_arg = generic_args[ param_index as usize ] ;
142+ let Ok ( Some ( instance) ) = ty:: Instance :: try_resolve (
143+ cx. tcx ,
144+ cx. typing_env ( ) ,
145+ into_iter_fn_def_id,
146+ cx. tcx . mk_args ( & [ self_ty_generic_arg] ) ,
147+ ) else {
148+ continue ;
149+ } ;
150+ // Does the input type's `IntoIterator` implementation have the
151+ // `rustc_lint_query_instability` attribute on its `into_iter` method?
152+ if !cx. tcx . has_attr ( instance. def_id ( ) , sym:: rustc_lint_query_instability) {
140153 return ;
154+ }
155+ let span = if let Some ( recv) = recv {
156+ if arg_index == 0 { recv. span } else { args[ arg_index - 1 ] . span }
157+ } else {
158+ args[ arg_index] . span
141159 } ;
142- cx. tcx . for_each_relevant_impl ( into_iterator_def_id, self_ty, |impl_id| {
143- let impl_ty = cx. tcx . type_of ( impl_id) . skip_binder ( ) ;
144- let Some ( impl_ty_adt_def) = impl_ty. peel_refs ( ) . ty_adt_def ( ) else {
145- return ;
146- } ;
147- // To reduce false positives, verify that `self_ty` and `impl_ty` refer to the same ADT.
148- if self_ty_adt_def != impl_ty_adt_def {
149- return ;
150- }
151- let Some ( into_iter_item) = cx
152- . tcx
153- . associated_items ( impl_id)
154- . filter_by_name_unhygienic ( sym:: into_iter)
155- . next ( )
156- else {
157- return ;
158- } ;
159- // Does the input type's `IntoIterator` implementation have the
160- // `rustc_lint_query_instability` attribute on its `into_iter` method?
161- if !cx. tcx . has_attr ( into_iter_item. def_id , sym:: rustc_lint_query_instability) {
162- return ;
163- }
164- let span = if let Some ( recv) = recv {
165- if arg_index == 0 { recv. span } else { args[ arg_index - 1 ] . span }
166- } else {
167- args[ arg_index] . span
168- } ;
169- cx. emit_span_lint (
170- POTENTIAL_QUERY_INSTABILITY ,
171- span,
172- QueryInstability { query : cx. tcx . item_name ( into_iter_item. def_id ) } ,
173- ) ;
174- } ) ;
160+ cx. emit_span_lint (
161+ POTENTIAL_QUERY_INSTABILITY ,
162+ span,
163+ QueryInstability { query : cx. tcx . item_name ( instance. def_id ( ) ) } ,
164+ ) ;
175165 }
176166 }
177167}
0 commit comments