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 6 pull requests #115125

Closed
wants to merge 12 commits into from

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

waywardmonkeys and others added 12 commits August 21, 2023 20:00
Automatically add OS labels to std PRs

I'd love to have `library/std/src/sys` PRs that touch Windows stuff to have the `O-windows` label for easier discovery (and rediscovery). While I'm here I added a couple of other auto OS labels. Perhaps `O-unix` is a little too broad but it's hard to be more specific and I think it's still useful insomuch as POSIX is a thing.

r? libs
…d-docs, r=cuviper

docs: Add example, reference link for `type` keyword.

Fixes rust-lang#114281.
…es, r=est31

Add support for `ptr::write`s for the `invalid_reference_casting` lint

This PR adds support for `ptr::write` and others for the `invalid_reference_casting` lint.

Detecting instances where instead of using the deref (`*`) operator to assign someone uses `ptr::write`, `ptr::write_unaligned` or `ptr::write_volatile`.

```rust
let data_len = 5u64;

std::ptr::write(
    std::mem::transmute::<*const u64, *mut u64>(&data_len),
    new_data_len,
);
```

r? `@est31`
…e, r=est31

Improve note for the `invalid_reference_casting` lint

This PR add link to the book interior mutability chapter, https://doc.rust-lang.org/book/ch15-05-interior-mutability.html; this is done to guide peoples to a place with many useful information and context.

*Note that this isn't the first occurrence of a link to the book in [tests outputs](https://github.com/search?q=repo%3Arust-lang%2Frust+book+path%3A%2F%5Etests%5C%2Fui%5C%2F%2F&type=code).*

r? `@est31`
Fix clippy lint for identical `if`/`else` contraining `?` expressions

Follow up to rust-lang#114819.
@rustbot rustbot added A-meta Area: Issues & PRs about the rust-lang/rust repository itself S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Aug 23, 2023
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=6

@bors
Copy link
Contributor

bors commented Aug 23, 2023

📌 Commit e777fd4 has been approved by matthiaskrgr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2023
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-15 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_fd29f66d-df6c-4365-8b40-913fea6b5374
GITHUB_EVENT_NAME=pull_request
GITHUB_EVENT_PATH=/home/runner/work/_temp/_github_workflow/event.json
GITHUB_GRAPHQL_URL=https://api.github.com/graphql
GITHUB_HEAD_REF=rollup-z5by4wq
GITHUB_JOB=pr
GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_fd29f66d-df6c-4365-8b40-913fea6b5374
GITHUB_REF=refs/pull/115125/merge
GITHUB_REF_NAME=115125/merge
GITHUB_REF_PROTECTED=false
---
182    | |_____^
+    |
+    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
183 
184 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`

215 ...
216 LL |     std::ptr::write(value, 2);
217    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
217    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
+    |
+    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
218 
219 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`

224 ...
225 LL |     std::ptr::write_unaligned(value, 2);
226    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
226    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    |
+    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
227 
228 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`

233 ...
234 LL |     std::ptr::write_volatile(value, 2);
235    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
235    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    |
+    = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
236 
237 error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/lint/reference_casting/reference_casting.stderr
---
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lint/reference_casting.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/lint/reference_casting" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/lint/reference_casting/auxiliary"
stdout: none
--- stderr -------------------------------
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(num as *const i32 as *mut i32);
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
   = note: `#[deny(invalid_reference_casting)]` on by default

error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(num as *const i32).cast_mut();
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *std::ptr::from_ref(num).cast_mut();
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *std::ptr::from_ref({ num }).cast_mut();
   |
Build completed unsuccessfully in 0:10:55
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *{ std::ptr::from_ref(num) }.cast_mut();
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(std::ptr::from_ref({ num }) as *mut i32);
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut();
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(num as *const i32).cast::<i32>().cast_mut().cast_const().cast_mut();
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(std::ptr::from_ref(static_u8()) as *mut i32);
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *std::mem::transmute::<_, *mut i32>(num);
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let deferred = num as *const i32 as *mut i32;
   |                    ----------------------------- casting happend here
LL |     let _num = &mut *deferred;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let deferred = (std::ptr::from_ref(num) as *const i32 as *const i32).cast_mut() as *mut i32;
   |                    ---------------------------------------------------------------------------- casting happend here
LL |     let _num = &mut *deferred;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |     let _num = &mut *(num as *const _ as usize as *mut i32);
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
   |
   |
LL |         &mut *((this as *const _) as *mut _)
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *(a as *const _ as *mut _) = String::from("Replaced");
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *(a as *const _ as *mut String) += " world";
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *std::ptr::from_ref(num).cast_mut() += 1;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *std::ptr::from_ref({ num }).cast_mut() += 1;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *{ std::ptr::from_ref(num) }.cast_mut() += 1;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *(std::ptr::from_ref({ num }) as *mut i32) += 1;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *std::mem::transmute::<_, *mut i32>(num) += 1;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
LL | /     std::ptr::write(
LL | /     std::ptr::write(
LL | |     //~^ ERROR assigning to `&T` is undefined behavior
LL | |         std::mem::transmute::<*const i32, *mut i32>(num),
LL | |         -1i32,
   | |_____^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
LL |     let value = num as *const i32 as *mut i32;
   |                 ----------------------------- casting happend here
LL |     *value = 1;
LL |     *value = 1;
   |     ^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *(num as *const i32).cast::<i32>().cast_mut() = 2;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |     *(num as *const _ as usize as *mut i32) = 2;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>


error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
LL |     let value = num as *const i32 as *mut i32;
   |                 ----------------------------- casting happend here
...
...
LL |     std::ptr::write(value, 2);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
LL |     let value = num as *const i32 as *mut i32;
   |                 ----------------------------- casting happend here
...
...
LL |     std::ptr::write_unaligned(value, 2);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
LL |     let value = num as *const i32 as *mut i32;
   |                 ----------------------------- casting happend here
...
...
LL |     std::ptr::write_volatile(value, 2);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>

error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell`
   |
   |
LL |         *(this as *const _ as *mut _) = a;
   |
   = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>

error: aborting due to 29 previous errors

@matthiaskrgr matthiaskrgr deleted the rollup-z5by4wq branch March 16, 2024 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: Issues & PRs about the rust-lang/rust repository itself rollup A PR which is a rollup S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants