diff options
Diffstat (limited to 'compiler/rustc_passes/src/entry.rs')
| -rw-r--r-- | compiler/rustc_passes/src/entry.rs | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index f5040a373c2..5a1373ad1a2 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -148,33 +148,29 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) -> Option<(De } else if let Some((def_id, _)) = visitor.attr_main_fn { Some((def_id.to_def_id(), EntryFnType::Main)) } else { - if let Some(main_def) = tcx.resolutions(()).main_def { - if let Some(def_id) = main_def.opt_fn_def_id() { - // non-local main imports are handled below - if let Some(def_id) = def_id.as_local() { - if matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) { - tcx.sess - .struct_span_err( - tcx.def_span(def_id), - "the `main` function cannot be declared in an `extern` block", - ) - .emit(); - return None; - } - } - - if main_def.is_import && !tcx.features().imported_main { - let span = main_def.span; - feature_err( - &tcx.sess.parse_sess, - sym::imported_main, - span, - "using an imported function as entry point `main` is experimental", + if let Some(main_def) = tcx.resolutions(()).main_def && let Some(def_id) = main_def.opt_fn_def_id() { + // non-local main imports are handled below + if let Some(def_id) = def_id.as_local() && matches!(tcx.hir().find_by_def_id(def_id), Some(Node::ForeignItem(_))) { + tcx.sess + .struct_span_err( + tcx.def_span(def_id), + "the `main` function cannot be declared in an `extern` block", ) .emit(); - } - return Some((def_id, EntryFnType::Main)); + return None; } + + if main_def.is_import && !tcx.features().imported_main { + let span = main_def.span; + feature_err( + &tcx.sess.parse_sess, + sym::imported_main, + span, + "using an imported function as entry point `main` is experimental", + ) + .emit(); + } + return Some((def_id, EntryFnType::Main)); } no_main_err(tcx, visitor); None @@ -225,11 +221,9 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_, '_>) { err.note(¬e); } - if let Some(main_def) = tcx.resolutions(()).main_def { - if main_def.opt_fn_def_id().is_none() { - // There is something at `crate::main`, but it is not a function definition. - err.span_label(main_def.span, "non-function item at `crate::main` is found"); - } + if let Some(main_def) = tcx.resolutions(()).main_def && main_def.opt_fn_def_id().is_none(){ + // There is something at `crate::main`, but it is not a function definition. + err.span_label(main_def.span, "non-function item at `crate::main` is found"); } if tcx.sess.teach(&err.get_code().unwrap()) { |
