Skip to content

Commit

Permalink
Auto merge of #35971 - jonathandturner:rollup, r=jonathandturner
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

- Successful merges: #35876, #35920, #35948, #35961
- Failed merges: #35395
  • Loading branch information
bors committed Aug 25, 2016
2 parents e9bc1ba + 2932db1 commit 0ccd5c8
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/doc/reference.md
Expand Up @@ -2283,7 +2283,7 @@ the `PartialEq` or `Clone` constraints for the appropriate `impl`:
#[derive(PartialEq, Clone)]
struct Foo<T> {
a: i32,
b: T
b: T,
}
```

Expand Down Expand Up @@ -3896,7 +3896,7 @@ Coercion is allowed between the following types:
use std::ops::Deref;

struct CharContainer {
value: char
value: char,
}

impl Deref for CharContainer {
Expand Down
62 changes: 43 additions & 19 deletions src/libcore/ops.rs
Expand Up @@ -245,25 +245,38 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
///
/// # Examples
///
/// A trivial implementation of `Sub`. When `Foo - Foo` happens, it ends up
/// calling `sub`, and therefore, `main` prints `Subtracting!`.
/// This example creates a `Point` struct that implements the `Sub` trait, and
/// then demonstrates subtracting two `Point`s.
///
/// ```
/// use std::ops::Sub;
///
/// struct Foo;
/// #[derive(Debug)]
/// struct Point {
/// x: i32,
/// y: i32,
/// }
///
/// impl Sub for Foo {
/// type Output = Foo;
/// impl Sub for Point {
/// type Output = Point;
///
/// fn sub(self, _rhs: Foo) -> Foo {
/// println!("Subtracting!");
/// self
/// fn sub(self, other: Point) -> Point {
/// Point {
/// x: self.x - other.x,
/// y: self.y - other.y,
/// }
/// }
/// }
///
/// impl PartialEq for Point {
/// fn eq(&self, other: &Self) -> bool {
/// self.x == other.x && self.y == other.y
/// }
/// }
///
/// fn main() {
/// Foo - Foo;
/// assert_eq!(Point { x: 3, y: 3 } - Point { x: 2, y: 3 },
/// Point { x: 1, y: 0 });
/// }
/// ```
#[lang = "sub"]
Expand Down Expand Up @@ -1156,25 +1169,36 @@ add_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
///
/// # Examples
///
/// A trivial implementation of `SubAssign`. When `Foo -= Foo` happens, it ends up
/// calling `sub_assign`, and therefore, `main` prints `Subtracting!`.
/// This example creates a `Point` struct that implements the `SubAssign`
/// trait, and then demonstrates sub-assigning to a mutable `Point`.
///
/// ```
/// use std::ops::SubAssign;
///
/// struct Foo;
/// #[derive(Debug)]
/// struct Point {
/// x: i32,
/// y: i32,
/// }
///
/// impl SubAssign for Foo {
/// fn sub_assign(&mut self, _rhs: Foo) {
/// println!("Subtracting!");
/// impl SubAssign for Point {
/// fn sub_assign(&mut self, other: Point) {
/// *self = Point {
/// x: self.x - other.x,
/// y: self.y - other.y,
/// };
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo -= Foo;
/// impl PartialEq for Point {
/// fn eq(&self, other: &Self) -> bool {
/// self.x == other.x && self.y == other.y
/// }
/// }
///
/// let mut point = Point { x: 3, y: 3 };
/// point -= Point { x: 2, y: 3 };
/// assert_eq!(point, Point {x: 1, y: 0});
/// ```
#[lang = "sub_assign"]
#[stable(feature = "op_assign_traits", since = "1.8.0")]
Expand Down
32 changes: 31 additions & 1 deletion src/librustc/diagnostics.rs
Expand Up @@ -1527,6 +1527,37 @@ fn main() {
```
"##,

E0478: r##"
A lifetime bound was not satisfied.
Erroneous code example:
```compile_fail,E0478
// Check that the explicit lifetime bound (`'SnowWhite`, in this example) must
// outlive all the superbounds from the trait (`'kiss`, in this example).
trait Wedding<'t>: 't { }
struct Prince<'kiss, 'SnowWhite> {
child: Box<Wedding<'kiss> + 'SnowWhite>,
// error: lifetime bound not satisfied
}
```
In this example, the `'SnowWhite` lifetime is supposed to outlive the `'kiss`
lifetime but the declaration of the `Prince` struct doesn't enforce it. To fix
this issue, you need to specify it:
```
trait Wedding<'t>: 't { }
struct Prince<'kiss, 'SnowWhite: 'kiss> { // You say here that 'kiss must live
// longer than 'SnowWhite.
child: Box<Wedding<'kiss> + 'SnowWhite>, // And now it's all good!
}
```
"##,

E0496: r##"
A lifetime name is shadowing another lifetime name. Erroneous code example:
Expand Down Expand Up @@ -1715,7 +1746,6 @@ register_diagnostics! {
E0475, // index of slice outside its lifetime
E0476, // lifetime of the source pointer does not outlive lifetime bound...
E0477, // the type `..` does not fulfill the required lifetime...
E0478, // lifetime bound not satisfied
E0479, // the type `..` (provided as the value of a type parameter) is...
E0480, // lifetime of method receiver does not outlive the method call
E0481, // lifetime of function argument does not outlive the function call
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_metadata/creader.rs
Expand Up @@ -101,8 +101,10 @@ fn register_native_lib(sess: &Session,
if name.is_empty() {
match span {
Some(span) => {
span_err!(sess, span, E0454,
"#[link(name = \"\")] given with empty name");
struct_span_err!(sess, span, E0454,
"#[link(name = \"\")] given with empty name")
.span_label(span, &format!("empty name given"))
.emit();
}
None => {
sess.err("empty library name given via `-l`");
Expand Down
25 changes: 12 additions & 13 deletions src/librustc_mir/diagnostics.rs
Expand Up @@ -18,7 +18,7 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on
the heap at runtime, and therefore cannot be done at compile time. Erroneous
code example:
```compile_fail
```compile_fail,E0010
#![feature(box_syntax)]
const CON : Box<i32> = box 0;
Expand All @@ -30,7 +30,7 @@ Static and const variables can refer to other const variables. But a const
variable cannot refer to a static variable. For example, `Y` cannot refer to
`X` here:
```compile_fail
```compile_fail,E0013
static X: i32 = 42;
const Y: i32 = X;
```
Expand Down Expand Up @@ -66,7 +66,7 @@ E0016: r##"
Blocks in constants may only contain items (such as constant, function
definition, etc...) and a tail expression. Erroneous code example:
```compile_fail
```compile_fail,E0016
const FOO: i32 = { let x = 0; x }; // 'x' isn't an item!
```
Expand All @@ -81,7 +81,7 @@ E0017: r##"
References in statics and constants may only refer to immutable values.
Erroneous code example:
```compile_fail
```compile_fail,E0017
static X: i32 = 1;
const C: i32 = 2;
Expand All @@ -107,7 +107,7 @@ vary.
For example, if you write:
```compile_fail
```compile_fail,E0018
static MY_STATIC: u32 = 42;
static MY_STATIC_ADDR: usize = &MY_STATIC as *const _ as usize;
static WHAT: usize = (MY_STATIC_ADDR^17) + MY_STATIC_ADDR;
Expand Down Expand Up @@ -152,7 +152,7 @@ impl Test {
fn main() {
const FOO: Test = Test::V1;
const A: i32 = FOO.test(); // You can't call Test::func() here !
const A: i32 = FOO.test(); // You can't call Test::func() here!
}
```
Expand Down Expand Up @@ -214,14 +214,13 @@ static B: &'static u32 = &A; // ok!
```
"##,


E0395: r##"
The value assigned to a constant scalar must be known at compile time,
which is not the case when comparing raw pointers.
Erroneous code example:
```compile_fail
```compile_fail,E0395
static FOO: i32 = 42;
static BAR: i32 = 42;
Expand Down Expand Up @@ -250,7 +249,7 @@ The value behind a raw pointer can't be determined at compile-time
(or even link-time), which means it can't be used in a constant
expression. Erroneous code example:
```compile_fail
```compile_fail,E0396
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
const VALUE: u8 = unsafe { *REG_ADDR };
Expand All @@ -272,7 +271,7 @@ E0492: r##"
A borrow of a constant containing interior mutability was attempted. Erroneous
code example:
```compile_fail
```compile_fail,E0492
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
const A: AtomicUsize = ATOMIC_USIZE_INIT;
Expand All @@ -299,7 +298,7 @@ static B: &'static AtomicUsize = &A; // ok!
You can also have this error while using a cell type:
```compile_fail
```compile_fail,E0492
#![feature(const_fn)]
use std::cell::Cell;
Expand Down Expand Up @@ -351,7 +350,7 @@ E0493: r##"
A type with a destructor was assigned to an invalid type of variable. Erroneous
code example:
```compile_fail
```compile_fail,E0493
struct Foo {
a: u32
}
Expand All @@ -374,7 +373,7 @@ E0494: r##"
A reference of an interior static was assigned to another const/static.
Erroneous code example:
```compile_fail
```compile_fail,E0494
struct Foo {
a: u32
}
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_privacy/lib.rs
Expand Up @@ -964,8 +964,11 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
if !vis.is_at_least(self.required_visibility, &self.tcx.map) {
if self.tcx.sess.features.borrow().pub_restricted ||
self.old_error_set.contains(&trait_ref.ref_id) {
span_err!(self.tcx.sess, trait_ref.path.span, E0445,
"private trait in public interface");
struct_span_err!(self.tcx.sess, trait_ref.path.span, E0445,
"private trait in public interface")
.span_label(trait_ref.path.span, &format!(
"private trait can't be public"))
.emit();
} else {
self.tcx.sess.add_lint(lint::builtin::PRIVATE_IN_PUBLIC,
node_id,
Expand Down
12 changes: 9 additions & 3 deletions src/test/compile-fail/E0445.rs
Expand Up @@ -12,8 +12,14 @@ trait Foo {
fn dummy(&self) { }
}

pub trait Bar : Foo {} //~ ERROR E0445
pub struct Bar2<T: Foo>(pub T); //~ ERROR E0445
pub fn foo<T: Foo> (t: T) {} //~ ERROR E0445
pub trait Bar : Foo {}
//~^ ERROR private trait in public interface [E0445]
//~| NOTE private trait can't be public
pub struct Bar2<T: Foo>(pub T);
//~^ ERROR private trait in public interface [E0445]
//~| NOTE private trait can't be public
pub fn foo<T: Foo> (t: T) {}
//~^ ERROR private trait in public interface [E0445]
//~| NOTE private trait can't be public

fn main() {}
4 changes: 3 additions & 1 deletion src/test/compile-fail/E0454.rs
Expand Up @@ -8,7 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[link(name = "")] extern {} //~ ERROR E0454
#[link(name = "")] extern {}
//~^ ERROR E0454
//~| NOTE empty name given

fn main() {
}
18 changes: 18 additions & 0 deletions src/test/compile-fail/E0478.rs
@@ -0,0 +1,18 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

trait Wedding<'t>: 't { }

struct Prince<'kiss, 'SnowWhite> {
child: Box<Wedding<'kiss> + 'SnowWhite>, //~ ERROR E0478
}

fn main() {
}
17 changes: 17 additions & 0 deletions src/test/compile-fail/E0492.rs
@@ -0,0 +1,17 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};

const A: AtomicUsize = ATOMIC_USIZE_INIT;
static B: &'static AtomicUsize = &A; //~ ERROR E0492

fn main() {
}
22 changes: 22 additions & 0 deletions src/test/compile-fail/E0493.rs
@@ -0,0 +1,22 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

struct Foo {
a: u32
}

impl Drop for Foo {
fn drop(&mut self) {}
}

const F : Foo = Foo { a : 0 }; //~ ERROR E0493

fn main() {
}

0 comments on commit 0ccd5c8

Please sign in to comment.