Skip to content

Commit 9f58fb7

Browse files
committed
Auto merge of #33658 - Manishearth:rollup, r=Manishearth
Rollup of 14 pull requests - Successful merges: #33342, #33393, #33415, #33475, #33517, #33533, #33534, #33565, #33580, #33584, #33585, #33590, #33591, #33598 - Failed merges: #33578
2 parents b358319 + 95ace6b commit 9f58fb7

File tree

26 files changed

+619
-43
lines changed

26 files changed

+619
-43
lines changed

src/liballoc/boxed.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,16 @@ impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
525525
/// }
526526
/// ```
527527
#[rustc_paren_sugar]
528-
#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
528+
#[unstable(feature = "fnbox",
529+
reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
529530
pub trait FnBox<A> {
530531
type Output;
531532

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

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

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

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

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

src/libcollections/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ use boxed::Box;
184184
/// let len = story.len();
185185
/// let capacity = story.capacity();
186186
///
187-
/// // story has thirteen bytes
187+
/// // story has nineteen bytes
188188
/// assert_eq!(19, len);
189189
///
190190
/// // Now that we have our parts, we throw the story away.

src/libcore/sync/atomic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ pub enum Ordering {
142142
#[stable(feature = "rust1", since = "1.0.0")]
143143
Relaxed,
144144
/// When coupled with a store, all previous writes become visible
145-
/// to another thread that performs a load with `Acquire` ordering
145+
/// to the other threads that perform a load with `Acquire` ordering
146146
/// on the same value.
147147
#[stable(feature = "rust1", since = "1.0.0")]
148148
Release,
149149
/// When coupled with a load, all subsequent loads will see data
150150
/// written before a store with `Release` ordering on the same value
151-
/// in another thread.
151+
/// in other threads.
152152
#[stable(feature = "rust1", since = "1.0.0")]
153153
Acquire,
154154
/// When coupled with a load, uses `Acquire` ordering, and with a store

src/librustc_borrowck/diagnostics.rs

+126-2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,53 @@ let c = &i; // still ok!
378378
```
379379
"##,
380380

381+
E0500: r##"
382+
A borrowed variable was used in another closure. Example of erroneous code:
383+
384+
```compile_fail
385+
fn you_know_nothing(jon_snow: &mut i32) {
386+
let nights_watch = || {
387+
*jon_snow = 2;
388+
};
389+
let starks = || {
390+
*jon_snow = 3; // error: closure requires unique access to `jon_snow`
391+
// but it is already borrowed
392+
};
393+
}
394+
395+
In here, `jon_snow` is already borrowed by the `nights_watch` closure, so it
396+
cannot be borrowed by the `starks` closure at the same time. To fix this issue,
397+
you can put the closure in its own scope:
398+
399+
```
400+
fn you_know_nothing(jon_snow: &mut i32) {
401+
{
402+
let nights_watch = || {
403+
*jon_snow = 2;
404+
};
405+
} // At this point, `jon_snow` is free.
406+
let starks = || {
407+
*jon_snow = 3;
408+
};
409+
}
410+
```
411+
412+
Or, if the type implements the `Clone` trait, you can clone it between
413+
closures:
414+
415+
```
416+
fn you_know_nothing(jon_snow: &mut i32) {
417+
let mut jon_copy = jon_snow.clone();
418+
let nights_watch = || {
419+
jon_copy = 2;
420+
};
421+
let starks = || {
422+
*jon_snow = 3;
423+
};
424+
}
425+
```
426+
"##,
427+
381428
E0501: r##"
382429
This error indicates that a mutable variable is being used while it is still
383430
captured by a closure. Because the closure has borrowed the variable, it is not
@@ -642,6 +689,85 @@ fn print_fancy_ref(fancy_ref: &FancyNum){
642689
```
643690
"##,
644691

692+
E0505: r##"
693+
A value was moved out while it was still borrowed.
694+
Erroneous code example:
695+
696+
```compile_fail
697+
struct Value {}
698+
699+
fn eat(val: Value) {}
700+
701+
fn main() {
702+
let x = Value{};
703+
{
704+
let _ref_to_val: &Value = &x;
705+
eat(x);
706+
}
707+
}
708+
```
709+
710+
Here, the function `eat` takes the ownership of `x`. However,
711+
`x` cannot be moved because it was borrowed to `_ref_to_val`.
712+
To fix that you can do few different things:
713+
714+
* Try to avoid moving the variable.
715+
* Release borrow before move.
716+
* Implement the `Copy` trait on the type.
717+
718+
Examples:
719+
720+
```
721+
struct Value {}
722+
723+
fn eat(val: &Value) {}
724+
725+
fn main() {
726+
let x = Value{};
727+
{
728+
let _ref_to_val: &Value = &x;
729+
eat(&x); // pass by reference, if it's possible
730+
}
731+
}
732+
```
733+
734+
Or:
735+
736+
```
737+
struct Value {}
738+
739+
fn eat(val: Value) {}
740+
741+
fn main() {
742+
let x = Value{};
743+
{
744+
let _ref_to_val: &Value = &x;
745+
}
746+
eat(x); // release borrow and then move it.
747+
}
748+
```
749+
750+
Or:
751+
752+
```
753+
#[derive(Clone, Copy)] // implement Copy trait
754+
struct Value {}
755+
756+
fn eat(val: Value) {}
757+
758+
fn main() {
759+
let x = Value{};
760+
{
761+
let _ref_to_val: &Value = &x;
762+
eat(x); // it will be copied here.
763+
}
764+
}
765+
```
766+
767+
You can find more information about borrowing in the rust-book:
768+
http://doc.rust-lang.org/stable/book/references-and-borrowing.html
769+
"##,
770+
645771
E0507: r##"
646772
You tried to move out of a value which was borrowed. Erroneous code example:
647773
@@ -857,10 +983,8 @@ fn main() {
857983
register_diagnostics! {
858984
E0385, // {} in an aliasable location
859985
E0388, // {} in a static location
860-
E0500, // closure requires unique access to `..` but .. is already borrowed
861986
E0502, // cannot borrow `..`.. as .. because .. is also borrowed as ...
862987
E0503, // cannot use `..` because it was mutably borrowed
863-
E0505, // cannot move out of `..` because it is borrowed
864988
E0508, // cannot move out of type `..`, a non-copy fixed-size array
865989
E0524, // two closures require unique access to `..` at the same time
866990
}

src/librustc_const_eval/diagnostics.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ fn foo(x: Empty) {
6262
However, this won't:
6363
6464
```compile_fail
65-
enum Empty {}
66-
6765
fn foo(x: Option<String>) {
6866
match x {
6967
// empty
@@ -191,7 +189,7 @@ inner `String` to be moved into a variable called `s`.
191189
let x = Some("s".to_string());
192190
193191
match x {
194-
op_string @ Some(s) => {},
192+
op_string @ Some(s) => {}, // error: cannot bind by-move with sub-bindings
195193
None => {},
196194
}
197195
```
@@ -288,7 +286,8 @@ struct X { x: (), }
288286
289287
let x = Some((X { x: () }, X { x: () }));
290288
match x {
291-
Some((y, ref z)) => {},
289+
Some((y, ref z)) => {}, // error: cannot bind by-move and by-ref in the
290+
// same pattern
292291
None => panic!()
293292
}
294293
```
@@ -574,6 +573,12 @@ be a compile-time constant. Erroneous code example:
574573
let x = [0i32; len]; // error: expected constant integer for repeat count,
575574
// found variable
576575
```
576+
577+
Working example:
578+
579+
```
580+
let x = [0i32; 10];
581+
```
577582
"##,
578583

579584
}

src/librustc_metadata/diagnostics.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ name. Example:
2626
```
2727
"##,
2828

29+
E0455: r##"
30+
Linking with `kind=framework` is only supported when targeting OS X,
31+
as frameworks are specific to that operating system.
32+
33+
Erroneous code example:
34+
35+
```compile_fail"
36+
#[link(name = "FooCoreServices", kind = "framework")] extern {}
37+
// OS used to compile is Linux for example
38+
```
39+
40+
To solve this error you can use conditional compilation:
41+
42+
```
43+
#[cfg_attr(target="macos", link(name = "FooCoreServices", kind = "framework"))]
44+
extern {}
45+
```
46+
47+
See more: https://doc.rust-lang.org/book/conditional-compilation.html
48+
"##,
49+
2950
E0458: r##"
3051
An unknown "kind" was specified for a link attribute. Erroneous code example:
3152
@@ -73,7 +94,6 @@ well, and you link to them the same way.
7394
}
7495

7596
register_diagnostics! {
76-
E0455, // native frameworks are only available on OSX targets
7797
E0456, // plugin `..` is not available for triple `..`
7898
E0457, // plugin `..` only found in rlib format, but must be available...
7999
E0514, // metadata version mismatch

src/librustc_typeck/check/method/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
8484
span: Span,
8585
method_name: ast::Name,
8686
self_ty: ty::Ty<'tcx>,
87-
call_expr_id: ast::NodeId)
87+
call_expr_id: ast::NodeId,
88+
allow_private: bool)
8889
-> bool
8990
{
9091
let mode = probe::Mode::MethodCall;
@@ -93,7 +94,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
9394
Err(NoMatch(..)) => false,
9495
Err(Ambiguity(..)) => true,
9596
Err(ClosureAmbiguity(..)) => true,
96-
Err(PrivateMatch(..)) => true,
97+
Err(PrivateMatch(..)) => allow_private,
9798
}
9899
}
99100

src/librustc_typeck/check/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -3053,12 +3053,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30533053

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

3310-
self.check_expr_struct_fields(expr_ty, expr.span, variant, fields,
3316+
self.check_expr_struct_fields(expr_ty, path.span, variant, fields,
33113317
base_expr.is_none());
33123318
if let &Some(ref base_expr) = base_expr {
33133319
self.check_expr_has_type(base_expr, expr_ty);

0 commit comments

Comments
 (0)