@@ -133,10 +133,11 @@ impl DanglingPointerSearcher<'_, '_> {
133
133
134
134
fn lint_expr ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) {
135
135
if let ExprKind :: MethodCall ( method, receiver, _args, _span) = expr. kind
136
- && matches ! ( method. ident. name, sym:: as_ptr | sym:: as_mut_ptr)
136
+ && let Some ( fn_id) = cx. typeck_results ( ) . type_dependent_def_id ( expr. hir_id )
137
+ && cx. tcx . has_attr ( fn_id, sym:: rustc_as_ptr)
137
138
&& is_temporary_rvalue ( receiver)
138
139
&& let ty = cx. typeck_results ( ) . expr_ty ( receiver)
139
- && is_interesting ( cx. tcx , ty)
140
+ && owns_allocation ( cx. tcx , ty)
140
141
{
141
142
// FIXME: use `emit_node_lint` when `#[primary_span]` is added.
142
143
cx. tcx . emit_node_span_lint (
@@ -201,14 +202,14 @@ fn is_temporary_rvalue(expr: &Expr<'_>) -> bool {
201
202
202
203
// Array, Vec, String, CString, MaybeUninit, Cell, Box<[_]>, Box<str>, Box<CStr>,
203
204
// or any of the above in arbitrary many nested Box'es.
204
- fn is_interesting ( tcx : TyCtxt < ' _ > , ty : Ty < ' _ > ) -> bool {
205
+ fn owns_allocation ( tcx : TyCtxt < ' _ > , ty : Ty < ' _ > ) -> bool {
205
206
if ty. is_array ( ) {
206
207
true
207
208
} else if let Some ( inner) = ty. boxed_ty ( ) {
208
209
inner. is_slice ( )
209
210
|| inner. is_str ( )
210
211
|| inner. ty_adt_def ( ) . is_some_and ( |def| tcx. is_lang_item ( def. did ( ) , LangItem :: CStr ) )
211
- || is_interesting ( tcx, inner)
212
+ || owns_allocation ( tcx, inner)
212
213
} else if let Some ( def) = ty. ty_adt_def ( ) {
213
214
for lang_item in [ LangItem :: String , LangItem :: MaybeUninit ] {
214
215
if tcx. is_lang_item ( def. did ( ) , lang_item) {
0 commit comments