@@ -1937,33 +1937,27 @@ fn parse_native_lib_kind(
1937
1937
} ;
1938
1938
1939
1939
let kind = match kind {
1940
- "dylib" => NativeLibKind :: Dylib { as_needed : None } ,
1941
- "framework" => NativeLibKind :: Framework { as_needed : None } ,
1942
1940
"static" => NativeLibKind :: Static { bundle : None , whole_archive : None } ,
1943
1941
"static-nobundle" => {
1944
1942
early_warn (
1945
1943
error_format,
1946
1944
"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`",
1948
1946
) ;
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
- }
1955
1947
if !nightly_options:: match_is_nightly_build ( matches) {
1956
1948
early_error (
1957
1949
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",
1960
1952
) ;
1961
1953
}
1962
1954
NativeLibKind :: Static { bundle : Some ( false ) , whole_archive : None }
1963
1955
}
1964
- s => early_error (
1956
+ "dylib" => NativeLibKind :: Dylib { as_needed : None } ,
1957
+ "framework" => NativeLibKind :: Framework { as_needed : None } ,
1958
+ _ => early_error (
1965
1959
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 " ) ,
1967
1961
) ,
1968
1962
} ;
1969
1963
match modifiers {
@@ -1978,94 +1972,83 @@ fn parse_native_lib_modifiers(
1978
1972
error_format : ErrorOutputType ,
1979
1973
matches : & getopts:: Matches ,
1980
1974
) -> ( 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 ;
1996
1975
let mut verbatim = None ;
1997
1976
for modifier in modifiers. split ( ',' ) {
1998
1977
let ( modifier, value) = match modifier. strip_prefix ( & [ '+' , '-' ] ) {
1999
1978
Some ( m) => ( m, modifier. starts_with ( '+' ) ) ,
2000
1979
None => early_error (
2001
1980
error_format,
2002
1981
"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",
2004
1983
) ,
2005
1984
} ;
2006
1985
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
+ } ;
2007
2007
match ( modifier, & mut kind) {
2008
2008
( "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)
2014
2011
}
2015
2012
( "bundle" , _) => early_error (
2016
2013
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" ,
2019
2015
) ,
2020
2016
2021
2017
( "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)
2027
2020
}
2028
2021
2029
2022
( "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)
2034
2024
}
2035
2025
( "whole-archive" , _) => early_error (
2036
2026
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" ,
2039
2028
) ,
2040
2029
2041
2030
( "as-needed" , NativeLibKind :: Dylib { as_needed } )
2042
2031
| ( "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)
2048
2034
}
2049
2035
( "as-needed" , _) => early_error (
2050
2036
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",
2053
2039
) ,
2054
2040
2055
2041
// Note: this error also excludes the case with empty modifier
2056
2042
// string, like `modifiers = ""`.
2057
2043
_ => early_error (
2058
2044
error_format,
2059
2045
& 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"
2062
2048
) ,
2063
2049
) ,
2064
2050
}
2065
2051
}
2066
- if has_duplicate_modifiers {
2067
- report_unstable_modifier ( "duplicating" )
2068
- }
2069
2052
2070
2053
( kind, verbatim)
2071
2054
}
@@ -2093,6 +2076,9 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
2093
2076
None => ( name, None ) ,
2094
2077
Some ( ( name, new_name) ) => ( name. to_string ( ) , Some ( new_name. to_owned ( ) ) ) ,
2095
2078
} ;
2079
+ if name. is_empty ( ) {
2080
+ early_error ( error_format, "library name must not be empty" ) ;
2081
+ }
2096
2082
NativeLib { name, new_name, kind, verbatim }
2097
2083
} )
2098
2084
. collect ( )
0 commit comments