Skip to content

Commit 6ed8e68

Browse files
Rollup merge of #149867 - 21aslade:lib-crate-main, r=Kivooeo
only resolve main in bin crates Fixes #149412
2 parents 4b195d1 + c27bcef commit 6ed8e68

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

compiler/rustc_resolve/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use rustc_middle::ty::{
7373
ResolverGlobalCtxt, TyCtxt, TyCtxtFeed, Visibility,
7474
};
7575
use rustc_query_system::ich::StableHashingContext;
76+
use rustc_session::config::CrateType;
7677
use rustc_session::lint::builtin::PRIVATE_MACRO_USE;
7778
use rustc_span::hygiene::{ExpnId, LocalExpnId, MacroKind, SyntaxContext, Transparency};
7879
use rustc_span::{DUMMY_SP, Ident, Macros20NormalizedIdent, Span, Symbol, kw, sym};
@@ -2430,6 +2431,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24302431
}
24312432

24322433
fn resolve_main(&mut self) {
2434+
let any_exe = self.tcx.crate_types().contains(&CrateType::Executable);
2435+
// Don't try to resolve main unless it's an executable
2436+
if !any_exe {
2437+
return;
2438+
}
2439+
24332440
let module = self.graph_root;
24342441
let ident = Ident::with_dummy_span(sym::main);
24352442
let parent_scope = &ParentScope::module(module, self.arenas);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Tests that ambiguously glob importing main doesn't fail to compile in non-executable crates
2+
// Regression test for #149412
3+
//@ check-pass
4+
#![crate_type = "lib"]
5+
6+
mod m1 { pub(crate) fn main() {} }
7+
mod m2 { pub(crate) fn main() {} }
8+
9+
use m1::*;
10+
use m2::*;

0 commit comments

Comments
 (0)