]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #53364 - varkor:gat-warn-broken, r=pnkfelix
authorkennytm <kennytm@gmail.com>
Thu, 16 Aug 2018 16:13:23 +0000 (00:13 +0800)
committerGitHub <noreply@github.com>
Thu, 16 Aug 2018 16:13:23 +0000 (00:13 +0800)
Warn if the user tries to use GATs

GATs are currently broken, but still accessible behind a feature gate. This leads to people attempting to use them and then immediately encountering ICEs (or other broken behaviour). Here, we emit a warning if the user tries to use any feature associated with GATs, hopefully making it obvious that ICEs and the like are expected. For the meantime, this seems better than continually getting reported errors (for example: [here](https://github.com/rust-lang/rust/issues?q=is%3Aissue+gat+is%3Aclosed) and [here](https://github.com/rust-lang/rust/issues?utf8=%E2%9C%93&q=is%3Aissue+generic_associated_types+is%3Aclosed)).

1  2 
src/libsyntax/feature_gate.rs

index f837bead6a08527e0647badba922205ecf5801d3,98fbbe4bdef0c2759e2b464afe4519b7da023855..395e5c98652326091ed5ce6f79d573698426722c
@@@ -1526,29 -1526,27 +1526,29 @@@ impl<'a> Visitor<'a> for PostExpansionV
              }
          }
  
 -        match attr.parse_meta(self.context.parse_sess) {
 -            Ok(meta) => {
 -                // allow attr_literals in #[repr(align(x))] and #[repr(packed(n))]
 -                let mut allow_attr_literal = false;
 -                if attr.path == "repr" {
 -                    if let Some(content) = meta.meta_item_list() {
 -                        allow_attr_literal = content.iter().any(
 -                            |c| c.check_name("align") || c.check_name("packed"));
 +        if !self.context.features.unrestricted_attribute_tokens {
 +            // Unfortunately, `parse_meta` cannot be called speculatively because it can report
 +            // errors by itself, so we have to call it only if the feature is disabled.
 +            match attr.parse_meta(self.context.parse_sess) {
 +                Ok(meta) => {
 +                    // allow attr_literals in #[repr(align(x))] and #[repr(packed(n))]
 +                    let mut allow_attr_literal = false;
 +                    if attr.path == "repr" {
 +                        if let Some(content) = meta.meta_item_list() {
 +                            allow_attr_literal = content.iter().any(
 +                                |c| c.check_name("align") || c.check_name("packed"));
 +                        }
                      }
 -                }
  
 -                if !allow_attr_literal && contains_novel_literal(&meta) {
 -                    gate_feature_post!(&self, attr_literals, attr.span,
 -                                    "non-string literals in attributes, or string \
 -                                    literals in top-level positions, are experimental");
 +                    if !allow_attr_literal && contains_novel_literal(&meta) {
 +                        gate_feature_post!(&self, attr_literals, attr.span,
 +                                        "non-string literals in attributes, or string \
 +                                        literals in top-level positions, are experimental");
 +                    }
 +                }
 +                Err(mut err) => {
 +                    err.help("try enabling `#![feature(unrestricted_attribute_tokens)]`").emit()
                  }
 -            }
 -            Err(mut err) => {
 -                err.cancel();
 -                gate_feature_post!(&self, unrestricted_attribute_tokens, attr.span,
 -                                    "arbitrary tokens in non-macro attributes are unstable");
              }
          }
      }
@@@ -1922,6 -1920,11 +1922,11 @@@ pub fn get_features(span_handler: &Hand
          err.emit();
      }
  
+     // Some features are known to be incomplete and using them is likely to have
+     // unanticipated results, such as compiler crashes. We warn the user about these
+     // to alert them.
+     let incomplete_features = ["generic_associated_types"];
      let mut features = Features::new();
      let mut edition_enabled_features = FxHashMap();
  
                  continue
              };
  
+             if incomplete_features.iter().any(|f| *f == name.as_str()) {
+                 span_handler.struct_span_warn(
+                     mi.span,
+                     &format!(
+                         "the feature `{}` is incomplete and may cause the compiler to crash",
+                         name
+                     )
+                 ).emit();
+             }
              if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
                  if *edition <= crate_edition {
                      continue