Skip to content

Commit 0ccd5c8

Browse files
authoredAug 25, 2016
Auto merge of #35971 - jonathandturner:rollup, r=jonathandturner
Rollup of 4 pull requests - Successful merges: #35876, #35920, #35948, #35961 - Failed merges: #35395
2 parents e9bc1ba + 2932db1 commit 0ccd5c8

File tree

15 files changed

+246
-43
lines changed

15 files changed

+246
-43
lines changed
 

‎src/doc/reference.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2283,7 +2283,7 @@ the `PartialEq` or `Clone` constraints for the appropriate `impl`:
22832283
#[derive(PartialEq, Clone)]
22842284
struct Foo<T> {
22852285
a: i32,
2286-
b: T
2286+
b: T,
22872287
}
22882288
```
22892289

@@ -3896,7 +3896,7 @@ Coercion is allowed between the following types:
38963896
use std::ops::Deref;
38973897

38983898
struct CharContainer {
3899-
value: char
3899+
value: char,
39003900
}
39013901

39023902
impl Deref for CharContainer {

‎src/libcore/ops.rs

+43-19
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,38 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
245245
///
246246
/// # Examples
247247
///
248-
/// A trivial implementation of `Sub`. When `Foo - Foo` happens, it ends up
249-
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
248+
/// This example creates a `Point` struct that implements the `Sub` trait, and
249+
/// then demonstrates subtracting two `Point`s.
250250
///
251251
/// ```
252252
/// use std::ops::Sub;
253253
///
254-
/// struct Foo;
254+
/// #[derive(Debug)]
255+
/// struct Point {
256+
/// x: i32,
257+
/// y: i32,
258+
/// }
255259
///
256-
/// impl Sub for Foo {
257-
/// type Output = Foo;
260+
/// impl Sub for Point {
261+
/// type Output = Point;
258262
///
259-
/// fn sub(self, _rhs: Foo) -> Foo {
260-
/// println!("Subtracting!");
261-
/// self
263+
/// fn sub(self, other: Point) -> Point {
264+
/// Point {
265+
/// x: self.x - other.x,
266+
/// y: self.y - other.y,
267+
/// }
268+
/// }
269+
/// }
270+
///
271+
/// impl PartialEq for Point {
272+
/// fn eq(&self, other: &Self) -> bool {
273+
/// self.x == other.x && self.y == other.y
262274
/// }
263275
/// }
264276
///
265277
/// fn main() {
266-
/// Foo - Foo;
278+
/// assert_eq!(Point { x: 3, y: 3 } - Point { x: 2, y: 3 },
279+
/// Point { x: 1, y: 0 });
267280
/// }
268281
/// ```
269282
#[lang = "sub"]
@@ -1156,25 +1169,36 @@ add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
11561169
///
11571170
/// # Examples
11581171
///
1159-
/// A trivial implementation of `SubAssign`. When `Foo -= Foo` happens, it ends up
1160-
/// calling `sub_assign`, and therefore, `main` prints `Subtracting!`.
1172+
/// This example creates a `Point` struct that implements the `SubAssign`
1173+
/// trait, and then demonstrates sub-assigning to a mutable `Point`.
11611174
///
11621175
/// ```
11631176
/// use std::ops::SubAssign;
11641177
///
1165-
/// struct Foo;
1178+
/// #[derive(Debug)]
1179+
/// struct Point {
1180+
/// x: i32,
1181+
/// y: i32,
1182+
/// }
11661183
///
1167-
/// impl SubAssign for Foo {
1168-
/// fn sub_assign(&mut self, _rhs: Foo) {
1169-
/// println!("Subtracting!");
1184+
/// impl SubAssign for Point {
1185+
/// fn sub_assign(&mut self, other: Point) {
1186+
/// *self = Point {
1187+
/// x: self.x - other.x,
1188+
/// y: self.y - other.y,
1189+
/// };
11701190
/// }
11711191
/// }
11721192
///
1173-
/// # #[allow(unused_assignments)]
1174-
/// fn main() {
1175-
/// let mut foo = Foo;
1176-
/// foo -= Foo;
1193+
/// impl PartialEq for Point {
1194+
/// fn eq(&self, other: &Self) -> bool {
1195+
/// self.x == other.x && self.y == other.y
1196+
/// }
11771197
/// }
1198+
///
1199+
/// let mut point = Point { x: 3, y: 3 };
1200+
/// point -= Point { x: 2, y: 3 };
1201+
/// assert_eq!(point, Point {x: 1, y: 0});
11781202
/// ```
11791203
#[lang = "sub_assign"]
11801204
#[stable(feature = "op_assign_traits", since = "1.8.0")]

‎src/librustc/diagnostics.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,37 @@ fn main() {
15271527
```
15281528
"##,
15291529

1530+
E0478: r##"
1531+
A lifetime bound was not satisfied.
1532+
1533+
Erroneous code example:
1534+
1535+
```compile_fail,E0478
1536+
// Check that the explicit lifetime bound (`'SnowWhite`, in this example) must
1537+
// outlive all the superbounds from the trait (`'kiss`, in this example).
1538+
1539+
trait Wedding<'t>: 't { }
1540+
1541+
struct Prince<'kiss, 'SnowWhite> {
1542+
child: Box<Wedding<'kiss> + 'SnowWhite>,
1543+
// error: lifetime bound not satisfied
1544+
}
1545+
```
1546+
1547+
In this example, the `'SnowWhite` lifetime is supposed to outlive the `'kiss`
1548+
lifetime but the declaration of the `Prince` struct doesn't enforce it. To fix
1549+
this issue, you need to specify it:
1550+
1551+
```
1552+
trait Wedding<'t>: 't { }
1553+
1554+
struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
1555+
// longer than 'SnowWhite.
1556+
child: Box<Wedding<'kiss> + 'SnowWhite>, // And now it's all good!
1557+
}
1558+
```
1559+
"##,
1560+
15301561
E0496: r##"
15311562
A lifetime name is shadowing another lifetime name. Erroneous code example:
15321563
@@ -1715,7 +1746,6 @@ register_diagnostics! {
17151746
E0475, // index of slice outside its lifetime
17161747
E0476, // lifetime of the source pointer does not outlive lifetime bound...
17171748
E0477, // the type `..` does not fulfill the required lifetime...
1718-
E0478, // lifetime bound not satisfied
17191749
E0479, // the type `..` (provided as the value of a type parameter) is...
17201750
E0480, // lifetime of method receiver does not outlive the method call
17211751
E0481, // lifetime of function argument does not outlive the function call

‎src/librustc_metadata/creader.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ fn register_native_lib(sess: &Session,
101101
if name.is_empty() {
102102
match span {
103103
Some(span) => {
104-
span_err!(sess, span, E0454,
105-
"#[link(name = \"\")] given with empty name");
104+
struct_span_err!(sess, span, E0454,
105+
"#[link(name = \"\")] given with empty name")
106+
.span_label(span, &format!("empty name given"))
107+
.emit();
106108
}
107109
None => {
108110
sess.err("empty library name given via `-l`");

‎src/librustc_mir/diagnostics.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on
1818
the heap at runtime, and therefore cannot be done at compile time. Erroneous
1919
code example:
2020
21-
```compile_fail
21+
```compile_fail,E0010
2222
#![feature(box_syntax)]
2323
2424
const CON : Box<i32> = box 0;
@@ -30,7 +30,7 @@ Static and const variables can refer to other const variables. But a const
3030
variable cannot refer to a static variable. For example, `Y` cannot refer to
3131
`X` here:
3232
33-
```compile_fail
33+
```compile_fail,E0013
3434
static X: i32 = 42;
3535
const Y: i32 = X;
3636
```
@@ -66,7 +66,7 @@ E0016: r##"
6666
Blocks in constants may only contain items (such as constant, function
6767
definition, etc...) and a tail expression. Erroneous code example:
6868
69-
```compile_fail
69+
```compile_fail,E0016
7070
const FOO: i32 = { let x = 0; x }; // 'x' isn't an item!
7171
```
7272
@@ -81,7 +81,7 @@ E0017: r##"
8181
References in statics and constants may only refer to immutable values.
8282
Erroneous code example:
8383
84-
```compile_fail
84+
```compile_fail,E0017
8585
static X: i32 = 1;
8686
const C: i32 = 2;
8787
@@ -107,7 +107,7 @@ vary.
107107
108108
For example, if you write:
109109
110-
```compile_fail
110+
```compile_fail,E0018
111111
static MY_STATIC: u32 = 42;
112112
static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;
113113
static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;
@@ -152,7 +152,7 @@ impl Test {
152152
fn main() {
153153
const FOO: Test = Test::V1;
154154
155-
const A: i32 = FOO.test(); // You can't call Test::func() here !
155+
const A: i32 = FOO.test(); // You can't call Test::func() here!
156156
}
157157
```
158158
@@ -214,14 +214,13 @@ static B: &'static u32 = &A; // ok!
214214
```
215215
"##,
216216

217-
218217
E0395: r##"
219218
The value assigned to a constant scalar must be known at compile time,
220219
which is not the case when comparing raw pointers.
221220
222221
Erroneous code example:
223222
224-
```compile_fail
223+
```compile_fail,E0395
225224
static FOO: i32 = 42;
226225
static BAR: i32 = 42;
227226
@@ -250,7 +249,7 @@ The value behind a raw pointer can't be determined at compile-time
250249
(or even link-time), which means it can't be used in a constant
251250
expression. Erroneous code example:
252251
253-
```compile_fail
252+
```compile_fail,E0396
254253
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
255254
256255
const VALUE: u8 = unsafe { *REG_ADDR };
@@ -272,7 +271,7 @@ E0492: r##"
272271
A borrow of a constant containing interior mutability was attempted. Erroneous
273272
code example:
274273
275-
```compile_fail
274+
```compile_fail,E0492
276275
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
277276
278277
const A: AtomicUsize = ATOMIC_USIZE_INIT;
@@ -299,7 +298,7 @@ static B: &'static AtomicUsize = &A; // ok!
299298
300299
You can also have this error while using a cell type:
301300
302-
```compile_fail
301+
```compile_fail,E0492
303302
#![feature(const_fn)]
304303
305304
use std::cell::Cell;
@@ -351,7 +350,7 @@ E0493: r##"
351350
A type with a destructor was assigned to an invalid type of variable. Erroneous
352351
code example:
353352
354-
```compile_fail
353+
```compile_fail,E0493
355354
struct Foo {
356355
a: u32
357356
}
@@ -374,7 +373,7 @@ E0494: r##"
374373
A reference of an interior static was assigned to another const/static.
375374
Erroneous code example:
376375
377-
```compile_fail
376+
```compile_fail,E0494
378377
struct Foo {
379378
a: u32
380379
}

‎src/librustc_privacy/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,11 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
964964
if !vis.is_at_least(self.required_visibility, &self.tcx.map) {
965965
if self.tcx.sess.features.borrow().pub_restricted ||
966966
self.old_error_set.contains(&trait_ref.ref_id) {
967-
span_err!(self.tcx.sess, trait_ref.path.span, E0445,
968-
"private trait in public interface");
967+
struct_span_err!(self.tcx.sess, trait_ref.path.span, E0445,
968+
"private trait in public interface")
969+
.span_label(trait_ref.path.span, &format!(
970+
"private trait can't be public"))
971+
.emit();
969972
} else {
970973
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
971974
node_id,

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ trait Foo {
1212
fn dummy(&self) { }
1313
}
1414

15-
pub trait Bar : Foo {} //~ ERROR E0445
16-
pub struct Bar2<T: Foo>(pub T); //~ ERROR E0445
17-
pub fn foo<T: Foo> (t: T) {} //~ ERROR E0445
15+
pub trait Bar : Foo {}
16+
//~^ ERROR private trait in public interface [E0445]
17+
//~| NOTE private trait can't be public
18+
pub struct Bar2<T: Foo>(pub T);
19+
//~^ ERROR private trait in public interface [E0445]
20+
//~| NOTE private trait can't be public
21+
pub fn foo<T: Foo> (t: T) {}
22+
//~^ ERROR private trait in public interface [E0445]
23+
//~| NOTE private trait can't be public
1824

1925
fn main() {}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[link(name = "")] extern {} //~ ERROR E0454
11+
#[link(name = "")] extern {}
12+
//~^ ERROR E0454
13+
//~| NOTE empty name given
1214

1315
fn main() {
1416
}

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

+18
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+
trait Wedding<'t>: 't { }
12+
13+
struct Prince<'kiss, 'SnowWhite> {
14+
child: Box<Wedding<'kiss> + 'SnowWhite>, //~ ERROR E0478
15+
}
16+
17+
fn main() {
18+
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
12+
13+
const A: AtomicUsize = ATOMIC_USIZE_INIT;
14+
static B: &'static AtomicUsize = &A; //~ ERROR E0492
15+
16+
fn main() {
17+
}

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

+22
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+
struct Foo {
12+
a: u32
13+
}
14+
15+
impl Drop for Foo {
16+
fn drop(&mut self) {}
17+
}
18+
19+
const F : Foo = Foo { a : 0 }; //~ ERROR E0493
20+
21+
fn main() {
22+
}

0 commit comments

Comments
 (0)
Please sign in to comment.