Skip to content

Commit

Permalink
Rollup merge of rust-lang#35363 - GuillaumeGomez:err_codes, r=jonatha…
Browse files Browse the repository at this point in the history
…ndturner

Err codes

r? @jonathandturner
  • Loading branch information
Jonathan Turner authored Aug 5, 2016
2 parents 39a1a25 + 7cd1779 commit 71b8958
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/librustc_passes/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ All statics and constants need to resolve to a value in an acyclic manner.
For example, neither of the following can be sensibly compiled:
```compile_fail
```compile_fail,E0265
const X: u32 = X;
```
```compile_fail
```compile_fail,E0265
const X: u32 = Y;
const Y: u32 = X;
```
Expand All @@ -135,7 +135,7 @@ E0267: r##"
This error indicates the use of a loop keyword (`break` or `continue`) inside a
closure but outside of any loop. Erroneous code example:
```compile_fail
```compile_fail,E0267
let w = || { break; }; // error: `break` inside of a closure
```
Expand All @@ -159,7 +159,7 @@ This error indicates the use of a loop keyword (`break` or `continue`) outside
of a loop. Without a loop to break out of or continue in, no sensible action can
be taken. Erroneous code example:
```compile_fail
```compile_fail,E0268
fn some_func() {
break; // error: `break` outside of loop
}
Expand Down
41 changes: 40 additions & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,53 @@ mod foo {
}
use foo::MyTrait::do_something;
// error: `do_something` is not directly importable
fn main() {}
```
It's invalid to directly import methods belonging to a trait or concrete type.
"##,

E0254: r##"
Attempt was made to import an item whereas an extern crate with this name has
already been imported.
Erroneous code example:
```compile_fail,E0254
extern crate collections;
mod foo {
pub trait collections {
fn do_something();
}
}
use foo::collections; // error: an extern crate named `collections` has already
// been imported in this module
fn main() {}
```
To fix issue issue, you have to rename at least one of the two imports.
Example:
```ignore
extern crate collections as libcollections; // ok!
mod foo {
pub trait collections {
fn do_something();
}
}
use foo::collections;
fn main() {}
```
"##,

E0255: r##"
You can't import a value whose name is the same as another value defined in the
module.
Expand Down Expand Up @@ -1237,7 +1277,6 @@ impl Foo for i32 {}
register_diagnostics! {
// E0153, unused error code
// E0157, unused error code
E0254, // import conflicts with imported crate in this module
// E0257,
// E0258,
E0402, // cannot use an outer type parameter in this context
Expand Down
19 changes: 19 additions & 0 deletions src/test/compile-fail/E0253.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

mod foo {
pub trait MyTrait {
fn do_something();
}
}

use foo::MyTrait::do_something; //~ ERROR E0253

fn main() {}
21 changes: 21 additions & 0 deletions src/test/compile-fail/E0254.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

extern crate collections;

mod foo {
pub trait collections {
fn do_something();
}
}

use foo::collections; //~ ERROR E0254

fn main() {}
19 changes: 19 additions & 0 deletions src/test/compile-fail/E0255.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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 bar::foo;

fn foo() {} //~ ERROR E0255

mod bar {
pub fn foo() {}
}

fn main() {}
14 changes: 14 additions & 0 deletions src/test/compile-fail/E0259.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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.

extern crate collections;
extern crate libc as collections; //~ ERROR E0259

fn main() {}
19 changes: 19 additions & 0 deletions src/test/compile-fail/E0260.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

extern crate collections;

mod collections { //~ ERROR E0260
pub trait MyTrait {
fn do_something();
}
}

fn main() {}
17 changes: 17 additions & 0 deletions src/test/compile-fail/E0261.rs
Original file line number Diff line number Diff line change
@@ -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.

fn foo(x: &'a str) { } //~ ERROR E0261

struct Foo {
x: &'a str, //~ ERROR E0261
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/compile-fail/E0262.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

fn foo<'static>(x: &'static str) { } //~ ERROR E0262

fn main() {}
13 changes: 13 additions & 0 deletions src/test/compile-fail/E0263.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { } //~ ERROR E0263

fn main() {}
18 changes: 18 additions & 0 deletions src/test/compile-fail/E0264.rs
Original file line number Diff line number Diff line change
@@ -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.

#![feature(lang_items)]

extern "C" {
#[lang = "cake"]
fn cake(); //~ ERROR E0264
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/compile-fail/E0267.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

fn main() {
let w = || { break; }; //~ ERROR E0267
}
13 changes: 13 additions & 0 deletions src/test/compile-fail/E0268.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

fn main() {
break; //~ ERROR E0268
}

0 comments on commit 71b8958

Please sign in to comment.