为什么这个Rust 2018代码使用'cargo build'编译,而不使用Rust C?

为什么这个Rust 2018代码使用'cargo build'编译,而不使用Rust C?,rust,borrow-checker,Rust,Borrow Checker,当使用cargo build编译下面的代码段时,借用检查器似乎很好,但是当使用rustc时,我得到了错误 error[E0502]:无法将'char\u counts'借用为可变的,因为它也被借用为不可变的 -->src/lib.rs:14:17 | 10 | let count=char_counts.get(&char); |--------此处发生不可变借用 ... 14 |字符计数。插入(字符,rem); |^^^^^^^^^^^^^^^此处发生可变借用 ... 19 | } |

当使用cargo build编译下面的代码段时,借用检查器似乎很好,但是当使用rustc时,我得到了错误

error[E0502]:无法将'char\u counts'借用为可变的,因为它也被借用为不可变的
-->src/lib.rs:14:17
|
10 | let count=char_counts.get(&char);
|--------此处发生不可变借用
...
14 |字符计数。插入(字符,rem);
|^^^^^^^^^^^^^^^此处发生可变借用
...
19 |     }
|-不可变的借阅到此结束
你知道为什么会这样吗

use std::collections::HashMap;

pub fn anagram(word: &str, another_word: &str) -> i32 {
    let mut char_counts = HashMap::new();
    for char in word.chars() {
        let count = char_counts.entry(char).or_insert(0);
        *count += 1;
    }
    for char in another_word.chars() {
        let count = char_counts.get(&char);
        if let Some(val) = count {
            let rem = val - 1;
            if rem > 0 {
                char_counts.insert(char, rem);
            } else {
                char_counts.remove(&char);
            }
        }
    }
    println!("{:?}", char_counts);
    return char_counts.keys().len() as i32;
}

cargo--version
rustc--version
两个命令都输出
1.33

如果启用了此函数,则该函数可以正常编译,没有它们就无法编译。默认情况下,2018版将启用它们。也许您的
edition=“2018”
中有
Cargo.toml
,但在直接使用RUSC时没有将其作为参数传递?

RUSC--version和
Cargo--version
的输出是什么?这两个命令的输出
1.33
我观察到了相同的行为(Linux,1.33.0用于
rustc
)。奇怪的是,如果我做了
rustc--edition 2018 main.rs
它会编译。