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

allow unused_mut ignored #40491

Closed
Cxarli opened this issue Mar 13, 2017 · 5 comments · Fixed by #44590
Closed

allow unused_mut ignored #40491

Cxarli opened this issue Mar 13, 2017 · 5 comments · Fixed by #44590
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@Cxarli
Copy link

Cxarli commented Mar 13, 2017

#[allow(unused_mut)] seems to be ignored

For example:

fn main() {
    #[allow(unused_mut)]
    let mut a = 10;

    println!("{}", a);
}

I expected to see no warning about the mut flag of a

Instead, this happened:

warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
 --> TEST.rs:3:9
  |
3 |     let mut a = 10;
  |         ^^^^^

Meta

This currently happens on all 3 major branches: stable, beta, nightly:

rustc 1.15.1 (021bd294c 2017-02-08)
binary: rustc
commit-hash: 021bd294c039bd54aa5c4aa85bcdffb0d24bc892
commit-date: 2017-02-08
host: x86_64-unknown-linux-gnu
release: 1.15.1
LLVM version: 3.9
rustc 1.16.0 (30cf806ef 2017-03-10)
binary: rustc
commit-hash: 30cf806ef8881c41821fbd43e5cf3699c5290c16
commit-date: 2017-03-10
host: x86_64-unknown-linux-gnu
release: 1.16.0
LLVM version: 3.9
rustc 1.17.0-nightly (824c9ebbd 2017-03-12)
binary: rustc
commit-hash: 824c9ebbd5f0611e326648d90ee3e50caf04bb7f
commit-date: 2017-03-12
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9

Backtrace: RUST_BACKTRACE=full does not give more information.

@codyps
Copy link
Contributor

codyps commented Mar 13, 2017

Note that increasing the scope of the allow avoids the warning as expected: https://is.gd/RyBaRj

fn main() {
    #![allow(unused_mut)]
    let mut a = 10;

    println!("{}", a);
}

Unclear whether applying the allow to the let should be sufficient.

@sfackler
Copy link
Member

I'm guessing that the lint passes were just not updated when attributes were allowed to be attached to statements.

@sfackler sfackler added the A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. label Mar 14, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Mar 14, 2017

The lint pass runs on functions, not on single statements, since you can't decide whether the mut should be linted just by looking at the statement. This is a failure of the current lint system and hard to address.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 14, 2017

cc @Manishearth @mcarton @llogiq

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 27, 2017
@zetok
Copy link

zetok commented Sep 15, 2017

The lint pass runs on functions, not on single statements, since you can't decide whether the mut should be linted just by looking at the statement. This is a failure of the current lint system and hard to address.

allow is also ignored when mut statement is located inside of a macro, regardless of whether allow is located above the statement, macro, or function in which macro is called:
https://github.com/zetok/tox/blob/dc9107c599a33b2b851284808a73f02646ac948f/src/toxcore/dht_node.rs#L231,L235

It would be nice if it did work for single statements inside of a macro.

Main channels are still affected:
stable: rustc 1.20.0 (f3d6973 2017-08-27)
beta: rustc 1.21.0-beta.3 (ea1fd7d 2017-09-15)
nightly: rustc 1.22.0-nightly (5dfc84c 2017-09-14)

oli-obk added a commit to oli-obk/rust that referenced this issue Sep 15, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 16, 2017
…=eddyb

Get `allow(unused_mut)` to work on `let` bindings

fixes rust-lang#40491
frewsxcv added a commit to frewsxcv/rust that referenced this issue Sep 16, 2017
…=eddyb

Get `allow(unused_mut)` to work on `let` bindings

fixes rust-lang#40491
alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 17, 2017
…=eddyb

Get `allow(unused_mut)` to work on `let` bindings

fixes rust-lang#40491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants