@@ -1930,7 +1930,15 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1930
1930
let mut features = Features :: new ( ) ;
1931
1931
let mut edition_enabled_features = FxHashMap ( ) ;
1932
1932
1933
- for & ( name, .., f_edition, set) in ACTIVE_FEATURES . iter ( ) {
1933
+ for & edition in ALL_EDITIONS {
1934
+ if edition <= crate_edition {
1935
+ // The `crate_edition` implies its respective umbrella feature-gate
1936
+ // (i.e. `#![feature(rust_20XX_preview)]` isn't needed on edition 20XX).
1937
+ edition_enabled_features. insert ( Symbol :: intern ( edition. feature_name ( ) ) , edition) ;
1938
+ }
1939
+ }
1940
+
1941
+ for & ( name, .., f_edition, set) in ACTIVE_FEATURES {
1934
1942
if let Some ( f_edition) = f_edition {
1935
1943
if f_edition <= crate_edition {
1936
1944
set ( & mut features, DUMMY_SP ) ;
@@ -1939,26 +1947,22 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1939
1947
}
1940
1948
}
1941
1949
1950
+ // Process the edition umbrella feature-gates first, to ensure
1951
+ // `edition_enabled_features` is completed before it's queried.
1942
1952
for attr in krate_attrs {
1943
1953
if !attr. check_name ( "feature" ) {
1944
1954
continue
1945
1955
}
1946
1956
1947
1957
let list = match attr. meta_item_list ( ) {
1948
1958
Some ( list) => list,
1949
- None => {
1950
- span_err ! ( span_handler, attr. span, E0555 ,
1951
- "malformed feature attribute, expected #![feature(...)]" ) ;
1952
- continue
1953
- }
1959
+ None => continue ,
1954
1960
} ;
1955
1961
1956
1962
for mi in list {
1957
1963
let name = if let Some ( word) = mi. word ( ) {
1958
1964
word. name ( )
1959
1965
} else {
1960
- span_err ! ( span_handler, mi. span, E0556 ,
1961
- "malformed feature, expected just one word" ) ;
1962
1966
continue
1963
1967
} ;
1964
1968
@@ -1974,10 +1978,10 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1974
1978
1975
1979
if let Some ( edition) = ALL_EDITIONS . iter ( ) . find ( |e| name == e. feature_name ( ) ) {
1976
1980
if * edition <= crate_edition {
1977
- continue
1981
+ continue ;
1978
1982
}
1979
1983
1980
- for & ( name, .., f_edition, set) in ACTIVE_FEATURES . iter ( ) {
1984
+ for & ( name, .., f_edition, set) in ACTIVE_FEATURES {
1981
1985
if let Some ( f_edition) = f_edition {
1982
1986
if f_edition <= * edition {
1983
1987
// FIXME(Manishearth) there is currently no way to set
@@ -1987,24 +1991,53 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
1987
1991
}
1988
1992
}
1989
1993
}
1994
+ }
1995
+ }
1996
+ }
1997
+
1998
+ for attr in krate_attrs {
1999
+ if !attr. check_name ( "feature" ) {
2000
+ continue
2001
+ }
2002
+
2003
+ let list = match attr. meta_item_list ( ) {
2004
+ Some ( list) => list,
2005
+ None => {
2006
+ span_err ! ( span_handler, attr. span, E0555 ,
2007
+ "malformed feature attribute, expected #![feature(...)]" ) ;
2008
+ continue
2009
+ }
2010
+ } ;
1990
2011
2012
+ for mi in list {
2013
+ let name = if let Some ( word) = mi. word ( ) {
2014
+ word. name ( )
2015
+ } else {
2016
+ span_err ! ( span_handler, mi. span, E0556 ,
2017
+ "malformed feature, expected just one word" ) ;
1991
2018
continue
2019
+ } ;
2020
+
2021
+ if let Some ( edition) = edition_enabled_features. get ( & name) {
2022
+ struct_span_warn ! (
2023
+ span_handler,
2024
+ mi. span,
2025
+ E0705 ,
2026
+ "the feature `{}` is included in the Rust {} edition" ,
2027
+ name,
2028
+ edition,
2029
+ ) . emit ( ) ;
2030
+ continue ;
2031
+ }
2032
+
2033
+ if ALL_EDITIONS . iter ( ) . any ( |e| name == e. feature_name ( ) ) {
2034
+ // Handled in the separate loop above.
2035
+ continue ;
1992
2036
}
1993
2037
1994
2038
if let Some ( ( .., set) ) = ACTIVE_FEATURES . iter ( ) . find ( |f| name == f. 0 ) {
1995
- if let Some ( edition) = edition_enabled_features. get ( & name) {
1996
- struct_span_warn ! (
1997
- span_handler,
1998
- mi. span,
1999
- E0705 ,
2000
- "the feature `{}` is included in the Rust {} edition" ,
2001
- name,
2002
- edition,
2003
- ) . emit ( ) ;
2004
- } else {
2005
- set ( & mut features, mi. span ) ;
2006
- features. declared_lang_features . push ( ( name, mi. span , None ) ) ;
2007
- }
2039
+ set ( & mut features, mi. span ) ;
2040
+ features. declared_lang_features . push ( ( name, mi. span , None ) ) ;
2008
2041
continue
2009
2042
}
2010
2043
0 commit comments