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,33 @@ 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 ( item. value_str ( ) . expect ( "`#[rustc_deprecated_safe_2024(todo)]` must have a string value" ) ) ;
98
+ }
99
+ }
100
+ None
101
+ }
102
+
93
103
match kind {
94
104
// Allow calls to deprecated-safe unsafe functions if the caller is
95
105
// from an edition before 2024.
96
106
& UnsafeOpKind :: CallToUnsafeFunction ( Some ( id) )
97
107
if !span. at_least_rust_2024 ( )
98
108
&& self . tcx . has_attr ( id, sym:: rustc_deprecated_safe_2024) =>
99
109
{
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
+
100
113
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
+
101
121
self . tcx . emit_node_span_lint (
102
122
DEPRECATED_SAFE ,
103
123
self . hir_context ,
@@ -106,7 +126,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
106
126
span,
107
127
function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
108
128
sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
109
- indent : sm . indentation_before ( span ) . unwrap_or_default ( ) ,
129
+ start_of_line_suggestion : suggestion ,
110
130
start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
111
131
left : span. shrink_to_lo ( ) ,
112
132
right : span. shrink_to_hi ( ) ,
0 commit comments