|
1 | 1 | use rustc_hir::{Expr, ExprKind, LangItem};
|
2 |
| -use rustc_middle::ty::{self, Ty}; |
| 2 | +use rustc_middle::ty::{self, Ty, TyCtxt}; |
3 | 3 | use rustc_session::{declare_lint, declare_lint_pass};
|
4 | 4 | use rustc_span::symbol::sym;
|
5 | 5 |
|
@@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for DanglingPointers {
|
100 | 100 | && matches!(method.ident.name, sym::as_ptr | sym::as_mut_ptr)
|
101 | 101 | && is_temporary_rvalue(receiver)
|
102 | 102 | && let ty = cx.typeck_results().expr_ty(receiver)
|
103 |
| - && is_interesting(cx, ty) |
| 103 | + && is_interesting(cx.tcx, ty) |
104 | 104 | {
|
105 | 105 | cx.emit_span_lint(
|
106 | 106 | DANGLING_POINTERS_FROM_TEMPORARIES,
|
@@ -164,23 +164,22 @@ fn is_temporary_rvalue(expr: &Expr<'_>) -> bool {
|
164 | 164 |
|
165 | 165 | // Array, Vec, String, CString, MaybeUninit, Cell, Box<[_]>, Box<str>, Box<CStr>,
|
166 | 166 | // 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 { |
168 | 168 | if ty.is_array() {
|
169 | 169 | true
|
170 | 170 | } else if ty.is_box() {
|
171 | 171 | let inner = ty.boxed_ty();
|
172 | 172 | inner.is_slice()
|
173 | 173 | || 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) |
176 | 176 | } else if let Some(def) = ty.ty_adt_def() {
|
177 | 177 | 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) { |
179 | 179 | return true;
|
180 | 180 | }
|
181 | 181 | }
|
182 |
| - cx.tcx |
183 |
| - .get_diagnostic_name(def.did()) |
| 182 | + tcx.get_diagnostic_name(def.did()) |
184 | 183 | .is_some_and(|name| matches!(name, sym::cstring_type | sym::Vec | sym::Cell))
|
185 | 184 | } else {
|
186 | 185 | false
|
|
0 commit comments