Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f58fb7

Browse files
committedMay 15, 2016
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

Lines changed: 8 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 126 additions & 2 deletions
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 21 additions & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 10 additions & 4 deletions
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);

‎src/librustc_typeck/diagnostics.rs

Lines changed: 162 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Matching with the wrong number of fields has no sensible interpretation:
4545
4646
```compile_fail
4747
enum Fruit {
48-
Apple(String, String),
49-
Pear(u32),
48+
Fruit::Apple(String, String),
49+
Fruit::Pear(u32),
5050
}
5151
5252
let x = Fruit::Apple(String::new(), String::new());
@@ -77,8 +77,8 @@ enum Number {
7777
7878
// Assuming x is a Number we can pattern match on its contents.
7979
match x {
80-
Zero(inside) => {},
81-
One(inside) => {},
80+
Number::Zero(inside) => {},
81+
Number::One(inside) => {},
8282
}
8383
```
8484
@@ -3284,6 +3284,164 @@ impl Baz for Bar { } // Note: This is OK
32843284
```
32853285
"##,
32863286

3287+
E0374: r##"
3288+
A struct without a field containing an unsized type cannot implement
3289+
`CoerceUnsized`. An
3290+
[unsized type](https://doc.rust-lang.org/book/unsized-types.html)
3291+
is any type that the compiler doesn't know the length or alignment of at
3292+
compile time. Any struct containing an unsized type is also unsized.
3293+
3294+
Example of erroneous code:
3295+
3296+
```compile_fail
3297+
#![feature(coerce_unsized)]
3298+
use std::ops::CoerceUnsized;
3299+
3300+
struct Foo<T: ?Sized> {
3301+
a: i32,
3302+
}
3303+
3304+
// error: Struct `Foo` has no unsized fields that need `CoerceUnsized`.
3305+
impl<T, U> CoerceUnsized<Foo<U>> for Foo<T>
3306+
where T: CoerceUnsized<U> {}
3307+
```
3308+
3309+
`CoerceUnsized` is used to coerce one struct containing an unsized type
3310+
into another struct containing a different unsized type. If the struct
3311+
doesn't have any fields of unsized types then you don't need explicit
3312+
coercion to get the types you want. To fix this you can either
3313+
not try to implement `CoerceUnsized` or you can add a field that is
3314+
unsized to the struct.
3315+
3316+
Example:
3317+
3318+
```
3319+
#![feature(coerce_unsized)]
3320+
use std::ops::CoerceUnsized;
3321+
3322+
// We don't need to impl `CoerceUnsized` here.
3323+
struct Foo {
3324+
a: i32,
3325+
}
3326+
3327+
// We add the unsized type field to the struct.
3328+
struct Bar<T: ?Sized> {
3329+
a: i32,
3330+
b: T,
3331+
}
3332+
3333+
// The struct has an unsized field so we can implement
3334+
// `CoerceUnsized` for it.
3335+
impl<T, U> CoerceUnsized<Bar<U>> for Bar<T>
3336+
where T: CoerceUnsized<U> {}
3337+
```
3338+
3339+
Note that `CoerceUnsized` is mainly used by smart pointers like `Box`, `Rc`
3340+
and `Arc` to be able to mark that they can coerce unsized types that they
3341+
are pointing at.
3342+
"##,
3343+
3344+
E0375: r##"
3345+
A struct with more than one field containing an unsized type cannot implement
3346+
`CoerceUnsized`. This only occurs when you are trying to coerce one of the
3347+
types in your struct to another type in the struct. In this case we try to
3348+
impl `CoerceUnsized` from `T` to `U` which are both types that the struct
3349+
takes. An [unsized type](https://doc.rust-lang.org/book/unsized-types.html)
3350+
is any type that the compiler doesn't know the length or alignment of at
3351+
compile time. Any struct containing an unsized type is also unsized.
3352+
3353+
Example of erroneous code:
3354+
3355+
```compile_fail
3356+
#![feature(coerce_unsized)]
3357+
use std::ops::CoerceUnsized;
3358+
3359+
struct Foo<T: ?Sized, U: ?Sized> {
3360+
a: i32,
3361+
b: T,
3362+
c: U,
3363+
}
3364+
3365+
// error: Struct `Foo` has more than one unsized field.
3366+
impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {}
3367+
```
3368+
3369+
`CoerceUnsized` only allows for coercion from a structure with a single
3370+
unsized type field to another struct with a single unsized type field.
3371+
In fact Rust only allows for a struct to have one unsized type in a struct
3372+
and that unsized type must be the last field in the struct. So having two
3373+
unsized types in a single struct is not allowed by the compiler. To fix this
3374+
use only one field containing an unsized type in the struct and then use
3375+
multiple structs to manage each unsized type field you need.
3376+
3377+
Example:
3378+
3379+
```
3380+
#![feature(coerce_unsized)]
3381+
use std::ops::CoerceUnsized;
3382+
3383+
struct Foo<T: ?Sized> {
3384+
a: i32,
3385+
b: T,
3386+
}
3387+
3388+
impl <T, U> CoerceUnsized<Foo<U>> for Foo<T>
3389+
where T: CoerceUnsized<U> {}
3390+
3391+
fn coerce_foo<T: CoerceUnsized<U>, U>(t: T) -> Foo<U> {
3392+
Foo { a: 12i32, b: t } // we use coercion to get the `Foo<U>` type we need
3393+
}
3394+
```
3395+
3396+
"##,
3397+
3398+
E0376: r##"
3399+
The type you are trying to impl `CoerceUnsized` for is not a struct.
3400+
`CoerceUnsized` can only be implemented for a struct. Unsized types are
3401+
already able to be coerced without an implementation of `CoerceUnsized`
3402+
whereas a struct containing an unsized type needs to know the unsized type
3403+
field it's containing is able to be coerced. An
3404+
[unsized type](https://doc.rust-lang.org/book/unsized-types.html)
3405+
is any type that the compiler doesn't know the length or alignment of at
3406+
compile time. Any struct containing an unsized type is also unsized.
3407+
3408+
Example of erroneous code:
3409+
3410+
```compile_fail
3411+
#![feature(coerce_unsized)]
3412+
use std::ops::CoerceUnsized;
3413+
3414+
struct Foo<T: ?Sized> {
3415+
a: T,
3416+
}
3417+
3418+
// error: The type `U` is not a struct
3419+
impl<T, U> CoerceUnsized<U> for Foo<T> {}
3420+
```
3421+
3422+
The `CoerceUnsized` trait takes a struct type. Make sure the type you are
3423+
providing to `CoerceUnsized` is a struct with only the last field containing an
3424+
unsized type.
3425+
3426+
Example:
3427+
3428+
```
3429+
#![feature(coerce_unsized)]
3430+
use std::ops::CoerceUnsized;
3431+
3432+
struct Foo<T> {
3433+
a: T,
3434+
}
3435+
3436+
// The `Foo<U>` is a struct so `CoerceUnsized` can be implemented
3437+
impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {}
3438+
```
3439+
3440+
Note that in Rust, structs can only contain an unsized type if the field
3441+
containing the unsized type is the last and only unsized type field in the
3442+
struct.
3443+
"##,
3444+
32873445
E0379: r##"
32883446
Trait methods cannot be declared `const` by design. For more information, see
32893447
[RFC 911].
@@ -3777,13 +3935,6 @@ register_diagnostics! {
37773935
E0320, // recursive overflow during dropck
37783936
E0328, // cannot implement Unsize explicitly
37793937
// E0372, // coherence not object safe
3780-
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
3781-
// between structures with one field being coerced, none found
3782-
E0375, // the trait `CoerceUnsized` may only be implemented for a coercion
3783-
// between structures with one field being coerced, but multiple
3784-
// fields need coercions
3785-
E0376, // the trait `CoerceUnsized` may only be implemented for a coercion
3786-
// between structures
37873938
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
37883939
// between structures with the same definition
37893940
E0399, // trait items need to be implemented because the associated

‎src/libstd/env.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,16 @@ pub fn home_dir() -> Option<PathBuf> {
452452

453453
/// Returns the path of a temporary directory.
454454
///
455-
/// On Unix, returns the value of the 'TMPDIR' environment variable if it is
456-
/// set, otherwise for non-Android it returns '/tmp'. If Android, since there
457-
/// is no global temporary folder (it is usually allocated per-app), we return
458-
/// '/data/local/tmp'.
459-
///
460-
/// On Windows, returns the value of, in order, the 'TMP', 'TEMP',
461-
/// 'USERPROFILE' environment variable if any are set and not the empty
462-
/// string. Otherwise, tmpdir returns the path of the Windows directory. This
463-
/// behavior is identical to that of [GetTempPath][msdn], which this function
464-
/// uses internally.
455+
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
456+
/// set, otherwise for non-Android it returns `/tmp`. If Android, since there
457+
/// is no global temporary folder (it is usually allocated per-app), it returns
458+
/// `/data/local/tmp`.
459+
///
460+
/// On Windows, returns the value of, in order, the `TMP`, `TEMP`,
461+
/// `USERPROFILE` environment variable if any are set and not the empty
462+
/// string. Otherwise, `temp_dir` returns the path of the Windows directory.
463+
/// This behavior is identical to that of [`GetTempPath`][msdn], which this
464+
/// function uses internally.
465465
///
466466
/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx
467467
///

‎src/libstd/sync/once.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ impl Once {
218218
/// The closure `f` is yielded a structure which can be used to query the
219219
/// state of this `Once` (whether initialization has previously panicked or
220220
/// not).
221-
/// poisoned or not.
222221
#[unstable(feature = "once_poison", issue = "31688")]
223222
pub fn call_once_force<F>(&'static self, f: F) where F: FnOnce(&OnceState) {
224223
// same as above, just with a different parameter to `call_inner`.

‎src/libstd/time/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct Instant(time::Instant);
7676
/// Distinct from the `Instant` type, this time measurement **is not
7777
/// monotonic**. This means that you can save a file to the file system, then
7878
/// save another file to the file system, **and the second file has a
79-
/// `SystemTime` measurement earlier than the second**. In other words, an
79+
/// `SystemTime` measurement earlier than the first**. In other words, an
8080
/// operation that happens after another operation in real time may have an
8181
/// earlier `SystemTime`!
8282
///

‎src/test/compile-fail/E0001.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let foo = Some(1);
13+
match foo {
14+
Some(bar) => {/* ... */}
15+
None => {/* ... */}
16+
_ => {/* ... */} //~ ERROR E0001
17+
}
18+
}

‎src/test/compile-fail/E0002.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = Some(1);
13+
14+
match x { } //~ ERROR E0002
15+
}

‎src/test/compile-fail/E0004.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Terminator {
12+
HastaLaVistaBaby,
13+
TalkToMyHand,
14+
}
15+
16+
fn main() {
17+
let x = Terminator::HastaLaVistaBaby;
18+
19+
match x { //~ ERROR E0004
20+
Terminator::TalkToMyHand => {}
21+
}
22+
}

‎src/test/compile-fail/E0005.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = Some(1);
13+
let Some(y) = x; //~ ERROR E0005
14+
}

‎src/test/compile-fail/E0007.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = Some("s".to_string());
13+
match x {
14+
op_string @ Some(s) => {}, //~ ERROR E0007
15+
//~| ERROR E0303
16+
None => {},
17+
}
18+
}

‎src/test/compile-fail/E0008.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
match Some("hi".to_string()) {
13+
Some(s) if s.len() == 0 => {}, //~ ERROR E0008
14+
_ => {},
15+
}
16+
}

‎src/test/compile-fail/E0009.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
struct X { x: (), }
13+
let x = Some((X { x: () }, X { x: () }));
14+
match x {
15+
Some((y, ref z)) => {}, //~ ERROR E0009
16+
None => panic!()
17+
}
18+
}

‎src/test/compile-fail/E0010.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(box_syntax)]
12+
13+
const CON : Box<i32> = box 0; //~ ERROR E0010
14+
15+
fn main() {}

‎src/test/compile-fail/E0017.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
static X: i32 = 1;
12+
const C: i32 = 2;
13+
14+
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
15+
//~| ERROR E0017
16+
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
17+
//~| ERROR E0017
18+
//~| ERROR E0388
19+
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
20+
//~| ERROR E0017
21+
22+
fn main() {}

‎src/test/compile-fail/E0023.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Fruit {
12+
Apple(String, String),
13+
Pear(u32),
14+
}
15+
16+
fn main() {
17+
let x = Fruit::Apple(String::new(), String::new());
18+
match x {
19+
Fruit::Apple(a) => {}, //~ ERROR E0023
20+
Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
21+
}
22+
}

‎src/test/compile-fail/E0024.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Number {
12+
Zero,
13+
One(u32)
14+
}
15+
16+
fn main() {
17+
let x = Number::Zero;
18+
match x {
19+
Number::Zero(inside) => {}, //~ ERROR E0024
20+
Number::One(inside) => {},
21+
}
22+
}

‎src/test/compile-fail/E0025.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Foo {
12+
a: u8,
13+
b: u8,
14+
}
15+
16+
fn main() {
17+
let x = Foo { a:1, b:2 };
18+
let Foo { a: x, a: y, b: 0 } = x; //~ ERROR E0025
19+
}

‎src/test/compile-fail/E0026.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Thing {
12+
x: u32,
13+
y: u32
14+
}
15+
16+
fn main() {
17+
let thing = Thing { x: 0, y: 0 };
18+
match thing {
19+
Thing { x, y, z } => {} //~ ERROR E0026
20+
}
21+
}

‎src/test/compile-fail/issue-26472.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
mod sub {
12+
pub struct S { len: usize }
13+
impl S {
14+
pub fn new() -> S { S { len: 0 } }
15+
pub fn len(&self) -> usize { self.len }
16+
}
17+
}
18+
19+
fn main() {
20+
let s = sub::S::new();
21+
let v = s.len;
22+
//~^ ERROR field `len` of struct `sub::S` is private
23+
//~| NOTE a method `len` also exists, perhaps you wish to call it
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.