Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #129060

Merged
merged 21 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
df27dfa
Optimize integer pow by removing exit branch
mzabaluev Mar 22, 2024
1faa101
Explicitly unroll integer pow for small exponents
mzabaluev Jul 11, 2024
2f23534
Use is_val_statically_known to optimize pow
mzabaluev Jul 12, 2024
1e445f4
Add must_use attribute to Coroutine trait
henryksloan Aug 13, 2024
ac88b33
Revert to original loop for const pow exponents
mzabaluev Aug 13, 2024
399ef23
Allow to customize `// TODO:` comment for deprecated safe autofix
tbu- Jul 17, 2024
811d7dd
`#[deprecated_safe_2024]`: Also use the `// TODO:` hint in the compil…
tbu- Jul 29, 2024
2a000c8
Don't panic on unknown JSON-like output lines
Zalathar Aug 13, 2024
355f264
Remove a confusing comment
Zalathar Aug 13, 2024
53e87d2
Remove duplicated rustdoc ui test
GuillaumeGomez Aug 13, 2024
d2177d9
Emit a warning instead of an error if `--generate-link-to-definition`…
GuillaumeGomez Aug 13, 2024
afbab80
Update rustdoc-ui test for `--generate-link-to-definition` option
GuillaumeGomez Aug 13, 2024
87a4c32
Fix target triple in bootstrap
Kobzol Aug 13, 2024
5082e25
Add mw back to review rotation
michaelwoerister Aug 13, 2024
bc9c31d
Rollup merge of #122884 - mzabaluev:pow-remove-exit-branch, r=Amanieu
matthiaskrgr Aug 13, 2024
f68a28d
Rollup merge of #127857 - tbu-:pr_deprecated_safe_todo, r=petrochenkov
matthiaskrgr Aug 13, 2024
d4f5a89
Rollup merge of #129034 - henryksloan:coroutine-must-use, r=joboet
matthiaskrgr Aug 13, 2024
65054ed
Rollup merge of #129049 - Zalathar:json-like, r=jieyouxu
matthiaskrgr Aug 13, 2024
5ef33d4
Rollup merge of #129050 - GuillaumeGomez:generate-link-to-definition-…
matthiaskrgr Aug 13, 2024
c013e2c
Rollup merge of #129056 - Kobzol:fix-target-triple, r=onur-ozkan
matthiaskrgr Aug 13, 2024
24a46c5
Rollup merge of #129058 - michaelwoerister:mwback082024, r=jackh726
matthiaskrgr Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow to customize // TODO: comment for deprecated safe autofix
Relevant for the deprecation of `CommandExt::before_exit` in #125970.
  • Loading branch information
tbu- committed Aug 13, 2024
commit 399ef23d2bf2b1619d360a87de9b83edf9d99762
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
through unstable paths"
),
rustc_attr!(
rustc_deprecated_safe_2024, Normal, template!(Word), WarnFollowing,
EncodeCrossCrate::Yes,
rustc_deprecated_safe_2024, Normal, template!(List: r#"todo = "...""#),
ErrorFollowing, EncodeCrossCrate::Yes,
"rustc_deprecated_safe_2024 is supposed to be used in libstd only",
),

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@ symbols! {
to_string,
to_string_method,
to_vec,
todo,
todo_macro,
tool_attributes,
tool_lints,
Expand Down
16 changes: 14 additions & 2 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,13 @@ impl Error for VarError {
/// }
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
/// ```
#[rustc_deprecated_safe_2024]
#[cfg_attr(bootstrap, rustc_deprecated_safe_2024)]
#[cfg_attr(
not(bootstrap),
rustc_deprecated_safe_2024(
todo = "Audit that the environment access only happens in single-threaded code."
)
)]
#[stable(feature = "env", since = "1.0.0")]
pub unsafe fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
let (key, value) = (key.as_ref(), value.as_ref());
Expand Down Expand Up @@ -419,7 +425,13 @@ pub unsafe fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
/// }
/// assert!(env::var(key).is_err());
/// ```
#[rustc_deprecated_safe_2024]
#[cfg_attr(bootstrap, rustc_deprecated_safe_2024)]
#[cfg_attr(
not(bootstrap),
rustc_deprecated_safe_2024(
todo = "Audit that the environment access only happens in single-threaded code."
)
)]
#[stable(feature = "env", since = "1.0.0")]
pub unsafe fn remove_var<K: AsRef<OsStr>>(key: K) {
let key = key.as_ref();
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/rust-2024/unsafe-env-suggestion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ note: the lint level is defined here
|
LL | #![deny(deprecated_safe_2024)]
| ^^^^^^^^^^^^^^^^^^^^
help: you can wrap the call in an `unsafe` block if you can guarantee the code is only ever called from single-threaded code
help: you can wrap the call in an `unsafe` block if you can guarantee its unsafe preconditions
|
LL + // TODO: Audit that the environment access only happens in single-threaded code.
LL ~ unsafe { env::set_var("FOO", "BAR") };
Expand All @@ -25,7 +25,7 @@ LL | env::remove_var("FOO");
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see issue #27970 <https://github.com/rust-lang/rust/issues/27970>
help: you can wrap the call in an `unsafe` block if you can guarantee the code is only ever called from single-threaded code
help: you can wrap the call in an `unsafe` block if you can guarantee its unsafe preconditions
|
LL + // TODO: Audit that the environment access only happens in single-threaded code.
LL ~ unsafe { env::remove_var("FOO") };
Expand Down