小编0us*_*nou的帖子

为什么在使用 dbg!() 后出现“在此处借用移动值”错误?

我有这段代码,但它给了我一个我不明白的错误:

\n
fn main() {\n    // --snip--\n\n    let mut unit = String::new();\n\n    std::io::stdin()\n        .read_line(&mut unit)\n        .expect("couldn\'t read line!");\n\n    let unit = unit.trim().to_lowercase();\n    dbg!(unit);\n\n    if unit == "f" {\n        println!("temperature in Celsius is : {}\xc2\xb0c", f_to_c(temp));\n    } else if unit == "c" {\n        println!("temperature in Fahrenheit is : {}\xc2\xb0f", c_to_f(temp));\n    } else {\n        println!("\'{unit}\' unit not supported!");\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n
error[E0382]: borrow of moved value: `unit`\n  --> src/lib.rs:16:8\n   |\n13 |     let unit = unit.trim().to_lowercase();\n   |         ---- move occurs because `unit` has type …
Run Code Online (Sandbox Code Playgroud)

rust borrow-checker

1
推荐指数
1
解决办法
624
查看次数

更改了 C 程序中的注释及其导致的分段错误

这是提交之间的区别,只是注释和行间距不同,但旧的提交正常运行,而新的结果导致段错误:

Binary files a/recover/recover and b/recover/recover differ
diff --git a/recover/recover.c b/recover/recover.c
index f0ffdf6..02ab42b 100644
--- a/recover/recover.c
+++ b/recover/recover.c
@@ -1,34 +1,32 @@
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 
 typedef enum
 {
-   false,
-   true
-} bool;
+   true,
+   false
 
-typedef uint8_t BYTE;
+} bool;
 
 typedef char *string;
 
+typedef uint8_t BYTE;
 int BLOCK_SIZE = 512;
 
 int main(int argc, char *argv[])
 {
-   // Check if a file name was provided as an argument
-   if …
Run Code Online (Sandbox Code Playgroud)

c gcc clang gnu-make segmentation-fault

-8
推荐指数
1
解决办法
64
查看次数

标签 统计

borrow-checker ×1

c ×1

clang ×1

gcc ×1

gnu-make ×1

rust ×1

segmentation-fault ×1