Skip to content

Commit b510b90

Browse files
committed
Do not fail if --emit≠link and there’s no main fn
Fixes #21813
1 parent e62fec3 commit b510b90

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/librustc/middle/entry.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ pub fn find_entry_point(session: &Session, ast_map: &ast_map::Map) {
5050
let any_exe = session.crate_types.borrow().iter().any(|ty| {
5151
*ty == config::CrateTypeExecutable
5252
});
53-
if !any_exe {
53+
let emit_link = session.opts.output_types.iter().any(|ty| {
54+
*ty == config::OutputTypeExe
55+
});
56+
if !any_exe || !emit_link {
5457
// No need to find a main function
5558
return
5659
}

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub struct Options {
8282
pub debuginfo: DebugInfoLevel,
8383
pub lint_opts: Vec<(String, lint::Level)>,
8484
pub describe_lints: bool,
85-
pub output_types: Vec<OutputType> ,
85+
pub output_types: Vec<OutputType>,
8686
// This was mutable for rustpkg, which updates search paths based on the
8787
// parsed code. It remains mutable in case its replacements wants to use
8888
// this.

0 commit comments

Comments
 (0)