Skip to content

Commit 8e8f8d9

Browse files
committed
Upgraded warning for invalid crate_type attribute syntax to an error
If the user intended to set the crate_type to "lib" but accidentally used incorrect syntax such as `#![crate_type(lib)]`, the compilation would fail with "main function not found". This made it hard to locate the source of the problem, since the failure would cause the warning about the incorrect attribute not to be shown.
1 parent d8b64c7 commit 8e8f8d9

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/librustc_driver/driver.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -871,11 +871,8 @@ pub fn collect_crate_types(session: &Session,
871871
None
872872
}
873873
_ => {
874-
session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPES,
875-
ast::CRATE_NODE_ID,
876-
a.span,
877-
"`crate_type` requires a \
878-
value".to_string());
874+
session.span_err(a.span, "`crate_type` requires a value");
875+
session.note("for example: `#![crate_type=\"lib\"]`");
879876
None
880877
}
881878
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// regression test for issue 16974
12+
#![crate_type(lib)] //~ ERROR `crate_type` requires a value
13+
14+
fn my_lib_fn() {}

0 commit comments

Comments
 (0)