diff --git a/Cargo.lock b/Cargo.lock index 1fde5ac8cb15a..652a8c6d9f156 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -47,6 +47,7 @@ name = "arena" version = "0.0.0" dependencies = [ "rustc_data_structures 0.0.0", + "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2081,6 +2082,7 @@ dependencies = [ "rustc_data_structures 0.0.0", "rustc_errors 0.0.0", "rustc_fs_util 0.0.0", + "rustc_macros 0.1.0", "rustc_target 0.0.0", "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serialize 0.0.0", @@ -2328,6 +2330,7 @@ dependencies = [ "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_llvm 0.0.0", + "rustc_macros 0.1.0", ] [[package]] @@ -2499,6 +2502,16 @@ dependencies = [ "core 0.0.0", ] +[[package]] +name = "rustc_macros" +version = "0.1.0" +dependencies = [ + "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc_metadata" version = "0.0.0" @@ -2700,6 +2713,7 @@ dependencies = [ "minifier 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_macros 0.1.0", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index a0c75cd9e9476..a08885cd53ceb 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -258,13 +258,6 @@ fn main() { } } - // Force all crates compiled by this compiler to (a) be unstable and (b) - // allow the `rustc_private` feature to link to other unstable crates - // also in the sysroot. - if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() { - cmd.arg("-Z").arg("force-unstable-if-unmarked"); - } - if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") { cmd.arg("--remap-path-prefix").arg(&map); } @@ -284,6 +277,13 @@ fn main() { } } + // Force all crates compiled by this compiler to (a) be unstable and (b) + // allow the `rustc_private` feature to link to other unstable crates + // also in the sysroot. + if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() { + cmd.arg("-Z").arg("force-unstable-if-unmarked"); + } + if env::var_os("RUSTC_PARALLEL_QUERIES").is_some() { cmd.arg("--cfg").arg("parallel_queries"); } diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index cc539d4c89571..07ef4dabc3287 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -42,7 +42,7 @@ impl Step for Std { true); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target)); + add_to_sysroot(&builder, &libdir, &libstd_stamp(builder, compiler, target), None); } } @@ -87,8 +87,14 @@ impl Step for Rustc { &librustc_stamp(builder, compiler, target), true); + let stage_out = builder.build.stage_out(compiler, Mode::Rustc); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(&builder, &libdir, &librustc_stamp(builder, compiler, target)); + add_to_sysroot( + &builder, + &libdir, + &librustc_stamp(builder, compiler, target), + Some(&stage_out), + ); } } @@ -175,7 +181,7 @@ impl Step for Test { true); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target)); + add_to_sysroot(builder, &libdir, &libtest_stamp(builder, compiler, target), None); } } @@ -222,7 +228,7 @@ impl Step for Rustdoc { true); let libdir = builder.sysroot_libdir(compiler, target); - add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target)); + add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target), None); builder.cargo(compiler, Mode::ToolRustc, target, "clean"); } } diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 8bc7c5838edda..19c82e507a48c 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -211,7 +211,7 @@ impl Step for StdLink { target_compiler.host, target)); let libdir = builder.sysroot_libdir(target_compiler, target); - add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target)); + add_to_sysroot(builder, &libdir, &libstd_stamp(builder, compiler, target), None); if builder.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" { // The sanitizers are only built in stage1 or above, so the dylibs will @@ -414,7 +414,7 @@ impl Step for TestLink { target_compiler.host, target)); add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target), - &libtest_stamp(builder, compiler, target)); + &libtest_stamp(builder, compiler, target), None); builder.cargo(target_compiler, Mode::ToolTest, target, "clean"); } @@ -574,8 +574,13 @@ impl Step for RustcLink { &compiler.host, target_compiler.host, target)); - add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target), - &librustc_stamp(builder, compiler, target)); + let stage_out = builder.build.stage_out(target_compiler, Mode::Rustc); + add_to_sysroot( + builder, + &builder.sysroot_libdir(target_compiler, target), + &librustc_stamp(builder, compiler, target), + if compiler.stage == 0 { Some(&stage_out) } else { None }, + ); builder.cargo(target_compiler, Mode::ToolRustc, target, "clean"); } } @@ -982,10 +987,26 @@ impl Step for Assemble { /// /// For a particular stage this will link the file listed in `stamp` into the /// `sysroot_dst` provided. -pub fn add_to_sysroot(builder: &Builder, sysroot_dst: &Path, stamp: &Path) { +pub fn add_to_sysroot( + builder: &Builder, + sysroot_dst: &Path, + stamp: &Path, + stage_out: Option<&Path>) { t!(fs::create_dir_all(&sysroot_dst)); for path in builder.read_stamp_file(stamp) { - builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap())); + let file_dir = path.parent().unwrap() // chop off base name + .parent().unwrap() // chop off `release` + .parent().unwrap(); // chop off `release` + if stage_out == Some(file_dir) { + // We are copying a build file. We need to add the build triple to it + let rustlib_dir = sysroot_dst.parent().unwrap() // chop off `lib` + .parent().unwrap(); // chop off `$target` + let build_dir = rustlib_dir.join(builder.build.build).join("lib"); + t!(fs::create_dir_all(&build_dir)); + builder.copy(&path, &build_dir.join(path.file_name().unwrap())); + } else { + builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap())); + } } } @@ -1014,8 +1035,12 @@ pub fn run_cargo(builder: &Builder, let mut deps = Vec::new(); let mut toplevel = Vec::new(); let ok = stream_cargo(builder, cargo, &mut |msg| { - let filenames = match msg { - CargoMessage::CompilerArtifact { filenames, .. } => filenames, + let (filenames, package_id) = match msg { + CargoMessage::CompilerArtifact { + filenames, + package_id, + .. + } => (filenames, package_id), _ => return, }; for filename in filenames { @@ -1030,8 +1055,12 @@ pub fn run_cargo(builder: &Builder, let filename = Path::new(&*filename); // If this was an output file in the "host dir" we don't actually - // worry about it, it's not relevant for us. + // worry about it, it's not relevant for us if filename.starts_with(&host_root_dir) { + // Unless it's a proc macro used in the compiler + if package_id.starts_with("rustc_macros ") { + deps.push(filename.to_path_buf()); + } continue; } diff --git a/src/libarena/Cargo.toml b/src/libarena/Cargo.toml index e2af67dd92861..e18bee505c9b3 100644 --- a/src/libarena/Cargo.toml +++ b/src/libarena/Cargo.toml @@ -9,4 +9,5 @@ path = "lib.rs" crate-type = ["dylib"] [dependencies] -rustc_data_structures = { path = "../librustc_data_structures" } \ No newline at end of file +rustc_data_structures = { path = "../librustc_data_structures" } +smallvec = { version = "0.6.7", features = ["union", "may_dangle"] } \ No newline at end of file diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 9f9ded51e37ee..163325cb711d8 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -23,9 +23,12 @@ #![allow(deprecated)] extern crate alloc; +extern crate smallvec; extern crate rustc_data_structures; use rustc_data_structures::sync::MTLock; +#[allow(unused_imports)] +use smallvec::SmallVec; use std::cell::{Cell, RefCell}; use std::cmp; @@ -151,6 +154,27 @@ impl TypedArena { } } + #[inline] + fn can_allocate(&self, len: usize) -> bool { + let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize; + let at_least_bytes = len * mem::size_of::(); + available_capacity_bytes >= at_least_bytes + } + + #[inline] + fn alloc_raw_slice(&self, len: usize) -> *mut T { + assert!(mem::size_of::() != 0); + assert!(len != 0); + + if !self.can_allocate(len) { + self.grow(len); + } + + let start_ptr = self.ptr.get(); + self.ptr.set(unsafe { start_ptr.add(len) }); + start_ptr + } + /// Allocates a slice of objects that are copied into the `TypedArena`, returning a mutable /// reference to it. Will panic if passed a zero-sized types. /// @@ -163,21 +187,40 @@ impl TypedArena { where T: Copy, { - assert!(mem::size_of::() != 0); - assert!(slice.len() != 0); + unsafe { + let len = slice.len(); + let start_ptr = self.alloc_raw_slice(len); + slice.as_ptr().copy_to_nonoverlapping(start_ptr, len); + slice::from_raw_parts_mut(start_ptr, len) + } + } - let available_capacity_bytes = self.end.get() as usize - self.ptr.get() as usize; - let at_least_bytes = slice.len() * mem::size_of::(); - if available_capacity_bytes < at_least_bytes { - self.grow(slice.len()); + #[allow(unreachable_code)] + pub fn alloc_from_iter>(&self, iter: I) -> &[T] where T: Clone { + assert!(mem::size_of::() != 0); + let vec: Vec<_> = iter.into_iter().collect(); + if vec.is_empty() { + return &[] + } + let vec2 = vec.clone(); + for a in vec { + self.alloc(a); + } + let result = &vec2[..] as *const [T]; + mem::forget(vec2);// FIXME: Remove + unsafe { + return &*result; } + // Move the content to the arena by copying and them forgetting the content of the SmallVec unsafe { - let start_ptr = self.ptr.get(); - let arena_slice = slice::from_raw_parts_mut(start_ptr, slice.len()); - self.ptr.set(start_ptr.add(arena_slice.len())); - arena_slice.copy_from_slice(slice); - arena_slice + let len = vec.len(); + let start_ptr = self.alloc_raw_slice(len); + vec.as_ptr().copy_to_nonoverlapping(start_ptr, len); + mem::forget(vec);// FIXME: Remove + //mem::forget(vec.drain()); + + slice::from_raw_parts_mut(start_ptr, len) } } diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 504e016e5b803..ac8a82ca81757 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -22,6 +22,7 @@ rustc-rayon = "0.1.1" rustc-rayon-core = "0.1.1" rustc_apfloat = { path = "../librustc_apfloat" } rustc_target = { path = "../librustc_target" } +rustc_macros = { path = "../librustc_macros" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } serialize = { path = "../libserialize" } diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 978d20ea94789..b16efbbcc0598 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -1,9 +1,9 @@ use cfg::*; use middle::region; use rustc_data_structures::graph::implementation as graph; -use syntax::ptr::P; use ty::{self, TyCtxt}; +use hir::ptr::P; use hir::{self, PatKind}; use hir::def_id::DefId; @@ -67,7 +67,7 @@ pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { - fn block(&mut self, blk: &hir::Block, pred: CFGIndex) -> CFGIndex { + fn block(&mut self, blk: &hir::Block<'_>, pred: CFGIndex) -> CFGIndex { if blk.targeted_by_break { let expr_exit = self.add_ast_node(blk.hir_id.local_id, &[]); @@ -98,7 +98,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex { + fn stmt(&mut self, stmt: &hir::Stmt<'_>, pred: CFGIndex) -> CFGIndex { let hir_id = self.tcx.hir().node_to_hir_id(stmt.node.id()); match stmt.node { hir::StmtKind::Decl(ref decl, _) => { @@ -114,7 +114,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn decl(&mut self, decl: &hir::Decl, pred: CFGIndex) -> CFGIndex { + fn decl(&mut self, decl: &hir::Decl<'_>, pred: CFGIndex) -> CFGIndex { match decl.node { hir::DeclKind::Local(ref local) => { let init_exit = self.opt_expr(&local.init, pred); @@ -125,7 +125,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex { + fn pat(&mut self, pat: &hir::Pat<'_>, pred: CFGIndex) -> CFGIndex { match pat.node { PatKind::Binding(.., None) | PatKind::Path(_) | @@ -160,14 +160,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn pats_all<'b, I: Iterator>>(&mut self, + fn pats_all<'b, 'h: 'b, I: Iterator>>>(&mut self, pats: I, pred: CFGIndex) -> CFGIndex { //! Handles case where all of the patterns must match. pats.fold(pred, |pred, pat| self.pat(&pat, pred)) } - fn expr(&mut self, expr: &hir::Expr, pred: CFGIndex) -> CFGIndex { + fn expr(&mut self, expr: &hir::Expr<'_>, pred: CFGIndex) -> CFGIndex { match expr.node { hir::ExprKind::Block(ref blk, _) => { let blk_exit = self.block(&blk, pred); @@ -347,7 +347,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { hir::ExprKind::Index(ref l, ref r) | hir::ExprKind::Binary(_, ref l, ref r) if self.tables.is_method_call(expr) => { - self.call(expr, pred, &l, Some(&**r).into_iter()) + self.call(expr, pred, &l, Some(&***r).into_iter()) } hir::ExprKind::Unary(_, ref e) if self.tables.is_method_call(expr) => { @@ -359,18 +359,18 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } hir::ExprKind::Struct(_, ref fields, ref base) => { - let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &*f.expr)); + let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &**f.expr)); self.opt_expr(base, field_cfg) } hir::ExprKind::Assign(ref l, ref r) | hir::ExprKind::AssignOp(_, ref l, ref r) => { - self.straightline(expr, pred, [r, l].iter().map(|&e| &**e)) + self.straightline(expr, pred, [r, l].iter().map(|&e| &***e)) } hir::ExprKind::Index(ref l, ref r) | hir::ExprKind::Binary(_, ref l, ref r) => { // N.B., && and || handled earlier - self.straightline(expr, pred, [l, r].iter().map(|&e| &**e)) + self.straightline(expr, pred, [l, r].iter().map(|&e| &***e)) } hir::ExprKind::Box(ref e) | @@ -381,7 +381,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { hir::ExprKind::Field(ref e, _) | hir::ExprKind::Yield(ref e) | hir::ExprKind::Repeat(ref e, _) => { - self.straightline(expr, pred, Some(&**e).into_iter()) + self.straightline(expr, pred, Some(&***e).into_iter()) } hir::ExprKind::InlineAsm(_, ref outputs, ref inputs) => { @@ -399,10 +399,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn call<'b, I: Iterator>(&mut self, - call_expr: &hir::Expr, + fn call<'b, 'h: 'b, I: Iterator>>(&mut self, + call_expr: &hir::Expr<'_>, pred: CFGIndex, - func_or_rcvr: &hir::Expr, + func_or_rcvr: &hir::Expr<'_>, args: I) -> CFGIndex { let func_or_rcvr_exit = self.expr(func_or_rcvr, pred); let ret = self.straightline(call_expr, func_or_rcvr_exit, args); @@ -414,7 +414,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } } - fn exprs<'b, I: Iterator>(&mut self, + fn exprs<'b, 'h: 'b, I: Iterator>>(&mut self, exprs: I, pred: CFGIndex) -> CFGIndex { //! Constructs graph for `exprs` evaluated in order @@ -422,14 +422,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } fn opt_expr(&mut self, - opt_expr: &Option>, + opt_expr: &Option>>, pred: CFGIndex) -> CFGIndex { //! Constructs graph for `opt_expr` evaluated, if Some opt_expr.iter().fold(pred, |p, e| self.expr(&e, p)) } - fn straightline<'b, I: Iterator>(&mut self, - expr: &hir::Expr, + fn straightline<'b, 'h: 'b, I: Iterator>>(&mut self, + expr: &hir::Expr<'_>, pred: CFGIndex, subexprs: I) -> CFGIndex { //! Handles case of an expression that evaluates `subexprs` in order @@ -438,8 +438,8 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.add_ast_node(expr.hir_id.local_id, &[subexprs_exit]) } - fn match_(&mut self, id: hir::ItemLocalId, discr: &hir::Expr, - arms: &[hir::Arm], pred: CFGIndex) -> CFGIndex { + fn match_(&mut self, id: hir::ItemLocalId, discr: &hir::Expr<'_>, + arms: &[hir::Arm<'_>], pred: CFGIndex) -> CFGIndex { // The CFG for match expression is quite complex, so no ASCII // art for it (yet). // @@ -542,7 +542,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } fn add_exiting_edge(&mut self, - from_expr: &hir::Expr, + from_expr: &hir::Expr<'_>, from_index: CFGIndex, target_scope: region::Scope, to_index: CFGIndex) { @@ -560,7 +560,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } fn add_returning_edge(&mut self, - _from_expr: &hir::Expr, + _from_expr: &hir::Expr<'_>, from_index: CFGIndex) { let data = CFGEdgeData { exiting_scopes: self.loop_scopes.iter() @@ -572,7 +572,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { } fn find_scope_edge(&self, - expr: &hir::Expr, + expr: &hir::Expr<'_>, destination: hir::Destination, scope_cf_kind: ScopeCfKind) -> (region::Scope, CFGIndex) { diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 20ec620a281fd..c6193728abbb0 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -8,7 +8,7 @@ use ty; use self::Namespace::*; -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] pub enum CtorKind { /// Constructor function automatically created by a tuple struct/variant. Fn, @@ -18,7 +18,7 @@ pub enum CtorKind { Fictive, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] pub enum NonMacroAttrKind { /// Single-segment attribute defined by the language (`#[inline]`) Builtin, @@ -32,7 +32,7 @@ pub enum NonMacroAttrKind { Custom, } -#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] pub enum Def { // Type namespace Mod(DefId), @@ -208,7 +208,7 @@ pub type ExportMap = DefIdMap>; /// namespace. pub type ImportMap = NodeMap>>; -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct Export { /// The name of the target. pub ident: ast::Ident, diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index d4f891c874a40..1d23494e084f4 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -43,10 +43,10 @@ use std::cmp; #[derive(Copy, Clone)] pub enum FnKind<'a> { /// #[xxx] pub async/const/extern "Abi" fn foo() - ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]), + ItemFn(Name, &'a Generics<'a>, FnHeader, &'a Visibility<'a>, &'a [Attribute]), /// fn foo(&self) - Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]), + Method(Ident, &'a MethodSig<'a>, Option<&'a Visibility<'a>>, &'a [Attribute]), /// |x, y| {} Closure(&'a [Attribute]), @@ -207,11 +207,11 @@ pub trait Visitor<'v> : Sized { /// Visit the top-level item and (optionally) nested items / impl items. See /// `visit_nested_item` for details. - fn visit_item(&mut self, i: &'v Item) { + fn visit_item(&mut self, i: &'v Item<'v>) { walk_item(self, i) } - fn visit_body(&mut self, b: &'v Body) { + fn visit_body(&mut self, b: &'v Body<'v>) { walk_body(self, b); } @@ -239,103 +239,103 @@ pub trait Visitor<'v> : Sized { fn visit_ident(&mut self, ident: Ident) { walk_ident(self, ident) } - fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: NodeId) { + fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: NodeId) { walk_mod(self, m, n) } - fn visit_foreign_item(&mut self, i: &'v ForeignItem) { + fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) { walk_foreign_item(self, i) } - fn visit_local(&mut self, l: &'v Local) { + fn visit_local(&mut self, l: &'v Local<'v>) { walk_local(self, l) } - fn visit_block(&mut self, b: &'v Block) { + fn visit_block(&mut self, b: &'v Block<'v>) { walk_block(self, b) } - fn visit_stmt(&mut self, s: &'v Stmt) { + fn visit_stmt(&mut self, s: &'v Stmt<'v>) { walk_stmt(self, s) } - fn visit_arm(&mut self, a: &'v Arm) { + fn visit_arm(&mut self, a: &'v Arm<'v>) { walk_arm(self, a) } - fn visit_pat(&mut self, p: &'v Pat) { + fn visit_pat(&mut self, p: &'v Pat<'v>) { walk_pat(self, p) } - fn visit_decl(&mut self, d: &'v Decl) { + fn visit_decl(&mut self, d: &'v Decl<'v>) { walk_decl(self, d) } fn visit_anon_const(&mut self, c: &'v AnonConst) { walk_anon_const(self, c) } - fn visit_expr(&mut self, ex: &'v Expr) { + fn visit_expr(&mut self, ex: &'v Expr<'v>) { walk_expr(self, ex) } - fn visit_ty(&mut self, t: &'v Ty) { + fn visit_ty(&mut self, t: &'v Ty<'v>) { walk_ty(self, t) } - fn visit_generic_param(&mut self, p: &'v GenericParam) { + fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) { walk_generic_param(self, p) } - fn visit_generics(&mut self, g: &'v Generics) { + fn visit_generics(&mut self, g: &'v Generics<'v>) { walk_generics(self, g) } - fn visit_where_predicate(&mut self, predicate: &'v WherePredicate) { + fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) { walk_where_predicate(self, predicate) } - fn visit_fn_decl(&mut self, fd: &'v FnDecl) { + fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) { walk_fn_decl(self, fd) } - fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: BodyId, s: Span, id: NodeId) { + fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, s: Span, id: NodeId) { walk_fn(self, fk, fd, b, s, id) } - fn visit_use(&mut self, path: &'v Path, id: NodeId, hir_id: HirId) { + fn visit_use(&mut self, path: &'v Path<'v>, id: NodeId, hir_id: HirId) { walk_use(self, path, id, hir_id) } - fn visit_trait_item(&mut self, ti: &'v TraitItem) { + fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) { walk_trait_item(self, ti) } fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) { walk_trait_item_ref(self, ii) } - fn visit_impl_item(&mut self, ii: &'v ImplItem) { + fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) { walk_impl_item(self, ii) } - fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) { + fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef<'v>) { walk_impl_item_ref(self, ii) } - fn visit_trait_ref(&mut self, t: &'v TraitRef) { + fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) { walk_trait_ref(self, t) } - fn visit_param_bound(&mut self, bounds: &'v GenericBound) { + fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) { walk_param_bound(self, bounds) } - fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>, m: TraitBoundModifier) { walk_poly_trait_ref(self, t, m) } fn visit_variant_data(&mut self, - s: &'v VariantData, + s: &'v VariantData<'v>, _: Name, - _: &'v Generics, + _: &'v Generics<'v>, _parent_id: NodeId, _: Span) { walk_struct_def(self, s) } - fn visit_struct_field(&mut self, s: &'v StructField) { + fn visit_struct_field(&mut self, s: &'v StructField<'v>) { walk_struct_field(self, s) } fn visit_enum_def(&mut self, enum_definition: &'v EnumDef, - generics: &'v Generics, + generics: &'v Generics<'v>, item_id: NodeId, _: Span) { walk_enum_def(self, enum_definition, generics, item_id) } - fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: NodeId) { + fn visit_variant(&mut self, v: &'v Variant<'v>, g: &'v Generics<'v>, item_id: NodeId) { walk_variant(self, v, g, item_id) } fn visit_label(&mut self, label: &'v Label) { walk_label(self, label) } - fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg) { + fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) { match generic_arg { GenericArg::Lifetime(lt) => self.visit_lifetime(lt), GenericArg::Type(ty) => self.visit_ty(ty), @@ -347,21 +347,21 @@ pub trait Visitor<'v> : Sized { fn visit_qpath(&mut self, qpath: &'v QPath, id: HirId, span: Span) { walk_qpath(self, qpath, id, span) } - fn visit_path(&mut self, path: &'v Path, _id: HirId) { + fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) { walk_path(self, path) } - fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) { + fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) { walk_path_segment(self, path_span, path_segment) } - fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs) { + fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) { walk_generic_args(self, path_span, generic_args) } - fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) { + fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) { walk_assoc_type_binding(self, type_binding) } fn visit_attribute(&mut self, _attr: &'v Attribute) { } - fn visit_macro_def(&mut self, macro_def: &'v MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) { walk_macro_def(self, macro_def) } fn visit_vis(&mut self, vis: &'v Visibility) { @@ -376,26 +376,26 @@ pub trait Visitor<'v> : Sized { } /// Walks the contents of a crate. See also `Crate::visit_all_items`. -pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) { +pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) { visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID); walk_list!(visitor, visit_attribute, &krate.attrs); walk_list!(visitor, visit_macro_def, &krate.exported_macros); } -pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) { +pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) { visitor.visit_id(macro_def.id); visitor.visit_name(macro_def.span, macro_def.name); walk_list!(visitor, visit_attribute, ¯o_def.attrs); } -pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_node_id: NodeId) { +pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_node_id: NodeId) { visitor.visit_id(mod_node_id); for &item_id in &module.item_ids { visitor.visit_nested_item(item_id); } } -pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) { +pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) { for argument in &body.arguments { visitor.visit_id(argument.id); visitor.visit_pat(&argument.pat); @@ -403,7 +403,7 @@ pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body) { visitor.visit_expr(&body.value); } -pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { +pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) { // Intentionally visiting the expr first - the initialization expr // dominates the local's definition. walk_list!(visitor, visit_expr, &local.init); @@ -437,7 +437,7 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime } pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V, - trait_ref: &'v PolyTraitRef, + trait_ref: &'v PolyTraitRef<'v>, _modifier: TraitBoundModifier) where V: Visitor<'v> { @@ -445,14 +445,14 @@ pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V, visitor.visit_trait_ref(&trait_ref.trait_ref); } -pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef) +pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) where V: Visitor<'v> { visitor.visit_id(trait_ref.ref_id); visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id) } -pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { +pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { visitor.visit_vis(&item.vis); visitor.visit_ident(item.ident); match item.node { @@ -547,7 +547,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { } pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, - path: &'v Path, + path: &'v Path<'v>, item_id: NodeId, hir_id: HirId) { visitor.visit_id(item_id); @@ -555,8 +555,8 @@ pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, } pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, - enum_definition: &'v EnumDef, - generics: &'v Generics, + enum_definition: &'v EnumDef<'v>, + generics: &'v Generics<'v>, item_id: NodeId) { visitor.visit_id(item_id); walk_list!(visitor, @@ -567,8 +567,8 @@ pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, } pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, - variant: &'v Variant, - generics: &'v Generics, + variant: &'v Variant<'v>, + generics: &'v Generics<'v>, parent_item_id: NodeId) { visitor.visit_ident(variant.node.ident); visitor.visit_variant_data(&variant.node.data, @@ -626,7 +626,12 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { } } -pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: HirId, span: Span) { +pub fn walk_qpath<'v, V: Visitor<'v>>( + visitor: &mut V, + qpath: &'v QPath<'v>, + id: HirId, + span: Span +) { match *qpath { QPath::Resolved(ref maybe_qself, ref path) => { if let Some(ref qself) = *maybe_qself { @@ -641,7 +646,7 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath, id: Hir } } -pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { +pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) { visitor.visit_def_mention(path.def); for segment in &path.segments { visitor.visit_path_segment(path.span, segment); @@ -650,7 +655,7 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, path_span: Span, - segment: &'v PathSegment) { + segment: &'v PathSegment<'v>) { visitor.visit_ident(segment.ident); if let Some(id) = segment.id { visitor.visit_id(id); @@ -662,19 +667,19 @@ pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, _path_span: Span, - generic_args: &'v GenericArgs) { + generic_args: &'v GenericArgs<'v>) { walk_list!(visitor, visit_generic_arg, &generic_args.args); walk_list!(visitor, visit_assoc_type_binding, &generic_args.bindings); } pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, - type_binding: &'v TypeBinding) { + type_binding: &'v TypeBinding<'v>) { visitor.visit_id(type_binding.id); visitor.visit_ident(type_binding.ident); visitor.visit_ty(&type_binding.ty); } -pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { +pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) { visitor.visit_id(pattern.id); match pattern.node { PatKind::TupleStruct(ref qpath, ref children, _) => { @@ -718,7 +723,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { } } -pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) { +pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) { visitor.visit_id(foreign_item.id); visitor.visit_vis(&foreign_item.vis); visitor.visit_ident(foreign_item.ident); @@ -738,7 +743,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v walk_list!(visitor, visit_attribute, &foreign_item.attrs); } -pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound) { +pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) { match *bound { GenericBound::Trait(ref typ, modifier) => { visitor.visit_poly_trait_ref(typ, modifier); @@ -747,7 +752,7 @@ pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericB } } -pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam) { +pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v GenericParam<'v>) { visitor.visit_id(param.id); walk_list!(visitor, visit_attribute, ¶m.attrs); match param.name { @@ -761,7 +766,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi walk_list!(visitor, visit_param_bound, ¶m.bounds); } -pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { +pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) { walk_list!(visitor, visit_generic_param, &generics.params); visitor.visit_id(generics.where_clause.id); walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates); @@ -797,13 +802,13 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>( } } -pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) { +pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy<'v>) { if let Return(ref output_ty) = *ret_ty { visitor.visit_ty(output_ty) } } -pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) { +pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) { for ty in &function_declaration.inputs { visitor.visit_ty(ty) } @@ -832,7 +837,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, visitor.visit_nested_body(body_id) } -pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) { +pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) { visitor.visit_ident(trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); visitor.visit_generics(&trait_item.generics); @@ -876,7 +881,7 @@ pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: visitor.visit_defaultness(defaultness); } -pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) { +pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem<'v>) { // N.B., deliberately force a compilation error if/when new fields are added. let ImplItem { id: _, @@ -922,7 +927,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt } } -pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) { +pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef<'v>) { // N.B., deliberately force a compilation error if/when new fields are added. let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref; visitor.visit_nested_impl_item(id); @@ -933,12 +938,15 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &' } -pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData) { +pub fn walk_struct_def<'v, V: Visitor<'v>>( + visitor: &mut V, + struct_definition: &'v VariantData<'v> +) { visitor.visit_id(struct_definition.id()); walk_list!(visitor, visit_struct_field, struct_definition.fields()); } -pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) { +pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField<'v>) { visitor.visit_id(struct_field.id); visitor.visit_vis(&struct_field.vis); visitor.visit_ident(struct_field.ident); @@ -946,13 +954,13 @@ pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v walk_list!(visitor, visit_attribute, &struct_field.attrs); } -pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { +pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) { visitor.visit_id(block.id); walk_list!(visitor, visit_stmt, &block.stmts); walk_list!(visitor, visit_expr, &block.expr); } -pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { +pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) { match statement.node { StmtKind::Decl(ref declaration, id) => { visitor.visit_id(id); @@ -966,7 +974,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { } } -pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) { +pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl<'v>) { match declaration.node { DeclKind::Local(ref local) => visitor.visit_local(local), DeclKind::Item(item) => visitor.visit_nested_item(item), @@ -978,7 +986,7 @@ pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonCo visitor.visit_nested_body(constant.body); } -pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { +pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) { visitor.visit_id(expression.id); walk_list!(visitor, visit_attribute, expression.attrs.iter()); match expression.node { @@ -1104,7 +1112,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } } -pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { +pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) { walk_list!(visitor, visit_pat, &arm.pats); if let Some(ref g) = arm.guard { match g { @@ -1115,7 +1123,7 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { walk_list!(visitor, visit_attribute, &arm.attrs); } -pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility) { +pub fn walk_vis<'v, V: Visitor<'v>>(visitor: &mut V, vis: &'v Visibility<'v>) { if let VisibilityKind::Restricted { ref path, id, hir_id } = vis.node { visitor.visit_id(id); visitor.visit_path(path, hir_id) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 359bd37488241..70f81da41cc25 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -32,11 +32,12 @@ use dep_graph::DepGraph; use hir::{self, ParamName}; -use hir::HirVec; +use hir::{HirVec, ThinHirVec}; use hir::map::{DefKey, DefPathData, Definitions}; use hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CRATE_DEF_INDEX}; use hir::def::{Def, PathResolution, PerNS}; use hir::GenericArg; +use hir::ptr::{P, IteratorExt}; use lint::builtin::{self, PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES, ELIDED_LIFETIMES_IN_PATHS}; use middle::cstore::CrateStore; @@ -47,6 +48,7 @@ use session::Session; use session::config::nightly_options; use util::common::FN_OUTPUT_NAME; use util::nodemap::{DefIdMap, NodeMap}; +use arena::SyncDroplessArena; use std::collections::BTreeMap; use std::fmt::Debug; @@ -58,7 +60,6 @@ use syntax::ast::*; use syntax::errors; use syntax::ext::hygiene::{Mark, SyntaxContext}; use syntax::print::pprust; -use syntax::ptr::P; use syntax::source_map::{self, respan, CompilerDesugaringKind, Spanned}; use syntax::std_inject; use syntax::symbol::{keywords, Symbol}; @@ -69,7 +70,31 @@ use syntax_pos::{Span, MultiSpan}; const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF; -pub struct LoweringContext<'a> { +macro_rules! p { + ($this:expr, $e:expr) => ({ + P::alloc($this.arena, $e) + }) +} + +macro_rules! hir_vec { + ($this:expr; $elem:expr; $n:expr) => ( + $crate::hir::HirVec::from_slice($this.arena, &[$elem; $n]) + ); + ($this:expr; $($x:expr),*) => ( + $crate::hir::HirVec::from_slice($this.arena, &[$($x),*]) + ); + () => ( + $crate::hir::HirVec::new() + ); +} + +macro_rules! thin_hir_vec { + () => ( + P::empty_thin() + ); +} + +pub struct LoweringContext<'r, 'a> { crate_root: Option<&'static str>, // Used to assign ids to HIR nodes that do not directly correspond to an AST node. @@ -77,15 +102,18 @@ pub struct LoweringContext<'a> { cstore: &'a dyn CrateStore, - resolver: &'a mut dyn Resolver, + arena: &'a SyncDroplessArena, + arenas: &'a hir::Arenas, + + resolver: &'r mut dyn Resolver<'a>, /// The items being lowered are collected here. - items: BTreeMap, + items: BTreeMap>, - trait_items: BTreeMap, - impl_items: BTreeMap, - bodies: BTreeMap, - exported_macros: Vec, + trait_items: BTreeMap>, + impl_items: BTreeMap>, + bodies: BTreeMap>, + exported_macros: Vec>, trait_impls: BTreeMap>, trait_auto_impl: BTreeMap, @@ -131,13 +159,14 @@ pub struct LoweringContext<'a> { node_id_to_hir_id: IndexVec, } -pub trait Resolver { +pub trait Resolver<'hir> { /// Resolve a path generated by the lowerer when expanding `for`, `if let`, etc. fn resolve_hir_path( &mut self, + arena: &'hir SyncDroplessArena, path: &ast::Path, is_value: bool, - ) -> hir::Path; + ) -> hir::Path<'hir>; /// Obtain the resolution for a node-id. fn get_resolution(&mut self, id: NodeId) -> Option; @@ -153,21 +182,22 @@ pub trait Resolver { /// resolves it based on `is_value`. fn resolve_str_path( &mut self, + arena: &'hir SyncDroplessArena, span: Span, crate_root: Option<&str>, components: &[&str], is_value: bool, - ) -> hir::Path; + ) -> hir::Path<'hir>; } #[derive(Debug)] -enum ImplTraitContext<'a> { +enum ImplTraitContext<'a, 'hir> { /// Treat `impl Trait` as shorthand for a new universal generic parameter. /// Example: `fn foo(x: impl Debug)`, where `impl Debug` is conceptually /// equivalent to a fresh universal parameter like `fn foo(x: T)`. /// /// Newly generated parameters should be inserted into the given `Vec`. - Universal(&'a mut Vec), + Universal(&'a mut Vec>), /// Treat `impl Trait` as shorthand for a new existential parameter. /// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually @@ -189,13 +219,13 @@ enum ImplTraitPosition { Other, } -impl<'a> ImplTraitContext<'a> { +impl<'a, 'hir> ImplTraitContext<'a, 'hir> { #[inline] fn disallowed() -> Self { ImplTraitContext::Disallowed(ImplTraitPosition::Other) } - fn reborrow(&'b mut self) -> ImplTraitContext<'b> { + fn reborrow(&'b mut self) -> ImplTraitContext<'b, 'hir> { use self::ImplTraitContext::*; match self { Universal(params) => Universal(params), @@ -205,19 +235,23 @@ impl<'a> ImplTraitContext<'a> { } } -pub fn lower_crate( - sess: &Session, - cstore: &dyn CrateStore, +pub fn lower_crate<'a>( + sess: &'a Session, + cstore: &'a dyn CrateStore, + arena: &'a SyncDroplessArena, + arenas: &'a hir::Arenas, dep_graph: &DepGraph, krate: &Crate, - resolver: &mut dyn Resolver, -) -> hir::Crate { + resolver: &mut dyn Resolver<'a>, +) -> hir::Crate<'a> { // We're constructing the HIR here; we don't care what we will // read, since we haven't even constructed the *input* to // incr. comp. yet. dep_graph.assert_ignored(); LoweringContext { + arena, + arenas, crate_root: std_inject::injected_crate_name(), sess, cstore, @@ -344,19 +378,19 @@ impl<'a, 'b> Visitor<'a> for ImplTraitTypeIdVisitor<'b> { } } -impl<'a> LoweringContext<'a> { - fn lower_crate(mut self, c: &Crate) -> hir::Crate { +impl<'a> LoweringContext<'_, 'a> { + fn lower_crate(mut self, c: &Crate) -> hir::Crate<'a> { /// Full-crate AST visitor that inserts into a fresh /// `LoweringContext` any information that may be /// needed from arbitrary locations in the crate, /// e.g., the number of lifetime generic parameters /// declared for every type and trait definition. - struct MiscCollector<'lcx, 'interner: 'lcx> { - lctx: &'lcx mut LoweringContext<'interner>, + struct MiscCollector<'l, 'lcx, 'interner> { + lctx: &'l mut LoweringContext<'lcx, 'interner>, } - impl<'lcx, 'interner> Visitor<'lcx> for MiscCollector<'lcx, 'interner> { - fn visit_item(&mut self, item: &'lcx Item) { + impl<'a, 'l, 'lcx, 'interner> Visitor<'a> for MiscCollector<'l, 'lcx, 'interner> { + fn visit_item(&mut self, item: &'a Item) { self.lctx.allocate_hir_id_counter(item.id, item); match item.node { @@ -382,22 +416,22 @@ impl<'a> LoweringContext<'a> { visit::walk_item(self, item); } - fn visit_trait_item(&mut self, item: &'lcx TraitItem) { + fn visit_trait_item(&mut self, item: &'a TraitItem) { self.lctx.allocate_hir_id_counter(item.id, item); visit::walk_trait_item(self, item); } - fn visit_impl_item(&mut self, item: &'lcx ImplItem) { + fn visit_impl_item(&mut self, item: &'a ImplItem) { self.lctx.allocate_hir_id_counter(item.id, item); visit::walk_impl_item(self, item); } } - struct ItemLowerer<'lcx, 'interner: 'lcx> { - lctx: &'lcx mut LoweringContext<'interner>, + struct ItemLowerer<'l, 'lcx, 'interner: 'lcx> { + lctx: &'l mut LoweringContext<'lcx, 'interner>, } - impl<'lcx, 'interner> ItemLowerer<'lcx, 'interner> { + impl<'l, 'lcx, 'interner> ItemLowerer<'l, 'lcx, 'interner> { fn with_trait_impl_ref(&mut self, trait_impl_ref: &Option, f: F) where F: FnOnce(&mut Self), @@ -413,8 +447,8 @@ impl<'a> LoweringContext<'a> { } } - impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> { - fn visit_item(&mut self, item: &'lcx Item) { + impl<'a, 'l, 'lcx, 'interner> Visitor<'a> for ItemLowerer<'l, 'lcx, 'interner> { + fn visit_item(&mut self, item: &'a Item) { let mut item_lowered = true; self.lctx.with_hir_id_owner(item.id, |lctx| { if let Some(hir_item) = lctx.lower_item(item) { @@ -446,7 +480,7 @@ impl<'a> LoweringContext<'a> { } } - fn visit_trait_item(&mut self, item: &'lcx TraitItem) { + fn visit_trait_item(&mut self, item: &'a TraitItem) { self.lctx.with_hir_id_owner(item.id, |lctx| { let id = hir::TraitItemId { node_id: item.id }; let hir_item = lctx.lower_trait_item(item); @@ -456,7 +490,7 @@ impl<'a> LoweringContext<'a> { visit::walk_trait_item(self, item); } - fn visit_impl_item(&mut self, item: &'lcx ImplItem) { + fn visit_impl_item(&mut self, item: &'a ImplItem) { self.lctx.with_hir_id_owner(item.id, |lctx| { let id = hir::ImplItemId { node_id: item.id }; let hir_item = lctx.lower_impl_item(item); @@ -484,7 +518,7 @@ impl<'a> LoweringContext<'a> { module, attrs, span: c.span, - exported_macros: hir::HirVec::from(self.exported_macros), + exported_macros: P::from_slice(self.arena, &self.exported_macros), items: self.items, trait_items: self.trait_items, impl_items: self.impl_items, @@ -610,10 +644,11 @@ impl<'a> LoweringContext<'a> { }) } - fn record_body(&mut self, value: hir::Expr, decl: Option<&FnDecl>) -> hir::BodyId { + fn record_body(&mut self, value: hir::Expr<'a>, decl: Option<&FnDecl>) -> hir::BodyId { + let arena = self.arena; let body = hir::Body { arguments: decl.map_or(hir_vec![], |decl| { - decl.inputs.iter().map(|x| self.lower_arg(x)).collect() + decl.inputs.iter().map(|x| self.lower_arg(x)).collect_hir_vec(arena) }), is_generator: self.is_generator, value, @@ -692,9 +727,9 @@ impl<'a> LoweringContext<'a> { parent_id: DefId, anonymous_lifetime_mode: AnonymousLifetimeMode, f: F, - ) -> (Vec, T) + ) -> (Vec>, T) where - F: FnOnce(&mut LoweringContext<'_>) -> (Vec, T), + F: FnOnce(&mut LoweringContext<'_, 'a>) -> (Vec>, T), { assert!(!self.is_collecting_in_band_lifetimes); assert!(self.lifetimes_to_define.is_empty()); @@ -802,7 +837,7 @@ impl<'a> LoweringContext<'a> { // for them. fn with_in_scope_lifetime_defs(&mut self, params: &[GenericParam], f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> T, { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { @@ -826,7 +861,7 @@ impl<'a> LoweringContext<'a> { params: &HirVec, f: F ) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> T, { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { @@ -853,9 +888,9 @@ impl<'a> LoweringContext<'a> { parent_id: DefId, anonymous_lifetime_mode: AnonymousLifetimeMode, f: F, - ) -> (hir::Generics, T) + ) -> (hir::Generics<'a>, T) where - F: FnOnce(&mut LoweringContext<'_>, &mut Vec) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>, &mut Vec>) -> T, { let (in_band_defs, (mut lowered_generics, res)) = self.with_in_scope_lifetime_defs( &generics.params, @@ -877,14 +912,14 @@ impl<'a> LoweringContext<'a> { .iter() .cloned() .chain(in_band_defs) - .collect(); + .collect_hir_vec(self.arena); (lowered_generics, res) } fn with_catch_scope(&mut self, catch_id: NodeId, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> T, { let len = self.catch_scopes.len(); self.catch_scopes.push(catch_id); @@ -906,13 +941,13 @@ impl<'a> LoweringContext<'a> { capture_clause: CaptureBy, closure_node_id: NodeId, ret_ty: Option<&Ty>, - body: impl FnOnce(&mut LoweringContext<'_>) -> hir::Expr, - ) -> hir::ExprKind { + body: impl FnOnce(&mut LoweringContext<'_, 'a>) -> hir::Expr<'a>, + ) -> hir::ExprKind<'a> { let prev_is_generator = mem::replace(&mut self.is_generator, true); let body_expr = body(self); let span = body_expr.span; let output = match ret_ty { - Some(ty) => FunctionRetTy::Ty(P(ty.clone())), + Some(ty) => FunctionRetTy::Ty(syntax::ptr::P(ty.clone())), None => FunctionRetTy::Default(span), }; let decl = FnDecl { @@ -932,18 +967,18 @@ impl<'a> LoweringContext<'a> { node: hir::ExprKind::Closure(capture_clause, decl, body_id, span, Some(hir::GeneratorMovability::Static)), span, - attrs: ThinVec::new(), + attrs: thin_hir_vec![], }; let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span); let gen_future = self.expr_std_path( - unstable_span, &["future", "from_generator"], None, ThinVec::new()); - hir::ExprKind::Call(P(gen_future), hir_vec![generator]) + unstable_span, &["future", "from_generator"], None, thin_hir_vec![]); + hir::ExprKind::Call(p!(self, gen_future), hir_vec![self; generator]) } fn lower_body(&mut self, decl: Option<&FnDecl>, f: F) -> hir::BodyId where - F: FnOnce(&mut LoweringContext<'_>) -> hir::Expr, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> hir::Expr<'a>, { let prev = mem::replace(&mut self.is_generator, false); let result = f(self); @@ -954,7 +989,7 @@ impl<'a> LoweringContext<'a> { fn with_loop_scope(&mut self, loop_id: NodeId, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> T, { // We're no longer in the base loop's condition; we're in another loop. let was_in_loop_condition = self.is_in_loop_condition; @@ -979,7 +1014,7 @@ impl<'a> LoweringContext<'a> { fn with_loop_condition_scope(&mut self, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> T, { let was_in_loop_condition = self.is_in_loop_condition; self.is_in_loop_condition = true; @@ -993,7 +1028,7 @@ impl<'a> LoweringContext<'a> { fn with_new_scopes(&mut self, f: F) -> T where - F: FnOnce(&mut LoweringContext<'_>) -> T, + F: FnOnce(&mut LoweringContext<'_, 'a>) -> T, { let was_in_loop_condition = self.is_in_loop_condition; self.is_in_loop_condition = false; @@ -1047,11 +1082,22 @@ impl<'a> LoweringContext<'a> { } } - fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec { - attrs - .iter() - .map(|a| self.lower_attr(a)) - .collect() + fn copy_attrs>( + &mut self, + attrs: I + ) -> hir::ThinHirVec<'a, Attribute> { + let vec = P::from_existing(self.arenas.attrs.alloc_from_iter(attrs)); + if vec.is_empty() { + P::empty_thin() + } else { + P::alloc(self.arena, vec) + } + } + + fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec<'a, Attribute> { + P::from_existing( + self.arenas.attrs.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a))) + ) } fn lower_attr(&mut self, attr: &Attribute) -> Attribute { @@ -1096,20 +1142,21 @@ impl<'a> LoweringContext<'a> { self.lower_token_stream(tts) } - fn lower_arm(&mut self, arm: &Arm) -> hir::Arm { + fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'a> { + let arena = self.arena; hir::Arm { attrs: self.lower_attrs(&arm.attrs), - pats: arm.pats.iter().map(|x| self.lower_pat(x)).collect(), + pats: arm.pats.iter().map(|x| self.lower_pat(x)).collect_hir_vec(arena), guard: match arm.guard { - Some(Guard::If(ref x)) => Some(hir::Guard::If(P(self.lower_expr(x)))), + Some(Guard::If(ref x)) => Some(hir::Guard::If(p!(self, self.lower_expr(x)))), _ => None, }, - body: P(self.lower_expr(&arm.body)), + body: p!(self, self.lower_expr(&arm.body)), } } fn lower_ty_binding(&mut self, b: &TypeBinding, - itctx: ImplTraitContext<'_>) -> hir::TypeBinding { + itctx: ImplTraitContext<'_, 'a>) -> hir::TypeBinding<'a> { hir::TypeBinding { id: self.lower_node_id(b.id).node_id, ident: b.ident, @@ -1120,19 +1167,20 @@ impl<'a> LoweringContext<'a> { fn lower_generic_arg(&mut self, arg: &ast::GenericArg, - itctx: ImplTraitContext<'_>) - -> hir::GenericArg { + itctx: ImplTraitContext<'_, 'a>) + -> hir::GenericArg<'a> { match arg { ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(<)), ast::GenericArg::Type(ty) => GenericArg::Type(self.lower_ty_direct(&ty, itctx)), } } - fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_>) -> P { - P(self.lower_ty_direct(t, itctx)) + fn lower_ty(&mut self, t: &Ty, itctx: ImplTraitContext<'_, 'a>) -> P<'a, hir::Ty<'a>> { + p!(self, self.lower_ty_direct(t, itctx)) } - fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_>) -> hir::Ty { + fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, 'a>) -> hir::Ty<'a> { + let arena = self.arena; let kind = match t.node { TyKind::Infer => hir::TyKind::Infer, TyKind::Err => hir::TyKind::Err, @@ -1152,7 +1200,7 @@ impl<'a> LoweringContext<'a> { this.with_anonymous_lifetime_mode( AnonymousLifetimeMode::PassThrough, |this| { - hir::TyKind::BareFn(P(hir::BareFnTy { + hir::TyKind::BareFn(p!(this, hir::BareFnTy { generic_params: this.lower_generic_params( &f.generic_params, &NodeMap::default(), @@ -1171,7 +1219,7 @@ impl<'a> LoweringContext<'a> { TyKind::Tup(ref tys) => { hir::TyKind::Tup(tys.iter().map(|ty| { self.lower_ty_direct(ty, itctx.reborrow()) - }).collect()) + }).collect_hir_vec(arena)) } TyKind::Paren(ref ty) => { return self.lower_ty_direct(ty, itctx); @@ -1187,9 +1235,12 @@ impl<'a> LoweringContext<'a> { } TyKind::ImplicitSelf => hir::TyKind::Path(hir::QPath::Resolved( None, - P(hir::Path { + p!(self, hir::Path { def: self.expect_full_def(t.id), - segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfUpper.ident())], + segments: hir_vec![ + self; + hir::PathSegment::from_ident(keywords::SelfUpper.ident()) + ], span: t.span, }), )), @@ -1215,7 +1266,7 @@ impl<'a> LoweringContext<'a> { None } }) - .collect(); + .collect_hir_vec(arena); let lifetime_bound = lifetime_bound.unwrap_or_else(|| self.elided_dyn_bound(t.span)); if kind != TraitObjectSyntax::Dyn { @@ -1262,10 +1313,10 @@ impl<'a> LoweringContext<'a> { hir::TyKind::Path(hir::QPath::Resolved( None, - P(hir::Path { + p!(self, hir::Path { span, def: Def::TyParam(DefId::local(def_index)), - segments: hir_vec![hir::PathSegment::from_ident(ident)], + segments: hir_vec![self; hir::PathSegment::from_ident(ident)], }), )) } @@ -1311,8 +1362,8 @@ impl<'a> LoweringContext<'a> { span: Span, fn_def_id: Option, exist_ty_node_id: NodeId, - lower_bounds: impl FnOnce(&mut LoweringContext<'_>) -> hir::GenericBounds, - ) -> hir::TyKind { + lower_bounds: impl FnOnce(&mut LoweringContext<'_, 'a>) -> hir::GenericBounds<'a>, + ) -> hir::TyKind<'a> { // Make sure we know that some funky desugaring has been going on here. // This is a first: there is code in other places like for loop // desugaring that explicitly states that we don't want to track that. @@ -1345,7 +1396,7 @@ impl<'a> LoweringContext<'a> { params: lifetime_defs, where_clause: hir::WhereClause { id: lctx.next_id().node_id, - predicates: Vec::new().into(), + predicates: hir_vec![], }, span, }, @@ -1382,29 +1433,29 @@ impl<'a> LoweringContext<'a> { exist_ty_id: NodeId, parent_index: DefIndex, bounds: &hir::GenericBounds, - ) -> (HirVec, HirVec) { + ) -> (HirVec<'a, hir::GenericArg<'a>>, HirVec<'a, hir::GenericParam<'a>>) { // This visitor walks over impl trait bounds and creates defs for all lifetimes which // appear in the bounds, excluding lifetimes that are created within the bounds. // E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`. - struct ImplTraitLifetimeCollector<'r, 'a: 'r> { - context: &'r mut LoweringContext<'a>, + struct ImplTraitLifetimeCollector<'l, 'r, 'a> { + context: &'l mut LoweringContext<'r, 'a>, parent: DefIndex, exist_ty_id: NodeId, collect_elided_lifetimes: bool, currently_bound_lifetimes: Vec, already_defined_lifetimes: FxHashSet, - output_lifetimes: Vec, - output_lifetime_params: Vec, + output_lifetimes: Vec>, + output_lifetime_params: Vec>, } - impl<'r, 'a: 'r, 'v> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'r, 'a> { + impl<'v> hir::intravisit::Visitor<'v> for ImplTraitLifetimeCollector<'_, '_, '_> { fn nested_visit_map<'this>( &'this mut self, ) -> hir::intravisit::NestedVisitorMap<'this, 'v> { hir::intravisit::NestedVisitorMap::None } - fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs) { + fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs<'v>) { // Don't collect elided lifetimes used inside of `Fn()` syntax. if parameters.parenthesized { let old_collect_elided_lifetimes = self.collect_elided_lifetimes; @@ -1416,7 +1467,7 @@ impl<'a> LoweringContext<'a> { } } - fn visit_ty(&mut self, t: &'v hir::Ty) { + fn visit_ty(&mut self, t: &'v hir::Ty<'v>) { // Don't collect elided lifetimes used inside of `fn()` syntax. if let hir::TyKind::BareFn(_) = t.node { let old_collect_elided_lifetimes = self.collect_elided_lifetimes; @@ -1436,7 +1487,7 @@ impl<'a> LoweringContext<'a> { fn visit_poly_trait_ref( &mut self, - trait_ref: &'v hir::PolyTraitRef, + trait_ref: &'v hir::PolyTraitRef<'v>, modifier: hir::TraitBoundModifier, ) { // Record the "stack height" of `for<'a>` lifetime bindings @@ -1446,7 +1497,7 @@ impl<'a> LoweringContext<'a> { self.currently_bound_lifetimes.truncate(old_len); } - fn visit_generic_param(&mut self, param: &'v hir::GenericParam) { + fn visit_generic_param(&mut self, param: &'v hir::GenericParam<'v>) { // Record the introduction of 'a in `for<'a> ...`. if let hir::GenericParamKind::Lifetime { .. } = param.kind { // Introduce lifetimes one at a time so that we can handle @@ -1522,6 +1573,8 @@ impl<'a> LoweringContext<'a> { } } + let arena = self.arena; + let mut lifetime_collector = ImplTraitLifetimeCollector { context: self, parent: parent_index, @@ -1538,29 +1591,30 @@ impl<'a> LoweringContext<'a> { } ( - lifetime_collector.output_lifetimes.into(), - lifetime_collector.output_lifetime_params.into(), + P::from_slice(arena, &lifetime_collector.output_lifetimes), + P::from_slice(arena, &lifetime_collector.output_lifetime_params), ) } - fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod { + fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod<'a> { + let arena = self.arena; hir::ForeignMod { abi: fm.abi, items: fm.items .iter() .map(|x| self.lower_foreign_item(x)) - .collect(), + .collect_hir_vec(arena), } } - fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P { - P(hir::GlobalAsm { + fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<'a, hir::GlobalAsm> { + p!(self, hir::GlobalAsm { asm: ga.asm, ctxt: ga.ctxt, }) } - fn lower_variant(&mut self, v: &Variant) -> hir::Variant { + fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'a> { Spanned { node: hir::VariantKind { ident: v.node.ident, @@ -1578,8 +1632,9 @@ impl<'a> LoweringContext<'a> { qself: &Option, p: &Path, param_mode: ParamMode, - mut itctx: ImplTraitContext<'_>, - ) -> hir::QPath { + mut itctx: ImplTraitContext<'_, 'a>, + ) -> hir::QPath<'a> { + let arena = self.arena; let qself_position = qself.as_ref().map(|q| q.position); let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx.reborrow())); @@ -1588,7 +1643,7 @@ impl<'a> LoweringContext<'a> { .unwrap_or_else(|| PathResolution::new(Def::Err)); let proj_start = p.segments.len() - resolution.unresolved_segments(); - let path = P(hir::Path { + let path = p!(self, hir::Path { def: resolution.base_def(), segments: p.segments[..proj_start] .iter() @@ -1672,7 +1727,7 @@ impl<'a> LoweringContext<'a> { None, ) }) - .collect(), + .collect_hir_vec(arena), span: p.span, }); @@ -1692,7 +1747,7 @@ impl<'a> LoweringContext<'a> { // e.g., `Vec` in `Vec::new` or `::Item` in // `::Item::default`. let new_id = self.next_id(); - P(self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path))) + p!(self, self.ty_path(new_id, p.span, hir::QPath::Resolved(qself, path))) }; // Anything after the base path are associated "extensions", @@ -1706,7 +1761,7 @@ impl<'a> LoweringContext<'a> { // 3. `<>::IntoIter>::Item` // * final path is `<<>::IntoIter>::Item>::clone` for (i, segment) in p.segments.iter().enumerate().skip(proj_start) { - let segment = P(self.lower_path_segment( + let segment = p!(self, self.lower_path_segment( p.span, segment, param_mode, @@ -1724,7 +1779,7 @@ impl<'a> LoweringContext<'a> { // Wrap the associated extension in another type node. let new_id = self.next_id(); - ty = P(self.ty_path(new_id, p.span, qpath)); + ty = p!(self, self.ty_path(new_id, p.span, qpath)); } // We should've returned in the for loop above. @@ -1742,7 +1797,8 @@ impl<'a> LoweringContext<'a> { p: &Path, param_mode: ParamMode, explicit_owner: Option, - ) -> hir::Path { + ) -> hir::Path<'a> { + let arena = self.arena; hir::Path { def, segments: p.segments @@ -1758,12 +1814,12 @@ impl<'a> LoweringContext<'a> { explicit_owner, ) }) - .collect(), + .collect_hir_vec(arena), span: p.span, } } - fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path { + fn lower_path(&mut self, id: NodeId, p: &Path, param_mode: ParamMode) -> hir::Path<'a> { let def = self.expect_full_def(id); self.lower_path_extra(def, p, param_mode, None) } @@ -1775,9 +1831,9 @@ impl<'a> LoweringContext<'a> { param_mode: ParamMode, expected_lifetimes: usize, parenthesized_generic_args: ParenthesizedGenericArgs, - itctx: ImplTraitContext<'_>, + itctx: ImplTraitContext<'_, 'a>, explicit_owner: Option, - ) -> hir::PathSegment { + ) -> hir::PathSegment<'a> { let (mut generic_args, infer_types) = if let Some(ref generic_args) = segment.args { let msg = "parenthesized parameters may only be used with a trait"; match **generic_args { @@ -1819,7 +1875,7 @@ impl<'a> LoweringContext<'a> { .into_iter() .map(|lt| GenericArg::Lifetime(lt)) .chain(generic_args.args.into_iter()) - .collect(); + .collect_hir_vec(self.arena); if expected_lifetimes > 0 && param_mode == ParamMode::Explicit { let anon_lt_suggestion = vec!["'_"; expected_lifetimes].join(", "); let no_ty_args = generic_args.args.len() == expected_lifetimes; @@ -1859,6 +1915,7 @@ impl<'a> LoweringContext<'a> { ); hir::PathSegment::new( + self.arena, segment.ident, Some(id.node_id), Some(def), @@ -1871,16 +1928,19 @@ impl<'a> LoweringContext<'a> { &mut self, data: &AngleBracketedArgs, param_mode: ParamMode, - mut itctx: ImplTraitContext<'_>, - ) -> (hir::GenericArgs, bool) { + mut itctx: ImplTraitContext<'_, 'a>, + ) -> (hir::GenericArgs<'a>, bool) { + let arena = self.arena; let &AngleBracketedArgs { ref args, ref bindings, .. } = data; let has_types = args.iter().any(|arg| match arg { ast::GenericArg::Type(_) => true, _ => false, }); (hir::GenericArgs { - args: args.iter().map(|a| self.lower_generic_arg(a, itctx.reborrow())).collect(), - bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx.reborrow())).collect(), + args: args.iter().map(|a| self.lower_generic_arg(a, itctx.reborrow())) + .collect_hir_vec(arena), + bindings: bindings.iter().map(|b| self.lower_ty_binding(b, itctx.reborrow())) + .collect_hir_vec(arena), parenthesized: false, }, !has_types && param_mode == ParamMode::Optional) @@ -1889,7 +1949,8 @@ impl<'a> LoweringContext<'a> { fn lower_parenthesized_parameter_data( &mut self, data: &ParenthesisedArgs, - ) -> (hir::GenericArgs, bool) { + ) -> (hir::GenericArgs<'a>, bool) { + let arena = self.arena; // Switch to `PassThrough` mode for anonymous lifetimes: this // means that we permit things like `&Ref`, where `Ref` has // a hidden lifetime parameter. This is needed for backwards @@ -1902,7 +1963,7 @@ impl<'a> LoweringContext<'a> { let inputs = inputs .iter() .map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())) - .collect(); + .collect_hir_vec(arena); let mk_tup = |this: &mut Self, tys, span| { let LoweredNodeId { node_id, hir_id } = this.next_id(); hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span } @@ -1910,15 +1971,19 @@ impl<'a> LoweringContext<'a> { ( hir::GenericArgs { - args: hir_vec![GenericArg::Type(mk_tup(this, inputs, span))], + args: hir_vec![this; GenericArg::Type(mk_tup(this, inputs, span))], bindings: hir_vec![ + this; hir::TypeBinding { id: this.next_id().node_id, ident: Ident::from_str(FN_OUTPUT_NAME), ty: output .as_ref() .map(|ty| this.lower_ty(&ty, ImplTraitContext::disallowed())) - .unwrap_or_else(|| P(mk_tup(this, hir::HirVec::new(), span))), + .unwrap_or_else(|| p!( + this, + mk_tup(this, hir::HirVec::new(), span) + )), span: output.as_ref().map_or(span, |ty| ty.span), } ], @@ -1930,7 +1995,7 @@ impl<'a> LoweringContext<'a> { ) } - fn lower_local(&mut self, l: &Local) -> (P, SmallVec<[hir::ItemId; 1]>) { + fn lower_local(&mut self, l: &Local) -> (P<'a, hir::Local<'a>>, SmallVec<[hir::ItemId; 1]>) { let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id); let mut ids = SmallVec::<[hir::ItemId; 1]>::new(); if self.sess.features_untracked().impl_trait_in_bindings { @@ -1940,7 +2005,7 @@ impl<'a> LoweringContext<'a> { } } let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0); - (P(hir::Local { + (p!(self, hir::Local { id: node_id, hir_id, ty: l.ty @@ -1953,9 +2018,9 @@ impl<'a> LoweringContext<'a> { } )), pat: self.lower_pat(&l.pat), - init: l.init.as_ref().map(|e| P(self.lower_expr(e))), + init: l.init.as_ref().map(|e| p!(self, self.lower_expr(e))), span: l.span, - attrs: l.attrs.clone(), + attrs: self.copy_attrs(l.attrs.iter().cloned()), source: hir::LocalSource::Normal, }), ids) } @@ -1967,7 +2032,7 @@ impl<'a> LoweringContext<'a> { } } - fn lower_arg(&mut self, arg: &Arg) -> hir::Arg { + fn lower_arg(&mut self, arg: &Arg) -> hir::Arg<'a> { let LoweredNodeId { node_id, hir_id } = self.lower_node_id(arg.id); hir::Arg { id: node_id, @@ -1976,14 +2041,14 @@ impl<'a> LoweringContext<'a> { } } - fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec { + fn lower_fn_args_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<'a, Ident> { decl.inputs .iter() .map(|arg| match arg.pat.node { PatKind::Ident(_, ident, _) => ident, _ => Ident::new(keywords::Invalid.name(), arg.pat.span), }) - .collect() + .collect_hir_vec(self.arena) } // Lowers a function declaration. @@ -2001,10 +2066,11 @@ impl<'a> LoweringContext<'a> { fn lower_fn_decl( &mut self, decl: &FnDecl, - mut in_band_ty_params: Option<(DefId, &mut Vec)>, + mut in_band_ty_params: Option<(DefId, &mut Vec>)>, impl_trait_return_allow: bool, make_ret_async: Option, - ) -> P { + ) -> P<'a, hir::FnDecl<'a>> { + let arena = self.arena; let inputs = decl.inputs .iter() .map(|arg| { @@ -2014,7 +2080,7 @@ impl<'a> LoweringContext<'a> { self.lower_ty_direct(&arg.ty, ImplTraitContext::disallowed()) } }) - .collect::>(); + .collect_hir_vec(arena); let output = if let Some(ret_id) = make_ret_async { self.lower_async_fn_ret_ty( @@ -2038,7 +2104,7 @@ impl<'a> LoweringContext<'a> { } }; - P(hir::FnDecl { + p!(self, hir::FnDecl { inputs, output, variadic: decl.variadic, @@ -2078,11 +2144,11 @@ impl<'a> LoweringContext<'a> { // fn_def_id: DefId of the parent function. Used to create child impl trait definition. fn lower_async_fn_ret_ty( &mut self, - inputs: &[hir::Ty], + inputs: &[hir::Ty<'a>], output: &FunctionRetTy, fn_def_id: DefId, return_impl_trait_id: NodeId, - ) -> hir::FunctionRetTy { + ) -> hir::FunctionRetTy<'a> { // Get lifetimes used in the input arguments to the function. Our output type must also // have the same lifetime. // FIXME(cramertj): multiple different lifetimes are not allowed because @@ -2090,8 +2156,8 @@ impl<'a> LoweringContext<'a> { // of the other. We really want some new lifetime that is a subset of all input lifetimes, // but that doesn't exist at the moment. - struct AsyncFnLifetimeCollector<'r, 'a: 'r> { - context: &'r mut LoweringContext<'a>, + struct AsyncFnLifetimeCollector<'l, 'r, 'a> { + context: &'l mut LoweringContext<'r, 'a>, // Lifetimes bound by HRTB. currently_bound_lifetimes: Vec, // Whether to count elided lifetimes. @@ -2102,14 +2168,14 @@ impl<'a> LoweringContext<'a> { output_lifetime: Option<(hir::LifetimeName, Span)>, } - impl<'r, 'a: 'r, 'v> hir::intravisit::Visitor<'v> for AsyncFnLifetimeCollector<'r, 'a> { + impl<'v> hir::intravisit::Visitor<'v> for AsyncFnLifetimeCollector<'_, '_, '_> { fn nested_visit_map<'this>( &'this mut self, ) -> hir::intravisit::NestedVisitorMap<'this, 'v> { hir::intravisit::NestedVisitorMap::None } - fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs) { + fn visit_generic_args(&mut self, span: Span, parameters: &'v hir::GenericArgs<'v>) { // Don't collect elided lifetimes used inside of `Fn()` syntax. if parameters.parenthesized { let old_collect_elided_lifetimes = self.collect_elided_lifetimes; @@ -2121,7 +2187,7 @@ impl<'a> LoweringContext<'a> { } } - fn visit_ty(&mut self, t: &'v hir::Ty) { + fn visit_ty(&mut self, t: &'v hir::Ty<'v>) { // Don't collect elided lifetimes used inside of `fn()` syntax. if let &hir::TyKind::BareFn(_) = &t.node { let old_collect_elided_lifetimes = self.collect_elided_lifetimes; @@ -2141,7 +2207,7 @@ impl<'a> LoweringContext<'a> { fn visit_poly_trait_ref( &mut self, - trait_ref: &'v hir::PolyTraitRef, + trait_ref: &'v hir::PolyTraitRef<'v>, modifier: hir::TraitBoundModifier, ) { // Record the "stack height" of `for<'a>` lifetime bindings @@ -2151,7 +2217,7 @@ impl<'a> LoweringContext<'a> { self.currently_bound_lifetimes.truncate(old_len); } - fn visit_generic_param(&mut self, param: &'v hir::GenericParam) { + fn visit_generic_param(&mut self, param: &'v hir::GenericParam<'v>) { // Record the introduction of 'a in `for<'a> ...` if let hir::GenericParamKind::Lifetime { .. } = param.kind { // Introduce lifetimes one at a time so that we can handle @@ -2235,13 +2301,14 @@ impl<'a> LoweringContext<'a> { let impl_trait_ty = self.lower_existential_impl_trait( span, Some(fn_def_id), return_impl_trait_id, |this| { + let arena = this.arena; let output_ty = match output { FunctionRetTy::Ty(ty) => { this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id))) } FunctionRetTy::Default(span) => { let LoweredNodeId { node_id, hir_id } = this.next_id(); - P(hir::Ty { + p!(this, hir::Ty { id: node_id, hir_id: hir_id, node: hir::TyKind::Tup(hir_vec![]), @@ -2251,9 +2318,9 @@ impl<'a> LoweringContext<'a> { }; // "" - let future_params = P(hir::GenericArgs { + let future_params = p!(this, hir::GenericArgs { args: hir_vec![], - bindings: hir_vec![hir::TypeBinding { + bindings: hir_vec![this; hir::TypeBinding { ident: Ident::from_str(FN_OUTPUT_NAME), ty: output_ty, id: this.next_id().node_id, @@ -2286,11 +2353,11 @@ impl<'a> LoweringContext<'a> { hir::Lifetime { id: this.next_id().node_id, name, span })); } - hir::HirVec::from(bounds) + P::from_slice(arena, &bounds) }); let LoweredNodeId { node_id, hir_id } = self.next_id(); - let impl_trait_ty = P(hir::Ty { + let impl_trait_ty = p!(self, hir::Ty { id: node_id, node: impl_trait_ty, span, @@ -2303,8 +2370,8 @@ impl<'a> LoweringContext<'a> { fn lower_param_bound( &mut self, tpb: &GenericBound, - itctx: ImplTraitContext<'_>, - ) -> hir::GenericBound { + itctx: ImplTraitContext<'_, 'a>, + ) -> hir::GenericBound<'a> { match *tpb { GenericBound::Trait(ref ty, modifier) => { hir::GenericBound::Trait( @@ -2361,18 +2428,19 @@ impl<'a> LoweringContext<'a> { &mut self, params: &[GenericParam], add_bounds: &NodeMap>, - mut itctx: ImplTraitContext<'_>, - ) -> hir::HirVec { + mut itctx: ImplTraitContext<'_, 'a>, + ) -> hir::HirVec<'a, hir::GenericParam<'a>> { + let arena = self.arena; params.iter().map(|param| { self.lower_generic_param(param, add_bounds, itctx.reborrow()) - }).collect() + }).collect_hir_vec(arena) } fn lower_generic_param(&mut self, param: &GenericParam, add_bounds: &NodeMap>, - mut itctx: ImplTraitContext<'_>) - -> hir::GenericParam { + mut itctx: ImplTraitContext<'_, 'a>) + -> hir::GenericParam<'a> { let mut bounds = self.with_anonymous_lifetime_mode( AnonymousLifetimeMode::ReportError, |this| this.lower_param_bounds(¶m.bounds, itctx.reborrow()), @@ -2425,7 +2493,7 @@ impl<'a> LoweringContext<'a> { let params = self.lower_param_bounds(add_bounds, itctx.reborrow()).into_iter(); bounds = bounds.into_iter() .chain(params) - .collect(); + .collect_hir_vec(self.arena); } hir::GenericParam { @@ -2452,8 +2520,8 @@ impl<'a> LoweringContext<'a> { fn lower_generics( &mut self, generics: &Generics, - itctx: ImplTraitContext<'_>) - -> hir::Generics + itctx: ImplTraitContext<'_, 'a>) + -> hir::Generics<'a> { // Collect `?Trait` bounds in where clause and move them to parameter definitions. // FIXME: this could probably be done with less rightward drift. Also looks like two control @@ -2515,7 +2583,8 @@ impl<'a> LoweringContext<'a> { } } - fn lower_where_clause(&mut self, wc: &WhereClause) -> hir::WhereClause { + fn lower_where_clause(&mut self, wc: &WhereClause) -> hir::WhereClause<'a> { + let arena = self.arena; self.with_anonymous_lifetime_mode( AnonymousLifetimeMode::ReportError, |this| { @@ -2524,13 +2593,14 @@ impl<'a> LoweringContext<'a> { predicates: wc.predicates .iter() .map(|predicate| this.lower_where_predicate(predicate)) - .collect(), + .collect_hir_vec(arena), } }, ) } - fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicate { + fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicate<'a> { + let arena = self.arena; match *pred { WherePredicate::BoundPredicate(WhereBoundPredicate { ref bound_generic_params, @@ -2559,7 +2629,7 @@ impl<'a> LoweringContext<'a> { ImplTraitContext::disallowed(), )), }) - .collect(), + .collect_hir_vec(arena), span, }) }, @@ -2588,14 +2658,15 @@ impl<'a> LoweringContext<'a> { } } - fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData { + fn lower_variant_data(&mut self, vdata: &VariantData) -> hir::VariantData<'a> { + let arena = self.arena; match *vdata { VariantData::Struct(ref fields, id) => hir::VariantData::Struct( fields .iter() .enumerate() .map(|f| self.lower_struct_field(f)) - .collect(), + .collect_hir_vec(arena), self.lower_node_id(id).node_id, ), VariantData::Tuple(ref fields, id) => hir::VariantData::Tuple( @@ -2603,16 +2674,20 @@ impl<'a> LoweringContext<'a> { .iter() .enumerate() .map(|f| self.lower_struct_field(f)) - .collect(), + .collect_hir_vec(arena), self.lower_node_id(id).node_id, ), VariantData::Unit(id) => hir::VariantData::Unit(self.lower_node_id(id).node_id), } } - fn lower_trait_ref(&mut self, p: &TraitRef, itctx: ImplTraitContext<'_>) -> hir::TraitRef { + fn lower_trait_ref( + &mut self, + p: &TraitRef, + itctx: ImplTraitContext<'_, 'a> + ) -> hir::TraitRef<'a> { let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx) { - hir::QPath::Resolved(None, path) => path.and_then(|path| path), + hir::QPath::Resolved(None, path) => **path, qpath => bug!("lower_trait_ref: unexpected QPath `{:?}`", qpath), }; let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.ref_id); @@ -2626,8 +2701,8 @@ impl<'a> LoweringContext<'a> { fn lower_poly_trait_ref( &mut self, p: &PolyTraitRef, - mut itctx: ImplTraitContext<'_>, - ) -> hir::PolyTraitRef { + mut itctx: ImplTraitContext<'_, 'a>, + ) -> hir::PolyTraitRef<'a> { let bound_generic_params = self.lower_generic_params( &p.bound_generic_params, &NodeMap::default(), @@ -2645,7 +2720,7 @@ impl<'a> LoweringContext<'a> { } } - fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField { + fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::StructField<'a> { hir::StructField { span: f.span, id: self.lower_node_id(f.id).node_id, @@ -2660,29 +2735,31 @@ impl<'a> LoweringContext<'a> { } } - fn lower_field(&mut self, f: &Field) -> hir::Field { + fn lower_field(&mut self, f: &Field) -> hir::Field<'a> { hir::Field { id: self.next_id().node_id, ident: f.ident, - expr: P(self.lower_expr(&f.expr)), + expr: p!(self, self.lower_expr(&f.expr)), span: f.span, is_shorthand: f.is_shorthand, } } - fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_>) -> hir::MutTy { + fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_, 'a>) -> hir::MutTy<'a> { hir::MutTy { ty: self.lower_ty(&mt.ty, itctx), mutbl: self.lower_mutability(mt.mutbl), } } - fn lower_param_bounds(&mut self, bounds: &[GenericBound], mut itctx: ImplTraitContext<'_>) - -> hir::GenericBounds { - bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect() + fn lower_param_bounds(&mut self, bounds: &[GenericBound], mut itctx: ImplTraitContext<'_, 'a>) + -> hir::GenericBounds<'a> { + let arena = self.arena; + bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())) + .collect_hir_vec(arena) } - fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P { + fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<'a, hir::Block<'a>> { let mut expr = None; let mut stmts = vec![]; @@ -2690,7 +2767,7 @@ impl<'a> LoweringContext<'a> { for (index, stmt) in b.stmts.iter().enumerate() { if index == b.stmts.len() - 1 { if let StmtKind::Expr(ref e) = stmt.node { - expr = Some(P(self.lower_expr(e))); + expr = Some(p!(self, self.lower_expr(e))); } else { stmts.extend(self.lower_stmt(stmt)); } @@ -2701,10 +2778,10 @@ impl<'a> LoweringContext<'a> { let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id); - P(hir::Block { + p!(self, hir::Block { id: node_id, hir_id, - stmts: stmts.into(), + stmts: P::from_slice(self.arena, &stmts), expr, rules: self.lower_block_check_mode(&b.rules), span: b.span, @@ -2724,12 +2801,12 @@ impl<'a> LoweringContext<'a> { CaptureBy::Value, closure_id, None, |this| { let body = this.lower_block(body, false); - this.expr_block(body, ThinVec::new()) + this.expr_block(body, thin_hir_vec![]) }); - this.expr(body.span, async_expr, ThinVec::new()) + this.expr(body.span, async_expr, thin_hir_vec![]) } else { let body = this.lower_block(body, false); - this.expr_block(body, ThinVec::new()) + this.expr_block(body, thin_hir_vec![]) } }) } @@ -2738,10 +2815,11 @@ impl<'a> LoweringContext<'a> { &mut self, id: NodeId, ident: &mut Ident, - attrs: &hir::HirVec, - vis: &mut hir::Visibility, + attrs: &hir::HirVec<'a, Attribute>, + vis: &mut hir::Visibility<'a>, i: &ItemKind, - ) -> hir::ItemKind { + ) -> hir::ItemKind<'a> { + let arena = self.arena; match *i { ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name), ItemKind::Use(ref use_tree) => { @@ -2829,7 +2907,7 @@ impl<'a> LoweringContext<'a> { .variants .iter() .map(|x| self.lower_variant(x)) - .collect(), + .collect_hir_vec(arena), }, self.lower_generics(generics, ImplTraitContext::disallowed()), ), @@ -2898,7 +2976,7 @@ impl<'a> LoweringContext<'a> { impl_items .iter() .map(|item| this.lower_impl_item_ref(item)) - .collect() + .collect_hir_vec(arena) }, ); @@ -2917,7 +2995,7 @@ impl<'a> LoweringContext<'a> { let items = items .iter() .map(|item| self.lower_trait_item_ref(item)) - .collect(); + .collect_hir_vec(arena); hir::ItemKind::Trait( self.lower_is_auto(is_auto), self.lower_unsafety(unsafety), @@ -2942,10 +3020,10 @@ impl<'a> LoweringContext<'a> { tree: &UseTree, prefix: &Path, id: NodeId, - vis: &mut hir::Visibility, + vis: &mut hir::Visibility<'a>, ident: &mut Ident, - attrs: &hir::HirVec, - ) -> hir::ItemKind { + attrs: &hir::HirVec<'a, Attribute>, + ) -> hir::ItemKind<'a> { debug!("lower_use_tree(tree={:?})", tree); debug!("lower_use_tree: vis = {:?}", vis); @@ -3009,7 +3087,7 @@ impl<'a> LoweringContext<'a> { let new_id = this.lower_node_id(new_node_id); let path = this.lower_path_extra(def, &path, ParamMode::Explicit, None); - let item = hir::ItemKind::Use(P(path), hir::UseKind::Single); + let item = hir::ItemKind::Use(p!(this, path), hir::UseKind::Single); let vis_kind = match vis.node { hir::VisibilityKind::Public => hir::VisibilityKind::Public, hir::VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), @@ -3042,11 +3120,11 @@ impl<'a> LoweringContext<'a> { } let path = - P(self.lower_path_extra(ret_def, &path, ParamMode::Explicit, None)); + p!(self, self.lower_path_extra(ret_def, &path, ParamMode::Explicit, None)); hir::ItemKind::Use(path, hir::UseKind::Single) } UseTreeKind::Glob => { - let path = P(self.lower_path( + let path = p!(self, self.lower_path( id, &Path { segments, @@ -3170,7 +3248,7 @@ impl<'a> LoweringContext<'a> { } let def = self.expect_full_def_from_use(id).next().unwrap_or(Def::Err); - let path = P(self.lower_path_extra(def, &prefix, ParamMode::Explicit, None)); + let path = p!(self, self.lower_path_extra(def, &prefix, ParamMode::Explicit, None)); hir::ItemKind::Use(path, hir::UseKind::ListStem) } } @@ -3179,18 +3257,20 @@ impl<'a> LoweringContext<'a> { /// Paths like the visibility path in `pub(super) use foo::{bar, baz}` are repeated /// many times in the HIR tree; for each occurrence, we need to assign distinct /// node-ids. (See e.g., #56128.) - fn renumber_segment_ids(&mut self, path: &P) -> P { + fn renumber_segment_ids(&mut self, path: &P<'a, hir::Path>) -> P<'a, hir::Path<'a>> { debug!("renumber_segment_ids(path = {:?})", path); - let mut path = path.clone(); - for seg in path.segments.iter_mut() { + let mut path = ***path; + let mut segments = path.segments.into_vec(); + for seg in &mut segments { if seg.id.is_some() { seg.id = Some(self.next_id().node_id); } } - path + path.segments = P::from_slice(self.arena, &segments); + p!(self, path) } - fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem { + fn lower_trait_item(&mut self, i: &TraitItem) -> hir::TraitItem<'a> { let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); let trait_item_def_id = self.resolver.definitions().local_def_id(node_id); @@ -3218,7 +3298,7 @@ impl<'a> LoweringContext<'a> { TraitItemKind::Method(ref sig, Some(ref body)) => { let body_id = self.lower_body(Some(&sig.decl), |this| { let body = this.lower_block(body, false); - this.expr_block(body, ThinVec::new()) + this.expr_block(body, thin_hir_vec![]) }); let (generics, sig) = self.lower_method_sig( &i.generics, @@ -3277,7 +3357,7 @@ impl<'a> LoweringContext<'a> { } } - fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem { + fn lower_impl_item(&mut self, i: &ImplItem) -> hir::ImplItem<'a> { let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id); let impl_item_def_id = self.resolver.definitions().local_def_id(node_id); @@ -3332,7 +3412,7 @@ impl<'a> LoweringContext<'a> { // [1] since `default impl` is not yet implemented, this is always true in impls } - fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef { + fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef<'a> { hir::ImplItemRef { id: hir::ImplItemId { node_id: i.id }, ident: i.ident, @@ -3353,10 +3433,11 @@ impl<'a> LoweringContext<'a> { // [1] since `default impl` is not yet implemented, this is always true in impls } - fn lower_mod(&mut self, m: &Mod) -> hir::Mod { + fn lower_mod(&mut self, m: &Mod) -> hir::Mod<'a> { + let arena = self.arena; hir::Mod { inner: m.inner, - item_ids: m.items.iter().flat_map(|x| self.lower_item_id(x)).collect(), + item_ids: m.items.iter().flat_map(|x| self.lower_item_id(x)).collect_hir_vec(arena), } } @@ -3412,7 +3493,7 @@ impl<'a> LoweringContext<'a> { } } - pub fn lower_item(&mut self, i: &Item) -> Option { + pub fn lower_item(&mut self, i: &Item) -> Option> { let mut ident = i.ident; let mut vis = self.lower_visibility(&i.vis, None); let attrs = self.lower_attrs(&i.attrs); @@ -3426,7 +3507,7 @@ impl<'a> LoweringContext<'a> { attrs, id: i.id, span: i.span, - body, + body: P::from_existing(self.arenas.token_streams.alloc(body)), legacy: def.legacy, }); } @@ -3448,7 +3529,7 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem { + fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'a> { let node_id = self.lower_node_id(i.id).node_id; let def_id = self.resolver.definitions().local_def_id(node_id); hir::ForeignItem { @@ -3491,7 +3572,7 @@ impl<'a> LoweringContext<'a> { fn_def_id: DefId, impl_trait_return_allow: bool, is_async: Option, - ) -> (hir::Generics, hir::MethodSig) { + ) -> (hir::Generics<'a>, hir::MethodSig<'a>) { let header = self.lower_fn_header(sig.header); let (generics, decl) = self.add_in_band_defs( generics, @@ -3578,7 +3659,8 @@ impl<'a> LoweringContext<'a> { } } - fn lower_pat(&mut self, p: &Pat) -> P { + fn lower_pat(&mut self, p: &Pat) -> P<'a, hir::Pat<'a>> { + let arena = self.arena; let node = match p.node { PatKind::Wild => hir::PatKind::Wild, PatKind::Ident(ref binding_mode, ident, ref sub) => { @@ -3598,15 +3680,15 @@ impl<'a> LoweringContext<'a> { } Some(def) => hir::PatKind::Path(hir::QPath::Resolved( None, - P(hir::Path { + p!(self, hir::Path { span: ident.span, def, - segments: hir_vec![hir::PathSegment::from_ident(ident)], + segments: hir_vec![self; hir::PathSegment::from_ident(ident)], }), )), } } - PatKind::Lit(ref e) => hir::PatKind::Lit(P(self.lower_expr(e))), + PatKind::Lit(ref e) => hir::PatKind::Lit(p!(self, self.lower_expr(e))), PatKind::TupleStruct(ref path, ref pats, ddpos) => { let qpath = self.lower_qpath( p.id, @@ -3617,7 +3699,7 @@ impl<'a> LoweringContext<'a> { ); hir::PatKind::TupleStruct( qpath, - pats.iter().map(|x| self.lower_pat(x)).collect(), + pats.iter().map(|x| self.lower_pat(x)).collect_hir_vec(arena), ddpos, ) } @@ -3651,32 +3733,33 @@ impl<'a> LoweringContext<'a> { is_shorthand: f.node.is_shorthand, }, }) - .collect(); + .collect_hir_vec(arena); hir::PatKind::Struct(qpath, fs, etc) } PatKind::Tuple(ref elts, ddpos) => { - hir::PatKind::Tuple(elts.iter().map(|x| self.lower_pat(x)).collect(), ddpos) + hir::PatKind::Tuple(elts.iter().map(|x| self.lower_pat(x)) + .collect_hir_vec(arena), ddpos) } PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)), PatKind::Ref(ref inner, mutbl) => { hir::PatKind::Ref(self.lower_pat(inner), self.lower_mutability(mutbl)) } PatKind::Range(ref e1, ref e2, Spanned { node: ref end, .. }) => hir::PatKind::Range( - P(self.lower_expr(e1)), - P(self.lower_expr(e2)), + p!(self, self.lower_expr(e1)), + p!(self, self.lower_expr(e2)), self.lower_range_end(end), ), PatKind::Slice(ref before, ref slice, ref after) => hir::PatKind::Slice( - before.iter().map(|x| self.lower_pat(x)).collect(), + before.iter().map(|x| self.lower_pat(x)).collect_hir_vec(arena), slice.as_ref().map(|x| self.lower_pat(x)), - after.iter().map(|x| self.lower_pat(x)).collect(), + after.iter().map(|x| self.lower_pat(x)).collect_hir_vec(arena), ), PatKind::Paren(ref inner) => return self.lower_pat(inner), PatKind::Mac(_) => panic!("Shouldn't exist here"), }; let LoweredNodeId { node_id, hir_id } = self.lower_node_id(p.id); - P(hir::Pat { + p!(self, hir::Pat { id: node_id, hir_id, node, @@ -3702,27 +3785,32 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_expr(&mut self, e: &Expr) -> hir::Expr { + fn lower_expr(&mut self, e: &Expr) -> hir::Expr<'a> { + let arena = self.arena; let kind = match e.node { - ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))), + ExprKind::Box(ref inner) => hir::ExprKind::Box(p!(self, self.lower_expr(inner))), ExprKind::ObsoleteInPlace(..) => { self.sess.abort_if_errors(); span_bug!(e.span, "encountered ObsoleteInPlace expr during lowering"); } ExprKind::Array(ref exprs) => { - hir::ExprKind::Array(exprs.iter().map(|x| self.lower_expr(x)).collect()) + hir::ExprKind::Array(exprs.iter().map(|x| self.lower_expr(x)) + .collect_hir_vec(arena)) } ExprKind::Repeat(ref expr, ref count) => { - let expr = P(self.lower_expr(expr)); + let expr = p!(self, self.lower_expr(expr)); let count = self.lower_anon_const(count); hir::ExprKind::Repeat(expr, count) } ExprKind::Tup(ref elts) => { - hir::ExprKind::Tup(elts.iter().map(|x| self.lower_expr(x)).collect()) + hir::ExprKind::Tup(elts.iter().map(|x| self.lower_expr(x)).collect_hir_vec(arena)) } ExprKind::Call(ref f, ref args) => { - let f = P(self.lower_expr(f)); - hir::ExprKind::Call(f, args.iter().map(|x| self.lower_expr(x)).collect()) + let f = p!(self, self.lower_expr(f)); + hir::ExprKind::Call( + f, + args.iter().map(|x| self.lower_expr(x)).collect_hir_vec(arena) + ) } ExprKind::MethodCall(ref seg, ref args) => { let hir_seg = self.lower_path_segment( @@ -3734,32 +3822,35 @@ impl<'a> LoweringContext<'a> { ImplTraitContext::disallowed(), None, ); - let args = args.iter().map(|x| self.lower_expr(x)).collect(); + let args = args.iter().map(|x| self.lower_expr(x)).collect_hir_vec(arena); hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args) } ExprKind::Binary(binop, ref lhs, ref rhs) => { let binop = self.lower_binop(binop); - let lhs = P(self.lower_expr(lhs)); - let rhs = P(self.lower_expr(rhs)); + let lhs = p!(self, self.lower_expr(lhs)); + let rhs = p!(self, self.lower_expr(rhs)); hir::ExprKind::Binary(binop, lhs, rhs) } ExprKind::Unary(op, ref ohs) => { let op = self.lower_unop(op); - let ohs = P(self.lower_expr(ohs)); + let ohs = p!(self, self.lower_expr(ohs)); hir::ExprKind::Unary(op, ohs) } - ExprKind::Lit(ref l) => hir::ExprKind::Lit(P((*l).clone())), + ExprKind::Lit(ref l) => { + let lit = P::from_existing(self.arenas.lits.alloc(l.clone())); + hir::ExprKind::Lit(lit) + }, ExprKind::Cast(ref expr, ref ty) => { - let expr = P(self.lower_expr(expr)); + let expr = p!(self, self.lower_expr(expr)); hir::ExprKind::Cast(expr, self.lower_ty(ty, ImplTraitContext::disallowed())) } ExprKind::Type(ref expr, ref ty) => { - let expr = P(self.lower_expr(expr)); + let expr = p!(self, self.lower_expr(expr)); hir::ExprKind::Type(expr, self.lower_ty(ty, ImplTraitContext::disallowed())) } ExprKind::AddrOf(m, ref ohs) => { let m = self.lower_mutability(m); - let ohs = P(self.lower_expr(ohs)); + let ohs = p!(self, self.lower_expr(ohs)); hir::ExprKind::AddrOf(m, ohs) } // More complicated than you might expect because the else branch @@ -3770,9 +3861,9 @@ impl<'a> LoweringContext<'a> { ExprKind::IfLet(..) => { // Wrap the `if let` expr in a block. let span = els.span; - let els = P(self.lower_expr(els)); + let els = p!(self, self.lower_expr(els)); let LoweredNodeId { node_id, hir_id } = self.next_id(); - let blk = P(hir::Block { + let blk = p!(self, hir::Block { stmts: hir_vec![], expr: Some(els), id: node_id, @@ -3781,20 +3872,20 @@ impl<'a> LoweringContext<'a> { span, targeted_by_break: false, }); - P(self.expr_block(blk, ThinVec::new())) + p!(self, self.expr_block(blk, thin_hir_vec![])) } - _ => P(self.lower_expr(els)), + _ => p!(self, self.lower_expr(els)), } }); let then_blk = self.lower_block(blk, false); - let then_expr = self.expr_block(then_blk, ThinVec::new()); + let then_expr = self.expr_block(then_blk, thin_hir_vec![]); - hir::ExprKind::If(P(self.lower_expr(cond)), P(then_expr), else_opt) + hir::ExprKind::If(p!(self, self.lower_expr(cond)), p!(self, then_expr), else_opt) } ExprKind::While(ref cond, ref body, opt_label) => self.with_loop_scope(e.id, |this| { hir::ExprKind::While( - this.with_loop_condition_scope(|this| P(this.lower_expr(cond))), + this.with_loop_condition_scope(|this| p!(this, this.lower_expr(cond))), this.lower_block(body, false), this.lower_label(opt_label), ) @@ -3819,27 +3910,27 @@ impl<'a> LoweringContext<'a> { id: node_id, span, node: hir::ExprKind::Tup(hir_vec![]), - attrs: ThinVec::new(), + attrs: thin_hir_vec![], hir_id, } }, - |x: P| x.into_inner(), + |x: P<'a, hir::Expr<'a>>| x.into_inner(), ); block.expr = Some(this.wrap_in_try_constructor( "from_ok", tail, unstable_span)); - hir::ExprKind::Block(P(block), None) + hir::ExprKind::Block(p!(this, block), None) }) } ExprKind::Match(ref expr, ref arms) => hir::ExprKind::Match( - P(self.lower_expr(expr)), - arms.iter().map(|x| self.lower_arm(x)).collect(), + p!(self, self.lower_expr(expr)), + arms.iter().map(|x| self.lower_arm(x)).collect_hir_vec(arena), hir::MatchSource::Normal, ), ExprKind::Async(capture_clause, closure_node_id, ref block) => { self.make_async_expr(capture_clause, closure_node_id, None, |this| { this.with_new_scopes(|this| { let block = this.lower_block(block, false); - this.expr_block(block, ThinVec::new()) + this.expr_block(block, thin_hir_vec![]) }) }) } @@ -3886,7 +3977,7 @@ impl<'a> LoweringContext<'a> { |this| { this.with_new_scopes(|this| this.lower_expr(body)) }); - this.expr(fn_decl_span, async_body, ThinVec::new()) + this.expr(fn_decl_span, async_body, thin_hir_vec![]) }); hir::ExprKind::Closure( this.lower_capture_clause(capture_clause), @@ -3948,28 +4039,36 @@ impl<'a> LoweringContext<'a> { self.lower_label(opt_label)) } ExprKind::Assign(ref el, ref er) => { - hir::ExprKind::Assign(P(self.lower_expr(el)), P(self.lower_expr(er))) + hir::ExprKind::Assign(p!(self, self.lower_expr(el)), p!(self, self.lower_expr(er))) } ExprKind::AssignOp(op, ref el, ref er) => hir::ExprKind::AssignOp( self.lower_binop(op), - P(self.lower_expr(el)), - P(self.lower_expr(er)), + p!(self, self.lower_expr(el)), + p!(self, self.lower_expr(er)), ), - ExprKind::Field(ref el, ident) => hir::ExprKind::Field(P(self.lower_expr(el)), ident), + ExprKind::Field(ref el, ident) => { + hir::ExprKind::Field(p!(self, self.lower_expr(el)), ident) + } ExprKind::Index(ref el, ref er) => { - hir::ExprKind::Index(P(self.lower_expr(el)), P(self.lower_expr(er))) + hir::ExprKind::Index(p!(self, self.lower_expr(el)), p!(self, self.lower_expr(er))) } // Desugar `..=` into `std::ops::RangeInclusive::new(, )`. ExprKind::Range(Some(ref e1), Some(ref e2), RangeLimits::Closed) => { let id = self.next_id(); let e1 = self.lower_expr(e1); let e2 = self.lower_expr(e2); - let ty_path = P(self.std_path(e.span, &["ops", "RangeInclusive"], None, false)); - let ty = P(self.ty_path(id, e.span, hir::QPath::Resolved(None, ty_path))); - let new_seg = P(hir::PathSegment::from_ident(Ident::from_str("new"))); + let ty_path = p!( + self, + self.std_path(e.span, &["ops", "RangeInclusive"], None, false) + ); + let ty = p!(self, self.ty_path(id, e.span, hir::QPath::Resolved(None, ty_path))); + let new_seg = p!(self, hir::PathSegment::from_ident(Ident::from_str("new"))); let new_path = hir::QPath::TypeRelative(ty, new_seg); - let new = P(self.expr(e.span, hir::ExprKind::Path(new_path), ThinVec::new())); - hir::ExprKind::Call(new, hir_vec![e1, e2]) + let new = p!( + self, + self.expr(e.span, hir::ExprKind::Path(new_path), thin_hir_vec![]) + ); + hir::ExprKind::Call(new, hir_vec![self; e1, e2]) } ExprKind::Range(ref e1, ref e2, lims) => { use syntax::ast::RangeLimits::*; @@ -3990,30 +4089,22 @@ impl<'a> LoweringContext<'a> { .map(|e| ("start", e)) .chain(e2.iter().map(|e| ("end", e))) .map(|(s, e)| { - let expr = P(self.lower_expr(&e)); + let expr = p!(self, self.lower_expr(&e)); let ident = Ident::new(Symbol::intern(s), e.span); self.field(ident, expr, e.span) }) - .collect::>(); + .collect_hir_vec(arena); let is_unit = fields.is_empty(); let struct_path = ["ops", path]; let struct_path = self.std_path(e.span, &struct_path, None, is_unit); - let struct_path = hir::QPath::Resolved(None, P(struct_path)); - - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); + let struct_path = hir::QPath::Resolved(None, p!(self, struct_path)); - return hir::Expr { - id: node_id, - hir_id, - node: if is_unit { - hir::ExprKind::Path(struct_path) - } else { - hir::ExprKind::Struct(struct_path, fields, None) - }, - span: e.span, - attrs: e.attrs.clone(), - }; + if is_unit { + hir::ExprKind::Path(struct_path) + } else { + hir::ExprKind::Struct(struct_path, fields, None) + } } ExprKind::Path(ref qself, ref path) => { let qpath = self.lower_qpath( @@ -4036,7 +4127,7 @@ impl<'a> LoweringContext<'a> { }; hir::ExprKind::Break( destination, - opt_expr.as_ref().map(|x| P(self.lower_expr(x))), + opt_expr.as_ref().map(|x| p!(self, self.lower_expr(x))), ) } ExprKind::Continue(opt_label) => { @@ -4049,7 +4140,9 @@ impl<'a> LoweringContext<'a> { self.lower_loop_destination(opt_label.map(|label| (e.id, label))) }) } - ExprKind::Ret(ref e) => hir::ExprKind::Ret(e.as_ref().map(|x| P(self.lower_expr(x)))), + ExprKind::Ret(ref e) => { + hir::ExprKind::Ret(e.as_ref().map(|x| p!(self, self.lower_expr(x)))) + } ExprKind::InlineAsm(ref asm) => { let hir_asm = hir::InlineAsm { inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(), @@ -4073,12 +4166,13 @@ impl<'a> LoweringContext<'a> { let outputs = asm.outputs .iter() .map(|out| self.lower_expr(&out.expr)) - .collect(); + .collect_hir_vec(arena); let inputs = asm.inputs .iter() .map(|&(_, ref input)| self.lower_expr(input)) - .collect(); - hir::ExprKind::InlineAsm(P(hir_asm), outputs, inputs) + .collect_hir_vec(arena); + let hir_asm = P::from_existing(self.arenas.inline_asms.alloc(hir_asm)); + hir::ExprKind::InlineAsm(hir_asm, outputs, inputs) } ExprKind::Struct(ref path, ref fields, ref maybe_expr) => hir::ExprKind::Struct( self.lower_qpath( @@ -4088,8 +4182,8 @@ impl<'a> LoweringContext<'a> { ParamMode::Optional, ImplTraitContext::disallowed(), ), - fields.iter().map(|x| self.lower_field(x)).collect(), - maybe_expr.as_ref().map(|x| P(self.lower_expr(x))), + fields.iter().map(|x| self.lower_field(x)).collect_hir_vec(arena), + maybe_expr.as_ref().map(|x| p!(self, self.lower_expr(x))), ), ExprKind::Paren(ref ex) => { let mut ex = self.lower_expr(ex); @@ -4098,9 +4192,11 @@ impl<'a> LoweringContext<'a> { ex.span = e.span; } // Merge attributes into the inner expression. - let mut attrs = e.attrs.clone(); - attrs.extend::>(ex.attrs.into()); - ex.attrs = attrs; + if !e.attrs.is_empty() { + ex.attrs = self.copy_attrs( + e.attrs.iter().cloned().chain(ex.attrs.iter().cloned()) + ); + } return ex; } @@ -4110,9 +4206,9 @@ impl<'a> LoweringContext<'a> { .as_ref() .map(|x| self.lower_expr(x)) .unwrap_or_else(|| - self.expr(e.span, hir::ExprKind::Tup(hir_vec![]), ThinVec::new()) + self.expr(e.span, hir::ExprKind::Tup(hir_vec![]), thin_hir_vec![]) ); - hir::ExprKind::Yield(P(expr)) + hir::ExprKind::Yield(p!(self, expr)) } ExprKind::Err => hir::ExprKind::Err, @@ -4132,8 +4228,8 @@ impl<'a> LoweringContext<'a> { // ` => ` { let body = self.lower_block(body, false); - let body_expr = P(self.expr_block(body, ThinVec::new())); - let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect(); + let body_expr = p!(self, self.expr_block(body, thin_hir_vec![])); + let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect_hir_vec(arena); arms.push(self.arm(pats, body_expr)); } @@ -4142,20 +4238,20 @@ impl<'a> LoweringContext<'a> { let wildcard_arm: Option<&Expr> = else_opt.as_ref().map(|p| &**p); let wildcard_pattern = self.pat_wild(e.span); let body = if let Some(else_expr) = wildcard_arm { - P(self.lower_expr(else_expr)) + p!(self, self.lower_expr(else_expr)) } else { self.expr_tuple(e.span, hir_vec![]) }; - arms.push(self.arm(hir_vec![wildcard_pattern], body)); + arms.push(self.arm(hir_vec![self; wildcard_pattern], body)); } let contains_else_clause = else_opt.is_some(); - let sub_expr = P(self.lower_expr(sub_expr)); + let sub_expr = p!(self, self.lower_expr(sub_expr)); hir::ExprKind::Match( sub_expr, - arms.into(), + P::from_slice(self.arena, &arms), hir::MatchSource::IfLetDesugar { contains_else_clause, }, @@ -4179,34 +4275,34 @@ impl<'a> LoweringContext<'a> { let (body, break_expr, sub_expr) = self.with_loop_scope(e.id, |this| { ( this.lower_block(body, false), - this.expr_break(e.span, ThinVec::new()), - this.with_loop_condition_scope(|this| P(this.lower_expr(sub_expr))), + this.expr_break(e.span, thin_hir_vec![]), + this.with_loop_condition_scope(|this| p!(this, this.lower_expr(sub_expr))), ) }); // ` => ` let pat_arm = { - let body_expr = P(self.expr_block(body, ThinVec::new())); - let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect(); + let body_expr = p!(self, self.expr_block(body, thin_hir_vec![])); + let pats = pats.iter().map(|pat| self.lower_pat(pat)).collect_hir_vec(arena); self.arm(pats, body_expr) }; // `_ => break` let break_arm = { let pat_under = self.pat_wild(e.span); - self.arm(hir_vec![pat_under], break_expr) + self.arm(hir_vec![self; pat_under], break_expr) }; // `match { ... }` - let arms = hir_vec![pat_arm, break_arm]; + let arms = hir_vec![self; pat_arm, break_arm]; let match_expr = self.expr( sub_expr.span, hir::ExprKind::Match(sub_expr, arms, hir::MatchSource::WhileLetDesugar), - ThinVec::new(), + thin_hir_vec![], ); // `[opt_ident]: loop { ... }` - let loop_block = P(self.block_expr(P(match_expr))); + let loop_block = p!(self, self.block_expr(p!(self, match_expr))); let loop_expr = hir::ExprKind::Loop( loop_block, self.lower_label(opt_label), @@ -4259,23 +4355,23 @@ impl<'a> LoweringContext<'a> { let pat_arm = { let val_ident = self.str_to_ident("val"); let val_pat = self.pat_ident(pat.span, val_ident); - let val_expr = P(self.expr_ident(pat.span, val_ident, val_pat.id)); - let next_expr = P(self.expr_ident(pat.span, next_ident, next_pat.id)); - let assign = P(self.expr( + let val_expr = p!(self, self.expr_ident(pat.span, val_ident, val_pat.id)); + let next_expr = p!(self, self.expr_ident(pat.span, next_ident, next_pat.id)); + let assign = p!(self, self.expr( pat.span, hir::ExprKind::Assign(next_expr, val_expr), - ThinVec::new(), + thin_hir_vec![], )); let some_pat = self.pat_some(pat.span, val_pat); - self.arm(hir_vec![some_pat], assign) + self.arm(hir_vec![self; some_pat], assign) }; // `::std::option::Option::None => break` let break_arm = { let break_expr = - self.with_loop_scope(e.id, |this| this.expr_break(e.span, ThinVec::new())); + self.with_loop_scope(e.id, |this| this.expr_break(e.span, thin_hir_vec![])); let pat = self.pat_none(e.span); - self.arm(hir_vec![pat], break_expr) + self.arm(hir_vec![self; pat], break_expr) }; // `mut iter` @@ -4287,21 +4383,27 @@ impl<'a> LoweringContext<'a> { // `match ::std::iter::Iterator::next(&mut iter) { ... }` let match_expr = { - let iter = P(self.expr_ident(head_sp, iter, iter_pat.id)); + let iter = p!(self, self.expr_ident(head_sp, iter, iter_pat.id)); let ref_mut_iter = self.expr_mut_addr_of(head_sp, iter); let next_path = &["iter", "Iterator", "next"]; - let next_path = P(self.expr_std_path(head_sp, next_path, None, ThinVec::new())); - let next_expr = P(self.expr_call(head_sp, next_path, hir_vec![ref_mut_iter])); - let arms = hir_vec![pat_arm, break_arm]; + let next_path = p!( + self, + self.expr_std_path(head_sp, next_path, None, thin_hir_vec![]) + ); + let next_expr = p!( + self, + self.expr_call(head_sp, next_path, hir_vec![self; ref_mut_iter]) + ); + let arms = hir_vec![self; pat_arm, break_arm]; - P(self.expr( + p!(self, self.expr( head_sp, hir::ExprKind::Match( next_expr, arms, hir::MatchSource::ForLoopDesugar ), - ThinVec::new(), + thin_hir_vec![], )) }; let match_stmt = respan( @@ -4309,7 +4411,7 @@ impl<'a> LoweringContext<'a> { hir::StmtKind::Expr(match_expr, self.next_id().node_id) ); - let next_expr = P(self.expr_ident(head_sp, next_ident, next_pat.id)); + let next_expr = p!(self, self.expr_ident(head_sp, next_ident, next_pat.id)); // `let mut __next` let next_let = self.stmt_let_pat( @@ -4329,15 +4431,15 @@ impl<'a> LoweringContext<'a> { ); let body_block = self.with_loop_scope(e.id, |this| this.lower_block(body, false)); - let body_expr = P(self.expr_block(body_block, ThinVec::new())); + let body_expr = p!(self, self.expr_block(body_block, thin_hir_vec![])); let body_stmt = respan( body.span, hir::StmtKind::Expr(body_expr, self.next_id().node_id) ); - let loop_block = P(self.block_all( + let loop_block = p!(self, self.block_all( e.span, - hir_vec![next_let, match_stmt, pat_let, body_stmt], + hir_vec![self; next_let, match_stmt, pat_let, body_stmt], None, )); @@ -4348,29 +4450,29 @@ impl<'a> LoweringContext<'a> { hir::LoopSource::ForLoop, ); let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); - let loop_expr = P(hir::Expr { + let loop_expr = p!(self, hir::Expr { id: node_id, hir_id, node: loop_expr, span: e.span, - attrs: ThinVec::new(), + attrs: thin_hir_vec![], }); // `mut iter => { ... }` - let iter_arm = self.arm(hir_vec![iter_pat], loop_expr); + let iter_arm = self.arm(hir_vec![self; iter_pat], loop_expr); // `match ::std::iter::IntoIterator::into_iter() { ... }` let into_iter_expr = { let into_iter_path = &["iter", "IntoIterator", "into_iter"]; - let into_iter = P(self.expr_std_path( - head_sp, into_iter_path, None, ThinVec::new())); - P(self.expr_call(head_sp, into_iter, hir_vec![head])) + let into_iter = p!(self, self.expr_std_path( + head_sp, into_iter_path, None, thin_hir_vec![])); + p!(self, self.expr_call(head_sp, into_iter, hir_vec![self; head])) }; - let match_expr = P(self.expr_match( + let match_expr = p!(self, self.expr_match( head_sp, into_iter_expr, - hir_vec![iter_arm], + hir_vec![self; iter_arm], hir::MatchSource::ForLoopDesugar, )); @@ -4380,10 +4482,14 @@ impl<'a> LoweringContext<'a> { let (let_stmt, let_stmt_binding) = self.stmt_let(e.span, false, result_ident, match_expr); - let result = P(self.expr_ident(e.span, result_ident, let_stmt_binding)); - let block = P(self.block_all(e.span, hir_vec![let_stmt], Some(result))); + let result = p!(self, self.expr_ident(e.span, result_ident, let_stmt_binding)); + let block = p!( + self, + self.block_all(e.span, hir_vec![self; let_stmt], Some(result)) + ); // Add the attributes to the outer returned expr node. - return self.expr_block(block, e.attrs.clone()); + let attrs = self.copy_attrs(e.attrs.iter().cloned()); + return self.expr_block(block, attrs); } // Desugar `ExprKind::Try` @@ -4409,9 +4515,9 @@ impl<'a> LoweringContext<'a> { let sub_expr = self.lower_expr(sub_expr); let path = &["ops", "Try", "into_result"]; - let path = P(self.expr_std_path( - unstable_span, path, None, ThinVec::new())); - P(self.expr_call(e.span, path, hir_vec![sub_expr])) + let path = p!(self, self.expr_std_path( + unstable_span, path, None, thin_hir_vec![])); + p!(self, self.expr_call(e.span, path, hir_vec![self; sub_expr])) }; // `#[allow(unreachable_code)]` @@ -4425,21 +4531,21 @@ impl<'a> LoweringContext<'a> { }; attr::mk_spanned_attr_outer(e.span, attr::mk_attr_id(), allow) }; - let attrs = vec![attr]; + let attrs = self.copy_attrs(Some(attr)); // `Ok(val) => #[allow(unreachable_code)] val,` let ok_arm = { let val_ident = self.str_to_ident("val"); let val_pat = self.pat_ident(e.span, val_ident); - let val_expr = P(self.expr_ident_with_attrs( + let val_expr = p!(self, self.expr_ident_with_attrs( e.span, val_ident, val_pat.id, - ThinVec::from(attrs.clone()), + attrs, )); let ok_pat = self.pat_ok(e.span, val_pat); - self.arm(hir_vec![ok_pat], val_expr) + self.arm(hir_vec![self; ok_pat], val_expr) }; // `Err(err) => #[allow(unreachable_code)] @@ -4449,18 +4555,17 @@ impl<'a> LoweringContext<'a> { let err_local = self.pat_ident(e.span, err_ident); let from_expr = { let path = &["convert", "From", "from"]; - let from = P(self.expr_std_path( - e.span, path, None, ThinVec::new())); + let from = p!(self, self.expr_std_path( + e.span, path, None, thin_hir_vec![])); let err_expr = self.expr_ident(e.span, err_ident, err_local.id); - self.expr_call(e.span, from, hir_vec![err_expr]) + self.expr_call(e.span, from, hir_vec![self; err_expr]) }; let from_err_expr = self.wrap_in_try_constructor("from_error", from_expr, unstable_span); - let thin_attrs = ThinVec::from(attrs); let catch_scope = self.catch_scopes.last().map(|x| *x); let ret_expr = if let Some(catch_node) = catch_scope { - P(self.expr( + p!(self, self.expr( e.span, hir::ExprKind::Break( hir::Destination { @@ -4469,19 +4574,19 @@ impl<'a> LoweringContext<'a> { }, Some(from_err_expr), ), - thin_attrs, + attrs, )) } else { - P(self.expr(e.span, hir::ExprKind::Ret(Some(from_err_expr)), thin_attrs)) + p!(self, self.expr(e.span, hir::ExprKind::Ret(Some(from_err_expr)), attrs)) }; let err_pat = self.pat_err(e.span, err_local); - self.arm(hir_vec![err_pat], ret_expr) + self.arm(hir_vec![self; err_pat], ret_expr) }; hir::ExprKind::Match( discr, - hir_vec![err_arm, ok_arm], + hir_vec![self; err_arm, ok_arm], hir::MatchSource::TryDesugar, ) } @@ -4496,11 +4601,11 @@ impl<'a> LoweringContext<'a> { hir_id, node: kind, span: e.span, - attrs: e.attrs.clone(), + attrs: self.copy_attrs(e.attrs.iter().cloned()), } } - fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> { + fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'a>; 1]> { smallvec![match s.node { StmtKind::Local(ref l) => { let (l, item_ids) = self.lower_local(l); @@ -4508,7 +4613,7 @@ impl<'a> LoweringContext<'a> { .into_iter() .map(|item_id| Spanned { node: hir::StmtKind::Decl( - P(Spanned { + p!(self, Spanned { node: hir::DeclKind::Item(item_id), span: s.span, }), @@ -4519,7 +4624,7 @@ impl<'a> LoweringContext<'a> { .collect(); ids.push(Spanned { node: hir::StmtKind::Decl( - P(Spanned { + p!(self, Spanned { node: hir::DeclKind::Local(l), span: s.span, }), @@ -4536,7 +4641,7 @@ impl<'a> LoweringContext<'a> { .into_iter() .map(|item_id| Spanned { node: hir::StmtKind::Decl( - P(Spanned { + p!(self, Spanned { node: hir::DeclKind::Item(item_id), span: s.span, }), @@ -4549,11 +4654,17 @@ impl<'a> LoweringContext<'a> { .collect(); } StmtKind::Expr(ref e) => Spanned { - node: hir::StmtKind::Expr(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), + node: hir::StmtKind::Expr( + p!(self, self.lower_expr(e)), + self.lower_node_id(s.id).node_id + ), span: s.span, }, StmtKind::Semi(ref e) => Spanned { - node: hir::StmtKind::Semi(P(self.lower_expr(e)), self.lower_node_id(s.id).node_id), + node: hir::StmtKind::Semi( + p!(self, self.lower_expr(e)), + self.lower_node_id(s.id).node_id + ), span: s.span, }, StmtKind::Mac(..) => panic!("Shouldn't exist here"), @@ -4576,7 +4687,7 @@ impl<'a> LoweringContext<'a> { &mut self, v: &Visibility, explicit_owner: Option, - ) -> hir::Visibility { + ) -> hir::Visibility<'a> { let node = match v.node { VisibilityKind::Public => hir::VisibilityKind::Public, VisibilityKind::Crate(sugar) => hir::VisibilityKind::Crate(sugar), @@ -4589,7 +4700,7 @@ impl<'a> LoweringContext<'a> { }; let def = self.expect_full_def(id); hir::VisibilityKind::Restricted { - path: P(self.lower_path_extra( + path: p!(self, self.lower_path_extra( def, path, ParamMode::Explicit, @@ -4655,7 +4766,11 @@ impl<'a> LoweringContext<'a> { // Helper methods for building HIR. - fn arm(&mut self, pats: hir::HirVec>, expr: P) -> hir::Arm { + fn arm( + &mut self, + pats: hir::HirVec<'a, P<'a, hir::Pat<'a>>>, + expr: P<'a, hir::Expr<'a>> + ) -> hir::Arm<'a> { hir::Arm { attrs: hir_vec![], pats, @@ -4664,7 +4779,7 @@ impl<'a> LoweringContext<'a> { } } - fn field(&mut self, ident: Ident, expr: P, span: Span) -> hir::Field { + fn field(&mut self, ident: Ident, expr: P<'a, hir::Expr<'a>>, span: Span) -> hir::Field<'a> { hir::Field { id: self.next_id().node_id, ident, @@ -4674,22 +4789,22 @@ impl<'a> LoweringContext<'a> { } } - fn expr_break(&mut self, span: Span, attrs: ThinVec) -> P { + fn expr_break(&mut self, span: Span, attrs: ThinHirVec<'a, Attribute>) -> P<'a, hir::Expr<'a>> { let expr_break = hir::ExprKind::Break(self.lower_loop_destination(None), None); - P(self.expr(span, expr_break, attrs)) + p!(self, self.expr(span, expr_break, attrs)) } fn expr_call( &mut self, span: Span, - e: P, - args: hir::HirVec, - ) -> hir::Expr { - self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new()) + e: P<'a, hir::Expr<'a>>, + args: hir::HirVec<'a, hir::Expr<'a>>, + ) -> hir::Expr<'a> { + self.expr(span, hir::ExprKind::Call(e, args), thin_hir_vec![]) } - fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr { - self.expr_ident_with_attrs(span, ident, binding, ThinVec::new()) + fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr<'a> { + self.expr_ident_with_attrs(span, ident, binding, thin_hir_vec![]) } fn expr_ident_with_attrs( @@ -4697,35 +4812,35 @@ impl<'a> LoweringContext<'a> { span: Span, ident: Ident, binding: NodeId, - attrs: ThinVec, - ) -> hir::Expr { + attrs: ThinHirVec<'a, Attribute>, + ) -> hir::Expr<'a> { let expr_path = hir::ExprKind::Path(hir::QPath::Resolved( None, - P(hir::Path { + p!(self, hir::Path { span, def: Def::Local(binding), - segments: hir_vec![hir::PathSegment::from_ident(ident)], + segments: hir_vec![self; hir::PathSegment::from_ident(ident)], }), )); self.expr(span, expr_path, attrs) } - fn expr_mut_addr_of(&mut self, span: Span, e: P) -> hir::Expr { - self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), ThinVec::new()) + fn expr_mut_addr_of(&mut self, span: Span, e: P<'a, hir::Expr<'a>>) -> hir::Expr<'a> { + self.expr(span, hir::ExprKind::AddrOf(hir::MutMutable, e), thin_hir_vec![]) } fn expr_std_path( &mut self, span: Span, components: &[&str], - params: Option>, - attrs: ThinVec, - ) -> hir::Expr { + params: Option>>, + attrs: ThinHirVec<'a, Attribute>, + ) -> hir::Expr<'a> { let path = self.std_path(span, components, params, true); self.expr( span, - hir::ExprKind::Path(hir::QPath::Resolved(None, P(path))), + hir::ExprKind::Path(hir::QPath::Resolved(None, p!(self, path))), attrs, ) } @@ -4733,22 +4848,35 @@ impl<'a> LoweringContext<'a> { fn expr_match( &mut self, span: Span, - arg: P, - arms: hir::HirVec, + arg: P<'a, hir::Expr<'a>>, + arms: hir::HirVec<'a, hir::Arm<'a>>, source: hir::MatchSource, - ) -> hir::Expr { - self.expr(span, hir::ExprKind::Match(arg, arms, source), ThinVec::new()) + ) -> hir::Expr<'a> { + self.expr(span, hir::ExprKind::Match(arg, arms, source), thin_hir_vec![]) } - fn expr_block(&mut self, b: P, attrs: ThinVec) -> hir::Expr { + fn expr_block( + &mut self, + b: P<'a, hir::Block<'a>>, + attrs: ThinHirVec<'a, Attribute> + ) -> hir::Expr<'a> { self.expr(b.span, hir::ExprKind::Block(b, None), attrs) } - fn expr_tuple(&mut self, sp: Span, exprs: hir::HirVec) -> P { - P(self.expr(sp, hir::ExprKind::Tup(exprs), ThinVec::new())) + fn expr_tuple( + &mut self, + sp: Span, + exprs: hir::HirVec<'a, hir::Expr<'a>> + ) -> P<'a, hir::Expr<'a>> { + p!(self, self.expr(sp, hir::ExprKind::Tup(exprs), thin_hir_vec![])) } - fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec) -> hir::Expr { + fn expr( + &mut self, + span: Span, + node: hir::ExprKind<'a>, + attrs: ThinHirVec<'a, Attribute> + ) -> hir::Expr<'a> { let LoweredNodeId { node_id, hir_id } = self.next_id(); hir::Expr { id: node_id, @@ -4762,24 +4890,24 @@ impl<'a> LoweringContext<'a> { fn stmt_let_pat( &mut self, sp: Span, - ex: Option>, - pat: P, + ex: Option>>, + pat: P<'a, hir::Pat<'a>>, source: hir::LocalSource, - ) -> hir::Stmt { + ) -> hir::Stmt<'a> { let LoweredNodeId { node_id, hir_id } = self.next_id(); - let local = P(hir::Local { + let local = p!(self, hir::Local { pat, ty: None, init: ex, id: node_id, hir_id, span: sp, - attrs: ThinVec::new(), + attrs: thin_hir_vec![], source, }); let decl = respan(sp, hir::DeclKind::Local(local)); - respan(sp, hir::StmtKind::Decl(P(decl), self.next_id().node_id)) + respan(sp, hir::StmtKind::Decl(p!(self, decl), self.next_id().node_id)) } fn stmt_let( @@ -4787,8 +4915,8 @@ impl<'a> LoweringContext<'a> { sp: Span, mutbl: bool, ident: Ident, - ex: P, - ) -> (hir::Stmt, NodeId) { + ex: P<'a, hir::Expr<'a>>, + ) -> (hir::Stmt<'a>, NodeId) { let pat = if mutbl { self.pat_ident_binding_mode(sp, ident, hir::BindingAnnotation::Mutable) } else { @@ -4801,16 +4929,16 @@ impl<'a> LoweringContext<'a> { ) } - fn block_expr(&mut self, expr: P) -> hir::Block { + fn block_expr(&mut self, expr: P<'a, hir::Expr<'a>>) -> hir::Block<'a> { self.block_all(expr.span, hir::HirVec::new(), Some(expr)) } fn block_all( &mut self, span: Span, - stmts: hir::HirVec, - expr: Option>, - ) -> hir::Block { + stmts: hir::HirVec<'a, hir::Stmt<'a>>, + expr: Option>>, + ) -> hir::Block<'a> { let LoweredNodeId { node_id, hir_id } = self.next_id(); hir::Block { @@ -4824,19 +4952,19 @@ impl<'a> LoweringContext<'a> { } } - fn pat_ok(&mut self, span: Span, pat: P) -> P { - self.pat_std_enum(span, &["result", "Result", "Ok"], hir_vec![pat]) + fn pat_ok(&mut self, span: Span, pat: P<'a, hir::Pat<'a>>) -> P<'a, hir::Pat<'a>> { + self.pat_std_enum(span, &["result", "Result", "Ok"], hir_vec![self; pat]) } - fn pat_err(&mut self, span: Span, pat: P) -> P { - self.pat_std_enum(span, &["result", "Result", "Err"], hir_vec![pat]) + fn pat_err(&mut self, span: Span, pat: P<'a, hir::Pat<'a>>) -> P<'a, hir::Pat<'a>> { + self.pat_std_enum(span, &["result", "Result", "Err"], hir_vec![self; pat]) } - fn pat_some(&mut self, span: Span, pat: P) -> P { - self.pat_std_enum(span, &["option", "Option", "Some"], hir_vec![pat]) + fn pat_some(&mut self, span: Span, pat: P<'a, hir::Pat<'a>>) -> P<'a, hir::Pat<'a>> { + self.pat_std_enum(span, &["option", "Option", "Some"], hir_vec![self; pat]) } - fn pat_none(&mut self, span: Span) -> P { + fn pat_none(&mut self, span: Span) -> P<'a, hir::Pat<'a>> { self.pat_std_enum(span, &["option", "Option", "None"], hir_vec![]) } @@ -4844,10 +4972,10 @@ impl<'a> LoweringContext<'a> { &mut self, span: Span, components: &[&str], - subpats: hir::HirVec>, - ) -> P { + subpats: hir::HirVec<'a, P<'a, hir::Pat<'a>>>, + ) -> P<'a, hir::Pat<'a>> { let path = self.std_path(span, components, None, true); - let qpath = hir::QPath::Resolved(None, P(path)); + let qpath = hir::QPath::Resolved(None, p!(self, path)); let pt = if subpats.is_empty() { hir::PatKind::Path(qpath) } else { @@ -4856,7 +4984,7 @@ impl<'a> LoweringContext<'a> { self.pat(span, pt) } - fn pat_ident(&mut self, span: Span, ident: Ident) -> P { + fn pat_ident(&mut self, span: Span, ident: Ident) -> P<'a, hir::Pat<'a>> { self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated) } @@ -4865,10 +4993,10 @@ impl<'a> LoweringContext<'a> { span: Span, ident: Ident, bm: hir::BindingAnnotation, - ) -> P { + ) -> P<'a, hir::Pat<'a>> { let LoweredNodeId { node_id, hir_id } = self.next_id(); - P(hir::Pat { + p!(self, hir::Pat { id: node_id, hir_id, node: hir::PatKind::Binding(bm, node_id, ident.with_span_pos(span), None), @@ -4876,13 +5004,13 @@ impl<'a> LoweringContext<'a> { }) } - fn pat_wild(&mut self, span: Span) -> P { + fn pat_wild(&mut self, span: Span) -> P<'a, hir::Pat<'a>> { self.pat(span, hir::PatKind::Wild) } - fn pat(&mut self, span: Span, pat: hir::PatKind) -> P { + fn pat(&mut self, span: Span, pat: hir::PatKind<'a>) -> P<'a, hir::Pat<'a>> { let LoweredNodeId { node_id, hir_id } = self.next_id(); - P(hir::Pat { + p!(self, hir::Pat { id: node_id, hir_id, node: pat, @@ -4897,23 +5025,23 @@ impl<'a> LoweringContext<'a> { &mut self, span: Span, components: &[&str], - params: Option>, + params: Option>>, is_value: bool - ) -> hir::Path { + ) -> hir::Path<'a> { let mut path = self.resolver - .resolve_str_path(span, self.crate_root, components, is_value); - path.segments.last_mut().unwrap().args = params; - - - for seg in path.segments.iter_mut() { + .resolve_str_path(self.arena, span, self.crate_root, components, is_value); + let mut segments = path.segments.into_vec(); + segments.last_mut().unwrap().args = params; + for seg in &mut segments { if let Some(id) = seg.id { seg.id = Some(self.lower_node_id(id).node_id); } } + path.segments = P::from_slice(self.arena, &segments); path } - fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath) -> hir::Ty { + fn ty_path(&mut self, id: LoweredNodeId, span: Span, qpath: hir::QPath<'a>) -> hir::Ty<'a> { let mut id = id; let node = match qpath { hir::QPath::Resolved(None, path) => { @@ -4923,7 +5051,7 @@ impl<'a> LoweringContext<'a> { let principal = hir::PolyTraitRef { bound_generic_params: hir::HirVec::new(), trait_ref: hir::TraitRef { - path: path.and_then(|path| path), + path: **path, ref_id: id.node_id, hir_ref_id: id.hir_id, }, @@ -4933,7 +5061,10 @@ impl<'a> LoweringContext<'a> { // The original ID is taken by the `PolyTraitRef`, // so the `Ty` itself needs a different one. id = self.next_id(); - hir::TyKind::TraitObject(hir_vec![principal], self.elided_dyn_bound(span)) + hir::TyKind::TraitObject( + hir_vec![self; principal], + self.elided_dyn_bound(span) + ) } _ => hir::TyKind::Path(hir::QPath::Resolved(None, path)), } @@ -5000,7 +5131,9 @@ impl<'a> LoweringContext<'a> { /// `std::cell::Ref`; note that implicit lifetimes in these /// sorts of cases are deprecated. This may therefore report a warning or an /// error, depending on the mode. - fn elided_path_lifetimes(&mut self, span: Span, count: usize) -> P<[hir::Lifetime]> { + fn elided_path_lifetimes(&mut self, span: Span, count: usize) -> P<'a, [hir::Lifetime]> { + let arena = self.arena; + match self.anonymous_lifetime_mode { // N.B., We intentionally ignore the create-parameter mode here // and instead "pass through" to resolve-lifetimes, which will then @@ -5013,7 +5146,7 @@ impl<'a> LoweringContext<'a> { AnonymousLifetimeMode::ReportError => { return (0..count) .map(|_| self.new_error_lifetime(None, span)) - .collect(); + .collect_hir_vec(arena); } // This is the normal case. @@ -5022,7 +5155,7 @@ impl<'a> LoweringContext<'a> { (0..count) .map(|_| self.new_implicit_lifetime(span)) - .collect() + .collect_hir_vec(arena) } /// Invoked to create the lifetime argument(s) for an elided trait object @@ -5078,13 +5211,13 @@ impl<'a> LoweringContext<'a> { fn wrap_in_try_constructor( &mut self, method: &'static str, - e: hir::Expr, + e: hir::Expr<'a>, unstable_span: Span, - ) -> P { + ) -> P<'a, hir::Expr<'a>> { let path = &["ops", "Try", method]; - let from_err = P(self.expr_std_path(unstable_span, path, None, - ThinVec::new())); - P(self.expr_call(e.span, from_err, hir_vec![e])) + let from_err = p!(self, self.expr_std_path(unstable_span, path, None, + thin_hir_vec![])); + p!(self, self.expr_call(e.span, from_err, hir_vec![self; e])) } } diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 837a20ac0f2f0..5d9d38e04d17f 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -35,19 +35,19 @@ pub struct FnLikeNode<'a> { node: Node<'a> } /// corresponds to some FnLikeNode. trait MaybeFnLike { fn is_fn_like(&self) -> bool; } -impl MaybeFnLike for ast::Item { +impl MaybeFnLike for ast::Item<'_> { fn is_fn_like(&self) -> bool { match self.node { ast::ItemKind::Fn(..) => true, _ => false, } } } -impl MaybeFnLike for ast::ImplItem { +impl MaybeFnLike for ast::ImplItem<'_> { fn is_fn_like(&self) -> bool { match self.node { ast::ImplItemKind::Method(..) => true, _ => false, } } } -impl MaybeFnLike for ast::TraitItem { +impl MaybeFnLike for ast::TraitItem<'_> { fn is_fn_like(&self) -> bool { match self.node { ast::TraitItemKind::Method(_, ast::TraitMethod::Provided(_)) => true, @@ -56,7 +56,7 @@ impl MaybeFnLike for ast::TraitItem { } } -impl MaybeFnLike for ast::Expr { +impl MaybeFnLike for ast::Expr<'_> { fn is_fn_like(&self) -> bool { match self.node { ast::ExprKind::Closure(..) => true, @@ -71,7 +71,7 @@ impl MaybeFnLike for ast::Expr { #[derive(Copy, Clone)] pub enum Code<'a> { FnLike(FnLikeNode<'a>), - Expr(&'a Expr), + Expr(&'a Expr<'a>), } impl<'a> Code<'a> { @@ -99,10 +99,10 @@ impl<'a> Code<'a> { /// use when implementing FnLikeNode operations. struct ItemFnParts<'a> { name: Name, - decl: &'a ast::FnDecl, + decl: &'a ast::FnDecl<'a>, header: ast::FnHeader, - vis: &'a ast::Visibility, - generics: &'a ast::Generics, + vis: &'a ast::Visibility<'a>, + generics: &'a ast::Generics<'a>, body: ast::BodyId, id: NodeId, span: Span, @@ -112,7 +112,7 @@ struct ItemFnParts<'a> { /// These are all the components one can extract from a closure expr /// for use when implementing FnLikeNode operations. struct ClosureParts<'a> { - decl: &'a FnDecl, + decl: &'a FnDecl<'a>, body: ast::BodyId, id: NodeId, span: Span, @@ -156,7 +156,7 @@ impl<'a> FnLikeNode<'a> { |c: ClosureParts<'a>| c.body) } - pub fn decl(self) -> &'a FnDecl { + pub fn decl(self) -> &'a FnDecl<'a> { self.handle(|i: ItemFnParts<'a>| &*i.decl, |_, _, sig: &'a ast::MethodSig, _, _, _, _| &sig.decl, |c: ClosureParts<'a>| c.decl) @@ -205,7 +205,7 @@ impl<'a> FnLikeNode<'a> { let closure = |c: ClosureParts<'a>| { FnKind::Closure(c.attrs) }; - let method = |_, ident: Ident, sig: &'a ast::MethodSig, vis, _, _, attrs| { + let method = |_, ident: Ident, sig: &'a ast::MethodSig<'a>, vis, _, _, attrs| { FnKind::Method(ident, sig, vis, attrs) }; self.handle(item, method, closure) @@ -215,8 +215,8 @@ impl<'a> FnLikeNode<'a> { I: FnOnce(ItemFnParts<'a>) -> A, M: FnOnce(NodeId, Ident, - &'a ast::MethodSig, - Option<&'a ast::Visibility>, + &'a ast::MethodSig<'a>, + Option<&'a ast::Visibility<'a>>, ast::BodyId, Span, &'a [Attribute]) diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 78acea9f58814..08aaeed768665 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -17,7 +17,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHashe /// A Visitor that walks over the HIR and collects Nodes into a HIR map pub(super) struct NodeCollector<'a, 'hir> { /// The crate - krate: &'hir Crate, + krate: &'hir Crate<'hir>, /// Source map source_map: &'a SourceMap, diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5bcbeeefa5030..3fb78679a7517 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -49,7 +49,7 @@ impl<'hir> Entry<'hir> { } } - fn fn_decl(&self) -> Option<&FnDecl> { + fn fn_decl(&self) -> Option<&FnDecl<'hir>> { match self.node { Node::Item(ref item) => { match item.node { @@ -132,28 +132,28 @@ impl<'hir> Entry<'hir> { } /// Stores a crate and any number of inlined items from other crates. -pub struct Forest { - krate: Crate, +pub struct Forest<'hir> { + krate: Crate<'hir>, pub dep_graph: DepGraph, } -impl Forest { - pub fn new(krate: Crate, dep_graph: &DepGraph) -> Forest { +impl<'hir> Forest<'hir> { + pub fn new(krate: Crate<'hir>, dep_graph: &DepGraph) -> Forest<'hir> { Forest { krate, dep_graph: dep_graph.clone(), } } - pub fn krate<'hir>(&'hir self) -> &'hir Crate { + pub fn krate(&'hir self) -> &'hir Crate<'hir> { self.dep_graph.read(DepNode::new_no_params(DepKind::Krate)); &self.krate } - /// This is internally in the depedency tracking system. + /// This is internally in the dependency tracking system. /// Use the `krate` method to ensure your dependency on the /// crate is tracked. - pub fn untracked_krate<'hir>(&'hir self) -> &'hir Crate { + pub fn untracked_krate(&'hir self) -> &'hir Crate<'hir> { &self.krate } } @@ -163,7 +163,7 @@ impl Forest { #[derive(Clone)] pub struct Map<'hir> { /// The backing storage for all the AST nodes. - pub forest: &'hir Forest, + pub forest: &'hir Forest<'hir>, /// Same as the dep_graph in forest, just available with one fewer /// deref. This is a gratuitous micro-optimization. @@ -375,7 +375,7 @@ impl<'hir> Map<'hir> { self.forest.krate() } - pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem { + pub fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> { self.read(id.node_id); // N.B., intentionally bypass `self.forest.krate()` so that we @@ -383,7 +383,7 @@ impl<'hir> Map<'hir> { self.forest.krate.trait_item(id) } - pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem { + pub fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> { self.read(id.node_id); // N.B., intentionally bypass `self.forest.krate()` so that we @@ -391,7 +391,7 @@ impl<'hir> Map<'hir> { self.forest.krate.impl_item(id) } - pub fn body(&self, id: BodyId) -> &'hir Body { + pub fn body(&self, id: BodyId) -> &'hir Body<'hir> { self.read(id.node_id); // N.B., intentionally bypass `self.forest.krate()` so that we @@ -399,7 +399,7 @@ impl<'hir> Map<'hir> { self.forest.krate.body(id) } - pub fn fn_decl(&self, node_id: ast::NodeId) -> Option { + pub fn fn_decl(&self, node_id: ast::NodeId) -> Option> { if let Some(entry) = self.find_entry(node_id) { entry.fn_decl().cloned() } else { @@ -517,7 +517,7 @@ impl<'hir> Map<'hir> { self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get` } - pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> { + pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> { self.get_if_local(id).and_then(|node| { match node { Node::ImplItem(ref impl_item) => Some(&impl_item.generics), @@ -754,28 +754,28 @@ impl<'hir> Map<'hir> { bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent)) } - pub fn expect_item(&self, id: NodeId) -> &'hir Item { + pub fn expect_item(&self, id: NodeId) -> &'hir Item<'hir> { match self.find(id) { // read recorded by `find` Some(Node::Item(item)) => item, _ => bug!("expected item, found {}", self.node_to_string(id)) } } - pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem { + pub fn expect_impl_item(&self, id: NodeId) -> &'hir ImplItem<'hir> { match self.find(id) { Some(Node::ImplItem(item)) => item, _ => bug!("expected impl item, found {}", self.node_to_string(id)) } } - pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem { + pub fn expect_trait_item(&self, id: NodeId) -> &'hir TraitItem<'hir> { match self.find(id) { Some(Node::TraitItem(item)) => item, _ => bug!("expected trait item, found {}", self.node_to_string(id)) } } - pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData { + pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData<'hir> { match self.find(id) { Some(Node::Item(i)) => { match i.node { @@ -790,21 +790,21 @@ impl<'hir> Map<'hir> { } } - pub fn expect_variant(&self, id: NodeId) -> &'hir Variant { + pub fn expect_variant(&self, id: NodeId) -> &'hir Variant<'hir> { match self.find(id) { Some(Node::Variant(variant)) => variant, _ => bug!("expected variant, found {}", self.node_to_string(id)), } } - pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem { + pub fn expect_foreign_item(&self, id: NodeId) -> &'hir ForeignItem<'hir> { match self.find(id) { Some(Node::ForeignItem(item)) => item, _ => bug!("expected foreign item, found {}", self.node_to_string(id)) } } - pub fn expect_expr(&self, id: NodeId) -> &'hir Expr { + pub fn expect_expr(&self, id: NodeId) -> &'hir Expr<'hir> { match self.find(id) { // read recorded by find Some(Node::Expr(expr)) => expr, _ => bug!("expected expr, found {}", self.node_to_string(id)) @@ -839,7 +839,7 @@ impl<'hir> Map<'hir> { Some(Node::ImplItem(ref ii)) => Some(&ii.attrs[..]), Some(Node::Variant(ref v)) => Some(&v.node.attrs[..]), Some(Node::Field(ref f)) => Some(&f.attrs[..]), - Some(Node::Expr(ref e)) => Some(&*e.attrs), + Some(Node::Expr(ref e)) => Some(&****e.attrs), Some(Node::Stmt(ref s)) => Some(s.node.attrs()), Some(Node::GenericParam(param)) => Some(¶m.attrs[..]), // unit/tuple structs take the attributes straight from @@ -1010,12 +1010,12 @@ trait Named { impl Named for Spanned { fn name(&self) -> Name { self.node.name() } } -impl Named for Item { fn name(&self) -> Name { self.ident.name } } -impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } } -impl Named for VariantKind { fn name(&self) -> Name { self.ident.name } } -impl Named for StructField { fn name(&self) -> Name { self.ident.name } } -impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } } -impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } } +impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } } +impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } } +impl Named for VariantKind<'_> { fn name(&self) -> Name { self.ident.name } } +impl Named for StructField<'_> { fn name(&self) -> Name { self.ident.name } } +impl Named for TraitItem<'_> { fn name(&self) -> Name { self.ident.name } } +impl Named for ImplItem<'_> { fn name(&self) -> Name { self.ident.name } } pub fn map_crate<'hir>(sess: &::session::Session, cstore: &dyn CrateStore, diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 7e87171a5edf7..003c6eeccb2e5 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -22,7 +22,6 @@ use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDiale use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy}; use syntax::attr::InlineAttr; use syntax::ext::hygiene::SyntaxContext; -use syntax::ptr::P; use syntax::symbol::{Symbol, keywords}; use syntax::tokenstream::TokenStream; use syntax::util::parser::ExprPrecedence; @@ -30,27 +29,22 @@ use ty::AdtKind; use ty::query::Providers; use rustc_data_structures::sync::{ParallelIterator, par_iter, Send, Sync, scope}; -use rustc_data_structures::thin_vec::ThinVec; +use arena::{TypedArena, SyncDroplessArena}; use serialize::{self, Encoder, Encodable, Decoder, Decodable}; use std::collections::BTreeMap; use std::fmt; +use self::ptr::P; + /// HIR doesn't commit to a concrete storage type and has its own alias for a vector. -/// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar +/// It can be `Vec`, `P<'a, [T]>` or potentially `Box<[T]>`, or some other container with similar /// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead /// of `Vec` to avoid keeping extra capacity. -pub type HirVec = P<[T]>; - -macro_rules! hir_vec { - ($elem:expr; $n:expr) => ( - $crate::hir::HirVec::from(vec![$elem; $n]) - ); - ($($x:expr),*) => ( - $crate::hir::HirVec::from(vec![$($x),*]) - ); -} +pub type HirVec<'a, T> = P<'a, [T]>; +pub type ThinHirVec<'a, T> = P<'a, P<'a, [T]>>; +pub mod ptr; pub mod check_attr; pub mod def; pub mod def_id; @@ -61,6 +55,14 @@ pub mod map; pub mod pat_util; pub mod print; +#[derive(Default)] +pub struct Arenas { + token_streams: TypedArena, + attrs: TypedArena, + inline_asms: TypedArena, + lits: TypedArena, +} + /// A HirId uniquely identifies a node in the HIR of the current crate. It is /// composed of the `owner`, which is the DefIndex of the directly enclosing /// hir::Item, hir::TraitItem, or hir::ImplItem (i.e., the closest "item-like"), @@ -123,7 +125,9 @@ mod item_local_id_inner { /// an "item-like" to something else can be implement by a `Vec` instead of a /// tree or hash map. newtype_index! { - pub struct ItemLocalId { .. } + pub struct ItemLocalId { + derive [HashStable] + } } } @@ -142,7 +146,7 @@ pub const DUMMY_HIR_ID: HirId = HirId { pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX; -#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, RustcEncodable, RustcDecodable, Copy, HashStable)] pub struct Label { pub ident: Ident, } @@ -153,7 +157,7 @@ impl fmt::Debug for Label { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, RustcEncodable, RustcDecodable, Copy, HashStable)] pub struct Lifetime { pub id: NodeId, pub span: Span, @@ -167,7 +171,7 @@ pub struct Lifetime { pub name: LifetimeName, } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy, HashStable)] pub enum ParamName { /// Some user-given name like `T` or `'x`. Plain(Ident), @@ -209,7 +213,7 @@ impl ParamName { } } -#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy, HashStable)] pub enum LifetimeName { /// User-given names or fresh (synthetic) names. Param(ParamName), @@ -292,28 +296,28 @@ impl Lifetime { /// A "Path" is essentially Rust's notion of a name; for instance: /// `std::cmp::PartialEq`. It's represented as a sequence of identifiers, /// along with a bunch of supporting information. -#[derive(Clone, RustcEncodable, RustcDecodable)] -pub struct Path { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] +pub struct Path<'a> { pub span: Span, /// The definition that the path resolved to. pub def: Def, /// The segments in the path: the things separated by `::`. - pub segments: HirVec, + pub segments: HirVec<'a, PathSegment<'a>>, } -impl Path { +impl Path<'_> { pub fn is_global(&self) -> bool { !self.segments.is_empty() && self.segments[0].ident.name == keywords::PathRoot.name() } } -impl fmt::Debug for Path { +impl fmt::Debug for Path<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "path({})", self) } } -impl fmt::Display for Path { +impl fmt::Display for Path<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", print::to_string(print::NO_ANN, |s| s.print_path(self, false))) } @@ -321,9 +325,10 @@ impl fmt::Display for Path { /// A segment of a path: an identifier, an optional lifetime, and a set of /// types. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct PathSegment { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct PathSegment<'a> { /// The identifier portion of this path segment. + #[stable_hasher(project(name))] pub ident: Ident, // `id` and `def` are optional. We currently only use these in save-analysis, // any path segments without these will not have save-analysis info and @@ -338,7 +343,7 @@ pub struct PathSegment { /// this is more than just simple syntactic sugar; the use of /// parens affects the region binding rules, so we preserve the /// distinction. - pub args: Option>, + pub args: Option>>, /// Whether to infer remaining type parameters, if any. /// This only applies to expression and pattern paths, and @@ -347,9 +352,9 @@ pub struct PathSegment { pub infer_types: bool, } -impl PathSegment { +impl<'a> PathSegment<'a> { /// Convert an identifier to the corresponding segment. - pub fn from_ident(ident: Ident) -> PathSegment { + pub fn from_ident(ident: Ident) -> Self { PathSegment { ident, id: None, @@ -360,10 +365,11 @@ impl PathSegment { } pub fn new( + arena: &'a SyncDroplessArena, ident: Ident, id: Option, def: Option, - args: GenericArgs, + args: GenericArgs<'a>, infer_types: bool, ) -> Self { PathSegment { @@ -374,7 +380,7 @@ impl PathSegment { args: if args.is_empty() { None } else { - Some(P(args)) + Some(P::alloc(arena, args)) } } } @@ -382,7 +388,7 @@ impl PathSegment { // FIXME: hack required because you can't create a static // `GenericArgs`, so you can't just return a `&GenericArgs`. pub fn with_generic_args(&self, f: F) -> R - where F: FnOnce(&GenericArgs) -> R + where F: FnOnce(&GenericArgs<'a>) -> R { let dummy = GenericArgs::none(); f(if let Some(ref args) = self.args { @@ -393,13 +399,13 @@ impl PathSegment { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum GenericArg { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum GenericArg<'a> { Lifetime(Lifetime), - Type(Ty), + Type(Ty<'a>), } -impl GenericArg { +impl GenericArg<'_> { pub fn span(&self) -> Span { match self { GenericArg::Lifetime(l) => l.span, @@ -415,20 +421,20 @@ impl GenericArg { } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct GenericArgs { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct GenericArgs<'a> { /// The generic arguments for this path segment. - pub args: HirVec, + pub args: HirVec<'a, GenericArg<'a>>, /// Bindings (equality constraints) on associated types, if present. /// E.g., `Foo`. - pub bindings: HirVec, + pub bindings: HirVec<'a, TypeBinding<'a>>, /// Were arguments written in parenthesized form `Fn(T) -> U`? /// This is required mostly for pretty-printing and diagnostics, /// but also for changing lifetime elision rules to be "function-like". pub parenthesized: bool, } -impl GenericArgs { +impl<'a> GenericArgs<'a> { pub fn none() -> Self { Self { args: HirVec::new(), @@ -441,7 +447,7 @@ impl GenericArgs { self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized } - pub fn inputs(&self) -> &[Ty] { + pub fn inputs(&self) -> &[Ty<'a>] { if self.parenthesized { for arg in &self.args { match arg { @@ -477,7 +483,7 @@ impl GenericArgs { /// A modifier on a bound, currently this is only used for `?Sized`, where the /// modifier is `Maybe`. Negative bounds should also be handled here. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] pub enum TraitBoundModifier { None, Maybe, @@ -487,13 +493,13 @@ pub enum TraitBoundModifier { /// `typeck::collect::compute_bounds` matches these against /// the "special" built-in traits (see `middle::lang_items`) and /// detects `Copy`, `Send` and `Sync`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum GenericBound { - Trait(PolyTraitRef, TraitBoundModifier), +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum GenericBound<'a> { + Trait(PolyTraitRef<'a>, TraitBoundModifier), Outlives(Lifetime), } -impl GenericBound { +impl GenericBound<'_> { pub fn span(&self) -> Span { match self { &GenericBound::Trait(ref t, ..) => t.span, @@ -502,9 +508,9 @@ impl GenericBound { } } -pub type GenericBounds = HirVec; +pub type GenericBounds<'a> = HirVec<'a, GenericBound<'a>>; -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum LifetimeParamKind { // Indicates that the lifetime definition was explicitly declared (e.g., in // `fn foo<'a>(x: &'a u8) -> &'a u8 { x }`). @@ -523,28 +529,28 @@ pub enum LifetimeParamKind { Error, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum GenericParamKind { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum GenericParamKind<'a> { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime { kind: LifetimeParamKind, }, Type { - default: Option>, + default: Option>>, synthetic: Option, } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct GenericParam { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct GenericParam<'a> { pub id: NodeId, pub name: ParamName, - pub attrs: HirVec, - pub bounds: GenericBounds, + pub attrs: HirVec<'a, Attribute>, + pub bounds: GenericBounds<'a>, pub span: Span, pub pure_wrt_drop: bool, - pub kind: GenericParamKind, + pub kind: GenericParamKind<'a>, } #[derive(Default)] @@ -555,15 +561,15 @@ pub struct GenericParamCount { /// Represents lifetimes and type parameters attached to a declaration /// of a function, enum, trait, etc. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Generics { - pub params: HirVec, - pub where_clause: WhereClause, +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct Generics<'a> { + pub params: HirVec<'a, GenericParam<'a>>, + pub where_clause: WhereClause<'a>, pub span: Span, } -impl Generics { - pub fn empty() -> Generics { +impl Generics<'_> { + pub fn empty<'a>() -> Generics<'a> { Generics { params: HirVec::new(), where_clause: WhereClause { @@ -602,19 +608,19 @@ impl Generics { /// Synthetic Type Parameters are converted to an other form during lowering, this allows /// to track the original form they had. Useful for error messages. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] pub enum SyntheticTyParamKind { ImplTrait } /// A `where` clause in a definition -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct WhereClause { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct WhereClause<'a> { pub id: NodeId, - pub predicates: HirVec, + pub predicates: HirVec<'a, WherePredicate<'a>>, } -impl WhereClause { +impl WhereClause<'_> { pub fn span(&self) -> Option { self.predicates.iter().map(|predicate| predicate.span()) .fold(None, |acc, i| match (acc, i) { @@ -627,17 +633,17 @@ impl WhereClause { } /// A single predicate in a `where` clause -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum WherePredicate { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum WherePredicate<'a> { /// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`). - BoundPredicate(WhereBoundPredicate), + BoundPredicate(WhereBoundPredicate<'a>), /// A lifetime predicate (e.g., `'a: 'b + 'c`). - RegionPredicate(WhereRegionPredicate), + RegionPredicate(WhereRegionPredicate<'a>), /// An equality predicate (unsupported). - EqPredicate(WhereEqPredicate), + EqPredicate(WhereEqPredicate<'a>), } -impl WherePredicate { +impl WherePredicate<'_> { pub fn span(&self) -> Span { match self { &WherePredicate::BoundPredicate(ref p) => p.span, @@ -648,32 +654,32 @@ impl WherePredicate { } /// A type bound, eg `for<'c> Foo: Send+Clone+'c` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct WhereBoundPredicate { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct WhereBoundPredicate<'a> { pub span: Span, /// Any generics from a `for` binding - pub bound_generic_params: HirVec, + pub bound_generic_params: HirVec<'a, GenericParam<'a>>, /// The type being bounded - pub bounded_ty: P, + pub bounded_ty: P<'a, Ty<'a>>, /// Trait and lifetime bounds (`Clone+Send+'static`) - pub bounds: GenericBounds, + pub bounds: GenericBounds<'a>, } /// A lifetime predicate, e.g., `'a: 'b+'c` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct WhereRegionPredicate { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct WhereRegionPredicate<'a> { pub span: Span, pub lifetime: Lifetime, - pub bounds: GenericBounds, + pub bounds: GenericBounds<'a>, } /// An equality predicate (unsupported), e.g., `T=int` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct WhereEqPredicate { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct WhereEqPredicate<'a> { pub id: NodeId, pub span: Span, - pub lhs_ty: P, - pub rhs_ty: P, + pub lhs_ty: P<'a, Ty<'a>>, + pub rhs_ty: P<'a, Ty<'a>>, } /// The top-level data structure that stores the entire contents of @@ -683,11 +689,11 @@ pub struct WhereEqPredicate { /// /// [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Crate { - pub module: Mod, - pub attrs: HirVec, +pub struct Crate<'a> { + pub module: Mod<'a>, + pub attrs: HirVec<'a, Attribute>, pub span: Span, - pub exported_macros: HirVec, + pub exported_macros: HirVec<'a, MacroDef<'a>>, // N.B., we use a BTreeMap here so that `visit_all_items` iterates // over the ids in increasing order. In principle it should not @@ -695,11 +701,11 @@ pub struct Crate { // does, because it can affect the order in which errors are // detected, which in turn can make compile-fail tests yield // slightly different results. - pub items: BTreeMap, + pub items: BTreeMap>, - pub trait_items: BTreeMap, - pub impl_items: BTreeMap, - pub bodies: BTreeMap, + pub trait_items: BTreeMap>, + pub impl_items: BTreeMap>, + pub bodies: BTreeMap>, pub trait_impls: BTreeMap>, pub trait_auto_impl: BTreeMap, @@ -710,7 +716,7 @@ pub struct Crate { pub body_ids: Vec, } -impl Crate { +impl Crate<'_> { pub fn item(&self, id: NodeId) -> &Item { &self.items[&id] } @@ -780,25 +786,27 @@ impl Crate { /// A macro definition, in this crate or imported from another. /// /// Not parsed directly, but created on macro import or `macro_rules!` expansion. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct MacroDef { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct MacroDef<'a> { pub name: Name, - pub vis: Visibility, - pub attrs: HirVec, + pub vis: Visibility<'a>, + pub attrs: HirVec<'a, Attribute>, pub id: NodeId, pub span: Span, - pub body: TokenStream, + pub body: P<'a, TokenStream>, pub legacy: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Block { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct Block<'a> { /// Statements in a block - pub stmts: HirVec, + pub stmts: HirVec<'a, Stmt<'a>>, /// An expression at the end of the block /// without a semicolon, if any - pub expr: Option>, + pub expr: Option>>, + #[stable_hasher(ignore)] pub id: NodeId, + #[stable_hasher(ignore)] pub hir_id: HirId, /// Distinguishes between `unsafe { ... }` and `{ ... }` pub rules: BlockCheckMode, @@ -809,22 +817,24 @@ pub struct Block { pub targeted_by_break: bool, } -#[derive(Clone, RustcEncodable, RustcDecodable)] -pub struct Pat { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] +pub struct Pat<'a> { + #[stable_hasher(ignore)] pub id: NodeId, + #[stable_hasher(ignore)] pub hir_id: HirId, - pub node: PatKind, + pub node: PatKind<'a>, pub span: Span, } -impl fmt::Debug for Pat { +impl fmt::Debug for Pat<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "pat({}: {})", self.id, print::to_string(print::NO_ANN, |s| s.print_pat(self))) } } -impl Pat { +impl Pat<'_> { // FIXME(#19596) this is a workaround, but there should be a better way fn walk_(&self, it: &mut G) -> bool where G: FnMut(&Pat) -> bool @@ -872,20 +882,22 @@ impl Pat { /// Patterns like the fields of Foo `{ x, ref y, ref mut z }` /// are treated the same as` x: x, y: ref y, z: ref mut z`, /// except is_shorthand is true -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct FieldPat { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct FieldPat<'a> { + #[stable_hasher(ignore)] pub id: NodeId, /// The identifier for the field + #[stable_hasher(project(name))] pub ident: Ident, /// The pattern the field is destructured to - pub pat: P, + pub pat: P<'a, Pat<'a>>, pub is_shorthand: bool, } /// Explicit binding annotations given in the HIR for a binding. Note /// that this is not the final binding *mode* that we infer after type /// inference. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] pub enum BindingAnnotation { /// No binding annotation given: this means that the final binding mode /// will depend on whether we have skipped through a `&` reference @@ -906,14 +918,14 @@ pub enum BindingAnnotation { RefMut, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum RangeEnd { Included, Excluded, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum PatKind { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum PatKind<'a> { /// Represents a wildcard pattern (`_`) Wild, @@ -921,38 +933,39 @@ pub enum PatKind { /// The `NodeId` is the canonical ID for the variable being bound, /// e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID, /// which is the pattern ID of the first `x`. - Binding(BindingAnnotation, NodeId, Ident, Option>), + Binding(BindingAnnotation, NodeId, Ident, Option>>), /// A struct or struct variant pattern, e.g., `Variant {x, y, ..}`. /// The `bool` is `true` in the presence of a `..`. - Struct(QPath, HirVec>, bool), + Struct(QPath<'a>, HirVec<'a, Spanned>>, bool), /// A tuple struct/variant pattern `Variant(x, y, .., z)`. /// If the `..` pattern fragment is present, then `Option` denotes its position. /// 0 <= position <= subpats.len() - TupleStruct(QPath, HirVec>, Option), + TupleStruct(QPath<'a>, HirVec<'a, P<'a, Pat<'a>>>, Option), /// A path pattern for an unit struct/variant or a (maybe-associated) constant. - Path(QPath), + Path(QPath<'a>), /// A tuple pattern `(a, b)`. /// If the `..` pattern fragment is present, then `Option` denotes its position. /// 0 <= position <= subpats.len() - Tuple(HirVec>, Option), + Tuple(HirVec<'a, P<'a, Pat<'a>>>, Option), /// A `box` pattern - Box(P), + Box(P<'a, Pat<'a>>), /// A reference pattern, e.g., `&mut (a, b)` - Ref(P, Mutability), + Ref(P<'a, Pat<'a>>, Mutability), /// A literal - Lit(P), + Lit(P<'a, Expr<'a>>), /// A range pattern, e.g., `1...2` or `1..2` - Range(P, P, RangeEnd), + Range(P<'a, Expr<'a>>, P<'a, Expr<'a>>, RangeEnd), /// `[a, b, ..i, y, z]` is represented as: /// `PatKind::Slice(box [a, b], Some(i), box [y, z])` - Slice(HirVec>, Option>, HirVec>), + Slice(HirVec<'a, P<'a, Pat<'a>>>, Option>>, HirVec<'a, P<'a, Pat<'a>>>), } -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, HashStable, + RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum Mutability { MutMutable, MutImmutable, @@ -968,7 +981,7 @@ impl Mutability { } } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash, HashStable)] pub enum BinOpKind { /// The `+` operator (addition) Add, @@ -1102,7 +1115,7 @@ impl Into for BinOpKind { pub type BinOp = Spanned; -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, Hash, HashStable)] pub enum UnOp { /// The `*` operator for dereferencing UnDeref, @@ -1131,9 +1144,9 @@ impl UnOp { } /// A statement -pub type Stmt = Spanned; +pub type Stmt<'a> = Spanned>; -impl fmt::Debug for StmtKind { +impl fmt::Debug for StmtKind<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Sadness. let spanned = source_map::dummy_spanned(self.clone()); @@ -1144,19 +1157,19 @@ impl fmt::Debug for StmtKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable)] -pub enum StmtKind { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] +pub enum StmtKind<'a> { /// Could be an item or a local (let) binding: - Decl(P, NodeId), + Decl(P<'a, Decl<'a>>, NodeId), /// Expr without trailing semi-colon (must have unit type): - Expr(P, NodeId), + Expr(P<'a, Expr<'a>>, NodeId), /// Expr with trailing semi-colon (may have any type): - Semi(P, NodeId), + Semi(P<'a, Expr<'a>>, NodeId), } -impl StmtKind { +impl StmtKind<'_> { pub fn attrs(&self) -> &[Attribute] { match *self { StmtKind::Decl(ref d, _) => d.node.attrs(), @@ -1175,30 +1188,30 @@ impl StmtKind { } /// Local represents a `let` statement, e.g., `let : = ;` -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Local { - pub pat: P, - pub ty: Option>, +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct Local<'a> { + pub pat: P<'a, Pat<'a>>, + pub ty: Option>>, /// Initializer expression to set the value, if any - pub init: Option>, + pub init: Option>>, pub id: NodeId, pub hir_id: HirId, pub span: Span, - pub attrs: ThinVec, + pub attrs: ThinHirVec<'a, Attribute>, pub source: LocalSource, } -pub type Decl = Spanned; +pub type Decl<'a> = Spanned>; -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum DeclKind { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum DeclKind<'a> { /// A local (let) binding: - Local(P), + Local(P<'a, Local<'a>>), /// An item binding: Item(ItemId), } -impl DeclKind { +impl DeclKind<'_> { pub fn attrs(&self) -> &[Attribute] { match *self { DeclKind::Local(ref l) => &l.attrs, @@ -1215,29 +1228,30 @@ impl DeclKind { } /// represents one arm of a 'match' -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Arm { - pub attrs: HirVec, - pub pats: HirVec>, - pub guard: Option, - pub body: P, +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct Arm<'a> { + pub attrs: HirVec<'a, Attribute>, + pub pats: HirVec<'a, P<'a, Pat<'a>>>, + pub guard: Option>, + pub body: P<'a, Expr<'a>>, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum Guard { - If(P), +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum Guard<'a> { + If(P<'a, Expr<'a>>), } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Field { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct Field<'a> { + #[stable_hasher(ignore)] pub id: NodeId, pub ident: Ident, - pub expr: P, + pub expr: P<'a, Expr<'a>>, pub span: Span, pub is_shorthand: bool, } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] pub enum BlockCheckMode { DefaultBlock, UnsafeBlock(UnsafeSource), @@ -1245,7 +1259,7 @@ pub enum BlockCheckMode { PopUnsafeBlock(UnsafeSource), } -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy, HashStable)] pub enum UnsafeSource { CompilerGenerated, UserProvided, @@ -1277,14 +1291,14 @@ pub struct BodyId { /// /// All bodies have an **owner**, which can be accessed via the HIR /// map using `body_owner_def_id()`. -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct Body { - pub arguments: HirVec, - pub value: Expr, +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] +pub struct Body<'a> { + pub arguments: HirVec<'a, Arg<'a>>, + pub value: Expr<'a>, pub is_generator: bool, } -impl Body { +impl Body<'_> { pub fn id(&self) -> BodyId { BodyId { node_id: self.value.id @@ -1309,7 +1323,7 @@ pub enum BodyOwnerKind { /// These are usually found nested inside types (e.g., array lengths) /// or expressions (e.g., repeat counts), and also used to define /// explicit discriminant values for enum variants. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct AnonConst { pub id: NodeId, pub hir_id: HirId, @@ -1317,16 +1331,16 @@ pub struct AnonConst { } /// An expression -#[derive(Clone, RustcEncodable, RustcDecodable)] -pub struct Expr { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable)] +pub struct Expr<'a> { pub id: NodeId, pub span: Span, - pub node: ExprKind, - pub attrs: ThinVec, + pub node: ExprKind<'a>, + pub attrs: ThinHirVec<'a, Attribute>, pub hir_id: HirId, } -impl Expr { +impl Expr<'_> { pub fn precedence(&self) -> ExprPrecedence { match self.node { ExprKind::Box(_) => ExprPrecedence::Box, @@ -1416,26 +1430,26 @@ impl Expr { } } -impl fmt::Debug for Expr { +impl fmt::Debug for Expr<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "expr({}: {})", self.id, print::to_string(print::NO_ANN, |s| s.print_expr(self))) } } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum ExprKind { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum ExprKind<'a> { /// A `box x` expression. - Box(P), + Box(P<'a, Expr<'a>>), /// An array (`[a, b, c, d]`) - Array(HirVec), + Array(HirVec<'a, Expr<'a>>), /// A function call /// /// The first field resolves to the function itself (usually an `ExprKind::Path`), /// and the second field is the list of arguments. /// This also represents calling the constructor of /// tuple-like ADTs such as tuple structs and enum variants. - Call(P, HirVec), + Call(P<'a, Expr<'a>>, HirVec<'a, Expr<'a>>), /// A method call (`x.foo::<'static, Bar, Baz>(a, b, c, d)`) /// /// The `PathSegment`/`Span` represent the method name and its generic arguments @@ -1445,110 +1459,110 @@ pub enum ExprKind { /// and the remaining elements are the rest of the arguments. /// Thus, `x.foo::(a, b, c, d)` is represented as /// `ExprKind::MethodCall(PathSegment { foo, [Bar, Baz] }, [x, a, b, c, d])`. - MethodCall(PathSegment, Span, HirVec), + MethodCall(PathSegment<'a>, Span, HirVec<'a, Expr<'a>>), /// A tuple (`(a, b, c ,d)`) - Tup(HirVec), + Tup(HirVec<'a, Expr<'a>>), /// A binary operation (For example: `a + b`, `a * b`) - Binary(BinOp, P, P), + Binary(BinOp, P<'a, Expr<'a>>, P<'a, Expr<'a>>), /// A unary operation (For example: `!x`, `*x`) - Unary(UnOp, P), + Unary(UnOp, P<'a, Expr<'a>>), /// A literal (For example: `1`, `"foo"`) - Lit(P), + Lit(P<'a, Lit>), /// A cast (`foo as f64`) - Cast(P, P), - Type(P, P), + Cast(P<'a, Expr<'a>>, P<'a, Ty<'a>>), + Type(P<'a, Expr<'a>>, P<'a, Ty<'a>>), /// An `if` block, with an optional else block /// /// `if expr { expr } else { expr }` - If(P, P, Option>), + If(P<'a, Expr<'a>>, P<'a, Expr<'a>>, Option>>), /// A while loop, with an optional label /// /// `'label: while expr { block }` - While(P, P, Option, D}` - Enum(EnumDef, Generics), + Enum(EnumDef<'a>, Generics<'a>), /// A struct definition, e.g., `struct Foo {x: A}` - Struct(VariantData, Generics), + Struct(VariantData<'a>, Generics<'a>), /// A union definition, e.g., `union Foo {x: A, y: B}` - Union(VariantData, Generics), + Union(VariantData<'a>, Generics<'a>), /// Represents a Trait Declaration - Trait(IsAuto, Unsafety, Generics, GenericBounds, HirVec), + Trait(IsAuto, Unsafety, Generics<'a>, GenericBounds<'a>, HirVec<'a, TraitItemRef>), /// Represents a Trait Alias Declaration - TraitAlias(Generics, GenericBounds), + TraitAlias(Generics<'a>, GenericBounds<'a>), /// An implementation, eg `impl Trait for Foo { .. }` Impl(Unsafety, ImplPolarity, Defaultness, - Generics, - Option, // (optional) trait this impl implements - P, // self - HirVec), + Generics<'a>, + Option>, // (optional) trait this impl implements + P<'a, Ty<'a>>, // self + HirVec<'a, ImplItemRef<'a>>), } -impl ItemKind { +impl ItemKind<'_> { pub fn descriptive_variant(&self) -> &str { match *self { ItemKind::ExternCrate(..) => "extern crate", @@ -2305,9 +2337,10 @@ impl ItemKind { /// type or method, and whether it is public). This allows other /// passes to find the impl they want without loading the id (which /// means fewer edges in the incremental compilation graph). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct TraitItemRef { pub id: TraitItemId, + #[stable_hasher(project(name))] pub ident: Ident, pub kind: AssociatedItemKind, pub span: Span, @@ -2320,17 +2353,18 @@ pub struct TraitItemRef { /// type or method, and whether it is public). This allows other /// passes to find the impl they want without loading the id (which /// means fewer edges in the incremental compilation graph). -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct ImplItemRef { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct ImplItemRef<'a> { pub id: ImplItemId, + #[stable_hasher(project(name))] pub ident: Ident, pub kind: AssociatedItemKind, pub span: Span, - pub vis: Visibility, + pub vis: Visibility<'a>, pub defaultness: Defaultness, } -#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum AssociatedItemKind { Const, Method { has_self: bool }, @@ -2338,29 +2372,39 @@ pub enum AssociatedItemKind { Existential, } -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub struct ForeignItem { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub struct ForeignItem<'a> { pub ident: Ident, - pub attrs: HirVec, - pub node: ForeignItemKind, + pub attrs: HirVec<'a, Attribute>, + pub node: ForeignItemKind<'a>, pub id: NodeId, pub span: Span, - pub vis: Visibility, + pub vis: Visibility<'a>, +} + +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] +pub struct ForeignItem2<'a> { + pub name: Name, + pub attrs: HirVec<'a, Attribute>, + pub node: ForeignItemKind<'a>, + pub id: NodeId, + pub span: Span, + pub vis: Visibility<'a>, } /// An item within an `extern` block -#[derive(Clone, RustcEncodable, RustcDecodable, Debug)] -pub enum ForeignItemKind { +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] +pub enum ForeignItemKind<'a> { /// A foreign function - Fn(P, HirVec, Generics), + Fn(P<'a, FnDecl<'a>>, HirVec<'a, Ident>, Generics<'a>), /// A foreign static item (`static ext: u8`), with optional mutability /// (the boolean is true when mutable) - Static(P, bool), + Static(P<'a, Ty<'a>>, bool), /// A foreign type Type, } -impl ForeignItemKind { +impl ForeignItemKind<'_> { pub fn descriptive_variant(&self) -> &str { match *self { ForeignItemKind::Fn(..) => "foreign function", @@ -2371,7 +2415,7 @@ impl ForeignItemKind { } /// A free variable referred to in a function. -#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct Freevar { /// The variable being accessed free. pub def: Def, @@ -2393,7 +2437,7 @@ pub type FreevarMap = NodeMap>; pub type CaptureModeMap = NodeMap; -#[derive(Clone, Debug)] +#[derive(Copy, Clone, Debug)] pub struct TraitCandidate { pub def_id: DefId, pub import_id: Option, @@ -2411,7 +2455,7 @@ pub fn provide(providers: &mut Providers<'_>) { providers.describe_def = map::describe_def; } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct CodegenFnAttrs { pub flags: CodegenFnAttrFlags, /// Parsed representation of the `#[inline]` attribute @@ -2435,7 +2479,7 @@ pub struct CodegenFnAttrs { } bitflags! { - #[derive(RustcEncodable, RustcDecodable)] + #[derive(RustcEncodable, RustcDecodable, HashStable)] pub struct CodegenFnAttrFlags: u32 { /// #[cold], a hint to LLVM that this function, when called, is never on /// the hot path @@ -2512,31 +2556,31 @@ impl CodegenFnAttrs { } #[derive(Copy, Clone, Debug)] -pub enum Node<'hir> { - Item(&'hir Item), - ForeignItem(&'hir ForeignItem), - TraitItem(&'hir TraitItem), - ImplItem(&'hir ImplItem), - Variant(&'hir Variant), - Field(&'hir StructField), - AnonConst(&'hir AnonConst), - Expr(&'hir Expr), - Stmt(&'hir Stmt), - PathSegment(&'hir PathSegment), - Ty(&'hir Ty), - TraitRef(&'hir TraitRef), - Binding(&'hir Pat), - Pat(&'hir Pat), - Block(&'hir Block), - Local(&'hir Local), - MacroDef(&'hir MacroDef), +pub enum Node<'a> { + Item(&'a Item<'a>), + ForeignItem(&'a ForeignItem<'a>), + TraitItem(&'a TraitItem<'a>), + ImplItem(&'a ImplItem<'a>), + Variant(&'a Variant<'a>), + Field(&'a StructField<'a>), + AnonConst(&'a AnonConst), + Expr(&'a Expr<'a>), + Stmt(&'a Stmt<'a>), + PathSegment(&'a PathSegment<'a>), + Ty(&'a Ty<'a>), + TraitRef(&'a TraitRef<'a>), + Binding(&'a Pat<'a>), + Pat(&'a Pat<'a>), + Block(&'a Block<'a>), + Local(&'a Local<'a>), + MacroDef(&'a MacroDef<'a>), /// StructCtor represents a tuple struct. - StructCtor(&'hir VariantData), + StructCtor(&'a VariantData<'a>), - Lifetime(&'hir Lifetime), - GenericParam(&'hir GenericParam), - Visibility(&'hir Visibility), + Lifetime(&'a Lifetime), + GenericParam(&'a GenericParam<'a>), + Visibility(&'a Visibility<'a>), Crate, } diff --git a/src/librustc/hir/pat_util.rs b/src/librustc/hir/pat_util.rs index 4df71a8768ab2..29f61d580777c 100644 --- a/src/librustc/hir/pat_util.rs +++ b/src/librustc/hir/pat_util.rs @@ -43,7 +43,7 @@ impl EnumerateAndAdjustIterator for T { } } -impl hir::Pat { +impl hir::Pat<'_> { pub fn is_refutable(&self) -> bool { match self.node { PatKind::Lit(_) | @@ -177,7 +177,7 @@ impl hir::Pat { } } -impl hir::Arm { +impl hir::Arm<'_> { /// Checks if the patterns for this arm contain any `ref` or `ref mut` /// bindings, and if yes whether its containing mutable ones or just immutables ones. pub fn contains_explicit_ref_binding(&self) -> Option { diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index d7acdefcc7d71..795692579cbb1 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -6,7 +6,6 @@ use syntax::parse::lexer::comments; use syntax::print::pp::{self, Breaks}; use syntax::print::pp::Breaks::{Consistent, Inconsistent}; use syntax::print::pprust::PrintState; -use syntax::ptr::P; use syntax::symbol::keywords; use syntax::util::parser::{self, AssocOp, Fixity}; use syntax_pos::{self, BytePos, FileName}; @@ -14,6 +13,7 @@ use syntax_pos::{self, BytePos, FileName}; use hir; use hir::{PatKind, GenericBound, TraitBoundModifier, RangeEnd}; use hir::{GenericParam, GenericParamKind, GenericArg}; +use hir::ptr::P; use std::borrow::Cow; use std::cell::Cell; @@ -23,11 +23,11 @@ use std::vec; pub enum AnnNode<'a> { Name(&'a ast::Name), - Block(&'a hir::Block), - Item(&'a hir::Item), + Block(&'a hir::Block<'a>), + Item(&'a hir::Item<'a>), SubItem(ast::NodeId), - Expr(&'a hir::Expr), - Pat(&'a hir::Pat), + Expr(&'a hir::Expr<'a>), + Pat(&'a hir::Pat<'a>), } pub enum Nested { @@ -57,7 +57,7 @@ pub struct NoAnn; impl PpAnn for NoAnn {} pub const NO_ANN: &dyn PpAnn = &NoAnn; -impl PpAnn for hir::Crate { +impl PpAnn for hir::Crate<'_> { fn try_fetch_item(&self, item: ast::NodeId) -> Option<&hir::Item> { Some(self.item(item)) } @@ -953,7 +953,7 @@ impl<'a> State<'a> { hir::TraitItemKind::Type(ref bounds, ref default) => { self.print_associated_type(ti.ident, Some(bounds), - default.as_ref().map(|ty| &**ty))?; + default.as_ref().map(|ty| &***ty))?; } } self.ann.post(self, AnnNode::SubItem(ti.id)) @@ -1075,7 +1075,7 @@ impl<'a> State<'a> { self.print_expr_as_cond(&i)?; self.s.space()?; self.print_expr(&then)?; - self.print_else(e.as_ref().map(|e| &**e)) + self.print_else(e.as_ref().map(|e| &***e)) } // "final else" hir::ExprKind::Block(ref b, _) => { @@ -1359,7 +1359,7 @@ impl<'a> State<'a> { self.print_type(&ty)?; } hir::ExprKind::If(ref test, ref blk, ref elseopt) => { - self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e))?; + self.print_if(&test, &blk, elseopt.as_ref().map(|e| &***e))?; } hir::ExprKind::While(ref test, ref blk, opt_label) => { if let Some(label) = opt_label { diff --git a/src/librustc/hir/ptr.rs b/src/librustc/hir/ptr.rs new file mode 100644 index 0000000000000..b19585ad57f38 --- /dev/null +++ b/src/librustc/hir/ptr.rs @@ -0,0 +1,216 @@ +use std::fmt::{self, Display, Debug}; +use std::iter::FromIterator; +use std::ops::{Deref, DerefMut}; +use std::{mem, ptr, slice, vec}; +use std::marker::PhantomData; +use arena::SyncDroplessArena; +use smallvec::SmallVec; + +use serialize::{Encodable, Decodable, Encoder, Decoder}; + +use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult, + HashStable}; + +pub trait IteratorExt: Iterator { + fn collect_hir_vec(self, arena: &SyncDroplessArena) -> P<'_, [Self::Item]>; +} + +impl IteratorExt for T where T::Item: Copy { + fn collect_hir_vec(self, arena: &SyncDroplessArena) -> P<'_, [Self::Item]> { + P::from_iter(arena, self) + } +} + +#[derive(Hash, PartialEq, Eq)] +#[repr(transparent)] +pub struct P<'a, T: ?Sized>(&'a T); + +impl<'a, T: 'a+?Sized> Clone for P<'a, T> { + #[inline] + fn clone(&self) -> Self { + P(self.0) + } +} +impl<'a, T: 'a+?Sized> Copy for P<'a, T> {} + +impl<'a, T: ?Sized> Deref for P<'a, T> { + type Target = &'a T; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl<'a, T: Copy> P<'a, [T]> { + #[inline] + pub fn from_slice(arena: &'a SyncDroplessArena, slice: &[T]) -> Self where T: Clone { + if slice.is_empty() { + P::new() + } else { + P(arena.alloc_slice(slice)) + } + } + + #[inline] + pub fn from_iter>(arena: &'a SyncDroplessArena, iter: I) -> Self + where T: Clone { + let mut iter = iter.into_iter(); + assert!(!mem::needs_drop::()); + + let size_hint = iter.size_hint(); + + match size_hint { + (min, Some(max)) if min == max => { + if min == 0 { + return P::new(); + } + let size = min.checked_mul(mem::size_of::()).unwrap(); + let mem = arena.alloc_raw(size, mem::align_of::()) as *mut _ as *mut T; + unsafe { + for i in 0..min { + ptr::write(mem.offset(i as isize), iter.next().unwrap()) + } + P(slice::from_raw_parts_mut(mem, min)) + } + } + (min, _) => { + let vec: SmallVec<[_; 8]> = iter.collect(); + P::from_slice(arena, &vec) + } + } + } +} + +impl<'a, T: Copy> P<'a, T> { + /// Equivalent to and_then(|x| x) + #[inline] + pub fn into_inner(&self) -> T { + *self.0 + } + + /// Move out of the pointer. + /// Intended for chaining transformations not covered by `map`. + #[inline] + pub fn and_then(&self, f: F) -> U where + F: FnOnce(T) -> U, + { + f(*self.0) + } + + #[inline] + pub fn alloc(arena: &'a SyncDroplessArena, inner: T) -> Self { + P(arena.alloc(inner)) + } +} + +impl<'a, T> P<'a, T> { + #[inline] + pub fn empty_thin() -> P<'a, P<'a, [T]>> { + P(&P(&[])) + } +} + +impl<'a, T: ?Sized> P<'a, T> { + // FIXME: Doesn't work with deserialization + #[inline] + pub fn from_existing(val: &'a T) -> Self { + P(val) + } +} + +impl Debug for P<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Debug::fmt(self.0, f) + } +} + +impl Display for P<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + Display::fmt(&**self, f) + } +} + +impl fmt::Pointer for P<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Pointer::fmt(&(self.0 as *const T), f) + } +} + +impl Decodable for P<'_, T> { + fn decode(d: &mut D) -> Result { + panic!() + //Decodable::decode(d).map(P) + } +} + +impl Encodable for P<'_, T> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + (**self).encode(s) + } +} + +impl<'a, T> P<'a, [T]> { + #[inline] + pub fn new() -> Self { + P(&[]) + } + + #[inline(never)] + pub fn into_vec(self) -> Vec where T: Clone { + (*self.0).iter().cloned().collect() + } +} + +impl Default for P<'_, [T]> { + /// Creates an empty `P<[T]>`. + #[inline] + fn default() -> Self { + P::new() + } +} + +impl Into> for P<'_, [T]> { + fn into(self) -> Vec { + self.into_vec() + } +} + +impl IntoIterator for P<'_, [T]> { + type Item = T; + type IntoIter = vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.into_vec().into_iter() + } +} + +impl<'a, T> IntoIterator for &'a P<'_, [T]> { + type Item = &'a T; + type IntoIter = slice::Iter<'a, T>; + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl Encodable for P<'_, [T]> { + fn encode(&self, s: &mut S) -> Result<(), S::Error> { + Encodable::encode(&**self, s) + } +} + +impl Decodable for P<'_, [T]> { + fn decode(d: &mut D) -> Result { + panic!()//Ok(P::from_vec(Decodable::decode(d)?)) + } +} + +impl HashStable for P<'_, T> + where T: ?Sized + HashStable +{ + fn hash_stable(&self, + hcx: &mut CTX, + hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher); + } +} diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index d5c9d9ff16dcb..6cbff029e8a6b 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -62,12 +62,12 @@ pub enum NodeIdHashingMode { /// We could also just store a plain reference to the hir::Crate but we want /// to avoid that the crate is used to get untracked access to all of the HIR. #[derive(Clone, Copy)] -struct BodyResolver<'gcx>(&'gcx hir::Crate); +struct BodyResolver<'gcx>(&'gcx hir::Crate<'gcx>); impl<'gcx> BodyResolver<'gcx> { // Return a reference to the hir::Body with the given BodyId. // DOES NOT DO ANY TRACKING, use carefully. - fn body(self, id: hir::BodyId) -> &'gcx hir::Body { + fn body(self, id: hir::BodyId) -> &'gcx hir::Body<'gcx> { self.0.body(id) } } diff --git a/src/librustc/ich/impls_cstore.rs b/src/librustc/ich/impls_cstore.rs deleted file mode 100644 index fdea62a1dd8f6..0000000000000 --- a/src/librustc/ich/impls_cstore.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! This module contains `HashStable` implementations for various data types -//! from rustc::middle::cstore in no particular order. - -use middle; - -impl_stable_hash_for!(enum middle::cstore::DepKind { - UnexportedMacrosOnly, - MacrosOnly, - Implicit, - Explicit -}); - -impl_stable_hash_for!(enum middle::cstore::NativeLibraryKind { - NativeStatic, - NativeStaticNobundle, - NativeFramework, - NativeUnknown -}); - -impl_stable_hash_for!(struct middle::cstore::NativeLibrary { - kind, - name, - cfg, - foreign_module, - wasm_import_module -}); - -impl_stable_hash_for!(struct middle::cstore::ForeignModule { - foreign_items, - def_id -}); - -impl_stable_hash_for!(enum middle::cstore::LinkagePreference { - RequireDynamic, - RequireStatic -}); - -impl_stable_hash_for!(struct middle::cstore::ExternCrate { - src, - span, - path_len, - direct -}); - -impl_stable_hash_for!(enum middle::cstore::ExternCrateSource { - Extern(def_id), - Use, - Path, -}); - -impl_stable_hash_for!(struct middle::cstore::CrateSource { - dylib, - rlib, - rmeta -}); diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 8ff60e5f56225..2cb6f998237ae 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -69,15 +69,6 @@ impl<'a> ToStableHashKey> for CrateNum { } } -impl<'a> HashStable> for hir::ItemLocalId { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.as_u32().hash_stable(hcx, hasher); - } -} - impl<'a> ToStableHashKey> for hir::ItemLocalId { type KeyType = hir::ItemLocalId; @@ -139,165 +130,7 @@ impl<'a> HashStable> for hir::ImplItemId { } } -impl_stable_hash_for!(enum hir::ParamName { - Plain(name), - Fresh(index), - Error, -}); - -impl_stable_hash_for!(enum hir::LifetimeName { - Param(param_name), - Implicit, - Underscore, - Static, - Error, -}); - -impl_stable_hash_for!(struct hir::Label { - ident -}); - -impl_stable_hash_for!(struct hir::Lifetime { - id, - span, - name -}); - -impl_stable_hash_for!(struct hir::Path { - span, - def, - segments -}); - -impl_stable_hash_for!(struct hir::PathSegment { - ident -> (ident.name), - id, - def, - infer_types, - args -}); - -impl_stable_hash_for!(enum hir::GenericArg { - Lifetime(lt), - Type(ty) -}); - -impl_stable_hash_for!(struct hir::GenericArgs { - args, - bindings, - parenthesized -}); - -impl_stable_hash_for!(enum hir::GenericBound { - Trait(poly_trait_ref, trait_bound_modifier), - Outlives(lifetime) -}); - -impl_stable_hash_for!(enum hir::TraitBoundModifier { - None, - Maybe -}); - -impl_stable_hash_for!(struct hir::GenericParam { - id, - name, - pure_wrt_drop, - attrs, - bounds, - span, - kind -}); - -impl_stable_hash_for!(enum hir::LifetimeParamKind { - Explicit, - InBand, - Elided, - Error, -}); - -impl<'a> HashStable> for hir::GenericParamKind { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - hir::GenericParamKind::Lifetime { kind } => { - kind.hash_stable(hcx, hasher); - } - hir::GenericParamKind::Type { ref default, synthetic } => { - default.hash_stable(hcx, hasher); - synthetic.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct hir::Generics { - params, - where_clause, - span -}); - -impl_stable_hash_for!(enum hir::SyntheticTyParamKind { - ImplTrait -}); - -impl_stable_hash_for!(struct hir::WhereClause { - id, - predicates -}); - -impl_stable_hash_for!(enum hir::WherePredicate { - BoundPredicate(pred), - RegionPredicate(pred), - EqPredicate(pred) -}); - -impl_stable_hash_for!(struct hir::WhereBoundPredicate { - span, - bound_generic_params, - bounded_ty, - bounds -}); - -impl_stable_hash_for!(struct hir::WhereRegionPredicate { - span, - lifetime, - bounds -}); - -impl_stable_hash_for!(struct hir::WhereEqPredicate { - id, - span, - lhs_ty, - rhs_ty -}); - -impl_stable_hash_for!(struct hir::MutTy { - ty, - mutbl -}); - -impl_stable_hash_for!(struct hir::MethodSig { - header, - decl -}); - -impl_stable_hash_for!(struct hir::TypeBinding { - id, - ident -> (ident.name), - ty, - span -}); - -impl_stable_hash_for!(struct hir::FnHeader { - unsafety, - constness, - asyncness, - abi -}); - -impl<'a> HashStable> for hir::Ty { +impl<'a> HashStable> for hir::Ty<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { @@ -315,234 +148,17 @@ impl<'a> HashStable> for hir::Ty { } } -impl_stable_hash_for!(enum hir::PrimTy { - Int(int_ty), - Uint(uint_ty), - Float(float_ty), - Str, - Bool, - Char -}); - -impl_stable_hash_for!(struct hir::BareFnTy { - unsafety, - abi, - generic_params, - decl, - arg_names -}); - -impl_stable_hash_for!(struct hir::ExistTy { - generics, - impl_trait_fn, - bounds -}); - -impl_stable_hash_for!(enum hir::TyKind { - Slice(t), - Array(t, body_id), - Ptr(t), - Rptr(lifetime, t), - BareFn(t), - Never, - Tup(ts), - Path(qpath), - Def(it, lt), - TraitObject(trait_refs, lifetime), - Typeof(body_id), - Err, - Infer -}); - -impl_stable_hash_for!(struct hir::FnDecl { - inputs, - output, - variadic, - implicit_self -}); - -impl_stable_hash_for!(enum hir::FunctionRetTy { - DefaultReturn(span), - Return(t) -}); - -impl_stable_hash_for!(enum hir::ImplicitSelfKind { - Imm, - Mut, - ImmRef, - MutRef, - None -}); - -impl_stable_hash_for!(struct hir::TraitRef { - // Don't hash the ref_id. It is tracked via the thing it is used to access - ref_id -> _, - hir_ref_id -> _, - path, -}); - -impl_stable_hash_for!(struct hir::PolyTraitRef { - bound_generic_params, - trait_ref, - span -}); - -impl_stable_hash_for!(enum hir::QPath { - Resolved(t, path), - TypeRelative(t, path_segment) -}); - -impl_stable_hash_for!(struct hir::MacroDef { - name, - vis, - attrs, - id, - span, - legacy, - body -}); - -impl_stable_hash_for!(struct hir::Block { - stmts, - expr, - id -> _, - hir_id -> _, - rules, - span, - targeted_by_break, -}); - -impl_stable_hash_for!(struct hir::Pat { - id -> _, - hir_id -> _, - node, - span, -}); - -impl_stable_hash_for_spanned!(hir::FieldPat); - -impl_stable_hash_for!(struct hir::FieldPat { - id -> _, - ident -> (ident.name), - pat, - is_shorthand, -}); - -impl_stable_hash_for!(enum hir::BindingAnnotation { - Unannotated, - Mutable, - Ref, - RefMut -}); - -impl_stable_hash_for!(enum hir::RangeEnd { - Included, - Excluded -}); - -impl_stable_hash_for!(enum hir::PatKind { - Wild, - Binding(binding_mode, var, name, sub), - Struct(path, field_pats, dotdot), - TupleStruct(path, field_pats, dotdot), - Path(path), - Tuple(field_pats, dotdot), - Box(sub), - Ref(sub, mutability), - Lit(expr), - Range(start, end, end_kind), - Slice(one, two, three) -}); - -impl_stable_hash_for!(enum hir::BinOpKind { - Add, - Sub, - Mul, - Div, - Rem, - And, - Or, - BitXor, - BitAnd, - BitOr, - Shl, - Shr, - Eq, - Lt, - Le, - Ne, - Ge, - Gt -}); +impl_stable_hash_for_spanned!(for<'hir> hir::FieldPat<'hir>); impl_stable_hash_for_spanned!(hir::BinOpKind); -impl_stable_hash_for!(enum hir::UnOp { - UnDeref, - UnNot, - UnNeg -}); +impl_stable_hash_for_spanned!(for<'hir> hir::StmtKind<'hir>); -impl_stable_hash_for_spanned!(hir::StmtKind); - -impl_stable_hash_for!(struct hir::Local { - pat, - ty, - init, - id, - hir_id, - span, - attrs, - source -}); - -impl_stable_hash_for_spanned!(hir::DeclKind); -impl_stable_hash_for!(enum hir::DeclKind { - Local(local), - Item(item_id) -}); - -impl_stable_hash_for!(struct hir::Arm { - attrs, - pats, - guard, - body -}); - -impl_stable_hash_for!(enum hir::Guard { - If(expr), -}); - -impl_stable_hash_for!(struct hir::Field { - id -> _, - ident, - expr, - span, - is_shorthand, -}); +impl_stable_hash_for_spanned!(for<'hir> hir::DeclKind<'hir>); impl_stable_hash_for_spanned!(ast::Name); - -impl_stable_hash_for!(enum hir::BlockCheckMode { - DefaultBlock, - UnsafeBlock(src), - PushUnsafeBlock(src), - PopUnsafeBlock(src) -}); - -impl_stable_hash_for!(enum hir::UnsafeSource { - CompilerGenerated, - UserProvided -}); - -impl_stable_hash_for!(struct hir::AnonConst { - id, - hir_id, - body -}); - -impl<'a> HashStable> for hir::Expr { +impl<'a> HashStable> for hir::Expr<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { @@ -562,177 +178,21 @@ impl<'a> HashStable> for hir::Expr { } } -impl_stable_hash_for!(enum hir::ExprKind { - Box(sub), - Array(subs), - Call(callee, args), - MethodCall(segment, span, args), - Tup(fields), - Binary(op, lhs, rhs), - Unary(op, operand), - Lit(value), - Cast(expr, t), - Type(expr, t), - If(cond, then, els), - While(cond, body, label), - Loop(body, label, loop_src), - Match(matchee, arms, match_src), - Closure(capture_clause, decl, body_id, span, gen), - Block(blk, label), - Assign(lhs, rhs), - AssignOp(op, lhs, rhs), - Field(owner, ident), - Index(lhs, rhs), - Path(path), - AddrOf(mutability, sub), - Break(destination, sub), - Continue(destination), - Ret(val), - InlineAsm(asm, inputs, outputs), - Struct(path, fields, base), - Repeat(val, times), - Yield(val), - Err -}); - -impl_stable_hash_for!(enum hir::LocalSource { - Normal, - ForLoopDesugar -}); - -impl_stable_hash_for!(enum hir::LoopSource { - Loop, - WhileLet, - ForLoop -}); - -impl<'a> HashStable> for hir::MatchSource { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use hir::MatchSource; - - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - MatchSource::Normal | - MatchSource::WhileLetDesugar | - MatchSource::ForLoopDesugar | - MatchSource::TryDesugar => { - // No fields to hash. - } - MatchSource::IfLetDesugar { contains_else_clause } => { - contains_else_clause.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(enum hir::GeneratorMovability { - Static, - Movable -}); - -impl_stable_hash_for!(enum hir::CaptureClause { - CaptureByValue, - CaptureByRef -}); - impl_stable_hash_for_spanned!(usize); -impl_stable_hash_for!(struct hir::Destination { - label, - target_id -}); - impl_stable_hash_for_spanned!(ast::Ident); -impl_stable_hash_for!(enum hir::LoopIdError { - OutsideLoopScope, - UnlabeledCfInWhileCondition, - UnresolvedLabel -}); - impl_stable_hash_for!(struct ast::Ident { name, span, }); -impl<'a> HashStable> for hir::TraitItem { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let hir::TraitItem { - id: _, - hir_id: _, - ident, - ref attrs, - ref generics, - ref node, - span - } = *self; - - hcx.hash_hir_item_like(|hcx| { - ident.name.hash_stable(hcx, hasher); - attrs.hash_stable(hcx, hasher); - generics.hash_stable(hcx, hasher); - node.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); - }); - } -} - -impl_stable_hash_for!(enum hir::TraitMethod { - Required(name), - Provided(body) -}); - -impl_stable_hash_for!(enum hir::TraitItemKind { - Const(t, body), - Method(sig, method), - Type(bounds, rhs) -}); - -impl<'a> HashStable> for hir::ImplItem { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let hir::ImplItem { - id: _, - hir_id: _, - ident, - ref vis, - defaultness, - ref attrs, - ref generics, - ref node, - span - } = *self; - - hcx.hash_hir_item_like(|hcx| { - ident.name.hash_stable(hcx, hasher); - vis.hash_stable(hcx, hasher); - defaultness.hash_stable(hcx, hasher); - attrs.hash_stable(hcx, hasher); - generics.hash_stable(hcx, hasher); - node.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); - }); - } -} - -impl_stable_hash_for!(enum hir::ImplItemKind { - Const(t, body), - Method(sig, body), - Existential(bounds), - Type(t) -}); - impl_stable_hash_for!(enum ::syntax::ast::CrateSugar { JustCrate, PubCrate, }); -impl<'a> HashStable> for hir::VisibilityKind { +impl<'a> HashStable> for hir::VisibilityKind<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { @@ -756,30 +216,9 @@ impl<'a> HashStable> for hir::VisibilityKind { } } -impl_stable_hash_for_spanned!(hir::VisibilityKind); - -impl<'a> HashStable> for hir::Defaultness { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - hir::Defaultness::Final => { - // No fields to hash. - } - hir::Defaultness::Default { has_value } => { - has_value.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(enum hir::ImplPolarity { - Positive, - Negative -}); +impl_stable_hash_for_spanned!(for<'hir> hir::VisibilityKind<'hir>); -impl<'a> HashStable> for hir::Mod { +impl<'a> HashStable> for hir::Mod<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { @@ -808,151 +247,9 @@ impl<'a> HashStable> for hir::Mod { } } -impl_stable_hash_for!(struct hir::ForeignMod { - abi, - items -}); - -impl_stable_hash_for!(struct hir::EnumDef { - variants -}); - -impl_stable_hash_for!(struct hir::VariantKind { - ident -> (ident.name), - attrs, - data, - disr_expr -}); - -impl_stable_hash_for_spanned!(hir::VariantKind); - -impl_stable_hash_for!(enum hir::UseKind { - Single, - Glob, - ListStem -}); - -impl_stable_hash_for!(struct hir::StructField { - span, - ident -> (ident.name), - vis, - id, - ty, - attrs -}); - -impl_stable_hash_for!(enum hir::VariantData { - Struct(fields, id), - Tuple(fields, id), - Unit(id) -}); - -impl<'a> HashStable> for hir::Item { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let hir::Item { - ident, - ref attrs, - id: _, - hir_id: _, - ref node, - ref vis, - span - } = *self; - - hcx.hash_hir_item_like(|hcx| { - ident.name.hash_stable(hcx, hasher); - attrs.hash_stable(hcx, hasher); - node.hash_stable(hcx, hasher); - vis.hash_stable(hcx, hasher); - span.hash_stable(hcx, hasher); - }); - } -} - -impl_stable_hash_for!(enum hir::ItemKind { - ExternCrate(orig_name), - Use(path, use_kind), - Static(ty, mutability, body_id), - Const(ty, body_id), - Fn(fn_decl, header, generics, body_id), - Mod(module), - ForeignMod(foreign_mod), - GlobalAsm(global_asm), - Ty(ty, generics), - Existential(exist), - Enum(enum_def, generics), - Struct(variant_data, generics), - Union(variant_data, generics), - Trait(is_auto, unsafety, generics, bounds, item_refs), - TraitAlias(generics, bounds), - Impl(unsafety, impl_polarity, impl_defaultness, generics, trait_ref, ty, impl_item_refs) -}); +impl_stable_hash_for_spanned!(for<'hir> hir::VariantKind<'hir>); -impl_stable_hash_for!(struct hir::TraitItemRef { - id, - ident -> (ident.name), - kind, - span, - defaultness -}); - -impl_stable_hash_for!(struct hir::ImplItemRef { - id, - ident -> (ident.name), - kind, - span, - vis, - defaultness -}); - -impl<'a> HashStable> for hir::AssociatedItemKind { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - hir::AssociatedItemKind::Const | - hir::AssociatedItemKind::Existential | - hir::AssociatedItemKind::Type => { - // No fields to hash. - } - hir::AssociatedItemKind::Method { has_self } => { - has_self.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct hir::ForeignItem { - ident -> (ident.name), - attrs, - node, - id, - span, - vis -}); - -impl_stable_hash_for!(enum hir::ForeignItemKind { - Fn(fn_decl, arg_names, generics), - Static(ty, is_mutbl), - Type -}); - -impl_stable_hash_for!(enum hir::StmtKind { - Decl(decl, id), - Expr(expr, id), - Semi(expr, id) -}); - -impl_stable_hash_for!(struct hir::Arg { - pat, - id, - hir_id -}); - -impl<'a> HashStable> for hir::Body { +impl<'a> HashStable> for hir::Body<'_> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { @@ -982,102 +279,6 @@ impl<'a> ToStableHashKey> for hir::BodyId { } } -impl_stable_hash_for!(struct hir::InlineAsmOutput { - constraint, - is_rw, - is_indirect, - span -}); - -impl_stable_hash_for!(struct hir::GlobalAsm { - asm, - ctxt -> _, // This is used for error reporting -}); - -impl_stable_hash_for!(struct hir::InlineAsm { - asm, - asm_str_style, - outputs, - inputs, - clobbers, - volatile, - alignstack, - dialect, - ctxt -> _, // This is used for error reporting -}); - -impl_stable_hash_for!(enum hir::def::CtorKind { - Fn, - Const, - Fictive -}); - -impl_stable_hash_for!(enum hir::def::NonMacroAttrKind { - Builtin, - Tool, - DeriveHelper, - LegacyPluginHelper, - Custom, -}); - -impl_stable_hash_for!(enum hir::def::Def { - Mod(def_id), - Struct(def_id), - Union(def_id), - Enum(def_id), - Existential(def_id), - Variant(def_id), - Trait(def_id), - TyAlias(def_id), - TraitAlias(def_id), - AssociatedTy(def_id), - AssociatedExistential(def_id), - PrimTy(prim_ty), - TyParam(def_id), - SelfTy(trait_def_id, impl_def_id), - ForeignTy(def_id), - Fn(def_id), - Const(def_id), - Static(def_id, is_mutbl), - StructCtor(def_id, ctor_kind), - SelfCtor(impl_def_id), - VariantCtor(def_id, ctor_kind), - Method(def_id), - AssociatedConst(def_id), - Local(def_id), - Upvar(def_id, index, expr_id), - Label(node_id), - Macro(def_id, macro_kind), - ToolMod, - NonMacroAttr(attr_kind), - Err -}); - -impl_stable_hash_for!(enum hir::Mutability { - MutMutable, - MutImmutable -}); - -impl_stable_hash_for!(enum hir::IsAuto { - Yes, - No -}); - -impl_stable_hash_for!(enum hir::Unsafety { - Unsafe, - Normal -}); - -impl_stable_hash_for!(enum hir::IsAsync { - Async, - NotAsync -}); - -impl_stable_hash_for!(enum hir::Constness { - Const, - NotConst -}); - impl<'a> HashStable> for hir::def_id::DefIndex { fn hash_stable(&self, @@ -1097,18 +298,6 @@ for hir::def_id::DefIndex { } } -impl_stable_hash_for!(struct hir::def::Export { - ident, - def, - vis, - span -}); - -impl_stable_hash_for!(struct ::middle::lib_features::LibFeatures { - stable, - unstable -}); - impl<'a> HashStable> for ::middle::lang_items::LangItem { fn hash_stable(&self, _: &mut StableHashingContext<'a>, @@ -1117,11 +306,6 @@ impl<'a> HashStable> for ::middle::lang_items::LangItem } } -impl_stable_hash_for!(struct ::middle::lang_items::LanguageItems { - items, - missing -}); - impl<'a> HashStable> for hir::TraitCandidate { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, @@ -1156,25 +340,6 @@ impl<'a> ToStableHashKey> for hir::TraitCandidate { } } -impl_stable_hash_for!(struct hir::CodegenFnAttrs { - flags, - inline, - export_name, - link_name, - target_features, - linkage, - link_section, -}); - -impl<'hir> HashStable> for hir::CodegenFnAttrFlags -{ - fn hash_stable(&self, - hcx: &mut StableHashingContext<'hir>, - hasher: &mut StableHasher) { - self.bits().hash_stable(hcx, hasher); - } -} - impl<'hir> HashStable> for attr::InlineAttr { fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, @@ -1182,8 +347,3 @@ impl<'hir> HashStable> for attr::InlineAttr { mem::discriminant(self).hash_stable(hcx, hasher); } } - -impl_stable_hash_for!(struct hir::Freevar { - def, - span -}); diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs deleted file mode 100644 index 002ac7cc7a9bb..0000000000000 --- a/src/librustc/ich/impls_mir.rs +++ /dev/null @@ -1,498 +0,0 @@ -//! This module contains `HashStable` implementations for various MIR data -//! types in no particular order. - -use ich::StableHashingContext; -use mir; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, - StableHasherResult}; -use std::mem; - -impl_stable_hash_for!(struct mir::GeneratorLayout<'tcx> { fields }); -impl_stable_hash_for!(struct mir::SourceInfo { span, scope }); -impl_stable_hash_for!(enum mir::Mutability { Mut, Not }); -impl_stable_hash_for!(enum mir::LocalKind { Var, Temp, Arg, ReturnPointer }); -impl_stable_hash_for!(struct mir::LocalDecl<'tcx> { - mutability, - ty, - user_ty, - name, - source_info, - visibility_scope, - internal, - is_block_tail, - is_user_variable -}); -impl_stable_hash_for!(struct mir::UpvarDecl { debug_name, var_hir_id, by_ref, mutability }); -impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator, is_cleanup }); -impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind }); -impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks }); - -impl_stable_hash_for!(enum mir::BorrowKind { - Shared, - Shallow, - Unique, - Mut { allow_two_phase_borrow }, -}); - -impl_stable_hash_for!(enum mir::UnsafetyViolationKind { - General, - GeneralAndConstFn, - ExternStatic(lint_node_id), - BorrowPacked(lint_node_id), -}); - -impl_stable_hash_for!(struct mir::Terminator<'tcx> { - kind, - source_info -}); - -impl_stable_hash_for!( - impl for enum mir::ClearCrossCrate [ mir::ClearCrossCrate ] { - Clear, - Set(value), - } -); - -impl<'a> HashStable> for mir::Local { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a> HashStable> for mir::BasicBlock { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a> HashStable> for mir::Field { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a> HashStable> -for mir::SourceScope { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a> HashStable> for mir::Promoted { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx> HashStable> -for mir::TerminatorKind<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - mir::TerminatorKind::Goto { ref target } => { - target.hash_stable(hcx, hasher); - } - mir::TerminatorKind::SwitchInt { ref discr, - switch_ty, - ref values, - ref targets } => { - discr.hash_stable(hcx, hasher); - switch_ty.hash_stable(hcx, hasher); - values.hash_stable(hcx, hasher); - targets.hash_stable(hcx, hasher); - } - mir::TerminatorKind::Resume | - mir::TerminatorKind::Abort | - mir::TerminatorKind::Return | - mir::TerminatorKind::GeneratorDrop | - mir::TerminatorKind::Unreachable => {} - mir::TerminatorKind::Drop { ref location, target, unwind } => { - location.hash_stable(hcx, hasher); - target.hash_stable(hcx, hasher); - unwind.hash_stable(hcx, hasher); - } - mir::TerminatorKind::DropAndReplace { ref location, - ref value, - target, - unwind, } => { - location.hash_stable(hcx, hasher); - value.hash_stable(hcx, hasher); - target.hash_stable(hcx, hasher); - unwind.hash_stable(hcx, hasher); - } - mir::TerminatorKind::Yield { ref value, - resume, - drop } => { - value.hash_stable(hcx, hasher); - resume.hash_stable(hcx, hasher); - drop.hash_stable(hcx, hasher); - } - mir::TerminatorKind::Call { ref func, - ref args, - ref destination, - cleanup, - from_hir_call, } => { - func.hash_stable(hcx, hasher); - args.hash_stable(hcx, hasher); - destination.hash_stable(hcx, hasher); - cleanup.hash_stable(hcx, hasher); - from_hir_call.hash_stable(hcx, hasher); - } - mir::TerminatorKind::Assert { ref cond, - expected, - ref msg, - target, - cleanup } => { - cond.hash_stable(hcx, hasher); - expected.hash_stable(hcx, hasher); - msg.hash_stable(hcx, hasher); - target.hash_stable(hcx, hasher); - cleanup.hash_stable(hcx, hasher); - } - mir::TerminatorKind::FalseEdges { ref real_target, ref imaginary_targets } => { - real_target.hash_stable(hcx, hasher); - for target in imaginary_targets { - target.hash_stable(hcx, hasher); - } - } - mir::TerminatorKind::FalseUnwind { ref real_target, ref unwind } => { - real_target.hash_stable(hcx, hasher); - unwind.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct mir::Statement<'tcx> { source_info, kind }); - -impl_stable_hash_for!(impl<'gcx> for enum mir::StatementKind<'gcx> [ mir::StatementKind ] { - Assign(place, rvalue), - FakeRead(cause, place), - SetDiscriminant { place, variant_index }, - StorageLive(place), - StorageDead(place), - Retag(retag_kind, place), - AscribeUserType(place, variance, c_ty), - Nop, - InlineAsm { asm, outputs, inputs }, -}); - -impl_stable_hash_for!(enum mir::RetagKind { FnEntry, TwoPhase, Raw, Default }); -impl_stable_hash_for!(enum mir::FakeReadCause { ForMatchGuard, ForMatchedPlace, ForLet }); - -impl<'a, 'gcx> HashStable> for mir::Place<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - mir::Place::Local(ref local) => { - local.hash_stable(hcx, hasher); - } - mir::Place::Static(ref statik) => { - statik.hash_stable(hcx, hasher); - } - mir::Place::Promoted(ref promoted) => { - promoted.hash_stable(hcx, hasher); - } - mir::Place::Projection(ref place_projection) => { - place_projection.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a, 'gcx, B, V, T> HashStable> -for mir::Projection<'gcx, B, V, T> - where B: HashStable>, - V: HashStable>, - T: HashStable> -{ - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let mir::Projection { - ref base, - ref elem, - } = *self; - - base.hash_stable(hcx, hasher); - elem.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, V, T> HashStable> -for mir::ProjectionElem<'gcx, V, T> - where V: HashStable>, - T: HashStable> -{ - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - mir::ProjectionElem::Deref => {} - mir::ProjectionElem::Field(field, ref ty) => { - field.hash_stable(hcx, hasher); - ty.hash_stable(hcx, hasher); - } - mir::ProjectionElem::Index(ref value) => { - value.hash_stable(hcx, hasher); - } - mir::ProjectionElem::ConstantIndex { offset, min_length, from_end } => { - offset.hash_stable(hcx, hasher); - min_length.hash_stable(hcx, hasher); - from_end.hash_stable(hcx, hasher); - } - mir::ProjectionElem::Subslice { from, to } => { - from.hash_stable(hcx, hasher); - to.hash_stable(hcx, hasher); - } - mir::ProjectionElem::Downcast(adt_def, variant) => { - adt_def.hash_stable(hcx, hasher); - variant.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct mir::SourceScopeData { span, parent_scope }); -impl_stable_hash_for!(struct mir::SourceScopeLocalData { - lint_root, safety -}); - -impl<'a> HashStable> for mir::Safety { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - mir::Safety::Safe | - mir::Safety::BuiltinUnsafe | - mir::Safety::FnUnsafe => {} - mir::Safety::ExplicitUnsafe(node_id) => { - node_id.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a, 'gcx> HashStable> for mir::Operand<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - mir::Operand::Copy(ref place) => { - place.hash_stable(hcx, hasher); - } - mir::Operand::Move(ref place) => { - place.hash_stable(hcx, hasher); - } - mir::Operand::Constant(ref constant) => { - constant.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a, 'gcx> HashStable> for mir::Rvalue<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - mir::Rvalue::Use(ref operand) => { - operand.hash_stable(hcx, hasher); - } - mir::Rvalue::Repeat(ref operand, ref val) => { - operand.hash_stable(hcx, hasher); - val.hash_stable(hcx, hasher); - } - mir::Rvalue::Ref(region, borrow_kind, ref place) => { - region.hash_stable(hcx, hasher); - borrow_kind.hash_stable(hcx, hasher); - place.hash_stable(hcx, hasher); - } - mir::Rvalue::Len(ref place) => { - place.hash_stable(hcx, hasher); - } - mir::Rvalue::Cast(cast_kind, ref operand, ty) => { - cast_kind.hash_stable(hcx, hasher); - operand.hash_stable(hcx, hasher); - ty.hash_stable(hcx, hasher); - } - mir::Rvalue::BinaryOp(op, ref operand1, ref operand2) | - mir::Rvalue::CheckedBinaryOp(op, ref operand1, ref operand2) => { - op.hash_stable(hcx, hasher); - operand1.hash_stable(hcx, hasher); - operand2.hash_stable(hcx, hasher); - } - mir::Rvalue::UnaryOp(op, ref operand) => { - op.hash_stable(hcx, hasher); - operand.hash_stable(hcx, hasher); - } - mir::Rvalue::Discriminant(ref place) => { - place.hash_stable(hcx, hasher); - } - mir::Rvalue::NullaryOp(op, ty) => { - op.hash_stable(hcx, hasher); - ty.hash_stable(hcx, hasher); - } - mir::Rvalue::Aggregate(ref kind, ref operands) => { - kind.hash_stable(hcx, hasher); - operands.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(enum mir::CastKind { - Misc, - ReifyFnPointer, - ClosureFnPointer, - UnsafeFnPointer, - Unsize -}); - -impl<'a, 'gcx> HashStable> -for mir::AggregateKind<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - mir::AggregateKind::Tuple => {} - mir::AggregateKind::Array(t) => { - t.hash_stable(hcx, hasher); - } - mir::AggregateKind::Adt(adt_def, idx, substs, user_substs, active_field) => { - adt_def.hash_stable(hcx, hasher); - idx.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - user_substs.hash_stable(hcx, hasher); - active_field.hash_stable(hcx, hasher); - } - mir::AggregateKind::Closure(def_id, ref substs) => { - def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - } - mir::AggregateKind::Generator(def_id, ref substs, movability) => { - def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - movability.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(enum mir::BinOp { - Add, - Sub, - Mul, - Div, - Rem, - BitXor, - BitAnd, - BitOr, - Shl, - Shr, - Eq, - Lt, - Le, - Ne, - Ge, - Gt, - Offset -}); - -impl_stable_hash_for!(enum mir::UnOp { - Not, - Neg -}); - -impl_stable_hash_for!(enum mir::NullOp { - Box, - SizeOf -}); - -impl_stable_hash_for!(struct mir::Constant<'tcx> { span, ty, user_ty, literal }); - -impl_stable_hash_for!(struct mir::Location { block, statement_index }); - -impl_stable_hash_for!(struct mir::BorrowCheckResult<'tcx> { - closure_requirements, - used_mut_upvars -}); - -impl_stable_hash_for!(struct mir::ClosureRegionRequirements<'tcx> { - num_external_vids, - outlives_requirements -}); - -impl_stable_hash_for!(struct mir::ClosureOutlivesRequirement<'tcx> { - subject, - outlived_free_region, - blame_span, - category -}); - -impl_stable_hash_for!(enum mir::ConstraintCategory { - Return, - Yield, - UseAsConst, - UseAsStatic, - TypeAnnotation, - Cast, - ClosureBounds, - CallArgument, - CopyBound, - SizedBound, - Assignment, - OpaqueType, - Boring, - BoringNoLocation, - Internal, -}); - -impl<'a, 'gcx> HashStable> for mir::ClosureOutlivesSubject<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - mir::ClosureOutlivesSubject::Ty(ref ty) => { - ty.hash_stable(hcx, hasher); - } - mir::ClosureOutlivesSubject::Region(ref region) => { - region.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct mir::interpret::GlobalId<'tcx> { instance, promoted }); - -impl_stable_hash_for!(struct mir::UserTypeProjection<'tcx> { base, projs }); -impl_stable_hash_for!(struct mir::UserTypeProjections<'tcx> { contents }); diff --git a/src/librustc/ich/impls_misc.rs b/src/librustc/ich/impls_misc.rs index f79adc8109a7f..417305139e472 100644 --- a/src/librustc/ich/impls_misc.rs +++ b/src/librustc/ich/impls_misc.rs @@ -1,15 +1,6 @@ //! This module contains `HashStable` implementations for various data types //! that don't fit into any of the other impls_xxx modules. -impl_stable_hash_for!(enum ::session::search_paths::PathKind { - Native, - Crate, - Dependency, - Framework, - ExternFlag, - All -}); - impl_stable_hash_for!(enum ::rustc_target::spec::PanicStrategy { Abort, Unwind diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index ef7fb0128ef4b..9fecba19973d0 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -6,11 +6,8 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher, StableHasherResult}; use std::cell::RefCell; -use std::hash as std_hash; use std::mem; use middle::region; -use infer; -use traits; use ty; use mir; @@ -65,19 +62,6 @@ impl<'a, 'gcx> HashStable> for ty::subst::Kind<'gcx> { } } -impl<'a, 'gcx> HashStable> -for ty::subst::UnpackedKind<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - ty::subst::UnpackedKind::Lifetime(lt) => lt.hash_stable(hcx, hasher), - ty::subst::UnpackedKind::Type(ty) => ty.hash_stable(hcx, hasher), - } - } -} - impl<'a> HashStable> for ty::RegionKind { fn hash_stable(&self, @@ -143,96 +127,6 @@ impl<'gcx> HashStable> for ty::BoundVar { } } -impl<'a, 'gcx> HashStable> -for ty::adjustment::AutoBorrow<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ty::adjustment::AutoBorrow::Ref(ref region, mutability) => { - region.hash_stable(hcx, hasher); - mutability.hash_stable(hcx, hasher); - } - ty::adjustment::AutoBorrow::RawPtr(mutability) => { - mutability.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a, 'gcx> HashStable> -for ty::adjustment::Adjust<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ty::adjustment::Adjust::NeverToAny | - ty::adjustment::Adjust::ReifyFnPointer | - ty::adjustment::Adjust::UnsafeFnPointer | - ty::adjustment::Adjust::ClosureFnPointer | - ty::adjustment::Adjust::MutToConstPointer | - ty::adjustment::Adjust::Unsize => {} - ty::adjustment::Adjust::Deref(ref overloaded) => { - overloaded.hash_stable(hcx, hasher); - } - ty::adjustment::Adjust::Borrow(ref autoref) => { - autoref.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target }); -impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl }); -impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region }); -impl_stable_hash_for!(enum ty::adjustment::AllowTwoPhase { - Yes, - No -}); - -impl<'gcx> HashStable> for ty::adjustment::AutoBorrowMutability { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'gcx>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ty::adjustment::AutoBorrowMutability::Mutable { ref allow_two_phase_borrow } => { - allow_two_phase_borrow.hash_stable(hcx, hasher); - } - ty::adjustment::AutoBorrowMutability::Immutable => {} - } - } -} - -impl_stable_hash_for!(struct ty::UpvarPath { hir_id }); - -impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id }); - -impl_stable_hash_for!(enum ty::BorrowKind { - ImmBorrow, - UniqueImmBorrow, - MutBorrow -}); - -impl_stable_hash_for!(impl<'gcx> for enum ty::UpvarCapture<'gcx> [ ty::UpvarCapture ] { - ByValue, - ByRef(up_var_borrow), -}); - -impl_stable_hash_for!(struct ty::GenSig<'tcx> { - yield_ty, - return_ty -}); - -impl_stable_hash_for!(struct ty::FnSig<'tcx> { - inputs_and_output, - variadic, - unsafety, - abi -}); - impl<'a, 'gcx, T> HashStable> for ty::Binder where T: HashStable> { @@ -243,97 +137,6 @@ impl<'a, 'gcx, T> HashStable> for ty::Binder } } -impl_stable_hash_for!(enum ty::ClosureKind { Fn, FnMut, FnOnce }); - -impl_stable_hash_for!(enum ty::Visibility { - Public, - Restricted(def_id), - Invisible -}); - -impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs }); -impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref }); -impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b }); -impl_stable_hash_for!(impl for tuple_struct ty::OutlivesPredicate { a, b }); -impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty }); -impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id }); - -impl_stable_hash_for!( - impl<'tcx> for enum ty::Predicate<'tcx> [ ty::Predicate ] { - Trait(pred), - Subtype(pred), - RegionOutlives(pred), - TypeOutlives(pred), - Projection(pred), - WellFormed(ty), - ObjectSafe(def_id), - ClosureKind(def_id, closure_substs, closure_kind), - ConstEvaluatable(def_id, substs), - } -); - -impl<'a> HashStable> for ty::AdtFlags { - fn hash_stable(&self, - _: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - std_hash::Hash::hash(self, hasher); - } -} - -impl<'a> HashStable> for ty::VariantFlags { - fn hash_stable(&self, - _: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - std_hash::Hash::hash(self, hasher); - } -} - -impl_stable_hash_for!(enum ty::VariantDiscr { - Explicit(def_id), - Relative(distance) -}); - -impl_stable_hash_for!(struct ty::FieldDef { - did, - ident -> (ident.name), - vis, -}); - -impl_stable_hash_for!( - impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] { - Scalar(val), - ScalarPair(a, b), - ByRef(id, alloc, offset), - } -); -impl_stable_hash_for!(struct ::mir::interpret::RawConst<'tcx> { - alloc_id, - ty, -}); - -impl_stable_hash_for! { - impl for struct mir::interpret::Pointer { - alloc_id, - offset, - tag, - } -} - -impl_stable_hash_for!( - impl for enum mir::interpret::Scalar [ mir::interpret::Scalar ] { - Bits { bits, size }, - Ptr(ptr), - } -); - -impl_stable_hash_for!( - impl<'tcx> for enum mir::interpret::AllocKind<'tcx> [ mir::interpret::AllocKind ] { - Function(instance), - Static(def_id), - Memory(mem), - } -); - // AllocIds get resolved to whatever they point to (to be stable) impl<'a> HashStable> for mir::interpret::AllocId { fn hash_stable( @@ -372,191 +175,6 @@ impl_stable_hash_for!(enum ::syntax::ast::Mutability { Mutable }); -impl_stable_hash_for!(struct ty::Const<'tcx> { - ty, - val -}); - -impl_stable_hash_for!(impl<'tcx> for enum ty::LazyConst<'tcx> [ty::LazyConst] { - Unevaluated(did, substs), - Evaluated(c) -}); - -impl_stable_hash_for!(enum mir::interpret::ErrorHandled { - Reported, - TooGeneric -}); - -impl_stable_hash_for!(struct mir::interpret::FrameInfo<'tcx> { - call_site, - lint_root, - instance -}); - -impl_stable_hash_for!(struct ty::ClosureSubsts<'tcx> { substs }); -impl_stable_hash_for!(struct ty::GeneratorSubsts<'tcx> { substs }); - -impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> { - parent, - predicates -}); - -impl_stable_hash_for!( - impl<'tcx, O> for enum mir::interpret::EvalErrorKind<'tcx, O> - [ mir::interpret::EvalErrorKind ] - { - FunctionArgCountMismatch, - DanglingPointerDeref, - DoubleFree, - InvalidMemoryAccess, - InvalidFunctionPointer, - InvalidBool, - InvalidNullPointerUsage, - ReadPointerAsBytes, - ReadBytesAsPointer, - ReadForeignStatic, - InvalidPointerMath, - DeadLocal, - StackFrameLimitReached, - OutOfTls, - TlsOutOfBounds, - CalledClosureAsFunction, - VtableForArgumentlessMethod, - ModifiedConstantMemory, - ModifiedStatic, - AssumptionNotHeld, - InlineAsm, - ReallocateNonBasePtr, - DeallocateNonBasePtr, - HeapAllocZeroBytes, - Unreachable, - ReadFromReturnPointer, - UnimplementedTraitSelection, - TypeckError, - TooGeneric, - DerefFunctionPointer, - ExecuteMemory, - OverflowNeg, - RemainderByZero, - DivisionByZero, - GeneratorResumedAfterReturn, - GeneratorResumedAfterPanic, - ReferencedConstant, - InfiniteLoop, - ReadUndefBytes(offset), - InvalidDiscriminant(val), - Panic { msg, file, line, col }, - MachineError(err), - FunctionAbiMismatch(a, b), - FunctionArgMismatch(a, b), - FunctionRetMismatch(a, b), - NoMirFor(s), - UnterminatedCString(ptr), - PointerOutOfBounds { ptr, check, allocation_size }, - InvalidBoolOp(bop), - Unimplemented(s), - BoundsCheck { len, index }, - Intrinsic(s), - InvalidChar(c), - AbiViolation(s), - AlignmentCheckFailed { required, has }, - ValidationFailure(s), - TypeNotPrimitive(ty), - ReallocatedWrongMemoryKind(a, b), - DeallocatedWrongMemoryKind(a, b), - IncorrectAllocationInformation(a, b, c, d), - Layout(lay), - HeapAllocNonPowerOfTwoAlignment(n), - PathNotFound(v), - Overflow(op), - } -); - -impl_stable_hash_for!(enum mir::interpret::InboundsCheck { - Live, - MaybeDead -}); - -impl_stable_hash_for!(enum ty::Variance { - Covariant, - Invariant, - Contravariant, - Bivariant -}); - -impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized { - Struct(index) -}); - -impl_stable_hash_for!(struct ty::Generics { - parent, - parent_count, - params, - // Reverse map to each param's `index` field, from its `def_id`. - param_def_id_to_index -> _, // Don't hash this - has_self, - has_late_bound_regions, -}); - -impl_stable_hash_for!(struct ty::GenericParamDef { - name, - def_id, - index, - pure_wrt_drop, - kind -}); - -impl_stable_hash_for!(enum ty::GenericParamDefKind { - Lifetime, - Type { has_default, object_lifetime_default, synthetic }, -}); - -impl_stable_hash_for!( - impl for enum ::middle::resolve_lifetime::Set1 [ ::middle::resolve_lifetime::Set1 ] { - Empty, - Many, - One(value), - } -); - -impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin { - ExplicitOrElided, - InBand, - Error, -}); - -impl_stable_hash_for!(enum ::middle::resolve_lifetime::Region { - Static, - EarlyBound(index, decl, is_in_band), - LateBound(db_index, decl, is_in_band), - LateBoundAnon(db_index, anon_index), - Free(call_site_scope_data, decl) -}); - -impl_stable_hash_for!(enum ty::cast::CastKind { - CoercionCast, - PtrPtrCast, - PtrAddrCast, - AddrPtrCast, - NumericCast, - EnumCast, - PrimIntCast, - U8CharCast, - ArrayPtrCast, - FnPtrPtrCast, - FnPtrAddrCast -}); - -impl_stable_hash_for!(struct ::middle::region::Scope { id, data }); - -impl_stable_hash_for!(enum ::middle::region::ScopeData { - Node, - CallSite, - Arguments, - Destruction, - Remainder(first_statement_index) -}); - impl<'a> ToStableHashKey> for region::Scope { type KeyType = region::Scope; @@ -566,129 +184,6 @@ impl<'a> ToStableHashKey> for region::Scope { } } -impl_stable_hash_for!(struct ty::adjustment::CoerceUnsizedInfo { - custom_kind -}); - -impl_stable_hash_for!(struct ty::FreeRegion { - scope, - bound_region -}); - -impl_stable_hash_for!(enum ty::BoundRegion { - BrAnon(index), - BrNamed(def_id, name), - BrFresh(index), - BrEnv -}); - -impl<'a, 'gcx> HashStable> -for ty::TyKind<'gcx> -{ - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use ty::TyKind::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - Bool | - Char | - Str | - Error | - Never => { - // Nothing more to hash. - } - Int(int_ty) => { - int_ty.hash_stable(hcx, hasher); - } - Uint(uint_ty) => { - uint_ty.hash_stable(hcx, hasher); - } - Float(float_ty) => { - float_ty.hash_stable(hcx, hasher); - } - Adt(adt_def, substs) => { - adt_def.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - } - Array(inner_ty, len) => { - inner_ty.hash_stable(hcx, hasher); - len.hash_stable(hcx, hasher); - } - Slice(inner_ty) => { - inner_ty.hash_stable(hcx, hasher); - } - RawPtr(pointee_ty) => { - pointee_ty.hash_stable(hcx, hasher); - } - Ref(region, pointee_ty, mutbl) => { - region.hash_stable(hcx, hasher); - pointee_ty.hash_stable(hcx, hasher); - mutbl.hash_stable(hcx, hasher); - } - FnDef(def_id, substs) => { - def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - } - FnPtr(ref sig) => { - sig.hash_stable(hcx, hasher); - } - Dynamic(ref existential_predicates, region) => { - existential_predicates.hash_stable(hcx, hasher); - region.hash_stable(hcx, hasher); - } - Closure(def_id, closure_substs) => { - def_id.hash_stable(hcx, hasher); - closure_substs.hash_stable(hcx, hasher); - } - Generator(def_id, generator_substs, movability) => { - def_id.hash_stable(hcx, hasher); - generator_substs.hash_stable(hcx, hasher); - movability.hash_stable(hcx, hasher); - } - GeneratorWitness(types) => { - types.hash_stable(hcx, hasher) - } - Tuple(inner_tys) => { - inner_tys.hash_stable(hcx, hasher); - } - Projection(ref data) | UnnormalizedProjection(ref data) => { - data.hash_stable(hcx, hasher); - } - Opaque(def_id, substs) => { - def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - } - Param(param_ty) => { - param_ty.hash_stable(hcx, hasher); - } - Bound(debruijn, bound_ty) => { - debruijn.hash_stable(hcx, hasher); - bound_ty.hash_stable(hcx, hasher); - } - ty::Placeholder(placeholder_ty) => { - placeholder_ty.hash_stable(hcx, hasher); - } - Foreign(def_id) => { - def_id.hash_stable(hcx, hasher); - } - Infer(infer_ty) => { - infer_ty.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(enum ty::InferTy { - TyVar(a), - IntVar(a), - FloatVar(a), - FreshTy(a), - FreshIntTy(a), - FreshFloatTy(a), -}); - impl<'a, 'gcx> HashStable> for ty::TyVid { @@ -725,141 +220,6 @@ for ty::FloatVid } } -impl_stable_hash_for!(struct ty::ParamTy { - idx, - name -}); - -impl_stable_hash_for!(struct ty::TypeAndMut<'tcx> { - ty, - mutbl -}); - -impl<'a, 'gcx> HashStable> -for ty::ExistentialPredicate<'gcx> -{ - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ty::ExistentialPredicate::Trait(ref trait_ref) => { - trait_ref.hash_stable(hcx, hasher); - } - ty::ExistentialPredicate::Projection(ref projection) => { - projection.hash_stable(hcx, hasher); - } - ty::ExistentialPredicate::AutoTrait(def_id) => { - def_id.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct ty::ExistentialTraitRef<'tcx> { - def_id, - substs -}); - -impl_stable_hash_for!(struct ty::ExistentialProjection<'tcx> { - item_def_id, - substs, - ty -}); - -impl_stable_hash_for!(struct ty::Instance<'tcx> { - def, - substs -}); - -impl<'a, 'gcx> HashStable> for ty::InstanceDef<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - - match *self { - ty::InstanceDef::Item(def_id) => { - def_id.hash_stable(hcx, hasher); - } - ty::InstanceDef::VtableShim(def_id) => { - def_id.hash_stable(hcx, hasher); - } - ty::InstanceDef::Intrinsic(def_id) => { - def_id.hash_stable(hcx, hasher); - } - ty::InstanceDef::FnPtrShim(def_id, ty) => { - def_id.hash_stable(hcx, hasher); - ty.hash_stable(hcx, hasher); - } - ty::InstanceDef::Virtual(def_id, n) => { - def_id.hash_stable(hcx, hasher); - n.hash_stable(hcx, hasher); - } - ty::InstanceDef::ClosureOnceShim { call_once } => { - call_once.hash_stable(hcx, hasher); - } - ty::InstanceDef::DropGlue(def_id, ty) => { - def_id.hash_stable(hcx, hasher); - ty.hash_stable(hcx, hasher); - } - ty::InstanceDef::CloneShim(def_id, ty) => { - def_id.hash_stable(hcx, hasher); - ty.hash_stable(hcx, hasher); - } - } - } -} - -impl_stable_hash_for!(struct ty::TraitDef { - // We already have the def_path_hash below, no need to hash it twice - def_id -> _, - unsafety, - paren_sugar, - has_auto_impl, - is_marker, - def_path_hash, -}); - -impl_stable_hash_for!(struct ty::Destructor { - did -}); - -impl_stable_hash_for!(struct ty::CrateVariancesMap { - variances, - // This is just an irrelevant helper value. - empty_variance -> _, -}); - -impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> { - predicates, - // This is just an irrelevant helper value. - empty_predicate -> _, -}); - -impl_stable_hash_for!(struct ty::AssociatedItem { - def_id, - ident -> (ident.name), - kind, - vis, - defaultness, - container, - method_has_self_argument -}); - -impl_stable_hash_for!(enum ty::AssociatedKind { - Const, - Method, - Existential, - Type -}); - -impl_stable_hash_for!(enum ty::AssociatedItemContainer { - TraitContainer(def_id), - ImplContainer(def_id) -}); - - impl<'a, 'gcx, T> HashStable> for ty::steal::Steal where T: HashStable> @@ -871,24 +231,6 @@ for ty::steal::Steal } } -impl_stable_hash_for!(struct ty::ParamEnv<'tcx> { - caller_bounds, - reveal, - def_id -}); - -impl_stable_hash_for!(enum traits::Reveal { - UserFacing, - All -}); - -impl_stable_hash_for!(enum ::middle::privacy::AccessLevel { - ReachableFromImplTrait, - Reachable, - Exported, - Public -}); - impl<'a> HashStable> for ::middle::privacy::AccessLevels { fn hash_stable(&self, @@ -903,365 +245,3 @@ for ::middle::privacy::AccessLevels { }); } } - -impl_stable_hash_for!(struct ty::CrateInherentImpls { - inherent_impls -}); - -impl_stable_hash_for!(enum ::session::CompileIncomplete { - Stopped, - Errored(error_reported) -}); - -impl_stable_hash_for!(struct ::util::common::ErrorReported {}); - -impl_stable_hash_for!(tuple_struct ::middle::reachable::ReachableSet { - reachable_set -}); - -impl<'a, 'gcx, N> HashStable> -for traits::Vtable<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::Vtable::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - - match self { - &VtableImpl(ref table_impl) => table_impl.hash_stable(hcx, hasher), - &VtableAutoImpl(ref table_def_impl) => table_def_impl.hash_stable(hcx, hasher), - &VtableParam(ref table_param) => table_param.hash_stable(hcx, hasher), - &VtableObject(ref table_obj) => table_obj.hash_stable(hcx, hasher), - &VtableBuiltin(ref table_builtin) => table_builtin.hash_stable(hcx, hasher), - &VtableClosure(ref table_closure) => table_closure.hash_stable(hcx, hasher), - &VtableFnPointer(ref table_fn_pointer) => table_fn_pointer.hash_stable(hcx, hasher), - &VtableGenerator(ref table_generator) => table_generator.hash_stable(hcx, hasher), - &VtableTraitAlias(ref table_alias) => table_alias.hash_stable(hcx, hasher), - } - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableImplData<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableImplData { - impl_def_id, - substs, - ref nested, - } = *self; - impl_def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableAutoImplData where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableAutoImplData { - trait_def_id, - ref nested, - } = *self; - trait_def_id.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableObjectData<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableObjectData { - upcast_trait_ref, - vtable_base, - ref nested, - } = *self; - upcast_trait_ref.hash_stable(hcx, hasher); - vtable_base.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableBuiltinData where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableBuiltinData { - ref nested, - } = *self; - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableClosureData<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableClosureData { - closure_def_id, - substs, - ref nested, - } = *self; - closure_def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableFnPointerData<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableFnPointerData { - fn_ty, - ref nested, - } = *self; - fn_ty.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableGeneratorData<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableGeneratorData { - generator_def_id, - substs, - ref nested, - } = *self; - generator_def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl<'a, 'gcx, N> HashStable> -for traits::VtableTraitAliasData<'gcx, N> where N: HashStable> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - let traits::VtableTraitAliasData { - alias_def_id, - substs, - ref nested, - } = *self; - alias_def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - nested.hash_stable(hcx, hasher); - } -} - -impl_stable_hash_for!( - impl<'tcx, V> for struct infer::canonical::Canonical<'tcx, V> { - max_universe, variables, value - } -); - -impl_stable_hash_for!( - struct infer::canonical::CanonicalVarValues<'tcx> { - var_values - } -); - -impl_stable_hash_for!(struct infer::canonical::CanonicalVarInfo { - kind -}); - -impl_stable_hash_for!(enum infer::canonical::CanonicalVarKind { - Ty(k), - PlaceholderTy(placeholder), - Region(ui), - PlaceholderRegion(placeholder), -}); - -impl_stable_hash_for!(enum infer::canonical::CanonicalTyVarKind { - General(ui), - Int, - Float -}); - -impl_stable_hash_for!( - impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> { - var_values, region_constraints, certainty, value - } -); - -impl_stable_hash_for!(enum infer::canonical::Certainty { - Proven, Ambiguous -}); - -impl<'a, 'tcx> HashStable> for traits::WhereClause<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::WhereClause::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - Implemented(trait_ref) => trait_ref.hash_stable(hcx, hasher), - ProjectionEq(projection) => projection.hash_stable(hcx, hasher), - TypeOutlives(ty_outlives) => ty_outlives.hash_stable(hcx, hasher), - RegionOutlives(region_outlives) => region_outlives.hash_stable(hcx, hasher), - } - } -} - -impl<'a, 'tcx> HashStable> for traits::WellFormed<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::WellFormed::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher), - Ty(ty) => ty.hash_stable(hcx, hasher), - } - } -} - -impl<'a, 'tcx> HashStable> for traits::FromEnv<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::FromEnv::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - Trait(trait_ref) => trait_ref.hash_stable(hcx, hasher), - Ty(ty) => ty.hash_stable(hcx, hasher), - } - } -} - -impl<'a, 'tcx> HashStable> for traits::DomainGoal<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::DomainGoal::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - Holds(wc) => wc.hash_stable(hcx, hasher), - WellFormed(wf) => wf.hash_stable(hcx, hasher), - FromEnv(from_env) => from_env.hash_stable(hcx, hasher), - Normalize(projection) => projection.hash_stable(hcx, hasher), - } - } -} - -impl<'a, 'tcx> HashStable> for traits::Goal<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::GoalKind::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - Implies(hypotheses, goal) => { - hypotheses.hash_stable(hcx, hasher); - goal.hash_stable(hcx, hasher); - }, - And(goal1, goal2) => { - goal1.hash_stable(hcx, hasher); - goal2.hash_stable(hcx, hasher); - } - Not(goal) => goal.hash_stable(hcx, hasher), - DomainGoal(domain_goal) => domain_goal.hash_stable(hcx, hasher), - Quantified(quantifier, goal) => { - quantifier.hash_stable(hcx, hasher); - goal.hash_stable(hcx, hasher); - }, - Subtype(a, b) => { - a.hash_stable(hcx, hasher); - b.hash_stable(hcx, hasher); - } - CannotProve => { }, - } - } -} - -impl_stable_hash_for!( - struct traits::ProgramClause<'tcx> { - goal, hypotheses, category - } -); - -impl_stable_hash_for!(enum traits::ProgramClauseCategory { - ImpliedBound, - WellFormed, - Other, -}); - -impl<'a, 'tcx> HashStable> for traits::Clause<'tcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - use traits::Clause::*; - - mem::discriminant(self).hash_stable(hcx, hasher); - match self { - Implies(clause) => clause.hash_stable(hcx, hasher), - ForAll(clause) => clause.hash_stable(hcx, hasher), - } - } -} - -impl_stable_hash_for!(enum traits::QuantifierKind { - Universal, - Existential -}); - -impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty }); - -impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty }); - -impl_stable_hash_for!( - struct traits::Environment<'tcx> { - clauses, - } -); - -impl_stable_hash_for!( - impl<'tcx, G> for struct traits::InEnvironment<'tcx, G> { - environment, - goal, - } -); - -impl<'a, 'gcx> HashStable> for ty::UserTypeAnnotation<'gcx> { - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - match *self { - ty::UserTypeAnnotation::Ty(ref ty) => { - ty.hash_stable(hcx, hasher); - } - ty::UserTypeAnnotation::TypeOf(ref def_id, ref substs) => { - def_id.hash_stable(hcx, hasher); - substs.hash_stable(hcx, hasher); - } - } - } -} - -impl<'a> HashStable> for ty::UserTypeAnnotationIndex { - #[inline] - fn hash_stable(&self, - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher) { - self.index().hash_stable(hcx, hasher); - } -} diff --git a/src/librustc/ich/mod.rs b/src/librustc/ich/mod.rs index a3a4c54178057..b407b75e68c9a 100644 --- a/src/librustc/ich/mod.rs +++ b/src/librustc/ich/mod.rs @@ -7,9 +7,7 @@ pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHa mod caching_source_map_view; mod hcx; -mod impls_cstore; mod impls_hir; -mod impls_mir; mod impls_misc; mod impls_ty; mod impls_syntax; diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs index eaf72f5a68710..2913fe16ddfff 100644 --- a/src/librustc/infer/canonical/mod.rs +++ b/src/librustc/infer/canonical/mod.rs @@ -41,7 +41,7 @@ mod substitute; /// A "canonicalized" type `V` is one where all free inference /// variables have been rewritten to "canonical vars". These are /// numbered starting from 0 in order of first appearance. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)] pub struct Canonical<'gcx, V> { pub max_universe: ty::UniverseIndex, pub variables: CanonicalVarInfos<'gcx>, @@ -61,7 +61,7 @@ impl<'gcx> UseSpecializedDecodable for CanonicalVarInfos<'gcx> {} /// vectors with the original values that were replaced by canonical /// variables. You will need to supply it later to instantiate the /// canonicalized query response. -#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)] pub struct CanonicalVarValues<'tcx> { pub var_values: IndexVec>, } @@ -99,7 +99,7 @@ impl Default for OriginalQueryValues<'tcx> { /// canonical value. This is sufficient information for code to create /// a copy of the canonical value in some other inference context, /// with fresh inference variables replacing the canonical values. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)] pub struct CanonicalVarInfo { pub kind: CanonicalVarKind, } @@ -122,7 +122,7 @@ impl CanonicalVarInfo { /// Describes the "kind" of the canonical variable. This is a "kind" /// in the type-theory sense of the term -- i.e., a "meta" type system /// that analyzes type-like values. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)] pub enum CanonicalVarKind { /// Some kind of type inference variable. Ty(CanonicalTyVarKind), @@ -159,7 +159,7 @@ impl CanonicalVarKind { /// 22.) can only be instantiated with integral/float types (e.g., /// usize or f32). In order to faithfully reproduce a type, we need to /// know what set of types a given type variable can be unified with. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable, HashStable)] pub enum CanonicalTyVarKind { /// General type variable `?T` that can be unified with arbitrary types. General(ty::UniverseIndex), @@ -174,7 +174,7 @@ pub enum CanonicalTyVarKind { /// After we execute a query with a canonicalized key, we get back a /// `Canonical>`. You can use /// `instantiate_query_result` to access the data in this result. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, HashStable)] pub struct QueryResponse<'tcx, R> { pub var_values: CanonicalVarValues<'tcx>, pub region_constraints: Vec>, @@ -189,7 +189,7 @@ pub type CanonicalizedQueryResponse<'gcx, T> = /// Indicates whether or not we were able to prove the query to be /// true. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum Certainty { /// The query is known to be true, presuming that you apply the /// given `var_values` and the region-constraints are satisfied. diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 8ee367c87c3ea..ae8724486dc28 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -11,8 +11,8 @@ struct FindLocalByTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, target_ty: &'a Ty<'tcx>, hir_map: &'a hir::map::Map<'gcx>, - found_local_pattern: Option<&'gcx Pat>, - found_arg_pattern: Option<&'gcx Pat>, + found_local_pattern: Option<&'gcx Pat<'gcx>>, + found_arg_pattern: Option<&'gcx Pat<'gcx>>, } impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> { diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index d230ce55471e9..ab451ceb9e123 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -25,7 +25,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { &self, region: Region<'tcx>, br: &ty::BoundRegion, - ) -> Option<(&hir::Ty, &hir::FnDecl)> { + ) -> Option<(&'gcx hir::Ty<'gcx>, &'gcx hir::FnDecl<'gcx>)> { if let Some(anon_reg) = self.tcx.is_suitable_region(region) { let def_id = anon_reg.def_id; if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) { @@ -50,7 +50,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { .iter() .filter_map(|arg| self.find_component_for_bound_region(arg, br)) .next() - .map(|ty| (ty, &**fndecl)); + .map(|ty| (ty, &***fndecl)); } } None @@ -62,7 +62,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { &self, arg: &'gcx hir::Ty, br: &ty::BoundRegion, - ) -> Option<(&'gcx hir::Ty)> { + ) -> Option<(&'gcx hir::Ty<'gcx>)> { let mut nested_visitor = FindNestedTypeVisitor { tcx: self.tcx, bound_region: *br, @@ -88,7 +88,7 @@ struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { bound_region: ty::BoundRegion, // The type where the anonymous lifetime appears // for e.g., Vec<`&u8`> and <`&u8`> - found_type: Option<&'gcx hir::Ty>, + found_type: Option<&'gcx hir::Ty<'gcx>>, current_index: ty::DebruijnIndex, } diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 43590a606ae90..9bb5e4d64eb8d 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -12,7 +12,7 @@ use syntax_pos::Span; #[derive(Debug)] pub(super) struct AnonymousArgInfo<'tcx> { // the argument corresponding to the anonymous region - pub arg: &'tcx hir::Arg, + pub arg: &'tcx hir::Arg<'tcx>, // the type corresponding to the anonymopus region argument pub arg_ty: Ty<'tcx>, // the ty::BoundRegion corresponding to the anonymous region diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index b2a924ac19895..9720f121c131f 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -66,6 +66,8 @@ #![warn(elided_lifetimes_in_paths)] +#![allow(warnings)] + extern crate arena; #[macro_use] extern crate bitflags; extern crate core; @@ -79,6 +81,7 @@ extern crate libc; extern crate polonius_engine; extern crate rustc_target; #[macro_use] extern crate rustc_data_structures; +#[macro_use] extern crate rustc_macros; extern crate serialize; extern crate parking_lot; extern crate rustc_errors as errors; @@ -168,6 +171,7 @@ pub mod util { #[doc(hidden)] mod rustc { pub use lint; + pub use ich; } // FIXME(#27438): right now the unit tests of librustc don't refer to any actual diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f5a7919ef09c8..4262953f5bd5b 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -515,7 +515,7 @@ pub struct LateContext<'a, 'tcx: 'a> { last_ast_node_with_lint_attrs: ast::NodeId, /// Generic type parameters in scope for the item we are in. - pub generics: Option<&'tcx hir::Generics>, + pub generics: Option<&'tcx hir::Generics<'tcx>>, } /// Context for lint checking of the AST, after expansion, before lowering to @@ -814,13 +814,13 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { self.tables = old_tables; } - fn visit_body(&mut self, body: &'tcx hir::Body) { + fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { run_lints!(self, check_body, body); hir_visit::walk_body(self, body); run_lints!(self, check_body_post, body); } - fn visit_item(&mut self, it: &'tcx hir::Item) { + fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) { let generics = self.generics.take(); self.generics = it.node.generics(); self.with_lint_attrs(it.id, &it.attrs, |cx| { @@ -833,7 +833,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { self.generics = generics; } - fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) { self.with_lint_attrs(it.id, &it.attrs, |cx| { cx.with_param_env(it.id, |cx| { run_lints!(cx, check_foreign_item, it); @@ -843,12 +843,12 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { }) } - fn visit_pat(&mut self, p: &'tcx hir::Pat) { + fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) { run_lints!(self, check_pat, p); hir_visit::walk_pat(self, p); } - fn visit_expr(&mut self, e: &'tcx hir::Expr) { + fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) { self.with_lint_attrs(e.id, &e.attrs, |cx| { run_lints!(cx, check_expr, e); hir_visit::walk_expr(cx, e); @@ -856,7 +856,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { }) } - fn visit_stmt(&mut self, s: &'tcx hir::Stmt) { + fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) { // statement attributes are actually just attributes on one of // - item // - local @@ -866,7 +866,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { hir_visit::walk_stmt(self, s); } - fn visit_fn(&mut self, fk: hir_visit::FnKind<'tcx>, decl: &'tcx hir::FnDecl, + fn visit_fn(&mut self, fk: hir_visit::FnKind<'tcx>, decl: &'tcx hir::FnDecl<'tcx>, body_id: hir::BodyId, span: Span, id: ast::NodeId) { // Wrap in tables here, not just in visit_nested_body, // in order for `check_fn` to be able to use them. @@ -880,9 +880,9 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { } fn visit_variant_data(&mut self, - s: &'tcx hir::VariantData, + s: &'tcx hir::VariantData<'tcx>, name: ast::Name, - g: &'tcx hir::Generics, + g: &'tcx hir::Generics<'tcx>, item_id: ast::NodeId, _: Span) { run_lints!(self, check_struct_def, s, name, g, item_id); @@ -890,7 +890,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { run_lints!(self, check_struct_def_post, s, name, g, item_id); } - fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { + fn visit_struct_field(&mut self, s: &'tcx hir::StructField<'tcx>) { self.with_lint_attrs(s.id, &s.attrs, |cx| { run_lints!(cx, check_struct_field, s); hir_visit::walk_struct_field(cx, s); @@ -898,8 +898,8 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { } fn visit_variant(&mut self, - v: &'tcx hir::Variant, - g: &'tcx hir::Generics, + v: &'tcx hir::Variant<'tcx>, + g: &'tcx hir::Generics<'tcx>, item_id: ast::NodeId) { self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |cx| { run_lints!(cx, check_variant, v, g); @@ -908,7 +908,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { }) } - fn visit_ty(&mut self, t: &'tcx hir::Ty) { + fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) { run_lints!(self, check_ty, t); hir_visit::walk_ty(self, t); } @@ -917,7 +917,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { run_lints!(self, check_name, sp, name); } - fn visit_mod(&mut self, m: &'tcx hir::Mod, s: Span, n: ast::NodeId) { + fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, s: Span, n: ast::NodeId) { run_lints!(self, check_mod, m, s, n); hir_visit::walk_mod(self, m, n); run_lints!(self, check_mod_post, m, s, n); @@ -930,44 +930,44 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { }) } - fn visit_block(&mut self, b: &'tcx hir::Block) { + fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) { run_lints!(self, check_block, b); hir_visit::walk_block(self, b); run_lints!(self, check_block_post, b); } - fn visit_arm(&mut self, a: &'tcx hir::Arm) { + fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) { run_lints!(self, check_arm, a); hir_visit::walk_arm(self, a); } - fn visit_decl(&mut self, d: &'tcx hir::Decl) { + fn visit_decl(&mut self, d: &'tcx hir::Decl<'tcx>) { run_lints!(self, check_decl, d); hir_visit::walk_decl(self, d); } - fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam) { + fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { run_lints!(self, check_generic_param, p); hir_visit::walk_generic_param(self, p); } - fn visit_generics(&mut self, g: &'tcx hir::Generics) { + fn visit_generics(&mut self, g: &'tcx hir::Generics<'tcx>) { run_lints!(self, check_generics, g); hir_visit::walk_generics(self, g); } - fn visit_where_predicate(&mut self, p: &'tcx hir::WherePredicate) { + fn visit_where_predicate(&mut self, p: &'tcx hir::WherePredicate<'tcx>) { run_lints!(self, check_where_predicate, p); hir_visit::walk_where_predicate(self, p); } - fn visit_poly_trait_ref(&mut self, t: &'tcx hir::PolyTraitRef, + fn visit_poly_trait_ref(&mut self, t: &'tcx hir::PolyTraitRef<'tcx>, m: hir::TraitBoundModifier) { run_lints!(self, check_poly_trait_ref, t, m); hir_visit::walk_poly_trait_ref(self, t, m); } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { let generics = self.generics.take(); self.generics = Some(&trait_item.generics); self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| { @@ -980,7 +980,7 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { self.generics = generics; } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { let generics = self.generics.take(); self.generics = Some(&impl_item.generics); self.with_lint_attrs(impl_item.id, &impl_item.attrs, |cx| { diff --git a/src/librustc/macros.rs b/src/librustc/macros.rs index 2978b35319944..5e35fc580ec96 100644 --- a/src/librustc/macros.rs +++ b/src/librustc/macros.rs @@ -172,6 +172,19 @@ macro_rules! impl_stable_hash_for { #[macro_export] macro_rules! impl_stable_hash_for_spanned { + (for<$($lt:lifetime),*> $T:path) => ( + impl<'a, 'tcx $(, $lt)*> HashStable> + for ::syntax::source_map::Spanned<$T> + { + #[inline] + fn hash_stable(&self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut StableHasher) { + self.node.hash_stable(hcx, hasher); + self.span.hash_stable(hcx, hasher); + } + } + ); ($T:path) => ( impl<'a, 'tcx> HashStable> for ::syntax::source_map::Spanned<$T> diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index c431dc77f782f..d86d98666e0c1 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -24,14 +24,15 @@ pub use self::NativeLibraryKind::*; /// Where a crate came from on the local filesystem. One of these three options /// must be non-None. -#[derive(PartialEq, Clone, Debug)] +#[derive(PartialEq, Clone, Debug, HashStable)] pub struct CrateSource { pub dylib: Option<(PathBuf, PathKind)>, pub rlib: Option<(PathBuf, PathKind)>, pub rmeta: Option<(PathBuf, PathKind)>, } -#[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)] +#[derive(RustcEncodable, RustcDecodable, Copy, Clone, + Ord, PartialOrd, Eq, PartialEq, Debug, HashStable)] pub enum DepKind { /// A dependency that is only used for its macros, none of which are visible from other crates. /// These are included in the metadata only as placeholders and are ignored when decoding. @@ -79,13 +80,14 @@ impl LibSource { } } -#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)] +#[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum LinkagePreference { RequireDynamic, RequireStatic, } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + RustcEncodable, RustcDecodable, HashStable)] pub enum NativeLibraryKind { /// native static library (.a archive) NativeStatic, @@ -97,7 +99,7 @@ pub enum NativeLibraryKind { NativeUnknown, } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct NativeLibrary { pub kind: NativeLibraryKind, pub name: Option, @@ -106,13 +108,13 @@ pub struct NativeLibrary { pub wasm_import_module: Option, } -#[derive(Clone, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct ForeignModule { pub foreign_items: Vec, pub def_id: DefId, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, HashStable)] pub struct ExternCrate { pub src: ExternCrateSource, @@ -129,7 +131,7 @@ pub struct ExternCrate { pub direct: bool, } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum ExternCrateSource { /// Crate is loaded by `extern crate`. Extern( diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0c769c91801b8..f313c8634dc76 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -334,7 +334,7 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>, // * Implementation of a trait method struct LifeSeeder<'k, 'tcx: 'k> { worklist: Vec, - krate: &'k hir::Crate, + krate: &'tcx hir::Crate<'tcx>, tcx: TyCtxt<'k, 'tcx, 'tcx>, // see `MarkSymbolVisitor::struct_constructors` struct_constructors: FxHashMap, @@ -399,7 +399,7 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> { fn create_and_seed_worklist<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, access_levels: &privacy::AccessLevels, - krate: &hir::Crate, + krate: &'tcx hir::Crate<'tcx>, ) -> (Vec, FxHashMap) { let worklist = access_levels.map.iter().filter_map(|(&id, level)| { if level >= &privacy::AccessLevel::Reachable { @@ -426,7 +426,7 @@ fn create_and_seed_worklist<'a, 'tcx>( fn find_live<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, access_levels: &privacy::AccessLevels, - krate: &hir::Crate) + krate: &'tcx hir::Crate<'tcx>) -> FxHashSet { let (worklist, struct_constructors) = create_and_seed_worklist(tcx, access_levels, krate); let mut symbol_visitor = MarkSymbolVisitor { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index c1aa25b6b75c2..accf45ee149e5 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -17,10 +17,10 @@ use middle::region; use ty::{self, TyCtxt, adjustment}; use hir::{self, PatKind}; +use hir::ptr::P; use rustc_data_structures::sync::Lrc; use std::rc::Rc; use syntax::ast; -use syntax::ptr::P; use syntax_pos::Span; use util::nodemap::ItemLocalSet; @@ -299,7 +299,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - pub fn consume_body(&mut self, body: &hir::Body) { + pub fn consume_body(&mut self, body: &hir::Body<'tcx>) { debug!("consume_body(body={:?})", body); for arg in &body.arguments { @@ -339,13 +339,13 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { self.delegate.consume(consume_id, consume_span, cmt, mode); } - fn consume_exprs(&mut self, exprs: &[hir::Expr]) { + fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) { for expr in exprs { self.consume_expr(&expr); } } - pub fn consume_expr(&mut self, expr: &hir::Expr) { + pub fn consume_expr(&mut self, expr: &hir::Expr<'_>) { debug!("consume_expr(expr={:?})", expr); let cmt = return_if_err!(self.mc.cat_expr(expr)); @@ -355,8 +355,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { fn mutate_expr(&mut self, span: Span, - assignment_expr: &hir::Expr, - expr: &hir::Expr, + assignment_expr: &hir::Expr<'_>, + expr: &hir::Expr<'_>, mode: MutateMode) { let cmt = return_if_err!(self.mc.cat_expr(expr)); self.delegate.mutate(assignment_expr.id, span, &cmt, mode); @@ -364,7 +364,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } fn borrow_expr(&mut self, - expr: &hir::Expr, + expr: &hir::Expr<'_>, r: ty::Region<'tcx>, bk: ty::BorrowKind, cause: LoanCause) { @@ -377,11 +377,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { self.walk_expr(expr) } - fn select_from_expr(&mut self, expr: &hir::Expr) { + fn select_from_expr(&mut self, expr: &hir::Expr<'_>) { self.walk_expr(expr) } - pub fn walk_expr(&mut self, expr: &hir::Expr) { + pub fn walk_expr(&mut self, expr: &hir::Expr<'_>) { debug!("walk_expr(expr={:?})", expr); self.walk_adjustment(expr); @@ -546,7 +546,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - fn walk_callee(&mut self, call: &hir::Expr, callee: &hir::Expr) { + fn walk_callee(&mut self, call: &hir::Expr<'_>, callee: &hir::Expr<'_>) { let callee_ty = return_if_err!(self.mc.expr_ty_adjusted(callee)); debug!("walk_callee: callee={:?} callee_ty={:?}", callee, callee_ty); @@ -587,7 +587,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - fn walk_stmt(&mut self, stmt: &hir::Stmt) { + fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) { match stmt.node { hir::StmtKind::Decl(ref decl, _) => { match decl.node { @@ -609,7 +609,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - fn walk_local(&mut self, local: &hir::Local) { + fn walk_local(&mut self, local: &hir::Local<'_>) { match local.init { None => { local.pat.each_binding(|_, hir_id, span, _| { @@ -632,7 +632,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// Indicates that the value of `blk` will be consumed, meaning either copied or moved /// depending on its type. - fn walk_block(&mut self, blk: &hir::Block) { + fn walk_block(&mut self, blk: &hir::Block<'_>) { debug!("walk_block(blk.id={})", blk.id); for stmt in &blk.stmts { @@ -645,15 +645,15 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } fn walk_struct_expr(&mut self, - fields: &[hir::Field], - opt_with: &Option>) { + fields: &[hir::Field<'_>], + opt_with: &Option>>) { // Consume the expressions supplying values for each field. for field in fields { self.consume_expr(&field.expr); } let with_expr = match *opt_with { - Some(ref w) => &**w, + Some(ref w) => &***w, None => { return; } }; @@ -701,7 +701,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // Invoke the appropriate delegate calls for anything that gets // consumed or borrowed as part of the automatic adjustment // process. - fn walk_adjustment(&mut self, expr: &hir::Expr) { + fn walk_adjustment(&mut self, expr: &hir::Expr<'_>) { let adjustments = self.mc.tables.expr_adjustments(expr); let mut cmt = return_if_err!(self.mc.cat_expr_unadjusted(expr)); for adjustment in adjustments { @@ -742,7 +742,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// `expr`. `cmt_base` is the mem-categorized form of `expr` /// after all relevant autoderefs have occurred. fn walk_autoref(&mut self, - expr: &hir::Expr, + expr: &hir::Expr<'_>, cmt_base: &mc::cmt_<'tcx>, autoref: &adjustment::AutoBorrow<'tcx>) { debug!("walk_autoref(expr.id={} cmt_base={:?} autoref={:?})", @@ -784,7 +784,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } } - fn arm_move_mode(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &hir::Arm) -> TrackMatchMode { + fn arm_move_mode(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &hir::Arm<'_>) -> TrackMatchMode { let mut mode = Unknown; for pat in &arm.pats { self.determine_pat_move_mode(discr_cmt.clone(), &pat, &mut mode); @@ -792,7 +792,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { mode } - fn walk_arm(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &hir::Arm, mode: MatchMode) { + fn walk_arm(&mut self, discr_cmt: mc::cmt<'tcx>, arm: &hir::Arm<'_>, mode: MatchMode) { for pat in &arm.pats { self.walk_pat(discr_cmt.clone(), &pat, mode); } @@ -806,7 +806,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// Walks a pat that occurs in isolation (i.e., top-level of fn /// arg or let binding. *Not* a match arm or nested pat.) - fn walk_irrefutable_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat) { + fn walk_irrefutable_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat<'_>) { let mut mode = Unknown; self.determine_pat_move_mode(cmt_discr.clone(), pat, &mut mode); let mode = mode.match_mode(); @@ -818,7 +818,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// copy, or borrow. fn determine_pat_move_mode(&mut self, cmt_discr: mc::cmt<'tcx>, - pat: &hir::Pat, + pat: &hir::Pat<'_>, mode: &mut TrackMatchMode) { debug!("determine_pat_move_mode cmt_discr={:?} pat={:?}", cmt_discr, pat); @@ -844,7 +844,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// The core driver for walking a pattern; `match_mode` must be /// established up front, e.g., via `determine_pat_move_mode` (see /// also `walk_irrefutable_pat` for patterns that stand alone). - fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat, match_mode: MatchMode) { + fn walk_pat(&mut self, cmt_discr: mc::cmt<'tcx>, pat: &hir::Pat<'_>, match_mode: MatchMode) { debug!("walk_pat(cmt_discr={:?}, pat={:?})", cmt_discr, pat); let tcx = self.tcx(); @@ -921,7 +921,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { })); } - fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) { + fn walk_captures(&mut self, closure_expr: &hir::Expr<'_>, fn_decl_span: Span) { debug!("walk_captures({:?})", closure_expr); self.tcx().with_freevars(closure_expr.id, |freevars| { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index c203ea96f3d64..436d234ede6a1 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -45,6 +45,7 @@ impl LangItem { } } +#[derive(HashStable)] pub struct LanguageItems { pub items: Vec>, pub missing: Vec, diff --git a/src/librustc/middle/lib_features.rs b/src/librustc/middle/lib_features.rs index 8c23377324f1f..6ed76d14f050a 100644 --- a/src/librustc/middle/lib_features.rs +++ b/src/librustc/middle/lib_features.rs @@ -12,6 +12,7 @@ use hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_data_structures::fx::{FxHashSet, FxHashMap}; use errors::DiagnosticId; +#[derive(HashStable)] pub struct LibFeatures { // A map from feature to stabilisation version. pub stable: FxHashMap, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index a78cf1a471b4b..e961589a1b102 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -110,12 +110,12 @@ use std::io::prelude::*; use std::io; use std::rc::Rc; use syntax::ast::{self, NodeId}; -use syntax::ptr::P; use syntax::symbol::keywords; use syntax_pos::Span; use hir::{Expr, HirId}; use hir; +use hir::ptr::P; use hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap}; /// For use with `propagate_through_loop`. @@ -123,7 +123,7 @@ enum LoopKind<'a> { /// An endless `loop` loop. LoopLoop, /// A `while` loop, with the given expression as condition. - WhileLoop(&'a Expr), + WhileLoop(&'a Expr<'a>), } #[derive(Copy, Clone, PartialEq)] @@ -947,7 +947,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { if blk.targeted_by_break { self.break_ln.insert(blk.id, succ); } - let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ); + let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &***e), succ); blk.stmts.iter().rev().fold(succ, |succ, stmt| { self.propagate_through_stmt(stmt, succ) }) @@ -992,7 +992,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // initialization, which is mildly more complex than checking // once at the func header but otherwise equivalent. - let succ = self.propagate_through_opt_expr(local.init.as_ref().map(|e| &**e), succ); + let succ = self.propagate_through_opt_expr(local.init.as_ref().map(|e| &***e), succ); self.define_bindings_in_pat(&local.pat, succ) } @@ -1064,7 +1064,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // v v // ( succ ) // - let else_ln = self.propagate_through_opt_expr(els.as_ref().map(|e| &**e), succ); + let else_ln = self.propagate_through_opt_expr(els.as_ref().map(|e| &***e), succ); let then_ln = self.propagate_through_expr(&then, succ); let ln = self.live_node(expr.hir_id, expr.span); self.init_from_succ(ln, else_ln); @@ -1104,14 +1104,14 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let body_succ = self.propagate_through_expr(&arm.body, succ); let guard_succ = self.propagate_through_opt_expr( - arm.guard.as_ref().map(|hir::Guard::If(e)| &**e), + arm.guard.as_ref().map(|hir::Guard::If(e)| &***e), body_succ ); // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoritative" set of ids let arm_succ = - self.define_bindings_in_arm_pats(arm.pats.first().map(|p| &**p), + self.define_bindings_in_arm_pats(arm.pats.first().map(|p| &***p), guard_succ); self.merge_from_succ(ln, arm_succ, first_merge); first_merge = false; @@ -1122,7 +1122,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hir::ExprKind::Ret(ref o_e) => { // ignore succ and subst exit_ln: let exit_ln = self.s.exit_ln; - self.propagate_through_opt_expr(o_e.as_ref().map(|e| &**e), exit_ln) + self.propagate_through_opt_expr(o_e.as_ref().map(|e| &***e), exit_ln) } hir::ExprKind::Break(label, ref opt_expr) => { @@ -1136,7 +1136,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // look it up in the break loop nodes table match target { - Some(b) => self.propagate_through_opt_expr(opt_expr.as_ref().map(|e| &**e), b), + Some(b) => self.propagate_through_opt_expr(opt_expr.as_ref().map(|e| &***e), b), None => span_bug!(expr.span, "break to unknown label") } } @@ -1181,7 +1181,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::Struct(_, ref fields, ref with_expr) => { - let succ = self.propagate_through_opt_expr(with_expr.as_ref().map(|e| &**e), succ); + let succ = self.propagate_through_opt_expr(with_expr.as_ref().map(|e| &***e), succ); fields.iter().rev().fold(succ, |succ, field| { self.propagate_through_expr(&field.expr, succ) }) @@ -1475,7 +1475,7 @@ fn check_arm<'a, 'tcx>(this: &mut Liveness<'a, 'tcx>, arm: &'tcx hir::Arm) { // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoritative" set of ids - this.arm_pats_bindings(arm.pats.first().map(|p| &**p), |this, ln, var, sp, id| { + this.arm_pats_bindings(arm.pats.first().map(|p| &***p), |this, ln, var, sp, id| { this.warn_about_unused(sp, id, ln, var); }); intravisit::walk_arm(this, arm); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 370f0d1a6c6d7..d42bffbdcd021 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -275,12 +275,12 @@ pub trait HirNode { fn span(&self) -> Span; } -impl HirNode for hir::Expr { +impl HirNode for hir::Expr<'_> { fn hir_id(&self) -> hir::HirId { self.hir_id } fn span(&self) -> Span { self.span } } -impl HirNode for hir::Pat { +impl HirNode for hir::Pat<'_> { fn hir_id(&self) -> hir::HirId { self.hir_id } fn span(&self) -> Span { self.span } } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 7736d5e795ea0..94ff24a883014 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -9,7 +9,7 @@ use std::fmt; use syntax::ast::NodeId; // Accessibility levels, sorted in ascending order -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, HashStable)] pub enum AccessLevel { // Superset of Reachable used to mark impl Trait items. ReachableFromImplTrait, diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 10deca836fff3..e03cf40d0b554 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -384,7 +384,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, // We introduce a new-type here, so we can have a specialized HashStable // implementation for it. -#[derive(Clone)] +#[derive(Clone, HashStable)] pub struct ReachableSet(pub Lrc); fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) -> ReachableSet { diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index ce2a348950622..5395e3e6869e6 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -90,7 +90,8 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, /// placate the same deriving in `ty::FreeRegion`, but we may want to /// actually attach a more meaningful ordering to scopes than the one /// generated via deriving here. -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, + RustcEncodable, RustcDecodable, HashStable)] pub struct Scope { pub id: hir::ItemLocalId, pub data: ScopeData, @@ -113,7 +114,8 @@ impl fmt::Debug for Scope { } } -#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, + RustcEncodable, RustcDecodable, HashStable)] pub enum ScopeData { Node, @@ -1311,7 +1313,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionResolutionVisitor<'a, 'tcx> { resolve_expr(self, ex); } fn visit_local(&mut self, l: &'tcx Local) { - resolve_local(self, Some(&l.pat), l.init.as_ref().map(|e| &**e)); + resolve_local(self, Some(&l.pat), l.init.as_ref().map(|e| &***e)); } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 2d3653464d538..7c4f8877f4b17 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -8,6 +8,7 @@ use hir::def::Def; use hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use hir::map::Map; +use hir::ptr::P; use hir::{GenericArg, GenericParam, ItemLocalId, LifetimeName, Node, ParamName}; use ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; @@ -20,7 +21,6 @@ use std::cell::Cell; use std::mem::replace; use syntax::ast; use syntax::attr; -use syntax::ptr::P; use syntax::symbol::keywords; use syntax_pos::Span; use util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet}; @@ -31,7 +31,7 @@ use hir::{self, GenericParamKind, LifetimeParamKind}; /// The origin of a named lifetime definition. /// /// This is used to prevent the usage of in-band lifetimes in `Fn`/`fn` syntax. -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum LifetimeDefOrigin { // Explicit binders like `fn foo<'a>(x: &'a u8)` or elided like `impl Foo<&u32>` ExplicitOrElided, @@ -62,7 +62,7 @@ pub enum LifetimeUseSet<'tcx> { Many, } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Region { Static, EarlyBound( @@ -161,7 +161,7 @@ impl Region { /// A set containing, at most, one known element. /// If two distinct values are inserted into a set, then it /// becomes `Many`, which can be used to detect ambiguities. -#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum Set1 { Empty, One(T), @@ -473,7 +473,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { replace(&mut self.labels_in_fn, saved); } - fn visit_item(&mut self, item: &'tcx hir::Item) { + fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { match item.node { hir::ItemKind::Fn(ref decl, _, ref generics, _) => { self.visit_early_late(None, decl, generics, |this| { @@ -558,7 +558,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) { + fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) { match item.node { hir::ForeignItemKind::Fn(ref decl, _, ref generics) => { self.visit_early_late(None, decl, generics, |this| { @@ -574,7 +574,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_ty(&mut self, ty: &'tcx hir::Ty) { + fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) { debug!("visit_ty: id={:?} ty={:?}", ty.id, ty); match ty.node { hir::TyKind::BareFn(ref c) => { @@ -774,7 +774,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) { use self::hir::TraitItemKind::*; match trait_item.node { Method(ref sig, _) => { @@ -829,7 +829,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) { use self::hir::ImplItemKind::*; match impl_item.node { Method(ref sig, _) => { @@ -924,7 +924,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { self.resolve_lifetime_ref(lifetime_ref); } - fn visit_path(&mut self, path: &'tcx hir::Path, _: hir::HirId) { + fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, _: hir::HirId) { for (i, segment) in path.segments.iter().enumerate() { let depth = path.segments.len() - i - 1; if let Some(ref args) = segment.args { @@ -933,7 +933,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } } - fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl) { + fn visit_fn_decl(&mut self, fd: &'tcx hir::FnDecl<'tcx>) { let output = match fd.output { hir::DefaultReturn(_) => None, hir::Return(ref ty) => Some(ty), @@ -941,7 +941,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { self.visit_fn_like_elision(&fd.inputs, output); } - fn visit_generics(&mut self, generics: &'tcx hir::Generics) { + fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) { check_mixed_explicit_and_in_band_defs(self.tcx, &generics.params); for param in &generics.params { match param.kind { diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 7ed29c5afd03f..2f80431cfc430 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -15,7 +15,7 @@ use rustc_target::abi::HasDataLayout; /// Used by `check_bounds` to indicate whether the pointer needs to be just inbounds /// or also inbounds of a *live* allocation. -#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable)] +#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum InboundsCheck { Live, MaybeDead, diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index c3fe5d773ab16..69063f6cb8921 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -17,7 +17,7 @@ use syntax_pos::{Pos, Span}; use syntax::ast; use syntax::symbol::Symbol; -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, HashStable)] pub enum ErrorHandled { /// Already reported a lint or an error for this evaluation Reported, @@ -46,7 +46,7 @@ pub struct ConstEvalErr<'tcx> { pub stacktrace: Vec>, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct FrameInfo<'tcx> { pub call_site: Span, // this span is in the caller! pub instance: ty::Instance<'tcx>, @@ -209,7 +209,7 @@ impl<'tcx> From> for EvalError<'tcx> { pub type AssertMessage<'tcx> = EvalErrorKind<'tcx, mir::Operand<'tcx>>; -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum EvalErrorKind<'tcx, O> { /// This variant is used by machines to signal their own errors that do not /// match an existing variant diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index e6a560b2ad7b6..26010a1173a90 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -40,7 +40,7 @@ use std::sync::atomic::{AtomicU32, Ordering}; use std::num::NonZeroU32; /// Uniquely identifies a specific constant or static. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct GlobalId<'tcx> { /// For a constant or static, the `Instance` of the item itself. /// For a promoted global, the `Instance` of the function they belong to. @@ -258,7 +258,7 @@ impl fmt::Display for AllocId { } } -#[derive(Debug, Clone, Eq, PartialEq, Hash, RustcDecodable, RustcEncodable)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, RustcDecodable, RustcEncodable, HashStable)] pub enum AllocKind<'tcx> { /// The alloc id is used as a function pointer Function(Instance<'tcx>), diff --git a/src/librustc/mir/interpret/pointer.rs b/src/librustc/mir/interpret/pointer.rs index a046825f088bb..8d47b9b54c54a 100644 --- a/src/librustc/mir/interpret/pointer.rs +++ b/src/librustc/mir/interpret/pointer.rs @@ -69,7 +69,8 @@ impl PointerArithmetic for T {} /// /// Pointer is also generic over the `Tag` associated with each pointer, /// which is used to do provenance tracking during execution. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, + RustcEncodable, RustcDecodable, Hash, HashStable)] pub struct Pointer { pub alloc_id: Id, pub offset: Size, diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 76eb43e73d166..064b6957167e7 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -5,7 +5,7 @@ use crate::ty::{Ty, layout::{HasDataLayout, Size}}; use super::{EvalResult, Pointer, PointerArithmetic, Allocation, AllocId, sign_extend, truncate}; /// Represents the result of a raw const operation, pre-validation. -#[derive(Copy, Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable, Hash, HashStable)] pub struct RawConst<'tcx> { // the value lives here, at offset 0, and that allocation definitely is a `AllocKind::Memory` // (so you can use `AllocMap::unwrap_memory`). @@ -15,7 +15,8 @@ pub struct RawConst<'tcx> { /// Represents a constant value in Rust. Scalar and ScalarPair are optimizations which /// matches the LocalValue optimizations for easy conversions between Value and ConstValue. -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, + RustcEncodable, RustcDecodable, Hash, HashStable)] pub enum ConstValue<'tcx> { /// Used only for types with layout::abi::Scalar ABI and ZSTs /// @@ -74,7 +75,8 @@ impl<'tcx> ConstValue<'tcx> { /// `memory::Allocation`. It is in many ways like a small chunk of a `Allocation`, up to 8 bytes in /// size. Like a range of bytes in an `Allocation`, a `Scalar` can either represent the raw bytes /// of a simple value or a pointer into another `Allocation` -#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, RustcEncodable, RustcDecodable, Hash)] +#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, + RustcEncodable, RustcDecodable, Hash, HashStable)] pub enum Scalar { /// The raw bytes of a simple value. Bits { diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index a1a6e890b1292..9bf46609e8117 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -405,7 +405,7 @@ impl<'tcx> Mir<'tcx> { } } -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum Safety { Safe, /// Unsafe because of a PushUnsafeBlock @@ -451,7 +451,7 @@ impl<'tcx> IndexMut for Mir<'tcx> { } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum ClearCrossCrate { Clear, Set(T), @@ -472,7 +472,7 @@ impl serialize::UseSpecializedDecodable for ClearCrossC /// Grouped information about the source code origin of a MIR entity. /// Intended to be inspected by diagnostics and debuginfo. /// Most passes can work with it as a whole, within a single function. -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, HashStable)] pub struct SourceInfo { /// Source span for the AST pertaining to this MIR entity. pub span: Span, @@ -485,7 +485,7 @@ pub struct SourceInfo { /////////////////////////////////////////////////////////////////////////// // Mutability and borrow kinds -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum Mutability { Mut, Not, @@ -500,7 +500,8 @@ impl From for hir::Mutability { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, + Ord, RustcEncodable, RustcDecodable, HashStable)] pub enum BorrowKind { /// Data must be immutable and is aliasable. Shared, @@ -585,13 +586,14 @@ impl BorrowKind { newtype_index! { pub struct Local { + derive [HashStable] DEBUG_FORMAT = "_{}", const RETURN_PLACE = 0, } } /// Classifies locals into categories. See `Mir::local_kind`. -#[derive(PartialEq, Eq, Debug)] +#[derive(PartialEq, Eq, Debug, HashStable)] pub enum LocalKind { /// User-declared variable binding Var, @@ -721,7 +723,7 @@ impl_stable_hash_for!(struct BlockTailInfo { tail_result_is_ignored }); /// /// This can be a binding declared by the user, a temporary inserted by the compiler, a function /// argument, or the return place. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct LocalDecl<'tcx> { /// `let mut x` vs `let x`. /// @@ -977,7 +979,7 @@ impl<'tcx> LocalDecl<'tcx> { } /// A closure capture, with its name and mode. -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct UpvarDecl { pub debug_name: Name, @@ -995,6 +997,7 @@ pub struct UpvarDecl { newtype_index! { pub struct BasicBlock { + derive [HashStable] DEBUG_FORMAT = "bb{}", const START_BLOCK = 0, } @@ -1012,7 +1015,7 @@ impl BasicBlock { /////////////////////////////////////////////////////////////////////////// // BasicBlockData and Terminator -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct BasicBlockData<'tcx> { /// List of statements in this block. pub statements: Vec>, @@ -1034,13 +1037,13 @@ pub struct BasicBlockData<'tcx> { pub is_cleanup: bool, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct Terminator<'tcx> { pub source_info: SourceInfo, pub kind: TerminatorKind<'tcx>, } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum TerminatorKind<'tcx> { /// block should have one successor in the graph; we jump there Goto { target: BasicBlock }, @@ -1723,7 +1726,7 @@ impl<'tcx> TerminatorKind<'tcx> { /////////////////////////////////////////////////////////////////////////// // Statements -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct Statement<'tcx> { pub source_info: SourceInfo, pub kind: StatementKind<'tcx>, @@ -1749,7 +1752,7 @@ impl<'tcx> Statement<'tcx> { } } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum StatementKind<'tcx> { /// Write the RHS Rvalue to the LHS Place. Assign(Place<'tcx>, Box>), @@ -1808,7 +1811,7 @@ pub enum StatementKind<'tcx> { } /// `RetagKind` describes what kind of retag is to be performed. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, PartialEq, Eq, HashStable)] pub enum RetagKind { /// The initial retag when entering a function FnEntry, @@ -1821,7 +1824,7 @@ pub enum RetagKind { } /// The `FakeReadCause` describes the type of pattern why a `FakeRead` statement exists. -#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug)] +#[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum FakeReadCause { /// Inject a fake read of the borrowed input at the start of each arm's /// pattern testing code. @@ -1889,7 +1892,7 @@ impl<'tcx> Debug for Statement<'tcx> { /// A path to a value; something that can be evaluated without /// changing or disturbing program state. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum Place<'tcx> { /// local variable Local(Local), @@ -1921,13 +1924,15 @@ impl_stable_hash_for!(struct Static<'tcx> { /// or `*B` or `B[index]`. Note that it is parameterized because it is /// shared between `Constant` and `Place`. See the aliases /// `PlaceProjection` etc below. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, + Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct Projection<'tcx, B, V, T> { pub base: B, pub elem: ProjectionElem<'tcx, V, T>, } -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, + Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum ProjectionElem<'tcx, V, T> { Deref, Field(Field, T), @@ -1984,6 +1989,7 @@ pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>; newtype_index! { pub struct Field { + derive [HashStable] DEBUG_FORMAT = "field[{}]" } } @@ -2085,18 +2091,19 @@ impl<'tcx> Debug for Place<'tcx> { newtype_index! { pub struct SourceScope { + derive [HashStable] DEBUG_FORMAT = "scope[{}]", const OUTERMOST_SOURCE_SCOPE = 0, } } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct SourceScopeData { pub span: Span, pub parent_scope: Option, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct SourceScopeLocalData { /// A NodeId with lint levels equivalent to this scope's lint levels. pub lint_root: ast::NodeId, @@ -2109,7 +2116,7 @@ pub struct SourceScopeLocalData { /// These are values that can appear inside an rvalue. They are intentionally /// limited to prevent rvalues from being nested in one another. -#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, HashStable)] pub enum Operand<'tcx> { /// Copy: The value must be available for use afterwards. /// @@ -2171,7 +2178,7 @@ impl<'tcx> Operand<'tcx> { /////////////////////////////////////////////////////////////////////////// /// Rvalues -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub enum Rvalue<'tcx> { /// x (either a move or copy, depending on type of x) Use(Operand<'tcx>), @@ -2207,7 +2214,7 @@ pub enum Rvalue<'tcx> { Aggregate(Box>, Vec>), } -#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum CastKind { Misc, @@ -2228,7 +2235,7 @@ pub enum CastKind { Unsize, } -#[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum AggregateKind<'tcx> { /// The type is of the element Array(Ty<'tcx>), @@ -2251,7 +2258,7 @@ pub enum AggregateKind<'tcx> { Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability), } -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum BinOp { /// The `+` operator (addition) Add, @@ -2299,7 +2306,7 @@ impl BinOp { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum NullOp { /// Return the size of a value of that type SizeOf, @@ -2307,7 +2314,7 @@ pub enum NullOp { Box, } -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum UnOp { /// The `!` operator for logical inversion Not, @@ -2447,7 +2454,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { /// this does not necessarily mean that they are "==" in Rust -- in /// particular one must be wary of `NaN`! -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct Constant<'tcx> { pub span: Span, pub ty: Ty<'tcx>, @@ -2494,7 +2501,7 @@ pub struct Constant<'tcx> { /// The first will lead to the constraint `w: &'1 str` (for some /// inferred region `'1`). The second will lead to the constraint `w: /// &'static str`. -#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UserTypeProjections<'tcx> { pub(crate) contents: Vec<(UserTypeProjection<'tcx>, Span)>, } @@ -2580,7 +2587,7 @@ impl<'tcx> UserTypeProjections<'tcx> { /// * `let (x, _): T = ...` -- here, the `projs` vector would contain /// `field[0]` (aka `.0`), indicating that the type of `s` is /// determined by finding the type of the `.0` field from `T`. -#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UserTypeProjection<'tcx> { pub base: UserTypeAnnotationIndex, pub projs: Vec>, @@ -2650,6 +2657,7 @@ impl<'tcx> TypeFoldable<'tcx> for UserTypeProjection<'tcx> { newtype_index! { pub struct Promoted { + derive [HashStable] DEBUG_FORMAT = "promoted[{}]" } } @@ -2774,7 +2782,7 @@ impl<'a, 'b> graph::GraphSuccessors<'b> for Mir<'a> { type Iter = iter::Cloned>; } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, HashStable)] pub struct Location { /// the location is within this block pub block: BasicBlock, @@ -2846,7 +2854,7 @@ impl Location { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum UnsafetyViolationKind { General, /// Permitted in const fn and regular fns @@ -2855,7 +2863,7 @@ pub enum UnsafetyViolationKind { BorrowPacked(ast::NodeId), } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UnsafetyViolation { pub source_info: SourceInfo, pub description: InternedString, @@ -2863,7 +2871,7 @@ pub struct UnsafetyViolation { pub kind: UnsafetyViolationKind, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UnsafetyCheckResult { /// Violations that are propagated *upwards* from this function pub violations: Lrc<[UnsafetyViolation]>, @@ -2873,12 +2881,12 @@ pub struct UnsafetyCheckResult { } /// The layout of generator state -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct GeneratorLayout<'tcx> { pub fields: Vec>, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct BorrowCheckResult<'gcx> { pub closure_requirements: Option>, pub used_mut_upvars: SmallVec<[Field; 8]>, @@ -2934,7 +2942,7 @@ pub struct BorrowCheckResult<'gcx> { /// that case because the regions must be allocated in the global /// TyCtxt, and hence we cannot use `ReVar` (which is what we use /// internally within the rest of the NLL code). -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct ClosureRegionRequirements<'gcx> { /// The number of external regions defined on the closure. In our /// example above, it would be 3 -- one for `'static`, then `'1` @@ -2950,7 +2958,7 @@ pub struct ClosureRegionRequirements<'gcx> { /// Indicates an outlives constraint between a type or between two /// free-regions declared on the closure. -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct ClosureOutlivesRequirement<'tcx> { // This region or type ... pub subject: ClosureOutlivesSubject<'tcx>, @@ -2970,7 +2978,8 @@ pub struct ClosureOutlivesRequirement<'tcx> { /// order of the category, thereby influencing diagnostic output. /// /// See also [rustc_mir::borrow_check::nll::constraints] -#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, + Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum ConstraintCategory { Return, Yield, @@ -3007,7 +3016,7 @@ pub enum ConstraintCategory { /// The subject of a ClosureOutlivesRequirement -- that is, the thing /// that must outlive some region. -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum ClosureOutlivesSubject<'tcx> { /// Subject is a type, typically a type parameter, but could also /// be a projection. Indicates a requirement like `T: 'a` being diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index ba09480f93f3d..b9d30710df6aa 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -1359,7 +1359,7 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) { handler.emit(&MultiSpan::new(), msg, errors::Level::Warning); } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, HashStable)] pub enum CompileIncomplete { Stopped, Errored(ErrorReported), diff --git a/src/librustc/session/search_paths.rs b/src/librustc/session/search_paths.rs index 85d64b1571266..cde028f00422c 100644 --- a/src/librustc/session/search_paths.rs +++ b/src/librustc/session/search_paths.rs @@ -9,7 +9,7 @@ pub struct SearchPath { pub files: Vec, } -#[derive(Eq, PartialEq, Clone, Copy, Debug, PartialOrd, Ord, Hash)] +#[derive(Eq, PartialEq, Clone, Copy, Debug, PartialOrd, Ord, Hash, HashStable)] pub enum PathKind { Native, Crate, diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 7ce5960b9b3d6..97f3d683677a6 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -973,12 +973,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { (self.tcx.sess.source_map().def_span(span), self.tcx.hir().body(id).arguments.iter() .map(|arg| { if let hir::Pat { - node: hir::PatKind::Tuple(args, _), + node: hir::PatKind::Tuple(ref args, _), span, .. - } = arg.pat.clone().into_inner() { + } = *arg.pat { ArgKind::Tuple( - Some(span), + Some(*span), args.iter().map(|pat| { let snippet = self.tcx.sess.source_map() .span_to_snippet(pat.span).unwrap(); diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index b42d742b7f841..bd66b8608235a 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -282,7 +282,7 @@ pub type TraitObligations<'tcx> = Vec>; /// are used for representing the trait system in the form of /// logic programming clauses. They are part of the interface /// for the chalk SLG solver. -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable)] pub enum WhereClause<'tcx> { Implemented(ty::TraitPredicate<'tcx>), ProjectionEq(ty::ProjectionPredicate<'tcx>), @@ -290,19 +290,19 @@ pub enum WhereClause<'tcx> { TypeOutlives(ty::TypeOutlivesPredicate<'tcx>), } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable)] pub enum WellFormed<'tcx> { Trait(ty::TraitPredicate<'tcx>), Ty(Ty<'tcx>), } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable)] pub enum FromEnv<'tcx> { Trait(ty::TraitPredicate<'tcx>), Ty(Ty<'tcx>), } -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable)] pub enum DomainGoal<'tcx> { Holds(WhereClause<'tcx>), WellFormed(WellFormed<'tcx>), @@ -312,13 +312,13 @@ pub enum DomainGoal<'tcx> { pub type PolyDomainGoal<'tcx> = ty::Binder>; -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub enum QuantifierKind { Universal, Existential, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub enum GoalKind<'tcx> { Implies(Clauses<'tcx>, Goal<'tcx>), And(Goal<'tcx>, Goal<'tcx>), @@ -364,7 +364,7 @@ impl<'tcx> GoalKind<'tcx> { /// This matches the definition from Page 7 of "A Proof Procedure for the Logic of Hereditary /// Harrop Formulas". -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub enum Clause<'tcx> { Implies(ProgramClause<'tcx>), ForAll(ty::Binder>), @@ -388,7 +388,7 @@ pub type Clauses<'tcx> = &'tcx List>; /// it with the reverse implication operator `:-` to emphasize the way /// that programs are actually solved (via backchaining, which starts /// with the goal to solve and proceeds from there). -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub struct ProgramClause<'tcx> { /// This goal will be considered true... pub goal: DomainGoal<'tcx>, @@ -400,7 +400,7 @@ pub struct ProgramClause<'tcx> { pub category: ProgramClauseCategory, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub enum ProgramClauseCategory { ImpliedBound, WellFormed, @@ -408,7 +408,7 @@ pub enum ProgramClauseCategory { } /// A set of clauses that we assume to be true. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub struct Environment<'tcx> { pub clauses: Clauses<'tcx>, } @@ -423,7 +423,7 @@ impl Environment<'tcx> { } /// Something (usually a goal), along with an environment. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)] pub struct InEnvironment<'tcx, G> { pub environment: Environment<'tcx>, pub goal: G, @@ -503,7 +503,7 @@ pub type SelectionResult<'tcx, T> = Result, SelectionError<'tcx>>; /// ### The type parameter `N` /// /// See explanation on `VtableImplData`. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum Vtable<'tcx, N> { /// Vtable identifying a particular impl. VtableImpl(VtableImplData<'tcx, N>), @@ -551,14 +551,14 @@ pub enum Vtable<'tcx, N> { /// is `Obligation`, as one might expect. During codegen, however, this /// is `()`, because codegen only requires a shallow resolution of an /// impl, and nested obligations are satisfied later. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableImplData<'tcx, N> { pub impl_def_id: DefId, pub substs: &'tcx Substs<'tcx>, pub nested: Vec } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableGeneratorData<'tcx, N> { pub generator_def_id: DefId, pub substs: ty::GeneratorSubsts<'tcx>, @@ -567,7 +567,7 @@ pub struct VtableGeneratorData<'tcx, N> { pub nested: Vec } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableClosureData<'tcx, N> { pub closure_def_id: DefId, pub substs: ty::ClosureSubsts<'tcx>, @@ -576,20 +576,20 @@ pub struct VtableClosureData<'tcx, N> { pub nested: Vec } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableAutoImplData { pub trait_def_id: DefId, pub nested: Vec } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableBuiltinData { pub nested: Vec } /// A vtable for some object-safe trait `Foo` automatically derived /// for the object type `Foo`. -#[derive(PartialEq, Eq, Clone, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Eq, Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableObjectData<'tcx, N> { /// `Foo` upcast to the obligation trait. This will be some supertrait of `Foo`. pub upcast_trait_ref: ty::PolyTraitRef<'tcx>, @@ -602,13 +602,13 @@ pub struct VtableObjectData<'tcx, N> { pub nested: Vec, } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableFnPointerData<'tcx, N> { pub fn_ty: Ty<'tcx>, pub nested: Vec } -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableTraitAliasData<'tcx, N> { pub alias_def_id: DefId, pub substs: &'tcx Substs<'tcx>, diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index bec45046cb93e..3b51c59c9d1f9 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -25,7 +25,7 @@ use util::common::FN_OUTPUT_NAME; /// Depending on the stage of compilation, we want projection to be /// more or less conservative. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable)] pub enum Reveal { /// At type-checking time, we refuse to project any associated /// type that is marked `default`. Non-`default` ("final") types diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index 117112c0c75f4..32653331c431b 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -44,13 +44,13 @@ use ty::subst::Substs; /// At some point, of course, `Box` should move out of the compiler, in which /// case this is analogous to transforming a struct. E.g., Box<[i32; 4]> -> /// Box<[i32]> is an `Adjust::Unsize` with the target `Box<[i32]>`. -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct Adjustment<'tcx> { pub kind: Adjust<'tcx>, pub target: Ty<'tcx>, } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum Adjust<'tcx> { /// Go from ! to any type. NeverToAny, @@ -90,7 +90,7 @@ pub enum Adjust<'tcx> { /// call, with the signature `&'a T -> &'a U` or `&'a mut T -> &'a mut U`. /// The target type is `U` in both cases, with the region and mutability /// being those shared by both the receiver and the returned reference. -#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct OverloadedDeref<'tcx> { pub region: ty::Region<'tcx>, pub mutbl: hir::Mutability, @@ -121,13 +121,13 @@ impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> { /// new code via two-phase borrows, so we try to limit where we create two-phase /// capable mutable borrows. /// See #49434 for tracking. -#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum AllowTwoPhase { Yes, No } -#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum AutoBorrowMutability { Mutable { allow_two_phase_borrow: AllowTwoPhase }, Immutable, @@ -142,7 +142,7 @@ impl From for hir::Mutability { } } -#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum AutoBorrow<'tcx> { /// Convert from T to &T. Ref(ty::Region<'tcx>, AutoBorrowMutability), @@ -157,7 +157,7 @@ pub enum AutoBorrow<'tcx> { /// This struct can be obtained via the `coerce_impl_info` query. /// Demanding this struct also has the side-effect of reporting errors /// for inappropriate impls. -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct CoerceUnsizedInfo { /// If this is a "custom coerce" impl, then what kind of custom /// coercion is it? This applies to impls of `CoerceUnsized` for @@ -166,7 +166,7 @@ pub struct CoerceUnsizedInfo { pub custom_kind: Option } -#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug)] +#[derive(Clone, Copy, RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum CustomCoerceUnsized { /// Records the index of the field being coerced. Struct(usize) diff --git a/src/librustc/ty/cast.rs b/src/librustc/ty/cast.rs index 0f067de3649bf..06c497fbf045c 100644 --- a/src/librustc/ty/cast.rs +++ b/src/librustc/ty/cast.rs @@ -32,7 +32,7 @@ pub enum CastTy<'tcx> { } /// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs) -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum CastKind { CoercionCast, PtrPtrCast, diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index c0ba4329ae05c..bb6b651900e1f 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -789,6 +789,7 @@ impl<'a, 'gcx> HashStable> for TypeckTables<'gcx> { newtype_index! { pub struct UserTypeAnnotationIndex { + derive [HashStable] DEBUG_FORMAT = "UserTypeAnnotation({})", const START_INDEX = 0, } @@ -841,7 +842,7 @@ impl CanonicalUserTypeAnnotation<'gcx> { /// A user-given type annotation attached to a constant. These arise /// from constants that are named via paths, like `Foo::::new` and /// so forth. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum UserTypeAnnotation<'tcx> { Ty(Ty<'tcx>), @@ -1026,8 +1027,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } + #[inline] + pub fn global_arena(self) -> &'gcx SyncDroplessArena { + &self.gcx.global_interners.arena + } + #[inline(always)] - pub fn hir(self) -> &'a hir_map::Map<'gcx> { + pub fn hir(self) -> &'gcx hir_map::Map<'gcx> { &self.hir_map } @@ -1138,7 +1144,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { cstore: &'tcx CrateStoreDyn, local_providers: ty::query::Providers<'tcx>, extern_providers: ty::query::Providers<'tcx>, - arenas: &'tcx mut AllArenas<'tcx>, + arenas: &'tcx AllArenas<'tcx>, + global_ctxt: &'tcx mut Option>, resolutions: ty::Resolutions, hir: hir_map::Map<'tcx>, on_disk_query_result_cache: query::OnDiskCache<'tcx>, @@ -1199,7 +1206,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { Lrc::new(StableVec::new(v))); } - arenas.global_ctxt = Some(GlobalCtxt { + *global_ctxt = Some(GlobalCtxt { sess: s, cstore, global_arenas: &arenas.global, @@ -1244,7 +1251,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { output_filenames: Arc::new(output_filenames.clone()), }); - let gcx = arenas.global_ctxt.as_ref().unwrap(); + let gcx = global_ctxt.as_ref().unwrap(); sync::assert_send_val(&gcx); diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 78b6ffaa54e17..f56c341fa60b1 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -8,13 +8,13 @@ use util::ppaux; use std::fmt; use std::iter; -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct Instance<'tcx> { pub def: InstanceDef<'tcx>, pub substs: &'tcx Substs<'tcx>, } -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum InstanceDef<'tcx> { Item(DefId), Intrinsic(DefId), diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index a2c96e7cf9f66..3791161ddd113 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -71,7 +71,7 @@ pub use self::binding::BindingMode; pub use self::binding::BindingMode::*; pub use self::context::{TyCtxt, FreeRegionInfo, GlobalArenas, AllArenas, tls, keep_local}; -pub use self::context::{Lift, TypeckTables, CtxtInterners}; +pub use self::context::{Lift, TypeckTables, CtxtInterners, GlobalCtxt}; pub use self::context::{ UserTypeAnnotationIndex, UserTypeAnnotation, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, @@ -137,7 +137,7 @@ pub struct Resolutions { pub extern_prelude: FxHashMap, } -#[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, Debug, HashStable)] pub enum AssociatedItemContainer { TraitContainer(DefId), ImplContainer(DefId), @@ -172,9 +172,10 @@ pub struct ImplHeader<'tcx> { pub predicates: Vec>, } -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, HashStable)] pub struct AssociatedItem { pub def_id: DefId, + #[stable_hasher(project(name))] pub ident: Ident, pub kind: AssociatedKind, pub vis: Visibility, @@ -186,7 +187,7 @@ pub struct AssociatedItem { pub method_has_self_argument: bool, } -#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum AssociatedKind { Const, Method, @@ -234,7 +235,7 @@ impl AssociatedItem { } } -#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Copy, RustcEncodable, RustcDecodable, HashStable)] pub enum Visibility { /// Visible everywhere (including in other crates). Public, @@ -321,7 +322,7 @@ impl Visibility { } } -#[derive(Copy, Clone, PartialEq, Eq, RustcDecodable, RustcEncodable, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, RustcDecodable, RustcEncodable, Hash, HashStable)] pub enum Variance { Covariant, // T <: T iff A <: B -- e.g., function return type Invariant, // T <: T iff B == A -- e.g., type of mutable cell @@ -335,6 +336,7 @@ pub enum Variance { /// HIR of every item in the local crate. Instead, use /// `tcx.variances_of()` to get the variance for a *particular* /// item. +#[derive(HashStable)] pub struct CrateVariancesMap { /// For each item with generics, maps to a vector of the variance /// of its generics. If an item has no generics, it will have no @@ -342,6 +344,7 @@ pub struct CrateVariancesMap { pub variances: FxHashMap>>, /// An empty vector, useful for cloning. + #[stable_hasher(ignore)] pub empty_variance: Lrc>, } @@ -724,7 +727,7 @@ impl List { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UpvarPath { pub hir_id: hir::HirId, } @@ -732,13 +735,13 @@ pub struct UpvarPath { /// Upvars do not get their own node-id. Instead, we use the pair of /// the original var id (that is, the root variable that is referenced /// by the upvar) and the id of the closure expression. -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UpvarId { pub var_path: UpvarPath, pub closure_expr_id: LocalDefId, } -#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, Copy)] +#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, Copy, HashStable)] pub enum BorrowKind { /// Data must be immutable and is aliasable. ImmBorrow, @@ -786,7 +789,7 @@ pub enum BorrowKind { /// Information describing the capture of an upvar. This is computed /// during `typeck`, specifically by `regionck`. -#[derive(PartialEq, Clone, Debug, Copy, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Clone, Debug, Copy, RustcEncodable, RustcDecodable, HashStable)] pub enum UpvarCapture<'tcx> { /// Upvar is captured by value. This is always true when the /// closure is labeled `move`, but can also be true in other cases @@ -797,7 +800,7 @@ pub enum UpvarCapture<'tcx> { ByRef(UpvarBorrow<'tcx>), } -#[derive(PartialEq, Clone, Copy, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Clone, Copy, RustcEncodable, RustcDecodable, HashStable)] pub struct UpvarBorrow<'tcx> { /// The kind of borrow: by-ref upvars have access to shared /// immutable borrows, which are not part of the normal language @@ -838,7 +841,7 @@ impl ty::EarlyBoundRegion { } } -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub enum GenericParamDefKind { Lifetime, Type { @@ -848,7 +851,7 @@ pub enum GenericParamDefKind { } } -#[derive(Clone, RustcEncodable, RustcDecodable)] +#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)] pub struct GenericParamDef { pub name: InternedString, pub def_id: DefId, @@ -895,13 +898,14 @@ pub struct GenericParamCount { /// /// The ordering of parameters is the same as in `Subst` (excluding child generics): /// `Self` (optionally), `Lifetime` params..., `Type` params... -#[derive(Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct Generics { pub parent: Option, pub parent_count: usize, pub params: Vec, /// Reverse map to the `index` field of each `GenericParamDef` + #[stable_hasher(ignore)] pub param_def_id_to_index: FxHashMap, pub has_self: bool, @@ -980,7 +984,7 @@ impl<'a, 'gcx, 'tcx> Generics { } /// Bounds on generics. -#[derive(Clone, Default)] +#[derive(Clone, Default, HashStable)] pub struct GenericPredicates<'tcx> { pub parent: Option, pub predicates: Vec<(Predicate<'tcx>, Span)>, @@ -1043,7 +1047,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum Predicate<'tcx> { /// Corresponds to `where Foo: Bar`. `Foo` here would be /// the `Self` type of the trait reference and `A`, `B`, and `C` @@ -1084,6 +1088,7 @@ pub enum Predicate<'tcx> { /// HIR of every item in the local crate. Instead, use /// `tcx.inferred_outlives_of()` to get the outlives for a *particular* /// item. +#[derive(HashStable)] pub struct CratePredicatesMap<'tcx> { /// For each struct with outlive bounds, maps to a vector of the /// predicate of its outlive bounds. If an item has no outlives @@ -1091,6 +1096,7 @@ pub struct CratePredicatesMap<'tcx> { pub predicates: FxHashMap>>>, /// An empty vector, useful for cloning. + #[stable_hasher(ignore)] pub empty_predicate: Lrc>>, } @@ -1194,7 +1200,7 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct TraitPredicate<'tcx> { pub trait_ref: TraitRef<'tcx> } @@ -1222,7 +1228,8 @@ impl<'tcx> PolyTraitPredicate<'tcx> { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, + Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct OutlivesPredicate(pub A, pub B); // `A: B` pub type PolyOutlivesPredicate = ty::Binder>; pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate, @@ -1232,7 +1239,7 @@ pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate, pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder>; pub type PolyTypeOutlivesPredicate<'tcx> = ty::Binder>; -#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct SubtypePredicate<'tcx> { pub a_is_expected: bool, pub a: Ty<'tcx>, @@ -1252,7 +1259,7 @@ pub type PolySubtypePredicate<'tcx> = ty::Binder>; /// equality between arbitrary types. Processing an instance of /// Form #2 eventually yields one of these `ProjectionPredicate` /// instances to normalize the LHS. -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct ProjectionPredicate<'tcx> { pub projection_ty: ProjectionTy<'tcx>, pub ty: Ty<'tcx>, @@ -1607,7 +1614,7 @@ pub type PlaceholderType = Placeholder; /// When type checking, we use the `ParamEnv` to track /// details about the set of where-clauses that are in scope at this /// particular point. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] pub struct ParamEnv<'tcx> { /// Obligations that the caller must satisfy. This is basically /// the set of bounds on the in-scope type parameters, translated @@ -1742,13 +1749,14 @@ impl<'a, 'gcx, T> HashStable> for ParamEnvAnd<'gcx, T> } } -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, HashStable)] pub struct Destructor { /// The def-id of the destructor method pub did: DefId, } bitflags! { + #[derive(HashStable)] pub struct AdtFlags: u32 { const NO_ADT_FLAGS = 0; const IS_ENUM = 1 << 0; @@ -1769,6 +1777,7 @@ bitflags! { } bitflags! { + #[derive(HashStable)] pub struct VariantFlags: u32 { const NO_VARIANT_FLAGS = 0; /// Indicates whether the field list of this variant is `#[non_exhaustive]`. @@ -1845,7 +1854,7 @@ impl_stable_hash_for!(struct VariantDef { flags }); -#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub enum VariantDiscr { /// Explicit value for this variant, i.e., `X = 123`. /// The `DefId` corresponds to the embedded constant. @@ -1858,9 +1867,10 @@ pub enum VariantDiscr { Relative(u32), } -#[derive(Debug)] +#[derive(Debug, HashStable)] pub struct FieldDef { pub did: DefId, + #[stable_hasher(project(name))] pub ident: Ident, pub vis: Visibility, } @@ -2494,7 +2504,8 @@ impl<'a, 'gcx, 'tcx> FieldDef { /// /// You can get the environment type of a closure using /// `tcx.closure_env_ty()`. -#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, + RustcEncodable, RustcDecodable, HashStable)] pub enum ClosureKind { // Warning: Ordering is significant here! The ordering is chosen // because the trait Fn is a subtrait of FnMut and so in turn, and @@ -3343,7 +3354,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { /// rather, you should request the vector for a specific type via /// `tcx.inherent_impls(def_id)` so as to minimize your dependencies /// (constructing this map requires touching the entire crate). -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, HashStable)] pub struct CrateInherentImpls { pub inherent_impls: DefIdMap>>, } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index b98369b62ea37..f72987f8d8a71 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -24,14 +24,15 @@ use serialize; use self::InferTy::*; use self::TyKind::*; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, + Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct TypeAndMut<'tcx> { pub ty: Ty<'tcx>, pub mutbl: hir::Mutability, } #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, - RustcEncodable, RustcDecodable, Copy)] + RustcEncodable, RustcDecodable, Copy, HashStable)] /// A "free" region `fr` can be interpreted as "some region /// at least as big as the scope `fr.scope`". pub struct FreeRegion { @@ -40,7 +41,7 @@ pub struct FreeRegion { } #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, - RustcEncodable, RustcDecodable, Copy)] + RustcEncodable, RustcDecodable, Copy, HashStable)] pub enum BoundRegion { /// An anonymous region parameter for a given fn (&T) BrAnon(u32), @@ -81,7 +82,8 @@ impl BoundRegion { /// N.B., if you change this, you'll probably want to change the corresponding /// AST structure in `libsyntax/ast.rs` as well. -#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, + RustcEncodable, RustcDecodable, HashStable)] pub enum TyKind<'tcx> { /// The primitive boolean type. Written as `bool`. Bool, @@ -301,7 +303,8 @@ static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::>() == 24); /// /// It'd be nice to split this struct into ClosureSubsts and /// GeneratorSubsts, I believe. -nmatsakis -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct ClosureSubsts<'tcx> { /// Lifetime and type parameters from the enclosing function, /// concatenated with the types of the upvars. @@ -384,7 +387,8 @@ impl<'tcx> ClosureSubsts<'tcx> { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, + RustcEncodable, RustcDecodable, HashStable)] pub struct GeneratorSubsts<'tcx> { pub substs: &'tcx Substs<'tcx>, } @@ -517,7 +521,8 @@ impl<'tcx> UpvarSubsts<'tcx> { } } -#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Debug, Copy, Clone, PartialEq, PartialOrd, Ord, Eq, Hash, + RustcEncodable, RustcDecodable, HashStable)] pub enum ExistentialPredicate<'tcx> { /// e.g., Iterator Trait(ExistentialTraitRef<'tcx>), @@ -668,7 +673,7 @@ impl<'tcx> Binder<&'tcx List>> { /// Note that a `TraitRef` introduces a level of region binding, to /// account for higher-ranked trait bounds like `T: for<'a> Foo<&'a U>` /// or higher-ranked object types. -#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct TraitRef<'tcx> { pub def_id: DefId, pub substs: &'tcx Substs<'tcx>, @@ -738,7 +743,8 @@ impl<'tcx> PolyTraitRef<'tcx> { /// /// The substitutions don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, + RustcEncodable, RustcDecodable, HashStable)] pub struct ExistentialTraitRef<'tcx> { pub def_id: DefId, pub substs: &'tcx Substs<'tcx>, @@ -911,7 +917,8 @@ impl Binder { /// Represents the projection of an associated type. In explicit UFCS /// form this would be written `>::N`. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, + Hash, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct ProjectionTy<'tcx> { /// The parameters of the associated item. pub substs: &'tcx Substs<'tcx>, @@ -956,7 +963,7 @@ impl<'a, 'tcx> ProjectionTy<'tcx> { } } -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct GenSig<'tcx> { pub yield_ty: Ty<'tcx>, pub return_ty: Ty<'tcx>, @@ -979,7 +986,8 @@ impl<'tcx> PolyGenSig<'tcx> { /// - `inputs` is the list of arguments and their modes. /// - `output` is the return type. /// - `variadic` indicates whether this is a variadic function. (only true for foreign fns) -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, + Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct FnSig<'tcx> { pub inputs_and_output: &'tcx List>, pub variadic: bool, @@ -1029,7 +1037,8 @@ impl<'tcx> PolyFnSig<'tcx> { pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder>>; -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, + Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct ParamTy { pub idx: u32, pub name: InternedString, @@ -1250,7 +1259,8 @@ impl Atom for RegionVid { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, + Hash, RustcEncodable, RustcDecodable, HashStable)] pub enum InferTy { TyVar(TyVid), IntVar(IntVid), @@ -1293,7 +1303,8 @@ impl From for BoundTy { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, + Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct ExistentialProjection<'tcx> { pub item_def_id: DefId, pub substs: &'tcx Substs<'tcx>, @@ -2055,7 +2066,8 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { } } -#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Copy, Clone, Debug, Hash, HashStable, + RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to `Evaluated` if the /// code is monomorphic enough for that. pub enum LazyConst<'tcx> { @@ -2082,7 +2094,8 @@ impl<'tcx> LazyConst<'tcx> { } /// Typed constant value. -#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)] +#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, + Eq, PartialEq, Ord, PartialOrd, HashStable)] pub struct Const<'tcx> { pub ty: Ty<'tcx>, diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 64e7af815b4bf..2909c7e534c82 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -31,7 +31,7 @@ const TAG_MASK: usize = 0b11; const TYPE_TAG: usize = 0b00; const REGION_TAG: usize = 0b01; -#[derive(Debug, RustcEncodable, RustcDecodable, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, RustcEncodable, RustcDecodable, PartialEq, Eq, PartialOrd, Ord, HashStable)] pub enum UnpackedKind<'tcx> { Lifetime(ty::Region<'tcx>), Type(Ty<'tcx>), @@ -560,7 +560,7 @@ pub type CanonicalUserSubsts<'tcx> = Canonical<'tcx, UserSubsts<'tcx>>; /// Stores the user-given substs to reach some fully qualified path /// (e.g., `::Item` or `::Item`). -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UserSubsts<'tcx> { /// The substitutions for the item as given by the user. pub substs: &'tcx Substs<'tcx>, @@ -601,7 +601,7 @@ BraceStructLiftImpl! { /// the impl (with the substs from `UserSubsts`) and apply those to /// the self-type, giving `Foo`. Finally, we unify that with /// the self-type here, which contains `?A` to be `&'static u32` -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, HashStable)] pub struct UserSelfTy<'tcx> { pub impl_def_id: DefId, pub self_ty: Ty<'tcx>, diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 37ec560d6c19f..e5dd092361d39 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -13,7 +13,10 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, use rustc_data_structures::sync::Lrc; /// A trait's definition with type information. +#[derive(HashStable)] pub struct TraitDef { + // We already have the def_path_hash below, no need to hash it twice + #[stable_hasher(ignore)] pub def_id: DefId, pub unsafety: hir::Unsafety, diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index cc0ca165053d3..4462dda64e3bf 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -22,7 +22,7 @@ pub const FN_OUTPUT_NAME: &str = "Output"; // Useful type to use with `Result<>` indicate that an error has already // been reported to the user, so no need to continue checking. -#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable)] +#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, HashStable)] pub struct ErrorReported; thread_local!(static TIME_DEPTH: Cell = Cell::new(0)); diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 04085387c37f0..f77257d383b2b 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -186,7 +186,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, dfcx_loans: &LoanDataFlow<'b, 'tcx>, move_data: &move_data::FlowedMoveData<'c, 'tcx>, all_loans: &[Loan<'tcx>], - body: &hir::Body) { + body: &hir::Body<'tcx>) { debug!("check_loans(body id={})", body.value.id); let def_id = bccx.tcx.hir().body_owner_def_id(body.id()); diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 72437e270b092..b18f17d8fb15f 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -26,8 +26,8 @@ struct GatherMoveInfo<'c, 'tcx: 'c> { /// Represents the kind of pattern #[derive(Debug, Clone, Copy)] pub enum PatternSource<'tcx> { - MatchExpr(&'tcx Expr), - LetDecl(&'tcx Local), + MatchExpr(&'tcx Expr<'tcx>), + LetDecl(&'tcx Local<'tcx>), Other, } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 66303ab71b25f..b561a275a60be 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -247,7 +247,7 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> { owner_def_id: DefId, - body: &'tcx hir::Body, + body: &'tcx hir::Body<'tcx>, used_mut_nodes: RefCell>, diff --git a/src/librustc_borrowck/borrowck/unused.rs b/src/librustc_borrowck/borrowck/unused.rs index 7340c7addb505..832679f6cf72f 100644 --- a/src/librustc_borrowck/borrowck/unused.rs +++ b/src/librustc_borrowck/borrowck/unused.rs @@ -1,11 +1,11 @@ use rustc::hir::intravisit::{Visitor, NestedVisitorMap}; use rustc::hir::{self, HirId}; +use rustc::hir::ptr::P; use rustc::lint::builtin::UNUSED_MUT; use rustc::ty; use rustc::util::nodemap::{FxHashMap, FxHashSet}; use errors::Applicability; use std::slice; -use syntax::ptr::P; use borrowck::BorrowckCtxt; diff --git a/src/librustc_codegen_llvm/Cargo.toml b/src/librustc_codegen_llvm/Cargo.toml index b711502b14b7f..ad3b788a3a432 100644 --- a/src/librustc_codegen_llvm/Cargo.toml +++ b/src/librustc_codegen_llvm/Cargo.toml @@ -14,6 +14,7 @@ cc = "1.0.1" num_cpus = "1.0" rustc-demangle = "0.1.4" rustc_llvm = { path = "../librustc_llvm" } +rustc_macros = { path = "../librustc_macros" } memmap = "0.6" [features] diff --git a/src/librustc_data_structures/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs index 359f9b7842da3..321a6f631885e 100644 --- a/src/librustc_data_structures/thin_vec.rs +++ b/src/librustc_data_structures/thin_vec.rs @@ -1,3 +1,5 @@ +use stable_hasher::{StableHasher, StableHasherResult, HashStable}; + /// A vector type optimized for cases where this size is usually 0 (cf. `SmallVector`). /// The `Option>` wrapping allows us to represent a zero sized vector with `None`, /// which uses only a single (null) pointer. @@ -47,3 +49,11 @@ impl Extend for ThinVec { } } } + +impl, CTX> HashStable for ThinVec { + fn hash_stable(&self, + hcx: &mut CTX, + hasher: &mut StableHasher) { + (**self).hash_stable(hcx, hasher) + } +} diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index bfff592a5dd49..604eb77b25191 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -4,7 +4,7 @@ use rustc::hir::lowering::lower_crate; use rustc::hir::map as hir_map; use rustc::lint; use rustc::middle::{self, reachable, resolve_lifetime, stability}; -use rustc::ty::{self, AllArenas, Resolutions, TyCtxt}; +use rustc::ty::{self, AllArenas, Resolutions, TyCtxt, GlobalCtxt}; use rustc::traits; use rustc::util::common::{install_panic_hook, time, ErrorReported}; use rustc::util::profiling::ProfileCategory; @@ -39,6 +39,7 @@ use syntax::util::lev_distance::find_best_match_for_name; use syntax::symbol::Symbol; use syntax_pos::{FileName, hygiene}; use syntax_ext; +use arena::SyncDroplessArena; use serialize::json; @@ -165,6 +166,10 @@ pub fn compile_input( ::rustc_codegen_utils::link::find_crate_name(Some(sess), &krate.attrs, input); install_panic_hook(); + let arenas = AllArenas::new(); + let hir_arenas = hir::Arenas::default(); + let mut global_ctxt = None; + let ExpansionResult { expanded_crate, defs, @@ -176,6 +181,8 @@ pub fn compile_input( sess, &cstore, krate, + &arenas.interner, + &hir_arenas, registry, &crate_name, addl_plugins, @@ -281,6 +288,7 @@ pub fn compile_input( analysis, resolutions, &mut arenas, + &mut global_ctxt, &crate_name, &outputs, |tcx, analysis, rx, result| { @@ -527,7 +535,7 @@ pub struct CompileState<'a, 'tcx: 'a> { pub out_dir: Option<&'a Path>, pub out_file: Option<&'a Path>, pub expanded_crate: Option<&'a ast::Crate>, - pub hir_crate: Option<&'a hir::Crate>, + pub hir_crate: Option<&'a hir::Crate<'tcx>>, pub hir_map: Option<&'a hir_map::Map<'tcx>>, pub resolutions: Option<&'a Resolutions>, pub analysis: Option<&'a ty::CrateAnalysis>, @@ -601,7 +609,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> { analysis: &'a ty::CrateAnalysis, resolutions: &'a Resolutions, krate: &'a ast::Crate, - hir_crate: &'a hir::Crate, + hir_crate: &'a hir::Crate<'tcx>, output_filenames: &'a OutputFilenames, crate_name: &'a str, ) -> Self { @@ -625,7 +633,7 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> { out_dir: &'a Option, out_file: &'a Option, krate: Option<&'a ast::Crate>, - hir_crate: &'a hir::Crate, + hir_crate: &'a hir::Crate<'tcx>, analysis: &'a ty::CrateAnalysis, tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_name: &'a str, @@ -711,18 +719,18 @@ fn count_nodes(krate: &ast::Crate) -> usize { // For continuing compilation after a parsed crate has been // modified -pub struct ExpansionResult { +pub struct ExpansionResult<'a> { pub expanded_crate: ast::Crate, pub defs: hir_map::Definitions, pub analysis: ty::CrateAnalysis, pub resolutions: Resolutions, - pub hir_forest: hir_map::Forest, + pub hir_forest: hir_map::Forest<'a>, } -pub struct InnerExpansionResult<'a> { +pub struct InnerExpansionResult<'a, 'b> { pub expanded_crate: ast::Crate, pub resolver: Resolver<'a>, - pub hir_forest: hir_map::Forest, + pub hir_forest: hir_map::Forest<'b>, } /// Run the "early phases" of the compiler: initial `cfg` processing, @@ -732,16 +740,18 @@ pub struct InnerExpansionResult<'a> { /// standard library and prelude, and name resolution. /// /// Returns `None` if we're aborting after handling -W help. -pub fn phase_2_configure_and_expand( - sess: &Session, - cstore: &CStore, +pub fn phase_2_configure_and_expand<'a, F>( + sess: &'a Session, + cstore: &'a CStore, krate: ast::Crate, + arena: &'a SyncDroplessArena, + arenas: &'a hir::Arenas, registry: Option, crate_name: &str, addl_plugins: Option>, make_glob_map: MakeGlobMap, after_expand: F, -) -> Result +) -> Result, CompileIncomplete> where F: FnOnce(&ast::Crate) -> CompileResult, { @@ -756,6 +766,8 @@ where sess, cstore, krate, + arena, + arenas, registry, crate_name, addl_plugins, @@ -798,10 +810,12 @@ where /// Same as phase_2_configure_and_expand, but doesn't let you keep the resolver /// around -pub fn phase_2_configure_and_expand_inner<'a, F>( - sess: &'a Session, - cstore: &'a CStore, +pub fn phase_2_configure_and_expand_inner<'a, 'b: 'a, F>( + sess: &'b Session, + cstore: &'b CStore, mut krate: ast::Crate, + arena: &'b SyncDroplessArena, + arenas: &'b hir::Arenas, registry: Option, crate_name: &str, addl_plugins: Option>, @@ -809,7 +823,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>( resolver_arenas: &'a ResolverArenas<'a>, crate_loader: &'a mut CrateLoader<'a>, after_expand: F, -) -> Result, CompileIncomplete> +) -> Result, CompileIncomplete> where F: FnOnce(&ast::Crate) -> CompileResult, { @@ -1132,7 +1146,15 @@ where } }; let hir_forest = time(sess, "lowering ast -> hir", || { - let hir_crate = lower_crate(sess, cstore, &dep_graph, &krate, &mut resolver); + let hir_crate = lower_crate( + sess, + cstore, + arena, + arenas, + &dep_graph, + &krate, + &mut resolver + ); if sess.opts.debugging_opts.hir_stats { hir_stats::print_hir_stats(&hir_crate); @@ -1190,7 +1212,8 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>( hir_map: hir_map::Map<'tcx>, analysis: ty::CrateAnalysis, resolutions: Resolutions, - arenas: &'tcx mut AllArenas<'tcx>, + arenas: &'tcx AllArenas<'tcx>, + global_ctxt: &'tcx mut Option>, name: &str, output_filenames: &OutputFilenames, f: F, @@ -1238,6 +1261,7 @@ where local_providers, extern_providers, arenas, + global_ctxt, resolutions, hir_map, query_result_on_disk_cache, diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index a9ec99358c1b2..52b743969d027 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -217,7 +217,8 @@ impl PpSourceMode { PpmTyped => { let control = &driver::CompileController::basic(); let codegen_backend = ::get_codegen_backend(sess); - let mut arenas = AllArenas::new(); + let arenas = AllArenas::new(); + let mut global_ctxt = None; abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend, control, sess, @@ -225,7 +226,8 @@ impl PpSourceMode { hir_map.clone(), analysis.clone(), resolutions.clone(), - &mut arenas, + &arenas, + &mut global_ctxt, id, output_filenames, |tcx, _, _, _| { @@ -1128,7 +1130,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, let control = &driver::CompileController::basic(); let codegen_backend = ::get_codegen_backend(sess); - let mut arenas = AllArenas::new(); + let arenas = AllArenas::new(); + let mut global_ctxt = None; abort_on_err(driver::phase_3_run_analysis_passes(&*codegen_backend, control, sess, @@ -1136,7 +1139,8 @@ fn print_with_analysis<'tcx, 'a: 'tcx>(sess: &'a Session, hir_map.clone(), analysis.clone(), resolutions.clone(), - &mut arenas, + &arenas, + &mut global_ctxt, crate_name, output_filenames, |tcx, _, _, _| { diff --git a/src/librustc_macros/Cargo.toml b/src/librustc_macros/Cargo.toml new file mode 100644 index 0000000000000..c5e01e9e0a76a --- /dev/null +++ b/src/librustc_macros/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "rustc_macros" +version = "0.1.0" +authors = ["The Rust Project Developers"] + +[lib] +proc-macro = true + +[dependencies] +synstructure = "0.10.1" +syn = { version = "0.15.22", features = ["full"] } +proc-macro2 = "0.4.24" +quote = "0.6.10" \ No newline at end of file diff --git a/src/librustc_macros/src/hash_stable.rs b/src/librustc_macros/src/hash_stable.rs new file mode 100644 index 0000000000000..585f5505f1fea --- /dev/null +++ b/src/librustc_macros/src/hash_stable.rs @@ -0,0 +1,87 @@ +use synstructure; +use syn::{self, Meta, NestedMeta}; +use proc_macro2::{self, Ident, Span}; + +struct Attributes { + ignore: bool, + project: Option, +} + +fn parse_attributes(field: &syn::Field) -> Attributes { + let mut attrs = Attributes { + ignore: false, + project: None, + }; + for attr in &field.attrs { + if let Ok(meta) = attr.parse_meta() { + if &meta.name().to_string() != "stable_hasher" { + continue; + } + let mut any_attr = false; + if let Meta::List(list) = meta { + for nested in list.nested.iter() { + if let NestedMeta::Meta(meta) = nested { + if &meta.name().to_string() == "ignore" { + attrs.ignore = true; + any_attr = true; + } + if &meta.name().to_string() == "project" { + if let Meta::List(list) = meta { + if let Some(nested) = list.nested.iter().next() { + if let NestedMeta::Meta(meta) = nested { + attrs.project = Some(meta.name().to_string()); + any_attr = true; + } + } + } + } + } + } + } + if !any_attr { + panic!("error parsing stable_hasher"); + } + } + } + attrs +} + +pub fn hash_stable_derive(mut s: synstructure::Structure) -> proc_macro2::TokenStream { + let generic: syn::GenericParam = parse_quote!('__ctx); + s.add_bounds(synstructure::AddBounds::Generics); + s.add_impl_generic(generic); + let body = s.each(|bi| { + let attrs = parse_attributes(bi.ast()); + if attrs.ignore { + quote!{} + } else if let Some(project) = attrs.project { + let project = Ident::new(&project, Span::call_site()); + quote!{ + &#bi.#project.hash_stable(__hcx, __hasher); + } + } else { + quote!{ + #bi.hash_stable(__hcx, __hasher); + } + } + }); + + let discriminant = match s.ast().data { + syn::Data::Enum(_) => quote! { + ::std::mem::discriminant(self).hash_stable(__hcx, __hasher); + }, + syn::Data::Struct(_) => quote! {}, + syn::Data::Union(_) => panic!("cannot derive on union"), + }; + + s.bound_impl(quote!(::rustc_data_structures::stable_hasher::HashStable + <::rustc::ich::StableHashingContext<'__ctx>>), quote!{ + fn hash_stable<__W: ::rustc_data_structures::stable_hasher::StableHasherResult>( + &self, + __hcx: &mut ::rustc::ich::StableHashingContext<'__ctx>, + __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<__W>) { + #discriminant + match *self { #body } + } + }) +} diff --git a/src/librustc_macros/src/lib.rs b/src/librustc_macros/src/lib.rs new file mode 100644 index 0000000000000..460b415c5375f --- /dev/null +++ b/src/librustc_macros/src/lib.rs @@ -0,0 +1,14 @@ +#![feature(proc_macro_hygiene)] + +#[macro_use] +extern crate syn; +#[macro_use] +extern crate synstructure; +#[macro_use] +extern crate quote; +extern crate proc_macro; +extern crate proc_macro2; + +mod hash_stable; + +decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive); diff --git a/src/librustc_metadata/index_builder.rs b/src/librustc_metadata/index_builder.rs index 3608b12aea934..0ae02f8daf69e 100644 --- a/src/librustc_metadata/index_builder.rs +++ b/src/librustc_metadata/index_builder.rs @@ -182,8 +182,8 @@ read_tuple!(A, B); read_tuple!(A, B, C); macro_rules! read_hir { - ($t:ty) => { - impl<'tcx> DepGraphRead for &'tcx $t { + ($($t:tt)*) => { + impl<'tcx> DepGraphRead for &'tcx $($t)*<'tcx> { fn read(&self, tcx: TyCtxt) { tcx.hir().read(self.id); } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index bff8015511242..230567849a6b9 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -543,9 +543,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, substs: &'tcx Substs<'tcx>, needle_fr: RegionVid, - last_segment: &'hir hir::PathSegment, + last_segment: &'hir hir::PathSegment<'hir>, counter: &mut usize, - search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>, + search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>, ) -> Option { // Did the user give explicit arguments? (e.g., `Foo<..>`) let args = last_segment.args.as_ref()?; @@ -589,8 +589,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, substs: &'tcx Substs<'tcx>, needle_fr: RegionVid, - args: &'hir hir::GenericArgs, - search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>, + args: &'hir hir::GenericArgs<'hir>, + search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty<'hir>)>, ) -> Option<&'hir hir::Lifetime> { for (kind, hir_arg) in substs.iter().zip(&args.args) { match (kind.unpack(), hir_arg) { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 727b769cf4d44..093cb0a860022 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -622,7 +622,7 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, struct ArgInfo<'gcx>(Ty<'gcx>, Option, - Option<&'gcx hir::Pat>, + Option<&'gcx hir::Pat<'gcx>>, Option); fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index ea8b2826732b4..89f67c4521c9f 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -7,7 +7,7 @@ use rustc::ty; use rustc_data_structures::indexed_vec::Idx; -impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { +impl<'tcx> Mirror<'tcx> for &'tcx hir::Block<'tcx> { type Output = Block<'tcx>; fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Block<'tcx> { @@ -42,7 +42,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, block_id: hir::ItemLocalId, - stmts: &'tcx [hir::Stmt]) + stmts: &'tcx [hir::Stmt<'tcx>]) -> Vec> { let mut result = vec![]; for (index, stmt) in stmts.iter().enumerate() { @@ -117,7 +117,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } pub fn to_expr_ref<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, - block: &'tcx hir::Block) + block: &'tcx hir::Block<'tcx>) -> ExprRef<'tcx> { let block_ty = cx.tables().node_id_to_type(block.hir_id); let temp_lifetime = cx.region_scope_tree.temporary_scope(block.hir_id.local_id); diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index eb536fbcf69bb..0ea65cbc4c6e5 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -14,7 +14,7 @@ use rustc::hir::def_id::LocalDefId; use rustc::mir::BorrowKind; use syntax_pos::Span; -impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { +impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr<'tcx> { type Output = Expr<'tcx>; fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> { @@ -69,7 +69,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { } fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, - hir_expr: &'tcx hir::Expr, + hir_expr: &'tcx hir::Expr<'tcx>, mut expr: Expr<'tcx>, adjustment: &Adjustment<'tcx>) -> Expr<'tcx> { @@ -831,7 +831,7 @@ fn user_substs_applied_to_def( fn method_callee<'a, 'gcx, 'tcx>( cx: &mut Cx<'a, 'gcx, 'tcx>, - expr: &hir::Expr, + expr: &hir::Expr<'tcx>, span: Span, overloaded_callee: Option<(DefId, &'tcx Substs<'tcx>)>, ) -> Expr<'tcx> { @@ -904,7 +904,7 @@ fn convert_arm<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, arm: &'tcx hir::Arm) } fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'tcx>, def: Def) -> ExprKind<'tcx> { let substs = cx.tables().node_substs(expr.hir_id); @@ -966,7 +966,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'tcx>, def: Def) -> ExprKind<'tcx> { let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id); @@ -1116,7 +1116,7 @@ fn bin_op(op: hir::BinOpKind) -> BinOp { } fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'tcx>, args: Vec>) -> ExprKind<'tcx> { let fun = method_callee(cx, expr, expr.span, None); @@ -1130,7 +1130,7 @@ fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, fn overloaded_place<'a, 'gcx, 'tcx>( cx: &mut Cx<'a, 'gcx, 'tcx>, - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'tcx>, place_ty: Ty<'tcx>, overloaded_callee: Option<(DefId, &'tcx Substs<'tcx>)>, args: Vec>, @@ -1177,7 +1177,7 @@ fn overloaded_place<'a, 'gcx, 'tcx>( } fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, - closure_expr: &'tcx hir::Expr, + closure_expr: &'tcx hir::Expr<'tcx>, freevar: &hir::Freevar, freevar_ty: Ty<'tcx>) -> ExprRef<'tcx> { diff --git a/src/librustc_mir/hair/cx/to_ref.rs b/src/librustc_mir/hair/cx/to_ref.rs index 1b87e4450c56e..b798ae17b8a08 100644 --- a/src/librustc_mir/hair/cx/to_ref.rs +++ b/src/librustc_mir/hair/cx/to_ref.rs @@ -1,14 +1,14 @@ use hair::*; use rustc::hir; -use syntax::ptr::P; +use rustc::hir::ptr::P; pub trait ToRef { type Output; fn to_ref(self) -> Self::Output; } -impl<'a, 'tcx: 'a> ToRef for &'tcx hir::Expr { +impl<'a, 'tcx: 'a> ToRef for &'tcx hir::Expr<'tcx> { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -16,7 +16,7 @@ impl<'a, 'tcx: 'a> ToRef for &'tcx hir::Expr { } } -impl<'a, 'tcx: 'a> ToRef for &'tcx P { +impl<'a, 'tcx: 'a> ToRef for &'tcx P<'tcx, hir::Expr<'tcx>> { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { @@ -52,7 +52,7 @@ impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx Vec } } -impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx P<[T]> +impl<'a, 'tcx: 'a, T, U> ToRef for &'tcx P<'tcx, [T]> where &'tcx T: ToRef { type Output = Vec; diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index e902423cd30fc..d9a387c520b6e 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -207,7 +207,7 @@ pub enum ExprKind<'tcx> { arms: Vec>, }, Block { - body: &'tcx hir::Block, + body: &'tcx hir::Block<'tcx>, }, Assign { lhs: ExprRef<'tcx>, @@ -302,7 +302,7 @@ pub enum ExprKind<'tcx> { #[derive(Clone, Debug)] pub enum ExprRef<'tcx> { - Hair(&'tcx hir::Expr), + Hair(&'tcx hir::Expr<'tcx>), Mirror(Box>), } diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index c104af7a7d81b..2ef57726dbe73 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -18,6 +18,7 @@ use rustc::util::common::ErrorReported; use rustc::hir::def::*; use rustc::hir::def_id::DefId; +use rustc::hir::ptr::P; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::{self, Pat, PatKind}; @@ -25,7 +26,6 @@ use smallvec::smallvec; use std::slice; use syntax::ast; -use syntax::ptr::P; use syntax_pos::{Span, DUMMY_SP, MultiSpan}; struct OuterVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> } @@ -161,8 +161,8 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { fn check_match( &self, - scrut: &hir::Expr, - arms: &'tcx [hir::Arm], + scrut: &hir::Expr<'_>, + arms: &'tcx [hir::Arm<'tcx>], source: hir::MatchSource) { for arm in arms { @@ -197,10 +197,10 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { patcx.report_inlining_errors(pat.span); have_errors = true; } - (pattern, &**pat) + (pattern, &***pat) }).collect(), arm.guard.as_ref().map(|g| match g { - hir::Guard::If(ref e) => &**e, + hir::Guard::If(ref e) => &***e, }) )).collect(); @@ -546,7 +546,7 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor, ty::BindByValue(..) => { let pat_ty = cx.tables.node_id_to_type(p.hir_id); if !pat_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, pat.span) { - check_move(p, sub.as_ref().map(|p| &**p), span_vec); + check_move(p, sub.as_ref().map(|p| &***p), span_vec); } } _ => {} diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 8991a90737c7e..aad1d3b1fbdb1 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -20,6 +20,7 @@ use rustc::ty::subst::{Substs, Kind}; use rustc::ty::layout::VariantIdx; use rustc::hir::{self, PatKind, RangeEnd}; use rustc::hir::def::{Def, CtorKind}; +use rustc::hir::ptr::P; use rustc::hir::pat_util::EnumerateAndAdjustIterator; use rustc_data_structures::indexed_vec::Idx; @@ -27,7 +28,6 @@ use rustc_data_structures::indexed_vec::Idx; use std::cmp::Ordering; use std::fmt; use syntax::ast; -use syntax::ptr::P; use syntax_pos::Span; #[derive(Clone, Debug)] diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 604b31e7167a9..ea4c33ed3d624 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -23,7 +23,7 @@ struct NodeData { } struct StatCollector<'k> { - krate: Option<&'k hir::Crate>, + krate: Option<&'k hir::Crate<'k>>, data: FxHashMap<&'static str, NodeData>, seen: FxHashSet, } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index a452bbf0c9d54..49e1e2955c430 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -375,6 +375,7 @@ impl<'a> Resolver<'a> { subclass: ImportDirectiveSubclass::ExternCrate { source: orig_name, target: ident, + no_link: attr::contains_name(&item.attrs, "no_link"), }, root_span: item.span, span: item.span, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index cf949b62a634e..5540abd2766c0 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -29,8 +29,10 @@ pub use rustc::hir::def::{Namespace, PerNS}; use self::TypeParameters::*; use self::RibKind::*; +use arena::SyncDroplessArena; + use rustc::hir::map::{Definitions, DefCollector}; -use rustc::hir::{self, PrimTy, Bool, Char, Float, Int, Uint, Str}; +use rustc::hir::{self, PrimTy, Bool, Char, Float, Int, Uint, Str, HirVec}; use rustc::middle::cstore::CrateStore; use rustc::session::Session; use rustc::lint; @@ -1645,23 +1647,25 @@ impl<'a, 'b: 'a> ty::DefIdTree for &'a Resolver<'b> { /// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that /// the resolver is no longer needed as all the relevant information is inline. -impl<'a> hir::lowering::Resolver for Resolver<'a> { +impl<'a, 'hir> hir::lowering::Resolver<'hir> for Resolver<'a> { fn resolve_hir_path( &mut self, + arena: &'hir SyncDroplessArena, path: &ast::Path, is_value: bool, - ) -> hir::Path { - self.resolve_hir_path_cb(path, is_value, + ) -> hir::Path<'hir> { + self.resolve_hir_path_cb(arena, path, is_value, |resolver, span, error| resolve_error(resolver, span, error)) } fn resolve_str_path( &mut self, + arena: &'hir SyncDroplessArena, span: Span, crate_root: Option<&str>, components: &[&str], is_value: bool - ) -> hir::Path { + ) -> hir::Path<'hir> { let segments = iter::once(keywords::PathRoot.ident()) .chain( crate_root.into_iter() @@ -1675,7 +1679,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { segments, }; - self.resolve_hir_path(&path, is_value) + self.resolve_hir_path(arena, &path, is_value) } fn get_resolution(&mut self, id: NodeId) -> Option { @@ -1696,8 +1700,13 @@ impl<'a> Resolver<'a> { /// isn't something that can be returned because it can't be made to live that long, /// and also it's a private type. Fortunately rustdoc doesn't need to know the error, /// just that an error occurred. - pub fn resolve_str_path_error(&mut self, span: Span, path_str: &str, is_value: bool) - -> Result { + pub fn resolve_str_path_error<'hir>( + &mut self, + arena: &'hir SyncDroplessArena, + span: Span, + path_str: &str, + is_value: bool + ) -> Result, ()> { use std::iter; let mut errored = false; @@ -1721,7 +1730,7 @@ impl<'a> Resolver<'a> { .collect(), } }; - let path = self.resolve_hir_path_cb(&path, is_value, |_, _, _| errored = true); + let path = self.resolve_hir_path_cb(arena, &path, is_value, |_, _, _| errored = true); if errored || path.def == Def::Err { Err(()) } else { @@ -1730,12 +1739,13 @@ impl<'a> Resolver<'a> { } /// resolve_hir_path, but takes a callback in case there was an error - fn resolve_hir_path_cb( + fn resolve_hir_path_cb<'hir, F>( &mut self, + arena: &'hir SyncDroplessArena, path: &ast::Path, is_value: bool, error_callback: F, - ) -> hir::Path + ) -> hir::Path<'hir> where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>) { let namespace = if is_value { ValueNS } else { TypeNS }; @@ -1769,7 +1779,7 @@ impl<'a> Resolver<'a> { hir::Path { span, def, - segments: segments.into(), + segments: HirVec::from_iter(arena, segments), } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c84dbd2974624..e32d224436475 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -51,6 +51,7 @@ pub enum ImportDirectiveSubclass<'a> { ExternCrate { source: Option, target: Ident, + no_link: bool, }, MacroUse, } @@ -1210,17 +1211,27 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { if is_good_import || binding.is_macro_def() { let def = binding.def(); if def != Def::Err { - if let Some(def_id) = def.opt_def_id() { - if !def_id.is_local() && def_id.krate != CrateNum::BuiltinMacros { - self.cstore.export_macros_untracked(def_id.krate); + let exp = if let NameBindingKind::Import { directive , .. } = binding.kind { + match directive.subclass { + ImportDirectiveSubclass::ExternCrate { no_link: true, .. } => false, + _ => true } + } else { + true + }; + if exp { + if let Some(def_id) = def.opt_def_id() { + if !def_id.is_local() && def_id.krate != CrateNum::BuiltinMacros { + self.cstore.export_macros_untracked(def_id.krate); + } + } + reexports.push(Export { + ident: ident.modern(), + def: def, + span: binding.span, + vis: binding.vis, + }); } - reexports.push(Export { - ident: ident.modern(), - def: def, - span: binding.span, - vis: binding.vis, - }); } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8e5eaa18b9de0..ef650f43b64a8 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -176,7 +176,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { pub fn ast_path_substs_for_ty(&self, span: Span, def_id: DefId, - item_segment: &hir::PathSegment) + item_segment: &hir::PathSegment<'gcx>) -> &'tcx Substs<'tcx> { let (substs, assoc_bindings, _) = item_segment.with_generic_args(|generic_args| { @@ -433,10 +433,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { parent_substs: &[Kind<'tcx>], has_self: bool, self_ty: Option>, - args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs>, bool), - provided_kind: impl Fn(&GenericParamDef, &GenericArg) -> Kind<'tcx>, + args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs<'gcx>>, bool), + provided_kind: impl Fn(&GenericParamDef, &GenericArg<'gcx>) -> Kind<'tcx>, inferred_kind: impl Fn(Option<&[Kind<'tcx>]>, &GenericParamDef, bool) -> Kind<'tcx>, - ) -> &'tcx Substs<'tcx> { + ) -> &'tcx Substs<'tcx> + where + 'gcx: 'b + { // Collect the segments of the path; we need to substitute arguments // for parameters throughout the entire path (wherever there are // generic parameters). @@ -549,7 +552,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { fn create_substs_for_ast_path(&self, span: Span, def_id: DefId, - generic_args: &hir::GenericArgs, + generic_args: &hir::GenericArgs<'gcx>, infer_types: bool, self_ty: Option>) -> (&'tcx Substs<'tcx>, Vec>, Option>) @@ -683,7 +686,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// If the `projections` argument is `None`, then assoc type bindings like `Foo` /// are disallowed. Otherwise, they are pushed onto the vector given. pub fn instantiate_mono_trait_ref(&self, - trait_ref: &hir::TraitRef, + trait_ref: &hir::TraitRef<'gcx>, self_ty: Ty<'tcx>) -> ty::TraitRef<'tcx> { @@ -711,7 +714,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// The given trait ref must actually be a trait. pub(super) fn instantiate_poly_trait_ref_inner(&self, - trait_ref: &hir::TraitRef, + trait_ref: &hir::TraitRef<'gcx>, self_ty: Ty<'tcx>, poly_projections: &mut Vec<(ty::PolyProjectionPredicate<'tcx>, Span)>, speculative: bool) @@ -747,7 +750,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { } pub fn instantiate_poly_trait_ref(&self, - poly_trait_ref: &hir::PolyTraitRef, + poly_trait_ref: &hir::PolyTraitRef<'gcx>, self_ty: Ty<'tcx>, poly_projections: &mut Vec<(ty::PolyProjectionPredicate<'tcx>, Span)>) -> (ty::PolyTraitRef<'tcx>, Option>) @@ -760,7 +763,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { span: Span, trait_def_id: DefId, self_ty: Ty<'tcx>, - trait_segment: &hir::PathSegment) + trait_segment: &hir::PathSegment<'gcx>) -> ty::TraitRef<'tcx> { let (substs, assoc_bindings, _) = @@ -777,7 +780,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { span: Span, trait_def_id: DefId, self_ty: Ty<'tcx>, - trait_segment: &hir::PathSegment, + trait_segment: &hir::PathSegment<'gcx>, ) -> (&'tcx Substs<'tcx>, Vec>, Option>) { debug!("create_substs_for_ast_trait_ref(trait_segment={:?})", trait_segment); @@ -934,7 +937,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { fn ast_path_to_ty(&self, span: Span, did: DefId, - item_segment: &hir::PathSegment) + item_segment: &hir::PathSegment<'gcx>) -> Ty<'tcx> { let substs = self.ast_path_substs_for_ty(span, did, item_segment); @@ -954,7 +957,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { fn conv_object_ty_poly_trait_ref(&self, span: Span, - trait_bounds: &[hir::PolyTraitRef], + trait_bounds: &[hir::PolyTraitRef<'gcx>], lifetime: &hir::Lifetime) -> Ty<'tcx> { @@ -1288,7 +1291,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { span: Span, ty: Ty<'tcx>, ty_path_def: Def, - item_segment: &hir::PathSegment) + item_segment: &hir::PathSegment<'gcx>) -> (Ty<'tcx>, Def) { let tcx = self.tcx(); @@ -1406,8 +1409,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { span: Span, opt_self_ty: Option>, item_def_id: DefId, - trait_segment: &hir::PathSegment, - item_segment: &hir::PathSegment) + trait_segment: &hir::PathSegment<'gcx>, + item_segment: &hir::PathSegment<'gcx>) -> Ty<'tcx> { let tcx = self.tcx(); @@ -1438,8 +1441,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { self.normalize_ty(span, tcx.mk_projection(item_def_id, trait_ref.substs)) } - pub fn prohibit_generics<'a, T: IntoIterator>( - &self, segments: T) -> bool { + pub fn prohibit_generics<'a, T: IntoIterator>>( + &self, + segments: T + ) -> bool + where + 'gcx: 'a + { let mut has_err = false; for segment in segments { segment.with_generic_args(|generic_args| { @@ -1618,7 +1626,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { // Check a type `Path` and convert it to a `Ty`. pub fn def_to_ty(&self, opt_self_ty: Option>, - path: &hir::Path, + path: &hir::Path<'gcx>, permit_variants: bool) -> Ty<'tcx> { let tcx = self.tcx(); @@ -1718,7 +1726,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// Parses the programmer's textual representation of a type into our /// internal notion of a type. - pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> { + pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty<'gcx>) -> Ty<'tcx> { debug!("ast_ty_to_ty(id={:?}, ast_ty={:?} ty_ty={:?})", ast_ty.id, ast_ty, ast_ty.node); @@ -1849,7 +1857,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { } pub fn ty_of_arg(&self, - ty: &hir::Ty, + ty: &hir::Ty<'gcx>, expected_ty: Option>) -> Ty<'tcx> { @@ -1865,7 +1873,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { pub fn ty_of_fn(&self, unsafety: hir::Unsafety, abi: abi::Abi, - decl: &hir::FnDecl) + decl: &hir::FnDecl<'gcx>) -> ty::PolyFnSig<'tcx> { debug!("ty_of_fn"); @@ -1973,8 +1981,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// Divides a list of general trait bounds into two groups: auto traits (e.g., Sync and Send) and /// the remaining general trait bounds. fn split_auto_traits<'a, 'b, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, - trait_bounds: &'b [hir::PolyTraitRef]) - -> (Vec, Vec<&'b hir::PolyTraitRef>) + trait_bounds: &'b [hir::PolyTraitRef<'gcx>]) + -> (Vec, Vec<&'b hir::PolyTraitRef<'gcx>>) { let (auto_traits, trait_bounds): (Vec<_>, _) = trait_bounds.iter().partition(|bound| { // Checks whether `trait_did` is an auto trait and adds it to `auto_traits` if so. @@ -1986,7 +1994,7 @@ fn split_auto_traits<'a, 'b, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, } }); - let auto_traits = auto_traits.into_iter().map(|tr| { + let auto_traits = auto_traits.into_iter().map(|tr: &'b hir::PolyTraitRef<'gcx>| { if let Def::Trait(trait_did) = tr.trait_ref.path.def { trait_did } else { diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index b66c383edb51e..b3856411d6877 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -2,6 +2,7 @@ use check::{FnCtxt, Expectation, Diverges, Needs}; use check::coercion::CoerceMany; use rustc::hir::{self, PatKind}; use rustc::hir::def::{Def, CtorKind}; +use rustc::hir::ptr::P; use rustc::hir::pat_util::EnumerateAndAdjustIterator; use rustc::infer; use rustc::infer::type_variable::TypeVariableOrigin; @@ -9,7 +10,6 @@ use rustc::traits::ObligationCauseCode; use rustc::ty::{self, Ty, TypeFoldable}; use syntax::ast; use syntax::source_map::Spanned; -use syntax::ptr::P; use syntax::util::lev_distance::find_best_match_for_name; use syntax_pos::Span; use util::nodemap::FxHashMap; @@ -704,9 +704,9 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } fn check_pat_struct(&self, - pat: &'gcx hir::Pat, - qpath: &hir::QPath, - fields: &'gcx [Spanned], + pat: &'gcx hir::Pat<'gcx>, + qpath: &hir::QPath<'gcx>, + fields: &'gcx [Spanned>], etc: bool, expected: Ty<'tcx>, def_bm: ty::BindingMode) -> Ty<'tcx> @@ -733,8 +733,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } fn check_pat_path(&self, - pat: &hir::Pat, - qpath: &hir::QPath, + pat: &hir::Pat<'gcx>, + qpath: &hir::QPath<'gcx>, expected: Ty<'tcx>) -> Ty<'tcx> { let tcx = self.tcx; @@ -768,9 +768,9 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } fn check_pat_tuple_struct(&self, - pat: &hir::Pat, - qpath: &hir::QPath, - subpats: &'gcx [P], + pat: &hir::Pat<'gcx>, + qpath: &hir::QPath<'gcx>, + subpats: &'gcx [P<'gcx, hir::Pat<'gcx>>], ddpos: Option, expected: Ty<'tcx>, def_bm: ty::BindingMode) -> Ty<'tcx> diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index c59c143f74b62..387dad7efd918 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -445,8 +445,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { #[derive(Debug)] pub struct DeferredCallResolution<'gcx: 'tcx, 'tcx> { - call_expr: &'gcx hir::Expr, - callee_expr: &'gcx hir::Expr, + call_expr: &'gcx hir::Expr<'gcx>, + callee_expr: &'gcx hir::Expr<'gcx>, adjusted_ty: Ty<'tcx>, adjustments: Vec>, fn_sig: ty::FnSig<'tcx>, diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 38f9adee0a48f..fe3cf99038c58 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -48,7 +48,7 @@ use util::common::ErrorReported; /// Reifies a cast check to be checked once we have full type information for /// a function context. pub struct CastCheck<'tcx> { - expr: &'tcx hir::Expr, + expr: &'tcx hir::Expr<'tcx>, expr_ty: Ty<'tcx>, cast_ty: Ty<'tcx>, cast_span: Span, diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index df83c92fde5b4..f042dbd525241 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -298,8 +298,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn sig_of_closure( &self, expr_def_id: DefId, - decl: &hir::FnDecl, - body: &hir::Body, + decl: &hir::FnDecl<'gcx>, + body: &hir::Body<'gcx>, expected_sig: Option>, ) -> ClosureSignatures<'tcx> { if let Some(e) = expected_sig { @@ -314,8 +314,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn sig_of_closure_no_expectation( &self, expr_def_id: DefId, - decl: &hir::FnDecl, - body: &hir::Body, + decl: &hir::FnDecl<'gcx>, + body: &hir::Body<'gcx>, ) -> ClosureSignatures<'tcx> { debug!("sig_of_closure_no_expectation()"); @@ -374,8 +374,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn sig_of_closure_with_expectation( &self, expr_def_id: DefId, - decl: &hir::FnDecl, - body: &hir::Body, + decl: &hir::FnDecl<'gcx>, + body: &hir::Body<'gcx>, expected_sig: ExpectedSig<'tcx>, ) -> ClosureSignatures<'tcx> { debug!( @@ -432,8 +432,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn sig_of_closure_with_mismatched_number_of_arguments( &self, expr_def_id: DefId, - decl: &hir::FnDecl, - body: &hir::Body, + decl: &hir::FnDecl<'gcx>, + body: &hir::Body<'gcx>, expected_sig: ExpectedSig<'tcx>, ) -> ClosureSignatures<'tcx> { let expr_map_node = self.tcx.hir().get_if_local(expr_def_id).unwrap(); @@ -464,8 +464,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_supplied_sig_against_expectation( &self, expr_def_id: DefId, - decl: &hir::FnDecl, - body: &hir::Body, + decl: &hir::FnDecl<'gcx>, + body: &hir::Body<'gcx>, expected_sigs: &ClosureSignatures<'tcx>, ) -> InferResult<'tcx, ()> { // Get the signature S that the user gave. @@ -572,7 +572,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn supplied_sig_of_closure( &self, expr_def_id: DefId, - decl: &hir::FnDecl, + decl: &hir::FnDecl<'gcx>, ) -> ty::PolyFnSig<'tcx> { let astconv: &dyn AstConv = self; @@ -605,7 +605,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Converts the types that the user supplied, in case that doing /// so should yield an error, but returns back a signature where /// all parameters are of type `TyErr`. - fn error_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> { + fn error_sig_of_closure(&self, decl: &hir::FnDecl<'gcx>) -> ty::PolyFnSig<'tcx> { let astconv: &dyn AstConv = self; let supplied_arguments = decl.inputs.iter().map(|a| { diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index a82a0d3ce5232..16d0cf787bdaf 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -54,6 +54,7 @@ use check::{FnCtxt, Needs}; use errors::DiagnosticBuilder; use rustc::hir; use rustc::hir::def_id::DefId; +use rustc::hir::ptr::P; use rustc::infer::{Coercion, InferResult, InferOk}; use rustc::infer::type_variable::TypeVariableOrigin; use rustc::traits::{self, ObligationCause, ObligationCauseCode}; @@ -65,7 +66,6 @@ use rustc::ty::relate::RelateResult; use smallvec::{smallvec, SmallVec}; use std::ops::Deref; use syntax::feature_gate; -use syntax::ptr::P; use syntax_pos; struct Coerce<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { @@ -813,10 +813,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { cause: &ObligationCause<'tcx>, exprs: &[E], prev_ty: Ty<'tcx>, - new: &hir::Expr, + new: &hir::Expr<'gcx>, new_ty: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> - where E: AsCoercionSite + where E: AsCoercionSite<'gcx> { let prev_ty = self.resolve_type_vars_with_obligations(prev_ty); let new_ty = self.resolve_type_vars_with_obligations(new_ty); @@ -982,7 +982,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// let final_ty = coerce.complete(fcx); /// ``` pub struct CoerceMany<'gcx, 'tcx, 'exprs, E> - where 'gcx: 'tcx, E: 'exprs + AsCoercionSite, + where 'gcx: 'tcx, E: 'exprs + AsCoercionSite<'gcx>, { expected_ty: Ty<'tcx>, final_ty: Option>, @@ -992,17 +992,17 @@ pub struct CoerceMany<'gcx, 'tcx, 'exprs, E> /// The type of a `CoerceMany` that is storing up the expressions into /// a buffer. We use this in `check/mod.rs` for things like `break`. -pub type DynamicCoerceMany<'gcx, 'tcx> = CoerceMany<'gcx, 'tcx, 'gcx, P>; +pub type DynamicCoerceMany<'gcx, 'tcx> = CoerceMany<'gcx, 'tcx, 'gcx, P<'gcx, hir::Expr<'gcx>>>; enum Expressions<'gcx, 'exprs, E> - where E: 'exprs + AsCoercionSite, + where E: 'exprs + AsCoercionSite<'gcx>, { - Dynamic(Vec<&'gcx hir::Expr>), + Dynamic(Vec<&'gcx hir::Expr<'gcx>>), UpFront(&'exprs [E]), } impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> - where 'gcx: 'tcx, E: 'exprs + AsCoercionSite, + where 'gcx: 'tcx, E: 'exprs + AsCoercionSite<'gcx>, { /// The usual case; collect the set of expressions dynamically. /// If the full set of coercion sites is known before hand, @@ -1265,38 +1265,38 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> /// Something that can be converted into an expression to which we can /// apply a coercion. -pub trait AsCoercionSite { - fn as_coercion_site(&self) -> &hir::Expr; +pub trait AsCoercionSite<'gcx> { + fn as_coercion_site(&self) -> &hir::Expr<'gcx>; } -impl AsCoercionSite for hir::Expr { - fn as_coercion_site(&self) -> &hir::Expr { +impl<'gcx> AsCoercionSite<'gcx> for hir::Expr<'gcx> { + fn as_coercion_site(&self) -> &hir::Expr<'gcx> { self } } -impl AsCoercionSite for P { - fn as_coercion_site(&self) -> &hir::Expr { +impl<'gcx> AsCoercionSite<'gcx> for P<'gcx, hir::Expr<'gcx>> { + fn as_coercion_site(&self) -> &hir::Expr<'gcx> { self } } -impl<'a, T> AsCoercionSite for &'a T - where T: AsCoercionSite +impl<'gcx, 'a, T> AsCoercionSite<'gcx> for &'a T + where T: AsCoercionSite<'gcx> { - fn as_coercion_site(&self) -> &hir::Expr { + fn as_coercion_site(&self) -> &hir::Expr<'gcx> { (**self).as_coercion_site() } } -impl AsCoercionSite for ! { - fn as_coercion_site(&self) -> &hir::Expr { +impl<'gcx> AsCoercionSite<'gcx> for ! { + fn as_coercion_site(&self) -> &hir::Expr<'gcx> { unreachable!() } } -impl AsCoercionSite for hir::Arm { - fn as_coercion_site(&self) -> &hir::Expr { +impl<'gcx> AsCoercionSite<'gcx> for hir::Arm<'gcx> { + fn as_coercion_site(&self) -> &hir::Expr<'gcx> { &self.body } } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 2cf2974a45a1c..ba6ec15495262 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -20,8 +20,8 @@ use std::ops::Deref; struct ConfirmContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, span: Span, - self_expr: &'gcx hir::Expr, - call_expr: &'gcx hir::Expr, + self_expr: &'gcx hir::Expr<'gcx>, + call_expr: &'gcx hir::Expr<'gcx>, } impl<'a, 'gcx, 'tcx> Deref for ConfirmContext<'a, 'gcx, 'tcx> { @@ -40,11 +40,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn confirm_method( &self, span: Span, - self_expr: &'gcx hir::Expr, - call_expr: &'gcx hir::Expr, + self_expr: &'gcx hir::Expr<'gcx>, + call_expr: &'gcx hir::Expr<'gcx>, unadjusted_self_ty: Ty<'tcx>, pick: probe::Pick<'tcx>, - segment: &hir::PathSegment, + segment: &hir::PathSegment<'gcx>, ) -> ConfirmResult<'tcx> { debug!( "confirm(unadjusted_self_ty={:?}, pick={:?}, generic_args={:?})", @@ -61,8 +61,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { fn new(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, span: Span, - self_expr: &'gcx hir::Expr, - call_expr: &'gcx hir::Expr) + self_expr: &'gcx hir::Expr<'gcx>, + call_expr: &'gcx hir::Expr<'gcx>) -> ConfirmContext<'a, 'gcx, 'tcx> { ConfirmContext { fcx, @@ -76,7 +76,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { &mut self, unadjusted_self_ty: Ty<'tcx>, pick: probe::Pick<'tcx>, - segment: &hir::PathSegment, + segment: &hir::PathSegment<'gcx>, ) -> ConfirmResult<'tcx> { // Adjust the self expression the user provided and obtain the adjusted type. let self_ty = self.adjust_self_ty(unadjusted_self_ty, &pick); @@ -299,7 +299,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { fn instantiate_method_substs( &mut self, pick: &probe::Pick<'tcx>, - seg: &hir::PathSegment, + seg: &hir::PathSegment<'gcx>, parent_substs: &Substs<'tcx>, ) -> &'tcx Substs<'tcx> { // Determine the values for the generic parameters of the method. diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 02687df6a94fc..7429b25c3e8a5 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -176,10 +176,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// * `self_expr`: the self expression (`foo`) pub fn lookup_method(&self, self_ty: Ty<'tcx>, - segment: &hir::PathSegment, + segment: &hir::PathSegment<'gcx>, span: Span, - call_expr: &'gcx hir::Expr, - self_expr: &'gcx hir::Expr) + call_expr: &'gcx hir::Expr<'gcx>, + self_expr: &'gcx hir::Expr<'gcx>) -> Result, MethodError<'tcx>> { debug!("lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})", segment.ident, @@ -249,7 +249,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { span: Span, method_name: ast::Ident, self_ty: Ty<'tcx>, - call_expr: &'gcx hir::Expr, + call_expr: &'gcx hir::Expr<'gcx>, scope: ProbeScope) -> probe::PickResult<'tcx> { let mode = probe::Mode::MethodCall; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 23bcd88d6afb5..fb666ceb1b91c 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -676,8 +676,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { #[derive(Copy, Clone)] pub enum SelfSource<'a> { - QPath(&'a hir::Ty), - MethodCall(&'a hir::Expr /* rcvr */), + QPath(&'a hir::Ty<'a>), + MethodCall(&'a hir::Expr<'a> /* rcvr */), } #[derive(Copy, Clone)] diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1a5d164873d32..1bc85ddee939f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -90,6 +90,7 @@ use rustc::hir::def::{CtorKind, Def}; use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; use rustc::hir::itemlikevisit::ItemLikeVisitor; +use rustc::hir::ptr::P; use middle::lang_items; use namespace::Namespace; use rustc::infer::{self, InferCtxt, InferOk, InferResult, RegionVariableOrigin}; @@ -116,7 +117,6 @@ use syntax_pos::{self, BytePos, Span, MultiSpan}; use syntax::ast; use syntax::attr; use syntax::feature_gate::{GateIssue, emit_feature_err}; -use syntax::ptr::P; use syntax::source_map::{DUMMY_SP, original_sp}; use syntax::symbol::{Symbol, LocalInternedString, keywords}; use syntax::util::lev_distance::find_best_match_for_name; @@ -763,7 +763,7 @@ fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// redirecting to the owning function. fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: ast::NodeId) - -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> + -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl<'tcx>>)> { match tcx.hir().get(id) { Node::Item(item) => { @@ -2410,13 +2410,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .register_bound(self, self.param_env, ty, def_id, cause); } - pub fn to_ty(&self, ast_t: &hir::Ty) -> Ty<'tcx> { + pub fn to_ty(&self, ast_t: &hir::Ty<'gcx>) -> Ty<'tcx> { let t = AstConv::ast_ty_to_ty(self, ast_t); self.register_wf_obligation(t, ast_t.span, traits::MiscObligation); t } - pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> { + pub fn to_ty_saving_user_provided_ty(&self, ast_ty: &hir::Ty<'gcx>) -> Ty<'tcx> { let ty = self.to_ty(ast_ty); debug!("to_ty_saving_user_provided_ty: ty={:?}", ty); @@ -3269,10 +3269,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Checks a method call. fn check_method_call(&self, - expr: &'gcx hir::Expr, - segment: &hir::PathSegment, + expr: &'gcx hir::Expr<'gcx>, + segment: &hir::PathSegment<'gcx>, span: Span, - args: &'gcx [hir::Expr], + args: &'gcx [hir::Expr<'gcx>], expected: Expectation<'tcx>, needs: Needs) -> Ty<'tcx> { let rcvr = &args[0]; @@ -3756,8 +3756,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } fn check_struct_fields_on_error(&self, - fields: &'gcx [hir::Field], - base_expr: &'gcx Option>) { + fields: &'gcx [hir::Field<'gcx>], + base_expr: &'gcx Option>>) { for field in fields { self.check_expr(&field.expr); } @@ -3767,7 +3767,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } pub fn check_struct_path(&self, - qpath: &QPath, + qpath: &QPath<'gcx>, node_id: ast::NodeId) -> Option<(&'tcx ty::VariantDef, Ty<'tcx>)> { let path_span = match *qpath { @@ -3823,11 +3823,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } fn check_expr_struct(&self, - expr: &hir::Expr, + expr: &hir::Expr<'gcx>, expected: Expectation<'tcx>, - qpath: &QPath, - fields: &'gcx [hir::Field], - base_expr: &'gcx Option>) -> Ty<'tcx> + qpath: &QPath<'gcx>, + fields: &'gcx [hir::Field<'gcx>], + base_expr: &'gcx Option>>) -> Ty<'tcx> { // Find the relevant variant let (variant, adt_ty) = @@ -4303,7 +4303,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } ExprKind::If(ref cond, ref then_expr, ref opt_else_expr) => { - self.check_then_else(&cond, then_expr, opt_else_expr.as_ref().map(|e| &**e), + self.check_then_else(&cond, then_expr, opt_else_expr.as_ref().map(|e| &***e), expr.span, expected) } ExprKind::While(ref cond, ref body, _) => { @@ -4603,7 +4603,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Finish resolving a path in a struct expression or pattern `S::A { .. }` if necessary. // The newly resolved definition is written into `type_dependent_defs`. fn finish_resolving_struct_path(&self, - qpath: &QPath, + qpath: &QPath<'gcx>, path_span: Span, node_id: ast::NodeId) -> (Def, Ty<'tcx>) @@ -4637,10 +4637,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Resolve associated value path into a base type and associated constant or method definition. // The newly resolved definition is written into `type_dependent_defs`. pub fn resolve_ty_and_def_ufcs<'b>(&self, - qpath: &'b QPath, + qpath: &'b QPath<'gcx>, node_id: ast::NodeId, span: Span) - -> (Def, Option>, &'b [hir::PathSegment]) + -> (Def, Option>, &'b [hir::PathSegment<'gcx>]) { debug!("resolve_ty_and_def_ufcs: qpath={:?} node_id={:?} span={:?}", qpath, node_id, span); let (ty, qself, item_segment) = match *qpath { @@ -4930,13 +4930,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Given a function block's `NodeId`, return its `FnDecl` if it exists, or `None` otherwise. - fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, ast::Ident)> { + fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl<'gcx>, ast::Ident)> { let parent = self.tcx.hir().get(self.tcx.hir().get_parent(blk_id)); self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident)) } /// Given a function `Node`, return its `FnDecl` if it exists, or `None` otherwise. - fn get_node_fn_decl(&self, node: Node) -> Option<(hir::FnDecl, ast::Ident, bool)> { + fn get_node_fn_decl<'hir>( + &self, + node: Node<'hir> + ) -> Option<(hir::FnDecl<'hir>, ast::Ident, bool)> { match node { Node::Item(&hir::Item { ident, node: hir::ItemKind::Fn(ref decl, ..), .. @@ -4962,7 +4965,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Given a `NodeId`, return the `FnDecl` of the method it is enclosed by and whether a /// suggestion can be made, `None` otherwise. - pub fn get_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, bool)> { + pub fn get_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl<'gcx>, bool)> { // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. self.tcx.hir().get_return_block(blk_id).and_then(|blk_id| { @@ -4979,7 +4982,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn suggest_mismatched_types_on_tail( &self, err: &mut DiagnosticBuilder<'tcx>, - expression: &'gcx hir::Expr, + expression: &'gcx hir::Expr<'gcx>, expected: Ty<'tcx>, found: Ty<'tcx>, cause_span: Span, @@ -5090,7 +5093,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// type. fn suggest_missing_return_type(&self, err: &mut DiagnosticBuilder<'tcx>, - fn_decl: &hir::FnDecl, + fn_decl: &hir::FnDecl<'gcx>, expected: Ty<'tcx>, found: Ty<'tcx>, can_suggest: bool) { @@ -5171,7 +5174,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Instantiates the given path, which must refer to an item with the given // number of type parameters and type. pub fn instantiate_value_path(&self, - segments: &[hir::PathSegment], + segments: &[hir::PathSegment<'gcx>], self_ty: Option>, def: Def, span: Span, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index b90c18eb41cb5..202cc6d1ff360 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -282,7 +282,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } /// Try to resolve the type for the given node. - pub fn resolve_expr_type_adjusted(&mut self, expr: &hir::Expr) -> Ty<'tcx> { + pub fn resolve_expr_type_adjusted(&mut self, expr: &hir::Expr<'gcx>) -> Ty<'tcx> { let ty = self.tables.borrow().expr_ty_adjusted(expr); self.resolve_type(ty) } @@ -454,7 +454,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { fn visit_fn( &mut self, fk: intravisit::FnKind<'gcx>, - _: &'gcx hir::FnDecl, + _: &'gcx hir::FnDecl<'gcx>, body_id: hir::BodyId, span: Span, id: ast::NodeId, @@ -485,7 +485,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { //visit_pat: visit_pat, // (..) see above - fn visit_arm(&mut self, arm: &'gcx hir::Arm) { + fn visit_arm(&mut self, arm: &'gcx hir::Arm<'gcx>) { // see above for p in &arm.pats { self.constrain_bindings_in_pat(p); @@ -493,14 +493,14 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { intravisit::walk_arm(self, arm); } - fn visit_local(&mut self, l: &'gcx hir::Local) { + fn visit_local(&mut self, l: &'gcx hir::Local<'gcx>) { // see above self.constrain_bindings_in_pat(&l.pat); self.link_local(l); intravisit::walk_local(self, l); } - fn visit_expr(&mut self, expr: &'gcx hir::Expr) { + fn visit_expr(&mut self, expr: &'gcx hir::Expr<'gcx>) { debug!( "regionck::visit_expr(e={:?}, repeating_scope={})", expr, self.repeating_scope @@ -584,21 +584,21 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { hir::ExprKind::AssignOp(_, ref lhs, ref rhs) => { if is_method_call { - self.constrain_call(expr, Some(&lhs), Some(&**rhs).into_iter()); + self.constrain_call(expr, Some(&lhs), Some(&***rhs).into_iter()); } intravisit::walk_expr(self, expr); } hir::ExprKind::Index(ref lhs, ref rhs) if is_method_call => { - self.constrain_call(expr, Some(&lhs), Some(&**rhs).into_iter()); + self.constrain_call(expr, Some(&lhs), Some(&***rhs).into_iter()); intravisit::walk_expr(self, expr); } hir::ExprKind::Binary(_, ref lhs, ref rhs) if is_method_call => { // As `ExprKind::MethodCall`, but the call is via an overloaded op. - self.constrain_call(expr, Some(&lhs), Some(&**rhs).into_iter()); + self.constrain_call(expr, Some(&lhs), Some(&***rhs).into_iter()); intravisit::walk_expr(self, expr); } @@ -617,7 +617,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { hir::ExprKind::Unary(hir::UnDeref, ref base) => { // For *a, the lifetime of a must enclose the deref if is_method_call { - self.constrain_call(expr, Some(base), None::.iter()); + self.constrain_call(expr, Some(base), None::>.iter()); } // For overloaded derefs, base_ty is the input to `Deref::deref`, // but it's a reference type uing the same region as the output. @@ -631,7 +631,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { hir::ExprKind::Unary(_, ref lhs) if is_method_call => { // As above. - self.constrain_call(expr, Some(&lhs), None::.iter()); + self.constrain_call(expr, Some(&lhs), None::>.iter()); intravisit::walk_expr(self, expr); } @@ -717,7 +717,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { } impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { - fn constrain_cast(&mut self, cast_expr: &hir::Expr, source_expr: &hir::Expr) { + fn constrain_cast(&mut self, cast_expr: &hir::Expr<'gcx>, source_expr: &hir::Expr<'gcx>) { debug!( "constrain_cast(cast_expr={:?}, source_expr={:?})", cast_expr, source_expr @@ -729,7 +729,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { self.walk_cast(cast_expr, source_ty, target_ty); } - fn walk_cast(&mut self, cast_expr: &hir::Expr, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) { + fn walk_cast(&mut self, cast_expr: &hir::Expr<'gcx>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) { debug!("walk_cast(from_ty={:?}, to_ty={:?})", from_ty, to_ty); match (&from_ty.sty, &to_ty.sty) { /*From:*/ @@ -757,13 +757,13 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } } - fn check_expr_fn_block(&mut self, expr: &'gcx hir::Expr, body_id: hir::BodyId) { + fn check_expr_fn_block(&mut self, expr: &'gcx hir::Expr<'gcx>, body_id: hir::BodyId) { let repeating_scope = self.set_repeating_scope(body_id.node_id); intravisit::walk_expr(self, expr); self.set_repeating_scope(repeating_scope); } - fn constrain_callee(&mut self, callee_expr: &hir::Expr) { + fn constrain_callee(&mut self, callee_expr: &hir::Expr<'gcx>) { let callee_ty = self.resolve_node_type(callee_expr.hir_id); match callee_ty.sty { ty::FnDef(..) | ty::FnPtr(_) => {} @@ -779,12 +779,15 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { } } - fn constrain_call<'b, I: Iterator>( + fn constrain_call<'b, I: Iterator>>( &mut self, - call_expr: &hir::Expr, - receiver: Option<&hir::Expr>, + call_expr: &hir::Expr<'gcx>, + receiver: Option<&hir::Expr<'gcx>>, arg_exprs: I, - ) { + ) + where + 'gcx: 'b + { //! Invoked on every call site (i.e., normal calls, method calls, //! and overloaded operators). Constrains the regions which appear //! in the type of the function. Also constrains the regions that @@ -840,7 +843,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// Invoked on any adjustments that occur. Checks that if this is a region pointer being /// dereferenced, the lifetime of the pointer includes the deref expr. - fn constrain_adjustments(&mut self, expr: &hir::Expr) -> mc::McResult> { + fn constrain_adjustments(&mut self, expr: &hir::Expr<'gcx>) -> mc::McResult> { debug!("constrain_adjustments(expr={:?})", expr); let mut cmt = self.with_mc(|mc| mc.cat_expr_unadjusted(expr))?; @@ -965,7 +968,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// Invoked on any index expression that occurs. Checks that if this is a slice /// being indexed, the lifetime of the pointer includes the deref expr. - fn constrain_index(&mut self, index_expr: &hir::Expr, indexed_ty: Ty<'tcx>) { + fn constrain_index(&mut self, index_expr: &hir::Expr<'gcx>, indexed_ty: Ty<'tcx>) { debug!( "constrain_index(index_expr=?, indexed_ty={}", self.ty_to_string(indexed_ty) @@ -1043,7 +1046,12 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// Computes the guarantor for an expression `&base` and then ensures that the lifetime of the /// resulting pointer is linked to the lifetime of its guarantor (if any). - fn link_addr_of(&mut self, expr: &hir::Expr, mutability: hir::Mutability, base: &hir::Expr) { + fn link_addr_of( + &mut self, + expr: &hir::Expr<'gcx>, + mutability: hir::Mutability, + base: &hir::Expr<'gcx> + ) { debug!("link_addr_of(expr={:?}, base={:?})", expr, base); let cmt = ignore_err!(self.with_mc(|mc| mc.cat_expr(base))); @@ -1071,7 +1079,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// Computes the guarantors for any ref bindings in a match and /// then ensures that the lifetime of the resulting pointer is /// linked to the lifetime of its guarantor (if any). - fn link_match(&self, discr: &hir::Expr, arms: &[hir::Arm]) { + fn link_match(&self, discr: &hir::Expr<'gcx>, arms: &[hir::Arm<'gcx>]) { debug!("regionck::for_match()"); let discr_cmt = Rc::new(ignore_err!(self.with_mc(|mc| mc.cat_expr(discr)))); debug!("discr_cmt={:?}", discr_cmt); @@ -1132,7 +1140,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { /// autoref'd. fn link_autoref( &self, - expr: &hir::Expr, + expr: &hir::Expr<'gcx>, expr_cmt: &mc::cmt_<'tcx>, autoref: &adjustment::AutoBorrow<'tcx>, ) { diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 86165d50b27e4..d907ce9877b25 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -80,7 +80,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { closure_node_id: ast::NodeId, closure_hir_id: hir::HirId, span: Span, - body: &hir::Body, + body: &hir::Body<'gcx>, capture_clause: hir::CaptureClause, ) { /*! diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 38de936a027ff..349422086c2cd 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -79,7 +79,7 @@ struct WritebackCx<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> { tables: ty::TypeckTables<'gcx>, - body: &'gcx hir::Body, + body: &'gcx hir::Body<'gcx>, rustc_dump_user_substs: bool, } @@ -734,7 +734,7 @@ struct Resolver<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> { tcx: TyCtxt<'cx, 'gcx, 'tcx>, infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>, span: &'cx dyn Locatable, - body: &'gcx hir::Body, + body: &'gcx hir::Body<'gcx>, } impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index e0e173901ef38..a436fdbc36a08 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -159,7 +159,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { } impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { - pub fn to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> { + pub fn to_ty(&self, ast_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { AstConv::ast_ty_to_ty(self, ast_ty) } } @@ -323,7 +323,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { /// bounds for a type parameter `X` if `X::Foo` is used. fn type_parameter_bounds_in_generics( &self, - ast_generics: &hir::Generics, + ast_generics: &hir::Generics<'tcx>, param_id: ast::NodeId, ty: Ty<'tcx>, only_self_bounds: OnlySelfBounds, @@ -1581,8 +1581,8 @@ fn is_unsized<'gcx: 'tcx, 'tcx>( /// `resolve_lifetime::early_bound_lifetimes`. fn early_bound_lifetimes_from_generics<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, - generics: &'a hir::Generics, -) -> impl Iterator + Captures<'tcx> { + generics: &'a hir::Generics<'tcx>, +) -> impl Iterator> + Captures<'tcx> { generics .params .iter() @@ -1993,7 +1993,7 @@ pub enum SizedByDefault { pub fn compute_bounds<'gcx: 'tcx, 'tcx>( astconv: &dyn AstConv<'gcx, 'tcx>, param_ty: Ty<'tcx>, - ast_bounds: &[hir::GenericBound], + ast_bounds: &[hir::GenericBound<'gcx>], sized_by_default: SizedByDefault, span: Span, ) -> Bounds<'tcx> { @@ -2052,7 +2052,7 @@ pub fn compute_bounds<'gcx: 'tcx, 'tcx>( fn predicates_from_bound<'tcx>( astconv: &dyn AstConv<'tcx, 'tcx>, param_ty: Ty<'tcx>, - bound: &hir::GenericBound, + bound: &hir::GenericBound<'tcx>, ) -> Vec<(ty::Predicate<'tcx>, Span)> { match *bound { hir::GenericBound::Trait(ref tr, hir::TraitBoundModifier::None) => { @@ -2076,7 +2076,7 @@ fn predicates_from_bound<'tcx>( fn compute_sig_of_foreign_fn_decl<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - decl: &hir::FnDecl, + decl: &hir::FnDecl<'tcx>, abi: abi::Abi, ) -> ty::PolyFnSig<'tcx> { let unsafety = if abi == abi::Abi::RustIntrinsic { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index c55a1258ce955..cdc4bc4dad775 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -375,7 +375,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) /// A quasi-deprecated helper used in rustdoc and save-analysis to get /// the type from a HIR node. -pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> Ty<'tcx> { +pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> { // In case there are any projections etc, find the "environment" // def-id that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. @@ -386,8 +386,10 @@ pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty) } -pub fn hir_trait_to_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_trait: &hir::TraitRef) - -> (ty::PolyTraitRef<'tcx>, Vec<(ty::PolyProjectionPredicate<'tcx>, Span)>) { +pub fn hir_trait_to_predicates<'a, 'tcx>( + tcx: TyCtxt<'a, 'tcx, 'tcx>, + hir_trait: &hir::TraitRef<'tcx> +) -> (ty::PolyTraitRef<'tcx>, Vec<(ty::PolyProjectionPredicate<'tcx>, Span)>) { // In case there are any projections etc, find the "environment" // def-id that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. diff --git a/src/librustc_typeck/namespace.rs b/src/librustc_typeck/namespace.rs index e8f6272810a37..f873abf659c28 100644 --- a/src/librustc_typeck/namespace.rs +++ b/src/librustc_typeck/namespace.rs @@ -19,7 +19,7 @@ impl From for Namespace { } } -impl<'a> From <&'a hir::ImplItemKind> for Namespace { +impl<'a> From <&'a hir::ImplItemKind<'a>> for Namespace { fn from(impl_kind: &'a hir::ImplItemKind) -> Self { match *impl_kind { hir::ImplItemKind::Existential(..) | diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 8bac007b748ac..1902d7dc0c021 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -12,3 +12,4 @@ pulldown-cmark = { version = "0.1.2", default-features = false } minifier = "0.0.20" tempfile = "3" parking_lot = "0.6.4" +rustc_macros = { path = "../librustc_macros" } diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 27ca205720d6a..afbe9f226bf7e 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -519,9 +519,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // * Fn bounds are handled specially - instead of leaving it as 'T: Fn(), = // K', we use the dedicated syntax 'T: Fn() -> K' // * We explcitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type - fn param_env_to_generics<'b, 'c, 'cx>( + fn param_env_to_generics<'cx>( &self, - tcx: TyCtxt<'b, 'c, 'cx>, + tcx: TyCtxt<'_, 'tcx, 'cx>, did: DefId, param_env: ty::ParamEnv<'cx>, type_generics: ty::Generics, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 9cb21df713e5b..10dc02bfece1c 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -436,7 +436,7 @@ fn build_macro(cx: &DocContext, did: DefId, name: ast::Name) -> clean::ItemEnum let imported_from = cx.tcx.original_crate_name(did.krate); match cx.cstore.load_macro_untracked(did, cx.sess()) { LoadedMacro::MacroDef(def) => { - let matchers: hir::HirVec = if let ast::ItemKind::MacroDef(ref def) = def.node { + let matchers: Vec = if let ast::ItemKind::MacroDef(ref def) = def.node { let tts: Vec<_> = def.stream().into_trees().collect(); tts.chunks(4).map(|arm| arm[0].span()).collect() } else { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 37c6407fbd1c0..86b6bfe625bb5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -19,6 +19,7 @@ use rustc::middle::stability; use rustc::mir::interpret::GlobalId; use rustc::hir::{self, GenericArg, HirVec}; use rustc::hir::def::{self, Def, CtorKind}; +use rustc::hir::ptr::{P, IteratorExt}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::ty::subst::Substs; use rustc::ty::{self, TyCtxt, Region, RegionVid, Ty, AdtKind}; @@ -29,7 +30,6 @@ use syntax::ast::{self, AttrStyle, Ident}; use syntax::attr; use syntax::ext::base::MacroKind; use syntax::source_map::{dummy_spanned, Spanned}; -use syntax::ptr::P; use syntax::symbol::keywords::{self, Keyword}; use syntax::symbol::InternedString; use syntax_pos::{self, DUMMY_SP, Pos, FileName}; @@ -78,48 +78,48 @@ fn get_deprecation(cx: &DocContext, def_id: DefId) -> Option { cx.tcx.lookup_deprecation(def_id).clean(cx) } -pub trait Clean { - fn clean(&self, cx: &DocContext) -> T; +pub trait Clean<'tcx, T> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> T; } -impl, U> Clean> for [T] { - fn clean(&self, cx: &DocContext) -> Vec { +impl<'tcx, T: Clean<'tcx, U>, U> Clean<'tcx, Vec> for [T] { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Vec { self.iter().map(|x| x.clean(cx)).collect() } } -impl, U, V: Idx> Clean> for IndexVec { - fn clean(&self, cx: &DocContext) -> IndexVec { +impl<'tcx, T: Clean<'tcx, U>, U, V: Idx> Clean<'tcx, IndexVec> for IndexVec { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> IndexVec { self.iter().map(|x| x.clean(cx)).collect() } } -impl, U> Clean for P { - fn clean(&self, cx: &DocContext) -> U { +impl<'tcx, T: Clean<'tcx, U>, U> Clean<'tcx, U> for P<'_, T> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> U { (**self).clean(cx) } } -impl, U> Clean for Rc { - fn clean(&self, cx: &DocContext) -> U { +impl<'tcx, T: Clean<'tcx, U>, U> Clean<'tcx, U> for Rc { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> U { (**self).clean(cx) } } -impl, U> Clean> for Option { - fn clean(&self, cx: &DocContext) -> Option { +impl<'tcx, T: Clean<'tcx, U>, U> Clean<'tcx, Option> for Option { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Option { self.as_ref().map(|v| v.clean(cx)) } } -impl Clean for ty::Binder where T: Clean { - fn clean(&self, cx: &DocContext) -> U { +impl<'tcx, T, U> Clean<'tcx, U> for ty::Binder where T: Clean<'tcx, U> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> U { self.skip_binder().clean(cx) } } -impl, U> Clean> for P<[T]> { - fn clean(&self, cx: &DocContext) -> Vec { +impl<'tcx, T: Clean<'tcx, U>, U> Clean<'tcx, Vec> for P<'_, [T]> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Vec { self.iter().map(|x| x.clean(cx)).collect() } } @@ -138,8 +138,8 @@ pub struct Crate { pub masked_crates: FxHashSet, } -impl<'a, 'tcx, 'rcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> { - fn clean(&self, cx: &DocContext) -> Crate { +impl<'a, 'tcx, 'rcx> Clean<'tcx, Crate> for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Crate { use ::visit_lib::LibEmbargoVisitor; { @@ -227,8 +227,8 @@ pub struct ExternalCrate { pub keywords: Vec<(DefId, String, Attributes)>, } -impl Clean for CrateNum { - fn clean(&self, cx: &DocContext) -> ExternalCrate { +impl<'tcx> Clean<'tcx, ExternalCrate> for CrateNum { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> ExternalCrate { let root = DefId { krate: *self, index: CRATE_DEF_INDEX }; let krate_span = cx.tcx.def_span(root); let krate_src = cx.sess().source_map().span_to_filename(krate_span); @@ -573,8 +573,8 @@ pub struct Module { pub is_crate: bool, } -impl Clean for doctree::Module { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Module<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let name = if self.name.is_some() { self.name.expect("No name provided").clean(cx) } else { @@ -1010,8 +1010,8 @@ impl AttributesExt for Attributes { } } -impl Clean for [ast::Attribute] { - fn clean(&self, cx: &DocContext) -> Attributes { +impl<'tcx> Clean<'tcx, Attributes> for [ast::Attribute] { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Attributes { Attributes::from_ast(cx.sess().diagnostic(), self) } } @@ -1065,8 +1065,8 @@ impl GenericBound { } } -impl Clean for hir::GenericBound { - fn clean(&self, cx: &DocContext) -> GenericBound { +impl<'tcx> Clean<'tcx, GenericBound> for hir::GenericBound<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> GenericBound { match *self { hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)), hir::GenericBound::Trait(ref t, modifier) => { @@ -1130,8 +1130,8 @@ fn external_path(cx: &DocContext, name: &str, trait_did: Option, has_self } } -impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec) { - fn clean(&self, cx: &DocContext) -> GenericBound { +impl<'a, 'tcx> Clean<'tcx, GenericBound> for (&'a ty::TraitRef<'_>, Vec) { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> GenericBound { let (trait_ref, ref bounds) = *self; inline::record_extern_fqn(cx, trait_ref.def_id, TypeKind::Trait); let path = external_path(cx, &cx.tcx.item_name(trait_ref.def_id).as_str(), @@ -1174,14 +1174,14 @@ impl<'a, 'tcx> Clean for (&'a ty::TraitRef<'tcx>, Vec } } -impl<'tcx> Clean for ty::TraitRef<'tcx> { - fn clean(&self, cx: &DocContext) -> GenericBound { +impl<'tcx> Clean<'tcx, GenericBound> for ty::TraitRef<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> GenericBound { (self, vec![]).clean(cx) } } -impl<'tcx> Clean>> for Substs<'tcx> { - fn clean(&self, cx: &DocContext) -> Option> { +impl<'tcx> Clean<'tcx, Option>> for Substs<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Option> { let mut v = Vec::new(); v.extend(self.regions().filter_map(|r| r.clean(cx)).map(GenericBound::Outlives)); v.extend(self.types().map(|t| GenericBound::TraitBound(PolyTrait { @@ -1207,8 +1207,8 @@ impl Lifetime { } } -impl Clean for hir::Lifetime { - fn clean(&self, cx: &DocContext) -> Lifetime { +impl<'tcx> Clean<'tcx, Lifetime> for hir::Lifetime { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Lifetime { if self.id != ast::DUMMY_NODE_ID { let hir_id = cx.tcx.hir().node_to_hir_id(self.id); let def = cx.tcx.named_region(hir_id); @@ -1227,7 +1227,7 @@ impl Clean for hir::Lifetime { } } -impl Clean for hir::GenericParam { +impl<'tcx> Clean<'tcx, Lifetime> for hir::GenericParam<'_> { fn clean(&self, _: &DocContext) -> Lifetime { match self.kind { hir::GenericParamKind::Lifetime { .. } => { @@ -1251,14 +1251,14 @@ impl Clean for hir::GenericParam { } } -impl<'tcx> Clean for ty::GenericParamDef { +impl<'tcx> Clean<'tcx, Lifetime> for ty::GenericParamDef { fn clean(&self, _cx: &DocContext) -> Lifetime { Lifetime(self.name.to_string()) } } -impl Clean> for ty::RegionKind { - fn clean(&self, cx: &DocContext) -> Option { +impl<'tcx> Clean<'tcx, Option> for ty::RegionKind { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Option { match *self { ty::ReStatic => Some(Lifetime::statik()), ty::ReLateBound(_, ty::BrNamed(_, name)) => Some(Lifetime(name.to_string())), @@ -1283,8 +1283,8 @@ pub enum WherePredicate { EqPredicate { lhs: Type, rhs: Type }, } -impl Clean for hir::WherePredicate { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx> Clean<'tcx, WherePredicate> for hir::WherePredicate<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> WherePredicate { match *self { hir::WherePredicate::BoundPredicate(ref wbp) => { WherePredicate::BoundPredicate { @@ -1310,8 +1310,8 @@ impl Clean for hir::WherePredicate { } } -impl<'a> Clean for ty::Predicate<'a> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx, 'a> Clean<'tcx, WherePredicate> for ty::Predicate<'a> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> WherePredicate { use rustc::ty::Predicate; match *self { @@ -1329,8 +1329,8 @@ impl<'a> Clean for ty::Predicate<'a> { } } -impl<'a> Clean for ty::TraitPredicate<'a> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx, 'a> Clean<'tcx, WherePredicate> for ty::TraitPredicate<'a> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> WherePredicate { WherePredicate::BoundPredicate { ty: self.trait_ref.self_ty().clean(cx), bounds: vec![self.trait_ref.clean(cx)] @@ -1338,15 +1338,15 @@ impl<'a> Clean for ty::TraitPredicate<'a> { } } -impl<'tcx> Clean for ty::SubtypePredicate<'tcx> { +impl<'tcx> Clean<'tcx, WherePredicate> for ty::SubtypePredicate<'_> { fn clean(&self, _cx: &DocContext) -> WherePredicate { panic!("subtype predicates are an internal rustc artifact \ and should not be seen by rustdoc") } } -impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region<'tcx>> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx> Clean<'tcx, WherePredicate> for ty::OutlivesPredicate, ty::Region<'_>> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> WherePredicate { let ty::OutlivesPredicate(ref a, ref b) = *self; WherePredicate::RegionPredicate { lifetime: a.clean(cx).expect("failed to clean lifetime"), @@ -1355,8 +1355,8 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty: } } -impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region<'tcx>> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx> Clean<'tcx, WherePredicate> for ty::OutlivesPredicate, ty::Region<'_>> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> WherePredicate { let ty::OutlivesPredicate(ref ty, ref lt) = *self; WherePredicate::BoundPredicate { @@ -1366,8 +1366,8 @@ impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region< } } -impl<'tcx> Clean for ty::ProjectionPredicate<'tcx> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx> Clean<'tcx, WherePredicate> for ty::ProjectionPredicate<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> WherePredicate { WherePredicate::EqPredicate { lhs: self.projection_ty.clean(cx), rhs: self.ty.clean(cx) @@ -1375,8 +1375,8 @@ impl<'tcx> Clean for ty::ProjectionPredicate<'tcx> { } } -impl<'tcx> Clean for ty::ProjectionTy<'tcx> { - fn clean(&self, cx: &DocContext) -> Type { +impl<'tcx> Clean<'tcx, Type> for ty::ProjectionTy<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Type { let trait_ = match self.trait_ref(cx.tcx).clean(cx) { GenericBound::TraitBound(t, _) => t.trait_, GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"), @@ -1416,8 +1416,8 @@ impl GenericParamDef { } } -impl<'tcx> Clean for ty::GenericParamDef { - fn clean(&self, cx: &DocContext) -> GenericParamDef { +impl<'tcx> Clean<'tcx, GenericParamDef> for ty::GenericParamDef { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> GenericParamDef { let (name, kind) = match self.kind { ty::GenericParamDefKind::Lifetime => { (self.name.to_string(), GenericParamDefKind::Lifetime) @@ -1446,8 +1446,8 @@ impl<'tcx> Clean for ty::GenericParamDef { } } -impl Clean for hir::GenericParam { - fn clean(&self, cx: &DocContext) -> GenericParamDef { +impl<'tcx> Clean<'tcx, GenericParamDef> for hir::GenericParam<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> GenericParamDef { let (name, kind) = match self.kind { hir::GenericParamKind::Lifetime { .. } => { let name = if self.bounds.len() > 0 { @@ -1490,8 +1490,8 @@ pub struct Generics { pub where_predicates: Vec, } -impl Clean for hir::Generics { - fn clean(&self, cx: &DocContext) -> Generics { +impl<'tcx> Clean<'tcx, Generics> for hir::Generics<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Generics { // Synthetic type-parameters are inserted after normal ones. // In order for normal parameters to be able to refer to synthetic ones, // scans them first. @@ -1557,9 +1557,9 @@ impl Clean for hir::Generics { } } -impl<'a, 'tcx> Clean for (&'a ty::Generics, +impl<'a, 'tcx> Clean<'tcx, Generics> for (&'a ty::Generics, &'a Lrc>) { - fn clean(&self, cx: &DocContext) -> Generics { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Generics { use self::WherePredicate as WP; let (gens, preds) = *self; @@ -1639,10 +1639,12 @@ pub struct Method { pub header: hir::FnHeader, } -impl<'a> Clean for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId) { - fn clean(&self, cx: &DocContext) -> Method { +impl<'tcx, 'a> Clean<'tcx, Method> for (&'a hir::MethodSig<'tcx>, + &'a hir::Generics<'tcx>, + hir::BodyId) { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Method { let (generics, decl) = enter_impl_trait(cx, || { - (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)) + (self.1.clean(cx), (&**self.0.decl, self.2).clean(cx)) }); Method { decl, @@ -1666,8 +1668,8 @@ pub struct Function { pub header: hir::FnHeader, } -impl Clean for doctree::Function { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Function<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let (generics, decl) = enter_impl_trait(cx, || { (self.generics.clean(cx), (&self.decl, self.body).clean(cx)) }); @@ -1714,8 +1716,8 @@ pub struct Arguments { pub values: Vec, } -impl<'a> Clean for (&'a [hir::Ty], &'a [ast::Ident]) { - fn clean(&self, cx: &DocContext) -> Arguments { +impl<'tcx, 'a> Clean<'tcx, Arguments> for (&'a [hir::Ty<'tcx>], &'a [ast::Ident]) { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Arguments { Arguments { values: self.0.iter().enumerate().map(|(i, ty)| { let mut name = self.1.get(i).map(|ident| ident.to_string()) @@ -1732,8 +1734,8 @@ impl<'a> Clean for (&'a [hir::Ty], &'a [ast::Ident]) { } } -impl<'a> Clean for (&'a [hir::Ty], hir::BodyId) { - fn clean(&self, cx: &DocContext) -> Arguments { +impl<'tcx, 'a> Clean<'tcx, Arguments> for (&'a [hir::Ty<'tcx>], hir::BodyId) { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Arguments { let body = cx.tcx.hir().body(self.1); Arguments { @@ -1747,10 +1749,10 @@ impl<'a> Clean for (&'a [hir::Ty], hir::BodyId) { } } -impl<'a, A: Copy> Clean for (&'a hir::FnDecl, A) - where (&'a [hir::Ty], A): Clean +impl<'tcx, 'a, A: Copy> Clean<'tcx, FnDecl> for (&'a hir::FnDecl<'tcx>, A) + where (&'a [hir::Ty<'tcx>], A): Clean<'tcx, Arguments> { - fn clean(&self, cx: &DocContext) -> FnDecl { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> FnDecl { FnDecl { inputs: (&self.0.inputs[..], self.1).clean(cx), output: self.0.output.clean(cx), @@ -1760,8 +1762,8 @@ impl<'a, A: Copy> Clean for (&'a hir::FnDecl, A) } } -impl<'a, 'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { - fn clean(&self, cx: &DocContext) -> FnDecl { +impl<'a, 'tcx> Clean<'tcx, FnDecl> for (DefId, ty::PolyFnSig<'tcx>) { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> FnDecl { let (did, sig) = *self; let mut names = if cx.tcx.hir().as_local_node_id(did).is_some() { vec![].into_iter() @@ -1821,8 +1823,8 @@ pub enum FunctionRetTy { DefaultReturn, } -impl Clean for hir::FunctionRetTy { - fn clean(&self, cx: &DocContext) -> FunctionRetTy { +impl<'tcx> Clean<'tcx, FunctionRetTy> for hir::FunctionRetTy<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> FunctionRetTy { match *self { hir::Return(ref typ) => Return(typ.clean(cx)), hir::DefaultReturn(..) => DefaultReturn, @@ -1850,8 +1852,8 @@ pub struct Trait { pub is_auto: bool, } -impl Clean for doctree::Trait { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Trait<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let attrs = self.attrs.clean(cx); let is_spotlight = attrs.has_doc_flag("spotlight"); Item { @@ -1875,7 +1877,7 @@ impl Clean for doctree::Trait { } } -impl Clean for hir::IsAuto { +impl<'tcx> Clean<'tcx, bool> for hir::IsAuto { fn clean(&self, _: &DocContext) -> bool { match *self { hir::IsAuto::Yes => true, @@ -1884,14 +1886,14 @@ impl Clean for hir::IsAuto { } } -impl Clean for hir::TraitRef { - fn clean(&self, cx: &DocContext) -> Type { +impl<'tcx> Clean<'tcx, Type> for hir::TraitRef<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Type { resolve_type(cx, self.path.clean(cx), self.ref_id) } } -impl Clean for hir::PolyTraitRef { - fn clean(&self, cx: &DocContext) -> PolyTrait { +impl<'tcx> Clean<'tcx, PolyTrait> for hir::PolyTraitRef<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> PolyTrait { PolyTrait { trait_: self.trait_ref.clean(cx), generic_params: self.bound_generic_params.clean(cx) @@ -1899,8 +1901,8 @@ impl Clean for hir::PolyTraitRef { } } -impl Clean for hir::TraitItem { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let inner = match self.node { hir::TraitItemKind::Const(ref ty, default) => { AssociatedConstItem(ty.clean(cx), @@ -1911,7 +1913,7 @@ impl Clean for hir::TraitItem { } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref names)) => { let (generics, decl) = enter_impl_trait(cx, || { - (self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx)) + (self.generics.clean(cx), (&**sig.decl, &names[..]).clean(cx)) }); TyMethodItem(TyMethod { header: sig.header, @@ -1936,8 +1938,8 @@ impl Clean for hir::TraitItem { } } -impl Clean for hir::ImplItem { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let inner = match self.node { hir::ImplItemKind::Const(ref ty, expr) => { AssociatedConstItem(ty.clean(cx), @@ -1968,8 +1970,8 @@ impl Clean for hir::ImplItem { } } -impl<'tcx> Clean for ty::AssociatedItem { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for ty::AssociatedItem { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let inner = match self.kind { ty::AssociatedKind::Const => { let ty = cx.tcx.type_of(self.def_id); @@ -2394,8 +2396,8 @@ impl From for PrimitiveType { } } -impl Clean for hir::Ty { - fn clean(&self, cx: &DocContext) -> Type { +impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Type { use rustc::hir::*; match self.node { @@ -2523,7 +2525,7 @@ impl Clean for hir::Ty { let trait_path = hir::Path { span: p.span, def: Def::Trait(cx.tcx.associated_item(p.def.def_id()).container.id()), - segments: segments.into(), + segments: P::from_slice(cx.tcx.global_arena(), &segments), }; Type::QPath { name: p.segments.last().expect("segments were empty").ident.name.clean(cx), @@ -2540,7 +2542,7 @@ impl Clean for hir::Ty { let trait_path = hir::Path { span: self.span, def, - segments: vec![].into(), + segments: hir::HirVec::new(), }; Type::QPath { name: segment.ident.name.clean(cx), @@ -2570,8 +2572,8 @@ impl Clean for hir::Ty { } } -impl<'tcx> Clean for Ty<'tcx> { - fn clean(&self, cx: &DocContext) -> Type { +impl<'tcx> Clean<'tcx, Type> for Ty<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Type { match self.sty { ty::Never => Never, ty::Bool => Primitive(PrimitiveType::Bool), @@ -2765,8 +2767,8 @@ impl<'tcx> Clean for Ty<'tcx> { } } -impl Clean for hir::StructField { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for hir::StructField<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.ident.name).clean(cx), attrs: self.attrs.clean(cx), @@ -2780,8 +2782,8 @@ impl Clean for hir::StructField { } } -impl<'tcx> Clean for ty::FieldDef { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for ty::FieldDef { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.ident.name).clean(cx), attrs: cx.tcx.get_attrs(self.did).clean(cx), @@ -2803,8 +2805,8 @@ pub enum Visibility { Restricted(DefId, Path), } -impl Clean> for hir::Visibility { - fn clean(&self, cx: &DocContext) -> Option { +impl<'tcx> Clean<'tcx, Option> for hir::Visibility<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Option { Some(match self.node { hir::VisibilityKind::Public => Visibility::Public, hir::VisibilityKind::Inherited => Visibility::Inherited, @@ -2818,7 +2820,7 @@ impl Clean> for hir::Visibility { } } -impl Clean> for ty::Visibility { +impl<'tcx> Clean<'tcx, Option> for ty::Visibility { fn clean(&self, _: &DocContext) -> Option { Some(if *self == ty::Visibility::Public { Public } else { Inherited }) } @@ -2840,8 +2842,8 @@ pub struct Union { pub fields_stripped: bool, } -impl Clean for doctree::Struct { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Struct<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -2860,8 +2862,8 @@ impl Clean for doctree::Struct { } } -impl Clean for doctree::Union { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Union<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -2890,8 +2892,8 @@ pub struct VariantStruct { pub fields_stripped: bool, } -impl Clean for ::rustc::hir::VariantData { - fn clean(&self, cx: &DocContext) -> VariantStruct { +impl<'tcx> Clean<'tcx, VariantStruct> for ::rustc::hir::VariantData<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> VariantStruct { VariantStruct { struct_type: doctree::struct_type_from_def(self), fields: self.fields().iter().map(|x| x.clean(cx)).collect(), @@ -2907,8 +2909,8 @@ pub struct Enum { pub variants_stripped: bool, } -impl Clean for doctree::Enum { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Enum<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -2931,8 +2933,8 @@ pub struct Variant { pub kind: VariantKind, } -impl Clean for doctree::Variant { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Variant<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -2948,8 +2950,8 @@ impl Clean for doctree::Variant { } } -impl<'tcx> Clean for ty::VariantDef { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for ty::VariantDef { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let kind = match self.ctor_kind { CtorKind::Const => VariantKind::CLike, CtorKind::Fn => { @@ -2996,8 +2998,8 @@ pub enum VariantKind { Struct(VariantStruct), } -impl Clean for hir::VariantData { - fn clean(&self, cx: &DocContext) -> VariantKind { +impl<'tcx> Clean<'tcx, VariantKind> for hir::VariantData<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> VariantKind { if self.is_struct() { VariantKind::Struct(self.clean(cx)) } else if self.is_unit() { @@ -3027,8 +3029,8 @@ impl Span { } } -impl Clean for syntax_pos::Span { - fn clean(&self, cx: &DocContext) -> Span { +impl<'tcx> Clean<'tcx, Span> for syntax_pos::Span { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Span { if self.is_dummy() { return Span::empty(); } @@ -3060,8 +3062,8 @@ impl Path { } } -impl Clean for hir::Path { - fn clean(&self, cx: &DocContext) -> Path { +impl<'tcx> Clean<'tcx, Path> for hir::Path<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Path { Path { global: self.is_global(), def: self.def, @@ -3083,8 +3085,8 @@ pub enum GenericArgs { } } -impl Clean for hir::GenericArgs { - fn clean(&self, cx: &DocContext) -> GenericArgs { +impl<'tcx> Clean<'tcx, GenericArgs> for hir::GenericArgs<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> GenericArgs { if self.parenthesized { let output = self.bindings[0].ty.clean(cx); GenericArgs::Parenthesized { @@ -3122,8 +3124,8 @@ pub struct PathSegment { pub args: GenericArgs, } -impl Clean for hir::PathSegment { - fn clean(&self, cx: &DocContext) -> PathSegment { +impl<'tcx> Clean<'tcx, PathSegment> for hir::PathSegment<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> PathSegment { PathSegment { name: self.ident.name.clean(cx), args: self.with_generic_args(|generic_args| generic_args.clean(cx)) @@ -3193,21 +3195,21 @@ fn qpath_to_string(p: &hir::QPath) -> String { s } -impl Clean for Ident { +impl<'tcx> Clean<'tcx, String> for Ident { #[inline] fn clean(&self, cx: &DocContext) -> String { self.name.clean(cx) } } -impl Clean for ast::Name { +impl<'tcx> Clean<'tcx, String> for ast::Name { #[inline] fn clean(&self, _: &DocContext) -> String { self.to_string() } } -impl Clean for InternedString { +impl<'tcx> Clean<'tcx, String> for InternedString { #[inline] fn clean(&self, _: &DocContext) -> String { self.to_string() @@ -3220,8 +3222,8 @@ pub struct Typedef { pub generics: Generics, } -impl Clean for doctree::Typedef { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Typedef<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -3244,8 +3246,8 @@ pub struct Existential { pub generics: Generics, } -impl Clean for doctree::Existential { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Existential<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -3270,10 +3272,10 @@ pub struct BareFunctionDecl { pub abi: Abi, } -impl Clean for hir::BareFnTy { - fn clean(&self, cx: &DocContext) -> BareFunctionDecl { +impl<'tcx> Clean<'tcx, BareFunctionDecl> for hir::BareFnTy<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> BareFunctionDecl { let (generic_params, decl) = enter_impl_trait(cx, || { - (self.generic_params.clean(cx), (&*self.decl, &self.arg_names[..]).clean(cx)) + (self.generic_params.clean(cx), (&**self.decl, &self.arg_names[..]).clean(cx)) }); BareFunctionDecl { unsafety: self.unsafety, @@ -3294,8 +3296,8 @@ pub struct Static { pub expr: String, } -impl Clean for doctree::Static { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Static<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { debug!("cleaning static {}: {:?}", self.name.clean(cx), self); Item { name: Some(self.name.clean(cx)), @@ -3320,8 +3322,8 @@ pub struct Constant { pub expr: String, } -impl Clean for doctree::Constant { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Constant<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -3344,7 +3346,7 @@ pub enum Mutability { Immutable, } -impl Clean for hir::Mutability { +impl<'tcx> Clean<'tcx, Mutability> for hir::Mutability { fn clean(&self, _: &DocContext) -> Mutability { match self { &hir::MutMutable => Mutable, @@ -3359,7 +3361,7 @@ pub enum ImplPolarity { Negative, } -impl Clean for hir::ImplPolarity { +impl<'tcx> Clean<'tcx, ImplPolarity> for hir::ImplPolarity { fn clean(&self, _: &DocContext) -> ImplPolarity { match self { &hir::ImplPolarity::Positive => ImplPolarity::Positive, @@ -3403,8 +3405,8 @@ pub fn get_blanket_impls_with_def_id(cx: &DocContext, id: DefId) -> Vec { finder.get_with_def_id(id) } -impl Clean> for doctree::Impl { - fn clean(&self, cx: &DocContext) -> Vec { +impl<'tcx> Clean<'tcx, Vec> for doctree::Impl<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Vec { let mut ret = Vec::new(); let trait_ = self.trait_.clean(cx); let items = self.items.clean(cx); @@ -3503,8 +3505,8 @@ fn build_deref_target_impls(cx: &DocContext, } } -impl Clean for doctree::ExternCrate { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::ExternCrate<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: None, attrs: self.attrs.clean(cx), @@ -3518,8 +3520,8 @@ impl Clean for doctree::ExternCrate { } } -impl Clean> for doctree::Import { - fn clean(&self, cx: &DocContext) -> Vec { +impl<'tcx> Clean<'tcx, Vec> for doctree::Import<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Vec { // We consider inlining the documentation of `pub use` statements, but we // forcefully don't inline if this is not public or if the // #[doc(no_inline)] attribute is present. @@ -3592,8 +3594,8 @@ pub struct ImportSource { pub did: Option, } -impl Clean> for hir::ForeignMod { - fn clean(&self, cx: &DocContext) -> Vec { +impl<'tcx> Clean<'tcx, Vec> for hir::ForeignMod<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Vec { let mut items = self.items.clean(cx); for item in &mut items { if let ForeignFunctionItem(ref mut f) = item.inner { @@ -3604,12 +3606,12 @@ impl Clean> for hir::ForeignMod { } } -impl Clean for hir::ForeignItem { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for hir::ForeignItem<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let inner = match self.node { hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => { let (generics, decl) = enter_impl_trait(cx, || { - (generics.clean(cx), (&**decl, &names[..]).clean(cx)) + (generics.clean(cx), (&***decl, &names[..]).clean(cx)) }); ForeignFunctionItem(Function { decl, @@ -3812,8 +3814,8 @@ pub struct Macro { pub imported_from: Option, } -impl Clean for doctree::Macro { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::Macro<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { let name = self.name.clean(cx); Item { name: Some(name.clone()), @@ -3841,8 +3843,8 @@ pub struct ProcMacro { pub helpers: Vec, } -impl Clean for doctree::ProcMacro { - fn clean(&self, cx: &DocContext) -> Item { +impl<'tcx> Clean<'tcx, Item> for doctree::ProcMacro<'_> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> Item { Item { name: Some(self.name.clean(cx)), attrs: self.attrs.clean(cx), @@ -3875,7 +3877,7 @@ pub struct Deprecation { pub note: Option, } -impl Clean for attr::Stability { +impl<'tcx> Clean<'tcx, Stability> for attr::Stability { fn clean(&self, _: &DocContext) -> Stability { Stability { level: stability::StabilityLevel::from_attr_level(&self.level), @@ -3902,13 +3904,13 @@ impl Clean for attr::Stability { } } -impl<'a> Clean for &'a attr::Stability { +impl<'tcx, 'a> Clean<'tcx, Stability> for &'a attr::Stability { fn clean(&self, dc: &DocContext) -> Stability { (**self).clean(dc) } } -impl Clean for attr::Deprecation { +impl<'tcx> Clean<'tcx, Deprecation> for attr::Deprecation { fn clean(&self, _: &DocContext) -> Deprecation { Deprecation { since: self.since.map(|s| s.to_string()).filter(|s| !s.is_empty()), @@ -3924,8 +3926,8 @@ pub struct TypeBinding { pub ty: Type } -impl Clean for hir::TypeBinding { - fn clean(&self, cx: &DocContext) -> TypeBinding { +impl<'tcx> Clean<'tcx, TypeBinding> for hir::TypeBinding<'tcx> { + fn clean(&self, cx: &DocContext<'_, 'tcx, '_>) -> TypeBinding { TypeBinding { name: self.ident.name.clean(cx), ty: self.ty.clean(cx) @@ -4022,7 +4024,11 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option { } } -pub fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: F) -> hir::Path +pub fn get_path_for_type<'tcx, F>( + tcx: TyCtxt<'_, 'tcx, '_>, + def_id: DefId, + def_ctor: F +) -> hir::Path<'tcx> where F: Fn(DefId) -> Def { #[derive(Debug)] struct AbsolutePathBuffer { @@ -4047,13 +4053,13 @@ where F: Fn(DefId) -> Def { hir::Path { span: DUMMY_SP, def: def_ctor(def_id), - segments: hir::HirVec::from_vec(apb.names.iter().map(|s| hir::PathSegment { + segments: apb.names.iter().map(|s| hir::PathSegment { ident: ast::Ident::from_str(&s), id: None, def: None, args: None, infer_types: false, - }).collect()) + }).collect_hir_vec(tcx.global_arena()), } } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 8bb0dc9daa6a2..a0181b4e99310 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -4,6 +4,7 @@ use rustc::session::{self, config}; use rustc::hir::def_id::{DefId, DefIndex, DefIndexAddressSpace, CrateNum, LOCAL_CRATE}; use rustc::hir::def::Def; use rustc::hir::{self, HirVec}; +use rustc::hir::ptr::P; use rustc::middle::cstore::CrateStore; use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, TyCtxt, AllArenas}; @@ -20,7 +21,6 @@ use syntax::ast::{self, Ident, NodeId}; use syntax::source_map; use syntax::feature_gate::UnstableFeatures; use syntax::json::JsonEmitter; -use syntax::ptr::P; use syntax::symbol::keywords; use syntax_pos::DUMMY_SP; use errors::{self, FatalError}; @@ -167,13 +167,14 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { def_ctor: &F, real_name: &Option, generics: &ty::Generics, - ) -> hir::Ty + ) -> hir::Ty<'tcx> where F: Fn(DefId) -> Def { let path = get_path_for_type(self.tcx, def_id, def_ctor); let mut segments = path.segments.into_vec(); let last = segments.pop().expect("segments were empty"); segments.push(hir::PathSegment::new( + self.tcx.global_arena(), real_name.unwrap_or(last.ident), None, None, @@ -184,18 +185,21 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { let new_path = hir::Path { span: path.span, def: path.def, - segments: HirVec::from_vec(segments), + segments: P::from_slice(self.tcx.global_arena(), &segments), }; hir::Ty { id: ast::DUMMY_NODE_ID, - node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), + node: hir::TyKind::Path(hir::QPath::Resolved( + None, + P::alloc(self.tcx.global_arena(), new_path) + )), span: DUMMY_SP, hir_id: hir::DUMMY_HIR_ID, } } - pub fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs { + pub fn generics_to_path_params(&self, generics: ty::Generics) -> hir::GenericArgs<'tcx> { let mut args = vec![]; for param in generics.params.iter() { @@ -220,22 +224,22 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { } hir::GenericArgs { - args: HirVec::from_vec(args), + args: P::from_slice(self.tcx.global_arena(), &args), bindings: HirVec::new(), parenthesized: false, } } - pub fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { + pub fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty<'tcx> { debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); hir::Ty { id: ast::DUMMY_NODE_ID, node: hir::TyKind::Path(hir::QPath::Resolved( None, - P(hir::Path { + P::alloc(self.tcx.global_arena(), hir::Path { span: DUMMY_SP, def: Def::TyParam(param.def_id), - segments: HirVec::from_vec(vec![ + segments: P::from_slice(self.tcx.global_arena(), &[ hir::PathSegment::from_ident(Ident::from_interned_str(param.name)) ]), }), @@ -444,10 +448,15 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let mut crate_loader = CrateLoader::new(&sess, &cstore, &name); + let arenas = AllArenas::new(); + let hir_arenas = hir::Arenas::default(); + let mut global_ctxt = None; let resolver_arenas = resolve::Resolver::arenas(); let result = driver::phase_2_configure_and_expand_inner(&sess, &cstore, krate, + &arenas.interner, + &hir_arenas, None, &name, None, @@ -479,7 +488,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt glob_map: if resolver.make_glob_map { Some(resolver.glob_map.clone()) } else { None }, }; - let mut arenas = AllArenas::new(); let hir_map = hir_map::map_crate(&sess, &*cstore, &mut hir_forest, &defs); let output_filenames = driver::build_output_filenames(&input, &None, @@ -495,7 +503,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt hir_map, analysis, resolutions, - &mut arenas, + &arenas, + &mut global_ctxt, &name, &output_filenames, |tcx, _, _, result| { diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index cc27da70b16d7..ca0ff50061082 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -6,43 +6,43 @@ use syntax::ast; use syntax::ast::{Name, NodeId}; use syntax::attr; use syntax::ext::base::MacroKind; -use syntax::ptr::P; use syntax::source_map::Spanned; use syntax_pos::{self, Span}; use rustc::hir; use rustc::hir::def_id::CrateNum; +use rustc::hir::ptr::P; -pub struct Module { +pub struct Module<'a> { pub name: Option, - pub attrs: hir::HirVec, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub where_outer: Span, pub where_inner: Span, - pub extern_crates: Vec, - pub imports: Vec, - pub structs: Vec, - pub unions: Vec, - pub enums: Vec, - pub fns: Vec, - pub mods: Vec, + pub extern_crates: Vec>, + pub imports: Vec>, + pub structs: Vec>, + pub unions: Vec>, + pub enums: Vec>, + pub fns: Vec>, + pub mods: Vec>, pub id: NodeId, - pub typedefs: Vec, - pub existentials: Vec, - pub statics: Vec, - pub constants: Vec, - pub traits: Vec, - pub vis: hir::Visibility, + pub typedefs: Vec>, + pub existentials: Vec>, + pub statics: Vec>, + pub constants: Vec>, + pub traits: Vec>, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, - pub impls: Vec, - pub foreigns: Vec, - pub macros: Vec, - pub proc_macros: Vec, + pub impls: Vec>, + pub foreigns: Vec>, + pub macros: Vec>, + pub proc_macros: Vec>, pub is_crate: bool, } -impl Module { - pub fn new(name: Option) -> Module { +impl Module<'_> { + pub fn new(name: Option) -> Self { Module { name : name, id: ast::CRATE_NODE_ID, @@ -83,143 +83,143 @@ pub enum StructType { Unit, } -pub struct Struct { - pub vis: hir::Visibility, +pub struct Struct<'a> { + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, pub id: NodeId, pub struct_type: StructType, pub name: Name, - pub generics: hir::Generics, - pub attrs: hir::HirVec, - pub fields: hir::HirVec, + pub generics: hir::Generics<'a>, + pub attrs: hir::HirVec<'a, ast::Attribute>, + pub fields: Vec>, pub whence: Span, } -pub struct Union { - pub vis: hir::Visibility, +pub struct Union<'a> { + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, pub id: NodeId, pub struct_type: StructType, pub name: Name, - pub generics: hir::Generics, - pub attrs: hir::HirVec, - pub fields: hir::HirVec, + pub generics: hir::Generics<'a>, + pub attrs: hir::HirVec<'a, ast::Attribute>, + pub fields: Vec>, pub whence: Span, } -pub struct Enum { - pub vis: hir::Visibility, +pub struct Enum<'a> { + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, - pub variants: hir::HirVec, - pub generics: hir::Generics, - pub attrs: hir::HirVec, + pub variants: Vec>, + pub generics: hir::Generics<'a>, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub id: NodeId, pub whence: Span, pub name: Name, } -pub struct Variant { +pub struct Variant<'a> { pub name: Name, - pub attrs: hir::HirVec, - pub def: hir::VariantData, + pub attrs: hir::HirVec<'a, ast::Attribute>, + pub def: hir::VariantData<'a>, pub stab: Option, pub depr: Option, pub whence: Span, } -pub struct Function { - pub decl: hir::FnDecl, - pub attrs: hir::HirVec, +pub struct Function<'a> { + pub decl: hir::FnDecl<'a>, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub id: NodeId, pub name: Name, - pub vis: hir::Visibility, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, pub header: hir::FnHeader, pub whence: Span, - pub generics: hir::Generics, + pub generics: hir::Generics<'a>, pub body: hir::BodyId, } -pub struct Typedef { - pub ty: P, - pub gen: hir::Generics, +pub struct Typedef<'a> { + pub ty: P<'a, hir::Ty<'a>>, + pub gen: hir::Generics<'a>, pub name: Name, pub id: ast::NodeId, - pub attrs: hir::HirVec, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub whence: Span, - pub vis: hir::Visibility, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, } -pub struct Existential { - pub exist_ty: hir::ExistTy, +pub struct Existential<'a> { + pub exist_ty: hir::ExistTy<'a>, pub name: Name, pub id: ast::NodeId, - pub attrs: hir::HirVec, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub whence: Span, - pub vis: hir::Visibility, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, } #[derive(Debug)] -pub struct Static { - pub type_: P, +pub struct Static<'a> { + pub type_: P<'a, hir::Ty<'a>>, pub mutability: hir::Mutability, pub expr: hir::BodyId, pub name: Name, - pub attrs: hir::HirVec, - pub vis: hir::Visibility, + pub attrs: hir::HirVec<'a, ast::Attribute>, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, pub id: ast::NodeId, pub whence: Span, } -pub struct Constant { - pub type_: P, +pub struct Constant<'a> { + pub type_: P<'a, hir::Ty<'a>>, pub expr: hir::BodyId, pub name: Name, - pub attrs: hir::HirVec, - pub vis: hir::Visibility, + pub attrs: hir::HirVec<'a, ast::Attribute>, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, pub id: ast::NodeId, pub whence: Span, } -pub struct Trait { +pub struct Trait<'a> { pub is_auto: hir::IsAuto, pub unsafety: hir::Unsafety, pub name: Name, - pub items: hir::HirVec, - pub generics: hir::Generics, - pub bounds: hir::HirVec, - pub attrs: hir::HirVec, + pub items: Vec>, + pub generics: hir::Generics<'a>, + pub bounds: Vec>, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub id: ast::NodeId, pub whence: Span, - pub vis: hir::Visibility, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, } #[derive(Debug)] -pub struct Impl { +pub struct Impl<'a> { pub unsafety: hir::Unsafety, pub polarity: hir::ImplPolarity, pub defaultness: hir::Defaultness, - pub generics: hir::Generics, - pub trait_: Option, - pub for_: P, - pub items: hir::HirVec, - pub attrs: hir::HirVec, + pub generics: hir::Generics<'a>, + pub trait_: Option>, + pub for_: P<'a, hir::Ty<'a>>, + pub items: Vec>, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub whence: Span, - pub vis: hir::Visibility, + pub vis: hir::Visibility<'a>, pub stab: Option, pub depr: Option, pub id: ast::NodeId, @@ -227,42 +227,42 @@ pub struct Impl { // For Macro we store the DefId instead of the NodeId, since we also create // these imported macro_rules (which only have a DUMMY_NODE_ID). -pub struct Macro { +pub struct Macro<'a> { pub name: Name, pub def_id: hir::def_id::DefId, - pub attrs: hir::HirVec, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub whence: Span, - pub matchers: hir::HirVec, + pub matchers: Vec, pub stab: Option, pub depr: Option, pub imported_from: Option, } -pub struct ExternCrate { +pub struct ExternCrate<'a> { pub name: Name, pub cnum: CrateNum, pub path: Option, - pub vis: hir::Visibility, - pub attrs: hir::HirVec, + pub vis: hir::Visibility<'a>, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub whence: Span, } -pub struct Import { +pub struct Import<'a> { pub name: Name, pub id: NodeId, - pub vis: hir::Visibility, - pub attrs: hir::HirVec, - pub path: hir::Path, + pub vis: hir::Visibility<'a>, + pub attrs: hir::HirVec<'a, ast::Attribute>, + pub path: hir::Path<'a>, pub glob: bool, pub whence: Span, } -pub struct ProcMacro { +pub struct ProcMacro<'a> { pub name: Name, pub id: NodeId, pub kind: MacroKind, pub helpers: Vec, - pub attrs: hir::HirVec, + pub attrs: hir::HirVec<'a, ast::Attribute>, pub whence: Span, pub stab: Option, pub depr: Option, diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index fdc1c0616187a..ae66df9faa6b6 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -77,8 +77,12 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { let result = cx.resolver.borrow_mut() .with_scope(id, |resolver| { - resolver.resolve_str_path_error(DUMMY_SP, - &path_str, is_val) + resolver.resolve_str_path_error( + cx.tcx.global_arena(), + DUMMY_SP, + &path_str, + is_val + ) }); if let Ok(result) = result { @@ -130,7 +134,12 @@ impl<'a, 'tcx, 'rcx> LinkCollector<'a, 'tcx, 'rcx> { let ty = cx.resolver.borrow_mut() .with_scope(id, |resolver| { - resolver.resolve_str_path_error(DUMMY_SP, &path, false) + resolver.resolve_str_path_error( + cx.tcx.global_arena(), + DUMMY_SP, + &path, + false + ) })?; match ty.def { Def::Struct(did) | Def::Union(did) | Def::Enum(did) | Def::TyAlias(did) => { diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 2170054b532b9..360f8d1d05f2f 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -1,3 +1,4 @@ +use arena::SyncDroplessArena; use errors::{self, FatalError}; use errors::emitter::ColorConfig; use rustc_data_structures::sync::Lrc; @@ -92,11 +93,15 @@ pub fn run(mut options: Options) -> isize { FatalError.raise(); } }; + let arena = SyncDroplessArena::default(); + let hir_arenas = hir::Arenas::default(); let driver::ExpansionResult { defs, mut hir_forest, .. } = { phase_2_configure_and_expand( &sess, &cstore, krate, + &arena, + &hir_arenas, None, "rustdoc-test", None, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 953ab7c2565bf..e4094ca314068 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -4,6 +4,7 @@ use rustc::hir::{self, Node}; use rustc::hir::def::Def; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::hir::ptr::{P, IteratorExt}; use rustc::middle::privacy::AccessLevel; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use syntax::ast; @@ -27,8 +28,8 @@ use doctree::*; // framework from syntax?. pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> { - pub module: Module, - pub attrs: hir::HirVec, + pub module: Module<'tcx>, + pub attrs: hir::HirVec<'tcx, ast::Attribute>, pub cx: &'a core::DocContext<'a, 'tcx, 'rcx>, view_item_stack: FxHashSet, inlining: bool, @@ -75,7 +76,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { .and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id)) } - pub fn visit(&mut self, krate: &hir::Crate) { + pub fn visit(&mut self, krate: &hir::Crate<'tcx>) { self.attrs = krate.attrs.clone(); self.module = self.visit_mod_contents(krate.span, @@ -94,9 +95,9 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths.take().unwrap(); } - pub fn visit_variant_data(&mut self, item: &hir::Item, - name: ast::Name, sd: &hir::VariantData, - generics: &hir::Generics) -> Struct { + pub fn visit_variant_data(&mut self, item: &hir::Item<'tcx>, + name: ast::Name, sd: &hir::VariantData<'tcx>, + generics: &hir::Generics<'tcx>) -> Struct<'tcx> { debug!("Visiting struct"); let struct_type = struct_type_from_def(&*sd); Struct { @@ -113,9 +114,9 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } } - pub fn visit_union_data(&mut self, item: &hir::Item, - name: ast::Name, sd: &hir::VariantData, - generics: &hir::Generics) -> Union { + pub fn visit_union_data(&mut self, item: &hir::Item<'tcx>, + name: ast::Name, sd: &hir::VariantData<'tcx>, + generics: &hir::Generics<'tcx>) -> Union<'tcx> { debug!("Visiting union"); let struct_type = struct_type_from_def(&*sd); Union { @@ -132,9 +133,9 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } } - pub fn visit_enum_def(&mut self, it: &hir::Item, - name: ast::Name, def: &hir::EnumDef, - params: &hir::Generics) -> Enum { + pub fn visit_enum_def(&mut self, it: &hir::Item<'tcx>, + name: ast::Name, def: &hir::EnumDef<'tcx>, + params: &hir::Generics<'tcx>) -> Enum<'tcx> { debug!("Visiting enum"); Enum { name, @@ -156,10 +157,10 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } } - pub fn visit_fn(&mut self, om: &mut Module, item: &hir::Item, - name: ast::Name, fd: &hir::FnDecl, + pub fn visit_fn(&mut self, om: &mut Module<'tcx>, item: &hir::Item<'tcx>, + name: ast::Name, fd: &hir::FnDecl<'tcx>, header: hir::FnHeader, - gen: &hir::Generics, + gen: &hir::Generics<'tcx>, body: hir::BodyId) { debug!("Visiting fn"); let macro_kind = item.attrs.iter().filter_map(|a| { @@ -228,10 +229,10 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } } - pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec, - vis: hir::Visibility, id: ast::NodeId, - m: &hir::Mod, - name: Option) -> Module { + pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec<'tcx, ast::Attribute>, + vis: hir::Visibility<'tcx>, id: ast::NodeId, + m: &hir::Mod<'tcx>, + name: Option) -> Module<'tcx> { let mut om = Module::new(name); om.where_outer = span; om.where_inner = m.inner; @@ -265,7 +266,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { def: Def, renamed: Option, glob: bool, - om: &mut Module, + om: &mut Module<'tcx>, please_inline: bool) -> bool { fn inherits_doc_hidden(cx: &core::DocContext, mut node: ast::NodeId) -> bool { @@ -356,10 +357,10 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { // Generate a fresh `extern {}` block if we want to inline a foreign item. om.foreigns.push(hir::ForeignMod { abi: tcx.hir().get_foreign_abi(it.id), - items: vec![hir::ForeignItem { + items: P::from_slice(tcx.global_arena(), &[hir::ForeignItem { ident: renamed.unwrap_or(it.ident), .. it.clone() - }].into(), + }]), }); true } @@ -373,8 +374,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { ret } - pub fn visit_item(&mut self, item: &hir::Item, - renamed: Option, om: &mut Module) { + pub fn visit_item(&mut self, item: &hir::Item<'tcx>, + renamed: Option, om: &mut Module<'tcx>) { debug!("Visiting item {:?}", item); let ident = renamed.unwrap_or(item.ident); @@ -389,7 +390,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om.foreigns.push(if self.inlining { hir::ForeignMod { abi: fm.abi, - items: fm.items.iter().filter(|i| i.vis.node.is_pub()).cloned().collect(), + items: fm.items.iter().filter(|i| i.vis.node.is_pub()) + .cloned().collect_hir_vec(self.cx.tcx.global_arena()), } } else { fm.clone() @@ -587,9 +589,9 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { // Convert each `exported_macro` into a doc item. fn visit_local_macro( &self, - def: &hir::MacroDef, + def: &hir::MacroDef<'tcx>, renamed: Option - ) -> Macro { + ) -> Macro<'tcx> { debug!("visit_local_macro: {}", def.name); let tts = def.body.trees().collect::>(); // Extract the spans of all matchers. They represent the "interface" of the macro. diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 7f0f0c6f79fcc..0c77aea59fede 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -135,6 +135,7 @@ const WHITELIST: &[Crate] = &[ Crate("smallvec"), Crate("stable_deref_trait"), Crate("syn"), + Crate("synstructure"), Crate("tempfile"), Crate("termcolor"), Crate("terminon"),