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

smallvec![] generate a "variable does not need to be mutable" warning. #127

Closed
crlf0710 opened this issue Oct 3, 2018 · 3 comments
Closed

smallvec![] generate a "variable does not need to be mutable" warning. #127

crlf0710 opened this issue Oct 3, 2018 · 3 comments

Comments

@crlf0710
Copy link

@crlf0710 crlf0710 commented Oct 3, 2018

When use the macro to build an empty SmallVec, it raises a warning. I think this should be dealt with from the smallvec crate side.

@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Oct 8, 2018

I can't reproduce this problem. The following program compiles without warning for me, using Rust 1.29.1 and smallvec 0.6.5.

#[macro_use] extern crate smallvec;

use smallvec::SmallVec;

fn main() {
    let _foo: SmallVec<[u8; 1]> = smallvec![];
}

Can you create a test case that demonstrates the problem?

@crlf0710
Copy link
Author

@crlf0710 crlf0710 commented Oct 9, 2018

Mmm i tried to reduce the test case, and found that this code

#[macro_use] extern crate smallvec;

use smallvec::SmallVec;
use std::cell::RefCell;
pub struct R;

pub struct S {
    pub instances: RefCell<SmallVec<[R; 1]>>,
}

impl S {
    pub fn new() -> Self {
        S {
            instances: RefCell::new(smallvec![]),
        }
    }
}

issues such warning under stable 1.28.0:

warning: variable does not need to be mutable
  --> src\main.rs:14:37
   |
14 |             instances: RefCell::new(smallvec![]),
   |                                     ^^^^^^^^^^^ help: remove this `mut`
   |
   = note: #[warn(unused_mut)] on by default
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-
backtrace for more info)

But such warning is gone in the nightly channel (rustc 1.30.0-nightly (02cb8f2a4 2018-08-29)). I cannot reproduce using play.rust-lang.org's stable 1.29.* either.

I think maybe this is a fixed problem of rustc itself. Maybe we can close this now.

@mbrubeck mbrubeck closed this Oct 9, 2018
@mbrubeck
Copy link
Contributor

@mbrubeck mbrubeck commented Oct 9, 2018

Thanks for investigating!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.