@@ -2,6 +2,7 @@ use std::borrow::Cow;
22use std:: mem;
33use std:: ops:: Bound ;
44
5+ use rustc_ast:: Attribute ;
56use rustc_errors:: DiagArgValue ;
67use rustc_hir:: def:: DefKind ;
78use rustc_hir:: { self as hir, BindingMode , ByRef , HirId , Mutability } ;
@@ -91,14 +92,36 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
9192 }
9293
9394 fn emit_deprecated_safe_fn_call ( & self , span : Span , kind : & UnsafeOpKind ) -> bool {
95+ fn parse_rustc_deprecated_safe_2024_attr ( attr : & Attribute ) -> Option < Symbol > {
96+ for item in attr. meta_item_list ( ) . unwrap_or_default ( ) {
97+ if item. has_name ( sym:: todo) {
98+ return Some (
99+ item. value_str ( ) . expect (
100+ "`#[rustc_deprecated_safe_2024(todo)]` must have a string value" ,
101+ ) ,
102+ ) ;
103+ }
104+ }
105+ None
106+ }
107+
94108 match kind {
95109 // Allow calls to deprecated-safe unsafe functions if the caller is
96110 // from an edition before 2024.
97111 & UnsafeOpKind :: CallToUnsafeFunction ( Some ( id) )
98112 if !span. at_least_rust_2024 ( )
99- && self . tcx . has_attr ( id, sym:: rustc_deprecated_safe_2024) =>
113+ && let Some ( attr ) = self . tcx . get_attr ( id, sym:: rustc_deprecated_safe_2024) =>
100114 {
115+ let suggestion = parse_rustc_deprecated_safe_2024_attr ( attr) ;
116+
101117 let sm = self . tcx . sess . source_map ( ) ;
118+ let suggestion = suggestion
119+ . and_then ( |suggestion| {
120+ sm. indentation_before ( span)
121+ . map ( |indent| format ! ( "{}// TODO: {}\n " , indent, suggestion) ) // ignore-tidy-todo
122+ } )
123+ . unwrap_or_default ( ) ;
124+
102125 self . tcx . emit_node_span_lint (
103126 DEPRECATED_SAFE_2024 ,
104127 self . hir_context ,
@@ -107,7 +130,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
107130 span,
108131 function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
109132 sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
110- indent : sm . indentation_before ( span ) . unwrap_or_default ( ) ,
133+ start_of_line_suggestion : suggestion ,
111134 start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
112135 left : span. shrink_to_lo ( ) ,
113136 right : span. shrink_to_hi ( ) ,
0 commit comments