diff options
Diffstat (limited to 'compiler/rustc_lint/src/dangling.rs')
| -rw-r--r-- | compiler/rustc_lint/src/dangling.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/dangling.rs b/compiler/rustc_lint/src/dangling.rs index a34c3e26778..09fe709e845 100644 --- a/compiler/rustc_lint/src/dangling.rs +++ b/compiler/rustc_lint/src/dangling.rs @@ -133,10 +133,11 @@ impl DanglingPointerSearcher<'_, '_> { fn lint_expr(cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::MethodCall(method, receiver, _args, _span) = expr.kind - && matches!(method.ident.name, sym::as_ptr | sym::as_mut_ptr) + && let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) + && cx.tcx.has_attr(fn_id, sym::rustc_as_ptr) && is_temporary_rvalue(receiver) && let ty = cx.typeck_results().expr_ty(receiver) - && is_interesting(cx.tcx, ty) + && owns_allocation(cx.tcx, ty) { // FIXME: use `emit_node_lint` when `#[primary_span]` is added. cx.tcx.emit_node_span_lint( @@ -201,14 +202,14 @@ fn is_temporary_rvalue(expr: &Expr<'_>) -> bool { // Array, Vec, String, CString, MaybeUninit, Cell, Box<[_]>, Box<str>, Box<CStr>, // or any of the above in arbitrary many nested Box'es. -fn is_interesting(tcx: TyCtxt<'_>, ty: Ty<'_>) -> bool { +fn owns_allocation(tcx: TyCtxt<'_>, ty: Ty<'_>) -> bool { if ty.is_array() { true } else if let Some(inner) = ty.boxed_ty() { inner.is_slice() || inner.is_str() || inner.ty_adt_def().is_some_and(|def| tcx.is_lang_item(def.did(), LangItem::CStr)) - || is_interesting(tcx, inner) + || owns_allocation(tcx, inner) } else if let Some(def) = ty.ty_adt_def() { for lang_item in [LangItem::String, LangItem::MaybeUninit] { if tcx.is_lang_item(def.did(), lang_item) { |
