@@ -2,6 +2,7 @@ use std::borrow::Cow;
2
2
use std:: mem;
3
3
use std:: ops:: Bound ;
4
4
5
+ use rustc_ast:: Attribute ;
5
6
use rustc_errors:: DiagArgValue ;
6
7
use rustc_hir:: def:: DefKind ;
7
8
use rustc_hir:: { self as hir, BindingMode , ByRef , HirId , Mutability } ;
@@ -91,14 +92,36 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
91
92
}
92
93
93
94
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
+
94
108
match kind {
95
109
// Allow calls to deprecated-safe unsafe functions if the caller is
96
110
// from an edition before 2024.
97
111
& UnsafeOpKind :: CallToUnsafeFunction ( Some ( id) )
98
112
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) =>
100
114
{
115
+ let suggestion = parse_rustc_deprecated_safe_2024_attr ( attr) ;
116
+
101
117
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
+
102
125
self . tcx . emit_node_span_lint (
103
126
DEPRECATED_SAFE_2024 ,
104
127
self . hir_context ,
@@ -107,7 +130,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
107
130
span,
108
131
function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
109
132
sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
110
- indent : sm . indentation_before ( span ) . unwrap_or_default ( ) ,
133
+ start_of_line_suggestion : suggestion ,
111
134
start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
112
135
left : span. shrink_to_lo ( ) ,
113
136
right : span. shrink_to_hi ( ) ,
0 commit comments