Skip to content

Commit 5db9bee

Browse files
committed
Rollup merge of #25252 - inrustwetrust:crate-type-attribute, r=alexcrichton
Fixes the problem in #16974 with unhelpful error messages when accidentally using the wrong syntax for the `crate_type="lib"` attribute. The attribute syntax error now shows up instead of "main function not found".
2 parents d6ce439 + 8e8f8d9 commit 5db9bee

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
@@ -872,11 +872,8 @@ pub fn collect_crate_types(session: &Session,
872872
None
873873
}
874874
_ => {
875-
session.add_lint(lint::builtin::UNKNOWN_CRATE_TYPES,
876-
ast::CRATE_NODE_ID,
877-
a.span,
878-
"`crate_type` requires a \
879-
value".to_string());
875+
session.span_err(a.span, "`crate_type` requires a value");
876+
session.note("for example: `#![crate_type=\"lib\"]`");
880877
None
881878
}
882879
}
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)