Skip to content

Commit ba9c93e

Browse files
committed
Address review comment
1 parent cd4f539 commit ba9c93e

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

compiler/rustc_lint/src/internal.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY, UNTRACKED_QUE
8484

8585
impl<'tcx> LateLintPass<'tcx> for QueryStability {
8686
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)) =
8888
get_callee_span_generic_args_and_args(cx, expr)
8989
&& 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)
9191
{
9292
let def_id = instance.def_id();
9393
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
@@ -96,6 +96,13 @@ impl<'tcx> LateLintPass<'tcx> for QueryStability {
9696
span,
9797
QueryInstability { query: cx.tcx.item_name(def_id) },
9898
);
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+
);
99106
}
100107
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
101108
cx.emit_span_lint(
@@ -105,25 +112,19 @@ impl<'tcx> LateLintPass<'tcx> for QueryStability {
105112
);
106113
}
107114
}
108-
check_into_iter_stability(cx, expr);
109115
}
110116
}
111117

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 {
113123
let Some(into_iterator_def_id) = cx.tcx.get_diagnostic_item(sym::IntoIterator) else {
114-
return;
124+
return false;
115125
};
116126
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;
127128
};
128129
let predicates = cx.tcx.predicates_of(callee_def_id).instantiate(cx.tcx, generic_args);
129130
for (predicate, _) in predicates {
@@ -143,16 +144,11 @@ fn check_into_iter_stability<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx
143144
};
144145
// Does the input type's `IntoIterator` implementation have the
145146
// `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;
148149
}
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-
);
155150
}
151+
false
156152
}
157153

158154
/// Checks whether an expression is a function or method call and, if so, returns its `DefId`,

0 commit comments

Comments
 (0)