Skip to content

Commit 241c8c4

Browse files
committed
pass less context around
1 parent 0c7e26b commit 241c8c4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

compiler/rustc_lint/src/dangling.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_hir::{Expr, ExprKind, LangItem};
2-
use rustc_middle::ty::{self, Ty};
2+
use rustc_middle::ty::{self, Ty, TyCtxt};
33
use rustc_session::{declare_lint, declare_lint_pass};
44
use rustc_span::symbol::sym;
55

@@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
100100
&& matches!(method.ident.name, sym::as_ptr | sym::as_mut_ptr)
101101
&& is_temporary_rvalue(receiver)
102102
&& let ty = cx.typeck_results().expr_ty(receiver)
103-
&& is_interesting(cx, ty)
103+
&& is_interesting(cx.tcx, ty)
104104
{
105105
cx.emit_span_lint(
106106
DANGLING_POINTERS_FROM_TEMPORARIES,
@@ -164,23 +164,22 @@ fn is_temporary_rvalue(expr: &Expr<'_>) -> bool {
164164

165165
// Array, Vec, String, CString, MaybeUninit, Cell, Box<[_]>, Box<str>, Box<CStr>,
166166
// or any of the above in arbitrary many nested Box'es.
167-
fn is_interesting(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
167+
fn is_interesting(tcx: TyCtxt<'_>, ty: Ty<'_>) -> bool {
168168
if ty.is_array() {
169169
true
170170
} else if ty.is_box() {
171171
let inner = ty.boxed_ty();
172172
inner.is_slice()
173173
|| inner.is_str()
174-
|| inner.ty_adt_def().is_some_and(|def| cx.tcx.is_lang_item(def.did(), LangItem::CStr))
175-
|| is_interesting(cx, inner)
174+
|| inner.ty_adt_def().is_some_and(|def| tcx.is_lang_item(def.did(), LangItem::CStr))
175+
|| is_interesting(tcx, inner)
176176
} else if let Some(def) = ty.ty_adt_def() {
177177
for lang_item in [LangItem::String, LangItem::MaybeUninit] {
178-
if cx.tcx.is_lang_item(def.did(), lang_item) {
178+
if tcx.is_lang_item(def.did(), lang_item) {
179179
return true;
180180
}
181181
}
182-
cx.tcx
183-
.get_diagnostic_name(def.did())
182+
tcx.get_diagnostic_name(def.did())
184183
.is_some_and(|name| matches!(name, sym::cstring_type | sym::Vec | sym::Cell))
185184
} else {
186185
false

0 commit comments

Comments
 (0)