Skip to content

Commit 8c93948

Browse files
committed
Auto merge of #93142 - estebank:missing-main, r=wesleywiser
Do not point at whole file missing `fn main` Only point at the end of the crate. We could try making it point at the beginning of the crate, but that is confused with `DUMMY_SP`, causing the output to be *worse*. This change will make it so that VSCode will *not* underline the whole file when `main` is missing, so other errors will be visible.
2 parents 69f11ff + 91f3603 commit 8c93948

19 files changed

+54
-103
lines changed

compiler/rustc_passes/src/entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
218218
// The file may be empty, which leads to the diagnostic machinery not emitting this
219219
// note. This is a relatively simple way to detect that case and emit a span-less
220220
// note instead.
221-
if tcx.sess.source_map().lookup_line(sp.lo()).is_ok() {
222-
err.set_span(sp);
223-
err.span_label(sp, &note);
221+
if tcx.sess.source_map().lookup_line(sp.hi()).is_ok() {
222+
err.set_span(sp.shrink_to_hi());
223+
err.span_label(sp.shrink_to_hi(), &note);
224224
} else {
225225
err.note(&note);
226226
}

src/test/ui/attributes/issue-90873.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![u=||{static d=||1;}]
22
//~^ unexpected token
33
//~| cannot find attribute `u` in this scope
4-
//~| `main` function not found in crate `issue_90873`
54
//~| missing type for `static` item
65

76
#![a={impl std::ops::Neg for i8 {}}]
87
//~^ ERROR unexpected token
98
//~| ERROR cannot find attribute `a` in this scope
9+
//~| ERROR `main` function not found in crate `issue_90873`

src/test/ui/attributes/issue-90873.stderr

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | #![u=||{static d=||1;}]
1010
error: unexpected token: `{
1111
impl std::ops::Neg for i8 {}
1212
}`
13-
--> $DIR/issue-90873.rs:7:6
13+
--> $DIR/issue-90873.rs:6:6
1414
|
1515
LL | #![a={impl std::ops::Neg for i8 {}}]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -22,22 +22,16 @@ LL | #![u=||{static d=||1;}]
2222
| ^
2323

2424
error: cannot find attribute `a` in this scope
25-
--> $DIR/issue-90873.rs:7:4
25+
--> $DIR/issue-90873.rs:6:4
2626
|
2727
LL | #![a={impl std::ops::Neg for i8 {}}]
2828
| ^
2929

3030
error[E0601]: `main` function not found in crate `issue_90873`
31-
--> $DIR/issue-90873.rs:1:1
31+
--> $DIR/issue-90873.rs:6:37
3232
|
33-
LL | / #![u=||{static d=||1;}]
34-
LL | |
35-
LL | |
36-
LL | |
37-
LL | |
38-
LL | |
39-
LL | | #![a={impl std::ops::Neg for i8 {}}]
40-
| |____________________________________^ consider adding a `main` function to `$DIR/issue-90873.rs`
33+
LL | #![a={impl std::ops::Neg for i8 {}}]
34+
| ^ consider adding a `main` function to `$DIR/issue-90873.rs`
4135

4236
error: missing type for `static` item
4337
--> $DIR/issue-90873.rs:1:16

src/test/ui/conditional-compilation/cfg-attr-cfg-2.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
error[E0601]: `main` function not found in crate `cfg_attr_cfg_2`
2-
--> $DIR/cfg-attr-cfg-2.rs:8:1
2+
--> $DIR/cfg-attr-cfg-2.rs:9:14
33
|
4-
LL | / #[cfg_attr(foo, cfg(bar))]
5-
LL | | fn main() { }
6-
| |_____________^ consider adding a `main` function to `$DIR/cfg-attr-cfg-2.rs`
4+
LL | fn main() { }
5+
| ^ consider adding a `main` function to `$DIR/cfg-attr-cfg-2.rs`
76

87
error: aborting due to previous error
98

src/test/ui/conditional-compilation/cfg-in-crate-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0601]: `main` function not found in crate `cfg_in_crate_1`
2-
--> $DIR/cfg-in-crate-1.rs:3:1
2+
--> $DIR/cfg-in-crate-1.rs:3:13
33
|
44
LL | #![cfg(bar)]
5-
| ^^^^^^^^^^^^ consider adding a `main` function to `$DIR/cfg-in-crate-1.rs`
5+
| ^ consider adding a `main` function to `$DIR/cfg-in-crate-1.rs`
66

77
error: aborting due to previous error
88

src/test/ui/continue-after-missing-main.nll.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
error[E0601]: `main` function not found in crate `continue_after_missing_main`
2-
--> $DIR/continue-after-missing-main.rs:1:1
2+
--> $DIR/continue-after-missing-main.rs:30:2
33
|
4-
LL | / #![allow(dead_code)]
5-
LL | |
6-
LL | | struct Tableau<'a, MP> {
7-
LL | | provider: &'a MP,
8-
... |
9-
LL | |
10-
LL | | }
11-
| |_^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
4+
LL | }
5+
| ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
126

137
error: aborting due to previous error
148

src/test/ui/continue-after-missing-main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(dead_code)] //~ ERROR `main` function not found in crate
1+
#![allow(dead_code)]
22

33
struct Tableau<'a, MP> {
44
provider: &'a MP,
@@ -27,4 +27,4 @@ fn create_and_solve_subproblems<'data_provider, 'original_data, MP>(
2727
) {
2828
let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound();
2929
//~^ ERROR lifetime mismatch
30-
}
30+
} //~ ERROR `main` function not found in crate

src/test/ui/continue-after-missing-main.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
error[E0601]: `main` function not found in crate `continue_after_missing_main`
2-
--> $DIR/continue-after-missing-main.rs:1:1
2+
--> $DIR/continue-after-missing-main.rs:30:2
33
|
4-
LL | / #![allow(dead_code)]
5-
LL | |
6-
LL | | struct Tableau<'a, MP> {
7-
LL | | provider: &'a MP,
8-
... |
9-
LL | |
10-
LL | | }
11-
| |_^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
4+
LL | }
5+
| ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
126

137
error[E0623]: lifetime mismatch
148
--> $DIR/continue-after-missing-main.rs:28:56

src/test/ui/elided-test.stderr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0601]: `main` function not found in crate `elided_test`
2-
--> $DIR/elided-test.rs:5:1
2+
--> $DIR/elided-test.rs:7:2
33
|
4-
LL | / #[test]
5-
LL | | fn main() {
6-
LL | | }
7-
| |_^ consider adding a `main` function to `$DIR/elided-test.rs`
4+
LL | }
5+
| ^ consider adding a `main` function to `$DIR/elided-test.rs`
86

97
error: aborting due to previous error
108

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(imported_main)]
22
#![feature(type_alias_impl_trait)]
33
#![allow(incomplete_features)]
4-
//~^^^ ERROR `main` function not found in crate
54
pub mod foo {
65
type MainFn = impl Fn();
76
//~^ ERROR could not find defining uses
@@ -11,4 +10,4 @@ pub mod foo {
1110
//~^ ERROR mismatched types [E0308]
1211
}
1312

14-
use foo::BAR as main;
13+
use foo::BAR as main; //~ ERROR `main` function not found in crate

0 commit comments

Comments
 (0)