11use crate :: build:: ExprCategory ;
22use crate :: errors:: * ;
33
4+ use rustc_ast:: Attribute ;
45use rustc_errors:: DiagArgValue ;
56use rustc_hir:: def:: DefKind ;
67use rustc_hir:: { self as hir, BindingMode , ByRef , HirId , Mutability } ;
@@ -90,14 +91,37 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
9091 }
9192
9293 fn emit_deprecated_safe_fn_call ( & self , span : Span , kind : & UnsafeOpKind ) -> bool {
94+ fn parse_rustc_deprecated_safe_2024_attr ( attr : & Attribute ) -> Option < Symbol > {
95+ for item in attr. meta_item_list ( ) . unwrap_or_default ( ) {
96+ if item. has_name ( sym:: todo) {
97+ return Some (
98+ item. value_str ( ) . expect (
99+ "`#[rustc_deprecated_safe_2024(todo)]` must have a string value" ,
100+ ) ,
101+ ) ;
102+ }
103+ }
104+ None
105+ }
106+
93107 match kind {
94108 // Allow calls to deprecated-safe unsafe functions if the caller is
95109 // from an edition before 2024.
96110 & UnsafeOpKind :: CallToUnsafeFunction ( Some ( id) )
97111 if !span. at_least_rust_2024 ( )
98112 && self . tcx . has_attr ( id, sym:: rustc_deprecated_safe_2024) =>
99113 {
114+ let attr = self . tcx . get_attr ( id, sym:: rustc_deprecated_safe_2024) . unwrap ( ) ;
115+ let suggestion = parse_rustc_deprecated_safe_2024_attr ( attr) ;
116+
100117 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+
101125 self . tcx . emit_node_span_lint (
102126 DEPRECATED_SAFE ,
103127 self . hir_context ,
@@ -106,7 +130,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
106130 span,
107131 function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
108132 sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
109- indent : sm . indentation_before ( span ) . unwrap_or_default ( ) ,
133+ start_of_line_suggestion : suggestion ,
110134 start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
111135 left : span. shrink_to_lo ( ) ,
112136 right : span. shrink_to_hi ( ) ,
0 commit comments