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,33 @@ 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 ( item. value_str ( ) . expect ( "`#[rustc_deprecated_safe_2024(todo)]` must have a string value" ) ) ;
98+ }
99+ }
100+ None
101+ }
102+
93103 match kind {
94104 // Allow calls to deprecated-safe unsafe functions if the caller is
95105 // from an edition before 2024.
96106 & UnsafeOpKind :: CallToUnsafeFunction ( Some ( id) )
97107 if !span. at_least_rust_2024 ( )
98108 && self . tcx . has_attr ( id, sym:: rustc_deprecated_safe_2024) =>
99109 {
110+ let attr = self . tcx . get_attr ( id, sym:: rustc_deprecated_safe_2024) . unwrap ( ) ;
111+ let suggestion = parse_rustc_deprecated_safe_2024_attr ( attr) ;
112+
100113 let sm = self . tcx . sess . source_map ( ) ;
114+ let suggestion = suggestion. and_then ( |suggestion| {
115+ sm. indentation_before ( span) . map ( |indent| {
116+ format ! ( "{}// TODO: {}\n " , indent, suggestion)
117+ } )
118+ } )
119+ . unwrap_or_default ( ) ;
120+
101121 self . tcx . emit_node_span_lint (
102122 DEPRECATED_SAFE ,
103123 self . hir_context ,
@@ -106,7 +126,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
106126 span,
107127 function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
108128 sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
109- indent : sm . indentation_before ( span ) . unwrap_or_default ( ) ,
129+ start_of_line_suggestion : suggestion ,
110130 start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
111131 left : span. shrink_to_lo ( ) ,
112132 right : span. shrink_to_hi ( ) ,
0 commit comments