Skip to content

Commit 13a05a2

Browse files
committed
Continue evaluating after missing main
1 parent 96d700f commit 13a05a2

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/librustc/middle/entry.rs

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ fn configure_main(
163163
err.span_note(span, "here is a function named 'main'");
164164
}
165165
err.emit();
166-
tcx.sess.abort_if_errors();
167166
} else {
168167
if let Some(ref filename) = tcx.sess.local_crate_source_file {
169168
err.note(&format!("consider adding a `main` function to `{}`", filename.display()));

src/librustc_interface/passes.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,11 @@ fn analysis<'tcx>(
888888
assert_eq!(cnum, LOCAL_CRATE);
889889

890890
let sess = tcx.sess;
891+
let mut entry_point = None;
891892

892893
time(sess, "misc checking 1", || {
893894
parallel!({
894-
time(sess, "looking for entry point", || {
895+
entry_point = time(sess, "looking for entry point", || {
895896
middle::entry::find_entry_point(tcx)
896897
});
897898

@@ -939,7 +940,10 @@ fn analysis<'tcx>(
939940

940941
// Abort so we don't try to construct MIR with liveness errors.
941942
// We also won't want to continue with errors from rvalue promotion
942-
tcx.sess.abort_if_errors();
943+
// We only do so if the only error found so far *isn't* a missing `fn main()`
944+
if !(entry_point.is_none() && sess.err_count() == 1) {
945+
tcx.sess.abort_if_errors();
946+
}
943947

944948
time(sess, "borrow checking", || {
945949
if tcx.use_ast_borrowck() {
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![allow(dead_code)]
2+
3+
// error-pattern:`main` function not found in crate
4+
5+
struct Tableau<'a, MP> {
6+
provider: &'a MP,
7+
}
8+
9+
impl<'adapted_matrix_provider, 'original_data, MP>
10+
Tableau<'adapted_matrix_provider, AdaptedMatrixProvider<'original_data, MP>>
11+
{
12+
fn provider(&self) -> &'adapted_matrix_provider AdaptedMatrixProvider</*'original_data,*/ MP> {
13+
self.provider
14+
}
15+
}
16+
17+
struct AdaptedMatrixProvider<'a, T> {
18+
original_problem: &'a T,
19+
}
20+
21+
impl<'a, T> AdaptedMatrixProvider<'a, T> {
22+
fn clone_with_extra_bound(&self) -> Self {
23+
AdaptedMatrixProvider { original_problem: self.original_problem }
24+
}
25+
}
26+
27+
fn create_and_solve_subproblems<'data_provider, 'original_data, MP>(
28+
tableau: Tableau<'data_provider, AdaptedMatrixProvider<'original_data, MP>>,
29+
) {
30+
let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound();
31+
//~^ ERROR lifetime mismatch
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0601]: `main` function not found in crate `continue_after_missing_main`
2+
|
3+
= note: consider adding a `main` function to `$DIR/continue-after-missing-main.rs`
4+
5+
error[E0623]: lifetime mismatch
6+
--> $DIR/continue-after-missing-main.rs:30:56
7+
|
8+
LL | tableau: Tableau<'data_provider, AdaptedMatrixProvider<'original_data, MP>>,
9+
| ------------------------------------------------------------------ these two types are declared with different lifetimes...
10+
LL | ) {
11+
LL | let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound();
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `tableau` flows into `tableau` here
13+
14+
error: aborting due to 2 previous errors
15+
16+
Some errors occurred: E0601, E0623.
17+
For more information about an error, try `rustc --explain E0601`.

0 commit comments

Comments
 (0)