Tobias Bucher
811d7dd113
#[deprecated_safe_2024]
: Also use the // TODO:
hint in the compiler error
...
This doesn't work for translated compiler error messages.
2024-08-13 11:32:47 +02:00
Tobias Bucher
399ef23d2b
Allow to customize // TODO:
comment for deprecated safe autofix
...
Relevant for the deprecation of `CommandExt::before_exit` in #125970 .
2024-08-13 11:32:24 +02:00
Matthias Krüger
7d9ed2a864
Rollup merge of #127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors
...
Stabilize unsafe extern blocks (RFC 3484)
# Stabilization report
## Summary
This is a tracking issue for the RFC 3484: Unsafe Extern Blocks
We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](https://github.com/rust-lang/rfcs/pull/3484 ). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use.
RFC: https://github.com/rust-lang/rfcs/pull/3484
Tracking issue: #123743
## What is stabilized
### Summary of stabilization
We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results.
```rust
unsafe extern {
// sqrt (from libm) may be called with any `f64`
pub safe fn sqrt(x: f64) -> f64;
// strlen (from libc) requires a valid pointer,
// so we mark it as being an unsafe fn
pub unsafe fn strlen(p: *const c_char) -> usize;
// this function doesn't say safe or unsafe, so it defaults to unsafe
pub fn free(p: *mut core::ffi::c_void);
pub safe static IMPORTANT_BYTES: [u8; 256];
pub safe static LINES: SyncUnsafeCell<i32>;
}
```
## Tests
The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`.
## History
- https://github.com/rust-lang/rust/pull/124482
- https://github.com/rust-lang/rust/pull/124455
- https://github.com/rust-lang/rust/pull/125077
- https://github.com/rust-lang/rust/pull/125522
- https://github.com/rust-lang/rust/issues/126738
- https://github.com/rust-lang/rust/issues/126749
- https://github.com/rust-lang/rust/issues/126755
- https://github.com/rust-lang/rust/pull/126757
- https://github.com/rust-lang/rust/pull/126758
- https://github.com/rust-lang/rust/issues/126756
- https://github.com/rust-lang/rust/pull/126973
- https://github.com/rust-lang/rust/pull/127535
- https://github.com/rust-lang/rustfmt/pull/6204
## Unresolved questions
I am not aware of any unresolved questions.
2024-08-03 20:51:51 +02:00
Matthias Krüger
cc17ca2414
Rollup merge of #125889 - Nilstrieb:migrate-into-the-future, r=compiler-errors
...
Add migration lint for 2024 prelude additions
This adds the migration lint for the newly ambiguous methods `poll` and `into_future`. When these methods are used on types implementing the respective traits, it will be ambiguous in the future, which can lead to hard errors or behavior changes depending on the exact circumstances.
tracked by #121042
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r? <reviewer name>
-->
r? compiler-errors as the method prober
2024-07-28 13:42:18 +02:00
Nilstrieb
6f662176e7
Add migration lint for 2024 prelude additions
...
This adds the migration lint for the newly ambiguous methods `poll` and
`into_future`. When these methods are used on types implementing the
respective traits, it will be ambiguous in the future, which can lead to
hard errors or behavior changes depending on the exact circumstances.
2024-07-28 11:44:03 +02:00
Santiago Pastorino
8366c7fe9c
Stabilize unsafe extern blocks (RFC 3484)
2024-07-23 00:29:39 -03:00
Trevor Gross
81135a015f
Rollup merge of #125990 - tbu-:pr_unsafe_env_lint_name, r=ehuss
...
Rename `deprecated_safe` lint to `deprecated_safe_2024`
Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`.
Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375 .
r? `@ehuss`
2024-07-22 11:40:19 -05:00
Michael Goulet
2f5a84ea16
Don't allow unsafe statics outside of extern blocks
2024-07-18 18:02:29 -04:00
Tobias Bucher
bf96c56e84
Rename deprecated_safe
lint to deprecated_safe_2024
...
Create a lint group `deprecated_safe` that includes
`deprecated_safe_2024`.
Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375 .
2024-07-17 14:39:56 +02:00
Santiago Pastorino
8b6435d5ce
Add parse fail test using safe trait/impl trait
2024-07-03 12:08:56 -03:00
Matthias Krüger
b2720867f1
Rollup merge of #126973 - chenyukang:yukang-fix-126756-unsafe-suggestion-error, r=spastorino
...
Fix bad replacement for unsafe extern block suggestion
Fixes #126756
r? ``@spastorino``
link #123743
2024-06-26 07:50:21 +02:00
yukang
0addda6578
Fix bad replacement for unsafe extern block suggestion
2024-06-26 08:50:50 +08:00
Nicholas Nethercote
cf0251d92c
Fix a span in parse_ty_bare_fn
.
...
It currently goes one token too far.
Example: line 259 of `tests/ui/abi/compatibility.rs`:
```
test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32);
```
This commit changes the span for the second element from `fn(),` to
`fn()`, i.e. removes the extraneous comma.
2024-06-26 08:23:57 +10:00
carbotaniuman
a23917cfd0
Add hard error and migration lint for unsafe attrs
2024-06-23 19:02:14 -05:00
Santiago Pastorino
22831ed117
Do not allow safe usafe on static and fn items
2024-06-21 09:12:13 -03:00
Tobias Bucher
4f5fb3126f
Add TODO comment to unsafe env modification
...
Addresses https://github.com/rust-lang/rust/pull/124636#issuecomment-2132119534 .
I think that the diff display regresses a little, because it's no longer
showing the `+` to show where the `unsafe {}` is added. I think it's
still fine.
2024-06-12 17:51:18 +02:00
bors
2d28b6384e
Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obk
...
Unsafe extern blocks
This implements RFC 3484.
Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484
This is better reviewed commit by commit.
2024-06-06 08:14:58 +00:00
Tobias Bucher
bb901a114f
Don't trigger unsafe_op_in_unsafe_fn
for deprecated safe fns
...
Fixes #125875 .
2024-06-05 23:44:59 +02:00
Santiago Pastorino
525828d5ee
Add rustfix test for unsafe extern blocks
2024-06-05 09:36:01 -03:00
Santiago Pastorino
be0726c7c1
Add revisions to safe/unsafe on unadorned extern blocks test
2024-06-05 09:36:01 -03:00
Santiago Pastorino
1afc7d716c
Make MISSING_UNSAFE_ON_EXTERN lint emit future compat info with suggestion to prepend unsafe
2024-06-05 09:36:01 -03:00
Santiago Pastorino
0380321e78
Add unsafe_extern_blocks feature flag
2024-06-05 09:35:57 -03:00
Santiago Pastorino
bac72cf7cf
Add safe/unsafe to static inside extern blocks
2024-06-04 14:19:43 -03:00
Santiago Pastorino
b4cbdb7246
Fail when using safe/unsafe items inside unadorned extern blocks
2024-06-04 14:19:43 -03:00
Santiago Pastorino
2a377122dd
Handle safety keyword for extern block inner items
2024-06-04 14:19:42 -03:00
Santiago Pastorino
bbddc9b58f
Allow using unsafe on functions inside extern blocks
2024-06-04 14:19:42 -03:00
Santiago Pastorino
3ba8de0b60
Make extern blocks without unsafe warn in edition 2024
2024-06-04 14:19:42 -03:00
Santiago Pastorino
46cd80b691
Test that unsafe extern defines unsafe fns
2024-06-04 14:19:42 -03:00
Santiago Pastorino
6d670b74e5
Allow unsafe extern on all editions
2024-06-04 14:19:42 -03:00
Santiago Pastorino
68b0b86c5b
Add unsafe extern blocks failing tests
2024-06-04 14:19:41 -03:00
Tobias Bucher
44f9f8bc33
Add deprecated_safe
lint
...
It warns about usages of `std::env::{set_var, remove_var}` with an
automatic fix wrapping the call in an `unsafe` block.
2024-05-30 00:20:48 +02:00
Tobias Bucher
5d8f9b4dc1
Make std::env::{set_var, remove_var}
unsafe in edition 2024
...
Allow calling these functions without `unsafe` blocks in editions up
until 2021, but don't trigger the `unused_unsafe` lint for `unsafe`
blocks containing these functions.
Fixes #27970 .
Fixes #90308 .
CC #124866 .
2024-05-29 23:42:27 +02:00
Michael Goulet
bc6b70f1d1
Adjust the method ambiguity lint too
2024-05-20 19:21:38 -04:00
Michael Goulet
1d9d6715ae
Make sure we don't deny macro vars w keyword names
2024-05-07 19:13:33 -04:00
Michael Goulet
7789874e6e
Deny gen keyword in edition_2024_compat lints
2024-04-22 11:51:50 -04:00
Nilstrieb
bd8a1a417a
Add Future
and IntoFuture
to the 2024 prelude
...
Implements RFC 3509.
2024-02-18 23:20:05 +01:00