4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
97
97
if !span. at_least_rust_2024 ( )
98
98
&& self . tcx . has_attr ( id, sym:: rustc_deprecated_safe_2024) =>
99
99
{
100
+ let sm = self . tcx . sess . source_map ( ) ;
100
101
self . tcx . emit_node_span_lint (
101
102
DEPRECATED_SAFE ,
102
103
self . hir_context ,
@@ -105,6 +106,8 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
105
106
span,
106
107
function : with_no_trimmed_paths ! ( self . tcx. def_path_str( id) ) ,
107
108
sub : CallToDeprecatedSafeFnRequiresUnsafeSub {
109
+ indent : sm. indentation_before ( span) . unwrap_or_default ( ) ,
110
+ start_of_line : sm. span_extend_to_line ( span) . shrink_to_lo ( ) ,
108
111
left : span. shrink_to_lo ( ) ,
109
112
right : span. shrink_to_hi ( ) ,
110
113
} ,
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafe {
33
33
#[ derive( Subdiagnostic ) ]
34
34
#[ multipart_suggestion( mir_build_suggestion, applicability = "machine-applicable" ) ]
35
35
pub ( crate ) struct CallToDeprecatedSafeFnRequiresUnsafeSub {
36
+ pub ( crate ) indent : String ,
37
+ #[ suggestion_part(
38
+ code = "{indent}// TODO: Audit that the environment access only happens in single-threaded code.\n " // ignore-tidy-todo
39
+ ) ]
40
+ pub ( crate ) start_of_line : Span ,
36
41
#[ suggestion_part( code = "unsafe {{ " ) ]
37
42
pub ( crate ) left : Span ,
38
43
#[ suggestion_part( code = " }}" ) ]
Original file line number Diff line number Diff line change @@ -6,9 +6,11 @@ use std::env;
6
6
7
7
#[deny(unused_unsafe)]
8
8
fn main() {
9
+ // TODO: Audit that the environment access only happens in single-threaded code.
9
10
unsafe { env::set_var("FOO", "BAR") };
10
11
//~^ ERROR call to deprecated safe function
11
12
//~| WARN this is accepted in the current edition
13
+ // TODO: Audit that the environment access only happens in single-threaded code.
12
14
unsafe { env::remove_var("FOO") };
13
15
//~^ ERROR call to deprecated safe function
14
16
//~| WARN this is accepted in the current edition
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ LL | #![deny(deprecated_safe)]
13
13
| ^^^^^^^^^^^^^^^
14
14
help: you can wrap the call in an `unsafe` block if you can guarantee the code is only ever called from single-threaded code
15
15
|
16
- LL | unsafe { env::set_var("FOO", "BAR") };
17
- | ++++++++ +
16
+ LL + // TODO: Audit that the environment access only happens in single-threaded code.
17
+ LL ~ unsafe { env::set_var("FOO", "BAR") };
18
+ |
18
19
19
20
error: call to deprecated safe function `std::env::remove_var` is unsafe and requires unsafe block
20
21
--> $DIR/unsafe-env-suggestion.rs:12:5
@@ -26,8 +27,9 @@ LL | env::remove_var("FOO");
26
27
= note: for more information, see issue #27970 <https://github.com/rust-lang/rust/issues/27970>
27
28
help: you can wrap the call in an `unsafe` block if you can guarantee the code is only ever called from single-threaded code
28
29
|
29
- LL | unsafe { env::remove_var("FOO") };
30
- | ++++++++ +
30
+ LL + // TODO: Audit that the environment access only happens in single-threaded code.
31
+ LL ~ unsafe { env::remove_var("FOO") };
32
+ |
31
33
32
34
error: aborting due to 2 previous errors
33
35
0 commit comments