From b242a86864216e4d03bb1f5158afc2e9ffed9e21 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 16:12:43 -0400 Subject: [PATCH 1/7] Mention that enum constructors are functions Fixes #25850 --- src/doc/trpl/enums.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/doc/trpl/enums.md b/src/doc/trpl/enums.md index 01905caf5ec0d..8ad4eeedd187f 100644 --- a/src/doc/trpl/enums.md +++ b/src/doc/trpl/enums.md @@ -64,3 +64,45 @@ equality yet, but we’ll find out in the [`traits`][traits] section. [match]: match.html [if-let]: if-let.html [traits]: traits.html + +# Constructors as functions + +An enum’s constructors can also be used like functions. For example: + +```rust +# enum Message { +# Write(String), +# } +let m = Message::Write("Hello, world".to_string()); +``` + +Is the same as + +```rust +# enum Message { +# Write(String), +# } +fn foo(x: String) -> Message { + Message::Write(x) +} + +let x = foo("Hello, world".to_string()); +``` + +This is not immediately useful to us, but when we get to +[`closures`][closures], we’ll talk about passing functions as arguments to +other functions. For example, with [`iterators`][iterators], we can do this +to convert a vector of `String`s into a vector of `Message::Write`s: + +```rust +# enum Message { +# Write(String), +# } + +let v = vec!["Hello".to_string(), "World".to_string()]; + +let v1: Vec = v.into_iter().map(Message::Write).collect(); +``` + +[closures]: closures.html +[iterators]: iterators.html From a3cd5eb1bd53a919bfc76da06e05e0d32c410e5b Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 16:26:21 -0400 Subject: [PATCH 2/7] Exise 'owned pointer' from the codebase Still some references left to this old term, I've updated them to say boxes. Related to #25851 --- src/liballoc/lib.rs | 6 +++--- src/librustc/middle/check_const.rs | 4 ++-- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc_borrowck/borrowck/README.md | 12 ++++++------ .../borrowck/gather_loans/restrictions.rs | 2 +- src/librustc_typeck/check/regionck.rs | 2 +- src/test/compile-fail/issue-6801.rs | 4 ++-- src/test/compile-fail/kindck-copy.rs | 2 +- src/test/run-pass/trait-with-bounds-default.rs | 2 +- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index ac5a5d60cbd47..5541a5f34c41c 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -22,9 +22,9 @@ //! //! ## Boxed values //! -//! The [`Box`](boxed/index.html) type is the core owned pointer type in Rust. -//! There can only be one owner of a `Box`, and the owner can decide to mutate -//! the contents, which live on the heap. +//! The [`Box`](boxed/index.html) type is a smart pointer type. There can +//! only be one owner of a `Box`, and the owner can decide to mutate the +//! contents, which live on the heap. //! //! This type can be sent among threads efficiently as the size of a `Box` value //! is the same as that of a pointer. Tree-like data structures are often built diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 7403462df8ace..c6978808f6d43 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -13,10 +13,10 @@ // // - For each *mutable* static item, it checks that its **type**: // - doesn't have a destructor -// - doesn't own an owned pointer +// - doesn't own a box // // - For each *immutable* static item, it checks that its **value**: -// - doesn't own owned, managed pointers +// - doesn't own a box // - doesn't contain a struct literal or a call to an enum variant / struct constructor where // - the type of the struct/enum has a dtor // diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3fff15049930b..6a638f3d427f8 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1410,7 +1410,7 @@ pub enum AliasableReason { impl<'tcx> cmt_<'tcx> { pub fn guarantor(&self) -> cmt<'tcx> { - //! Returns `self` after stripping away any owned pointer derefs or + //! Returns `self` after stripping away any derefs or //! interior content. The return value is basically the `cmt` which //! determines how long the value in `self` remains live. diff --git a/src/librustc_borrowck/borrowck/README.md b/src/librustc_borrowck/borrowck/README.md index 08f0897e7617e..5cfbd59d33368 100644 --- a/src/librustc_borrowck/borrowck/README.md +++ b/src/librustc_borrowck/borrowck/README.md @@ -170,7 +170,7 @@ overwrite (or freeze) `(*x).f`, and thus invalidate the reference that was created. In general it holds that when a path is lent, restrictions are issued for all the owning prefixes of that path. In this case, the path `*x` owns the path `(*x).f` and, -because `x` is an owned pointer, the path `x` owns the path `*x`. +because `x` has ownership, the path `x` owns the path `*x`. Therefore, borrowing `(*x).f` yields restrictions on both `*x` and `x`. @@ -286,7 +286,7 @@ MUTABILITY(X, imm) // M-Var-Imm ### Checking mutability of owned content -Fields and owned pointers inherit their mutability from +Fields and boxes inherit their mutability from their base expressions, so both of their rules basically delegate the check to the base expression `LV`: @@ -387,7 +387,7 @@ LIFETIME(X, LT, MQ) // L-Local ### Checking lifetime for owned content -The lifetime of a field or owned pointer is the same as the lifetime +The lifetime of a field or box is the same as the lifetime of its owner: ```text @@ -466,10 +466,10 @@ origin of inherited mutability. Because the mutability of owned referents is inherited, restricting an owned referent is similar to restricting a field, in that it implies -restrictions on the pointer. However, owned pointers have an important +restrictions on the pointer. However, boxes have an important twist: if the owner `LV` is mutated, that causes the owned referent `*LV` to be freed! So whenever an owned referent `*LV` is borrowed, we -must prevent the owned pointer `LV` from being mutated, which means +must prevent the box `LV` from being mutated, which means that we always add `MUTATE` and `CLAIM` to the restriction set imposed on `LV`: @@ -648,7 +648,7 @@ fn main() { ``` Clause (2) propagates the restrictions on the referent to the pointer -itself. This is the same as with an owned pointer, though the +itself. This is the same as with an box, though the reasoning is mildly different. The basic goal in all cases is to prevent the user from establishing another route to the same data. To see what I mean, let's examine various cases of what can go wrong and diff --git a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs index 7078b2b5f1797..b806f185205f9 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs @@ -110,7 +110,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> { mc::Unique => { // R-Deref-Send-Pointer // - // When we borrow the interior of an owned pointer, we + // When we borrow the interior of a box, we // cannot permit the base to be mutated, because that // would cause the unique pointer to be freed. // diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 090d111b62b89..fbb6502b5b901 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -76,7 +76,7 @@ //! the borrow itself (L2). What do I mean by "guaranteed" by a //! borrowed pointer? I mean any data that is reached by first //! dereferencing a borrowed pointer and then either traversing -//! interior offsets or owned pointers. We say that the guarantor +//! interior offsets or boxes. We say that the guarantor //! of such data it the region of the borrowed pointer that was //! traversed. This is essentially the same as the ownership //! relation, except that a borrowed pointer never owns its diff --git a/src/test/compile-fail/issue-6801.rs b/src/test/compile-fail/issue-6801.rs index 9e79701939245..8261862c5fc51 100644 --- a/src/test/compile-fail/issue-6801.rs +++ b/src/test/compile-fail/issue-6801.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Creating a stack closure which references an owned pointer and then -// transferring ownership of the owned box before invoking the stack +// Creating a stack closure which references an box and then +// transferring ownership of the box before invoking the stack // closure results in a crash. #![feature(box_syntax)] diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index 95ab2bbab14a3..997c940c9547e 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -37,7 +37,7 @@ fn test<'a,T,U:Copy>(_: &'a isize) { assert_copy::<&'static mut isize>(); //~ ERROR `core::marker::Copy` is not implemented assert_copy::<&'a mut isize>(); //~ ERROR `core::marker::Copy` is not implemented - // owned pointers are not ok + // boxes are not ok assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented assert_copy::(); //~ ERROR `core::marker::Copy` is not implemented assert_copy:: >(); //~ ERROR `core::marker::Copy` is not implemented diff --git a/src/test/run-pass/trait-with-bounds-default.rs b/src/test/run-pass/trait-with-bounds-default.rs index cfd812400947e..6b0faa2207b25 100644 --- a/src/test/run-pass/trait-with-bounds-default.rs +++ b/src/test/run-pass/trait-with-bounds-default.rs @@ -10,7 +10,7 @@ // pub trait Clone2 { - /// Returns a copy of the value. The contents of owned pointers + /// Returns a copy of the value. The contents of boxes /// are copied to maintain uniqueness, while the contents of /// managed pointers are not copied. fn clone(&self) -> Self; From 34e5c24c5d7b693e043b1e35c137959fdcda19a8 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 16:37:47 -0400 Subject: [PATCH 3/7] make note of slicing syntax in TRPL: strings Fixes #25853 --- src/doc/trpl/strings.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/doc/trpl/strings.md b/src/doc/trpl/strings.md index 55154036286d2..7d5c43ea14c03 100644 --- a/src/doc/trpl/strings.md +++ b/src/doc/trpl/strings.md @@ -117,6 +117,30 @@ let dog = hachiko.chars().nth(1); // kinda like hachiko[1] This emphasizes that we have to go through the whole list of `chars`. +## Slicing + +You can get a slice of a string with slicing syntax: + +```rust +let dog = "hachiko"; +let hachi = &dog[0..5]; +``` + +But note that these are _byte_ offsets, not _character_ offsets. So +this will fail at runtime: + +```rust,should_panic +let dog = "忠犬ハチ公"; +let hachi = &dog[0..2]; +``` + +with this error: + +```text +thread '
' panicked at 'index 0 and/or 2 in `忠犬ハチ公` do not lie on +character boundary' +``` + ## Concatenation If you have a `String`, you can concatenate a `&str` to the end of it: From 2c75256c151774407e5f4a0e4c655604d34bee17 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Tue, 9 Jun 2015 16:49:24 -0400 Subject: [PATCH 4/7] Exise 'unsafe pointer' in favor of 'raw pointer' Using two terms for one thing is confusing, these are called 'raw pointers' today. --- src/doc/trpl/ffi.md | 4 ++-- src/doc/trpl/raw-pointers.md | 6 +++--- src/libcollections/slice.rs | 2 +- src/libcollections/str.rs | 2 +- src/libcollections/vec.rs | 2 +- src/libcore/intrinsics.rs | 2 +- src/libcore/marker.rs | 2 +- src/libcore/ptr.rs | 8 ++++---- src/librustc/middle/effect.rs | 2 +- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/ty.rs | 2 +- .../borrowck/gather_loans/gather_moves.rs | 2 +- .../borrowck/gather_loans/restrictions.rs | 2 +- src/librustc_typeck/check/cast.rs | 4 ++-- src/libstd/sys/common/thread_local.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs | 2 +- src/test/compile-fail/issue-20801.rs | 4 ++-- .../regions-bounded-by-trait-requiring-static.rs | 2 +- src/test/compile-fail/unsafe-fn-assign-deref-ptr.rs | 2 +- src/test/compile-fail/unsafe-fn-deref-ptr.rs | 2 +- src/test/parse-fail/no-unsafe-self.rs | 8 ++++---- 22 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 9ede835e521c9..c6b4e21b06c3a 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -238,7 +238,7 @@ However it is often desired that the callback is targeted to a special Rust object. This could be the object that represents the wrapper for the respective C object. -This can be achieved by passing an unsafe pointer to the object down to the +This can be achieved by passing an raw pointer to the object down to the C library. The C library can then include the pointer to the Rust object in the notification. This will allow the callback to unsafely access the referenced Rust object. @@ -368,7 +368,7 @@ On OSX, frameworks behave with the same semantics as a dynamic library. # Unsafe blocks -Some operations, like dereferencing unsafe pointers or calling functions that have been marked +Some operations, like dereferencing raw pointers or calling functions that have been marked unsafe are only allowed inside unsafe blocks. Unsafe blocks isolate unsafety and are a promise to the compiler that the unsafety does not leak out of the block. diff --git a/src/doc/trpl/raw-pointers.md b/src/doc/trpl/raw-pointers.md index 0f189adf40abf..8a3b98b72927b 100644 --- a/src/doc/trpl/raw-pointers.md +++ b/src/doc/trpl/raw-pointers.md @@ -52,9 +52,9 @@ println!("raw points at {}", *raw); It gives this error: ```text -error: dereference of unsafe pointer requires unsafe function or block [E0133] - println!("raw points at{}", *raw); - ^~~~ +error: dereference of raw pointer requires unsafe function or block [E0133] + println!("raw points at {}", *raw); + ^~~~ ``` When you dereference a raw pointer, you’re taking responsibility that it’s not diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 634b3f56e8e4c..e99fc95d200bd 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -370,7 +370,7 @@ impl [T] { core_slice::SliceExt::get_unchecked_mut(self, index) } - /// Returns an unsafe pointer to the slice's buffer + /// Returns an raw pointer to the slice's buffer /// /// The caller must ensure that the slice outlives the pointer this /// function returns, or else it will end up pointing to garbage. diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index a9725214c1953..c23b0445e8705 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -525,7 +525,7 @@ impl str { core_str::StrExt::as_bytes(&self[..]) } - /// Returns an unsafe pointer to the `&str`'s buffer. + /// Returns a raw pointer to the `&str`'s buffer. /// /// The caller must ensure that the string outlives this pointer, and /// that it is not diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 0cc0108fd0116..e7b700119f907 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1215,7 +1215,7 @@ impl Vec { let ln = self.len(); if ln < 1 { return; } - // Avoid bounds checks by using unsafe pointers. + // Avoid bounds checks by using raw pointers. let p = self.as_mut_ptr(); let mut r: usize = 1; let mut w: usize = 1; diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 16094f2e6cc3c..774f86563d79c 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -46,7 +46,7 @@ use marker::Sized; extern "rust-intrinsic" { - // NB: These intrinsics take unsafe pointers because they mutate aliased + // NB: These intrinsics take raw pointers because they mutate aliased // memory, which is not valid for either `&` or `&mut`. pub fn atomic_cxchg(dst: *mut T, old: T, src: T) -> T; diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index bc0f3045972fe..7c20722b26d47 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -357,7 +357,7 @@ macro_rules! impls{ /// struct is dropped, it may in turn drop one or more instances of /// the type `T`, though that may not be apparent from the other /// structure of the type itself. This is commonly necessary if the -/// structure is using an unsafe pointer like `*mut T` whose referent +/// structure is using a raw pointer like `*mut T` whose referent /// may be dropped when the type is dropped, as a `*mut T` is /// otherwise not treated as owned. /// diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 47c029f11b38f..9ca9b4fc46c99 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -10,16 +10,16 @@ // FIXME: talk about offset, copy_memory, copy_nonoverlapping_memory -//! Operations on unsafe pointers, `*const T`, and `*mut T`. +//! Operations on raw pointers, `*const T`, and `*mut T`. //! -//! Working with unsafe pointers in Rust is uncommon, +//! Working with raw pointers in Rust is uncommon, //! typically limited to a few patterns. //! //! Use the `null` function to create null pointers, and the `is_null` method //! of the `*const T` type to check for null. The `*const T` type also defines //! the `offset` method, for pointer math. //! -//! # Common ways to create unsafe pointers +//! # Common ways to create raw pointers //! //! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`). //! @@ -86,7 +86,7 @@ //! //! Usually you wouldn't literally use `malloc` and `free` from Rust, //! but C APIs hand out a lot of pointers generally, so are a common source -//! of unsafe pointers in Rust. +//! of raw pointers in Rust. #![stable(feature = "rust1", since = "1.0.0")] #![doc(primitive = "pointer")] diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index cfff439f02d19..defdf2ae08865 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -162,7 +162,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> { debug!("effect: unary case, base type is {}", ppaux::ty_to_string(self.tcx, base_type)); if let ty::ty_ptr(_) = base_type.sty { - self.require_unsafe(expr.span, "dereference of unsafe pointer") + self.require_unsafe(expr.span, "dereference of raw pointer") } } ast::ExprAssign(ref base, _) | ast::ExprAssignOp(_, ref base, _) => { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3fff15049930b..82d1b45dadb17 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1546,7 +1546,7 @@ impl<'tcx> cmt_<'tcx> { format!("`Box` content") } UnsafePtr(..) => { - format!("dereference of unsafe pointer") + format!("dereference of raw pointer") } BorrowedPtr(..) => { format!("borrowed content") diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 0b014c9e6a20c..ec3e1b3219cd4 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3644,7 +3644,7 @@ impl TypeContents { *self & TC::ReachesAll) } - /// Includes only those bits that still apply when indirected through an unsafe pointer (`*`) + /// Includes only those bits that still apply when indirected through a raw pointer (`*`) pub fn unsafe_pointer(&self) -> TypeContents { *self & TC::ReachesAll } diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index d0f5aa8cf003b..fef8acf2f7b5c 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -137,7 +137,7 @@ fn gather_move<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_info.id, move_info.kind); } None => { - // move from rvalue or unsafe pointer, hence ok + // move from rvalue or raw pointer, hence ok } } } diff --git a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs index 7078b2b5f1797..248010324f6f5 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/restrictions.rs @@ -145,7 +145,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> { } } } - // Borrowck is not relevant for unsafe pointers + // Borrowck is not relevant for raw pointers mc::UnsafePtr(..) => Safe } } diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 5258a77204d60..b84572292923a 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -341,8 +341,8 @@ impl<'tcx> CastCheck<'tcx> { // Due to the limitations of LLVM global constants, // region pointers end up pointing at copies of // vector elements instead of the original values. - // To allow unsafe pointers to work correctly, we - // need to special-case obtaining an unsafe pointer + // To allow raw pointers to work correctly, we + // need to special-case obtaining a raw pointer // from a region pointer to a vector. // this will report a type mismatch if needed diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index eb4cbfcfbcdda..3b2cb00d8c47d 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -102,7 +102,7 @@ pub struct StaticKey { /// type is entirely safe to use. /// /// Implementations will likely, however, contain unsafe code as this type only -/// operates on `*mut u8`, an unsafe pointer. +/// operates on `*mut u8`, a raw pointer. /// /// # Examples /// diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index dcf6667b60644..32066b744134d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4215,7 +4215,7 @@ impl<'a> Parser<'a> { }; if self.is_self_ident() { let span = self.span; - self.span_err(span, "cannot pass self by unsafe pointer"); + self.span_err(span, "cannot pass self by raw pointer"); try!(self.bump()); } // error case, making bogus self ident: diff --git a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs index 8310d4ba1444a..7284fa7a850f0 100644 --- a/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs +++ b/src/test/compile-fail/borrowck-move-from-unsafe-ptr.rs @@ -10,7 +10,7 @@ fn foo(x: *const Box) -> Box { - let y = *x; //~ ERROR dereference of unsafe pointer requires unsafe function or block + let y = *x; //~ ERROR dereference of raw pointer requires unsafe function or block return y; } diff --git a/src/test/compile-fail/issue-20801.rs b/src/test/compile-fail/issue-20801.rs index fe7807042e55b..d3b97a9c05863 100644 --- a/src/test/compile-fail/issue-20801.rs +++ b/src/test/compile-fail/issue-20801.rs @@ -40,8 +40,8 @@ pub fn main() { //~^ ERROR cannot move out of borrowed content let c = unsafe { *mut_ptr() }; - //~^ ERROR cannot move out of dereference of unsafe pointer + //~^ ERROR cannot move out of dereference of raw pointer let d = unsafe { *const_ptr() }; - //~^ ERROR cannot move out of dereference of unsafe pointer + //~^ ERROR cannot move out of dereference of raw pointer } diff --git a/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs b/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs index 9e4c4e677cc69..19c50d57e1b39 100644 --- a/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs +++ b/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs @@ -54,7 +54,7 @@ fn box_with_region_not_ok<'a>() { assert_send::>(); //~ ERROR does not fulfill the required lifetime } -// unsafe pointers are ok unless they point at unsendable things +// raw pointers are ok unless they point at unsendable things fn unsafe_ok1<'a>(_: &'a isize) { assert_send::<*const isize>(); diff --git a/src/test/compile-fail/unsafe-fn-assign-deref-ptr.rs b/src/test/compile-fail/unsafe-fn-assign-deref-ptr.rs index 4ea7051775e13..cff10329b8589 100644 --- a/src/test/compile-fail/unsafe-fn-assign-deref-ptr.rs +++ b/src/test/compile-fail/unsafe-fn-assign-deref-ptr.rs @@ -10,7 +10,7 @@ fn f(p: *const u8) { - *p = 0; //~ ERROR dereference of unsafe pointer requires unsafe function or block + *p = 0; //~ ERROR dereference of raw pointer requires unsafe function or block return; } diff --git a/src/test/compile-fail/unsafe-fn-deref-ptr.rs b/src/test/compile-fail/unsafe-fn-deref-ptr.rs index bdf079e24d2a1..bf87df71fd87d 100644 --- a/src/test/compile-fail/unsafe-fn-deref-ptr.rs +++ b/src/test/compile-fail/unsafe-fn-deref-ptr.rs @@ -10,7 +10,7 @@ fn f(p: *const u8) -> u8 { - return *p; //~ ERROR dereference of unsafe pointer requires unsafe function or block + return *p; //~ ERROR dereference of raw pointer requires unsafe function or block } fn main() { diff --git a/src/test/parse-fail/no-unsafe-self.rs b/src/test/parse-fail/no-unsafe-self.rs index 2a0ed9dcc243f..1cc0e62f5b2d5 100644 --- a/src/test/parse-fail/no-unsafe-self.rs +++ b/src/test/parse-fail/no-unsafe-self.rs @@ -11,14 +11,14 @@ // compile-flags: -Z parse-only trait A { - fn foo(*mut self); //~ ERROR cannot pass self by unsafe pointer - fn bar(*self); //~ ERROR cannot pass self by unsafe pointer + fn foo(*mut self); //~ ERROR cannot pass self by raw pointer + fn bar(*self); //~ ERROR cannot pass self by raw pointer } struct X; impl A for X { - fn foo(*mut self) { } //~ ERROR cannot pass self by unsafe pointer - fn bar(*self) { } //~ ERROR cannot pass self by unsafe pointer + fn foo(*mut self) { } //~ ERROR cannot pass self by raw pointer + fn bar(*self) { } //~ ERROR cannot pass self by raw pointer } fn main() { } From cb31373dc26ca447f7a4a142b2ed352677fb55a0 Mon Sep 17 00:00:00 2001 From: Johann Tuffe Date: Wed, 10 Jun 2015 10:51:48 +0800 Subject: [PATCH 5/7] early return if 1 element No need to dedup if there is only 1 element in the vec, can early return --- src/libcollections/vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 0cc0108fd0116..c4921cb8560bd 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1213,7 +1213,7 @@ impl Vec { // Duplicate, advance r. End of vec. Truncate to w. let ln = self.len(); - if ln < 1 { return; } + if ln <= 1 { return; } // Avoid bounds checks by using unsafe pointers. let p = self.as_mut_ptr(); From 1ece0058382c234dc64ce596eb62b1f636632566 Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Wed, 10 Jun 2015 10:59:36 +0100 Subject: [PATCH 6/7] trpl: why (assignment == empty tuple) #26120 --- src/doc/trpl/functions.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/functions.md b/src/doc/trpl/functions.md index 21a29f0059987..f2113031655cd 100644 --- a/src/doc/trpl/functions.md +++ b/src/doc/trpl/functions.md @@ -144,7 +144,9 @@ an expression, and a `let` can only begin a statement, not an expression. Note that assigning to an already-bound variable (e.g. `y = 5`) is still an expression, although its value is not particularly useful. Unlike other languages where an assignment evaluates to the assigned value (e.g. `5` in the -previous example), in Rust the value of an assignment is an empty tuple `()`: +previous example), in Rust the value of an assignment is an empty tuple `()` +because the assigned value can have (just one owner)[ownership.html], and any +other returned value would be too surprising: ```rust let mut y = 5; From aaf1983a5688683fa7514f273b86c030e9c7b92a Mon Sep 17 00:00:00 2001 From: Matthew Astley Date: Wed, 10 Jun 2015 16:15:24 +0100 Subject: [PATCH 7/7] mend bad Markdown --- src/doc/trpl/functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/functions.md b/src/doc/trpl/functions.md index f2113031655cd..ea927707ecd6f 100644 --- a/src/doc/trpl/functions.md +++ b/src/doc/trpl/functions.md @@ -145,7 +145,7 @@ Note that assigning to an already-bound variable (e.g. `y = 5`) is still an expression, although its value is not particularly useful. Unlike other languages where an assignment evaluates to the assigned value (e.g. `5` in the previous example), in Rust the value of an assignment is an empty tuple `()` -because the assigned value can have (just one owner)[ownership.html], and any +because the assigned value can have [just one owner](ownership.html), and any other returned value would be too surprising: ```rust