1
1
use crate :: build:: ExprCategory ;
2
2
use crate :: errors:: * ;
3
3
4
+ use rustc_ast:: Attribute ;
4
5
use rustc_errors:: DiagArgValue ;
5
6
use rustc_hir:: def:: DefKind ;
6
7
use rustc_hir:: { self as hir, BindingMode , ByRef , HirId , Mutability } ;
@@ -90,14 +91,37 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
90
91
}
91
92
92
93
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
+
93
107
match kind {
94
108
// Allow calls to deprecated-safe unsafe functions if the caller is
95
109
// from an edition before 2024.
96
110
& UnsafeOpKind :: CallToUnsafeFunction ( Some ( id) )
97
111
if !span. at_least_rust_2024 ( )
98
112
&& self . tcx . has_attr ( id, sym:: rustc_deprecated_safe_2024) =>
99
113
{
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
+
100
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
+
101
125
self . tcx . emit_node_span_lint (
102
126
DEPRECATED_SAFE ,
103
127
self . hir_context ,
@@ -106,7 +130,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
106
130
span,
107
131
function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
108
132
sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
109
- indent : sm . indentation_before ( span ) . unwrap_or_default ( ) ,
133
+ start_of_line_suggestion : suggestion ,
110
134
start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
111
135
left : span. shrink_to_lo ( ) ,
112
136
right : span. shrink_to_hi ( ) ,
0 commit comments