]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #30145 - petrochenkov:hyg, r=nrc
authorbors <bors@rust-lang.org>
Wed, 9 Dec 2015 00:41:26 +0000 (00:41 +0000)
committerbors <bors@rust-lang.org>
Wed, 9 Dec 2015 00:41:26 +0000 (00:41 +0000)
Instead of `ast::Ident`, bindings, paths and labels in HIR now keep a new structure called `hir::Ident` containing mtwt-renamed `name` and the original not-renamed `unhygienic_name`. `name` is supposed to be used by default, `unhygienic_name` is rarely used.

This is not ideal, but better than the status quo for two reasons:
- MTWT tables can be cleared immediately after lowering to HIR
- This is less bug-prone, because it is impossible now to forget applying `mtwt::resolve` to a name. It is still possible to use `name` instead of `unhygienic_name` by mistake, but `unhygienic_name`s are used only in few very special circumstances, so it shouldn't be a problem.

Besides name resolution `unhygienic_name` is used in some lints and debuginfo. `unhygienic_name` can be very well approximated by "reverse renaming" `token::intern(name.as_str())` or even plain string `name.as_str()`, except that it would break gensyms like `iter` in desugared `for` loops. This approximation is likely good enough for lints and debuginfo, but not for name resolution, unfortunately (see https://github.com/rust-lang/rust/issues/27639), so `unhygienic_name` has to be kept.

cc https://github.com/rust-lang/rust/issues/29782

r? @nrc

1  2 
src/librustc/middle/check_match.rs
src/librustc/middle/liveness.rs
src/librustc/middle/pat_util.rs
src/librustc_front/fold.rs
src/librustc_front/hir.rs
src/librustc_front/lowering.rs
src/librustc_resolve/lib.rs
src/librustc_trans/trans/_match.rs
src/librustc_trans/trans/debuginfo/create_scope_map.rs
src/librustc_typeck/check/_match.rs

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 5a169095fa90bfa94f9571e31b35358578f2a894,62ed8b0416a11846d03c80643acf168ea95b33db..7dbd6dbf0b8de0491e9c4ab7ab08f8a3bc95d697
@@@ -273,10 -281,14 +281,14 @@@ pub fn lower_variant(lctx: &LoweringCon
              disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(lctx, e)),
          },
          span: v.span,
 -    })
 +    }
  }
  
- pub fn lower_path(lctx: &LoweringContext, p: &Path) -> hir::Path {
+ // Path segments are usually unhygienic, hygienic path segments can occur only in
+ // identifier-like paths originating from `ExprPath`.
+ // Make life simpler for rustc_resolve by renaming only such segments.
+ pub fn lower_path_full(lctx: &LoweringContext, p: &Path, maybe_hygienic: bool) -> hir::Path {
+     let maybe_hygienic = maybe_hygienic && !p.global && p.segments.len() == 1;
      hir::Path {
          global: p.global,
          segments: p.segments
@@@ -1641,10 -1668,10 +1668,10 @@@ fn expr(lctx: &LoweringContext, span: S
  fn stmt_let(lctx: &LoweringContext,
              sp: Span,
              mutbl: bool,
-             ident: Ident,
+             ident: hir::Ident,
              ex: P<hir::Expr>,
              attrs: ThinAttributes)
 -            -> P<hir::Stmt> {
 +            -> hir::Stmt {
      let pat = if mutbl {
          pat_ident_binding_mode(lctx, sp, ident, hir::BindByValue(hir::MutMutable))
      } else {
@@@ -1745,10 -1772,10 +1772,10 @@@ fn path_global(span: Span, strs: Vec<hi
  
  fn path_all(sp: Span,
              global: bool,
-             mut idents: Vec<Ident>,
+             mut idents: Vec<hir::Ident>,
              lifetimes: Vec<hir::Lifetime>,
              types: Vec<P<hir::Ty>>,
 -            bindings: Vec<P<hir::TypeBinding>>)
 +            bindings: Vec<hir::TypeBinding>)
              -> hir::Path {
      let last_identifier = idents.pop().unwrap();
      let mut segments: Vec<hir::PathSegment> = idents.into_iter()
index 469ec14a1a0d2de7b4323c69e208cd6f5d97e644,d15b3a0ccf7533ca2dd9e92673ae3e10231964b3..ddada1b513d745248f324f15a31d4bee5b94c5e7
@@@ -67,8 -67,8 +67,7 @@@ use syntax::ast
  use syntax::ast::{CRATE_NODE_ID, Ident, Name, NodeId, CrateNum, TyIs, TyI8, TyI16, TyI32, TyI64};
  use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32};
  use syntax::attr::AttrMetaMethods;
- use syntax::ext::mtwt;
  use syntax::parse::token::{self, special_names, special_idents};
 -use syntax::ptr::P;
  use syntax::codemap::{self, Span, Pos};
  use syntax::util::lev_distance::{lev_distance, max_suggestion_distance};
  
Simple merge
Simple merge