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

unused_parens now fires on cast expression #110189

Conversation

KisaragiEffective
Copy link
Contributor

@KisaragiEffective KisaragiEffective commented Apr 11, 2023

close rust-lang/rust-clippy#10557.
close rust-lang/rust-clippy#10625.

@llogiq suggested submit PR to solve the issue.

@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2023

⚠️ Warning ⚠️

  • These commits modify submodules.

@rustbot rustbot added 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. labels Apr 11, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 11, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Copy link
Contributor

@b-naber b-naber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but LGTM.

Also you shouldn't have any changes in submodules here.

@rust-log-analyzer

This comment has been minimized.

@KisaragiEffective
Copy link
Contributor Author

KisaragiEffective commented Apr 12, 2023

(force-pushed to drop accidental changes in stdarch submodule)
By the way, this PR makes the lint fire on x86/sse.rs:

https://github.com/rust-lang/stdarch/blob/b655243782c18d3419439daa523782e0818ecf26/crates/core_arch/src/x86/sse.rs#L1375-L1379

should it be fixed in this PR as well as other occurrences?

@KittyBorgX
Copy link
Member

should it be fixed in this PR as well as other occurrences?

@KisaragiEffective I'd suggest doing so if it isn't against the reviewer's descretion since that'll be the only way the CI passes and the compiler builds fully :)

@KisaragiEffective
Copy link
Contributor Author

submitted rust-lang/stdarch#1411, marking this as a draft until it is synced.

@KisaragiEffective KisaragiEffective marked this pull request as draft April 12, 2023 11:19
@rust-log-analyzer

This comment has been minimized.

@KisaragiEffective
Copy link
Contributor Author

It's merged 🚀
Should I update the submodule in this PR or will they become updated eventually? :)

@b-naber
Copy link
Contributor

b-naber commented Apr 13, 2023

I think it points to the master branch on that submodule, so should be fine now. Eh no it doesn't. Yeah I think stdarch would need to be updated for CI to pass. You would need to open a PR like #109359

Can you please squash your commits?

@KisaragiEffective
Copy link
Contributor Author

Can you please squash your commits?

Sure! However, I'd like to rebase (and squash) after stdarch update is landed in order to reduce force-push, so I'll submit another PR first.

@KisaragiEffective
Copy link
Contributor Author

KisaragiEffective commented Apr 13, 2023

submitted #110285, this PR remains to be a draft. Once it has approved and merged, I will rebase and squash commit.

@bors
Copy link
Contributor

bors commented Apr 17, 2023

☔ The latest upstream changes (presumably #110458) made this pull request unmergeable. Please resolve the merge conflicts.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 24, 2023
…Amanieu

stdarch: update submodule

We need [this commit](rust-lang/stdarch@cf3deea) introduced by [stdarch#1411](rust-lang/stdarch#1411) in order to merge rust-lang#110189.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2023
…anieu

stdarch: update submodule

We need [this commit](rust-lang/stdarch@cf3deea) introduced by [stdarch#1411](rust-lang/stdarch#1411) in order to merge rust-lang#110189.

Note to myself: `git pull && git submodule update --remote library/stdarch`
@rust-log-analyzer

This comment has been minimized.

@KisaragiEffective
Copy link
Contributor Author

It looks like another PR to stdarch is needed.

@@ -198,7 +198,7 @@ fn casts() {
assert_eq::<i32>(f32::INFINITY as i32, i32::MAX);
assert_eq::<i32>(f32::NEG_INFINITY as i32, i32::MIN);
assert_eq::<i32>(f32::NAN as i32, 0);
assert_eq::<i32>((-f32::NAN) as i32, 0);
Copy link
Member

@RalfJung RalfJung Jun 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should lint against (-expr) as i32. Looking at -expr as i32 I have no idea whether the as or the - are executed first, and I might care about that (in particular when casting to an unsigned type). (The formatting indicates that - goes first but I don't know if that actually matches how this is parsed.)

Parentheses to disambiguate parsing precedence are a good thing, we should not steer people away from them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agreed :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The diff in the Miri test can hopefully be removed then. :)

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/tokio/sleep.rs ... ok
tests/fail/panic/double_panic.rs ... ok

tests/fail/stacked_borrows/illegal_dealloc1.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-8197e2dce1dfb558.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-8197e2dce1dfb558.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-19aeac02a6c0ffc3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-19aeac02a6c0ffc3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-ef2fbe160fcdd653.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-ef2fbe160fcdd653.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-54bb73fbdf6df9ac.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-54bb73fbdf6df9ac.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/librand-0ff886e7eaab9922.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/librand-0ff886e7eaab9922.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-6a0f79efa3d70627.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-6a0f79efa3d70627.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-c06a3f45b0e19bd7.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-c06a3f45b0e19bd7.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/lock_api-67529c054bcce400" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/proc-macro2-88560543811a7474" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/parking_lot_core-057742f3b212972a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/quote-059f15a9694b54ae" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/syn-2407d38215cd42b2" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/tokio-644c63a1da1ce210" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/log-1ec6f959fa319c8e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/getrandom-3c088a94c925444e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/memchr-8c21ca7640ca0068" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/libc-117bf3c154c8368e" "tests/fail/stacked_borrows/illegal_dealloc1.rs" "--edition" "2021"

actual output differed from expected
--- tests/fail/stacked_borrows/illegal_dealloc1.stderr
+++ <stderr output>
+++ <stderr output>
... 9 lines skipped ...
   --> $DIR/illegal_deALLOC.rs:LL:CC
    |
-LL |         let ptr2 = (&mut *ptr1) as *mut u8;
+LL |         let ptr2 = &mut *ptr1 as *mut u8;
+   |                    ^^^^^^^^^^
+   |                    ^^^^^^^^^^
 help: <TAG> was later invalidated at offsets [0x0..0x1] by a write access
   --> $DIR/illegal_deALLOC.rs:LL:CC


full stderr:
full stderr:
error: Undefined Behavior: attempting deallocation using <2532> at alloc1317, but that tag does not exist in the borrow stack for this location
##[error]  --> /checkout/library/alloc/src/alloc.rs:121:14
LL |     unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
LL |     unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempting deallocation using <2532> at alloc1317, but that tag does not exist in the borrow stack for this location
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
   = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
   = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <2532> was created by a SharedReadWrite retag at offsets [0x0..0x1]
   |
LL |         let ptr2 = &mut *ptr1 as *mut u8;
   |                    ^^^^^^^^^^
   |                    ^^^^^^^^^^
help: <2532> was later invalidated at offsets [0x0..0x1] by a write access
   |
LL |         ptr1.write(0);
   |         ^^^^^^^^^^^^^
   = note: BACKTRACE (of the first span):
---



tests/fail/tree-borrows/reserved/int-protected-write.rs FAILED:
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Zui-testing" "--target" "x86_64-unknown-linux-gnu" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-8197e2dce1dfb558.rlib" "--extern" "getrandom=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-8197e2dce1dfb558.rmeta" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-19aeac02a6c0ffc3.rlib" "--extern" "getrandom_1=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-19aeac02a6c0ffc3.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-ef2fbe160fcdd653.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-ef2fbe160fcdd653.rmeta" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-54bb73fbdf6df9ac.rlib" "--extern" "num_cpus=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libnum_cpus-54bb73fbdf6df9ac.rmeta" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/librand-0ff886e7eaab9922.rlib" "--extern" "rand=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/librand-0ff886e7eaab9922.rmeta" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-6a0f79efa3d70627.rlib" "--extern" "page_size=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libpage_size-6a0f79efa3d70627.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-c06a3f45b0e19bd7.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps/libtokio-c06a3f45b0e19bd7.rmeta" "--extern" "miri_test_deps=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/miri-test-deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/lock_api-67529c054bcce400" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/proc-macro2-88560543811a7474" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/parking_lot_core-057742f3b212972a" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/quote-059f15a9694b54ae" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/syn-2407d38215cd42b2" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/tokio-644c63a1da1ce210" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/log-1ec6f959fa319c8e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/getrandom-3c088a94c925444e" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/x86_64-unknown-linux-gnu/debug" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/memchr-8c21ca7640ca0068" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/miri/debug/build/libc-117bf3c154c8368e" "tests/fail/tree-borrows/reserved/int-protected-write.rs" "-Zmiri-tree-borrows" "-Zmiri-tag-gc=0" "--edition" "2021"

actual output differed from expected
--- tests/fail/tree-borrows/reserved/int-protected-write.stderr
+++ <stderr output>
+++ <stderr output>
... 21 lines skipped ...
   --> $DIR/int-protected-write.rs:LL:CC
    |
-LL |         let y = (&mut *n) as *mut _;
-   |                 ^^^^^^^^^
+LL |         let y = &mut *n as *mut _;
 help: the protected tag <TAG> was created here, in the initial state Reserved
   --> $DIR/int-protected-write.rs:LL:CC
... 16 lines skipped ...



full stderr:
──────────────────────────────────────────────────────────────────────
Warning: this tree is indicative only. Some tags may have been hidden.
0..  1
| Act|    └─┬──<2505=root of the allocation>
| Res|      └─┬──<2506=n>
| Res|        ├─┬──<2520=x>
| Res|        │ └─┬──<2546=caller:x>
| Res|        │   └────<2547=callee:x> Strongly protected
| Res|        └────<2533=y, callee:y, caller:y>
──────────────────────────────────────────────────────────────────────
error: Undefined Behavior: write access through <2533> (y, callee:y, caller:y) is forbidden
##[error]  --> tests/fail/tree-borrows/reserved/int-protected-write.rs:29:13
   |
LL |             *y = 0;
   |             ^^^^^^ write access through <2533> (y, callee:y, caller:y) is forbidden
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the Tree Borrows rules it violated are still experimental
   = help: the accessed tag <2533> (y, callee:y, caller:y) is foreign to the protected tag <2547> (callee:x) (i.e., it is not a child)
   = help: the access would cause the protected tag <2547> (callee:x) to transition from Reserved to Disabled
   = help: this is a loss of read and write permissions, which is not allowed for protected tags
help: the accessed tag <2533> was created here
   |
   |
LL |         let y = &mut *n as *mut _;
help: the protected tag <2547> was created here, in the initial state Reserved
  --> tests/fail/tree-borrows/reserved/int-protected-write.rs:18:32
   |
   |
LL |         unsafe fn write_second(x: &mut u8, y: *mut u8) {
   = note: BACKTRACE (of the first span):
   = note: inside `main::write_second` at tests/fail/tree-borrows/reserved/int-protected-write.rs:29:13: 29:19
note: inside `main`
  --> tests/fail/tree-borrows/reserved/int-protected-write.rs:17:9
---
test result: FAIL. 2 tests failed, 381 tests passed, 3 ignored, 0 filtered out
Error: 
   0: tests failed

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/compiletest-247d1a491ee4198c --quiet` (exit status: 1)
Build completed unsuccessfully in 0:03:38

// cast is left-assoc
let _ = (true as u8) as u16;
//~^ WARN unnecessary parentheses around cast expression
// should not fire
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unary - to this block (and other unary operator as well?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your intention include *expr as Ty and &expr as Ty?

@bors
Copy link
Contributor

bors commented Jun 29, 2023

☔ The latest upstream changes (presumably #113151) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@KisaragiEffective any updates on it?

@Dylan-DPC
Copy link
Member

Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks

@Dylan-DPC Dylan-DPC closed this Feb 8, 2024
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. 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.

Unnecssary parenthesis lint
8 participants