Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #33236

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a3f5d8a
make the borrowing example more concrete
kindlychung Apr 15, 2016
4d0b0e9
Improve as_mut ptr method example
GuillaumeGomez Apr 17, 2016
f252cfa
Update ownership.md
Apr 19, 2016
864eba8
Opening sentence was confusing and something cannot be "one of the mo…
Apr 19, 2016
f7ec687
Opening sentence was confusing and something cannot be "one of the mo…
Apr 19, 2016
3e9ea3b
Make HashSet::Insert documentation more consistent
bwinterton Apr 22, 2016
9348618
Improve error message about regions of function body
bombless Apr 26, 2016
6343f26
allow InternedString to be compared to &str directly
oli-obk Apr 26, 2016
10abb66
Update references-and-borrowing.md
kindlychung Apr 26, 2016
e6b9760
Fix use of the `move` command in the Windows shell
TomasHubelbauer Apr 27, 2016
d569228
mir: drop temps outside-in by scheduling the drops inside-out.
eddyb Apr 27, 2016
0fdce5c
Rollup merge of #32991 - kindlychung:patch-2, r=steveklabnik
Manishearth Apr 27, 2016
d9c9c32
Rollup merge of #33056 - GuillaumeGomez:as_mut_ptr_example, r=stevekl…
Manishearth Apr 27, 2016
cc00ebe
Rollup merge of #33095 - xogeny:xogeny-patch-1, r=steveklabnik
Manishearth Apr 27, 2016
be918b6
Rollup merge of #33152 - bwinterton:master, r=steveklabnik
Manishearth Apr 27, 2016
98c91e0
Rollup merge of #33212 - bombless:scope-of-function-body, r=nikomatsakis
Manishearth Apr 27, 2016
e9e85e8
Rollup merge of #33218 - oli-obk:interned_str_cmp, r=nikomatsakis
Manishearth Apr 27, 2016
c316b48
Rollup merge of #33234 - TomasHubelbauer:TomasHubelbauer-patch-1, r=G…
Manishearth Apr 27, 2016
651ae26
Rollup merge of #33239 - eddyb:mir-temp-drops, r=arielb1
Manishearth Apr 27, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/book/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ enter the following commands:

```bash
$ mkdir src
$ mv main.rs src/main.rs
$ mv main.rs src/main.rs # or 'move main.rs src/main.rs' on Windows
$ rm main # or 'del main.exe' on Windows
```

Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/lifetimes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% Lifetimes

This guide is three of three presenting Rust’s ownership system. This is one of
Rust’s most unique and compelling features, with which Rust developers should
This is the last of three sections presenting Rust’s ownership system. This is one of
Rust’s most distinct and compelling features, with which Rust developers should
become quite acquainted. Ownership is how Rust achieves its largest goal,
memory safety. There are a few distinct concepts, each with its own chapter:

Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/ownership.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% Ownership

This guide is one of three presenting Rust’s ownership system. This is one of
Rust’s most unique and compelling features, with which Rust developers should
This is the first of three sections presenting Rust’s ownership system. This is one of
Rust’s most distinct and compelling features, with which Rust developers should
become quite acquainted. Ownership is how Rust achieves its largest goal,
memory safety. There are a few distinct concepts, each with its own
chapter:
Expand Down
30 changes: 28 additions & 2 deletions src/doc/book/references-and-borrowing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% References and Borrowing

This guide is two of three presenting Rust’s ownership system. This is one of
Rust’s most unique and compelling features, with which Rust developers should
This is the second of three sections presenting Rust’s ownership system. This is one of
Rust’s most distinct and compelling features, with which Rust developers should
become quite acquainted. Ownership is how Rust achieves its largest goal,
memory safety. There are a few distinct concepts, each with its own
chapter:
Expand Down Expand Up @@ -77,6 +77,32 @@ let answer = foo(&v1, &v2);
// we can use v1 and v2 here!
```

A more concrete example:

```rust
fn main() {
// Don't worry if you don't understand how `fold` works, the point here is that an immutable reference is borrowed.
fn sum_vec(v: &Vec<i32>) -> i32 {
return v.iter().fold(0, |a, &b| a + b);
}
// Borrow two vectors and and sum them.
// This kind of borrowing does not allow mutation to the borrowed.
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
// do stuff with v1 and v2
let s1 = sum_vec(v1);
let s2 = sum_vec(v2);
// return the answer
s1 + s2
}

let v1 = vec![1, 2, 3];
let v2 = vec![4, 5, 6];

let answer = foo(&v1, &v2);
println!("{}", answer);
}
```

Instead of taking `Vec<i32>`s as our arguments, we take a reference:
`&Vec<i32>`. And instead of passing `v1` and `v2` directly, we pass `&v1` and
`&v2`. We call the `&T` type a ‘reference’, and rather than owning the resource,
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ impl<T: ?Sized> *mut T {
/// ```
/// let mut s = [1, 2, 3];
/// let ptr: *mut u32 = s.as_mut_ptr();
/// let first_value = unsafe { ptr.as_mut().unwrap() };
/// *first_value = 4;
/// println!("{:?}", s); // It'll print: "[4, 2, 3]".
/// ```
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
"scope of call-site for function"
}
region::CodeExtentData::ParameterScope { .. } => {
"scope of parameters for function"
"scope of function body"
}
region::CodeExtentData::DestructionScope(_) => {
new_string = format!("destruction scope surrounding {}", tag);
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_mir/build/expr/as_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a,'tcx> Builder<'a,'tcx> {
span_bug!(expr.span, "no temp_lifetime for expr");
}
};
this.schedule_drop(expr.span, temp_lifetime, &temp, expr_ty);
let expr_span = expr.span;

// Careful here not to cause an infinite cycle. If we always
// called `into`, then for lvalues like `x.f`, it would
Expand All @@ -52,7 +52,6 @@ impl<'a,'tcx> Builder<'a,'tcx> {
// course) `as_temp`.
match Category::of(&expr.kind).unwrap() {
Category::Lvalue => {
let expr_span = expr.span;
let lvalue = unpack!(block = this.as_lvalue(block, expr));
let rvalue = Rvalue::Use(Operand::Consume(lvalue));
let scope_id = this.innermost_scope_id();
Expand All @@ -63,6 +62,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
}
}

this.schedule_drop(expr_span, temp_lifetime, &temp, expr_ty);

block.and(temp)
}
}
4 changes: 2 additions & 2 deletions src/libstd/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ impl<T, S> HashSet<T, S>

/// Adds a value to the set.
///
/// If the set did not have a value present, `true` is returned.
/// If the set did not have this value present, `true` is returned.
///
/// If the set did have this key present, `false` is returned.
/// If the set did have this value present, `false` is returned.
///
/// # Examples
///
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,11 @@ pub enum InlineAttr {
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
attrs.iter().fold(InlineAttr::None, |ia,attr| {
match attr.node.value.node {
MetaItemKind::Word(ref n) if *n == "inline" => {
MetaItemKind::Word(ref n) if n == "inline" => {
mark_used(attr);
InlineAttr::Hint
}
MetaItemKind::List(ref n, ref items) if *n == "inline" => {
MetaItemKind::List(ref n, ref items) if n == "inline" => {
mark_used(attr);
if items.len() != 1 {
diagnostic.map(|d|{ d.span_err(attr.span, "expected one argument"); });
Expand Down Expand Up @@ -711,7 +711,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
let mut acc = Vec::new();
match attr.node.value.node {
ast::MetaItemKind::List(ref s, ref items) if *s == "repr" => {
ast::MetaItemKind::List(ref s, ref items) if s == "repr" => {
mark_used(attr);
for item in items {
match item.node {
Expand Down
22 changes: 22 additions & 0 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,28 @@ impl<'a> PartialEq<InternedString> for &'a str {
}
}

impl PartialEq<str> for InternedString {
#[inline(always)]
fn eq(&self, other: &str) -> bool {
PartialEq::eq(&self.string[..], other)
}
#[inline(always)]
fn ne(&self, other: &str) -> bool {
PartialEq::ne(&self.string[..], other)
}
}

impl PartialEq<InternedString> for str {
#[inline(always)]
fn eq(&self, other: &InternedString) -> bool {
PartialEq::eq(self, &other.string[..])
}
#[inline(always)]
fn ne(&self, other: &InternedString) -> bool {
PartialEq::ne(self, &other.string[..])
}
}

impl Decodable for InternedString {
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
Ok(intern(d.read_str()?.as_ref()).as_str())
Expand Down
3 changes: 0 additions & 3 deletions src/test/run-pass/issue-23338-ensure-param-drop-order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(rustc_attrs)]

// ignore-pretty : (#23623) problems when ending with // comments

// This test is ensuring that parameters are indeed dropped after
Expand Down Expand Up @@ -66,7 +64,6 @@ fn test<'a>(log: d::Log<'a>) {
d::println(&format!("result {}", result));
}

#[rustc_no_mir] // FIXME #29855 MIR doesn't handle all drops correctly.
fn foo<'a>(da0: D<'a>, de1: D<'a>) -> D<'a> {
d::println("entered foo");
let de2 = de1.incr(); // creates D(de_2, 2)
Expand Down