From 4347cbbd665c8c65c88f31e73cd6d682de156025 Mon Sep 17 00:00:00 2001 From: Matt Roche Date: Sun, 18 Jan 2015 15:22:16 -0500 Subject: [PATCH 1/2] Error message fixes and removed explicit returns in example code --- src/doc/trpl/pointers.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/doc/trpl/pointers.md b/src/doc/trpl/pointers.md index d74c10b8145..fd839d17b20 100644 --- a/src/doc/trpl/pointers.md +++ b/src/doc/trpl/pointers.md @@ -87,7 +87,11 @@ println!("{}", x + z); This gives us an error: ```text -hello.rs:6:24: 6:25 error: mismatched types: expected `i32` but found `&i32` (expected i32 but found &-ptr) +hello.rs:6:24: 6:25 error: mismatched types: + expected `_`, + found `&_` +(expected integral variable, + found &-ptr) hello.rs:6 println!("{}", x + z); ^ ``` @@ -305,7 +309,7 @@ References are immutable by default: let x = 5; let y = &x; -*y = 5; // error: cannot assign to immutable dereference of `&`-pointer `*y` +*y = 5; // error: cannot assign to immutable borrowed content `*y` ``` They can be made mutable with `mut`, but only if its referent is also mutable. @@ -668,7 +672,7 @@ struct BigStruct { } fn foo(x: Box) -> Box { - return Box::new(*x); + Box::new(*x) } fn main() { @@ -696,7 +700,7 @@ struct BigStruct { } fn foo(x: Box) -> BigStruct { - return *x; + *x } fn main() { From 9293607f8f485acc91be83bcc216ae01ed70b5fd Mon Sep 17 00:00:00 2001 From: Matt Roche Date: Sun, 18 Jan 2015 15:28:12 -0500 Subject: [PATCH 2/2] quick formatting fix --- src/doc/trpl/pointers.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/doc/trpl/pointers.md b/src/doc/trpl/pointers.md index fd839d17b20..29986d7f235 100644 --- a/src/doc/trpl/pointers.md +++ b/src/doc/trpl/pointers.md @@ -87,11 +87,7 @@ println!("{}", x + z); This gives us an error: ```text -hello.rs:6:24: 6:25 error: mismatched types: - expected `_`, - found `&_` -(expected integral variable, - found &-ptr) +hello.rs:6:24: 6:25 error: mismatched types: expected `_`, found `&_` (expected integral variable, found &-ptr) hello.rs:6 println!("{}", x + z); ^ ```