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

Missing unnecessary parentheses warning in constant expressions #67942

Closed
leonardo-m opened this issue Jan 6, 2020 · 5 comments · Fixed by #68751
Closed

Missing unnecessary parentheses warning in constant expressions #67942

leonardo-m opened this issue Jan 6, 2020 · 5 comments · Fixed by #68751
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

leonardo-m commented Jan 6, 2020

#![allow(dead_code, unused_variables)]
fn main() {
    const N1: f64 = (2.0 * 2.0);
    let n2: f64 = (2.0 * 2.0);
}

It doesn't give a warning for the unnecessary parentheses for N1:

warning: unnecessary parentheses around assigned value
 --> ...\test.rs:4:19
  |
4 |     let n2: f64 = (2.0 * 2.0);
  |                   ^^^^^^^^^^^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

This issue has been assigned to @Tyg13 via this comment.

@leonardo-m leonardo-m changed the title Missing unnecessary parentheses for constant expressions Missing unnecessary parentheses warning in constant expressions Jan 6, 2020
@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Jan 6, 2020
@csmoe csmoe added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jan 7, 2020
@csmoe
Copy link
Member

csmoe commented Jan 7, 2020

implemented check_item for UnusedParens to check the Const item's Expr field.

@mental32
Copy link
Contributor

mental32 commented Jan 9, 2020

@rustbot claim

@rustbot rustbot self-assigned this Jan 9, 2020
@mental32
Copy link
Contributor

mental32 commented Jan 9, 2020

I've encountered an issue I'm not quite sure how to handle :(

After getting what looks like a correct solution up with: https://github.com/mental32/rust/commit/438ade9ae57f3b5d1abb92a05cfc52a7f18eb046

I am met with the following after starting to build stage-1:

   Compiling rustc_lint v0.0.0 (/home/mental/Desktop/open_projects/rust/src/librustc_lint)
   Compiling rustc_interface v0.0.0 (/home/mental/Desktop/open_projects/rust/src/librustc_interface)
   Compiling rustc_driver v0.0.0 (/home/mental/Desktop/open_projects/rust/src/librustc_driver)
   Compiling rustc-main v0.0.0 (/home/mental/Desktop/open_projects/rust/src/rustc)
    Finished release [optimized] target(s) in 10m 43s
Installing libLLVM.so to stage 0 (x86_64-unknown-linux-gnu)
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling core v0.0.0 (/home/mental/Desktop/open_projects/rust/src/libcore)
error: unnecessary parentheses around const item
  --> src/libcore/../stdarch/crates/core_arch/src/x86/sse41.rs:38:35
   |
38 | pub const _MM_FROUND_FLOOR: i32 = (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_NEG_INF);
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses
   |
   = note: `-D unused-parens` implied by `-D warnings`

error: unnecessary parentheses around const item
  --> src/libcore/../stdarch/crates/core_arch/src/x86/sse41.rs:41:34
   |
41 | pub const _MM_FROUND_CEIL: i32 = (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_POS_INF);
   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

error: unnecessary parentheses around const item
  --> src/libcore/../stdarch/crates/core_arch/src/x86/sse41.rs:44:35
   |
44 | pub const _MM_FROUND_TRUNC: i32 = (_MM_FROUND_RAISE_EXC | _MM_FROUND_TO_ZERO);
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

error: unnecessary parentheses around const item
  --> src/libcore/../stdarch/crates/core_arch/src/x86/sse41.rs:48:34
   |
48 | pub const _MM_FROUND_RINT: i32 = (_MM_FROUND_RAISE_EXC | _MM_FROUND_CUR_DIRECTION);
   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

error: unnecessary parentheses around const item
  --> src/libcore/../stdarch/crates/core_arch/src/x86/sse41.rs:51:39
   |
51 | pub const _MM_FROUND_NEARBYINT: i32 = (_MM_FROUND_NO_EXC | _MM_FROUND_CUR_DIRECTION);
   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these parentheses

error: aborting due to 5 previous errors

error: could not compile `core`.

To learn more, run the command again with --verbose.
command did not execute successfully: "/home/mental/Desktop/open_projects/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "/home/mental/Desktop/open_projects/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "-Zconfig-profile" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/home/mental/Desktop/open_projects/rust/src/libtest/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
failed to run: /home/mental/Desktop/open_projects/rust/build/bootstrap/debug/bootstrap build
Build completed unsuccessfully in 0:13:03

Should I open a separate Issue & PR to deal with any errors generated by unused parens or is it within the scope of this issue (and PR coming soon once I write the UI tests) to deal with them?

@csmoe
Copy link
Member

csmoe commented Jan 10, 2020

@mental32 should be fixed within this issue, and don' forget to add a testcase named issue-67942-unnecessary-paren-in-const-expr.rs into src/test/ui/issues, then ./x.py test src/test/ui --stage 1 --bless, git add the new .stderr and updated .stderr if any.

@Tyg13
Copy link
Contributor

Tyg13 commented Feb 1, 2020

I resolved the issue with the submodule, is it alright if I claim this? It's a small patch to land.

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants