Skip to content

Commit

Permalink
Rollup merge of rust-lang#42302 - GuillaumeGomez:new-error-codes-next…
Browse files Browse the repository at this point in the history
…, r=Susurrus

New error codes next

Part rust-lang#42229.
To be merged after rust-lang#42264.

cc @Susurrus
  • Loading branch information
frewsxcv authored Jun 1, 2017
2 parents b3947f8 + a333be7 commit 0381fc7
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 16 deletions.
19 changes: 18 additions & 1 deletion src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,9 @@ makes a difference in practice.)

E0593: r##"
You tried to supply an `Fn`-based type with an incorrect number of arguments
than what was expected. Erroneous code example:
than what was expected.
Erroneous code example:
```compile_fail,E0593
fn foo<F: Fn()>(x: F) { }
Expand All @@ -1883,6 +1885,21 @@ fn main() {
```
"##,

E0601: r##"
No `main` function was found in a binary crate. To fix this error, just add a
`main` function. For example:
```
fn main() {
// Your program will start here.
println!("Hello world!");
}
```
If you don't know the basics of Rust, you can go look to the Rust Book to get
started: https://doc.rust-lang.org/book/
"##,

}


Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn configure_main(this: &mut EntryContext) {
this.session.entry_type.set(Some(config::EntryMain));
} else {
// No main function
let mut err = this.session.struct_err("main function not found");
let mut err = struct_err!(this.session, E0601, "main function not found");
if !this.non_main_fns.is_empty() {
// There were some functions named 'main' though. Try to give the user a hint.
err.note("the main function must be defined at the crate level \
Expand Down
18 changes: 11 additions & 7 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ impl Session {
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str)
-> DiagnosticBuilder<'a> {
-> DiagnosticBuilder<'a> {
self.diagnostic().struct_span_warn(sp, msg)
}
pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str,
code: &str)
-> DiagnosticBuilder<'a> {
-> DiagnosticBuilder<'a> {
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
}
pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
Expand All @@ -174,30 +174,34 @@ impl Session {
pub fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str)
-> DiagnosticBuilder<'a> {
-> DiagnosticBuilder<'a> {
self.diagnostic().struct_span_err(sp, msg)
}
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str,
code: &str)
-> DiagnosticBuilder<'a> {
-> DiagnosticBuilder<'a> {
self.diagnostic().struct_span_err_with_code(sp, msg, code)
}
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
// FIXME: This method should be removed (every error should have an associated error code).
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
self.diagnostic().struct_err(msg)
}
pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
self.diagnostic().struct_err_with_code(msg, code)
}
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str)
-> DiagnosticBuilder<'a> {
-> DiagnosticBuilder<'a> {
self.diagnostic().struct_span_fatal(sp, msg)
}
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str,
code: &str)
-> DiagnosticBuilder<'a> {
-> DiagnosticBuilder<'a> {
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
}
pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,15 @@ impl Handler {
result.code(code.to_owned());
result
}
// FIXME: This method should be removed (every error should have an associated error code).
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
DiagnosticBuilder::new(self, Level::Error, msg)
}
pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
result.code(code.to_owned());
result
}
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
msg: &str)
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/diagnostics/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ macro_rules! span_warn {
})
}

#[macro_export]
macro_rules! struct_err {
($session:expr, $code:ident, $($message:tt)*) => ({
__diagnostic_used!($code);
$session.struct_err_with_code(&format!($($message)*), stringify!($code))
})
}

#[macro_export]
macro_rules! span_err_or_warn {
($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/missing-items/m2.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: main function not found
error[E0601]: main function not found

error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`
--> $DIR/m2.rs:20:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-14254.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ error[E0425]: cannot find value `bah` in this scope
133 | bah;
| ^^^ did you mean `Self::bah`?

error: main function not found
error[E0601]: main function not found

error: aborting due to previous error(s)

2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-21221-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error[E0405]: cannot find trait `T` in this scope
help: possible candidate is found in another module, you can import it into scope
| use foo::bar::T;

error: main function not found
error[E0601]: main function not found

error: cannot continue compilation due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ error[E0423]: expected function, found module `a::b`
| |
| did you mean `I`?

error: main function not found
error[E0601]: main function not found

error: aborting due to previous error(s)

2 changes: 1 addition & 1 deletion src/test/ui/span/issue-35987.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ error[E0404]: expected trait, found type parameter `Add`
help: possible better candidate is found in another module, you can import it into scope
| use std::ops::Add;

error: main function not found
error[E0601]: main function not found

error: cannot continue compilation due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/token/issue-10636-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error: expected expression, found `)`
19 | } //~ ERROR: incorrect close delimiter
| ^

error: main function not found
error[E0601]: main function not found

error: aborting due to previous error(s)

2 changes: 1 addition & 1 deletion src/test/ui/token/issue-41155.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ error[E0412]: cannot find type `S` in this scope
11 | impl S {
| ^ not found in this scope

error: main function not found
error[E0601]: main function not found

error: aborting due to previous error(s)

0 comments on commit 0381fc7

Please sign in to comment.