1
Fork 0

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.
This commit is contained in:
bors 2022-03-05 02:46:24 +00:00
commit 8c93948d6e
19 changed files with 54 additions and 103 deletions

View file

@ -218,9 +218,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) {
// The file may be empty, which leads to the diagnostic machinery not emitting this // The file may be empty, which leads to the diagnostic machinery not emitting this
// note. This is a relatively simple way to detect that case and emit a span-less // note. This is a relatively simple way to detect that case and emit a span-less
// note instead. // note instead.
if tcx.sess.source_map().lookup_line(sp.lo()).is_ok() { if tcx.sess.source_map().lookup_line(sp.hi()).is_ok() {
err.set_span(sp); err.set_span(sp.shrink_to_hi());
err.span_label(sp, &note); err.span_label(sp.shrink_to_hi(), &note);
} else { } else {
err.note(&note); err.note(&note);
} }

View file

@ -1,9 +1,9 @@
#![u=||{static d=||1;}] #![u=||{static d=||1;}]
//~^ unexpected token //~^ unexpected token
//~| cannot find attribute `u` in this scope //~| cannot find attribute `u` in this scope
//~| `main` function not found in crate `issue_90873`
//~| missing type for `static` item //~| missing type for `static` item
#![a={impl std::ops::Neg for i8 {}}] #![a={impl std::ops::Neg for i8 {}}]
//~^ ERROR unexpected token //~^ ERROR unexpected token
//~| ERROR cannot find attribute `a` in this scope //~| ERROR cannot find attribute `a` in this scope
//~| ERROR `main` function not found in crate `issue_90873`

View file

@ -10,7 +10,7 @@ LL | #![u=||{static d=||1;}]
error: unexpected token: `{ error: unexpected token: `{
impl std::ops::Neg for i8 {} impl std::ops::Neg for i8 {}
}` }`
--> $DIR/issue-90873.rs:7:6 --> $DIR/issue-90873.rs:6:6
| |
LL | #![a={impl std::ops::Neg for i8 {}}] LL | #![a={impl std::ops::Neg for i8 {}}]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -22,22 +22,16 @@ LL | #![u=||{static d=||1;}]
| ^ | ^
error: cannot find attribute `a` in this scope error: cannot find attribute `a` in this scope
--> $DIR/issue-90873.rs:7:4 --> $DIR/issue-90873.rs:6:4
| |
LL | #![a={impl std::ops::Neg for i8 {}}] LL | #![a={impl std::ops::Neg for i8 {}}]
| ^ | ^
error[E0601]: `main` function not found in crate `issue_90873` error[E0601]: `main` function not found in crate `issue_90873`
--> $DIR/issue-90873.rs:1:1 --> $DIR/issue-90873.rs:6:37
| |
LL | / #![u=||{static d=||1;}] LL | #![a={impl std::ops::Neg for i8 {}}]
LL | | | ^ consider adding a `main` function to `$DIR/issue-90873.rs`
LL | |
LL | |
LL | |
LL | |
LL | | #![a={impl std::ops::Neg for i8 {}}]
| |____________________________________^ consider adding a `main` function to `$DIR/issue-90873.rs`
error: missing type for `static` item error: missing type for `static` item
--> $DIR/issue-90873.rs:1:16 --> $DIR/issue-90873.rs:1:16

View file

@ -1,9 +1,8 @@
error[E0601]: `main` function not found in crate `cfg_attr_cfg_2` error[E0601]: `main` function not found in crate `cfg_attr_cfg_2`
--> $DIR/cfg-attr-cfg-2.rs:8:1 --> $DIR/cfg-attr-cfg-2.rs:9:14
| |
LL | / #[cfg_attr(foo, cfg(bar))] LL | fn main() { }
LL | | fn main() { } | ^ consider adding a `main` function to `$DIR/cfg-attr-cfg-2.rs`
| |_____________^ consider adding a `main` function to `$DIR/cfg-attr-cfg-2.rs`
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0601]: `main` function not found in crate `cfg_in_crate_1` error[E0601]: `main` function not found in crate `cfg_in_crate_1`
--> $DIR/cfg-in-crate-1.rs:3:1 --> $DIR/cfg-in-crate-1.rs:3:13
| |
LL | #![cfg(bar)] LL | #![cfg(bar)]
| ^^^^^^^^^^^^ consider adding a `main` function to `$DIR/cfg-in-crate-1.rs` | ^ consider adding a `main` function to `$DIR/cfg-in-crate-1.rs`
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,14 +1,8 @@
error[E0601]: `main` function not found in crate `continue_after_missing_main` error[E0601]: `main` function not found in crate `continue_after_missing_main`
--> $DIR/continue-after-missing-main.rs:1:1 --> $DIR/continue-after-missing-main.rs:30:2
| |
LL | / #![allow(dead_code)] LL | }
LL | | | ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
LL | | struct Tableau<'a, MP> {
LL | | provider: &'a MP,
... |
LL | |
LL | | }
| |_^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,4 +1,4 @@
#![allow(dead_code)] //~ ERROR `main` function not found in crate #![allow(dead_code)]
struct Tableau<'a, MP> { struct Tableau<'a, MP> {
provider: &'a MP, provider: &'a MP,
@ -27,4 +27,4 @@ fn create_and_solve_subproblems<'data_provider, 'original_data, MP>(
) { ) {
let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound(); let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound();
//~^ ERROR lifetime mismatch //~^ ERROR lifetime mismatch
} } //~ ERROR `main` function not found in crate

View file

@ -1,14 +1,8 @@
error[E0601]: `main` function not found in crate `continue_after_missing_main` error[E0601]: `main` function not found in crate `continue_after_missing_main`
--> $DIR/continue-after-missing-main.rs:1:1 --> $DIR/continue-after-missing-main.rs:30:2
| |
LL | / #![allow(dead_code)] LL | }
LL | | | ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
LL | | struct Tableau<'a, MP> {
LL | | provider: &'a MP,
... |
LL | |
LL | | }
| |_^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
error[E0623]: lifetime mismatch error[E0623]: lifetime mismatch
--> $DIR/continue-after-missing-main.rs:28:56 --> $DIR/continue-after-missing-main.rs:28:56

View file

@ -1,10 +1,8 @@
error[E0601]: `main` function not found in crate `elided_test` error[E0601]: `main` function not found in crate `elided_test`
--> $DIR/elided-test.rs:5:1 --> $DIR/elided-test.rs:7:2
| |
LL | / #[test] LL | }
LL | | fn main() { | ^ consider adding a `main` function to `$DIR/elided-test.rs`
LL | | }
| |_^ consider adding a `main` function to `$DIR/elided-test.rs`
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,7 +1,6 @@
#![feature(imported_main)] #![feature(imported_main)]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
//~^^^ ERROR `main` function not found in crate
pub mod foo { pub mod foo {
type MainFn = impl Fn(); type MainFn = impl Fn();
//~^ ERROR could not find defining uses //~^ ERROR could not find defining uses
@ -11,4 +10,4 @@ pub mod foo {
//~^ ERROR mismatched types [E0308] //~^ ERROR mismatched types [E0308]
} }
use foo::BAR as main; use foo::BAR as main; //~ ERROR `main` function not found in crate

View file

@ -1,19 +1,13 @@
error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden` error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden`
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:1:1 --> $DIR/imported_main_const_fn_item_type_forbidden.rs:13:22
| |
LL | / #![feature(imported_main)] LL | use foo::BAR as main;
LL | | #![feature(type_alias_impl_trait)] | ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs`
LL | | #![allow(incomplete_features)] | |
LL | | | non-function item at `crate::main` is found
... |
LL | |
LL | | use foo::BAR as main;
| |_____----------------^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs`
| |
| non-function item at `crate::main` is found
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:10:29 --> $DIR/imported_main_const_fn_item_type_forbidden.rs:9:29
| |
LL | type MainFn = impl Fn(); LL | type MainFn = impl Fn();
| --------- the expected opaque type | --------- the expected opaque type
@ -25,7 +19,7 @@ LL | pub const BAR: MainFn = bar;
found fn item `fn() {bar}` found fn item `fn() {bar}`
error: could not find defining uses error: could not find defining uses
--> $DIR/imported_main_const_fn_item_type_forbidden.rs:6:19 --> $DIR/imported_main_const_fn_item_type_forbidden.rs:5:19
| |
LL | type MainFn = impl Fn(); LL | type MainFn = impl Fn();
| ^^^^^^^^^ | ^^^^^^^^^

View file

@ -1,7 +1,6 @@
#![feature(imported_main)] #![feature(imported_main)]
//~^ ERROR `main` function not found in crate
pub mod foo { pub mod foo {
pub const BAR: usize = 42; pub const BAR: usize = 42;
} }
use foo::BAR as main; use foo::BAR as main; //~ ERROR `main` function not found in crate

View file

@ -1,16 +1,10 @@
error[E0601]: `main` function not found in crate `imported_main_const_forbidden` error[E0601]: `main` function not found in crate `imported_main_const_forbidden`
--> $DIR/imported_main_const_forbidden.rs:1:1 --> $DIR/imported_main_const_forbidden.rs:6:22
| |
LL | / #![feature(imported_main)] LL | use foo::BAR as main;
LL | | | ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_forbidden.rs`
LL | | pub mod foo { | |
LL | | pub const BAR: usize = 42; | non-function item at `crate::main` is found
LL | | }
LL | |
LL | | use foo::BAR as main;
| |_____----------------^ consider adding a `main` function to `$DIR/imported_main_const_forbidden.rs`
| |
| non-function item at `crate::main` is found
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,6 +1,5 @@
mod m { mod m {
//~^ ERROR `main` function not found
// An inferred main entry point // An inferred main entry point
// must appear at the top of the crate // must appear at the top of the crate
fn main() { } fn main() { }
} } //~ ERROR `main` function not found

View file

@ -1,16 +1,11 @@
error[E0601]: `main` function not found in crate `main_wrong_location` error[E0601]: `main` function not found in crate `main_wrong_location`
--> $DIR/main-wrong-location.rs:1:1 --> $DIR/main-wrong-location.rs:5:2
| |
LL | / mod m { LL | }
LL | | | ^ the main function must be defined at the crate level (in `$DIR/main-wrong-location.rs`)
LL | | // An inferred main entry point
LL | | // must appear at the top of the crate
LL | | fn main() { }
LL | | }
| |_^ the main function must be defined at the crate level (in `$DIR/main-wrong-location.rs`)
| |
note: here is a function named `main` note: here is a function named `main`
--> $DIR/main-wrong-location.rs:5:5 --> $DIR/main-wrong-location.rs:4:5
| |
LL | fn main() { } LL | fn main() { }
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^

View file

@ -1,8 +1,8 @@
error[E0601]: `main` function not found in crate `missing_main` error[E0601]: `main` function not found in crate `missing_main`
--> $DIR/missing-main.rs:2:1 --> $DIR/missing-main.rs:2:14
| |
LL | fn mian() { } LL | fn mian() { }
| ^^^^^^^^^^^^^ consider adding a `main` function to `$DIR/missing-main.rs` | ^ consider adding a `main` function to `$DIR/missing-main.rs`
error: aborting due to previous error error: aborting due to previous error

View file

@ -5,10 +5,10 @@ LL | #![allow(unused_variables)];
| ^ help: remove this semicolon | ^ help: remove this semicolon
error[E0601]: `main` function not found in crate `issue_49040` error[E0601]: `main` function not found in crate `issue_49040`
--> $DIR/issue-49040.rs:1:1 --> $DIR/issue-49040.rs:1:29
| |
LL | #![allow(unused_variables)]; LL | #![allow(unused_variables)];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ consider adding a `main` function to `$DIR/issue-49040.rs` | ^ consider adding a `main` function to `$DIR/issue-49040.rs`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -1,14 +1,8 @@
error[E0601]: `main` function not found in crate `ice_6250` error[E0601]: `main` function not found in crate `ice_6250`
--> $DIR/ice-6250.rs:4:1 --> $DIR/ice-6250.rs:16:2
| |
LL | / pub struct Cache { LL | }
LL | | data: Vec<i32>, | ^ consider adding a `main` function to `$DIR/ice-6250.rs`
LL | | }
LL | |
... |
LL | | }
LL | | }
| |_^ consider adding a `main` function to `$DIR/ice-6250.rs`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/ice-6250.rs:12:14 --> $DIR/ice-6250.rs:12:14

View file

@ -1,10 +1,8 @@
error[E0601]: `main` function not found in crate `ice_6251` error[E0601]: `main` function not found in crate `ice_6251`
--> $DIR/ice-6251.rs:4:1 --> $DIR/ice-6251.rs:6:2
| |
LL | / fn bug<T>() -> impl Iterator<Item = [(); { |x: [u8]| x }]> { LL | }
LL | | std::iter::empty() | ^ consider adding a `main` function to `$DIR/ice-6251.rs`
LL | | }
| |_^ consider adding a `main` function to `$DIR/ice-6251.rs`
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
--> $DIR/ice-6251.rs:4:45 --> $DIR/ice-6251.rs:4:45