} 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
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()) {