]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #15650 : jakub-/rust/patterns-statics, r=pcwalton
authorbors <bors@rust-lang.org>
Sat, 19 Jul 2014 21:46:37 +0000 (21:46 +0000)
committerbors <bors@rust-lang.org>
Sat, 19 Jul 2014 21:46:37 +0000 (21:46 +0000)
This is accomplished by rewriting static expressions into equivalent patterns.
This way, patterns referencing static variables can both participate
in exhaustiveness analysis as well as be compiled down into the appropriate
branch of the decision trees that match expressions are codegened to.

Fixes #6533.
Fixes #13626.
Fixes #13731.
Fixes #14576.
Fixes #15393.

1  2 
src/librustc/middle/resolve.rs

index 187390821109a3180ba1092554d24654d8c1fe59,cd736197a24cd317849066a8ed411d94281d5602..a0adbf6e920ea935ab6a9a45655b72c6f4e23491
@@@ -4016,17 -4016,14 +4016,17 @@@ impl<'a> Resolver<'a> 
                                  this.record_def(path_id, (def, lp));
                              }
                              Some((DefStruct(_), _)) => {
 -                                this.session.span_err(t.span,
 -                                                      "super-struct is defined \
 -                                                       in a different crate")
 +                                span_err!(this.session, t.span, E0154,
 +                                    "super-struct is defined in a different crate");
                              },
 -                            Some(_) => this.session.span_err(t.span,
 -                                                             "super-struct is not a struct type"),
 -                            None => this.session.span_err(t.span,
 -                                                          "super-struct could not be resolved"),
 +                            Some(_) => {
 +                                span_err!(this.session, t.span, E0155,
 +                                    "super-struct is not a struct type");
 +                            }
 +                            None => {
 +                                span_err!(this.session, t.span, E0156,
 +                                    "super-struct could not be resolved");
 +                            }
                          }
                      },
                      _ => this.session.span_bug(t.span, "path not mapped to a TyPath")
                              if path.segments
                                     .iter()
                                     .any(|s| !s.lifetimes.is_empty()) {
 -                                self.session.span_err(path.span,
 -                                                      "lifetime parameters \
 -                                                       are not allowed on \
 -                                                       this type")
 +                                span_err!(self.session, path.span, E0157,
 +                                    "lifetime parameters are not allowed on this type");
                              } else if path.segments
                                            .iter()
                                            .any(|s| s.types.len() > 0) {
 -                                self.session.span_err(path.span,
 -                                                      "type parameters are \
 -                                                       not allowed on this \
 -                                                       type")
 +                                span_err!(self.session, path.span, E0153,
 +                                    "type parameters are not allowed on this type");
                              }
                          }
                          None => {
                      let ident = path1.node;
                      let renamed = mtwt::resolve(ident);
  
-                     match self.resolve_bare_identifier_pattern(ident) {
+                     match self.resolve_bare_identifier_pattern(ident, pattern.span) {
                          FoundStructOrEnumVariant(def, lp)
                                  if mode == RefutableMode => {
                              debug!("(resolving pattern) resolving `{}` to \
          });
      }
  
-     fn resolve_bare_identifier_pattern(&mut self, name: Ident)
+     fn resolve_bare_identifier_pattern(&mut self, name: Ident, span: Span)
                                         -> BareIdentifierPatternResolution {
          let module = self.current_module.clone();
          match self.resolve_item_in_lexical_scope(module,
                              def @ DefStatic(_, false) => {
                                  return FoundConst(def, LastMod(AllPublic));
                              }
+                             DefStatic(_, true) => {
+                                 self.resolve_error(span,
+                                     "mutable static variables cannot be referenced in a pattern");
+                                 return BareIdentifierPatternUnresolved;
+                             }
                              _ => {
                                  return BareIdentifierPatternUnresolved;
                              }