Allow to customize // TODO:
comment for deprecated safe autofix
Relevant for the deprecation of `CommandExt::before_exit` in #125970.
This commit is contained in:
parent
591ecb88df
commit
399ef23d2b
7 changed files with 42 additions and 13 deletions
|
@ -30,7 +30,7 @@ mir_build_call_to_deprecated_safe_fn_requires_unsafe =
|
|||
call to deprecated safe function `{$function}` is unsafe and requires unsafe block
|
||||
.note = consult the function's documentation for information on how to avoid undefined behavior
|
||||
.label = call to unsafe function
|
||||
.suggestion = you can wrap the call in an `unsafe` block if you can guarantee the code is only ever called from single-threaded code
|
||||
.suggestion = you can wrap the call in an `unsafe` block if you can guarantee its unsafe preconditions
|
||||
|
||||
mir_build_call_to_fn_with_requires_unsafe =
|
||||
call to function `{$function}` with `#[target_feature]` is unsafe and requires unsafe block
|
||||
|
|
|
@ -96,9 +96,27 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
|||
// from an edition before 2024.
|
||||
&UnsafeOpKind::CallToUnsafeFunction(Some(id))
|
||||
if !span.at_least_rust_2024()
|
||||
&& self.tcx.has_attr(id, sym::rustc_deprecated_safe_2024) =>
|
||||
&& let Some(attr) = self.tcx.get_attr(id, sym::rustc_deprecated_safe_2024) =>
|
||||
{
|
||||
let suggestion = attr
|
||||
.meta_item_list()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.find(|item| item.has_name(sym::todo))
|
||||
.map(|item| {
|
||||
item.value_str().expect(
|
||||
"`#[rustc_deprecated_safe_2024(todo)]` must have a string value",
|
||||
)
|
||||
});
|
||||
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let suggestion = suggestion
|
||||
.and_then(|suggestion| {
|
||||
sm.indentation_before(span)
|
||||
.map(|indent| format!("{}// TODO: {}\n", indent, suggestion)) // ignore-tidy-todo
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
self.tcx.emit_node_span_lint(
|
||||
DEPRECATED_SAFE_2024,
|
||||
self.hir_context,
|
||||
|
@ -107,7 +125,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
|
|||
span,
|
||||
function: with_no_trimmed_paths!(self.tcx.def_path_str(id)),
|
||||
sub: CallToDeprecatedSafeFnRequiresUnsafeSub {
|
||||
indent: sm.indentation_before(span).unwrap_or_default(),
|
||||
start_of_line_suggestion: suggestion,
|
||||
start_of_line: sm.span_extend_to_line(span).shrink_to_lo(),
|
||||
left: span.shrink_to_lo(),
|
||||
right: span.shrink_to_hi(),
|
||||
|
|
|
@ -35,10 +35,8 @@ pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafe {
|
|||
#[derive(Subdiagnostic)]
|
||||
#[multipart_suggestion(mir_build_suggestion, applicability = "machine-applicable")]
|
||||
pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafeSub {
|
||||
pub(crate) indent: String,
|
||||
#[suggestion_part(
|
||||
code = "{indent}// TODO: Audit that the environment access only happens in single-threaded code.\n" // ignore-tidy-todo
|
||||
)]
|
||||
pub(crate) start_of_line_suggestion: String,
|
||||
#[suggestion_part(code = "{start_of_line_suggestion}")]
|
||||
pub(crate) start_of_line: Span,
|
||||
#[suggestion_part(code = "unsafe {{ ")]
|
||||
pub(crate) left: Span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue