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

Highlight "types differ in mutability" errors if a variable type is not manually declared #4705

Closed
lancelote opened this issue Nov 29, 2019 · 0 comments · Fixed by #5548
Closed
Labels
feature subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc.

Comments

@lancelote
Copy link
Member

Environment

  • IntelliJ Rust plugin version: 0.2.112.2801-193-nightly
  • Rust toolchain version: 1.39.0 (4560ea788 2019-11-04) x86_64-apple-darwin
  • IDE name and version: CLion 2019.3 (CL-193.5233.103)
  • Operating system: macOS 10.15

Problem description

Passing an immutable reference to a function expecting a mutable is not highlighted as an error if the variable type is not explicitly declared.

Steps to reproduce

Standalone example:

use std::collections::HashMap;

fn fib_dyn(n: u64, map: &mut HashMap<u64, u64>) -> u64 {
    match n {
        0 | 1 => 1,
        n => {
            if map.contains_key(&n) {
                *map.get(&n).unwrap()
            } else {
                let val = fib_dyn(n - 1, map) + fib_dyn(n - 2, map);
                map.insert(n, val);
                val
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn fib_5() {
        let mut map = HashMap::new();
        assert_eq!(fib_dyn(5, &map), 8);
    }
}

Build fails with

error[E0308]: mismatched types
  --> src/chapter1/dynamic_fibonacci.rs:25:31
   |
25 |         assert_eq!(fib_dyn(5, &map), 8);
   |                               ^^^^ types differ in mutability
   |
   = note: expected type `&mut std::collections::HashMap<u64, u64>`
              found type `&std::collections::HashMap<_, _>`

map type is reported as HashMap<?, ?>, no error is highlighted

Screen Shot 2019-11-29 at 11 30 55

If I do specify the type

Screen Shot 2019-11-29 at 11 33 17

@lancelote lancelote changed the title Highlight "types differ in mutability" errors if a type is not manually specified Highlight "types differ in mutability" errors if a variable type is not manually declared Nov 29, 2019
@Undin Undin added feature subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc. labels Nov 29, 2019
@bors bors bot closed this as completed in 64644fc Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature subsystem::code insight General label for issues related to code understanding: highlighting, completion, annotation, etc.
Projects
None yet
2 participants