From 35af0872451dd0659d27daf830d9b68b2134cb0f Mon Sep 17 00:00:00 2001 From: Fanyjie Date: Fri, 14 Jan 2022 14:24:12 +0800 Subject: [PATCH 1/3] pattern-match: add missed error message --- book/contents/basic/match-pattern/pattern-match.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/book/contents/basic/match-pattern/pattern-match.md b/book/contents/basic/match-pattern/pattern-match.md index 83581255..355062ad 100644 --- a/book/contents/basic/match-pattern/pattern-match.md +++ b/book/contents/basic/match-pattern/pattern-match.md @@ -90,6 +90,20 @@ let (x, y, z) = (1, 2, 3); ```rust let (x, y) = (1, 2, 3); ``` +```rust +error[E0308]: mismatched types + --> src/main.rs:4:5 + | +4 | let (x, y) = (1, 2, 3); + | ^^^^^^ --------- this expression has type `({integer}, {integer}, {integer})` + | | + | expected a tuple with 3 elements, found one with 2 elements + | + = note: expected tuple `({integer}, {integer}, {integer})` + found tuple `(_, _)` +For more information about this error, try `rustc --explain E0308`. +error: could not compile `playground` due to previous error +``` 对于元组来说,元素个数也是类型的一部分! #### 函数参数 From a4c7c49f00c660fb2fb001e60e9e38b7f4fc49d4 Mon Sep 17 00:00:00 2001 From: mtaech Date: Fri, 14 Jan 2022 14:42:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E2=80=9CRust=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E8=A7=84=E8=8C=83=E2=80=9D=E7=9A=84=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- book/contents/basic/variable.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/contents/basic/variable.md b/book/contents/basic/variable.md index cc106566..8d89cc15 100644 --- a/book/contents/basic/variable.md +++ b/book/contents/basic/variable.md @@ -12,7 +12,7 @@ ## 变量命名 -在命名方面,和其它语言没有区别,不过当给变量命名时,需要遵循[Rust命名规范](../style-guide/naming.md)。 +在命名方面,和其它语言没有区别,不过当给变量命名时,需要遵循[Rust命名规范](../practice/style-guide/naming.md)。 > Rust语言有一些**关键字**(*keywords*),和其他语言一样,这些关键字都是被保留给Rust语言使用的,因此,它们不能被用作变量或函数的名称。 在[附录 A](../appendix/keywords) 中可找到关键字列表。 From eeaa4ea5aa4fe794859b271ffc554f08056614bb Mon Sep 17 00:00:00 2001 From: mtaech Date: Fri, 14 Jan 2022 14:54:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E7=9A=84=E8=B7=B3=E8=BD=AC=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- book/contents/basic/base-type/function.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/contents/basic/base-type/function.md b/book/contents/basic/base-type/function.md index 0ff723b4..e7fa1cc4 100644 --- a/book/contents/basic/base-type/function.md +++ b/book/contents/basic/base-type/function.md @@ -17,7 +17,7 @@ fn add(i: i32, j: i32) -> i32 { 当你看懂了这张图,其实就等于差不多完成了函数章节的学习,但是这么短的章节显然对不起读者老爷们的厚爱,所以我们来展开下。 ## 函数要点 -- 函数名和变量名使用[蛇形命名法(snake case)](../../style-guide/naming.md),例如`fn add_two() -> {}` +- 函数名和变量名使用[蛇形命名法(snake case)](../../practice/style-guide/naming.md),例如`fn add_two() -> {}` - 函数的位置可以随便放,Rust不关心我们在哪里定义了函数,只要有定义即可 - 每个函数参数都需要标注类型