Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ use rustc_middle::ty::{
ResolverGlobalCtxt, TyCtxt, TyCtxtFeed, Visibility,
};
use rustc_query_system::ich::StableHashingContext;
use rustc_session::config::CrateType;
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
use rustc_span::{DUMMY_SP, Ident, Macros20NormalizedIdent, Span, Symbol, kw, sym};
Expand Down Expand Up @@ -2430,6 +2431,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

fn resolve_main(&mut self) {
let any_exe = self.tcx.crate_types().contains(&CrateType::Executable);
// Don't try to resolve main unless it's an executable
if !any_exe {
return;
}

let module = self.graph_root;
let ident = Ident::with_dummy_span(sym::main);
let parent_scope = &ParentScope::module(module, self.arenas);
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/entry-point/imported_main_conflict_lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Tests that ambiguously glob importing main doesn't fail to compile in non-executable crates
// Regression test for #149412
//@ check-pass
#![crate_type = "lib"]

mod m1 { pub(crate) fn main() {} }
mod m2 { pub(crate) fn main() {} }

use m1::*;
use m2::*;
Loading