From 30b6c59f24cfb0e451e3df14ef536e4e40fe2672 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 22 Jun 2019 12:44:03 +0100 Subject: [PATCH 01/13] Prefer to use `has_errors` to `err_count` --- src/librustc/session/mod.rs | 15 ++++++--------- src/librustc_errors/lib.rs | 7 +++---- src/librustc_interface/passes.rs | 2 +- src/librustc_typeck/check/expr.rs | 8 +++----- src/librustc_typeck/check/mod.rs | 6 +++--- src/librustc_typeck/check/regionck.rs | 4 ++-- src/librustdoc/core.rs | 2 +- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index d04b9ac083ce5..bb4ef2d7bd426 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -320,8 +320,13 @@ impl Session { self.diagnostic().abort_if_errors(); } pub fn compile_status(&self) -> Result<(), ErrorReported> { - compile_result_from_err_count(self.err_count()) + if self.has_errors() { + Err(ErrorReported) + } else { + Ok(()) + } } + // FIXME(matthewjasper) Remove this method, it should never be needed. pub fn track_errors(&self, f: F) -> Result where F: FnOnce() -> T, @@ -1388,11 +1393,3 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) { } pub type CompileResult = Result<(), ErrorReported>; - -pub fn compile_result_from_err_count(err_count: usize) -> CompileResult { - if err_count == 0 { - Ok(()) - } else { - Err(ErrorReported) - } -} diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 05cee6dff2309..082f981338a6c 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -352,7 +352,7 @@ pub struct HandlerFlags { impl Drop for Handler { fn drop(&mut self) { - if self.err_count() == 0 { + if !self.has_errors() { let mut bugs = self.delayed_span_bugs.borrow_mut(); let has_bugs = !bugs.is_empty(); for bug in bugs.drain(..) { @@ -705,10 +705,9 @@ impl Handler { } pub fn abort_if_errors(&self) { - if self.err_count() == 0 { - return; + if self.has_errors() { + FatalError.raise(); } - FatalError.raise(); } pub fn emit(&self, msp: &MultiSpan, msg: &str, lvl: Level) { if lvl == Warning && !self.flags.can_emit_warnings { diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 69cb696f4c580..c1b6e3409c915 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -959,7 +959,7 @@ fn analysis<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> Result<()> { // lot of annoying errors in the compile-fail tests (basically, // lint warnings and so on -- kindck used to do this abort, but // kindck is gone now). -nmatsakis - if sess.err_count() > 0 { + if sess.has_errors() { return Err(ErrorReported); } diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 8ca1b85ad9aee..85da325197143 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -565,7 +565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // else an error would have been flagged by the // `loops` pass for using break with an expression // where you are not supposed to. - assert!(expr_opt.is_none() || self.tcx.sess.err_count() > 0); + assert!(expr_opt.is_none() || self.tcx.sess.has_errors()); } ctxt.may_break = true; @@ -577,10 +577,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // this can only happen if the `break` was not // inside a loop at all, which is caught by the // loop-checking pass. - if self.tcx.sess.err_count() == 0 { - self.tcx.sess.delay_span_bug(expr.span, - "break was outside loop, but no error was emitted"); - } + self.tcx.sess.delay_span_bug(expr.span, + "break was outside loop, but no error was emitted"); // We still need to assign a type to the inner expression to // prevent the ICE in #43162. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0e83db48284a8..40812b6a952d9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2129,8 +2129,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self.tcx.sess } - pub fn err_count_since_creation(&self) -> usize { - self.tcx.sess.err_count() - self.err_count_on_creation + pub fn errors_reported_since_creation(&self) -> bool { + self.tcx.sess.err_count() > self.err_count_on_creation } /// Produces warning on the given node, if the current point in the @@ -4376,7 +4376,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t } else if let ty::Error = leaf_ty.sty { // If there is already another error, do not emit // an error for not using a type Parameter. - assert!(tcx.sess.err_count() > 0); + assert!(tcx.sess.has_errors()); return; } } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 5c710399446ef..5313e1d0f73a3 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -123,7 +123,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // standalone expr (e.g., the `E` in a type like `[u32; E]`). rcx.outlives_environment.save_implied_bounds(id); - if self.err_count_since_creation() == 0 { + if !self.errors_reported_since_creation() { // regionck assumes typeck succeeded rcx.visit_body(body); rcx.visit_region_obligations(id); @@ -173,7 +173,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.param_env, ); - if self.err_count_since_creation() == 0 { + if !self.errors_reported_since_creation() { // regionck assumes typeck succeeded rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id)); } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 20a4f86aedb90..621292a13c83a 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -346,7 +346,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt // current architecture. let resolver = abort_on_err(compiler.expansion(), sess).peek().1.clone(); - if sess.err_count() > 0 { + if sess.has_errors() { sess.fatal("Compilation failed, aborting rustdoc"); } From 95a32157af8291b452570319c2d035a4307b52e6 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 22 Jun 2019 12:46:48 +0100 Subject: [PATCH 02/13] Count all errors for `track_errors` --- src/librustc/infer/mod.rs | 1 + src/librustc_errors/lib.rs | 16 ++++++++-- src/librustc_mir/const_eval.rs | 20 ++++--------- src/librustc_save_analysis/span_utils.rs | 6 ---- src/librustc_typeck/check/mod.rs | 10 +++---- src/librustc_typeck/lib.rs | 5 +++- src/test/ui/consts/enum-discr-type-err.rs | 29 +++++++++++++++++++ src/test/ui/consts/enum-discr-type-err.stderr | 19 ++++++++++++ 8 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 src/test/ui/consts/enum-discr-type-err.rs create mode 100644 src/test/ui/consts/enum-discr-type-err.stderr diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index fc46fe383c972..eb007062e6d50 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -171,6 +171,7 @@ pub struct InferCtxt<'a, 'tcx> { /// Track how many errors were reported when this infcx is created. /// If the number of errors increases, that's also a sign (line /// `tained_by_errors`) to avoid reporting certain kinds of errors. + // FIXME(matthewjasper) Merge into `tainted_by_errors_flag` err_count_on_creation: usize, /// This flag is true while there is an active snapshot. diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 082f981338a6c..70bd25a9d5772 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -307,7 +307,12 @@ pub use diagnostic_builder::DiagnosticBuilder; pub struct Handler { pub flags: HandlerFlags, + /// The number of errors that have been emitted, including duplicates. + /// + /// This is not necessarily the count that's reported to the user once + /// compilation ends. err_count: AtomicUsize, + deduplicated_err_count: AtomicUsize, emitter: Lock>, continue_after_error: AtomicBool, delayed_span_bugs: Lock>, @@ -407,6 +412,7 @@ impl Handler { Handler { flags, err_count: AtomicUsize::new(0), + deduplicated_err_count: AtomicUsize::new(0), emitter: Lock::new(e), continue_after_error: AtomicBool::new(true), delayed_span_bugs: Lock::new(Vec::new()), @@ -428,6 +434,7 @@ impl Handler { pub fn reset_err_count(&self) { // actually frees the underlying memory (which `clear` would not do) *self.emitted_diagnostics.borrow_mut() = Default::default(); + self.deduplicated_err_count.store(0, SeqCst); self.err_count.store(0, SeqCst); } @@ -660,10 +667,10 @@ impl Handler { } pub fn print_error_count(&self, registry: &Registry) { - let s = match self.err_count() { + let s = match self.deduplicated_err_count.load(SeqCst) { 0 => return, 1 => "aborting due to previous error".to_string(), - _ => format!("aborting due to {} previous errors", self.err_count()) + count => format!("aborting due to {} previous errors", count) }; if self.treat_err_as_bug() { return; @@ -769,9 +776,12 @@ impl Handler { if self.emitted_diagnostics.borrow_mut().insert(diagnostic_hash) { self.emitter.borrow_mut().emit_diagnostic(db); if db.is_error() { - self.bump_err_count(); + self.deduplicated_err_count.fetch_add(1, SeqCst); } } + if db.is_error() { + self.bump_err_count(); + } } pub fn emit_artifact_notification(&self, path: &Path, artifact_type: &str) { diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 284a8f40e1f35..8c2bfc42b020a 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -15,7 +15,6 @@ use rustc::ty::{self, TyCtxt, query::TyCtxtAt}; use rustc::ty::layout::{self, LayoutOf, VariantIdx}; use rustc::ty::subst::Subst; use rustc::traits::Reveal; -use rustc::util::common::ErrorReported; use rustc_data_structures::fx::FxHashMap; use syntax::source_map::{Span, DUMMY_SP}; @@ -655,19 +654,12 @@ pub fn const_eval_raw_provider<'tcx>( if tcx.is_static(def_id) { // Ensure that if the above error was either `TooGeneric` or `Reported` // an error must be reported. - let reported_err = tcx.sess.track_errors(|| { - err.report_as_error(ecx.tcx, - "could not evaluate static initializer") - }); - match reported_err { - Ok(v) => { - tcx.sess.delay_span_bug(err.span, - &format!("static eval failure did not emit an error: {:#?}", - v)); - v - }, - Err(ErrorReported) => ErrorHandled::Reported, - } + let v = err.report_as_error(ecx.tcx, "could not evaluate static initializer"); + tcx.sess.delay_span_bug( + err.span, + &format!("static eval failure did not emit an error: {:#?}", v) + ); + v } else if def_id.is_local() { // constant defined in this crate, we can figure out a lint level! match tcx.def_kind(def_id) { diff --git a/src/librustc_save_analysis/span_utils.rs b/src/librustc_save_analysis/span_utils.rs index 5831b0bcd8fa3..8905f475647ba 100644 --- a/src/librustc_save_analysis/span_utils.rs +++ b/src/librustc_save_analysis/span_utils.rs @@ -2,8 +2,6 @@ use rustc::session::Session; use crate::generated_code; -use std::cell::Cell; - use syntax::parse::lexer::{self, StringReader}; use syntax::parse::token::{self, TokenKind}; use syntax_pos::*; @@ -11,16 +9,12 @@ use syntax_pos::*; #[derive(Clone)] pub struct SpanUtils<'a> { pub sess: &'a Session, - // FIXME given that we clone SpanUtils all over the place, this err_count is - // probably useless and any logic relying on it is bogus. - pub err_count: Cell, } impl<'a> SpanUtils<'a> { pub fn new(sess: &'a Session) -> SpanUtils<'a> { SpanUtils { sess, - err_count: Cell::new(0), } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 40812b6a952d9..6d092011f7c9c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -527,6 +527,8 @@ pub struct FnCtxt<'a, 'tcx> { /// checking this function. On exit, if we find that *more* errors /// have been reported, we will skip regionck and other work that /// expects the types within the function to be consistent. + // FIXME(matthewjasper) This should not exist, and it's not correct + // if type checking is run in parallel. err_count_on_creation: usize, ret_coercion: Option>>, @@ -696,11 +698,9 @@ impl ItemLikeVisitor<'tcx> for CheckItemTypesVisitor<'tcx> { fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { } } -pub fn check_wf_new<'tcx>(tcx: TyCtxt<'tcx>) -> Result<(), ErrorReported> { - tcx.sess.track_errors(|| { - let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx); - tcx.hir().krate().par_visit_all_item_likes(&mut visit); - }) +pub fn check_wf_new<'tcx>(tcx: TyCtxt<'tcx>) { + let mut visit = wfcheck::CheckTypeWellFormedVisitor::new(tcx); + tcx.hir().krate().par_visit_all_item_likes(&mut visit); } fn check_mod_item_types<'tcx>(tcx: TyCtxt<'tcx>, module_def_id: DefId) { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index cc6f7a07d9621..8728f80bd985c 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -321,6 +321,7 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) -> Result<(), ErrorReported> { // this ensures that later parts of type checking can assume that items // have valid types and not error + // FIXME(matthewjasper) We shouldn't need to do this. tcx.sess.track_errors(|| { time(tcx.sess, "type collecting", || { for &module in tcx.hir().krate().modules.keys() { @@ -353,7 +354,9 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>) -> Result<(), ErrorReported> { })?; } - time(tcx.sess, "wf checking", || check::check_wf_new(tcx))?; + tcx.sess.track_errors(|| { + time(tcx.sess, "wf checking", || check::check_wf_new(tcx)); + })?; time(tcx.sess, "item-types checking", || { for &module in tcx.hir().krate().modules.keys() { diff --git a/src/test/ui/consts/enum-discr-type-err.rs b/src/test/ui/consts/enum-discr-type-err.rs new file mode 100644 index 0000000000000..d66c4f47d03ee --- /dev/null +++ b/src/test/ui/consts/enum-discr-type-err.rs @@ -0,0 +1,29 @@ +// Test that we mark enum discriminant values as having errors, even when the +// diagnostic is deduplicated. + +struct F; +struct T; + +impl F { + const V: i32 = 0; +} + +impl T { + const V: i32 = 0; +} + +macro_rules! mac { + ($( $v: ident = $s: ident,)*) => { + enum E { + $( $v = $s::V, )* + //~^ ERROR mismatched types + } + } +} + +mac! { + A = F, + B = T, +} + +fn main() {} diff --git a/src/test/ui/consts/enum-discr-type-err.stderr b/src/test/ui/consts/enum-discr-type-err.stderr new file mode 100644 index 0000000000000..3c4fac7327d40 --- /dev/null +++ b/src/test/ui/consts/enum-discr-type-err.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/enum-discr-type-err.rs:18:21 + | +LL | $( $v = $s::V, )* + | ^^^^^ expected isize, found i32 +... +LL | / mac! { +LL | | A = F, +LL | | B = T, +LL | | } + | |_- in this macro invocation +help: you can convert an `i32` to `isize` and panic if the converted value wouldn't fit + | +LL | $( $v = $s::V.try_into().unwrap(), )* + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From e1d871e2d97f8afe056642c6afc433c7d1d1ee1d Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 23 Jun 2019 15:14:04 +0300 Subject: [PATCH 03/13] Remove built-in derive macros `Send` and `Sync` --- src/librustc_resolve/macros.rs | 6 ++++++ src/libsyntax_ext/deriving/bounds.rs | 8 -------- src/libsyntax_ext/deriving/mod.rs | 2 -- src/test/ui/derives/deriving-bounds.rs | 4 ++-- src/test/ui/derives/deriving-bounds.stderr | 16 ++++++++++++++-- src/test/ui/issues/issue-33571.rs | 2 +- src/test/ui/issues/issue-33571.stderr | 8 +++++++- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 5623016c2e5e7..392a46a262f50 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -1022,6 +1022,12 @@ impl<'a> Resolver<'a> { fn suggest_macro_name(&mut self, name: Symbol, kind: MacroKind, err: &mut DiagnosticBuilder<'a>, span: Span) { + if kind == MacroKind::Derive && (name.as_str() == "Send" || name.as_str() == "Sync") { + let msg = format!("unsafe traits like `{}` should be implemented explicitly", name); + err.span_note(span, &msg); + return; + } + // First check if this is a locally-defined bang macro. let suggestion = if let MacroKind::Bang = kind { find_best_match_for_name( diff --git a/src/libsyntax_ext/deriving/bounds.rs b/src/libsyntax_ext/deriving/bounds.rs index c7b805e0bdca6..d5b8a00c75b83 100644 --- a/src/libsyntax_ext/deriving/bounds.rs +++ b/src/libsyntax_ext/deriving/bounds.rs @@ -6,14 +6,6 @@ use syntax::ast::MetaItem; use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax_pos::Span; -pub fn expand_deriving_unsafe_bound(cx: &mut ExtCtxt<'_>, - span: Span, - _: &MetaItem, - _: &Annotatable, - _: &mut dyn FnMut(Annotatable)) { - cx.span_err(span, "this unsafe trait should be implemented explicitly"); -} - pub fn expand_deriving_copy(cx: &mut ExtCtxt<'_>, span: Span, mitem: &MetaItem, diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index e75eff2e85714..aa9913d436cfa 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -111,8 +111,6 @@ derive_traits! { "Default" => default::expand_deriving_default, - "Send" => bounds::expand_deriving_unsafe_bound, - "Sync" => bounds::expand_deriving_unsafe_bound, "Copy" => bounds::expand_deriving_copy, // deprecated diff --git a/src/test/ui/derives/deriving-bounds.rs b/src/test/ui/derives/deriving-bounds.rs index 607cfa1bb2cd7..52659bd11e080 100644 --- a/src/test/ui/derives/deriving-bounds.rs +++ b/src/test/ui/derives/deriving-bounds.rs @@ -1,9 +1,9 @@ #[derive(Send)] -//~^ ERROR this unsafe trait should be implemented explicitly +//~^ ERROR cannot find derive macro `Send` in this scope struct Test; #[derive(Sync)] -//~^ ERROR this unsafe trait should be implemented explicitly +//~^ ERROR cannot find derive macro `Sync` in this scope struct Test1; pub fn main() {} diff --git a/src/test/ui/derives/deriving-bounds.stderr b/src/test/ui/derives/deriving-bounds.stderr index deb84fd99bd2a..99976da72da1d 100644 --- a/src/test/ui/derives/deriving-bounds.stderr +++ b/src/test/ui/derives/deriving-bounds.stderr @@ -1,10 +1,22 @@ -error: this unsafe trait should be implemented explicitly +error: cannot find derive macro `Send` in this scope + --> $DIR/deriving-bounds.rs:1:10 + | +LL | #[derive(Send)] + | ^^^^ + | +note: unsafe traits like `Send` should be implemented explicitly --> $DIR/deriving-bounds.rs:1:10 | LL | #[derive(Send)] | ^^^^ -error: this unsafe trait should be implemented explicitly +error: cannot find derive macro `Sync` in this scope + --> $DIR/deriving-bounds.rs:5:10 + | +LL | #[derive(Sync)] + | ^^^^ + | +note: unsafe traits like `Sync` should be implemented explicitly --> $DIR/deriving-bounds.rs:5:10 | LL | #[derive(Sync)] diff --git a/src/test/ui/issues/issue-33571.rs b/src/test/ui/issues/issue-33571.rs index 223bbc3ff5e21..147fb3fa8cf33 100644 --- a/src/test/ui/issues/issue-33571.rs +++ b/src/test/ui/issues/issue-33571.rs @@ -1,5 +1,5 @@ #[derive(Clone, - Sync, //~ ERROR this unsafe trait should be implemented explicitly + Sync, //~ ERROR cannot find derive macro `Sync` in this scope Copy)] enum Foo {} diff --git a/src/test/ui/issues/issue-33571.stderr b/src/test/ui/issues/issue-33571.stderr index 5d83a08e90757..78e7202077498 100644 --- a/src/test/ui/issues/issue-33571.stderr +++ b/src/test/ui/issues/issue-33571.stderr @@ -1,4 +1,10 @@ -error: this unsafe trait should be implemented explicitly +error: cannot find derive macro `Sync` in this scope + --> $DIR/issue-33571.rs:2:10 + | +LL | Sync, + | ^^^^ + | +note: unsafe traits like `Sync` should be implemented explicitly --> $DIR/issue-33571.rs:2:10 | LL | Sync, From a257dff99cc0717f4ed2de02b8a4496206c03364 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 24 Jun 2019 04:36:13 +0900 Subject: [PATCH 04/13] Add test for issue-38591 --- src/test/ui/issues/issue-38591.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/test/ui/issues/issue-38591.rs diff --git a/src/test/ui/issues/issue-38591.rs b/src/test/ui/issues/issue-38591.rs new file mode 100644 index 0000000000000..7aa71f8b9eb9b --- /dev/null +++ b/src/test/ui/issues/issue-38591.rs @@ -0,0 +1,10 @@ +// run-pass + +struct S { + t : T, + s : Box> +} + +fn f(x : S) {} + +fn main () {} From c7e1f4dcb78739fae7127c9d1ede182420f08a70 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 24 Jun 2019 09:41:29 +0200 Subject: [PATCH 05/13] HIR: remove the NodeId get_parent_node, HirIdify is_argument --- src/librustc/hir/map/mod.rs | 23 ++++++++--------------- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc_save_analysis/lib.rs | 5 ++++- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 0b8b69be0a480..b31941f28392d 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -615,23 +615,16 @@ impl<'hir> Map<'hir> { result } - /// Similar to `get_parent`; returns the parent node-ID, or just `hir_id` if there - /// is no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself + /// Similar to `get_parent`; returns the parent HIR Id, or just `hir_id` if there + /// is no parent. Note that the parent may be `CRATE_HIR_ID`, which is not itself /// present in the map, so passing the return value of `get_parent_node` to /// `get` may in fact panic. - /// This function returns the immediate parent in the AST, whereas `get_parent` + /// This function returns the immediate parent in the HIR, whereas `get_parent` /// returns the enclosing item. Note that this might not be the actual parent - /// node in the AST -- some kinds of nodes are not in the map and these will + /// node in the HIR -- some kinds of nodes are not in the map and these will /// never appear as the parent node. Thus, you can always walk the parent nodes - /// from a node to the root of the AST (unless you get back the same ID here, + /// from a node to the root of the HIR (unless you get back the same ID here, /// which can happen if the ID is not in the map itself or is just weird). - pub fn get_parent_node(&self, id: NodeId) -> NodeId { - let hir_id = self.node_to_hir_id(id); - let parent_hir_id = self.get_parent_node_by_hir_id(hir_id); - self.hir_to_node_id(parent_hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_parent_node_by_hir_id(&self, hir_id: HirId) -> HirId { if self.dep_graph.is_fully_enabled() { let hir_id_owner = hir_id.owner; @@ -646,12 +639,12 @@ impl<'hir> Map<'hir> { /// Check if the node is an argument. An argument is a local variable whose /// immediate parent is an item or a closure. - pub fn is_argument(&self, id: NodeId) -> bool { - match self.find(id) { + pub fn is_argument(&self, id: HirId) -> bool { + match self.find_by_hir_id(id) { Some(Node::Binding(_)) => (), _ => return false, } - match self.find(self.get_parent_node(id)) { + match self.find_by_hir_id(self.get_parent_node_by_hir_id(id)) { Some(Node::Item(_)) | Some(Node::TraitItem(_)) | Some(Node::ImplItem(_)) => true, diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 10796abe5d4c4..e7253a73bd418 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1526,7 +1526,7 @@ impl<'tcx> cmt_<'tcx> { "non-place".into() } Categorization::Local(vid) => { - if tcx.hir().is_argument(tcx.hir().hir_to_node_id(vid)) { + if tcx.hir().is_argument(vid) { "argument" } else { "local variable" diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 23fe150c6ff65..edee8eeaeb30c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -621,7 +621,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { Node::PathSegment(seg) => { match seg.res { Some(res) if res != Res::Err => res, - _ => self.get_path_res(self.tcx.hir().get_parent_node(id)), + _ => { + let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node)) + }, } } From d08bd72e977d05f7fe6d1140e10d7311f64f0f21 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 24 Jun 2019 09:46:38 +0200 Subject: [PATCH 06/13] HIR: rename get_parent_node_by_hir_id to get_parent_node --- src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/mod.rs | 14 +++++++------- src/librustc/middle/resolve_lifetime.rs | 4 ++-- src/librustc/traits/error_reporting.rs | 4 ++-- src/librustc/ty/context.rs | 4 ++-- .../borrowck/gather_loans/gather_moves.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 4 ++-- src/librustc_driver/pretty.rs | 2 +- src/librustc_lint/types.rs | 4 ++-- src/librustc_mir/hair/cx/expr.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_privacy/lib.rs | 6 +++--- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_typeck/astconv.rs | 4 ++-- src/librustc_typeck/check/_match.rs | 12 ++++++------ src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/coercion.rs | 4 ++-- src/librustc_typeck/check/demand.rs | 10 +++++----- src/librustc_typeck/check/method/suggest.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/collect.rs | 2 +- 21 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 8c5fa97d4b72d..351f5818f7e67 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -87,7 +87,7 @@ impl<'a> Code<'a> { match map.get(id) { map::Node::Block(_) => { // Use the parent, hopefully an expression node. - Code::from_node(map, map.get_parent_node_by_hir_id(id)) + Code::from_node(map, map.get_parent_node(id)) } map::Node::Expr(expr) => Some(Code::Expr(expr)), node => FnLikeNode::from_node(node).map(Code::FnLike) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index b31941f28392d..bb39f85e1c3bd 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -347,7 +347,7 @@ impl<'hir> Map<'hir> { if variant_data.ctor_hir_id().is_none() { return None; } - let ctor_of = match self.find_by_hir_id(self.get_parent_node_by_hir_id(hir_id)) { + let ctor_of = match self.find_by_hir_id(self.get_parent_node(hir_id)) { Some(Node::Item(..)) => def::CtorOf::Struct, Some(Node::Variant(..)) => def::CtorOf::Variant, _ => unreachable!(), @@ -424,7 +424,7 @@ impl<'hir> Map<'hir> { /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { - let parent = self.get_parent_node_by_hir_id(hir_id); + let parent = self.get_parent_node(hir_id); assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id))); parent } @@ -485,7 +485,7 @@ impl<'hir> Map<'hir> { match self.get(id) { Node::Item(&Item { node: ItemKind::Trait(..), .. }) | Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id, - Node::GenericParam(_) => self.get_parent_node_by_hir_id(id), + Node::GenericParam(_) => self.get_parent_node(id), _ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id)) } } @@ -625,7 +625,7 @@ impl<'hir> Map<'hir> { /// never appear as the parent node. Thus, you can always walk the parent nodes /// from a node to the root of the HIR (unless you get back the same ID here, /// which can happen if the ID is not in the map itself or is just weird). - pub fn get_parent_node_by_hir_id(&self, hir_id: HirId) -> HirId { + pub fn get_parent_node(&self, hir_id: HirId) -> HirId { if self.dep_graph.is_fully_enabled() { let hir_id_owner = hir_id.owner; let def_path_hash = self.definitions.def_path_hash(hir_id_owner); @@ -644,7 +644,7 @@ impl<'hir> Map<'hir> { Some(Node::Binding(_)) => (), _ => return false, } - match self.find_by_hir_id(self.get_parent_node_by_hir_id(id)) { + match self.find_by_hir_id(self.get_parent_node(id)) { Some(Node::Item(_)) | Some(Node::TraitItem(_)) | Some(Node::ImplItem(_)) => true, @@ -680,7 +680,7 @@ impl<'hir> Map<'hir> { { let mut id = start_id; loop { - let parent_id = self.get_parent_node_by_hir_id(id); + let parent_id = self.get_parent_node(id); if parent_id == CRATE_HIR_ID { return Ok(CRATE_HIR_ID); } @@ -1022,7 +1022,7 @@ impl<'hir> Map<'hir> { Some(Node::Arm(arm)) => arm.span, Some(Node::Block(block)) => block.span, Some(Node::Ctor(..)) => match self.find_by_hir_id( - self.get_parent_node_by_hir_id(hir_id)) + self.get_parent_node(hir_id)) { Some(Node::Item(item)) => item.span, Some(Node::Variant(variant)) => variant.span, diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index b8e7db99d071c..ac2124f4a161f 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -662,7 +662,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { if let Some(Region::LateBound(_, def_id, _)) = def { if let Some(hir_id) = self.tcx.hir().as_local_hir_id(def_id) { // Ensure that the parent of the def is an item, not HRTB - let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent_id = self.tcx.hir().get_parent_node(hir_id); let parent_impl_id = hir::ImplItemId { hir_id: parent_id }; let parent_trait_id = hir::TraitItemId { hir_id: parent_id }; let krate = self.tcx.hir().forest.krate(); @@ -2051,7 +2051,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // and whether there's a `self` argument (treated specially). let mut assoc_item_kind = None; let mut impl_self = None; - let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id); + let parent = self.tcx.hir().get_parent_node(output.hir_id); let body = match self.tcx.hir().get(parent) { // `fn` definitions and methods. Node::Item(&hir::Item { diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index b433098c1b265..f99d68469765a 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -938,7 +938,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'tcx>, ) { if let &ObligationCauseCode::VariableType(hir_id) = code { - let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent_node = self.tcx.hir().get_parent_node(hir_id); if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) { if let Some(ref expr) = local.init { if let hir::ExprKind::Index(_, _) = expr.node { @@ -1013,7 +1013,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { trait_ref: &ty::Binder>, ) { let hir = self.tcx.hir(); - let parent_node = hir.get_parent_node_by_hir_id(obligation.cause.body_id); + let parent_node = hir.get_parent_node(obligation.cause.body_id); let node = hir.find_by_hir_id(parent_node); if let Some(hir::Node::Item(hir::Item { node: hir::ItemKind::Fn(decl, _, _, body_id), diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 28399ed5439f7..45822fcba7ba4 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2880,7 +2880,7 @@ impl<'tcx> TyCtxt<'tcx> { if lint::maybe_lint_level_root(self, id) { return id; } - let next = self.hir().get_parent_node_by_hir_id(id); + let next = self.hir().get_parent_node(id); if next == id { bug!("lint traversal reached the root of the crate"); } @@ -2898,7 +2898,7 @@ impl<'tcx> TyCtxt<'tcx> { if let Some(pair) = sets.level_and_source(lint, id, self.sess) { return pair } - let next = self.hir().get_parent_node_by_hir_id(id); + let next = self.hir().get_parent_node(id); if next == id { bug!("lint traversal reached the root of the crate"); } diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index fa286632dac84..658e4307348db 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -47,7 +47,7 @@ pub enum PatternSource<'tcx> { /// with a reference to the let fn get_pattern_source<'tcx>(tcx: TyCtxt<'tcx>, pat: &Pat) -> PatternSource<'tcx> { - let parent = tcx.hir().get_parent_node_by_hir_id(pat.hir_id); + let parent = tcx.hir().get_parent_node(pat.hir_id); match tcx.hir().get(parent) { Node::Expr(ref e) => { diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 87c0b8563cadb..4ff669ddad9ca 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1189,7 +1189,7 @@ impl BorrowckCtxt<'_, 'tcx> { } fn local_ty(&self, hir_id: hir::HirId) -> (Option<&hir::Ty>, bool) { - let parent = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent = self.tcx.hir().get_parent_node(hir_id); let parent_node = self.tcx.hir().get(parent); // The parent node is like a fn @@ -1287,7 +1287,7 @@ impl BorrowckCtxt<'_, 'tcx> { }, )) = ty.map(|t| &t.node) { - let borrow_expr_id = self.tcx.hir().get_parent_node_by_hir_id(borrowed_hir_id); + let borrow_expr_id = self.tcx.hir().get_parent_node(borrowed_hir_id); db.span_suggestion( self.tcx.hir().span(borrow_expr_id), "consider removing the `&mut`, as it is an \ diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 030166182490b..1b78f77e4f915 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -631,7 +631,7 @@ fn print_flowgraph<'tcx, W: Write>( if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) { break n.body(); } - let parent = tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent = tcx.hir().get_parent_node(hir_id); assert_ne!(hir_id, parent); hir_id = parent; } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 2fb534e8228e6..d0258ca30c507 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -275,7 +275,7 @@ fn lint_int_literal<'a, 'tcx>( return; } - let par_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id); + let par_id = cx.tcx.hir().get_parent_node(e.hir_id); if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) { if let hir::ExprKind::Struct(..) = par_e.node { if is_range_literal(cx.sess(), par_e) @@ -314,7 +314,7 @@ fn lint_uint_literal<'a, 'tcx>( _ => bug!(), }; if lit_val < min || lit_val > max { - let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id); + let parent_id = cx.tcx.hir().get_parent_node(e.hir_id); if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) { match par_e.node { hir::ExprKind::Cast(..) => { diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 597f172da671f..94b4f6e8dd1c5 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -909,7 +909,7 @@ fn convert_path_expr<'a, 'tcx>( Res::Def(DefKind::ConstParam, def_id) => { let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap(); - let item_id = cx.tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_id = cx.tcx.hir().get_parent_node(hir_id); let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(item_id); let generics = cx.tcx.generics_of(item_def_id); let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 9c78d761cb2ca..545336a5906bb 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -570,7 +570,7 @@ fn is_enclosed( used_unsafe: &FxHashSet, id: hir::HirId, ) -> Option<(String, hir::HirId)> { - let parent_id = tcx.hir().get_parent_node_by_hir_id(id); + let parent_id = tcx.hir().get_parent_node(id); if parent_id != id { if used_unsafe.contains(&parent_id) { Some(("block".to_string(), parent_id)) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 0fdc9ac890350..e95911bbec29a 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -247,7 +247,7 @@ fn def_id_visibility<'tcx>( } } Node::Ctor(vdata) => { - let parent_hir_id = tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent_hir_id = tcx.hir().get_parent_node(hir_id); match tcx.hir().get(parent_hir_id) { Node::Variant(..) => { let parent_did = tcx.hir().local_def_id_from_hir_id(parent_hir_id); @@ -784,7 +784,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { if module_id == hir::CRATE_HIR_ID { break } - module_id = self.tcx.hir().get_parent_node_by_hir_id(module_id); + module_id = self.tcx.hir().get_parent_node(module_id); } } } @@ -1674,7 +1674,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { has_old_errors = true; break; } - let parent = self.tcx.hir().get_parent_node_by_hir_id(id); + let parent = self.tcx.hir().get_parent_node(id); if parent == id { break; } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index edee8eeaeb30c..750222451db6f 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -622,7 +622,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { match seg.res { Some(res) if res != Res::Err => res, _ => { - let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent_node = self.tcx.hir().get_parent_node(hir_id); self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node)) }, } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 33d9b1ff0c6ce..0375ad4a08f26 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2000,7 +2000,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.prohibit_generics(&path.segments); let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_id = tcx.hir().get_parent_node(hir_id); let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&def_id]; @@ -2190,7 +2190,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // Find the name and index of the const parameter by indexing the generics of the // parent item and construct a `ParamConst`. let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_id = tcx.hir().get_parent_node(hir_id); let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)]; diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 293b68c871131..b435c99ad01f5 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -546,7 +546,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let tcx = self.tcx; if let PatKind::Binding(..) = inner.node { - let parent_id = tcx.hir().get_parent_node_by_hir_id(pat.hir_id); + let parent_id = tcx.hir().get_parent_node(pat.hir_id); let parent = tcx.hir().get(parent_id); debug!("inner {:?} pat {:?} parent {:?}", inner, pat, parent); match parent { @@ -808,16 +808,16 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); use hir::Node::{Block, Item, Local}; let hir = self.tcx.hir(); - let arm_id = hir.get_parent_node_by_hir_id(hir_id); - let match_id = hir.get_parent_node_by_hir_id(arm_id); - let containing_id = hir.get_parent_node_by_hir_id(match_id); + let arm_id = hir.get_parent_node(hir_id); + let match_id = hir.get_parent_node(arm_id); + let containing_id = hir.get_parent_node(match_id); let node = hir.get(containing_id); if let Block(block) = node { // check that the body's parent is an fn let parent = hir.get( - hir.get_parent_node_by_hir_id( - hir.get_parent_node_by_hir_id(block.hir_id), + hir.get_parent_node( + hir.get_parent_node(block.hir_id), ), ); if let (Some(expr), Item(hir::Item { diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 87807ad91a27d..e6999f9e3ac8a 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -244,7 +244,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { callee_node: &hir::ExprKind, callee_span: Span, ) { - let hir_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let hir_id = self.tcx.hir().get_parent_node(hir_id); let parent_node = self.tcx.hir().get(hir_id); if let ( hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, sp, ..), .. }), diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 71a0ca090b0d8..4bd2f216224a5 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -1231,7 +1231,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { db.span_label(cause.span, "return type is not `()`"); } ObligationCauseCode::BlockTailExpression(blk_id) => { - let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(blk_id); + let parent_id = fcx.tcx.hir().get_parent_node(blk_id); db = self.report_return_mismatched_types( cause, expected, @@ -1281,7 +1281,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { // Verify that this is a tail expression of a function, otherwise the // label pointing out the cause for the type coercion will be wrong // as prior return coercions would not be relevant (#57664). - let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(id); + let parent_id = fcx.tcx.hir().get_parent_node(id); let fn_decl = if let Some((expr, blk_id)) = expression { pointing_at_return_type = fcx.suggest_mismatched_types_on_tail( &mut db, diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index aff8eba3130d6..180b1eadd6818 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -236,13 +236,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Option<(Span, &'static str, String)> { if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = expr.node { if let hir::def::Res::Local(id) = path.res { - let parent = self.tcx.hir().get_parent_node_by_hir_id(id); + let parent = self.tcx.hir().get_parent_node(id); if let Some(Node::Expr(hir::Expr { hir_id, node: hir::ExprKind::Closure(_, decl, ..), .. })) = self.tcx.hir().find_by_hir_id(parent) { - let parent = self.tcx.hir().get_parent_node_by_hir_id(*hir_id); + let parent = self.tcx.hir().get_parent_node(*hir_id); if let (Some(Node::Expr(hir::Expr { node: hir::ExprKind::MethodCall(path, span, expr), .. @@ -276,7 +276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sp: Span, ) -> bool { let cm = self.sess().source_map(); - let parent_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id); + let parent_id = self.tcx.hir().get_parent_node(hir_id); if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) { // Account for fields if let Node::Expr(hir::Expr { @@ -422,7 +422,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { node: hir::ExprKind::Assign(left_expr, _), .. })) = self.tcx.hir().find_by_hir_id( - self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id), + self.tcx.hir().get_parent_node(expr.hir_id), ) { if mutability == hir::Mutability::MutMutable { // Found the following case: @@ -551,7 +551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(hir::Node::Expr(hir::Expr { node: hir::ExprKind::Struct(_, fields, _), .. - })) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id)) { + })) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node(expr.hir_id)) { // `expr` is a literal field for a struct, only suggest if appropriate for field in fields { if field.expr.hir_id == expr.hir_id && field.is_shorthand { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 8ad67c2adc035..fa1b07d2dcfcd 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -269,7 +269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let filename = tcx.sess.source_map().span_to_filename(span); let parent_node = self.tcx.hir().get( - self.tcx.hir().get_parent_node_by_hir_id(hir_id), + self.tcx.hir().get_parent_node(hir_id), ); let msg = format!( "you must specify a type for this binding, like `{}`", @@ -390,7 +390,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } else { let call_expr = self.tcx.hir().expect_expr( - self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id), + self.tcx.hir().get_parent_node(expr.hir_id), ); if let Some(span) = call_expr.span.trim_start(item_name.span) { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0ec5c9763a0fb..2da761f6d37df 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4259,7 +4259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // If our calling expression is indeed the function itself, we're good! // If not, generate an error that this can only be called directly. if let Node::Expr(expr) = self.tcx.hir().get( - self.tcx.hir().get_parent_node_by_hir_id(hir_id)) + self.tcx.hir().get_parent_node(hir_id)) { if let ExprKind::Call(ref callee, ..) = expr.node { if callee.hir_id == hir_id { @@ -4334,7 +4334,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut contained_in_place = false; while let hir::Node::Expr(parent_expr) = - self.tcx.hir().get(self.tcx.hir().get_parent_node_by_hir_id(expr_id)) + self.tcx.hir().get(self.tcx.hir().get_parent_node(expr_id)) { match &parent_expr.node { hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 301168aefd203..87e1166b7c041 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1298,7 +1298,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op } Node::AnonConst(_) => { - let parent_node = tcx.hir().get(tcx.hir().get_parent_node_by_hir_id(hir_id)); + let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); match parent_node { Node::Ty(&hir::Ty { node: hir::TyKind::Array(_, ref constant), From 90de9edce576d03bd6e7e5d294fa44d8d1ef8a5a Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 24 Jun 2019 09:55:11 +0200 Subject: [PATCH 07/13] HIR: remove the NodeId find --- src/librustc/hir/map/mod.rs | 6 ------ src/librustc_driver/pretty.rs | 4 ++-- src/librustc_mir/build/mod.rs | 3 +-- src/librustc_save_analysis/lib.rs | 11 ++++++++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index bb39f85e1c3bd..ea18a73577cf0 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -595,12 +595,6 @@ impl<'hir> Map<'hir> { } /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. - pub fn find(&self, id: NodeId) -> Option> { - let hir_id = self.node_to_hir_id(id); - self.find_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn find_by_hir_id(&self, hir_id: HirId) -> Option> { let result = self.find_entry(hir_id).and_then(|entry| { if let Node::Crate = entry.node { diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 1b78f77e4f915..ff0e6aacef138 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -907,11 +907,11 @@ fn print_with_analysis<'tcx>( let nodeid = nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \ suffix (b::c::d)"); - let node = tcx.hir().find(nodeid).unwrap_or_else(|| { + let hir_id = tcx.hir().node_to_hir_id(nodeid); + let node = tcx.hir().find_by_hir_id(hir_id).unwrap_or_else(|| { tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid)) }); - let hir_id = tcx.hir().node_to_hir_id(nodeid); match blocks::Code::from_node(&tcx.hir(), hir_id) { Some(code) => { let variants = gather_flowgraph_variants(tcx.sess); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 66064221b391c..1cc15ca484eca 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -552,7 +552,6 @@ where .into_iter() .flatten() .map(|(&var_hir_id, &upvar_id)| { - let var_node_id = tcx_hir.hir_to_node_id(var_hir_id); let capture = hir_tables.upvar_capture(upvar_id); let by_ref = match capture { ty::UpvarCapture::ByValue => false, @@ -563,7 +562,7 @@ where by_ref, }; let mut mutability = Mutability::Not; - if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) { + if let Some(Node::Binding(pat)) = tcx_hir.find_by_hir_id(var_hir_id) { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { debuginfo.debug_name = ident.name; if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 750222451db6f..3d88b2347c17a 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -410,7 +410,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { let mut decl_id = None; let mut docs = String::new(); let mut attrs = vec![]; - if let Some(Node::ImplItem(item)) = self.tcx.hir().find(id) { + let hir_id = self.tcx.hir().node_to_hir_id(id); + if let Some(Node::ImplItem(item)) = + self.tcx.hir().find_by_hir_id(hir_id) + { docs = self.docs_for_attrs(&item.attrs); attrs = item.attrs.to_vec(); } @@ -451,8 +454,9 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { Some(def_id) => { let mut docs = String::new(); let mut attrs = vec![]; + let hir_id = self.tcx.hir().node_to_hir_id(id); - if let Some(Node::TraitItem(item)) = self.tcx.hir().find(id) { + if let Some(Node::TraitItem(item)) = self.tcx.hir().find_by_hir_id(hir_id) { docs = self.docs_for_attrs(&item.attrs); attrs = item.attrs.to_vec(); } @@ -521,7 +525,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { } match expr.node { ast::ExprKind::Field(ref sub_ex, ident) => { - let hir_node = match self.tcx.hir().find(sub_ex.id) { + let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id); + let hir_node = match self.tcx.hir().find_by_hir_id(sub_ex_hir_id) { Some(Node::Expr(expr)) => expr, _ => { debug!( From f05cbc98f8402f3146f96ebde63148427b3322f1 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 24 Jun 2019 09:58:49 +0200 Subject: [PATCH 08/13] HIR: rename find_by_hir_id to find --- src/librustc/hir/map/mod.rs | 32 +++++++++---------- src/librustc/infer/error_reporting/mod.rs | 4 +-- src/librustc/infer/opaque_types/mod.rs | 2 +- src/librustc/middle/dead.rs | 4 +-- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/reachable.rs | 6 ++-- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/traits/error_reporting.rs | 4 +-- src/librustc/ty/context.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_driver/pretty.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- .../borrow_check/mutability_errors.rs | 4 +-- src/librustc_mir/build/mod.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_passes/loops.rs | 4 +-- src/librustc_privacy/lib.rs | 2 +- src/librustc_save_analysis/lib.rs | 6 ++-- src/librustc_typeck/check/demand.rs | 10 +++--- src/librustc_typeck/check_unused.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 2 +- src/librustc_typeck/lib.rs | 4 +-- 22 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index ea18a73577cf0..3d591c9a1c6bd 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -292,7 +292,7 @@ impl<'hir> Map<'hir> { } fn def_kind(&self, hir_id: HirId) -> Option { - let node = if let Some(node) = self.find_by_hir_id(hir_id) { + let node = if let Some(node) = self.find(hir_id) { node } else { return None @@ -347,7 +347,7 @@ impl<'hir> Map<'hir> { if variant_data.ctor_hir_id().is_none() { return None; } - let ctor_of = match self.find_by_hir_id(self.get_parent_node(hir_id)) { + let ctor_of = match self.find(self.get_parent_node(hir_id)) { Some(Node::Item(..)) => def::CtorOf::Struct, Some(Node::Variant(..)) => def::CtorOf::Variant, _ => unreachable!(), @@ -563,7 +563,7 @@ impl<'hir> Map<'hir> { /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. pub fn get(&self, id: HirId) -> Node<'hir> { // read recorded by `find` - self.find_by_hir_id(id).unwrap_or_else(|| + self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id)) } @@ -595,7 +595,7 @@ impl<'hir> Map<'hir> { } /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found. - pub fn find_by_hir_id(&self, hir_id: HirId) -> Option> { + pub fn find(&self, hir_id: HirId) -> Option> { let result = self.find_entry(hir_id).and_then(|entry| { if let Node::Crate = entry.node { None @@ -634,11 +634,11 @@ impl<'hir> Map<'hir> { /// Check if the node is an argument. An argument is a local variable whose /// immediate parent is an item or a closure. pub fn is_argument(&self, id: HirId) -> bool { - match self.find_by_hir_id(id) { + match self.find(id) { Some(Node::Binding(_)) => (), _ => return false, } - match self.find_by_hir_id(self.get_parent_node(id)) { + match self.find(self.get_parent_node(id)) { Some(Node::Item(_)) | Some(Node::TraitItem(_)) | Some(Node::ImplItem(_)) => true, @@ -859,28 +859,28 @@ impl<'hir> Map<'hir> { } pub fn expect_item(&self, id: HirId) -> &'hir Item { - match self.find_by_hir_id(id) { // read recorded by `find` + 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: HirId) -> &'hir ImplItem { - match self.find_by_hir_id(id) { + 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: HirId) -> &'hir TraitItem { - match self.find_by_hir_id(id) { + 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: HirId) -> &'hir VariantData { - match self.find_by_hir_id(id) { + match self.find(id) { Some(Node::Item(i)) => { match i.node { ItemKind::Struct(ref struct_def, _) | @@ -895,21 +895,21 @@ impl<'hir> Map<'hir> { } pub fn expect_variant(&self, id: HirId) -> &'hir Variant { - match self.find_by_hir_id(id) { + 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: HirId) -> &'hir ForeignItem { - match self.find_by_hir_id(id) { + 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: HirId) -> &'hir Expr { - match self.find_by_hir_id(id) { // read recorded by find + match self.find(id) { // read recorded by find Some(Node::Expr(expr)) => expr, _ => bug!("expected expr, found {}", self.node_to_string(id)) } @@ -1015,7 +1015,7 @@ impl<'hir> Map<'hir> { Some(Node::Pat(pat)) => pat.span, Some(Node::Arm(arm)) => arm.span, Some(Node::Block(block)) => block.span, - Some(Node::Ctor(..)) => match self.find_by_hir_id( + Some(Node::Ctor(..)) => match self.find( self.get_parent_node(hir_id)) { Some(Node::Item(item)) => item.span, @@ -1087,7 +1087,7 @@ impl<'a> NodesMatchingSuffix<'a> { // chain, then returns `None`. fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: HirId) -> Option<(HirId, Name)> { loop { - if let Node::Item(item) = map.find_by_hir_id(id)? { + if let Node::Item(item) = map.find(id)? { if item_is_mod(&item) { return Some((id, item.ident.name)) } @@ -1260,7 +1260,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { }) }; - match map.find_by_hir_id(id) { + match map.find(id) { Some(Node::Item(item)) => { let item_str = match item.node { ItemKind::ExternCrate(..) => "extern crate", diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index d1e32b1dbad36..65225163a25a4 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> { ) }; let span = scope.span(self, region_scope_tree); - let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) { + let tag = match self.hir().find(scope.hir_id(region_scope_tree)) { Some(Node::Block(_)) => "block", Some(Node::Expr(expr)) => match expr.node { hir::ExprKind::Call(..) => "call", @@ -182,7 +182,7 @@ impl<'tcx> TyCtxt<'tcx> { let scope = region.free_region_binding_scope(self); let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); - let tag = match self.hir().find_by_hir_id(node) { + let tag = match self.hir().find(node) { Some(Node::Block(_)) | Some(Node::Expr(_)) => "body", Some(Node::Item(it)) => Self::item_scope_tag(&it), Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it), diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index a687b0e459100..6b6dbd43167fa 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -777,7 +777,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { .local_def_id_from_hir_id(opaque_parent_hir_id) }; let (in_definition_scope, origin) = - match tcx.hir().find_by_hir_id(opaque_hir_id) + match tcx.hir().find(opaque_hir_id) { Some(Node::Item(item)) => match item.node { // Anonymous `impl Trait` diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 9e2038fa89ed0..e02ee8943603a 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -27,7 +27,7 @@ use syntax_pos; // function, then we should explore its block to check for codes that // may need to be marked as live. fn should_explore<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> bool { - match tcx.hir().find_by_hir_id(hir_id) { + match tcx.hir().find(hir_id) { Some(Node::Item(..)) | Some(Node::ImplItem(..)) | Some(Node::ForeignItem(..)) | @@ -145,7 +145,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { // tuple struct constructor function let id = self.struct_constructors.get(&id).cloned().unwrap_or(id); - if let Some(node) = self.tcx.hir().find_by_hir_id(id) { + if let Some(node) = self.tcx.hir().find(id) { self.live_symbols.insert(id); self.visit_node(node); } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 0d59e32b09818..bea10e914d038 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -369,7 +369,7 @@ fn visit_fn<'tcx>( // Don't run unused pass for #[derive()] if let FnKind::Method(..) = fk { let parent = ir.tcx.hir().get_parent_item(id); - if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) { + if let Some(Node::Item(i)) = ir.tcx.hir().find(parent) { if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) { return; } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 593c5e7342168..d607c35f8762b 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -53,7 +53,7 @@ fn method_might_be_inlined<'tcx>( return true } if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_src) { - match tcx.hir().find_by_hir_id(impl_hir_id) { + match tcx.hir().find(impl_hir_id) { Some(Node::Item(item)) => item_might_be_inlined(tcx, &item, codegen_fn_attrs), Some(..) | None => @@ -147,7 +147,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { None => { return false; } }; - match self.tcx.hir().find_by_hir_id(hir_id) { + match self.tcx.hir().find(hir_id) { Some(Node::Item(item)) => { match item.node { hir::ItemKind::Fn(..) => @@ -205,7 +205,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { continue } - if let Some(ref item) = self.tcx.hir().find_by_hir_id(search_item) { + if let Some(ref item) = self.tcx.hir().find(search_item) { self.propagate_node(item, search_item); } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index ac2124f4a161f..412346bab257e 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1489,7 +1489,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } }; if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) { - if let Some(parent) = self.tcx.hir().find_by_hir_id( + if let Some(parent) = self.tcx.hir().find( self.tcx.hir().get_parent_item(hir_lifetime.hir_id)) { match parent { diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index f99d68469765a..f54575ff8fc1d 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -939,7 +939,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ) { if let &ObligationCauseCode::VariableType(hir_id) = code { let parent_node = self.tcx.hir().get_parent_node(hir_id); - if let Some(Node::Local(ref local)) = self.tcx.hir().find_by_hir_id(parent_node) { + if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) { if let Some(ref expr) = local.init { if let hir::ExprKind::Index(_, _) = expr.node { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) { @@ -1014,7 +1014,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ) { let hir = self.tcx.hir(); let parent_node = hir.get_parent_node(obligation.cause.body_id); - let node = hir.find_by_hir_id(parent_node); + let node = hir.find(parent_node); if let Some(hir::Node::Item(hir::Item { node: hir::ItemKind::Fn(decl, _, _, body_id), .. diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 45822fcba7ba4..4710d611d99df 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1589,7 +1589,7 @@ impl<'tcx> TyCtxt<'tcx> { let hir_id = self.hir() .as_local_hir_id(suitable_region_binding_scope) .unwrap(); - let is_impl_item = match self.hir().find_by_hir_id(hir_id) { + let is_impl_item = match self.hir().find(hir_id) { Some(Node::Item(..)) | Some(Node::TraitItem(..)) => false, Some(Node::ImplItem(..)) => { self.is_bound_region_in_impl_item(suitable_region_binding_scope) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 4ff669ddad9ca..3c7f19f7fbf4f 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1022,7 +1022,7 @@ impl BorrowckCtxt<'_, 'tcx> { if let ty::ReScope(scope) = *super_scope { let hir_id = scope.hir_id(&self.region_scope_tree); - match self.tcx.hir().find_by_hir_id(hir_id) { + match self.tcx.hir().find(hir_id) { Some(Node::Stmt(_)) => { if *sub_scope != ty::ReStatic { db.note("consider using a `let` binding to increase its lifetime"); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index ff0e6aacef138..87f7f2fdb48b2 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -908,7 +908,7 @@ fn print_with_analysis<'tcx>( nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \ suffix (b::c::d)"); let hir_id = tcx.hir().node_to_hir_id(nodeid); - let node = tcx.hir().find_by_hir_id(hir_id).unwrap_or_else(|| { + let node = tcx.hir().find(hir_id).unwrap_or_else(|| { tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid)) }); diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 1a4b12b03d831..12719c3b9d303 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -405,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { // reported for missing docs. let real_trait = trait_ref.path.res.def_id(); if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(real_trait) { - match cx.tcx.hir().find_by_hir_id(hir_id) { + match cx.tcx.hir().find(hir_id) { Some(Node::Item(item)) => { if let hir::VisibilityKind::Inherited = item.vis.node { for impl_item_ref in impl_item_refs { diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index fc11cd82f8a9a..92c2e4e01f760 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -304,7 +304,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err.span_label(span, format!("cannot {ACT}", ACT = act)); let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id; - if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find_by_hir_id(upvar_hir_id) + if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) { if let hir::PatKind::Binding( hir::BindingAnnotation::Unannotated, @@ -633,7 +633,7 @@ fn annotate_struct_field( let field = def.all_fields().nth(field.index())?; // Use the HIR types to construct the diagnostic message. let hir_id = tcx.hir().as_local_hir_id(field.did)?; - let node = tcx.hir().find_by_hir_id(hir_id)?; + let node = tcx.hir().find(hir_id)?; // Now we're dealing with the actual struct that we're going to suggest a change to, // we can expect a field that is an immutable reference to a type. if let hir::Node::Field(field) = node { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 1cc15ca484eca..311b6aa0c14de 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -562,7 +562,7 @@ where by_ref, }; let mut mutability = Mutability::Not; - if let Some(Node::Binding(pat)) = tcx_hir.find_by_hir_id(var_hir_id) { + if let Some(Node::Binding(pat)) = tcx_hir.find(var_hir_id) { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { debuginfo.debug_name = ident.name; if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) { diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 545336a5906bb..24df3549be481 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -577,7 +577,7 @@ fn is_enclosed( } else if let Some(Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, header, _, _), .. - })) = tcx.hir().find_by_hir_id(parent_id) { + })) = tcx.hir().find(parent_id) { match header.unsafety { hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)), hir::Unsafety::Normal => None, diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 1c18322259f80..ed0a78b465276 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -107,7 +107,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { }; if loop_id != hir::DUMMY_HIR_ID { - if let Node::Block(_) = self.hir_map.find_by_hir_id(loop_id).unwrap() { + if let Node::Block(_) = self.hir_map.find(loop_id).unwrap() { return } } @@ -155,7 +155,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> { match destination.target_id { Ok(loop_id) => { - if let Node::Block(block) = self.hir_map.find_by_hir_id(loop_id).unwrap() { + if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() { struct_span_err!(self.sess, e.span, E0696, "`continue` pointing to a labeled block") .span_label(e.span, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index e95911bbec29a..3e98200e53274 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1233,7 +1233,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { if let Some(hir_id) = self.tcx.hir().as_local_hir_id(did) { // .. and it corresponds to a private type in the AST (this returns // `None` for type parameters). - match self.tcx.hir().find_by_hir_id(hir_id) { + match self.tcx.hir().find(hir_id) { Some(Node::Item(ref item)) => !item.vis.node.is_pub(), Some(_) | None => false, } diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 3d88b2347c17a..19ed9e214073c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -412,7 +412,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { let mut attrs = vec![]; let hir_id = self.tcx.hir().node_to_hir_id(id); if let Some(Node::ImplItem(item)) = - self.tcx.hir().find_by_hir_id(hir_id) + self.tcx.hir().find(hir_id) { docs = self.docs_for_attrs(&item.attrs); attrs = item.attrs.to_vec(); @@ -456,7 +456,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { let mut attrs = vec![]; let hir_id = self.tcx.hir().node_to_hir_id(id); - if let Some(Node::TraitItem(item)) = self.tcx.hir().find_by_hir_id(hir_id) { + if let Some(Node::TraitItem(item)) = self.tcx.hir().find(hir_id) { docs = self.docs_for_attrs(&item.attrs); attrs = item.attrs.to_vec(); } @@ -526,7 +526,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { match expr.node { ast::ExprKind::Field(ref sub_ex, ident) => { let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id); - let hir_node = match self.tcx.hir().find_by_hir_id(sub_ex_hir_id) { + let hir_node = match self.tcx.hir().find(sub_ex_hir_id) { Some(Node::Expr(expr)) => expr, _ => { debug!( diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 180b1eadd6818..c469d3516e2d4 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -241,12 +241,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir_id, node: hir::ExprKind::Closure(_, decl, ..), .. - })) = self.tcx.hir().find_by_hir_id(parent) { + })) = self.tcx.hir().find(parent) { let parent = self.tcx.hir().get_parent_node(*hir_id); if let (Some(Node::Expr(hir::Expr { node: hir::ExprKind::MethodCall(path, span, expr), .. - })), 1) = (self.tcx.hir().find_by_hir_id(parent), decl.inputs.len()) { + })), 1) = (self.tcx.hir().find(parent), decl.inputs.len()) { let self_ty = self.tables.borrow().node_type(expr[0].hir_id); let self_ty = format!("{:?}", self_ty); let name = path.ident.as_str(); @@ -277,7 +277,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> bool { let cm = self.sess().source_map(); let parent_id = self.tcx.hir().get_parent_node(hir_id); - if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) { + if let Some(parent) = self.tcx.hir().find(parent_id) { // Account for fields if let Node::Expr(hir::Expr { node: hir::ExprKind::Struct(_, fields, ..), .. @@ -421,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(hir::Node::Expr(hir::Expr { node: hir::ExprKind::Assign(left_expr, _), .. - })) = self.tcx.hir().find_by_hir_id( + })) = self.tcx.hir().find( self.tcx.hir().get_parent_node(expr.hir_id), ) { if mutability == hir::Mutability::MutMutable { @@ -551,7 +551,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(hir::Node::Expr(hir::Expr { node: hir::ExprKind::Struct(_, fields, _), .. - })) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node(expr.hir_id)) { + })) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.hir_id)) { // `expr` is a literal field for a struct, only suggest if appropriate for field in fields { if field.expr.hir_id == expr.hir_id && field.is_shorthand { diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index 8f89a77bd1a3a..7e781eeec56a9 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -95,7 +95,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'tcx>) { // below it'll cause a panic because `def_id` is actually bogus at this // point in time otherwise. if let Some(id) = tcx.hir().as_local_hir_id(def_id) { - if tcx.hir().find_by_hir_id(id).is_none() { + if tcx.hir().find(id).is_none() { return false; } } diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index e392622060c9b..42deeaf31f427 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -52,7 +52,7 @@ fn visit_implementation_of_drop<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { } else { // Destructors only work on nominal types. if let Some(impl_hir_id) = tcx.hir().as_local_hir_id(impl_did) { - if let Some(Node::Item(item)) = tcx.hir().find_by_hir_id(impl_hir_id) { + if let Some(Node::Item(item)) = tcx.hir().find(impl_hir_id) { let span = match item.node { ItemKind::Impl(.., ref ty, _) => ty.span, _ => item.span, diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index ec0f431d9b25e..3bca41ca7e40d 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -182,7 +182,7 @@ fn check_main_fn_ty<'tcx>(tcx: TyCtxt<'tcx>, main_def_id: DefId) { let main_t = tcx.type_of(main_def_id); match main_t.sty { ty::FnDef(..) => { - if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(main_id) { + if let Some(Node::Item(it)) = tcx.hir().find(main_id) { if let hir::ItemKind::Fn(.., ref generics, _) = it.node { let mut error = false; if !generics.params.is_empty() { @@ -247,7 +247,7 @@ fn check_start_fn_ty<'tcx>(tcx: TyCtxt<'tcx>, start_def_id: DefId) { let start_t = tcx.type_of(start_def_id); match start_t.sty { ty::FnDef(..) => { - if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(start_id) { + if let Some(Node::Item(it)) = tcx.hir().find(start_id) { if let hir::ItemKind::Fn(.., ref generics, _) = it.node { let mut error = false; if !generics.params.is_empty() { From d82a12f64f05d33f10f0e345e14175c4256703f8 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 24 Jun 2019 10:03:37 +0200 Subject: [PATCH 09/13] HirIdify driver::pretty::HirPrinterSupport::node_path --- src/librustc_driver/pretty.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 87f7f2fdb48b2..d92f3aafa1c7e 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -253,10 +253,9 @@ trait HirPrinterSupport<'hir>: pprust_hir::PpAnn { fn pp_ann<'a>(&'a self) -> &'a dyn pprust_hir::PpAnn; /// Computes an user-readable representation of a path, if possible. - fn node_path(&self, id: ast::NodeId) -> Option { + fn node_path(&self, id: hir::HirId) -> Option { self.hir_map().and_then(|map| { - let hir_id = map.node_to_hir_id(id); - map.def_path_from_hir_id(hir_id) + map.def_path_from_hir_id(id) }).map(|path| { path.data .into_iter() @@ -471,8 +470,8 @@ impl<'b, 'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'b, 'tcx> { self } - fn node_path(&self, id: ast::NodeId) -> Option { - Some(self.tcx.def_path_str(self.tcx.hir().local_def_id(id))) + fn node_path(&self, id: hir::HirId) -> Option { + Some(self.tcx.def_path_str(self.tcx.hir().local_def_id_from_hir_id(id))) } } @@ -834,7 +833,7 @@ pub fn print_after_hir_lowering<'tcx>( let node = hir_map.get(hir_id); pp_state.print_node(node)?; pp_state.s.space()?; - let path = annotation.node_path(node_id) + let path = annotation.node_path(hir_id) .expect("-Z unpretty missing node paths"); pp_state.synth_comment(path)?; pp_state.s.hardbreak()?; From 87438a163ec153e2322b70e8c5c987c7c89be0b4 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 24 Jun 2019 10:17:04 +0200 Subject: [PATCH 10/13] HirIdification: miscellaneous bits --- src/librustc/middle/liveness.rs | 8 +++----- src/librustc/ty/inhabitedness/def_id_forest.rs | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index bea10e914d038..7b69fe394fb2c 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -110,7 +110,7 @@ use std::{fmt, u32}; use std::io::prelude::*; use std::io; use std::rc::Rc; -use syntax::ast::{self, NodeId}; +use syntax::ast; use syntax::ptr::P; use syntax::symbol::{kw, sym}; use syntax_pos::Span; @@ -1327,12 +1327,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } - fn access_var(&mut self, hir_id: HirId, nid: NodeId, succ: LiveNode, acc: u32, span: Span) + fn access_var(&mut self, hir_id: HirId, var_hid: HirId, succ: LiveNode, acc: u32, span: Span) -> LiveNode { let ln = self.live_node(hir_id, span); if acc != 0 { self.init_from_succ(ln, succ); - let var_hid = self.ir.tcx.hir().node_to_hir_id(nid); let var = self.variable(var_hid, span); self.acc(ln, var, acc); } @@ -1345,8 +1344,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { Res::Local(hid) => { let upvars = self.ir.tcx.upvars(self.ir.body_owner); if !upvars.map_or(false, |upvars| upvars.contains_key(&hid)) { - let nid = self.ir.tcx.hir().hir_to_node_id(hid); - self.access_var(hir_id, nid, succ, acc, path.span) + self.access_var(hir_id, hid, succ, acc, path.span) } else { succ } diff --git a/src/librustc/ty/inhabitedness/def_id_forest.rs b/src/librustc/ty/inhabitedness/def_id_forest.rs index b22bd21e9de43..af8dedfc8812e 100644 --- a/src/librustc/ty/inhabitedness/def_id_forest.rs +++ b/src/librustc/ty/inhabitedness/def_id_forest.rs @@ -1,6 +1,6 @@ use std::mem; use smallvec::SmallVec; -use syntax::ast::CRATE_NODE_ID; +use rustc::hir::CRATE_HIR_ID; use crate::ty::context::TyCtxt; use crate::ty::{DefId, DefIdTree}; @@ -33,7 +33,7 @@ impl<'tcx> DefIdForest { /// crate. #[inline] pub fn full(tcx: TyCtxt<'tcx>) -> DefIdForest { - let crate_id = tcx.hir().local_def_id(CRATE_NODE_ID); + let crate_id = tcx.hir().local_def_id_from_hir_id(CRATE_HIR_ID); DefIdForest::from_id(crate_id) } From b7a0e401759505f39a07e9cb9421aa695b4856e9 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 25 Jun 2019 03:39:23 +0100 Subject: [PATCH 11/13] Fix an ICE with uninhabited consts --- src/librustc/ty/inhabitedness/mod.rs | 2 +- src/librustc_mir/interpret/terminator.rs | 10 ++++---- .../consts/uninhabited-const-issue-61744.rs | 19 +++++++++++++++ .../uninhabited-const-issue-61744.stderr | 24 +++++++++++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/consts/uninhabited-const-issue-61744.rs create mode 100644 src/test/ui/consts/uninhabited-const-issue-61744.stderr diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index 5ce750849f42d..0d96e5ea625da 100644 --- a/src/librustc/ty/inhabitedness/mod.rs +++ b/src/librustc/ty/inhabitedness/mod.rs @@ -97,7 +97,7 @@ impl<'tcx> TyCtxt<'tcx> { self.ty_inhabitedness_forest(ty).contains(self, module) } - pub fn is_ty_uninhabited_from_all_modules(self, ty: Ty<'tcx>) -> bool { + pub fn is_ty_uninhabited_from_any_module(self, ty: Ty<'tcx>) -> bool { !self.ty_inhabitedness_forest(ty).is_empty() } diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index af061f968104e..a29611e4814f1 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -388,12 +388,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { )); } } else { - let callee_layout = - self.layout_of_local(self.frame(), mir::RETURN_PLACE, None)?; - if !callee_layout.abi.is_uninhabited() { - return err!(FunctionRetMismatch( - self.tcx.types.never, callee_layout.ty - )); + let local = mir::RETURN_PLACE; + let ty = self.frame().body.local_decls[local].ty; + if !self.tcx.is_ty_uninhabited_from_any_module(ty) { + return err!(FunctionRetMismatch(self.tcx.types.never, ty)); } } Ok(()) diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.rs b/src/test/ui/consts/uninhabited-const-issue-61744.rs new file mode 100644 index 0000000000000..21fbbf8cfb5a8 --- /dev/null +++ b/src/test/ui/consts/uninhabited-const-issue-61744.rs @@ -0,0 +1,19 @@ +// compile-fail + +pub const unsafe fn fake_type() -> T { + hint_unreachable() +} + +pub const unsafe fn hint_unreachable() -> ! { + fake_type() //~ ERROR any use of this value will cause an error +} + +trait Const { + const CONSTANT: i32 = unsafe { fake_type() }; +} + +impl Const for T {} + +pub fn main() -> () { + dbg!(i32::CONSTANT); //~ ERROR erroneous constant used +} diff --git a/src/test/ui/consts/uninhabited-const-issue-61744.stderr b/src/test/ui/consts/uninhabited-const-issue-61744.stderr new file mode 100644 index 0000000000000..5c2855437118f --- /dev/null +++ b/src/test/ui/consts/uninhabited-const-issue-61744.stderr @@ -0,0 +1,24 @@ +error: any use of this value will cause an error + --> $DIR/uninhabited-const-issue-61744.rs:8:5 + | +LL | fake_type() + | ^^^^^^^^^^^ + | | + | tried to call a function with return type T passing return place of type ! + | inside call to `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:4:5 + | inside call to `fake_type::` at $DIR/uninhabited-const-issue-61744.rs:12:36 +... +LL | const CONSTANT: i32 = unsafe { fake_type() }; + | --------------------------------------------- + | + = note: #[deny(const_err)] on by default + +error[E0080]: erroneous constant used + --> $DIR/uninhabited-const-issue-61744.rs:18:10 + | +LL | dbg!(i32::CONSTANT); + | ^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`. From e6ee8a0d44fcedb583067bbaf36bcdf325029cdd Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 20 Jun 2019 15:00:31 +0300 Subject: [PATCH 12/13] rustc: produce AST instead of HIR from `hir::lowering::Resolver` methods. --- src/librustc/hir/lowering.rs | 30 ++++++++----- src/librustc_resolve/lib.rs | 42 +++++++------------ .../passes/collect_intra_doc_links.rs | 20 +++++---- 3 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index e1d0d5a1c7af2..1b8e2999afe6a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -148,11 +148,11 @@ pub struct LoweringContext<'a> { pub trait Resolver { /// Resolve a path generated by the lowerer when expanding `for`, `if let`, etc. - fn resolve_hir_path( + fn resolve_ast_path( &mut self, path: &ast::Path, is_value: bool, - ) -> hir::Path; + ) -> Res; /// Obtain resolution for a `NodeId` with a single resolution. fn get_partial_res(&mut self, id: NodeId) -> Option; @@ -167,7 +167,7 @@ pub trait Resolver { /// This should only return `None` during testing. fn definitions(&mut self) -> &mut Definitions; - /// Given suffix `["b", "c", "d"]`, creates a HIR path for `[::crate_root]::b::c::d` and + /// Given suffix `["b", "c", "d"]`, creates an AST path for `[::crate_root]::b::c::d` and /// resolves it based on `is_value`. fn resolve_str_path( &mut self, @@ -175,7 +175,7 @@ pub trait Resolver { crate_root: Option, components: &[Symbol], is_value: bool, - ) -> hir::Path; + ) -> (ast::Path, Res); } /// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree, @@ -5546,16 +5546,26 @@ impl<'a> LoweringContext<'a> { params: Option>, is_value: bool, ) -> hir::Path { - let mut path = self.resolver + let (path, res) = 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() { - if seg.hir_id.is_some() { - seg.hir_id = Some(self.next_id()); + let mut segments: Vec<_> = path.segments.iter().map(|segment| { + let res = self.expect_full_res(segment.id); + hir::PathSegment { + ident: segment.ident, + hir_id: Some(self.lower_node_id(segment.id)), + res: Some(self.lower_res(res)), + infer_args: true, + args: None, } + }).collect(); + segments.last_mut().unwrap().args = params; + + hir::Path { + span, + res: res.map_id(|_| panic!("unexpected node_id")), + segments: segments.into(), } - path } fn ty_path(&mut self, mut hir_id: hir::HirId, span: Span, qpath: hir::QPath) -> hir::Ty { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 3b418d0dbb665..81adfac0a291a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1744,12 +1744,12 @@ impl<'a, 'b> 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> { - fn resolve_hir_path( + fn resolve_ast_path( &mut self, path: &ast::Path, is_value: bool, - ) -> hir::Path { - self.resolve_hir_path_cb(path, is_value, + ) -> Res { + self.resolve_ast_path_cb(path, is_value, |resolver, span, error| resolve_error(resolver, span, error)) } @@ -1759,7 +1759,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { crate_root: Option, components: &[Symbol], is_value: bool - ) -> hir::Path { + ) -> (ast::Path, Res) { let root = if crate_root.is_some() { kw::PathRoot } else { @@ -1777,7 +1777,8 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> { segments, }; - self.resolve_hir_path(&path, is_value) + let res = self.resolve_ast_path(&path, is_value); + (path, res) } fn get_partial_res(&mut self, id: NodeId) -> Option { @@ -1803,7 +1804,7 @@ impl<'a> Resolver<'a> { /// 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 { + -> Result<(ast::Path, Res), ()> { let mut errored = false; let path = if path_str.starts_with("::") { @@ -1826,29 +1827,29 @@ impl<'a> Resolver<'a> { .collect(), } }; - let path = self.resolve_hir_path_cb(&path, is_value, |_, _, _| errored = true); - if errored || path.res == def::Res::Err { + let res = self.resolve_ast_path_cb(&path, is_value, |_, _, _| errored = true); + if errored || res == def::Res::Err { Err(()) } else { - Ok(path) + Ok((path, res)) } } - /// Like `resolve_hir_path`, but takes a callback in case there was an error. - fn resolve_hir_path_cb( + /// Like `resolve_ast_path`, but takes a callback in case there was an error. + // FIXME(eddyb) use `Result` or something instead of callbacks. + fn resolve_ast_path_cb( &mut self, path: &ast::Path, is_value: bool, error_callback: F, - ) -> hir::Path + ) -> Res where F: for<'c, 'b> FnOnce(&'c mut Resolver<'_>, Span, ResolutionError<'b>) { let namespace = if is_value { ValueNS } else { TypeNS }; let span = path.span; - let segments = &path.segments; let path = Segment::from_path(&path); // FIXME(Manishearth): intra-doc links won't get warned of epoch changes. - let res = match self.resolve_path_without_parent_scope(&path, Some(namespace), true, + match self.resolve_path_without_parent_scope(&path, Some(namespace), true, span, CrateLint::No) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res().unwrap(), @@ -1869,19 +1870,6 @@ impl<'a> Resolver<'a> { }); Res::Err } - }; - - let segments: Vec<_> = segments.iter().map(|seg| { - let mut hir_seg = hir::PathSegment::from_ident(seg.ident); - hir_seg.res = Some(self.partial_res_map.get(&seg.id).map_or(def::Res::Err, |p| { - p.base_res().map_id(|_| panic!("unexpected node_id")) - })); - hir_seg - }).collect(); - hir::Path { - span, - res: res.map_id(|_| panic!("unexpected node_id")), - segments: segments.into(), } } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index e6f09927796fa..bb85fe898dabd 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -71,15 +71,16 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { }) }); - if let Ok(result) = result { + if let Ok((_, res)) = result { + let res = res.map_id(|_| panic!("unexpected node_id")); // In case this is a trait item, skip the // early return and try looking for the trait. - let value = match result.res { + let value = match res { Res::Def(DefKind::Method, _) | Res::Def(DefKind::AssocConst, _) => true, Res::Def(DefKind::AssocTy, _) => false, - Res::Def(DefKind::Variant, _) => return handle_variant(cx, result.res), + Res::Def(DefKind::Variant, _) => return handle_variant(cx, res), // Not a trait item; just return what we found. - _ => return Ok((result.res, None)) + _ => return Ok((res, None)) }; if value != (ns == ValueNS) { @@ -129,10 +130,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { // FIXME: `with_scope` requires the `NodeId` of a module. let node_id = cx.tcx.hir().hir_to_node_id(id); - let ty = cx.enter_resolver(|resolver| resolver.with_scope(node_id, |resolver| { + let (_, ty_res) = cx.enter_resolver(|resolver| resolver.with_scope(node_id, |resolver| { resolver.resolve_str_path_error(DUMMY_SP, &path, false) }))?; - match ty.res { + let ty_res = ty_res.map_id(|_| panic!("unexpected node_id")); + match ty_res { Res::Def(DefKind::Struct, did) | Res::Def(DefKind::Union, did) | Res::Def(DefKind::Enum, did) @@ -147,7 +149,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { ty::AssocKind::Const if ns == ValueNS => "associatedconstant", _ => return Err(()) }; - Ok((ty.res, Some(format!("{}.{}", out, item_name)))) + Ok((ty_res, Some(format!("{}.{}", out, item_name)))) } else { match cx.tcx.type_of(did).sty { ty::Adt(def, _) => { @@ -159,7 +161,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { .iter() .find(|item| item.ident.name == item_name) } { - Ok((ty.res, + Ok((ty_res, Some(format!("{}.{}", if def.is_enum() { "variant" @@ -193,7 +195,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { _ => return Err(()) }; - Ok((ty.res, Some(format!("{}.{}", kind, item_name)))) + Ok((ty_res, Some(format!("{}.{}", kind, item_name)))) } else { Err(()) } From 099f9e4e8aac3968888636e2126c4b7f8e6bb2d3 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 24 Jun 2019 17:46:09 +0200 Subject: [PATCH 13/13] Implement From for Place and PlaceBase --- src/librustc/mir/mod.rs | 12 ++++++ src/librustc_codegen_ssa/mir/place.rs | 2 +- .../borrow_check/error_reporting.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- .../borrow_check/nll/explain_borrow/mod.rs | 2 +- .../borrow_check/nll/invalidation.rs | 4 +- .../borrow_check/nll/type_check/mod.rs | 2 +- src/librustc_mir/build/expr/as_operand.rs | 2 +- src/librustc_mir/build/expr/as_place.rs | 16 +++---- src/librustc_mir/build/expr/as_rvalue.rs | 14 +++---- src/librustc_mir/build/expr/as_temp.rs | 2 +- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/build/expr/stmt.rs | 2 +- src/librustc_mir/build/matches/mod.rs | 10 ++--- src/librustc_mir/build/misc.rs | 2 +- src/librustc_mir/build/mod.rs | 2 +- .../dataflow/drop_flag_effects.rs | 2 +- src/librustc_mir/dataflow/impls/borrows.rs | 2 +- .../dataflow/move_paths/builder.rs | 6 +-- src/librustc_mir/interpret/terminator.rs | 2 +- src/librustc_mir/shim.rs | 42 +++++++++---------- .../transform/add_moves_for_packed_drops.rs | 4 +- src/librustc_mir/transform/add_retag.rs | 2 +- src/librustc_mir/transform/elaborate_drops.rs | 6 +-- src/librustc_mir/transform/generator.rs | 16 +++---- src/librustc_mir/transform/inline.rs | 6 +-- src/librustc_mir/transform/lower_128bit.rs | 4 +- src/librustc_mir/transform/promote_consts.rs | 4 +- .../transform/uniform_array_move_out.rs | 4 +- src/librustc_mir/util/elaborate_drops.rs | 33 +++++++-------- src/librustc_mir/util/graphviz.rs | 6 +-- src/librustc_mir/util/pretty.rs | 2 +- 32 files changed, 114 insertions(+), 105 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 6f9cede7e46b1..9b1808c585ce7 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2096,6 +2096,18 @@ impl<'tcx> Place<'tcx> { } } +impl From for Place<'_> { + fn from(local: Local) -> Self { + Place::Base(local.into()) + } +} + +impl From for PlaceBase<'_> { + fn from(local: Local) -> Self { + PlaceBase::Local(local) + } +} + /// A linked list of projections running up the stack; begins with the /// innermost projection and extends to the outermost (e.g., `a.b.c` /// would have the place `b` with a "next" pointer to `b.c`). diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index d56f39c6de204..be5d7b09965d4 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -470,7 +470,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::ProjectionElem::Index(index) => { let index = &mir::Operand::Copy( - mir::Place::Base(mir::PlaceBase::Local(index)) + mir::Place::from(index) ); let index = self.codegen_operand(bx, index); let llindex = index.immediate(); diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index ac64cf79537cd..10c9a439bf70f 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -627,7 +627,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { def_id, is_generator, places ); if let Some((args_span, var_span)) = self.closure_span( - *def_id, &Place::Base(PlaceBase::Local(target)), places + *def_id, &Place::from(target), places ) { return ClosureUse { is_generator, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 919ed5ccaba1e..4872440f5bd4a 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -620,7 +620,7 @@ impl<'cx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx StatementKind::StorageDead(local) => { self.access_place( location, - (&Place::Base(PlaceBase::Local(local)), span), + (&Place::from(local), span), (Shallow(None), Write(WriteKind::StorageDeadOrDrop)), LocalMutationIsAllowed::Yes, flow_state, diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 4bc2f7064bef4..ed88b16253584 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -252,7 +252,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some(Cause::LiveVar(local, location)) => { let span = body.source_info(location).span; let spans = self - .move_spans(&Place::Base(PlaceBase::Local(local)), location) + .move_spans(&Place::from(local), location) .or_else(|| self.borrow_spans(span, location)); let borrow_location = location; diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index c45c28c61465f..c7b4a40305259 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -11,7 +11,7 @@ use crate::borrow_check::path_utils::*; use crate::dataflow::indexes::BorrowIndex; use rustc::ty::TyCtxt; use rustc::mir::visit::Visitor; -use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue}; +use rustc::mir::{BasicBlock, Location, Body, Place, Rvalue}; use rustc::mir::{Statement, StatementKind}; use rustc::mir::TerminatorKind; use rustc::mir::{Operand, BorrowKind}; @@ -124,7 +124,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { StatementKind::StorageDead(local) => { self.access_place( location, - &Place::Base(PlaceBase::Local(local)), + &Place::from(local), (Shallow(None), Write(WriteKind::StorageDeadOrDrop)), LocalMutationIsAllowed::Yes, ); diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index e1f5964ff9340..9409fefb6bde7 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -632,7 +632,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { ) } ProjectionElem::Index(i) => { - let index_ty = Place::Base(PlaceBase::Local(i)).ty(self.body, tcx).ty; + let index_ty = Place::from(i).ty(self.body, tcx).ty; if index_ty != tcx.types.usize { PlaceTy::from_ty( span_mirbug_and_err!(self, i, "index by non-usize {:?}", i), diff --git a/src/librustc_mir/build/expr/as_operand.rs b/src/librustc_mir/build/expr/as_operand.rs index dd78e7e869a8f..207399fbdcf0e 100644 --- a/src/librustc_mir/build/expr/as_operand.rs +++ b/src/librustc_mir/build/expr/as_operand.rs @@ -74,7 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } Category::Place | Category::Rvalue(..) => { let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut)); - block.and(Operand::Move(Place::Base(PlaceBase::Local(operand)))) + block.and(Operand::Move(Place::from(operand))) } } } diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 51808ef7ebdee..0640c01d255c2 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -98,26 +98,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { <, Rvalue::BinaryOp( BinOp::Lt, - Operand::Copy(Place::Base(PlaceBase::Local(idx))), + Operand::Copy(Place::from(idx)), Operand::Copy(len.clone()), ), ); let msg = BoundsCheck { len: Operand::Move(len), - index: Operand::Copy(Place::Base(PlaceBase::Local(idx))), + index: Operand::Copy(Place::from(idx)), }; let success = this.assert(block, Operand::Move(lt), true, msg, expr_span); success.and(slice.index(idx)) } - ExprKind::SelfRef => block.and(Place::Base(PlaceBase::Local(Local::new(1)))), + ExprKind::SelfRef => block.and(Place::from(Local::new(1))), ExprKind::VarRef { id } => { let place = if this.is_bound_var_in_guard(id) { let index = this.var_local_id(id, RefWithinGuard); - Place::Base(PlaceBase::Local(index)).deref() + Place::from(index).deref() } else { let index = this.var_local_id(id, OutsideGuard); - Place::Base(PlaceBase::Local(index)) + Place::from(index) }; block.and(place) } @@ -168,14 +168,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Statement { source_info, kind: StatementKind::AscribeUserType( - Place::Base(PlaceBase::Local(temp.clone())), + Place::from(temp.clone()), Variance::Invariant, box UserTypeProjection { base: annotation_index, projs: vec![], }, ), }, ); } - block.and(Place::Base(PlaceBase::Local(temp))) + block.and(Place::from(temp)) } ExprKind::Array { .. } @@ -211,7 +211,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }); let temp = unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability)); - block.and(Place::Base(PlaceBase::Local(temp))) + block.and(Place::from(temp)) } } } diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 243c13c2982d0..73ce2a5dc9b8c 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -127,7 +127,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.schedule_drop_storage_and_value( expr_span, scope, - &Place::Base(PlaceBase::Local(result)), + &Place::from(result), value.ty, ); } @@ -135,16 +135,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // malloc some memory of suitable type (thus far, uninitialized): let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty); this.cfg - .push_assign(block, source_info, &Place::Base(PlaceBase::Local(result)), box_); + .push_assign(block, source_info, &Place::from(result), box_); // initialize the box contents: unpack!( block = this.into( - &Place::Base(PlaceBase::Local(result)).deref(), + &Place::from(result).deref(), block, value ) ); - block.and(Rvalue::Use(Operand::Move(Place::Base(PlaceBase::Local(result))))) + block.and(Rvalue::Use(Operand::Move(Place::from(result)))) } ExprKind::Cast { source } => { let source = unpack!(block = this.as_operand(block, scope, source)); @@ -548,7 +548,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.cfg.push_assign( block, source_info, - &Place::Base(PlaceBase::Local(temp)), + &Place::from(temp), Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place), ); @@ -559,12 +559,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { this.schedule_drop_storage_and_value( upvar_span, temp_lifetime, - &Place::Base(PlaceBase::Local(temp)), + &Place::from(temp), upvar_ty, ); } - block.and(Operand::Move(Place::Base(PlaceBase::Local(temp)))) + block.and(Operand::Move(Place::from(temp))) } // Helper to get a `-1` value of the appropriate type diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index 9d907c6ec04ab..1b3ebac4a3d4d 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -64,7 +64,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } this.local_decls.push(local_decl) }; - let temp_place = &Place::Base(PlaceBase::Local(temp)); + let temp_place = &Place::from(temp); if !expr_ty.is_never() { this.cfg.push( diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index a3976238fbe82..f70ecef0c254a 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -258,7 +258,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { is_user_variable: None, is_block_tail: None, }); - let ptr_temp = Place::Base(PlaceBase::Local(ptr_temp)); + let ptr_temp = Place::from(ptr_temp); let block = unpack!(this.into(&ptr_temp, block, ptr)); this.into(&ptr_temp.deref(), block, val) } else { diff --git a/src/librustc_mir/build/expr/stmt.rs b/src/librustc_mir/build/expr/stmt.rs index 74338de67759e..4463e7fd4d4a6 100644 --- a/src/librustc_mir/build/expr/stmt.rs +++ b/src/librustc_mir/build/expr/stmt.rs @@ -235,7 +235,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } let temp = this.local_decls.push(local_decl); - let place = Place::Base(PlaceBase::Local(temp)); + let place = Place::from(temp); debug!("created temp {:?} for expr {:?} in block_context: {:?}", temp, expr, this.block_context); place diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 55093f28a42e1..d2e56c4981faa 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -531,7 +531,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { kind: StatementKind::StorageLive(local_id), }, ); - let place = Place::Base(PlaceBase::Local(local_id)); + let place = Place::from(local_id); let var_ty = self.local_decls[local_id].ty; let region_scope = self.hir.region_scope_tree.var_scope(var.local_id); self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage); @@ -545,7 +545,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.schedule_drop( span, region_scope, - &Place::Base(PlaceBase::Local(local_id)), + &Place::from(local_id), var_ty, DropKind::Value, ); @@ -1478,7 +1478,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.cfg.push_assign( block, scrutinee_source_info, - &Place::Base(PlaceBase::Local(temp)), + &Place::from(temp), borrow, ); } @@ -1502,7 +1502,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { source_info: guard_end, kind: StatementKind::FakeRead( FakeReadCause::ForMatchGuard, - Place::Base(PlaceBase::Local(temp)), + Place::from(temp), ), }); } @@ -1575,7 +1575,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // place they refer to can't be modified by the guard. for binding in by_value_bindings.clone() { let local_id = self.var_local_id(binding.var_id, RefWithinGuard); - let place = Place::Base(PlaceBase::Local(local_id)); + let place = Place::from(local_id); self.cfg.push( block, Statement { diff --git a/src/librustc_mir/build/misc.rs b/src/librustc_mir/build/misc.rs index ad891b1c1ea0a..56025eeaaa922 100644 --- a/src/librustc_mir/build/misc.rs +++ b/src/librustc_mir/build/misc.rs @@ -16,7 +16,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// call `schedule_drop` once the temporary is initialized. pub fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> { let temp = self.local_decls.push(LocalDecl::new_temp(ty, span)); - let place = Place::Base(PlaceBase::Local(temp)); + let place = Place::from(temp); debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty); place diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 66064221b391c..4c3a113123665 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -809,7 +809,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { for (index, arg_info) in arguments.iter().enumerate() { // Function arguments always get the first Local indices after the return place let local = Local::new(index + 1); - let place = Place::Base(PlaceBase::Local(local)); + let place = Place::from(local); let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info; // Make sure we drop (parts of) the argument even when not matched on. diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index 37f2a91578249..a73ec2ed8e06a 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -170,7 +170,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>( { let move_data = &ctxt.move_data; for arg in body.args_iter() { - let place = mir::Place::Base(mir::PlaceBase::Local(arg)); + let place = mir::Place::from(arg); let lookup_result = move_data.rev_lookup.find(&place); on_lookup_result_bits(tcx, body, move_data, lookup_result, diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 53d00d44e3f55..dcc6ba5ca05cc 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -288,7 +288,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> { mir::StatementKind::StorageDead(local) => { // Make sure there are no remaining borrows for locals that // are gone out of scope. - self.kill_borrows_on_place(trans, &Place::Base(PlaceBase::Local(local))); + self.kill_borrows_on_place(trans, &Place::from(local)); } mir::StatementKind::InlineAsm(ref asm) => { diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index e8386e8fef11b..f282c276e0926 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -33,13 +33,13 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { moves: IndexVec::new(), loc_map: LocationMap::new(body), rev_lookup: MovePathLookup { - locals: body.local_decls.indices().map(PlaceBase::Local).map(|v| { + locals: body.local_decls.indices().map(|i| { Self::new_move_path( &mut move_paths, &mut path_map, &mut init_path_map, None, - Place::Base(v), + Place::from(i), ) }).collect(), projections: Default::default(), @@ -289,7 +289,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { } StatementKind::StorageLive(_) => {} StatementKind::StorageDead(local) => { - self.gather_move(&Place::Base(PlaceBase::Local(local))); + self.gather_move(&Place::from(local)); } StatementKind::SetDiscriminant{ .. } => { span_bug!(stmt.source_info.span, diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index af061f968104e..e7601f887c32e 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -355,7 +355,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpretCx<'mir, 'tcx, M> { let mut locals_iter = body.args_iter(); while let Some(local) = locals_iter.next() { let dest = self.eval_place( - &mir::Place::Base(mir::PlaceBase::Local(local)) + &mir::Place::from(local) )?; if Some(local) == body.spread_arg { // Must be a tuple diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index c04672f8331e6..7987095a33401 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -213,7 +213,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) if let Some(..) = ty { // The first argument (index 0), but add 1 for the return value. - let dropee_ptr = Place::Base(PlaceBase::Local(Local::new(1+0))); + let dropee_ptr = Place::from(Local::new(1+0)); if tcx.sess.opts.debugging_opts.mir_emit_retag { // Function arguments should be retagged, and we make this one raw. body.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement { @@ -308,7 +308,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - let is_copy = self_ty.is_copy_modulo_regions(tcx, tcx.param_env(def_id), builder.span); let dest = Place::RETURN_PLACE; - let src = Place::Base(PlaceBase::Local(Local::new(1+0))).deref(); + let src = Place::from(Local::new(1+0)).deref(); match self_ty.sty { _ if is_copy => builder.copy_shim(), @@ -412,7 +412,7 @@ impl CloneShimBuilder<'tcx> { } fn copy_shim(&mut self) { - let rcvr = Place::Base(PlaceBase::Local(Local::new(1+0))).deref(); + let rcvr = Place::from(Local::new(1+0)).deref(); let ret_statement = self.make_statement( StatementKind::Assign( Place::RETURN_PLACE, @@ -424,9 +424,7 @@ impl CloneShimBuilder<'tcx> { fn make_place(&mut self, mutability: Mutability, ty: Ty<'tcx>) -> Place<'tcx> { let span = self.span; - Place::Base(PlaceBase::Local( - self.local_decls.push(temp_decl(mutability, ty, span)) - )) + Place::from(self.local_decls.push(temp_decl(mutability, ty, span))) } fn make_clone_call( @@ -525,7 +523,7 @@ impl CloneShimBuilder<'tcx> { let inits = vec![ self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::Use(Operand::Constant(self.make_usize(0))) ) ), @@ -543,7 +541,7 @@ impl CloneShimBuilder<'tcx> { // BB #3; // } // BB #4; - self.loop_header(Place::Base(PlaceBase::Local(beg)), + self.loop_header(Place::from(beg), end, BasicBlock::new(2), BasicBlock::new(4), @@ -563,10 +561,10 @@ impl CloneShimBuilder<'tcx> { let statements = vec![ self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::BinaryOp( BinOp::Add, - Operand::Copy(Place::Base(PlaceBase::Local(beg))), + Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)) ) ) @@ -586,7 +584,7 @@ impl CloneShimBuilder<'tcx> { let beg = self.local_decls.push(temp_decl(Mutability::Mut, tcx.types.usize, span)); let init = self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::Use(Operand::Constant(self.make_usize(0))) ) ); @@ -597,7 +595,7 @@ impl CloneShimBuilder<'tcx> { // BB #8; // } // BB #9; - self.loop_header(Place::Base(PlaceBase::Local(beg)), Place::Base(PlaceBase::Local(end)), + self.loop_header(Place::from(beg), Place::from(end), BasicBlock::new(7), BasicBlock::new(9), true); // BB #7 (cleanup) @@ -613,10 +611,10 @@ impl CloneShimBuilder<'tcx> { // `goto #6;` let statement = self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::BinaryOp( BinOp::Add, - Operand::Copy(Place::Base(PlaceBase::Local(beg))), + Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)) ) ) @@ -701,7 +699,7 @@ fn build_call_shim<'tcx>( let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }; let rcvr_arg = Local::new(1+0); - let rcvr_l = Place::Base(PlaceBase::Local(rcvr_arg)); + let rcvr_l = Place::from(rcvr_arg); let mut statements = vec![]; let rcvr = match rcvr_adjustment { @@ -731,11 +729,11 @@ fn build_call_shim<'tcx>( statements.push(Statement { source_info, kind: StatementKind::Assign( - Place::Base(PlaceBase::Local(ref_rcvr)), + Place::from(ref_rcvr), box Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_l) ) }); - Operand::Move(Place::Base(PlaceBase::Local(ref_rcvr))) + Operand::Move(Place::from(ref_rcvr)) } }; @@ -755,12 +753,12 @@ fn build_call_shim<'tcx>( if let Some(untuple_args) = untuple_args { args.extend(untuple_args.iter().enumerate().map(|(i, ity)| { - let arg_place = Place::Base(PlaceBase::Local(Local::new(1+1))); + let arg_place = Place::from(Local::new(1+1)); Operand::Move(arg_place.field(Field::new(i), *ity)) })); } else { args.extend((1..sig.inputs().len()).map(|i| { - Operand::Move(Place::Base(PlaceBase::Local(Local::new(1+i)))) + Operand::Move(Place::from(Local::new(1+i))) })); } @@ -791,7 +789,7 @@ fn build_call_shim<'tcx>( if let Adjustment::RefMut = rcvr_adjustment { // BB #1 - drop for Self block(&mut blocks, vec![], TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(rcvr_arg)), + location: Place::from(rcvr_arg), target: BasicBlock::new(2), unwind: None }, false); @@ -801,7 +799,7 @@ fn build_call_shim<'tcx>( if let Adjustment::RefMut = rcvr_adjustment { // BB #3 - drop if closure panics block(&mut blocks, vec![], TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(rcvr_arg)), + location: Place::from(rcvr_arg), target: BasicBlock::new(4), unwind: None }, true); @@ -881,7 +879,7 @@ pub fn build_adt_ctor<'tcx>(tcx: TyCtxt<'tcx>, ctor_id: DefId) -> &'tcx Body<'tc .iter() .enumerate() .map(|(idx, field_def)| ( - Operand::Move(Place::Base(PlaceBase::Local(Local::new(idx + 1)))), + Operand::Move(Place::from(Local::new(idx + 1))), field_def.ty(tcx, substs), )), AggregateKind::Adt(adt_def, variant_index, substs, None, None), diff --git a/src/librustc_mir/transform/add_moves_for_packed_drops.rs b/src/librustc_mir/transform/add_moves_for_packed_drops.rs index a111669f14982..426e16698d74d 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -112,10 +112,10 @@ fn add_move_for_packed_drop<'tcx>( patch.add_statement( loc, StatementKind::StorageLive(temp)); - patch.add_assign(loc, Place::Base(PlaceBase::Local(temp)), + patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(location.clone()))); patch.patch_terminator(loc.block, TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(temp)), + location: Place::from(temp), target: storage_dead_block, unwind }); diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index ee040bf65901c..e01017d7c9bdb 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -96,7 +96,7 @@ impl MirPass for AddRetag { }; // Gather all arguments, skip return value. let places = local_decls.iter_enumerated().skip(1).take(arg_count) - .map(|(local, _)| Place::Base(PlaceBase::Local(local))) + .map(|(local, _)| Place::from(local)) .filter(needs_retag) .collect::>(); // Emit their retags. diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index b2b489b2e3884..ad19b974d7d61 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -326,7 +326,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { } fn drop_flag(&mut self, index: MovePathIndex) -> Option> { - self.drop_flags.get(&index).map(|t| Place::Base(PlaceBase::Local(*t))) + self.drop_flags.get(&index).map(|t| Place::from(*t)) } /// create a patch that elaborates all drops in the input @@ -537,7 +537,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { if let Some(&flag) = self.drop_flags.get(&path) { let span = self.patch.source_info_for_location(self.body, loc).span; let val = self.constant_bool(span, val.value()); - self.patch.add_assign(loc, Place::Base(PlaceBase::Local(flag)), val); + self.patch.add_assign(loc, Place::from(flag), val); } } @@ -546,7 +546,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { let span = self.patch.source_info_for_location(self.body, loc).span; let false_ = self.constant_bool(span, false); for flag in self.drop_flags.values() { - self.patch.add_assign(loc, Place::Base(PlaceBase::Local(*flag)), false_.clone()); + self.patch.add_assign(loc, Place::from(*flag), false_.clone()); } } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index ba8c47c665e03..7b961e97a10de 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -200,7 +200,7 @@ impl TransformVisitor<'tcx> { // Create a Place referencing a generator struct field fn make_field(&self, variant_index: VariantIdx, idx: usize, ty: Ty<'tcx>) -> Place<'tcx> { - let self_place = Place::Base(PlaceBase::Local(self_arg())); + let self_place = Place::from(self_arg()); let base = self_place.downcast_unnamed(variant_index); let field = Projection { base: base, @@ -211,7 +211,7 @@ impl TransformVisitor<'tcx> { // Create a statement which changes the discriminant fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statement<'tcx> { - let self_place = Place::Base(PlaceBase::Local(self_arg())); + let self_place = Place::from(self_arg()); Statement { source_info, kind: StatementKind::SetDiscriminant { place: self_place, variant_index: state_disc }, @@ -222,9 +222,9 @@ impl TransformVisitor<'tcx> { fn get_discr(&self, body: &mut Body<'tcx>) -> (Statement<'tcx>, Place<'tcx>) { let temp_decl = LocalDecl::new_internal(self.tcx.types.isize, body.span); let local_decls_len = body.local_decls.push(temp_decl); - let temp = Place::Base(PlaceBase::Local(local_decls_len)); + let temp = Place::from(local_decls_len); - let self_place = Place::Base(PlaceBase::Local(self_arg())); + let self_place = Place::from(self_arg()); let assign = Statement { source_info: source_info(body), kind: StatementKind::Assign(temp.clone(), box Rvalue::Discriminant(self_place)), @@ -271,7 +271,7 @@ impl MutVisitor<'tcx> for TransformVisitor<'tcx> { let ret_val = match data.terminator().kind { TerminatorKind::Return => Some((VariantIdx::new(1), None, - Operand::Move(Place::Base(PlaceBase::Local(self.new_ret_local))), + Operand::Move(Place::from(self.new_ret_local)), None)), TerminatorKind::Yield { ref value, resume, drop } => Some((VariantIdx::new(0), Some(resume), @@ -840,7 +840,7 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut elaborate_drop( &mut elaborator, source_info, - &Place::Base(PlaceBase::Local(gen)), + &Place::from(gen), (), target, unwind, @@ -913,7 +913,7 @@ fn create_generator_drop_shim<'tcx>( // Alias tracking must know we changed the type body.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement { source_info, - kind: StatementKind::Retag(RetagKind::Raw, Place::Base(PlaceBase::Local(self_arg()))), + kind: StatementKind::Retag(RetagKind::Raw, Place::from(self_arg())), }) } @@ -1031,7 +1031,7 @@ fn insert_clean_drop<'tcx>(body: &mut Body<'tcx>) -> BasicBlock { // Create a block to destroy an unresumed generators. This can only destroy upvars. let drop_clean = BasicBlock::new(body.basic_blocks().len()); let term = TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(self_arg())), + location: Place::from(self_arg()), target: return_block, unwind: None, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index e2f98e46dba57..dc73e58d15c3d 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -467,7 +467,7 @@ impl Inliner<'tcx> { let temp = LocalDecl::new_temp(ty, callsite.location.span); let tmp = caller_body.local_decls.push(temp); - let tmp = Place::Base(PlaceBase::Local(tmp)); + let tmp = Place::from(tmp); let stmt = Statement { source_info: callsite.location, @@ -561,7 +561,7 @@ impl Inliner<'tcx> { let tuple = self.create_temp_if_necessary(args.next().unwrap(), callsite, caller_body); assert!(args.next().is_none()); - let tuple = Place::Base(PlaceBase::Local(tuple)); + let tuple = Place::from(tuple); let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.sty { s } else { @@ -621,7 +621,7 @@ impl Inliner<'tcx> { let stmt = Statement { source_info: callsite.location, - kind: StatementKind::Assign(Place::Base(PlaceBase::Local(arg_tmp)), box arg), + kind: StatementKind::Assign(Place::from(arg_tmp), box arg), }; caller_body[callsite.bb].statements.push(stmt); arg_tmp diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index f0aa189804f7d..f09a77d486c7e 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -83,13 +83,13 @@ impl Lower128Bit { block.statements.push(Statement { source_info: source_info, kind: StatementKind::Assign( - Place::Base(PlaceBase::Local(local)), + Place::from(local), box Rvalue::Cast( CastKind::Misc, rhs, rhs_override_ty.unwrap())), }); - rhs = Operand::Move(Place::Base(PlaceBase::Local(local))); + rhs = Operand::Move(Place::from(local)); } let call_did = check_lang_item_type( diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index d78adfe433c47..b1804fb0ab331 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -182,7 +182,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { span, scope: OUTERMOST_SOURCE_SCOPE }, - kind: StatementKind::Assign(Place::Base(PlaceBase::Local(dest)), box rvalue) + kind: StatementKind::Assign(Place::from(dest), box rvalue) }); } @@ -273,7 +273,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { args, cleanup: None, destination: Some( - (Place::Base(PlaceBase::Local(new_temp)), new_target) + (Place::from(new_temp), new_target) ), from_hir_call, }, diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index 812a024e1d911..6878eceb2a5db 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -97,7 +97,7 @@ impl<'a, 'tcx> UniformArrayMoveOutVisitor<'a, 'tcx> { let temp = self.patch.new_temp(item_ty, self.body.source_info(location).span); self.patch.add_statement(location, StatementKind::StorageLive(temp)); self.patch.add_assign(location, - Place::Base(PlaceBase::Local(temp)), + Place::from(temp), Rvalue::Use( Operand::Move( Place::Projection(box Projection{ @@ -115,7 +115,7 @@ impl<'a, 'tcx> UniformArrayMoveOutVisitor<'a, 'tcx> { Rvalue::Aggregate( box AggregateKind::Array(item_ty), temps.iter().map( - |x| Operand::Move(Place::Base(PlaceBase::Local(*x))) + |x| Operand::Move(Place::from(*x)) ).collect() ) ); diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 91fc19b71d8ba..dac90d37275b4 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -486,7 +486,7 @@ where // discriminant after it is free-ed, because that // way lies only trouble. let discr_ty = adt.repr.discr_type().to_ty(self.tcx()); - let discr = Place::Base(PlaceBase::Local(self.new_temp(discr_ty))); + let discr = Place::from(self.new_temp(discr_ty)); let discr_rv = Rvalue::Discriminant(self.place.clone()); let switch_block = BasicBlockData { statements: vec![self.assign(&discr, discr_rv)], @@ -518,11 +518,11 @@ where mutbl: hir::Mutability::MutMutable }); let ref_place = self.new_temp(ref_ty); - let unit_temp = Place::Base(PlaceBase::Local(self.new_temp(tcx.mk_unit()))); + let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); let result = BasicBlockData { statements: vec![self.assign( - &Place::Base(PlaceBase::Local(ref_place)), + &Place::from(ref_place), Rvalue::Ref(tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, self.place.clone()) @@ -531,7 +531,7 @@ where kind: TerminatorKind::Call { func: Operand::function_handle(tcx, drop_fn.def_id, substs, self.source_info.span), - args: vec![Operand::Move(Place::Base(PlaceBase::Local(ref_place)))], + args: vec![Operand::Move(Place::from(ref_place))], destination: Some((unit_temp, succ)), cleanup: unwind.into_option(), from_hir_call: true, @@ -576,8 +576,8 @@ where ty: ety, mutbl: hir::Mutability::MutMutable }); - let ptr = &Place::Base(PlaceBase::Local(self.new_temp(ref_ty))); - let can_go = &Place::Base(PlaceBase::Local(self.new_temp(tcx.types.bool))); + let ptr = &Place::from(self.new_temp(ref_ty)); + let can_go = &Place::from(self.new_temp(tcx.types.bool)); let one = self.constant_usize(1); let (ptr_next, cur_next) = if ptr_based { @@ -589,19 +589,19 @@ where elem: ProjectionElem::Deref, })) ), - Rvalue::BinaryOp(BinOp::Offset, move_(&Place::Base(PlaceBase::Local(cur))), one)) + Rvalue::BinaryOp(BinOp::Offset, move_(&Place::from(cur)), one)) } else { (Rvalue::Ref( tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, self.place.clone().index(cur)), - Rvalue::BinaryOp(BinOp::Add, move_(&Place::Base(PlaceBase::Local(cur))), one)) + Rvalue::BinaryOp(BinOp::Add, move_(&Place::from(cur)), one)) }; let drop_block = BasicBlockData { statements: vec![ self.assign(ptr, ptr_next), - self.assign(&Place::Base(PlaceBase::Local(cur)), cur_next) + self.assign(&Place::from(cur), cur_next) ], is_cleanup: unwind.is_cleanup(), terminator: Some(Terminator { @@ -615,7 +615,7 @@ where let loop_block = BasicBlockData { statements: vec![ self.assign(can_go, Rvalue::BinaryOp(BinOp::Eq, - copy(&Place::Base(PlaceBase::Local(cur))), + copy(&Place::from(cur)), copy(length_or_end))) ], is_cleanup: unwind.is_cleanup(), @@ -665,8 +665,8 @@ where let move_ = |place: &Place<'tcx>| Operand::Move(place.clone()); let tcx = self.tcx(); - let elem_size = &Place::Base(PlaceBase::Local(self.new_temp(tcx.types.usize))); - let len = &Place::Base(PlaceBase::Local(self.new_temp(tcx.types.usize))); + let elem_size = &Place::from(self.new_temp(tcx.types.usize)); + let len = &Place::from(self.new_temp(tcx.types.usize)); static USIZE_SWITCH_ZERO: &[u128] = &[0]; @@ -713,8 +713,7 @@ where let length_or_end = if ptr_based { // FIXME check if we want to make it return a `Place` directly // if all use sites want a `Place::Base` anyway. - let temp = self.new_temp(iter_ty); - Place::Base(PlaceBase::Local(temp)) + Place::from(self.new_temp(iter_ty)) } else { length.clone() }; @@ -736,10 +735,10 @@ where unwind, ptr_based); - let cur = Place::Base(PlaceBase::Local(cur)); + let cur = Place::from(cur); let drop_block_stmts = if ptr_based { let tmp_ty = tcx.mk_mut_ptr(self.place_ty(self.place)); - let tmp = Place::Base(PlaceBase::Local(self.new_temp(tmp_ty))); + let tmp = Place::from(self.new_temp(tmp_ty)); // tmp = &mut P; // cur = tmp as *mut T; // end = Offset(cur, len); @@ -894,7 +893,7 @@ where unwind: Unwind, ) -> BasicBlock { let tcx = self.tcx(); - let unit_temp = Place::Base(PlaceBase::Local(self.new_temp(tcx.mk_unit()))); + let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem); let args = adt.variants[VariantIdx::new(0)].fields.iter().enumerate().map(|(i, f)| { let field = Field::new(i); diff --git a/src/librustc_mir/util/graphviz.rs b/src/librustc_mir/util/graphviz.rs index 7b154a9d46fa3..1d876d7bddb53 100644 --- a/src/librustc_mir/util/graphviz.rs +++ b/src/librustc_mir/util/graphviz.rs @@ -153,7 +153,7 @@ fn write_graph_label<'tcx, W: Write>( } write!(w, "{:?}: {}", - Place::Base(PlaceBase::Local(arg)), + Place::from(arg), escape(&body.local_decls[arg].ty) )?; } @@ -171,10 +171,10 @@ fn write_graph_label<'tcx, W: Write>( if let Some(name) = decl.name { write!(w, r#"{:?}: {}; // {}
"#, - Place::Base(PlaceBase::Local(local)), escape(&decl.ty), name)?; + Place::from(local), escape(&decl.ty), name)?; } else { write!(w, r#"{:?}: {};
"#, - Place::Base(PlaceBase::Local(local)), escape(&decl.ty))?; + Place::from(local), escape(&decl.ty))?; } } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index fc46adb702c8d..d66f35f82c662 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -601,7 +601,7 @@ fn write_mir_sig( if i != 0 { write!(w, ", ")?; } - write!(w, "{:?}: {}", Place::Base(PlaceBase::Local(arg)), body.local_decls[arg].ty)?; + write!(w, "{:?}: {}", Place::from(arg), body.local_decls[arg].ty)?; } write!(w, ") -> {}", body.return_ty())?;