Skip to content

Commit 811d7dd

Browse files
committed
#[deprecated_safe_2024]: Also use the // TODO: hint in the compiler error
This doesn't work for translated compiler error messages.
1 parent 399ef23 commit 811d7dd

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
643643
through unstable paths"
644644
),
645645
rustc_attr!(
646-
rustc_deprecated_safe_2024, Normal, template!(List: r#"todo = "...""#),
646+
rustc_deprecated_safe_2024, Normal, template!(List: r#"audit_that = "...""#),
647647
ErrorFollowing, EncodeCrossCrate::Yes,
648648
"rustc_deprecated_safe_2024 is supposed to be used in libstd only",
649649
),

compiler/rustc_mir_build/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mir_build_call_to_deprecated_safe_fn_requires_unsafe =
3030
call to deprecated safe function `{$function}` is unsafe and requires unsafe block
3131
.note = consult the function's documentation for information on how to avoid undefined behavior
3232
.label = call to unsafe function
33-
.suggestion = you can wrap the call in an `unsafe` block if you can guarantee its unsafe preconditions
33+
.suggestion = you can wrap the call in an `unsafe` block if you can guarantee {$guarantee}
3434
3535
mir_build_call_to_fn_with_requires_unsafe =
3636
call to function `{$function}` with `#[target_feature]` is unsafe and requires unsafe block

compiler/rustc_mir_build/src/check_unsafety.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,23 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
102102
.meta_item_list()
103103
.unwrap_or_default()
104104
.into_iter()
105-
.find(|item| item.has_name(sym::todo))
105+
.find(|item| item.has_name(sym::audit_that))
106106
.map(|item| {
107107
item.value_str().expect(
108-
"`#[rustc_deprecated_safe_2024(todo)]` must have a string value",
108+
"`#[rustc_deprecated_safe_2024(audit_that)]` must have a string value",
109109
)
110110
});
111111

112112
let sm = self.tcx.sess.source_map();
113+
let guarantee = suggestion
114+
.as_ref()
115+
.map(|suggestion| format!("that {}", suggestion))
116+
.unwrap_or_else(|| String::from("its unsafe preconditions"));
113117
let suggestion = suggestion
114118
.and_then(|suggestion| {
115-
sm.indentation_before(span)
116-
.map(|indent| format!("{}// TODO: {}\n", indent, suggestion)) // ignore-tidy-todo
119+
sm.indentation_before(span).map(|indent| {
120+
format!("{}// TODO: Audit that {}.\n", indent, suggestion) // ignore-tidy-todo
121+
})
117122
})
118123
.unwrap_or_default();
119124

@@ -124,6 +129,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
124129
CallToDeprecatedSafeFnRequiresUnsafe {
125130
span,
126131
function: with_no_trimmed_paths!(self.tcx.def_path_str(id)),
132+
guarantee,
127133
sub: CallToDeprecatedSafeFnRequiresUnsafeSub {
128134
start_of_line_suggestion: suggestion,
129135
start_of_line: sm.span_extend_to_line(span).shrink_to_lo(),

compiler/rustc_mir_build/src/errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafe {
2828
#[label]
2929
pub(crate) span: Span,
3030
pub(crate) function: String,
31+
pub(crate) guarantee: String,
3132
#[subdiagnostic]
3233
pub(crate) sub: CallToDeprecatedSafeFnRequiresUnsafeSub,
3334
}

compiler/rustc_span/src/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ symbols! {
472472
attr,
473473
attr_literals,
474474
attributes,
475+
audit_that,
475476
augmented_assignments,
476477
auto_traits,
477478
automatically_derived,
@@ -1897,7 +1898,6 @@ symbols! {
18971898
to_string,
18981899
to_string_method,
18991900
to_vec,
1900-
todo,
19011901
todo_macro,
19021902
tool_attributes,
19031903
tool_lints,

library/std/src/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl Error for VarError {
359359
#[cfg_attr(
360360
not(bootstrap),
361361
rustc_deprecated_safe_2024(
362-
todo = "Audit that the environment access only happens in single-threaded code."
362+
audit_that = "the environment access only happens in single-threaded code"
363363
)
364364
)]
365365
#[stable(feature = "env", since = "1.0.0")]
@@ -429,7 +429,7 @@ pub unsafe fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
429429
#[cfg_attr(
430430
not(bootstrap),
431431
rustc_deprecated_safe_2024(
432-
todo = "Audit that the environment access only happens in single-threaded code."
432+
audit_that = "the environment access only happens in single-threaded code"
433433
)
434434
)]
435435
#[stable(feature = "env", since = "1.0.0")]

tests/ui/rust-2024/unsafe-env-suggestion.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ note: the lint level is defined here
1111
|
1212
LL | #![deny(deprecated_safe_2024)]
1313
| ^^^^^^^^^^^^^^^^^^^^
14-
help: you can wrap the call in an `unsafe` block if you can guarantee its unsafe preconditions
14+
help: you can wrap the call in an `unsafe` block if you can guarantee that the environment access only happens in single-threaded code
1515
|
1616
LL + // TODO: Audit that the environment access only happens in single-threaded code.
1717
LL ~ unsafe { env::set_var("FOO", "BAR") };
@@ -25,7 +25,7 @@ LL | env::remove_var("FOO");
2525
|
2626
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
2727
= note: for more information, see issue #27970 <https://github.com/rust-lang/rust/issues/27970>
28-
help: you can wrap the call in an `unsafe` block if you can guarantee its unsafe preconditions
28+
help: you can wrap the call in an `unsafe` block if you can guarantee that the environment access only happens in single-threaded code
2929
|
3030
LL + // TODO: Audit that the environment access only happens in single-threaded code.
3131
LL ~ unsafe { env::remove_var("FOO") };

0 commit comments

Comments
 (0)