Skip to content

Commit

Permalink
Auto merge of #33658 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
Rollup of 14 pull requests

- Successful merges: #33342, #33393, #33415, #33475, #33517, #33533, #33534, #33565, #33580, #33584, #33585, #33590, #33591, #33598
- Failed merges: #33578
  • Loading branch information
bors committed May 15, 2016
2 parents b358319 + 95ace6b commit 9f58fb7
Show file tree
Hide file tree
Showing 26 changed files with 619 additions and 43 deletions.
12 changes: 8 additions & 4 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,16 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
/// }
/// ```
#[rustc_paren_sugar]
#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
#[unstable(feature = "fnbox",
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
pub trait FnBox<A> {
type Output;

fn call_box(self: Box<Self>, args: A) -> Self::Output;
}

#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
#[unstable(feature = "fnbox",
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
impl<A, F> FnBox<A> for F where F: FnOnce<A>
{
type Output = F::Output;
Expand All @@ -542,7 +544,8 @@ impl<A, F> FnBox<A> for F where F: FnOnce<A>
}
}

#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
#[unstable(feature = "fnbox",
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
type Output = R;

Expand All @@ -551,7 +554,8 @@ impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
}
}

#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
#[unstable(feature = "fnbox",
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
type Output = R;

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ use boxed::Box;
/// let len = story.len();
/// let capacity = story.capacity();
///
/// // story has thirteen bytes
/// // story has nineteen bytes
/// assert_eq!(19, len);
///
/// // Now that we have our parts, we throw the story away.
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/sync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ pub enum Ordering {
#[stable(feature = "rust1", since = "1.0.0")]
Relaxed,
/// When coupled with a store, all previous writes become visible
/// to another thread that performs a load with `Acquire` ordering
/// to the other threads that perform a load with `Acquire` ordering
/// on the same value.
#[stable(feature = "rust1", since = "1.0.0")]
Release,
/// When coupled with a load, all subsequent loads will see data
/// written before a store with `Release` ordering on the same value
/// in another thread.
/// in other threads.
#[stable(feature = "rust1", since = "1.0.0")]
Acquire,
/// When coupled with a load, uses `Acquire` ordering, and with a store
Expand Down
128 changes: 126 additions & 2 deletions src/librustc_borrowck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,53 @@ let c = &i; // still ok!
```
"##,

E0500: r##"
A borrowed variable was used in another closure. Example of erroneous code:
```compile_fail
fn you_know_nothing(jon_snow: &mut i32) {
let nights_watch = || {
*jon_snow = 2;
};
let starks = || {
*jon_snow = 3; // error: closure requires unique access to `jon_snow`
// but it is already borrowed
};
}
In here, `jon_snow` is already borrowed by the `nights_watch` closure, so it
cannot be borrowed by the `starks` closure at the same time. To fix this issue,
you can put the closure in its own scope:
```
fn you_know_nothing(jon_snow: &mut i32) {
{
let nights_watch = || {
*jon_snow = 2;
};
} // At this point, `jon_snow` is free.
let starks = || {
*jon_snow = 3;
};
}
```
Or, if the type implements the `Clone` trait, you can clone it between
closures:
```
fn you_know_nothing(jon_snow: &mut i32) {
let mut jon_copy = jon_snow.clone();
let nights_watch = || {
jon_copy = 2;
};
let starks = || {
*jon_snow = 3;
};
}
```
"##,

E0501: r##"
This error indicates that a mutable variable is being used while it is still
captured by a closure. Because the closure has borrowed the variable, it is not
Expand Down Expand Up @@ -642,6 +689,85 @@ fn print_fancy_ref(fancy_ref: &FancyNum){
```
"##,

E0505: r##"
A value was moved out while it was still borrowed.
Erroneous code example:
```compile_fail
struct Value {}
fn eat(val: Value) {}
fn main() {
let x = Value{};
{
let _ref_to_val: &Value = &x;
eat(x);
}
}
```
Here, the function `eat` takes the ownership of `x`. However,
`x` cannot be moved because it was borrowed to `_ref_to_val`.
To fix that you can do few different things:
* Try to avoid moving the variable.
* Release borrow before move.
* Implement the `Copy` trait on the type.
Examples:
```
struct Value {}
fn eat(val: &Value) {}
fn main() {
let x = Value{};
{
let _ref_to_val: &Value = &x;
eat(&x); // pass by reference, if it's possible
}
}
```
Or:
```
struct Value {}
fn eat(val: Value) {}
fn main() {
let x = Value{};
{
let _ref_to_val: &Value = &x;
}
eat(x); // release borrow and then move it.
}
```
Or:
```
#[derive(Clone, Copy)] // implement Copy trait
struct Value {}
fn eat(val: Value) {}
fn main() {
let x = Value{};
{
let _ref_to_val: &Value = &x;
eat(x); // it will be copied here.
}
}
```
You can find more information about borrowing in the rust-book:
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
"##,

E0507: r##"
You tried to move out of a value which was borrowed. Erroneous code example:
Expand Down Expand Up @@ -857,10 +983,8 @@ fn main() {
register_diagnostics! {
E0385, // {} in an aliasable location
E0388, // {} in a static location
E0500, // closure requires unique access to `..` but .. is already borrowed
E0502, // cannot borrow `..`.. as .. because .. is also borrowed as ...
E0503, // cannot use `..` because it was mutably borrowed
E0505, // cannot move out of `..` because it is borrowed
E0508, // cannot move out of type `..`, a non-copy fixed-size array
E0524, // two closures require unique access to `..` at the same time
}
13 changes: 9 additions & 4 deletions src/librustc_const_eval/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ fn foo(x: Empty) {
However, this won't:
```compile_fail
enum Empty {}
fn foo(x: Option<String>) {
match x {
// empty
Expand Down Expand Up @@ -191,7 +189,7 @@ inner `String` to be moved into a variable called `s`.
let x = Some("s".to_string());
match x {
op_string @ Some(s) => {},
op_string @ Some(s) => {}, // error: cannot bind by-move with sub-bindings
None => {},
}
```
Expand Down Expand Up @@ -288,7 +286,8 @@ struct X { x: (), }
let x = Some((X { x: () }, X { x: () }));
match x {
Some((y, ref z)) => {},
Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the
// same pattern
None => panic!()
}
```
Expand Down Expand Up @@ -574,6 +573,12 @@ be a compile-time constant. Erroneous code example:
let x = [0i32; len]; // error: expected constant integer for repeat count,
// found variable
```
Working example:
```
let x = [0i32; 10];
```
"##,

}
Expand Down
22 changes: 21 additions & 1 deletion src/librustc_metadata/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ name. Example:
```
"##,

E0455: r##"
Linking with `kind=framework` is only supported when targeting OS X,
as frameworks are specific to that operating system.
Erroneous code example:
```compile_fail"
#[link(name = "FooCoreServices", kind = "framework")] extern {}
// OS used to compile is Linux for example
```
To solve this error you can use conditional compilation:
```
#[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))]
extern {}
```
See more: https://doc.rust-lang.org/book/conditional-compilation.html
"##,

E0458: r##"
An unknown "kind" was specified for a link attribute. Erroneous code example:
Expand Down Expand Up @@ -73,7 +94,6 @@ well, and you link to them the same way.
}

register_diagnostics! {
E0455, // native frameworks are only available on OSX targets
E0456, // plugin `..` is not available for triple `..`
E0457, // plugin `..` only found in rlib format, but must be available...
E0514, // metadata version mismatch
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_typeck/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
span: Span,
method_name: ast::Name,
self_ty: ty::Ty<'tcx>,
call_expr_id: ast::NodeId)
call_expr_id: ast::NodeId,
allow_private: bool)
-> bool
{
let mode = probe::Mode::MethodCall;
Expand All @@ -93,7 +94,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Err(NoMatch(..)) => false,
Err(Ambiguity(..)) => true,
Err(ClosureAmbiguity(..)) => true,
Err(PrivateMatch(..)) => true,
Err(PrivateMatch(..)) => allow_private,
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3053,12 +3053,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

if let Some((did, field_ty)) = private_candidate {
let struct_path = self.tcx().item_path_str(did);
let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
self.tcx().sess.span_err(expr.span, &msg);
self.write_ty(expr.id, field_ty);
let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
let mut err = self.tcx().sess.struct_span_err(expr.span, &msg);
// Also check if an accessible method exists, which is often what is meant.
if self.method_exists(field.span, field.node, expr_t, expr.id, false) {
err.note(&format!("a method `{}` also exists, perhaps you wish to call it",
field.node));
}
err.emit();
} else if field.node == keywords::Invalid.name() {
self.write_error(expr.id);
} else if self.method_exists(field.span, field.node, expr_t, expr.id) {
} else if self.method_exists(field.span, field.node, expr_t, expr.id, true) {
self.type_error_struct(field.span, |actual| {
format!("attempted to take value of method `{}` on type \
`{}`", field.node, actual)
Expand Down Expand Up @@ -3307,7 +3313,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let expr_ty = self.instantiate_type(def.def_id(), path);
self.write_ty(expr.id, expr_ty);

self.check_expr_struct_fields(expr_ty, expr.span, variant, fields,
self.check_expr_struct_fields(expr_ty, path.span, variant, fields,
base_expr.is_none());
if let &Some(ref base_expr) = base_expr {
self.check_expr_has_type(base_expr, expr_ty);
Expand Down
Loading

0 comments on commit 9f58fb7

Please sign in to comment.