Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny mixing bin crate type with lib crate types #92933

Merged
merged 2 commits into from
Feb 18, 2022
Merged
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
5 changes: 0 additions & 5 deletions compiler/rustc_builtin_macros/src/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub fn inject(
is_proc_macro_crate: bool,
has_proc_macro_decls: bool,
is_test_crate: bool,
num_crate_types: usize,
handler: &rustc_errors::Handler,
) -> ast::Crate {
let ecfg = ExpansionConfig::default("proc_macro".to_string());
Expand All @@ -81,10 +80,6 @@ pub fn inject(
return krate;
}

if num_crate_types > 1 {
handler.err("cannot mix `proc-macro` crate type with others");
}

if is_test_crate {
return krate;
}
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,18 @@ pub fn configure_and_expand(
});

let crate_types = sess.crate_types();
let is_executable_crate = crate_types.contains(&CrateType::Executable);
let is_proc_macro_crate = crate_types.contains(&CrateType::ProcMacro);

if crate_types.len() > 1 {
if is_executable_crate {
sess.err("cannot mix `bin` crate type with others");
}
if is_proc_macro_crate {
sess.err("cannot mix `proc-macro` crate type with others");
}
}

// For backwards compatibility, we don't try to run proc macro injection
// if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being
// specified. This should only affect users who manually invoke 'rustdoc', as
Expand All @@ -400,7 +410,6 @@ pub fn configure_and_expand(
msg.emit()
} else {
krate = sess.time("maybe_create_a_macro_crate", || {
let num_crate_types = crate_types.len();
let is_test_crate = sess.opts.test;
rustc_builtin_macros::proc_macro_harness::inject(
sess,
Expand All @@ -409,7 +418,6 @@ pub fn configure_and_expand(
is_proc_macro_crate,
has_proc_macro_decls,
is_test_crate,
num_crate_types,
sess.diagnostic(),
)
});
Expand Down
6 changes: 0 additions & 6 deletions src/test/run-make-fulldeps/libs-and-bins/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions src/test/run-make-fulldeps/libs-and-bins/foo.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/test/run-make-fulldeps/output-with-hyphens/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-include ../tools.mk

all:
$(RUSTC) foo-bar.rs
$(RUSTC) foo-bar.rs --crate-type bin
[ -f $(TMPDIR)/$(call BIN,foo-bar) ]
$(RUSTC) foo-bar.rs --crate-type lib
[ -f $(TMPDIR)/libfoo_bar.rlib ]
3 changes: 0 additions & 3 deletions src/test/run-make-fulldeps/output-with-hyphens/foo-bar.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#![crate_type = "lib"]
#![crate_type = "bin"]

fn main() {}