Skip to content

Commit 3616da7

Browse files
committed
Split syntax::feature_gate::get_features in two methods
1 parent bce32b5 commit 3616da7

File tree

1 file changed

+50
-42
lines changed

1 file changed

+50
-42
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,14 +1891,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18911891

18921892
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
18931893
crate_edition: Edition) -> Features {
1894-
fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
1895-
let mut err = struct_span_err!(span_handler, span, E0557, "feature has been removed");
1896-
if let Some(reason) = reason {
1897-
err.span_note(span, reason);
1898-
}
1899-
err.emit();
1900-
}
1901-
19021894
let mut features = Features::new();
19031895

19041896
let mut feature_checker = FeatureChecker::default();
@@ -1934,49 +1926,65 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
19341926
continue
19351927
};
19361928

1937-
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
1938-
set(&mut features, mi.span);
1939-
feature_checker.collect(&features, mi.span);
1940-
continue
1941-
}
1929+
set_feature(
1930+
name,
1931+
mi.span,
1932+
span_handler,
1933+
&mut features,
1934+
&mut feature_checker,
1935+
crate_edition,
1936+
);
1937+
}
1938+
}
19421939

1943-
let removed = REMOVED_FEATURES.iter().find(|f| name == f.0);
1944-
let stable_removed = STABLE_REMOVED_FEATURES.iter().find(|f| name == f.0);
1945-
if let Some((.., reason)) = removed.or(stable_removed) {
1946-
feature_removed(span_handler, mi.span, *reason);
1947-
continue
1948-
}
1940+
feature_checker.check(span_handler);
19491941

1950-
if ACCEPTED_FEATURES.iter().any(|f| name == f.0) {
1951-
features.declared_stable_lang_features.push((name, mi.span));
1952-
continue
1953-
}
1942+
features
1943+
}
19541944

1955-
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
1956-
if *edition <= crate_edition {
1957-
continue
1958-
}
1945+
fn set_feature(name: Symbol, span: Span, span_handler: &Handler, features: &mut Features,
1946+
feature_checker: &mut FeatureChecker, crate_edition: Edition) {
1947+
if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) {
1948+
set(features, span);
1949+
feature_checker.collect(&features, span);
1950+
return;
1951+
}
19591952

1960-
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1961-
if let Some(f_edition) = f_edition {
1962-
if *edition >= f_edition {
1963-
// FIXME(Manishearth) there is currently no way to set
1964-
// lib features by edition
1965-
set(&mut features, DUMMY_SP);
1966-
}
1967-
}
1968-
}
1953+
let removed = REMOVED_FEATURES.iter().find(|f| name == f.0);
1954+
let stable_removed = STABLE_REMOVED_FEATURES.iter().find(|f| name == f.0);
1955+
if let Some((.., reason)) = removed.or(stable_removed) {
1956+
let mut err = struct_span_err!(span_handler, span, E0557, "feature has been removed");
1957+
if let Some(reason) = reason {
1958+
err.span_note(span, reason);
1959+
}
1960+
err.emit();
1961+
return;
1962+
}
19691963

1970-
continue
1971-
}
1964+
if ACCEPTED_FEATURES.iter().any(|f| name == f.0) {
1965+
features.declared_stable_lang_features.push((name, span));
1966+
return;
1967+
}
19721968

1973-
features.declared_lib_features.push((name, mi.span));
1969+
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
1970+
if *edition <= crate_edition {
1971+
return;
19741972
}
1975-
}
19761973

1977-
feature_checker.check(span_handler);
1974+
for &(.., f_edition, set) in ACTIVE_FEATURES.iter() {
1975+
if let Some(f_edition) = f_edition {
1976+
if *edition >= f_edition {
1977+
// FIXME(Manishearth) there is currently no way to set
1978+
// lib features by edition
1979+
set(features, DUMMY_SP);
1980+
}
1981+
}
1982+
}
19781983

1979-
features
1984+
return;
1985+
}
1986+
1987+
features.declared_lib_features.push((name, span));
19801988
}
19811989

19821990
/// A collector for mutually exclusive and interdependent features and their flag spans.

0 commit comments

Comments
 (0)