Skip to content

Commit 0381fc7

Browse files
authored
Rollup merge of rust-lang#42302 - GuillaumeGomez:new-error-codes-next, r=Susurrus
New error codes next Part rust-lang#42229. To be merged after rust-lang#42264. cc @Susurrus
2 parents b3947f8 + a333be7 commit 0381fc7

File tree

12 files changed

+51
-16
lines changed

12 files changed

+51
-16
lines changed

src/librustc/diagnostics.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,9 @@ makes a difference in practice.)
18711871

18721872
E0593: r##"
18731873
You tried to supply an `Fn`-based type with an incorrect number of arguments
1874-
than what was expected. Erroneous code example:
1874+
than what was expected.
1875+
1876+
Erroneous code example:
18751877
18761878
```compile_fail,E0593
18771879
fn foo<F: Fn()>(x: F) { }
@@ -1883,6 +1885,21 @@ fn main() {
18831885
```
18841886
"##,
18851887

1888+
E0601: r##"
1889+
No `main` function was found in a binary crate. To fix this error, just add a
1890+
`main` function. For example:
1891+
1892+
```
1893+
fn main() {
1894+
// Your program will start here.
1895+
println!("Hello world!");
1896+
}
1897+
```
1898+
1899+
If you don't know the basics of Rust, you can go look to the Rust Book to get
1900+
started: https://doc.rust-lang.org/book/
1901+
"##,
1902+
18861903
}
18871904

18881905

src/librustc/middle/entry.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn configure_main(this: &mut EntryContext) {
162162
this.session.entry_type.set(Some(config::EntryMain));
163163
} else {
164164
// No main function
165-
let mut err = this.session.struct_err("main function not found");
165+
let mut err = struct_err!(this.session, E0601, "main function not found");
166166
if !this.non_main_fns.is_empty() {
167167
// There were some functions named 'main' though. Try to give the user a hint.
168168
err.note("the main function must be defined at the crate level \

src/librustc/session/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,14 @@ impl Session {
158158
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
159159
sp: S,
160160
msg: &str)
161-
-> DiagnosticBuilder<'a> {
161+
-> DiagnosticBuilder<'a> {
162162
self.diagnostic().struct_span_warn(sp, msg)
163163
}
164164
pub fn struct_span_warn_with_code<'a, S: Into<MultiSpan>>(&'a self,
165165
sp: S,
166166
msg: &str,
167167
code: &str)
168-
-> DiagnosticBuilder<'a> {
168+
-> DiagnosticBuilder<'a> {
169169
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
170170
}
171171
pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
@@ -174,30 +174,34 @@ impl Session {
174174
pub fn struct_span_err<'a, S: Into<MultiSpan>>(&'a self,
175175
sp: S,
176176
msg: &str)
177-
-> DiagnosticBuilder<'a> {
177+
-> DiagnosticBuilder<'a> {
178178
self.diagnostic().struct_span_err(sp, msg)
179179
}
180180
pub fn struct_span_err_with_code<'a, S: Into<MultiSpan>>(&'a self,
181181
sp: S,
182182
msg: &str,
183183
code: &str)
184-
-> DiagnosticBuilder<'a> {
184+
-> DiagnosticBuilder<'a> {
185185
self.diagnostic().struct_span_err_with_code(sp, msg, code)
186186
}
187-
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
187+
// FIXME: This method should be removed (every error should have an associated error code).
188+
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
188189
self.diagnostic().struct_err(msg)
189190
}
191+
pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
192+
self.diagnostic().struct_err_with_code(msg, code)
193+
}
190194
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
191195
sp: S,
192196
msg: &str)
193-
-> DiagnosticBuilder<'a> {
197+
-> DiagnosticBuilder<'a> {
194198
self.diagnostic().struct_span_fatal(sp, msg)
195199
}
196200
pub fn struct_span_fatal_with_code<'a, S: Into<MultiSpan>>(&'a self,
197201
sp: S,
198202
msg: &str,
199203
code: &str)
200-
-> DiagnosticBuilder<'a> {
204+
-> DiagnosticBuilder<'a> {
201205
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
202206
}
203207
pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {

src/librustc_errors/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,15 @@ impl Handler {
345345
result.code(code.to_owned());
346346
result
347347
}
348+
// FIXME: This method should be removed (every error should have an associated error code).
348349
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
349350
DiagnosticBuilder::new(self, Level::Error, msg)
350351
}
352+
pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> {
353+
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
354+
result.code(code.to_owned());
355+
result
356+
}
351357
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
352358
sp: S,
353359
msg: &str)

src/libsyntax/diagnostics/macros.rs

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ macro_rules! span_warn {
3838
})
3939
}
4040

41+
#[macro_export]
42+
macro_rules! struct_err {
43+
($session:expr, $code:ident, $($message:tt)*) => ({
44+
__diagnostic_used!($code);
45+
$session.struct_err_with_code(&format!($($message)*), stringify!($code))
46+
})
47+
}
48+
4149
#[macro_export]
4250
macro_rules! span_err_or_warn {
4351
($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({

src/test/ui/missing-items/m2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: main function not found
1+
error[E0601]: main function not found
22

33
error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method`
44
--> $DIR/m2.rs:20:1

src/test/ui/resolve/issue-14254.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ error[E0425]: cannot find value `bah` in this scope
142142
133 | bah;
143143
| ^^^ did you mean `Self::bah`?
144144

145-
error: main function not found
145+
error[E0601]: main function not found
146146

147147
error: aborting due to previous error(s)
148148

src/test/ui/resolve/issue-21221-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ error[E0405]: cannot find trait `T` in this scope
77
help: possible candidate is found in another module, you can import it into scope
88
| use foo::bar::T;
99

10-
error: main function not found
10+
error[E0601]: main function not found
1111

1212
error: cannot continue compilation due to previous error
1313

src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ error[E0423]: expected function, found module `a::b`
7272
| |
7373
| did you mean `I`?
7474

75-
error: main function not found
75+
error[E0601]: main function not found
7676

7777
error: aborting due to previous error(s)
7878

src/test/ui/span/issue-35987.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ error[E0404]: expected trait, found type parameter `Add`
77
help: possible better candidate is found in another module, you can import it into scope
88
| use std::ops::Add;
99

10-
error: main function not found
10+
error[E0601]: main function not found
1111

1212
error: cannot continue compilation due to previous error
1313

src/test/ui/token/issue-10636-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error: expected expression, found `)`
2222
19 | } //~ ERROR: incorrect close delimiter
2323
| ^
2424

25-
error: main function not found
25+
error[E0601]: main function not found
2626

2727
error: aborting due to previous error(s)
2828

src/test/ui/token/issue-41155.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0412]: cannot find type `S` in this scope
1212
11 | impl S {
1313
| ^ not found in this scope
1414

15-
error: main function not found
15+
error[E0601]: main function not found
1616

1717
error: aborting due to previous error(s)
1818

0 commit comments

Comments
 (0)