@@ -1937,33 +1937,27 @@ fn parse_native_lib_kind(
19371937 } ;
19381938
19391939 let kind = match kind {
1940- "dylib" => NativeLibKind :: Dylib { as_needed : None } ,
1941- "framework" => NativeLibKind :: Framework { as_needed : None } ,
19421940 "static" => NativeLibKind :: Static { bundle : None , whole_archive : None } ,
19431941 "static-nobundle" => {
19441942 early_warn (
19451943 error_format,
19461944 "library kind `static-nobundle` has been superseded by specifying \
1947- `-bundle` on library kind `static`. Try `static:-bundle`",
1945+ modifier `-bundle` with library kind `static`. Try `static:-bundle`",
19481946 ) ;
1949- if modifiers. is_some ( ) {
1950- early_error (
1951- error_format,
1952- "linking modifier can't be used with library kind `static-nobundle`" ,
1953- )
1954- }
19551947 if !nightly_options:: match_is_nightly_build ( matches) {
19561948 early_error (
19571949 error_format,
1958- "library kind `static-nobundle` are currently unstable and only accepted on \
1959- the nightly compiler",
1950+ "library kind `static-nobundle` is unstable \
1951+ and only accepted on the nightly compiler",
19601952 ) ;
19611953 }
19621954 NativeLibKind :: Static { bundle : Some ( false ) , whole_archive : None }
19631955 }
1964- s => early_error (
1956+ "dylib" => NativeLibKind :: Dylib { as_needed : None } ,
1957+ "framework" => NativeLibKind :: Framework { as_needed : None } ,
1958+ _ => early_error (
19651959 error_format,
1966- & format ! ( "unknown library kind `{s }`, expected one of dylib, framework, or static " ) ,
1960+ & format ! ( "unknown library kind `{kind }`, expected one of: static, dylib, framework " ) ,
19671961 ) ,
19681962 } ;
19691963 match modifiers {
@@ -1978,94 +1972,83 @@ fn parse_native_lib_modifiers(
19781972 error_format : ErrorOutputType ,
19791973 matches : & getopts:: Matches ,
19801974) -> ( NativeLibKind , Option < bool > ) {
1981- let report_unstable_modifier = |modifier| {
1982- if !nightly_options:: is_unstable_enabled ( matches) {
1983- let why = if nightly_options:: match_is_nightly_build ( matches) {
1984- " and only accepted on the nightly compiler"
1985- } else {
1986- ", the `-Z unstable-options` flag must also be passed to use it"
1987- } ;
1988- early_error (
1989- error_format,
1990- & format ! ( "{modifier} linking modifier is currently unstable{why}" ) ,
1991- )
1992- }
1993- } ;
1994-
1995- let mut has_duplicate_modifiers = false ;
19961975 let mut verbatim = None ;
19971976 for modifier in modifiers. split ( ',' ) {
19981977 let ( modifier, value) = match modifier. strip_prefix ( & [ '+' , '-' ] ) {
19991978 Some ( m) => ( m, modifier. starts_with ( '+' ) ) ,
20001979 None => early_error (
20011980 error_format,
20021981 "invalid linking modifier syntax, expected '+' or '-' prefix \
2003- before one of: bundle, verbatim, whole-archive, as-needed",
1982+ before one of: bundle, verbatim, whole-archive, as-needed",
20041983 ) ,
20051984 } ;
20061985
1986+ let report_unstable_modifier = || {
1987+ if !nightly_options:: is_unstable_enabled ( matches) {
1988+ let why = if nightly_options:: match_is_nightly_build ( matches) {
1989+ " and only accepted on the nightly compiler"
1990+ } else {
1991+ ", the `-Z unstable-options` flag must also be passed to use it"
1992+ } ;
1993+ early_error (
1994+ error_format,
1995+ & format ! ( "linking modifier `{modifier}` is unstable{why}" ) ,
1996+ )
1997+ }
1998+ } ;
1999+ let assign_modifier = |dst : & mut Option < bool > | {
2000+ if dst. is_some ( ) {
2001+ let msg = format ! ( "multiple `{modifier}` modifiers in a single `-l` option" ) ;
2002+ early_error ( error_format, & msg)
2003+ } else {
2004+ * dst = Some ( value) ;
2005+ }
2006+ } ;
20072007 match ( modifier, & mut kind) {
20082008 ( "bundle" , NativeLibKind :: Static { bundle, .. } ) => {
2009- report_unstable_modifier ( modifier) ;
2010- if bundle. is_some ( ) {
2011- has_duplicate_modifiers = true ;
2012- }
2013- * bundle = Some ( value) ;
2009+ report_unstable_modifier ( ) ;
2010+ assign_modifier ( bundle)
20142011 }
20152012 ( "bundle" , _) => early_error (
20162013 error_format,
2017- "bundle linking modifier is only compatible with \
2018- `static` linking kind",
2014+ "linking modifier `bundle` is only compatible with `static` linking kind" ,
20192015 ) ,
20202016
20212017 ( "verbatim" , _) => {
2022- report_unstable_modifier ( modifier) ;
2023- if verbatim. is_some ( ) {
2024- has_duplicate_modifiers = true ;
2025- }
2026- verbatim = Some ( value) ;
2018+ report_unstable_modifier ( ) ;
2019+ assign_modifier ( & mut verbatim)
20272020 }
20282021
20292022 ( "whole-archive" , NativeLibKind :: Static { whole_archive, .. } ) => {
2030- if whole_archive. is_some ( ) {
2031- has_duplicate_modifiers = true ;
2032- }
2033- * whole_archive = Some ( value) ;
2023+ assign_modifier ( whole_archive)
20342024 }
20352025 ( "whole-archive" , _) => early_error (
20362026 error_format,
2037- "whole-archive linking modifier is only compatible with \
2038- `static` linking kind",
2027+ "linking modifier `whole-archive` is only compatible with `static` linking kind" ,
20392028 ) ,
20402029
20412030 ( "as-needed" , NativeLibKind :: Dylib { as_needed } )
20422031 | ( "as-needed" , NativeLibKind :: Framework { as_needed } ) => {
2043- report_unstable_modifier ( modifier) ;
2044- if as_needed. is_some ( ) {
2045- has_duplicate_modifiers = true ;
2046- }
2047- * as_needed = Some ( value) ;
2032+ report_unstable_modifier ( ) ;
2033+ assign_modifier ( as_needed)
20482034 }
20492035 ( "as-needed" , _) => early_error (
20502036 error_format,
2051- "as-needed linking modifier is only compatible with \
2052- `dylib` and `framework` linking kinds",
2037+ "linking modifier `as-needed` is only compatible with \
2038+ `dylib` and `framework` linking kinds",
20532039 ) ,
20542040
20552041 // Note: this error also excludes the case with empty modifier
20562042 // string, like `modifiers = ""`.
20572043 _ => early_error (
20582044 error_format,
20592045 & format ! (
2060- "unrecognized linking modifier `{modifier}`, expected one \
2061- of: bundle, verbatim, whole-archive, as-needed"
2046+ "unknown linking modifier `{modifier}`, expected one \
2047+ of: bundle, verbatim, whole-archive, as-needed"
20622048 ) ,
20632049 ) ,
20642050 }
20652051 }
2066- if has_duplicate_modifiers {
2067- report_unstable_modifier ( "duplicating" )
2068- }
20692052
20702053 ( kind, verbatim)
20712054}
@@ -2093,6 +2076,9 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
20932076 None => ( name, None ) ,
20942077 Some ( ( name, new_name) ) => ( name. to_string ( ) , Some ( new_name. to_owned ( ) ) ) ,
20952078 } ;
2079+ if name. is_empty ( ) {
2080+ early_error ( error_format, "library name must not be empty" ) ;
2081+ }
20962082 NativeLib { name, new_name, kind, verbatim }
20972083 } )
20982084 . collect ( )
0 commit comments