Skip to content

Commit 4db1249

Browse files
author
Nick Hamann
committed
---
yaml --- r: 207083 b: refs/heads/master c: c69a152 h: refs/heads/master i: 207081: 8abd788 207079: 7ec1def v: v3
1 parent b5189a2 commit 4db1249

File tree

10 files changed

+156
-55
lines changed

10 files changed

+156
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 84b1e084862c08c19c36f0cf1f3698343c8ba7fa
2+
refs/heads/master: c69a152018de3c70e949f758d59e6aa86e19e9d4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 857ef6e272e5634cb9f3e6ee50eb6bc2a2e71651
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f

trunk/src/doc/trpl/closures.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ The second is that the syntax is similar, but a bit different. I’ve added spac
5454
here to make them look a little closer:
5555

5656
```rust
57-
fn plus_one_v1 (x: i32) -> i32 { x + 1 }
58-
let plus_one_v2 = |x: i32| -> i32 { x + 1 };
59-
let plus_one_v3 = |x: i32| x + 1 ;
57+
fn plus_one_v1 (x: i32 ) -> i32 { x + 1 }
58+
let plus_one_v2 = |x: i32 | -> i32 { x + 1 };
59+
let plus_one_v3 = |x: i32 | x + 1 ;
6060
```
6161

6262
Small differences, but they’re similar in ways.
@@ -136,7 +136,7 @@ This gives us:
136136
note: `nums` moved into closure environment here because it has type
137137
`[closure(()) -> collections::vec::Vec<i32>]`, which is non-copyable
138138
let takes_nums = || nums;
139-
^~~~~~~
139+
^~~~~~~
140140
```
141141

142142
`Vec<T>` has ownership over its contents, and therefore, when we refer to it
@@ -352,8 +352,8 @@ error: the trait `core::marker::Sized` is not implemented for the type
352352
factory() -> (Fn(i32) -> Vec<i32>) {
353353
^~~~~~~~~~~~~~~~~~~~~
354354
note: `core::ops::Fn(i32) -> collections::vec::Vec<i32>` does not have a constant size known at compile-time
355-
factory() -> (Fn(i32) -> Vec<i32>) {
356-
^~~~~~~~~~~~~~~~~~~~~
355+
fa ctory() -> (Fn(i32) -> Vec<i32>) {
356+
^~~~~~~~~~~~~~~~~~~~~
357357
358358
```
359359

trunk/src/doc/trpl/references-and-borrowing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ We can’t modify `v` because it’s borrowed by the loop.
297297
References must live as long as the resource they refer to. Rust will check the
298298
scopes of your references to ensure that this is true.
299299

300-
If Rust didn’t check this property, we could accidentally use a reference
300+
If Rust didn’t check that this property, we could accidentally use a reference
301301
which was invalid. For example:
302302

303303
```rust,ignore

trunk/src/grammar/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
111111
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None),
112112
"QUESTION" => token::Question,
113113
"SHEBANG" => token::Shebang(Name(0)),
114-
_ => continue,
114+
_ => panic!("Bad token str `{}`", val),
115115
};
116116

117117
res.insert(num.to_string(), tok);

trunk/src/librustc/middle/const_eval.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -34,7 +34,7 @@ use std::borrow::{Cow, IntoCow};
3434
use std::num::wrapping::OverflowingOps;
3535
use std::cmp::Ordering;
3636
use std::collections::hash_map::Entry::Vacant;
37-
use std::{i8, i16, i32, i64, u8, u16, u32, u64};
37+
use std::{i8, i16, i32, i64};
3838
use std::rc::Rc;
3939

4040
fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> {
@@ -461,16 +461,6 @@ pub fn const_uint_checked_neg<'a>(
461461
Ok(const_uint((!a).wrapping_add(1)))
462462
}
463463

464-
fn const_uint_not(a: u64, opt_ety: Option<UintTy>) -> const_val {
465-
let mask = match opt_ety {
466-
Some(UintTy::U8) => u8::MAX as u64,
467-
Some(UintTy::U16) => u16::MAX as u64,
468-
Some(UintTy::U32) => u32::MAX as u64,
469-
None | Some(UintTy::U64) => u64::MAX,
470-
};
471-
const_uint(!a & mask)
472-
}
473-
474464
macro_rules! overflow_checking_body {
475465
($a:ident, $b:ident, $ety:ident, $overflowing_op:ident,
476466
lhs: $to_8_lhs:ident $to_16_lhs:ident $to_32_lhs:ident,
@@ -687,7 +677,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
687677
ast::ExprUnary(ast::UnNot, ref inner) => {
688678
match try!(eval_const_expr_partial(tcx, &**inner, ety)) {
689679
const_int(i) => const_int(!i),
690-
const_uint(i) => const_uint_not(i, expr_uint_type),
680+
const_uint(i) => const_uint(!i),
691681
const_bool(b) => const_bool(!b),
692682
const_str(_) => signal!(e, NotOnString),
693683
const_float(_) => signal!(e, NotOnFloat),

trunk/src/librustc_typeck/check/mod.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,10 +3153,26 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
31533153
Some(&**oprnd), oprnd_t, lvalue_pref) {
31543154
Some(mt) => mt.ty,
31553155
None => {
3156-
fcx.type_error_message(expr.span, |actual| {
3157-
format!("type `{}` cannot be \
3158-
dereferenced", actual)
3159-
}, oprnd_t, None);
3156+
let is_newtype = match oprnd_t.sty {
3157+
ty::ty_struct(did, substs) => {
3158+
let fields = ty::struct_fields(fcx.tcx(), did, substs);
3159+
fields.len() == 1
3160+
&& fields[0].name ==
3161+
token::special_idents::unnamed_field.name
3162+
}
3163+
_ => false
3164+
};
3165+
if is_newtype {
3166+
// This is an obsolete struct deref
3167+
span_err!(tcx.sess, expr.span, E0068,
3168+
"single-field tuple-structs can \
3169+
no longer be dereferenced");
3170+
} else {
3171+
fcx.type_error_message(expr.span, |actual| {
3172+
format!("type `{}` cannot be \
3173+
dereferenced", actual)
3174+
}, oprnd_t, None);
3175+
}
31603176
tcx.types.err
31613177
}
31623178
}

trunk/src/librustc_typeck/diagnostics.rs

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,63 @@ Since `return;` is just like `return ();`, there is a mismatch between the
170170
function's return type and the value being returned.
171171
"##,
172172

173+
E0072: r##"
174+
When defining a recursive struct or enum, any use of the type being defined
175+
from inside the definition must occur behind a pointer (like `Box` or `&`).
176+
This is because structs and enums must have a well-defined size, and without
177+
the pointer the size of the type would need to be unbounded.
178+
179+
Consider the following erroneous definition of a type for a list of bytes:
180+
181+
```
182+
// error, illegal recursive struct type
183+
struct ListNode {
184+
head: u8,
185+
tail: Option<ListNode>,
186+
}
187+
```
188+
189+
This type cannot have a well-defined size, because it needs to be arbitrarily
190+
large (since we would be able to nest `ListNode`s to any depth). Specifically,
191+
192+
```
193+
size of ListNode = 1 byte for head
194+
+ 1 byte for the discriminant of the Option
195+
+ size of ListNode
196+
```
197+
198+
One way to fix this is by wrapping `ListNode` in a `Box`, like so:
199+
200+
```
201+
struct ListNode {
202+
head: u8,
203+
tail: Option<Box<ListNode>>,
204+
}
205+
```
206+
207+
This works because `Box` is a pointer, so its size is well-known.
208+
"##,
209+
210+
E0073: r##"
211+
You cannot define a struct (or enum) `Foo` that requires an instance of `Foo`
212+
in order to make a new `Foo` value. This is because there would be no way a
213+
first instance of `Foo` could be made to initialize another instance!
214+
215+
Here's an example of a struct that has this problem:
216+
217+
```
218+
struct Foo { x: Box<Foo> } // error
219+
```
220+
221+
One fix is to use `Option`, like so:
222+
223+
```
224+
struct Foo { x: Option<Box<Foo>> }
225+
```
226+
227+
Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`.
228+
"##,
229+
173230
E0081: r##"
174231
Enum discriminants are used to differentiate enum variants stored in memory.
175232
This error indicates that the same value was used for two or more variants,
@@ -327,6 +384,19 @@ RFC. It is, however, [currently unimplemented][iss15872].
327384
[iss15872]: https://github.com/rust-lang/rust/issues/15872
328385
"##,
329386

387+
E0121: r##"
388+
In order to be consistent with Rust's lack of global type inference, type
389+
placeholders are disallowed by design in item signatures.
390+
391+
Examples of this error include:
392+
393+
```
394+
fn foo() -> _ { 5 } // error, explicitly write out the return type instead
395+
396+
static BAR: _ = "test"; // error, explicitly write out the type instead
397+
```
398+
"##,
399+
330400
E0131: r##"
331401
It is not possible to define `main` with type parameters, or even with function
332402
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -355,6 +425,28 @@ return, for example with a `loop` that never breaks or a call to another
355425
diverging function (such as `panic!()`).
356426
"##,
357427

428+
E0178: r##"
429+
In types, the `+` type operator has low precedence, so it is often necessary
430+
to use parentheses.
431+
432+
For example:
433+
434+
```
435+
trait Foo {}
436+
437+
struct Bar<'a> {
438+
w: &'a Foo + Copy, // error, use &'a (Foo + Copy)
439+
x: &'a Foo + 'a, // error, use &'a (Foo + 'a)
440+
y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
441+
z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
442+
}
443+
```
444+
445+
More details can be found in [RFC 438].
446+
447+
[RFC 438]: https://github.com/rust-lang/rfcs/pull/438
448+
"##,
449+
358450
E0184: r##"
359451
Explicitly implementing both Drop and Copy for a type is currently disallowed.
360452
This feature can make some sense in theory, but the current implementation is
@@ -632,6 +724,35 @@ traits, so it is not possible to overload them. See [RFC 953] for a proposal
632724
to change this.
633725
634726
[RFC 953]: https://github.com/rust-lang/rfcs/pull/953
727+
"##,
728+
729+
E0371: r##"
730+
When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a
731+
definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement
732+
`Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by
733+
definition, so it is not useful to do this.
734+
735+
Example:
736+
737+
```
738+
trait Foo { fn foo(&self) { } }
739+
trait Bar: Foo { }
740+
trait Baz: Bar { }
741+
742+
impl Bar for Baz { } // error, `Baz` implements `Bar` by definition
743+
impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo`
744+
impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz`
745+
impl Baz for Bar { } // Note: This is OK
746+
```
747+
"##,
748+
749+
E0372: r##"
750+
Trying to implement a trait for a trait object (as in `impl Trait1 for
751+
Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
752+
[RFC 255] for more details on object safety rules.
753+
754+
[RFC 255]:https://github.com/rust-lang/rfcs/blob/master/text/0255-object-\
755+
safety.md
635756
"##
636757

637758
}
@@ -660,8 +781,6 @@ register_diagnostics! {
660781
E0068,
661782
E0070,
662783
E0071,
663-
E0072,
664-
E0073,
665784
E0074,
666785
E0075,
667786
E0076,
@@ -685,7 +804,6 @@ register_diagnostics! {
685804
E0118,
686805
E0119,
687806
E0120,
688-
E0121,
689807
E0122,
690808
E0123,
691809
E0124,
@@ -702,7 +820,6 @@ register_diagnostics! {
702820
E0172,
703821
E0173, // manual implementations of unboxed closure traits are experimental
704822
E0174, // explicit use of unboxed closure methods are experimental
705-
E0178,
706823
E0182,
707824
E0183,
708825
E0185,
@@ -774,8 +891,6 @@ register_diagnostics! {
774891
E0366, // dropck forbid specialization to concrete type or region
775892
E0367, // dropck forbid specialization to predicate not in struct/enum
776893
E0369, // binary operation `<op>` cannot be applied to types
777-
E0371, // impl Trait for Trait is illegal
778-
E0372, // impl Trait for Trait where Trait is not object safe
779894
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion
780895
// between structures with one field being coerced, none found
781896
E0375, // the trait `CoerceUnsized` may only be implemented for a coercion

trunk/src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
258258
("no_builtins", Whitelisted),
259259
("no_mangle", Whitelisted),
260260
("no_stack_check", Whitelisted),
261+
("packed", Whitelisted),
261262
("static_assert", Gated("static_assert",
262263
"`#[static_assert]` is an experimental feature, and has a poor API")),
263264
("no_debug", Whitelisted),

trunk/src/test/compile-fail/coherence-impl-trait-for-trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ trait Foo { fn dummy(&self) { } }
1515
trait Bar: Foo { }
1616
trait Baz: Bar { }
1717

18-
// Subtraits of Baz are not legal:
18+
// Supertraits of Baz are not legal:
1919
impl Foo for Baz { } //~ ERROR E0371
2020
impl Bar for Baz { } //~ ERROR E0371
2121
impl Baz for Baz { } //~ ERROR E0371
2222

2323
// But other random traits are:
2424
trait Other { }
25-
impl Other for Baz { } // OK, Bar not a subtrait of Baz
25+
impl Other for Baz { } // OK, Other not a supertrait of Baz
2626

2727
// If the trait is not object-safe, we give a more tailored message
2828
// because we're such schnuckels:

trunk/src/test/run-pass/issue-23968-const-not-overflow.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)