diff options
| author | scalexm <martin.alex32@hotmail.fr> | 2017-09-13 22:40:48 +0200 |
|---|---|---|
| committer | scalexm <martin.alex32@hotmail.fr> | 2017-09-20 20:43:41 +0200 |
| commit | f7964aebe516bc7e4f06f7128ebb39ad5576a1a7 (patch) | |
| tree | fb903110af5ee4e9a3437f70b2cd9b7a7466ef6d /src/libsyntax | |
| parent | 01c65cb15ac57bfdc91613a4f6032ecc76c402a3 (diff) | |
| download | rust-f7964aebe516bc7e4f06f7128ebb39ad5576a1a7.tar.gz rust-f7964aebe516bc7e4f06f7128ebb39ad5576a1a7.zip | |
Implement `Copy`/`Clone` for closures
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ae0dd872963..6560943a932 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -385,6 +385,10 @@ declare_features! ( // allow '|' at beginning of match arms (RFC 1925) (active, match_beginning_vert, "1.21.0", Some(44101)), + + // Copy/Clone closures (RFC 2132) + (active, clone_closures, "1.22.0", Some(44490)), + (active, copy_closures, "1.22.0", Some(44490)), ); declare_features! ( @@ -1573,7 +1577,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> Features { let mut features = Features::new(); - let mut feature_checker = MutexFeatureChecker::default(); + let mut feature_checker = FeatureChecker::default(); for attr in krate_attrs { if !attr.check_name("feature") { @@ -1622,14 +1626,16 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute]) -> F features } -// A collector for mutually-exclusive features and their flag spans +/// A collector for mutually exclusive and interdependent features and their flag spans. #[derive(Default)] -struct MutexFeatureChecker { +struct FeatureChecker { proc_macro: Option<Span>, custom_attribute: Option<Span>, + copy_closures: Option<Span>, + clone_closures: Option<Span>, } -impl MutexFeatureChecker { +impl FeatureChecker { // If this method turns out to be a hotspot due to branching, // the branching can be eliminated by modifying `set!()` to set these spans // only for the features that need to be checked for mutual exclusion. @@ -1642,6 +1648,14 @@ impl MutexFeatureChecker { if features.custom_attribute { self.custom_attribute = self.custom_attribute.or(Some(span)); } + + if features.copy_closures { + self.copy_closures = self.copy_closures.or(Some(span)); + } + + if features.clone_closures { + self.clone_closures = self.clone_closures.or(Some(span)); + } } fn check(self, handler: &Handler) { @@ -1653,6 +1667,15 @@ impl MutexFeatureChecker { panic!(FatalError); } + + if let (Some(span), None) = (self.copy_closures, self.clone_closures) { + handler.struct_span_err(span, "`#![feature(copy_closures)]` can only be used with \ + `#![feature(clone_closures)]`") + .span_note(span, "`#![feature(copy_closures)]` declared here") + .emit(); + + panic!(FatalError); + } } } |
