Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New error codes next #42302

Merged
merged 1 commit into from Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/librustc/diagnostics.rs
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
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
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
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
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
@@ -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
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
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

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
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
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
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)