From 3dd114e1cb24ce56d136dfd0af00780f06a2975c Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Fri, 24 May 2019 21:04:56 -0500 Subject: [PATCH 01/28] SliceConcatExt::connect defaults to calling join --- src/liballoc/slice.rs | 8 +++----- src/liballoc/str.rs | 4 ---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 8768f1ff081..04bef58774b 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -582,7 +582,9 @@ pub trait SliceConcatExt { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_deprecated(since = "1.3.0", reason = "renamed to join")] - fn connect(&self, sep: &T) -> Self::Output; + fn connect(&self, sep: &T) -> Self::Output { + self.join(sep) + } } #[unstable(feature = "slice_concat_ext", @@ -616,10 +618,6 @@ fn join(&self, sep: &T) -> Vec { } result } - - fn connect(&self, sep: &T) -> Vec { - self.join(sep) - } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index f66ff894ae8..0b7374fd8e4 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -86,10 +86,6 @@ fn join(&self, sep: &str) -> String { String::from_utf8_unchecked( join_generic_copy(self, sep.as_bytes()) ) } } - - fn connect(&self, sep: &str) -> String { - self.join(sep) - } } macro_rules! spezialize_for_lengths { From f65b6a87865d3768a798d33e97aa52656eeabe68 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 28 May 2019 14:05:00 +0200 Subject: [PATCH 02/28] rustc-book: Update the rustc/clang compatibility table for xLTO. --- src/doc/rustc/src/linker-plugin-lto.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/doc/rustc/src/linker-plugin-lto.md b/src/doc/rustc/src/linker-plugin-lto.md index 73a2efcb33a..2ae726c4ba6 100644 --- a/src/doc/rustc/src/linker-plugin-lto.md +++ b/src/doc/rustc/src/linker-plugin-lto.md @@ -100,9 +100,10 @@ LLVM. However, the approximation is usually reliable. The following table shows known good combinations of toolchain versions. -| | Clang 7 | Clang 8 | +| | Clang 7 | Clang 8 | |-----------|-----------|-----------| | Rust 1.34 | ✗ | ✓ | -| Rust 1.35 | ✗ | ✓(?) | +| Rust 1.35 | ✗ | ✓ | +| Rust 1.36 | ✗ | ✓ | Note that the compatibility policy for this feature might change in the future. From cf5df271b66822e1325e3825ccb439ca5a63bc51 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 9 Jun 2019 13:16:13 +0800 Subject: [PATCH 03/28] Changed the error message to more clearly explain what is allowed --- src/librustc_typeck/astconv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index cc054adee7b..6721730d945 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1011,7 +1011,7 @@ fn conv_object_ty_poly_trait_ref(&self, if regular_traits.is_empty() && auto_traits.is_empty() { span_err!(tcx.sess, span, E0224, - "at least one non-builtin trait is required for an object type"); + "at least one non-builtin trait, outside of &send, is required for an object type"); return tcx.types.err; } From 4e9615d88532c5373ff15dd1e7e29b54e250bbef Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 9 Jun 2019 14:31:39 +0800 Subject: [PATCH 04/28] changed the language of the error message to make it more clear --- src/librustc_typeck/astconv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 6721730d945..6dd8349299a 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1011,7 +1011,7 @@ fn conv_object_ty_poly_trait_ref(&self, if regular_traits.is_empty() && auto_traits.is_empty() { span_err!(tcx.sess, span, E0224, - "at least one non-builtin trait, outside of &send, is required for an object type"); + "at least one trait is required for an object type"); return tcx.types.err; } From 44109169a61daecb89e48c182601ba34250d8245 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 19 Jun 2019 15:25:31 +0200 Subject: [PATCH 05/28] replace NodeId with HirId in traits::ObligationCauseCode --- src/librustc/traits/error_reporting.rs | 6 +++--- src/librustc/traits/mod.rs | 2 +- src/librustc_typeck/check/mod.rs | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 2555833cd77..b433098c1b2 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -937,9 +937,9 @@ fn suggest_borrow_on_unsized_slice( code: &ObligationCauseCode<'tcx>, err: &mut DiagnosticBuilder<'tcx>, ) { - if let &ObligationCauseCode::VariableType(node_id) = code { - let parent_node = self.tcx.hir().get_parent_node(node_id); - if let Some(Node::Local(ref local)) = self.tcx.hir().find(parent_node) { + if let &ObligationCauseCode::VariableType(hir_id) = code { + let parent_node = self.tcx.hir().get_parent_node_by_hir_id(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 { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(expr.span) { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index f5c91a77517..8d17df1e610 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -188,7 +188,7 @@ pub enum ObligationCauseCode<'tcx> { /// S { ... } must be Sized StructInitializerSized, /// Type of each variable must be Sized - VariableType(ast::NodeId), + VariableType(hir::HirId), /// Argument type must be Sized SizedArgumentType, /// Return type must be Sized diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0e83db48284..0fee2f063b8 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -993,10 +993,9 @@ fn visit_pat(&mut self, p: &'tcx hir::Pat) { if let PatKind::Binding(_, _, ident, _) = p.node { let var_ty = self.assign(p.span, p.hir_id, None); - let node_id = self.fcx.tcx.hir().hir_to_node_id(p.hir_id); if !self.fcx.tcx.features().unsized_locals { self.fcx.require_type_is_sized(var_ty, p.span, - traits::VariableType(node_id)); + traits::VariableType(p.hir_id)); } debug!("Pattern binding {} is assigned to {} with type {:?}", From b710e08868514fb08ab3e93c85c1019aec1c7cf3 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 19 Jun 2019 15:28:27 +0200 Subject: [PATCH 06/28] remove TyCtx::expr_span (unused) --- src/librustc/ty/mod.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 361410380e8..e8b75be27e5 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2777,20 +2777,6 @@ pub fn par_body_owners(self, f: F) { }); } - pub fn expr_span(self, id: NodeId) -> Span { - match self.hir().find(id) { - Some(Node::Expr(e)) => { - e.span - } - Some(f) => { - bug!("node-ID {} is not an expr: {:?}", id, f); - } - None => { - bug!("node-ID {} is not present in the node map", id); - } - } - } - pub fn provided_trait_methods(self, id: DefId) -> Vec { self.associated_items(id) .filter(|item| item.kind == AssocKind::Method && item.defaultness.has_value()) From f6eb39203bcd8add887f72c1633cb46c50a13bf4 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 19 Jun 2019 15:33:32 +0200 Subject: [PATCH 07/28] replace NodeId with HirId in infer::SubregionOrigin --- src/librustc/infer/error_reporting/note.rs | 4 ++-- src/librustc/infer/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index cc7c13cea7d..3c6253a9604 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -50,7 +50,7 @@ pub(super) fn note_region_origin(&self, err.span_note(span, &format!("...so that captured variable `{}` does not outlive the \ enclosing closure", - self.tcx.hir().name(id))); + self.tcx.hir().name_by_hir_id(id))); } infer::IndexSlice(span) => { err.span_note(span, "...so that slice is not indexed outside the lifetime"); @@ -220,7 +220,7 @@ pub(super) fn report_concrete_failure(&self, E0474, "captured variable `{}` does not outlive the \ enclosing closure", - self.tcx.hir().name(id)); + self.tcx.hir().name_by_hir_id(id)); self.tcx.note_and_explain_region(region_scope_tree, &mut err, "captured variable is valid for ", sup, ""); self.tcx.note_and_explain_region(region_scope_tree, &mut err, diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index fc46fe383c9..5c5e6303b82 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -265,7 +265,7 @@ pub enum SubregionOrigin<'tcx> { DerefPointer(Span), /// Closure bound must not outlive captured variables - ClosureCapture(Span, ast::NodeId), + ClosureCapture(Span, hir::HirId), /// Index into slice must be within its lifetime IndexSlice(Span), From 468647cabb231d7a3efbdc7a1819d7dbdf699b36 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 19 Jun 2019 15:35:56 +0200 Subject: [PATCH 08/28] remove hir::map::name --- src/librustc/hir/map/mod.rs | 7 ------- src/librustc_mir/borrow_check/mod.rs | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 87da3273bd2..10632bc4d8a 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -940,13 +940,6 @@ pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { } } - /// Returns the name associated with the given `NodeId`'s AST. - pub fn name(&self, id: NodeId) -> Name { - let hir_id = self.node_to_hir_id(id); - self.name_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn name_by_hir_id(&self, id: HirId) -> Name { match self.get_by_hir_id(id) { Node::Item(i) => i.ident.name, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index ca8c4c58301..72e392fdddc 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -124,14 +124,13 @@ fn do_mir_borrowck<'a, 'tcx>( .flat_map(|v| v.values()) .map(|upvar_id| { let var_hir_id = upvar_id.var_path.hir_id; - let var_node_id = tcx.hir().hir_to_node_id(var_hir_id); let capture = tables.upvar_capture(*upvar_id); let by_ref = match capture { ty::UpvarCapture::ByValue => false, ty::UpvarCapture::ByRef(..) => true, }; let mut upvar = Upvar { - name: tcx.hir().name(var_node_id), + name: tcx.hir().name_by_hir_id(var_hir_id), var_hir_id, by_ref, mutability: Mutability::Not, From 98cc18a5db11c7833a93d7d28d7045569395f835 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 19 Jun 2019 15:44:51 +0200 Subject: [PATCH 09/28] rename hir::map::name_by_hir_id to ::name --- src/librustc/hir/map/mod.rs | 4 ++-- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/infer/error_reporting/note.rs | 8 ++++---- src/librustc/mir/mod.rs | 4 ++-- src/librustc/ty/print/pretty.rs | 4 ++-- src/librustc/ty/structural_impls.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 4 ++-- src/librustc_mir/borrow_check/conflict_errors.rs | 2 +- src/librustc_mir/borrow_check/error_reporting.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- .../nll/region_infer/error_reporting/var_name.rs | 2 +- src/librustc_mir/borrow_check/nll/universal_regions.rs | 2 +- src/librustc_mir/hair/cx/expr.rs | 2 +- src/librustc_typeck/astconv.rs | 6 +++--- src/librustc_typeck/check/upvar.rs | 2 +- src/librustdoc/passes/collect_intra_doc_links.rs | 2 +- 16 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 10632bc4d8a..259f6cd2711 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -940,7 +940,7 @@ pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { } } - pub fn name_by_hir_id(&self, id: HirId) -> Name { + pub fn name(&self, id: HirId) -> Name { match self.get_by_hir_id(id) { Node::Item(i) => i.ident.name, Node::ForeignItem(fi) => fi.ident.name, @@ -951,7 +951,7 @@ pub fn name_by_hir_id(&self, id: HirId) -> Name { Node::Lifetime(lt) => lt.name.ident().name, Node::GenericParam(param) => param.name.ident().name, Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name, - Node::Ctor(..) => self.name_by_hir_id(self.get_parent_item(id)), + Node::Ctor(..) => self.name(self.get_parent_item(id)), _ => bug!("no name for {}", self.node_to_string(id)) } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 321c06897de..2c063aaaa86 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1583,7 +1583,7 @@ fn report_inference_failure( format!(" for lifetime parameter `{}` in coherence check", name) } infer::UpvarRegion(ref upvar_id, _) => { - let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); + let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); format!(" for capture of `{}` by closure", var_name) } infer::NLL(..) => bug!("NLL variable found in lexical phase"), diff --git a/src/librustc/infer/error_reporting/note.rs b/src/librustc/infer/error_reporting/note.rs index 3c6253a9604..caed4288892 100644 --- a/src/librustc/infer/error_reporting/note.rs +++ b/src/librustc/infer/error_reporting/note.rs @@ -31,7 +31,7 @@ pub(super) fn note_region_origin(&self, "...so that reference does not outlive borrowed content"); } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); + let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); err.span_note(span, &format!("...so that closure can access `{}`", var_name)); } @@ -50,7 +50,7 @@ pub(super) fn note_region_origin(&self, err.span_note(span, &format!("...so that captured variable `{}` does not outlive the \ enclosing closure", - self.tcx.hir().name_by_hir_id(id))); + self.tcx.hir().name(id))); } infer::IndexSlice(span) => { err.span_note(span, "...so that slice is not indexed outside the lifetime"); @@ -163,7 +163,7 @@ pub(super) fn report_concrete_failure(&self, err } infer::ReborrowUpvar(span, ref upvar_id) => { - let var_name = self.tcx.hir().name_by_hir_id(upvar_id.var_path.hir_id); + let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); let mut err = struct_span_err!(self.tcx.sess, span, E0313, @@ -220,7 +220,7 @@ pub(super) fn report_concrete_failure(&self, E0474, "captured variable `{}` does not outlive the \ enclosing closure", - self.tcx.hir().name_by_hir_id(id)); + self.tcx.hir().name(id)); self.tcx.note_and_explain_region(region_scope_tree, &mut err, "captured variable is valid for ", sup, ""); self.tcx.note_and_explain_region(region_scope_tree, &mut err, diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 9dfd8d959a3..cc78640c8db 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2571,7 +2571,7 @@ fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result { if let Some(upvars) = tcx.upvars(def_id) { for (&var_id, place) in upvars.keys().zip(places) { - let var_name = tcx.hir().name_by_hir_id(var_id); + let var_name = tcx.hir().name(var_id); struct_fmt.field(&var_name.as_str(), place); } } @@ -2590,7 +2590,7 @@ fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result { if let Some(upvars) = tcx.upvars(def_id) { for (&var_id, place) in upvars.keys().zip(places) { - let var_name = tcx.hir().name_by_hir_id(var_id); + let var_name = tcx.hir().name(var_id); struct_fmt.field(&var_name.as_str(), place); } } diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index d143cc3e609..cb0ac0f07f2 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -600,7 +600,7 @@ fn pretty_print_type( p!( write("{}{}:", sep, - self.tcx().hir().name_by_hir_id(var_id)), + self.tcx().hir().name(var_id)), print(upvar_ty)); sep = ", "; } @@ -643,7 +643,7 @@ fn pretty_print_type( p!( write("{}{}:", sep, - self.tcx().hir().name_by_hir_id(var_id)), + self.tcx().hir().name(var_id)), print(upvar_ty)); sep = ", "; } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 4cd0fd3e824..fed6100b1b2 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -62,7 +62,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { impl fmt::Debug for ty::UpvarId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let name = ty::tls::with(|tcx| { - tcx.hir().name_by_hir_id(self.var_path.hir_id) + tcx.hir().name(self.var_path.hir_id) }); write!(f, "UpvarId({:?};`{}`;{:?})", self.var_path.hir_id, diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 025d5adc2b3..bfc61520d51 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1394,10 +1394,10 @@ pub fn append_loan_path_to_string(&self, out: &mut String) { match loan_path.kind { LpUpvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id: id }, closure_expr_id: _ }) => { - out.push_str(&self.tcx.hir().name_by_hir_id(id).as_str()); + out.push_str(&self.tcx.hir().name(id).as_str()); } LpVar(id) => { - out.push_str(&self.tcx.hir().name_by_hir_id(id).as_str()); + out.push_str(&self.tcx.hir().name(id).as_str()); } LpDowncast(ref lp_base, variant_def_id) => { diff --git a/src/librustc_mir/borrow_check/conflict_errors.rs b/src/librustc_mir/borrow_check/conflict_errors.rs index dfaad95fa3c..f23cffeda68 100644 --- a/src/librustc_mir/borrow_check/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/conflict_errors.rs @@ -853,7 +853,7 @@ fn report_local_value_does_not_live_long_enough( format!( "...but `{}` will be dropped here, when the function `{}` returns", name, - self.infcx.tcx.hir().name_by_hir_id(fn_hir_id), + self.infcx.tcx.hir().name(fn_hir_id), ), ); diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 7eb296353a4..27049119b26 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -349,7 +349,7 @@ fn describe_field_from_ty( let (&var_id, _) = self.infcx.tcx.upvars(def_id).unwrap() .get_index(field.index()).unwrap(); - self.infcx.tcx.hir().name_by_hir_id(var_id).to_string() + self.infcx.tcx.hir().name(var_id).to_string() } _ => { // Might need a revision when the fields in trait RFC is implemented diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 72e392fdddc..a78bf0356d1 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -130,7 +130,7 @@ fn do_mir_borrowck<'a, 'tcx>( ty::UpvarCapture::ByRef(..) => true, }; let mut upvar = Upvar { - name: tcx.hir().name_by_hir_id(var_hir_id), + name: tcx.hir().name(var_hir_id), var_hir_id, by_ref, mutability: Mutability::Not, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index 59fc4113794..750a1324fae 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -72,7 +72,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let upvar_hir_id = upvars[upvar_index].var_hir_id; debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id); - let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id); + let upvar_name = tcx.hir().name(upvar_hir_id); let upvar_span = tcx.hir().span(upvar_hir_id); debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}", upvar_name, upvar_span); diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index fa3c7b9613e..a85f4776a8b 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -767,7 +767,7 @@ fn for_each_late_bound_region_defined_on<'tcx>( owner: fn_def_id.index, local_id: *late_bound, }; - let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str(); + let name = tcx.hir().name(hir_id).as_interned_str(); let region_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion { scope: fn_def_id, diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index baf9086a480..597f172da67 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -914,7 +914,7 @@ fn convert_path_expr<'a, 'tcx>( let generics = cx.tcx.generics_of(item_def_id); let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); let index = generics.param_def_id_to_index[&local_def_id]; - let name = cx.tcx.hir().name_by_hir_id(hir_id).as_interned_str(); + let name = cx.tcx.hir().name(hir_id).as_interned_str(); let val = ConstValue::Param(ty::ParamConst::new(index, name)); ExprKind::Literal { literal: cx.tcx.mk_const( diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 267f3798bd1..514a400d90e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -123,7 +123,7 @@ pub fn ast_region_to_region(&self, { let tcx = self.tcx(); let lifetime_name = |def_id| { - tcx.hir().name_by_hir_id(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str() + tcx.hir().name(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str() }; let r = match tcx.named_region(lifetime.hir_id) { @@ -2004,7 +2004,7 @@ pub fn res_to_ty(&self, 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]; - tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str()) + tcx.mk_ty_param(index, tcx.hir().name(hir_id).as_interned_str()) } Res::SelfTy(Some(_), None) => { // `Self` in trait or type alias. @@ -2194,7 +2194,7 @@ pub fn ast_const_to_const( 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)]; - let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str(); + let name = tcx.hir().name(hir_id).as_interned_str(); const_.val = ConstValue::Param(ty::ParamConst::new(index, name)); } diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index bba108aa282..ac39757df74 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -652,5 +652,5 @@ fn mutate( } fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> ast::Name { - tcx.hir().name_by_hir_id(var_hir_id) + tcx.hir().name(var_hir_id) } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 68b96a40829..e6f09927796 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -246,7 +246,7 @@ fn fold_item(&mut self, mut item: Item) -> Option { match parent_node.or(self.mod_ids.last().cloned()) { Some(parent) if parent != hir::CRATE_HIR_ID => { // FIXME: can we pull the parent module's name from elsewhere? - Some(self.cx.tcx.hir().name_by_hir_id(parent).to_string()) + Some(self.cx.tcx.hir().name(parent).to_string()) } _ => None, } From 3ed75856352d6d1731eb47a2206fdc5633688451 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 09:41:26 +0200 Subject: [PATCH 10/28] make hir::def_kind work with HirId --- src/librustc/hir/map/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 259f6cd2711..572f94d3382 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -291,8 +291,8 @@ pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId { self.definitions.def_index_to_hir_id(def_id.to_def_id().index) } - fn def_kind(&self, node_id: NodeId) -> Option { - let node = if let Some(node) = self.find(node_id) { + fn def_kind(&self, hir_id: HirId) -> Option { + let node = if let Some(node) = self.find_by_hir_id(hir_id) { node } else { return None @@ -347,7 +347,7 @@ fn def_kind(&self, node_id: NodeId) -> Option { if variant_data.ctor_hir_id().is_none() { return None; } - let ctor_of = match self.find(self.get_parent_node(node_id)) { + let ctor_of = match self.find_by_hir_id(self.get_parent_node_by_hir_id(hir_id)) { Some(Node::Item(..)) => def::CtorOf::Struct, Some(Node::Variant(..)) => def::CtorOf::Variant, _ => unreachable!(), @@ -1400,8 +1400,8 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { pub fn provide(providers: &mut Providers<'_>) { providers.def_kind = |tcx, def_id| { - if let Some(node_id) = tcx.hir().as_local_node_id(def_id) { - tcx.hir().def_kind(node_id) + if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { + tcx.hir().def_kind(hir_id) } else { bug!("calling local def_kind query provider for upstream DefId: {:?}", def_id From 21e63dddbeca3ab15cf365f9bd8dbb8a188c1d9b Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 09:51:00 +0200 Subject: [PATCH 11/28] remove definitions::def_index_to_node_id (unused) --- src/librustc/hir/map/definitions.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index 6a561f0c63a..b4bda36bc8a 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -397,11 +397,6 @@ pub fn def_index_to_hir_id(&self, def_index: DefIndex) -> hir::HirId { self.node_to_hir_id[node_id] } - #[inline] - pub fn def_index_to_node_id(&self, def_index: DefIndex) -> ast::NodeId { - self.as_local_node_id(DefId::local(def_index)).unwrap() - } - /// Retrieves the span of the given `DefId` if `DefId` is in the local crate, the span exists /// and it's not `DUMMY_SP`. #[inline] From 2d1e223a0e61e93aaeeef01a0e4a71ee2234aa06 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 09:55:21 +0200 Subject: [PATCH 12/28] remove uses of the NodeId hir::map::expr --- src/librustc/hir/map/mod.rs | 6 ------ src/librustc_save_analysis/dump_visitor.rs | 3 ++- src/librustc_save_analysis/lib.rs | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 572f94d3382..10a85cc833a 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -927,12 +927,6 @@ pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem { } } - pub fn expect_expr(&self, id: NodeId) -> &'hir Expr { - let hir_id = self.node_to_hir_id(id); - self.expect_expr_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { match self.find_by_hir_id(id) { // read recorded by find Some(Node::Expr(expr)) => expr, diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index a7f46e87683..fa7e000106f 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1531,7 +1531,8 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) { self.process_macro_use(ex.span); match ex.node { ast::ExprKind::Struct(ref path, ref fields, ref base) => { - let hir_expr = self.save_ctxt.tcx.hir().expect_expr(ex.id); + let expr_hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ex.id); + let hir_expr = self.save_ctxt.tcx.hir().expect_expr_by_hir_id(expr_hir_id); let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) { Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(), _ => { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index bc813b3d5a2..3b0d0622bae 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -513,7 +513,8 @@ pub fn get_trait_ref_data(&self, trait_ref: &ast::TraitRef) -> Option { } pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { - let hir_node = self.tcx.hir().expect_expr(expr.id); + let expr_hir_id = self.tcx.hir().node_to_hir_id(expr.id); + let hir_node = self.tcx.hir().expect_expr_by_hir_id(expr_hir_id); let ty = self.tables.expr_ty_adjusted_opt(&hir_node); if ty.is_none() || ty.unwrap().sty == ty::Error { return None; From fe044a8bc2a1d24a43cd926c6e2afd1d5fc2052a Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 10:05:56 +0200 Subject: [PATCH 13/28] rename hir::map::expect_expr_by_hir_id to expect_expr --- src/librustc/hir/map/mod.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/infer/error_reporting/need_type_info.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 2 +- src/librustc_mir/borrow_check/error_reporting.rs | 2 +- .../nll/region_infer/error_reporting/region_name.rs | 2 +- src/librustc_passes/loops.rs | 2 +- src/librustc_save_analysis/dump_visitor.rs | 2 +- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 10a85cc833a..51ebd1188a5 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -927,7 +927,7 @@ pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem { } } - pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { + pub fn expect_expr(&self, id: HirId) -> &'hir Expr { match self.find_by_hir_id(id) { // read recorded by find Some(Node::Expr(expr)) => expr, _ => bug!("expected expr, found {}", self.node_to_string(id)) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 2c063aaaa86..18a2bc45385 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -617,7 +617,7 @@ fn note_error_origin( } hir::MatchSource::TryDesugar => { if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found { - let discrim_expr = self.tcx.hir().expect_expr_by_hir_id(discrim_hir_id); + let discrim_expr = self.tcx.hir().expect_expr(discrim_hir_id); let discrim_ty = if let hir::ExprKind::Call(_, args) = &discrim_expr.node { let arg_expr = args.first().expect("try desugaring call w/out arg"); self.in_progress_tables.and_then(|tables| { diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index fe151bdec6a..4426b5c0e85 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -133,7 +133,7 @@ pub fn need_type_info_err( }; if let Some(body_id) = body_id { - let expr = self.tcx.hir().expect_expr_by_hir_id(body_id.hir_id); + let expr = self.tcx.hir().expect_expr(body_id.hir_id); local_visitor.visit_expr(expr); } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index bfc61520d51..b22a8412ac8 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -702,7 +702,7 @@ pub fn report_use_of_moved_value(&self, move_data::MovePat => (self.tcx.hir().span(hir_id), ""), move_data::Captured => - (match self.tcx.hir().expect_expr_by_hir_id(hir_id).node { + (match self.tcx.hir().expect_expr(hir_id).node { hir::ExprKind::Closure(.., fn_decl_span, _) => fn_decl_span, ref r => bug!("Captured({:?}) maps to non-closure: {:?}", the_move.id, r), diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 27049119b26..ac64cf79537 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -659,7 +659,7 @@ fn closure_span( def_id, target_place, places ); let hir_id = self.infcx.tcx.hir().as_local_hir_id(def_id)?; - let expr = &self.infcx.tcx.hir().expect_expr_by_hir_id(hir_id).node; + let expr = &self.infcx.tcx.hir().expect_expr(hir_id).node; debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr); if let hir::ExprKind::Closure( .., args_span, _ diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 46b690129ea..3dc0a99c78b 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -237,7 +237,7 @@ fn give_name_from_error_region( if let DefiningTy::Closure(def_id, substs) = def_ty { let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) = - tcx.hir().expect_expr_by_hir_id(mir_hir_id).node + tcx.hir().expect_expr(mir_hir_id).node { span } else { diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index e1e4195d6d5..1c18322259f 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -116,7 +116,7 @@ fn visit_expr(&mut self, e: &'hir hir::Expr) { let loop_kind = if loop_id == hir::DUMMY_HIR_ID { None } else { - Some(match self.hir_map.expect_expr_by_hir_id(loop_id).node { + Some(match self.hir_map.expect_expr(loop_id).node { hir::ExprKind::While(..) => LoopKind::WhileLoop, hir::ExprKind::Loop(_, _, source) => LoopKind::Loop(source), ref r => span_bug!(e.span, diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index fa7e000106f..f67241ef23e 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1532,7 +1532,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) { match ex.node { ast::ExprKind::Struct(ref path, ref fields, ref base) => { let expr_hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ex.id); - let hir_expr = self.save_ctxt.tcx.hir().expect_expr_by_hir_id(expr_hir_id); + let hir_expr = self.save_ctxt.tcx.hir().expect_expr(expr_hir_id); let adt = match self.save_ctxt.tables.expr_ty_opt(&hir_expr) { Some(ty) if ty.ty_adt_def().is_some() => ty.ty_adt_def().unwrap(), _ => { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 3b0d0622bae..0664327d403 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -514,7 +514,7 @@ pub fn get_trait_ref_data(&self, trait_ref: &ast::TraitRef) -> Option { pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { let expr_hir_id = self.tcx.hir().node_to_hir_id(expr.id); - let hir_node = self.tcx.hir().expect_expr_by_hir_id(expr_hir_id); + let hir_node = self.tcx.hir().expect_expr(expr_hir_id); let ty = self.tables.expr_ty_adjusted_opt(&hir_node); if ty.is_none() || ty.unwrap().sty == ty::Error { return None; diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 5943302c708..10efae59867 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -389,7 +389,7 @@ pub fn report_method_error<'b>( Applicability::MachineApplicable, ); } else { - let call_expr = self.tcx.hir().expect_expr_by_hir_id( + let call_expr = self.tcx.hir().expect_expr( self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id), ); From ae72c9124709b5aac5d716176c8c89f2a3485bfc Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 10:15:07 +0200 Subject: [PATCH 14/28] make blocks::Code work with HirId --- src/librustc/hir/map/blocks.rs | 8 ++++---- src/librustc_driver/pretty.rs | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index f50037a746d..dd11bd15db8 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -15,7 +15,7 @@ use crate::hir::map; use crate::hir::{Expr, FnDecl, Node}; use crate::hir::intravisit::FnKind; -use syntax::ast::{Attribute, Ident, NodeId}; +use syntax::ast::{Attribute, Ident}; use syntax_pos::Span; /// An FnLikeNode is a Node that is like a fn, in that it has a decl @@ -83,11 +83,11 @@ pub fn id(&self) -> ast::HirId { } /// Attempts to construct a Code from presumed FnLike or Expr node input. - pub fn from_node(map: &map::Map<'a>, id: NodeId) -> Option> { - match map.get(id) { + pub fn from_node(map: &map::Map<'a>, id: ast::HirId) -> Option> { + match map.get_by_hir_id(id) { map::Node::Block(_) => { // Use the parent, hopefully an expression node. - Code::from_node(map, map.get_parent_node(id)) + Code::from_node(map, map.get_parent_node_by_hir_id(id)) } map::Node::Expr(expr) => Some(Code::Expr(expr)), node => FnLikeNode::from_node(node).map(Code::FnLike) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index eb89b5c1e63..13f179f037f 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -909,7 +909,8 @@ fn print_with_analysis<'tcx>( tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid)) }); - match blocks::Code::from_node(&tcx.hir(), 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); From a64456e48e782137d9c4a7ac407a047bc765db81 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 10:34:57 +0200 Subject: [PATCH 15/28] remove hir::map::get --- src/librustc/hir/map/mod.rs | 8 +------- src/librustc_driver/pretty.rs | 6 ++++-- src/librustc_save_analysis/dump_visitor.rs | 12 +++++++----- src/librustc_save_analysis/lib.rs | 14 +++++++------- src/librustc_save_analysis/sig.rs | 6 ++++-- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 51ebd1188a5..0cd4c98ec6c 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -561,12 +561,6 @@ pub fn visit_item_likes_in_module(&self, module: DefId, visitor: &mut V) } /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. - pub fn get(&self, id: NodeId) -> Node<'hir> { - let hir_id = self.node_to_hir_id(id); - self.get_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> { // read recorded by `find` self.find_by_hir_id(id).unwrap_or_else(|| @@ -574,7 +568,7 @@ pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> { } pub fn get_if_local(&self, id: DefId) -> Option> { - self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get` + self.as_local_hir_id(id).map(|id| self.get_by_hir_id(id)) // read recorded by `get` } pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> { diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 13f179f037f..7b2c70a3cad 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -830,7 +830,8 @@ pub fn print_after_hir_lowering<'tcx>( box out, annotation.pp_ann()); for node_id in uii.all_matching_node_ids(hir_map) { - let node = hir_map.get(node_id); + let hir_id = tcx.hir().node_to_hir_id(node_id); + let node = hir_map.get_by_hir_id(hir_id); pp_state.print_node(node)?; pp_state.s.space()?; let path = annotation.node_path(node_id) @@ -847,7 +848,8 @@ pub fn print_after_hir_lowering<'tcx>( s.call_with_pp_support_hir(tcx, move |_annotation, _krate| { debug!("pretty printing source code {:?}", s); for node_id in uii.all_matching_node_ids(tcx.hir()) { - let node = tcx.hir().get(node_id); + let hir_id = tcx.hir().node_to_hir_id(node_id); + let node = tcx.hir().get_by_hir_id(hir_id); write!(out, "{:#?}", node)?; } Ok(()) diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index f67241ef23e..4719965da8d 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -233,7 +233,8 @@ fn write_sub_paths_truncated(&mut self, path: &ast::Path) { } fn lookup_def_id(&self, ref_id: NodeId) -> Option { - match self.save_ctxt.get_path_res(ref_id) { + let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ref_id); + match self.save_ctxt.get_path_res(hir_id) { Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None, def => Some(def.def_id()), } @@ -886,7 +887,8 @@ fn process_pat(&mut self, p: &'l ast::Pat) { return; } }; - let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id)); + let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(p.id); + let variant = adt.variant_of_res(self.save_ctxt.get_path_res(hir_id)); for &Spanned { node: ref field, .. } in fields { if let Some(index) = self.tcx.find_field_index(field.ident, variant) { @@ -916,7 +918,8 @@ fn process_var_decl_multi(&mut self, pats: &'l [P]) { // process collected paths for (id, ident, immut) in collector.collected_idents { - match self.save_ctxt.get_path_res(id) { + let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(id); + match self.save_ctxt.get_path_res(hir_id) { Res::Local(hir_id) => { let mut value = if immut == ast::Mutability::Immutable { self.span.snippet(ident.span) @@ -1540,8 +1543,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) { return; } }; - let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id); - let res = self.save_ctxt.get_path_res(node_id); + let res = self.save_ctxt.get_path_res(hir_expr.hir_id); self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base) } ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args), diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 0664327d403..231fbac1f95 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -606,8 +606,8 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { } } - pub fn get_path_res(&self, id: NodeId) -> Res { - match self.tcx.hir().get(id) { + pub fn get_path_res(&self, hir_id: hir::HirId) -> Res { + match self.tcx.hir().get_by_hir_id(hir_id) { Node::TraitRef(tr) => tr.path.res, Node::Item(&hir::Item { @@ -620,7 +620,7 @@ pub fn get_path_res(&self, id: NodeId) -> Res { Node::PathSegment(seg) => { match seg.res { Some(res) if res != Res::Err => res, - _ => self.get_path_res(self.tcx.hir().get_parent_node(id)), + _ => self.get_path_res(self.tcx.hir().get_parent_node_by_hir_id(hir_id)), } } @@ -628,7 +628,6 @@ pub fn get_path_res(&self, id: NodeId) -> Res { node: hir::ExprKind::Struct(ref qpath, ..), .. }) => { - let hir_id = self.tcx.hir().node_to_hir_id(id); self.tables.qpath_res(qpath, hir_id) } @@ -652,7 +651,6 @@ pub fn get_path_res(&self, id: NodeId) -> Res { node: hir::TyKind::Path(ref qpath), .. }) => { - let hir_id = self.tcx.hir().node_to_hir_id(id); self.tables.qpath_res(qpath, hir_id) } @@ -697,7 +695,8 @@ fn fn_type(seg: &ast::PathSegment) -> bool { return None; } - let res = self.get_path_res(id); + let hir_id = self.tcx.hir().node_to_hir_id(id); + let res = self.get_path_res(hir_id); let span = path_seg.ident.span; filter!(self.span_utils, span); let span = self.span_from_span(span); @@ -869,7 +868,8 @@ pub fn get_macro_use_data(&self, span: Span) -> Option { } fn lookup_ref_id(&self, ref_id: NodeId) -> Option { - match self.get_path_res(ref_id) { + let hir_id = self.tcx.hir().node_to_hir_id(ref_id); + match self.get_path_res(hir_id) { Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None, def => Some(def.def_id()), } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index db8b5eacd94..7af18a8676a 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -273,7 +273,8 @@ fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, }; let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?); - let res = scx.get_path_res(id.ok_or("Missing id for Path")?); + let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id)); + let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?); let id = id_from_def_id(res.def_id()); if path.segments.len() - qself.position == 1 { let start = offset + prefix.len(); @@ -576,7 +577,8 @@ fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, impl Sig for ast::Path { fn make(&self, offset: usize, id: Option, scx: &SaveContext<'_, '_>) -> Result { - let res = scx.get_path_res(id.ok_or("Missing id for Path")?); + let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id)); + let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?); let (name, start, end) = match res { Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => { From 73cb9ab5261813309b41e21cacfc44d2b61fe396 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 20 Jun 2019 10:39:19 +0200 Subject: [PATCH 16/28] rename hir::map::get_by_hir_id to get --- src/librustc/hir/map/blocks.rs | 2 +- src/librustc/hir/map/mod.rs | 16 +++++++-------- src/librustc/infer/error_reporting/mod.rs | 2 +- .../nice_region_error/find_anon_type.rs | 2 +- .../nice_region_error/outlives_closure.rs | 2 +- src/librustc/infer/opaque_types/mod.rs | 4 ++-- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/region.rs | 4 ++-- src/librustc/middle/resolve_lifetime.rs | 10 +++++----- src/librustc/middle/stability.rs | 2 +- src/librustc/ty/constness.rs | 2 +- src/librustc/ty/context.rs | 2 +- src/librustc/ty/mod.rs | 4 ++-- src/librustc_borrowck/borrowck/check_loans.rs | 2 +- .../borrowck/gather_loans/gather_moves.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 12 +++++------ src/librustc_codegen_llvm/consts.rs | 2 +- .../back/symbol_export.rs | 2 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- src/librustc_driver/pretty.rs | 6 +++--- .../persist/dirty_clean.rs | 2 +- src/librustc_lint/types.rs | 4 ++-- src/librustc_mir/borrow_check/mod.rs | 2 +- .../error_reporting/region_name.rs | 4 ++-- src/librustc_mir/build/mod.rs | 2 +- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/interpret/validity.rs | 2 +- src/librustc_mir/lints.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 2 +- src/librustc_privacy/lib.rs | 8 ++++---- src/librustc_save_analysis/lib.rs | 2 +- src/librustc_traits/lowering/environment.rs | 2 +- src/librustc_typeck/check/_match.rs | 6 +++--- src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/coercion.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 16 +++++++-------- src/librustc_typeck/collect.rs | 20 +++++++++---------- .../outlives/implicit_infer.rs | 2 +- src/librustc_typeck/outlives/mod.rs | 2 +- src/librustc_typeck/variance/mod.rs | 2 +- src/librustdoc/visit_ast.rs | 2 +- .../auxiliary/issue-40001-plugin.rs | 2 +- 44 files changed, 88 insertions(+), 88 deletions(-) diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index dd11bd15db8..8c5fa97d4b7 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -84,7 +84,7 @@ pub fn id(&self) -> ast::HirId { /// Attempts to construct a Code from presumed FnLike or Expr node input. pub fn from_node(map: &map::Map<'a>, id: ast::HirId) -> Option> { - match map.get_by_hir_id(id) { + 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)) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 0cd4c98ec6c..0b8b69be0a4 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -458,7 +458,7 @@ pub fn body_owned_by(&self, id: HirId) -> BodyId { } pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { - match self.get_by_hir_id(id) { + match self.get(id) { Node::Item(&Item { node: ItemKind::Const(..), .. }) | Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) | Node::ImplItem(&ImplItem { node: ImplItemKind::Const(..), .. }) | @@ -482,7 +482,7 @@ pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { } pub fn ty_param_owner(&self, id: HirId) -> HirId { - match self.get_by_hir_id(id) { + 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), @@ -491,7 +491,7 @@ pub fn ty_param_owner(&self, id: HirId) -> HirId { } pub fn ty_param_name(&self, id: HirId) -> Name { - match self.get_by_hir_id(id) { + match self.get(id) { Node::Item(&Item { node: ItemKind::Trait(..), .. }) | Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper, Node::GenericParam(param) => param.name.ident().name, @@ -561,14 +561,14 @@ pub fn visit_item_likes_in_module(&self, module: DefId, visitor: &mut V) } /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. - pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> { + pub fn get(&self, id: HirId) -> Node<'hir> { // read recorded by `find` self.find_by_hir_id(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id)) } pub fn get_if_local(&self, id: DefId) -> Option> { - self.as_local_hir_id(id).map(|id| self.get_by_hir_id(id)) // read recorded by `get` + self.as_local_hir_id(id).map(|id| self.get(id)) // read recorded by `get` } pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> { @@ -840,7 +840,7 @@ pub fn get_defining_scope(&self, id: HirId) -> Option { if scope == CRATE_HIR_ID { return Some(CRATE_HIR_ID); } - match self.get_by_hir_id(scope) { + match self.get(scope) { Node::Item(i) => { match i.node { ItemKind::Existential(ExistTy { impl_trait_fn: None, .. }) => {} @@ -929,7 +929,7 @@ pub fn expect_expr(&self, id: HirId) -> &'hir Expr { } pub fn name(&self, id: HirId) -> Name { - match self.get_by_hir_id(id) { + match self.get(id) { Node::Item(i) => i.ident.name, Node::ForeignItem(fi) => fi.ident.name, Node::ImplItem(ii) => ii.ident.name, @@ -1061,7 +1061,7 @@ pub fn hir_to_user_string(&self, id: HirId) -> String { } pub fn hir_to_pretty_string(&self, id: HirId) -> String { - print::to_string(self, |s| s.print_node(self.get_by_hir_id(id))) + print::to_string(self, |s| s.print_node(self.get(id))) } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 18a2bc45385..d1e32b1dbad 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1335,7 +1335,7 @@ pub fn construct_generic_bound_failure( // We do this to avoid suggesting code that ends up as `T: 'a'b`, // instead we suggest `T: 'a + 'b` in that case. let mut has_bounds = false; - if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) { + if let Node::GenericParam(ref param) = hir.get(id) { has_bounds = !param.bounds.is_empty(); } let sp = hir.span(id); diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index 78d1d56993e..283af94b89b 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -29,7 +29,7 @@ pub(super) fn find_anon_type( if let Some(anon_reg) = self.tcx().is_suitable_region(region) { let def_id = anon_reg.def_id; if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) { - let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) { + let fndecl = match self.tcx().hir().get(hir_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(ref fndecl, ..), .. diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs index 6ed2b67556d..f5a4dac2c2c 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -52,7 +52,7 @@ pub(super) fn try_report_outlives_closure(&self) -> Option { if let Node::Expr(Expr { node: Closure(_, _, _, closure_span, None), .. - }) = hir.get_by_hir_id(hir_id) { + }) = hir.get(hir_id) { let sup_sp = sup_origin.span(); let origin_sp = origin.span(); let mut err = self.tcx().sess.struct_span_err( diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 60554a30060..a687b0e4591 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -945,8 +945,8 @@ pub fn may_define_existential_type( let mut hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); trace!( "may_define_existential_type(def={:?}, opaque_node={:?})", - tcx.hir().get_by_hir_id(hir_id), - tcx.hir().get_by_hir_id(opaque_hir_id) + tcx.hir().get(hir_id), + tcx.hir().get(opaque_hir_id) ); // Named existential types can be defined by any siblings or children of siblings. diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index bf054d68b70..0d59e32b098 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1630,7 +1630,7 @@ fn warn_about_unused(&self, ); if self.ir.variable_is_shorthand(var) { - if let Node::Binding(pat) = self.ir.tcx.hir().get_by_hir_id(hir_id) { + if let Node::Binding(pat) = self.ir.tcx.hir().get(hir_id) { // Handle `ref` and `ref mut`. let spans = spans.iter() .map(|_span| (pat.span, format!("{}: _", name))) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index c0f56a33eec..10796abe5d4 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -344,7 +344,7 @@ fn from_local( tables: &ty::TypeckTables<'_>, id: hir::HirId, ) -> MutabilityCategory { - let ret = match tcx.hir().get_by_hir_id(id) { + let ret = match tcx.hir().get(id) { Node::Binding(p) => match p.node { PatKind::Binding(..) => { let bm = *tables.pat_binding_modes() diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 93cb6ab96f8..d9ccb9d42f2 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -190,7 +190,7 @@ pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span { } let span = tcx.hir().span(hir_id); if let ScopeData::Remainder(first_statement_index) = self.data { - if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) { + if let Node::Block(ref blk) = tcx.hir().get(hir_id) { // Want span for scope starting after the // indexed statement and ending at end of // `blk`; reuse span of `blk` and shift `lo` @@ -1368,7 +1368,7 @@ fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ScopeTree // If the item is an associated const or a method, // record its impl/trait parent, as it can also have // lifetime parameters free in this body. - match tcx.hir().get_by_hir_id(id) { + match tcx.hir().get(id) { Node::ImplItem(_) | Node::TraitItem(_) => { visitor.scope_tree.root_parent = Some(tcx.hir().get_parent_item(id)); diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index f68e18c2bb8..b8e7db99d07 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1488,7 +1488,7 @@ fn suggest_eliding_single_use_lifetime( } } }; - if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get_by_hir_id(lifetime.hir_id) { + if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.hir_id) { if let Some(parent) = self.tcx.hir().find_by_hir_id( self.tcx.hir().get_parent_item(hir_lifetime.hir_id)) { @@ -1569,7 +1569,7 @@ fn check_uses_for_lifetimes_defined_by_scope(&mut self) { Some(LifetimeUseSet::One(lifetime)) => { let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); debug!("hir id first={:?}", hir_id); - if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) { + if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) { Node::Lifetime(hir_lifetime) => Some(( hir_lifetime.hir_id, hir_lifetime.span, @@ -1620,7 +1620,7 @@ fn check_uses_for_lifetimes_defined_by_scope(&mut self) { } None => { let hir_id = self.tcx.hir().as_local_hir_id(def_id).unwrap(); - if let Some((id, span, name)) = match self.tcx.hir().get_by_hir_id(hir_id) { + if let Some((id, span, name)) = match self.tcx.hir().get(hir_id) { Node::Lifetime(hir_lifetime) => Some(( hir_lifetime.hir_id, hir_lifetime.span, @@ -1823,7 +1823,7 @@ fn resolve_lifetime_ref(&mut self, lifetime_ref: &'tcx hir::Lifetime) { // Do not free early-bound regions, only late-bound ones. } else if let Some(body_id) = outermost_body { let fn_id = self.tcx.hir().body_owner(body_id); - match self.tcx.hir().get_by_hir_id(fn_id) { + match self.tcx.hir().get(fn_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(..), .. @@ -2052,7 +2052,7 @@ fn visit_fn_like_elision(&mut self, inputs: &'tcx [hir::Ty], output: Option<&'tc 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 body = match self.tcx.hir().get_by_hir_id(parent) { + let body = match self.tcx.hir().get(parent) { // `fn` definitions and methods. Node::Item(&hir::Item { node: hir::ItemKind::Fn(.., body), diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 5a1e5212f86..38df4060652 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -580,7 +580,7 @@ pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> Eva let mut diag = self.struct_span_lint_hir(lint, id, span, &msg); if let Some(suggestion) = suggestion { - if let hir::Node::Expr(_) = self.hir().get_by_hir_id(id) { + if let hir::Node::Expr(_) = self.hir().get(id) { diag.span_suggestion( span, "replace the use of the deprecated item", diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs index 65b83224ae5..80d97b7bc77 100644 --- a/src/librustc/ty/constness.rs +++ b/src/librustc/ty/constness.rs @@ -73,7 +73,7 @@ fn is_const_fn_raw<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { let hir_id = tcx.hir().as_local_hir_id(def_id) .expect("Non-local call to local provider is_const_fn"); - let node = tcx.hir().get_by_hir_id(hir_id); + let node = tcx.hir().get(hir_id); if let Some(fn_like) = FnLikeNode::from_node(node) { fn_like.constness() == hir::Constness::Const } else if let hir::Node::Ctor(_) = node { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index b84ebd8afe8..f0452befed8 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1610,7 +1610,7 @@ pub fn return_type_impl_trait( ) -> Option> { // HACK: `type_of_def_id()` will fail on these (#55796), so return None let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap(); - match self.hir().get_by_hir_id(hir_id) { + match self.hir().get(hir_id) { Node::Item(item) => { match item.node { ItemKind::Fn(..) => { /* type_of_def_id() will work */ } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index e8b75be27e5..a3cb9d17cd2 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2791,7 +2791,7 @@ pub fn trait_relevant_for_never(self, did: DefId) -> bool { pub fn opt_associated_item(self, def_id: DefId) -> Option { let is_associated_item = if let Some(hir_id) = self.hir().as_local_hir_id(def_id) { - match self.hir().get_by_hir_id(hir_id) { + match self.hir().get(hir_id) { Node::TraitItem(_) | Node::ImplItem(_) => true, _ => false, } @@ -3213,7 +3213,7 @@ fn trait_of_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option { /// Yields the parent function's `DefId` if `def_id` is an `impl Trait` definition. pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { - if let Node::Item(item) = tcx.hir().get_by_hir_id(hir_id) { + if let Node::Item(item) = tcx.hir().get(hir_id) { if let hir::ItemKind::Existential(ref exist_ty) = item.node { return exist_ty.impl_trait_fn; } diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index ace44421d37..714b7c27200 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -191,7 +191,7 @@ pub fn check_loans<'a, 'tcx>( let def_id = bccx.tcx.hir().body_owner_def_id(body.id()); let hir_id = bccx.tcx.hir().as_local_hir_id(def_id).unwrap(); - let movable_generator = !match bccx.tcx.hir().get_by_hir_id(hir_id) { + let movable_generator = !match bccx.tcx.hir().get(hir_id) { Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)), .. diff --git a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs index 05c0a22900a..fa286632dac 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/gather_moves.rs @@ -49,7 +49,7 @@ 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); - match tcx.hir().get_by_hir_id(parent) { + match tcx.hir().get(parent) { Node::Expr(ref e) => { // the enclosing expression must be a `match` or something else assert!(match e.node { diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index b22a8412ac8..87c0b8563ca 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -80,7 +80,7 @@ fn borrowck<'tcx>(tcx: TyCtxt<'tcx>, owner_def_id: DefId) -> &'tcx BorrowCheckRe let owner_id = tcx.hir().as_local_hir_id(owner_def_id).unwrap(); - match tcx.hir().get_by_hir_id(owner_id) { + match tcx.hir().get(owner_id) { Node::Ctor(..) => { // We get invoked with anything that has MIR, but some of // those things (notably the synthesized constructors from @@ -390,7 +390,7 @@ pub enum LoanPathElem<'tcx> { fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_>) -> HirId { let closure_id = tcx.hir().local_def_id_to_hir_id(closure_id); - match tcx.hir().get_by_hir_id(closure_id) { + match tcx.hir().get(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { body_id.hir_id @@ -896,7 +896,7 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) { // to implement two traits for "one operator" is not very intuitive for // many programmers. if err.cmt.note == mc::NoteIndex { - let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); + let node = self.tcx.hir().get(err.cmt.hir_id); // This pattern probably always matches. if let Node::Expr( @@ -1172,7 +1172,7 @@ fn suggest_mut_for_immutable(&self, pty: &hir::Ty, is_implicit_self: bool) -> Op } fn local_binding_mode(&self, hir_id: hir::HirId) -> ty::BindingMode { - let pat = match self.tcx.hir().get_by_hir_id(hir_id) { + let pat = match self.tcx.hir().get(hir_id) { Node::Binding(pat) => pat, node => bug!("bad node for local: {:?}", node) }; @@ -1190,7 +1190,7 @@ fn local_binding_mode(&self, hir_id: hir::HirId) -> ty::BindingMode { 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_node = self.tcx.hir().get_by_hir_id(parent); + let parent_node = self.tcx.hir().get(parent); // The parent node is like a fn if let Some(fn_like) = FnLikeNode::from_node(parent_node) { @@ -1255,7 +1255,7 @@ fn note_immutability_blame(&self, None => return }; - if let Node::Field(ref field) = self.tcx.hir().get_by_hir_id(hir_id) { + if let Node::Field(ref field) = self.tcx.hir().get(hir_id) { if let Some(msg) = self.suggest_mut_for_immutable(&field.ty, false) { db.span_label(field.ty.span, msg); } diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 4bf91bbed60..ef8ca6f7a06 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -208,7 +208,7 @@ impl CodegenCx<'ll, 'tcx> { let g = if let Some(id) = self.tcx.hir().as_local_hir_id(def_id) { let llty = self.layout_of(ty).llvm_type(self); - let (g, attrs) = match self.tcx.hir().get_by_hir_id(id) { + let (g, attrs) = match self.tcx.hir().get(id) { Node::Item(&hir::Item { ref attrs, span, node: hir::ItemKind::Static(..), .. }) => { diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index aeff73c7e52..b9ee82f108a 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -82,7 +82,7 @@ fn reachable_non_generics_provider<'tcx>( // // As a result, if this id is an FFI item (foreign item) then we only // let it through if it's included statically. - match tcx.hir().get_by_hir_id(hir_id) { + match tcx.hir().get(hir_id) { Node::ForeignItem(..) => { let def_id = tcx.hir().local_def_id_from_hir_id(hir_id); if tcx.is_statically_included_foreign_item(def_id) { diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index ba74f79eba3..7ccd024769f 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -135,7 +135,7 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString { // FIXME(eddyb) Precompute a custom symbol name based on attributes. let is_foreign = if let Some(id) = hir_id { - match tcx.hir().get_by_hir_id(id) { + match tcx.hir().get(id) { Node::ForeignItem(_) => true, _ => false, } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 7b2c70a3cad..03016618249 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -627,7 +627,7 @@ fn print_flowgraph<'tcx, W: Write>( // Find the function this expression is from. let mut hir_id = expr.hir_id; loop { - let node = tcx.hir().get_by_hir_id(hir_id); + let node = tcx.hir().get(hir_id); if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) { break n.body(); } @@ -831,7 +831,7 @@ pub fn print_after_hir_lowering<'tcx>( annotation.pp_ann()); for node_id in uii.all_matching_node_ids(hir_map) { let hir_id = tcx.hir().node_to_hir_id(node_id); - let node = hir_map.get_by_hir_id(hir_id); + let node = hir_map.get(hir_id); pp_state.print_node(node)?; pp_state.s.space()?; let path = annotation.node_path(node_id) @@ -849,7 +849,7 @@ pub fn print_after_hir_lowering<'tcx>( debug!("pretty printing source code {:?}", s); for node_id in uii.all_matching_node_ids(tcx.hir()) { let hir_id = tcx.hir().node_to_hir_id(node_id); - let node = tcx.hir().get_by_hir_id(hir_id); + let node = tcx.hir().get(hir_id); write!(out, "{:#?}", node)?; } Ok(()) diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index e2e4a4ebcb0..5296ed0ffd0 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -322,7 +322,7 @@ fn except(&self, attr: &Attribute) -> Labels { /// Return all DepNode labels that should be asserted for this item. /// index=0 is the "name" used for error messages fn auto_labels(&mut self, item_id: hir::HirId, attr: &Attribute) -> (&'static str, Labels) { - let node = self.tcx.hir().get_by_hir_id(item_id); + let node = self.tcx.hir().get(item_id); let (name, labels) = match node { HirNode::Item(item) => { match item.node { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 5f052f65333..cd4eecf2638 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -276,7 +276,7 @@ fn lint_int_literal<'a, 'tcx>( } let par_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id); - if let Node::Expr(par_e) = cx.tcx.hir().get_by_hir_id(par_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) && lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t) @@ -315,7 +315,7 @@ fn lint_uint_literal<'a, 'tcx>( }; if lit_val < min || lit_val > max { let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id); - if let Node::Expr(par_e) = cx.tcx.hir().get_by_hir_id(parent_id) { + if let Node::Expr(par_e) = cx.tcx.hir().get(parent_id) { match par_e.node { hir::ExprKind::Cast(..) => { if let ty::Char = cx.tables.expr_ty(par_e).sty { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index a78bf0356d1..919ed5ccaba 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -230,7 +230,7 @@ fn do_mir_borrowck<'a, 'tcx>( |bd, i| DebugFormatted::new(&bd.move_data().inits[i]), )); - let movable_generator = match tcx.hir().get_by_hir_id(id) { + let movable_generator = match tcx.hir().get(id) { Node::Expr(&hir::Expr { node: hir::ExprKind::Closure(.., Some(hir::GeneratorMovability::Static)), .. diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 3dc0a99c78b..3f5b2f4bce7 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -698,7 +698,7 @@ fn give_name_if_anonymous_region_appears_in_output( let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); - let (return_span, mir_description) = match tcx.hir().get_by_hir_id(mir_hir_id) { + let (return_span, mir_description) = match tcx.hir().get(mir_hir_id) { hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, return_ty, _, span, gen_move), .. @@ -761,7 +761,7 @@ fn give_name_if_anonymous_region_appears_in_yield_ty( let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); - let yield_span = match tcx.hir().get_by_hir_id(mir_hir_id) { + let yield_span = match tcx.hir().get(mir_hir_id) { hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, span, _), .. diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index f7958434afa..66064221b39 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -26,7 +26,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); // Figure out what primary body this item has. - let (body_id, return_ty_span) = match tcx.hir().get_by_hir_id(id) { + let (body_id, return_ty_span) = match tcx.hir().get(id) { Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, decl, body_id, _, _), .. }) | Node::Item(hir::Item { node: hir::ItemKind::Fn(decl, _, _, body_id), .. }) | Node::ImplItem( diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index 4e197f1ed4e..a21d900cf5e 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -155,7 +155,7 @@ pub fn const_eval_literal( pub fn pattern_from_hir(&mut self, p: &hir::Pat) -> Pattern<'tcx> { let tcx = self.tcx.global_tcx(); - let p = match tcx.hir().get_by_hir_id(p.hir_id) { + let p = match tcx.hir().get(p.hir_id) { Node::Pat(p) | Node::Binding(p) => p, node => bug!("pattern became {:?}", node) }; diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index d747eddd8d7..e42c667fec9 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -193,7 +193,7 @@ fn aggregate_field_path_elem( // Sometimes the index is beyond the number of upvars (seen // for a generator). if let Some((&var_hir_id, _)) = upvars.get_index(field) { - let node = self.ecx.tcx.hir().get_by_hir_id(var_hir_id); + let node = self.ecx.tcx.hir().get(var_hir_id); if let hir::Node::Binding(pat) = node { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { name = Some(ident.name); diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index a7120888742..8c815a51b5d 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -10,7 +10,7 @@ pub fn check(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)) { + if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) { check_fn_for_unconditional_recursion(tcx, fn_like_node.kind(), body, def_id); } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 5b567512a7b..9092cf2c457 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -41,7 +41,7 @@ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut let hir_id = tcx.hir().as_local_hir_id(source.def_id()) .expect("Non-local call to local provider is_const_fn"); - let is_fn_like = FnLikeNode::from_node(tcx.hir().get_by_hir_id(hir_id)).is_some(); + let is_fn_like = FnLikeNode::from_node(tcx.hir().get(hir_id)).is_some(); let is_assoc_const = match tcx.def_kind(source.def_id()) { Some(DefKind::AssocConst) => true, _ => false, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index ba834bf09aa..0fdc9ac8903 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -229,14 +229,14 @@ fn def_id_visibility<'tcx>( ) -> (ty::Visibility, Span, &'static str) { match tcx.hir().as_local_hir_id(def_id) { Some(hir_id) => { - let vis = match tcx.hir().get_by_hir_id(hir_id) { + let vis = match tcx.hir().get(hir_id) { Node::Item(item) => &item.vis, Node::ForeignItem(foreign_item) => &foreign_item.vis, Node::TraitItem(..) | Node::Variant(..) => { return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id)); } Node::ImplItem(impl_item) => { - match tcx.hir().get_by_hir_id(tcx.hir().get_parent_item(hir_id)) { + match tcx.hir().get(tcx.hir().get_parent_item(hir_id)) { Node::Item(item) => match &item.node { hir::ItemKind::Impl(.., None, _, _) => &impl_item.vis, hir::ItemKind::Impl(.., Some(trait_ref), _, _) @@ -248,7 +248,7 @@ fn def_id_visibility<'tcx>( } Node::Ctor(vdata) => { let parent_hir_id = tcx.hir().get_parent_node_by_hir_id(hir_id); - match tcx.hir().get_by_hir_id(parent_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); let (mut ctor_vis, mut span, mut descr) = def_id_visibility( @@ -274,7 +274,7 @@ fn def_id_visibility<'tcx>( return (ctor_vis, span, descr); } Node::Item(..) => { - let item = match tcx.hir().get_by_hir_id(parent_hir_id) { + let item = match tcx.hir().get(parent_hir_id) { Node::Item(item) => item, node => bug!("unexpected node kind: {:?}", node), }; diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 231fbac1f95..27e312f65ce 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -607,7 +607,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { } pub fn get_path_res(&self, hir_id: hir::HirId) -> Res { - match self.tcx.hir().get_by_hir_id(hir_id) { + match self.tcx.hir().get(hir_id) { Node::TraitRef(tr) => tr.path.res, Node::Item(&hir::Item { diff --git a/src/librustc_traits/lowering/environment.rs b/src/librustc_traits/lowering/environment.rs index d1bad6b4d1e..01736855831 100644 --- a/src/librustc_traits/lowering/environment.rs +++ b/src/librustc_traits/lowering/environment.rs @@ -185,7 +185,7 @@ fn visit_clause(&mut self, clause: Clause<'tcx>) { .map(Clause::ForAll); let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let node = tcx.hir().get_by_hir_id(hir_id); + let node = tcx.hir().get(hir_id); enum NodeKind { TraitImpl, diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 65a36d92306..293b68c8711 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -547,7 +547,7 @@ fn borrow_pat_suggestion( 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 = tcx.hir().get_by_hir_id(parent_id); + let parent = tcx.hir().get(parent_id); debug!("inner {:?} pat {:?} parent {:?}", inner, pat, parent); match parent { hir::Node::Item(hir::Item { node: hir::ItemKind::Fn(..), .. }) | @@ -812,10 +812,10 @@ fn maybe_get_coercion_reason(&self, hir_id: hir::HirId, span: Span) -> Option<(S 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 node = hir.get_by_hir_id(containing_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_by_hir_id( + let parent = hir.get( hir.get_parent_node_by_hir_id( hir.get_parent_node_by_hir_id(block.hir_id), ), diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 42c7ff607c5..87807ad91a2 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -245,7 +245,7 @@ fn identify_bad_closure_def_and_call( callee_span: Span, ) { let hir_id = self.tcx.hir().get_parent_node_by_hir_id(hir_id); - let parent_node = self.tcx.hir().get_by_hir_id(hir_id); + let parent_node = self.tcx.hir().get(hir_id); if let ( hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, sp, ..), .. }), hir::ExprKind::Block(..), diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index a56196ccf82..71a0ca090b0 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -1291,7 +1291,7 @@ fn report_return_mismatched_types<'a>( cause.span, blk_id, ); - let parent = fcx.tcx.hir().get_by_hir_id(parent_id); + let parent = fcx.tcx.hir().get(parent_id); fcx.get_node_fn_decl(parent).map(|(fn_decl, _, is_main)| (fn_decl, is_main)) } else { fcx.get_fn_decl(parent_id) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 10efae59867..8ad67c2adc0 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -268,7 +268,7 @@ pub fn report_method_error<'b>( let snippet = tcx.sess.source_map().span_to_snippet(span); let filename = tcx.sess.source_map().span_to_filename(span); - let parent_node = self.tcx.hir().get_by_hir_id( + let parent_node = self.tcx.hir().get( self.tcx.hir().get_parent_node_by_hir_id(hir_id), ); let msg = format!( diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0fee2f063b8..bddbebb4e15 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -759,7 +759,7 @@ fn primary_body_of<'tcx>( tcx: TyCtxt<'tcx>, id: hir::HirId, ) -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> { - match tcx.hir().get_by_hir_id(id) { + match tcx.hir().get(id) { Node::Item(item) => { match item.node { hir::ItemKind::Const(_, body) | @@ -1213,7 +1213,7 @@ fn check_fn<'a, 'tcx>( ); } - if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -1261,7 +1261,7 @@ fn check_fn<'a, 'tcx>( ); } - if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -3676,7 +3676,7 @@ fn check_block_with_expected( } fn parent_item_span(&self, id: hir::HirId) -> Option { - let node = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(id)); + let node = self.tcx.hir().get(self.tcx.hir().get_parent_item(id)); match node { Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, _, _, body_id), .. @@ -3696,7 +3696,7 @@ fn parent_item_span(&self, id: hir::HirId) -> Option { /// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise. fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl, ast::Ident)> { - let parent = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(blk_id)); + let parent = self.tcx.hir().get(self.tcx.hir().get_parent_item(blk_id)); self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident)) } @@ -3731,7 +3731,7 @@ pub fn get_fn_decl(&self, blk_id: hir::HirId) -> Option<(&'tcx hir::FnDecl, bool // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. self.tcx.hir().get_return_block(blk_id).and_then(|blk_id| { - let parent = self.tcx.hir().get_by_hir_id(blk_id); + let parent = self.tcx.hir().get(blk_id); self.get_node_fn_decl(parent).map(|(fn_decl, _, is_main)| (fn_decl, is_main)) }) } @@ -4258,7 +4258,7 @@ fn check_rustc_args_require_const(&self, // 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_by_hir_id( + if let Node::Expr(expr) = self.tcx.hir().get( self.tcx.hir().get_parent_node_by_hir_id(hir_id)) { if let ExprKind::Call(ref callee, ..) = expr.node { @@ -4334,7 +4334,7 @@ fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool { let mut contained_in_place = false; while let hir::Node::Expr(parent_expr) = - self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_node_by_hir_id(expr_id)) + self.tcx.hir().get(self.tcx.hir().get_parent_node_by_hir_id(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 52cda4ac3c6..301168aefd2 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -284,7 +284,7 @@ fn type_param_predicates<'tcx>( let mut extend = None; let item_hir_id = tcx.hir().as_local_hir_id(item_def_id).unwrap(); - let ast_generics = match tcx.hir().get_by_hir_id(item_hir_id) { + let ast_generics = match tcx.hir().get(item_hir_id) { Node::TraitItem(item) => &item.generics, Node::ImplItem(item) => &item.generics, @@ -623,7 +623,7 @@ fn adt_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::AdtDef { use rustc::hir::*; let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = match tcx.hir().get_by_hir_id(hir_id) { + let item = match tcx.hir().get(hir_id) { Node::Item(item) => item, _ => bug!(), }; @@ -693,7 +693,7 @@ fn super_predicates_of<'tcx>( debug!("super_predicates(trait_def_id={:?})", trait_def_id); let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id).unwrap(); - let item = match tcx.hir().get_by_hir_id(trait_hir_id) { + let item = match tcx.hir().get(trait_hir_id) { Node::Item(item) => item, _ => bug!("trait_node_id {} is not an item", trait_hir_id), }; @@ -884,7 +884,7 @@ fn generics_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::Generics { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let node = tcx.hir().get_by_hir_id(hir_id); + let node = tcx.hir().get(hir_id); let parent_def_id = match node { Node::ImplItem(_) | Node::TraitItem(_) | Node::Variant(_) | Node::Ctor(..) | Node::Field(_) => { @@ -1154,7 +1154,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op let icx = ItemCtxt::new(tcx, def_id); - Some(match tcx.hir().get_by_hir_id(hir_id) { + Some(match tcx.hir().get(hir_id) { Node::TraitItem(item) => match item.node { TraitItemKind::Method(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); @@ -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_by_hir_id(tcx.hir().get_parent_node_by_hir_id(hir_id)); + let parent_node = tcx.hir().get(tcx.hir().get_parent_node_by_hir_id(hir_id)); match parent_node { Node::Ty(&hir::Ty { node: hir::TyKind::Array(_, ref constant), @@ -1660,8 +1660,8 @@ fn visit_trait_item(&mut self, it: &'tcx TraitItem) { if scope == hir::CRATE_HIR_ID { intravisit::walk_crate(&mut locator, tcx.hir().krate()); } else { - debug!("find_existential_constraints: scope={:?}", tcx.hir().get_by_hir_id(scope)); - match tcx.hir().get_by_hir_id(scope) { + debug!("find_existential_constraints: scope={:?}", tcx.hir().get(scope)); + match tcx.hir().get(scope) { Node::Item(ref it) => intravisit::walk_item(&mut locator, it), Node::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it), Node::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it), @@ -1690,7 +1690,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { let icx = ItemCtxt::new(tcx, def_id); - match tcx.hir().get_by_hir_id(hir_id) { + match tcx.hir().get(hir_id) { TraitItem(hir::TraitItem { node: TraitItemKind::Method(sig, _), .. @@ -1903,7 +1903,7 @@ fn extend, Span)>>(&mut self, iter: Some(hir_id) => hir_id, None => return tcx.predicates_of(def_id), }; - let node = tcx.hir().get_by_hir_id(hir_id); + let node = tcx.hir().get(hir_id); let mut is_trait = None; let mut is_default_impl_trait = None; diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 1c2bb8c2f0b..f2661b46b8b 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -61,7 +61,7 @@ fn visit_item(&mut self, item: &hir::Item) { .hir() .as_local_hir_id(item_did) .expect("expected local def-id"); - let item = match self.tcx.hir().get_by_hir_id(hir_id) { + let item = match self.tcx.hir().get(hir_id) { Node::Item(item) => item, _ => bug!(), }; diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs index ad538b0effe..63e41e01fbf 100644 --- a/src/librustc_typeck/outlives/mod.rs +++ b/src/librustc_typeck/outlives/mod.rs @@ -29,7 +29,7 @@ fn inferred_outlives_of<'tcx>( .as_local_hir_id(item_def_id) .expect("expected local def-id"); - match tcx.hir().get_by_hir_id(id) { + match tcx.hir().get(id) { Node::Item(item) => match item.node { hir::ItemKind::Struct(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Union(..) => { let crate_map = tcx.inferred_outlives_crate(LOCAL_CRATE); diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index 5dbd667485e..1a8871a3da9 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -48,7 +48,7 @@ fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> &'tcx [ty::Varia // Variance not relevant. span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") }; - match tcx.hir().get_by_hir_id(id) { + match tcx.hir().get(id) { Node::Item(item) => match item.node { hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index c94149d3102..781e62c3b27 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -337,7 +337,7 @@ fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool if !self.view_item_stack.insert(res_hir_id) { return false } - let ret = match tcx.hir().get_by_hir_id(res_hir_id) { + let ret = match tcx.hir().get(res_hir_id) { Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => { let prev = mem::replace(&mut self.inlining, true); for i in &m.item_ids { diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs index 76554eaba9c..64b795af926 100644 --- a/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs +++ b/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs @@ -43,7 +43,7 @@ fn check_fn(&mut self, span: source_map::Span, id: hir::HirId) { - let item = match cx.tcx.hir().get_by_hir_id(id) { + let item = match cx.tcx.hir().get(id) { Node::Item(item) => item, _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)), }; From cfd754d8929db49a699f8e18ab7ab1cb78354a49 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 25 May 2019 14:32:24 +0200 Subject: [PATCH 17/28] Fix theme-checker failure --- src/librustdoc/theme.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 7a0ccf6975f..b3196217adc 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -110,7 +110,7 @@ fn load_css_events(v: &[u8]) -> Vec { let mut pos = 0; let mut events = Vec::with_capacity(100); - while pos < v.len() - 1 { + while pos + 1 < v.len() { match v[pos] { b'/' if pos + 1 < v.len() && v[pos + 1] == b'*' => { events.push(Events::StartComment(pos)); From 165a95b37151105c0822bc84d0939439f7b96b06 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 May 2019 00:02:44 +0200 Subject: [PATCH 18/28] Add test for empty css file check --- src/librustdoc/theme.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index b3196217adc..48142de95a9 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -366,4 +366,10 @@ fn test_comparison() { get_differences(&other, &against, &mut ret); assert_eq!(ret, vec![" Missing \"c\" rule".to_owned()]); } + + #[test] + fn check_empty_css() { + let events = load_css_events(&[]); + assert_eq!(events.len(), 0); + } } From 640bdbdb1da73cde39c33fc2be3cddd3b71389b0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 May 2019 15:25:01 +0200 Subject: [PATCH 19/28] Improve theme checker by removing unneeded conditions --- src/librustdoc/theme.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 48142de95a9..7220a05df47 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -103,7 +103,7 @@ fn is_line_comment(pos: usize, v: &[u8], events: &[Events]) -> bool { if let Some(&Events::StartComment(_)) = events.last() { return false; } - pos + 1 < v.len() && v[pos + 1] == b'/' + v[pos + 1] == b'/' } fn load_css_events(v: &[u8]) -> Vec { @@ -112,7 +112,7 @@ fn load_css_events(v: &[u8]) -> Vec { while pos + 1 < v.len() { match v[pos] { - b'/' if pos + 1 < v.len() && v[pos + 1] == b'*' => { + b'/' if v[pos + 1] == b'*' => { events.push(Events::StartComment(pos)); pos += 1; } @@ -123,7 +123,7 @@ fn load_css_events(v: &[u8]) -> Vec { b'\n' if previous_is_line_comment(&events) => { events.push(Events::EndComment(pos)); } - b'*' if pos + 1 < v.len() && v[pos + 1] == b'/' => { + b'*' if v[pos + 1] == b'/' => { events.push(Events::EndComment(pos + 2)); pos += 1; } @@ -264,9 +264,11 @@ pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec) } } -pub fn test_theme_against>(f: &P, against: &CssPath, diag: &Handler) - -> (bool, Vec) -{ +pub fn test_theme_against>( + f: &P, + against: &CssPath, + diag: &Handler, +) -> (bool, Vec) { let data = try_something!(fs::read(f), diag, (false, vec![])); let paths = load_css_paths(&data); let mut ret = vec![]; @@ -372,4 +374,10 @@ fn check_empty_css() { let events = load_css_events(&[]); assert_eq!(events.len(), 0); } + + #[test] + fn check_invalid_css() { + let events = load_css_events(b"*"); + assert_eq!(events.len(), 0); + } } From b4c73a297c59dea86e7e529701d6e06d55e5e2e2 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 21 Jun 2019 15:18:00 +0900 Subject: [PATCH 20/28] Add test for issue-27697 --- src/test/ui/issues/issue-27697.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/ui/issues/issue-27697.rs diff --git a/src/test/ui/issues/issue-27697.rs b/src/test/ui/issues/issue-27697.rs new file mode 100644 index 00000000000..83070012f5f --- /dev/null +++ b/src/test/ui/issues/issue-27697.rs @@ -0,0 +1,21 @@ +// run-pass + +use std::ops::Deref; + +trait MyTrait { + fn do_something(&self); + fn as_str(&self) -> &str; +} + +impl Deref for dyn MyTrait { + type Target = str; + fn deref(&self) -> &Self::Target { + self.as_str() + } +} + +fn trait_object_does_something(t: &dyn MyTrait) { + t.do_something() +} + +fn main() {} From 0a511cce79c41eeddbdc0623581e61872f97793c Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 21 Jun 2019 08:57:34 +0200 Subject: [PATCH 21/28] revert the NodeId to HirId parameter change to get_path_res --- src/librustc_save_analysis/dump_visitor.rs | 12 +++++------- src/librustc_save_analysis/lib.rs | 11 +++++------ src/librustc_save_analysis/sig.rs | 6 ++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 4719965da8d..f67241ef23e 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -233,8 +233,7 @@ fn write_sub_paths_truncated(&mut self, path: &ast::Path) { } fn lookup_def_id(&self, ref_id: NodeId) -> Option { - let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ref_id); - match self.save_ctxt.get_path_res(hir_id) { + match self.save_ctxt.get_path_res(ref_id) { Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None, def => Some(def.def_id()), } @@ -887,8 +886,7 @@ fn process_pat(&mut self, p: &'l ast::Pat) { return; } }; - let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(p.id); - let variant = adt.variant_of_res(self.save_ctxt.get_path_res(hir_id)); + let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id)); for &Spanned { node: ref field, .. } in fields { if let Some(index) = self.tcx.find_field_index(field.ident, variant) { @@ -918,8 +916,7 @@ fn process_var_decl_multi(&mut self, pats: &'l [P]) { // process collected paths for (id, ident, immut) in collector.collected_idents { - let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(id); - match self.save_ctxt.get_path_res(hir_id) { + match self.save_ctxt.get_path_res(id) { Res::Local(hir_id) => { let mut value = if immut == ast::Mutability::Immutable { self.span.snippet(ident.span) @@ -1543,7 +1540,8 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) { return; } }; - let res = self.save_ctxt.get_path_res(hir_expr.hir_id); + let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id); + let res = self.save_ctxt.get_path_res(node_id); self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base) } ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args), diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 27e312f65ce..23fe150c6ff 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -606,7 +606,8 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { } } - pub fn get_path_res(&self, hir_id: hir::HirId) -> Res { + pub fn get_path_res(&self, id: NodeId) -> Res { + let hir_id = self.tcx.hir().node_to_hir_id(id); match self.tcx.hir().get(hir_id) { Node::TraitRef(tr) => tr.path.res, @@ -620,7 +621,7 @@ pub fn get_path_res(&self, hir_id: hir::HirId) -> Res { Node::PathSegment(seg) => { match seg.res { Some(res) if res != Res::Err => res, - _ => self.get_path_res(self.tcx.hir().get_parent_node_by_hir_id(hir_id)), + _ => self.get_path_res(self.tcx.hir().get_parent_node(id)), } } @@ -695,8 +696,7 @@ fn fn_type(seg: &ast::PathSegment) -> bool { return None; } - let hir_id = self.tcx.hir().node_to_hir_id(id); - let res = self.get_path_res(hir_id); + let res = self.get_path_res(id); let span = path_seg.ident.span; filter!(self.span_utils, span); let span = self.span_from_span(span); @@ -868,8 +868,7 @@ pub fn get_macro_use_data(&self, span: Span) -> Option { } fn lookup_ref_id(&self, ref_id: NodeId) -> Option { - let hir_id = self.tcx.hir().node_to_hir_id(ref_id); - match self.get_path_res(hir_id) { + match self.get_path_res(ref_id) { Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None, def => Some(def.def_id()), } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 7af18a8676a..db8b5eacd94 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -273,8 +273,7 @@ fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, }; let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?); - let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id)); - let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?); + let res = scx.get_path_res(id.ok_or("Missing id for Path")?); let id = id_from_def_id(res.def_id()); if path.segments.len() - qself.position == 1 { let start = offset + prefix.len(); @@ -577,8 +576,7 @@ fn make(&self, offset: usize, _parent_id: Option, scx: &SaveContext<'_, impl Sig for ast::Path { fn make(&self, offset: usize, id: Option, scx: &SaveContext<'_, '_>) -> Result { - let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id)); - let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?); + let res = scx.get_path_res(id.ok_or("Missing id for Path")?); let (name, start, end) = match res { Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => { From 0d67510a48e867935b4bb84fea9fc8123a194d69 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 28 May 2019 17:27:46 +0200 Subject: [PATCH 22/28] Remove warnings about incr. comp. generating less debugging output. --- src/librustc/session/config.rs | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index fc092481a4a..895f9c6d8fb 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -330,14 +330,6 @@ macro_rules! hash_option { bug!("Duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name)) } }); - ($opt_name:ident, - $opt_expr:expr, - $sub_hashes:expr, - [UNTRACKED_WITH_WARNING $warn_val:expr, $warn_text:expr, $error_format:expr]) => ({ - if *$opt_expr == $warn_val { - early_warn($error_format, $warn_text) - } - }); } macro_rules! top_level_options { @@ -383,10 +375,6 @@ pub fn dep_tracking_hash(&self) -> u64 { // [UNTRACKED] // Incremental compilation is not influenced by this option. // -// [UNTRACKED_WITH_WARNING(val, warning)] -// The option is incompatible with incremental compilation in some way. If it -// has the value `val`, the string `warning` is emitted as a warning. -// // If you add a new option to this struct or one of the sub-structs like // CodegenOptions, think about how it influences incremental compilation. If in // doubt, specify [TRACKED], which is always "correct" but might lead to @@ -1163,9 +1151,7 @@ fn parse_symbol_mangling_version( "a list of extra LLVM passes to run (space separated)"), llvm_args: Vec = (Vec::new(), parse_list, [TRACKED], "a list of arguments to pass to llvm (space separated)"), - save_temps: bool = (false, parse_bool, [UNTRACKED_WITH_WARNING(true, - "`-C save-temps` might not produce all requested temporary products \ - when incremental compilation is enabled.")], + save_temps: bool = (false, parse_bool, [UNTRACKED], "save all temporary output files during compilation"), rpath: bool = (false, parse_bool, [UNTRACKED], "set rpath values in libs/exes"), @@ -1241,9 +1227,7 @@ fn parse_symbol_mangling_version( "measure time of each rustc pass"), time: bool = (false, parse_bool, [UNTRACKED], "measure time of rustc processes"), - time_llvm_passes: bool = (false, parse_bool, [UNTRACKED_WITH_WARNING(true, - "The output of `-Z time-llvm-passes` will only reflect timings of \ - re-codegened modules when used with incremental compilation" )], + time_llvm_passes: bool = (false, parse_bool, [UNTRACKED], "measure time of each LLVM pass"), input_stats: bool = (false, parse_bool, [UNTRACKED], "gather statistics about the input"), From 004efa27059441651b240ee1a408d40f420413f8 Mon Sep 17 00:00:00 2001 From: Jeremy Stucki Date: Fri, 21 Jun 2019 11:39:28 +0200 Subject: [PATCH 23/28] Remove needless lifetimes --- src/librustc/ty/constness.rs | 8 ++++---- src/librustc/ty/context.rs | 6 +++--- src/librustc/ty/fast_reject.rs | 4 ++-- src/librustc/ty/mod.rs | 24 ++++++++++++------------ src/librustc/ty/trait_def.rs | 6 +++--- src/librustc/ty/walk.rs | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs index 65b83224ae5..9e8857741b2 100644 --- a/src/librustc/ty/constness.rs +++ b/src/librustc/ty/constness.rs @@ -67,9 +67,9 @@ pub fn is_min_const_fn(self, def_id: DefId) -> bool { } -pub fn provide<'tcx>(providers: &mut Providers<'tcx>) { +pub fn provide(providers: &mut Providers<'_>) { /// only checks whether the function has a `const` modifier - fn is_const_fn_raw<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { + fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let hir_id = tcx.hir().as_local_hir_id(def_id) .expect("Non-local call to local provider is_const_fn"); @@ -83,7 +83,7 @@ fn is_const_fn_raw<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { } } - fn is_promotable_const_fn<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { + fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool { tcx.is_const_fn(def_id) && match tcx.lookup_stability(def_id) { Some(stab) => { if cfg!(debug_assertions) && stab.promotable { @@ -101,7 +101,7 @@ fn is_promotable_const_fn<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { } } - fn const_fn_is_allowed_fn_ptr<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { + fn const_fn_is_allowed_fn_ptr(tcx: TyCtxt<'_>, def_id: DefId) -> bool { tcx.is_const_fn(def_id) && tcx.lookup_stability(def_id) .map(|stab| stab.allow_const_fn_ptr).unwrap_or(false) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index b84ebd8afe8..1ae1f344021 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2223,7 +2223,7 @@ fn borrow<'a>(&'a self) -> &'a [Ty<'tcx>] { } impl<'tcx> Borrow<[CanonicalVarInfo]> for Interned<'tcx, List> { - fn borrow<'a>(&'a self) -> &'a [CanonicalVarInfo] { + fn borrow(&self) -> &[CanonicalVarInfo] { &self.0[..] } } @@ -2236,13 +2236,13 @@ fn borrow<'a>(&'a self) -> &'a [Kind<'tcx>] { impl<'tcx> Borrow<[ProjectionKind]> for Interned<'tcx, List> { - fn borrow<'a>(&'a self) -> &'a [ProjectionKind] { + fn borrow(&self) -> &[ProjectionKind] { &self.0[..] } } impl<'tcx> Borrow for Interned<'tcx, RegionKind> { - fn borrow<'a>(&'a self) -> &'a RegionKind { + fn borrow(&self) -> &RegionKind { &self.0 } } diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index 7aab1aef3b8..ee0d33dbe34 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -55,8 +55,8 @@ pub enum SimplifiedTypeGen /// then we can't say much about whether two types would unify. Put another way, /// `can_simplify_params` should be true if type parameters appear free in `ty` and `false` if they /// are to be considered bound. -pub fn simplify_type<'tcx>( - tcx: TyCtxt<'tcx>, +pub fn simplify_type( + tcx: TyCtxt<'_>, ty: Ty<'_>, can_simplify_params: bool, ) -> Option { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 361410380e8..22c2fd63b19 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -213,7 +213,7 @@ pub fn relevant_for_never(&self) -> bool { } } - pub fn signature<'tcx>(&self, tcx: TyCtxt<'tcx>) -> String { + pub fn signature(&self, tcx: TyCtxt<'_>) -> String { match self.kind { ty::AssocKind::Method => { // We skip the binder here because the binder would deanonymize all @@ -2311,7 +2311,7 @@ pub fn predicates(&self, tcx: TyCtxt<'tcx>) -> &'tcx GenericPredicates<'tcx> { /// Returns an iterator over all fields contained /// by this ADT. #[inline] - pub fn all_fields<'s>(&'s self) -> impl Iterator + Clone { + pub fn all_fields(&self) -> impl Iterator + Clone { self.variants.iter().flat_map(|v| v.fields.iter()) } @@ -3125,7 +3125,7 @@ fn next(&mut self) -> Option { } } -fn associated_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AssocItem { +fn associated_item(tcx: TyCtxt<'_>, def_id: DefId) -> AssocItem { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let parent_id = tcx.hir().get_parent_item(id); let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id); @@ -3170,7 +3170,7 @@ fn associated_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AssocItem { /// such. /// - a Error, if a type contained itself. The representability /// check should catch this case. -fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AdtSizedConstraint<'tcx> { +fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> AdtSizedConstraint<'_> { let def = tcx.adt_def(def_id); let result = tcx.mk_type_list(def.variants.iter().flat_map(|v| { @@ -3184,7 +3184,7 @@ fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AdtSizedConst AdtSizedConstraint(result) } -fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [DefId] { +fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let item = tcx.hir().expect_item(id); match item.node { @@ -3207,14 +3207,14 @@ fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [Def } } -fn def_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span { +fn def_span(tcx: TyCtxt<'_>, def_id: DefId) -> Span { tcx.hir().span_if_local(def_id).unwrap() } /// If the given `DefId` describes an item belonging to a trait, /// returns the `DefId` of the trait that the trait item belongs to; /// otherwise, returns `None`. -fn trait_of_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option { +fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option { tcx.opt_associated_item(def_id) .and_then(|associated_item| { match associated_item.container { @@ -3237,7 +3237,7 @@ pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option { } /// See `ParamEnv` struct definition for details. -fn param_env<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ParamEnv<'tcx> { +fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ParamEnv<'_> { // The param_env of an impl Trait type is its defining function's param_env if let Some(parent) = is_impl_trait_defn(tcx, def_id) { return param_env(tcx, parent); @@ -3272,17 +3272,17 @@ fn param_env<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ParamEnv<'tcx> { traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) } -fn crate_disambiguator<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> CrateDisambiguator { +fn crate_disambiguator(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateDisambiguator { assert_eq!(crate_num, LOCAL_CRATE); tcx.sess.local_crate_disambiguator() } -fn original_crate_name<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> Symbol { +fn original_crate_name(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Symbol { assert_eq!(crate_num, LOCAL_CRATE); tcx.crate_name.clone() } -fn crate_hash<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> Svh { +fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { assert_eq!(crate_num, LOCAL_CRATE); tcx.hir().crate_hash } @@ -3302,7 +3302,7 @@ fn instance_def_size_estimate<'tcx>(tcx: TyCtxt<'tcx>, instance_def: InstanceDef /// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`. /// /// See [`ImplOverlapKind::Issue33140`] for more details. -fn issue33140_self_ty<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option> { +fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { debug!("issue33140_self_ty({:?})", def_id); let trait_ref = tcx.impl_trait_ref(def_id).unwrap_or_else(|| { diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index c40d4d5b9cc..a7ade875bf1 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -150,10 +150,10 @@ pub fn all_impls(self, def_id: DefId) -> Vec { } // Query provider for `trait_impls_of`. -pub(super) fn trait_impls_of_provider<'tcx>( - tcx: TyCtxt<'tcx>, +pub(super) fn trait_impls_of_provider( + tcx: TyCtxt<'_>, trait_id: DefId, -) -> &'tcx TraitImpls { +) -> &TraitImpls { let mut impls = TraitImpls::default(); { diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs index 234407a7c4e..c74511cf0fd 100644 --- a/src/librustc/ty/walk.rs +++ b/src/librustc/ty/walk.rs @@ -56,7 +56,7 @@ fn next(&mut self) -> Option> { } } -pub fn walk_shallow<'tcx>(ty: Ty<'tcx>) -> smallvec::IntoIter> { +pub fn walk_shallow(ty: Ty<'_>) -> smallvec::IntoIter> { let mut stack = SmallVec::new(); push_subtypes(&mut stack, ty); stack.into_iter() From 6392bc9fcdf3b3984f92e7930329f940a53cf335 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 20 May 2019 14:04:04 +1200 Subject: [PATCH 24/28] Add DocFS layer to rustdoc * Move fs::create_dir_all calls into DocFS to provide a clean extension point if async extension there is needed. * Convert callsites of create_dir_all to ensure_dir to reduce syscalls. * Convert fs::write usage to DocFS.write (which also removes a lot of try_err! usage for easier reading) * Convert File::create calls to use Vec buffers and then DocFS.write in order to consistently reduce syscalls as well, make deferring to threads cleaner and avoid leaving dangling content if writing to existing files.... * Convert OpenOptions usage similarly - I could find no discussion on the use of create_new for that one output file vs all the other files render creates, if link redirection attacks are a concern DocFS will provide a good central point to introduce systematic create_new usage. (fs::write/File::create is vulnerable to link redirection attacks). * DocFS::write defers to rayon for IO on Windows producing a modest speedup: before this patch on my development workstation: $ time cargo +mystg1 doc -p winapi:0.3.7 Documenting winapi v0.3.7 Finished dev [unoptimized + debuginfo] target(s) in 6m 11s real 6m11.734s Afterwards: $ time cargo +mystg1 doc -p winapi:0.3.7 Compiling winapi v0.3.7 Documenting winapi v0.3.7 Finished dev [unoptimized + debuginfo] target(s) in 49.53s real 0m49.643s I haven't measured how much time is in the compilation logic vs in the IO and outputting etc, but this takes it from frustating to tolerable for me, at least for now. --- src/librustdoc/Cargo.toml | 1 + src/librustdoc/docfs.rs | 77 +++++++++ src/librustdoc/html/render.rs | 288 ++++++++++++++++++---------------- src/librustdoc/lib.rs | 1 + 4 files changed, 231 insertions(+), 136 deletions(-) create mode 100644 src/librustdoc/docfs.rs diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index b75212d606f..3158ec3832a 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -11,5 +11,6 @@ path = "lib.rs" [dependencies] pulldown-cmark = { version = "0.5.2", default-features = false } minifier = "0.0.30" +rayon = { version = "0.2.0", package = "rustc-rayon" } tempfile = "3" parking_lot = "0.7" diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs new file mode 100644 index 00000000000..eddd426a920 --- /dev/null +++ b/src/librustdoc/docfs.rs @@ -0,0 +1,77 @@ +//! Rustdoc's FileSystem abstraction module. +//! +//! On Windows this indirects IO into threads to work around performance issues +//! with Defender (and other similar virus scanners that do blocking operations). +//! On other platforms this is a thin shim to fs. +//! +//! Only calls needed to permit this workaround have been abstracted: thus +//! fs::read is still done directly via the fs module; if in future rustdoc +//! needs to read-after-write from a file, then it would be added to this +//! abstraction. + +use std::fs; +use std::io; +use std::path::Path; + +macro_rules! try_err { + ($e:expr, $file:expr) => {{ + match $e { + Ok(e) => e, + Err(e) => return Err(E::new(e, $file)), + } + }}; +} + +pub trait PathError { + fn new>(e: io::Error, path: P) -> Self; +} + +pub struct DocFS { + sync_only: bool, +} + +impl DocFS { + pub fn new() -> DocFS { + DocFS { + sync_only: false, + } + } + + pub fn set_sync_only(&mut self, sync_only: bool) { + self.sync_only = sync_only; + } + + pub fn create_dir_all>(&self, path: P) -> io::Result<()> { + // For now, dir creation isn't a huge time consideration, do it + // synchronously, which avoids needing ordering between write() actions + // and directory creation. + fs::create_dir_all(path) + } + + pub fn write(&self, path: P, contents: C) -> Result<(), E> + where + P: AsRef, + C: AsRef<[u8]>, + E: PathError, + { + if !self.sync_only && cfg!(windows) { + // A possible future enhancement after more detailed profiling would + // be to create the file sync so errors are reported eagerly. + let contents = contents.as_ref().to_vec(); + let path = path.as_ref().to_path_buf(); + rayon::spawn(move || + match fs::write(&path, &contents) { + Ok(_) => (), + Err(e) => { + // In principle these should get displayed at the top + // level, but just in case, send to stderr as well. + eprintln!("\"{}\": {}", path.display(), e); + panic!("\"{}\": {}", path.display(), e); + } + }); + Ok(()) + } else { + Ok(try_err!(fs::write(&path, contents), path)) + } + } +} diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b42a78f1e22..8b514cb09ae 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -35,9 +35,9 @@ use std::error; use std::fmt::{self, Display, Formatter, Write as FmtWrite}; use std::ffi::OsStr; -use std::fs::{self, File, OpenOptions}; +use std::fs::{self, File}; use std::io::prelude::*; -use std::io::{self, BufWriter, BufReader}; +use std::io::{self, BufReader}; use std::mem; use std::path::{PathBuf, Path, Component}; use std::str; @@ -61,6 +61,7 @@ use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, Mutability}; use crate::config::RenderOptions; +use crate::docfs::{DocFS, PathError}; use crate::doctree; use crate::fold::DocFolder; use crate::html::escape::Escape; @@ -89,6 +90,53 @@ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { } } +#[derive(Debug)] +pub struct Error { + pub file: PathBuf, + pub error: io::Error, +} + +impl error::Error for Error { + fn description(&self) -> &str { + self.error.description() + } +} + +impl Display for Error { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "\"{}\": {}", self.file.display(), self.error) + } +} + +impl PathError for Error { + fn new>(e: io::Error, path: P) -> Error { + Error { + file: path.as_ref().to_path_buf(), + error: e, + } + } +} + +macro_rules! try_none { + ($e:expr, $file:expr) => ({ + use std::io; + match $e { + Some(e) => e, + None => return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), + $file)) + } + }) +} + +macro_rules! try_err { + ($e:expr, $file:expr) => ({ + match $e { + Ok(e) => e, + Err(e) => return Err(Error::new(e, $file)), + } + }) +} + /// Major driving force in all rustdoc rendering. This contains information /// about where in the tree-like hierarchy rendering is occurring and controls /// how the current page is being rendered. @@ -156,13 +204,15 @@ struct SharedContext { pub generate_search_filter: bool, /// Option disabled by default to generate files used by RLS and some other tools. pub generate_redirect_pages: bool, + /// The fs handle we are working with. + pub fs: DocFS, } impl SharedContext { - fn ensure_dir(&self, dst: &Path) -> io::Result<()> { + fn ensure_dir(&self, dst: &Path) -> Result<(), Error> { let mut dirs = self.created_dirs.borrow_mut(); if !dirs.contains(dst) { - fs::create_dir_all(dst)?; + try_err!(self.fs.create_dir_all(dst), dst); dirs.insert(dst.to_path_buf()); } @@ -216,53 +266,6 @@ fn trait_did(&self) -> Option { } } -#[derive(Debug)] -pub struct Error { - pub file: PathBuf, - pub error: io::Error, -} - -impl error::Error for Error { - fn description(&self) -> &str { - self.error.description() - } -} - -impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "\"{}\": {}", self.file.display(), self.error) - } -} - -impl Error { - pub fn new(e: io::Error, file: &Path) -> Error { - Error { - file: file.to_path_buf(), - error: e, - } - } -} - -macro_rules! try_none { - ($e:expr, $file:expr) => ({ - use std::io; - match $e { - Some(e) => e, - None => return Err(Error::new(io::Error::new(io::ErrorKind::Other, "not found"), - $file)) - } - }) -} - -macro_rules! try_err { - ($e:expr, $file:expr) => ({ - match $e { - Ok(e) => e, - Err(e) => return Err(Error::new(e, $file)), - } - }) -} - /// This cache is used to store information about the `clean::Crate` being /// rendered in order to provide more useful documentation. This contains /// information like all implementors of a trait, all traits a type implements, @@ -564,6 +567,7 @@ pub fn run(mut krate: clean::Crate, static_root_path, generate_search_filter, generate_redirect_pages, + fs: DocFS::new(), }; // If user passed in `--playground-url` arg, we fill in crate name here @@ -601,9 +605,9 @@ pub fn run(mut krate: clean::Crate, } } let dst = output; - try_err!(fs::create_dir_all(&dst), &dst); + scx.ensure_dir(&dst)?; krate = render_sources(&dst, &mut scx, krate)?; - let cx = Context { + let mut cx = Context { current: Vec::new(), dst, render_redirect_pages: false, @@ -705,7 +709,10 @@ pub fn run(mut krate: clean::Crate, CACHE_KEY.with(|v| *v.borrow_mut() = cache.clone()); CURRENT_LOCATION_KEY.with(|s| s.borrow_mut().clear()); + // Write shared runs within a flock; disable thread dispatching of IO temporarily. + Arc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(true); write_shared(&cx, &krate, &*cache, index, &md_opts, diag)?; + Arc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false); // And finally render the whole crate's documentation cx.krate(krate) @@ -797,13 +804,13 @@ fn write_shared( // Add all the static files. These may already exist, but we just // overwrite them anyway to make sure that they're fresh and up-to-date. - write_minify(cx.dst.join(&format!("rustdoc{}.css", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("rustdoc{}.css", cx.shared.resource_suffix)), static_files::RUSTDOC_CSS, options.enable_minification)?; - write_minify(cx.dst.join(&format!("settings{}.css", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("settings{}.css", cx.shared.resource_suffix)), static_files::SETTINGS_CSS, options.enable_minification)?; - write_minify(cx.dst.join(&format!("noscript{}.css", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("noscript{}.css", cx.shared.resource_suffix)), static_files::NOSCRIPT_CSS, options.enable_minification)?; @@ -815,11 +822,13 @@ fn write_shared( let content = try_err!(fs::read(&entry), &entry); let theme = try_none!(try_none!(entry.file_stem(), &entry).to_str(), &entry); let extension = try_none!(try_none!(entry.extension(), &entry).to_str(), &entry); - write(cx.dst.join(format!("{}{}.{}", theme, cx.shared.resource_suffix, extension)), - content.as_slice())?; + cx.shared.fs.write( + cx.dst.join(format!("{}{}.{}", theme, cx.shared.resource_suffix, extension)), + content.as_slice())?; themes.insert(theme.to_owned()); } + let write = |p, c| { cx.shared.fs.write(p, c) }; if (*cx.shared).layout.logo.is_empty() { write(cx.dst.join(&format!("rust-logo{}.png", cx.shared.resource_suffix)), static_files::RUST_LOGO)?; @@ -834,11 +843,11 @@ fn write_shared( static_files::WHEEL_SVG)?; write(cx.dst.join(&format!("down-arrow{}.svg", cx.shared.resource_suffix)), static_files::DOWN_ARROW_SVG)?; - write_minify(cx.dst.join(&format!("light{}.css", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("light{}.css", cx.shared.resource_suffix)), static_files::themes::LIGHT, options.enable_minification)?; themes.insert("light".to_owned()); - write_minify(cx.dst.join(&format!("dark{}.css", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("dark{}.css", cx.shared.resource_suffix)), static_files::themes::DARK, options.enable_minification)?; themes.insert("dark".to_owned()); @@ -847,8 +856,7 @@ fn write_shared( themes.sort(); // To avoid theme switch latencies as much as possible, we put everything theme related // at the beginning of the html files into another js file. - write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)), - format!( + let theme_js = format!( r#"var themes = document.getElementById("theme-choices"); var themePicker = document.getElementById("theme-picker"); @@ -891,39 +899,45 @@ fn write_shared( themes.iter() .map(|s| format!("\"{}\"", s)) .collect::>() - .join(",")).as_bytes(), + .join(",")); + write(cx.dst.join(&format!("theme{}.js", cx.shared.resource_suffix)), + theme_js.as_bytes() )?; - write_minify(cx.dst.join(&format!("main{}.js", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("main{}.js", cx.shared.resource_suffix)), static_files::MAIN_JS, options.enable_minification)?; - write_minify(cx.dst.join(&format!("settings{}.js", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("settings{}.js", cx.shared.resource_suffix)), static_files::SETTINGS_JS, options.enable_minification)?; if cx.shared.include_sources { - write_minify(cx.dst.join(&format!("source-script{}.js", cx.shared.resource_suffix)), - static_files::sidebar::SOURCE_SCRIPT, - options.enable_minification)?; + write_minify( + &cx.shared.fs, + cx.dst.join(&format!("source-script{}.js", cx.shared.resource_suffix)), + static_files::sidebar::SOURCE_SCRIPT, + options.enable_minification)?; } { - write_minify(cx.dst.join(&format!("storage{}.js", cx.shared.resource_suffix)), - &format!("var resourcesSuffix = \"{}\";{}", - cx.shared.resource_suffix, - static_files::STORAGE_JS), - options.enable_minification)?; + write_minify( + &cx.shared.fs, + cx.dst.join(&format!("storage{}.js", cx.shared.resource_suffix)), + &format!("var resourcesSuffix = \"{}\";{}", + cx.shared.resource_suffix, + static_files::STORAGE_JS), + options.enable_minification)?; } if let Some(ref css) = cx.shared.css_file_extension { let out = cx.dst.join(&format!("theme{}.css", cx.shared.resource_suffix)); + let buffer = try_err!(fs::read_to_string(css), css); if !options.enable_minification { - try_err!(fs::copy(css, out), css); + cx.shared.fs.write(&out, &buffer)?; } else { - let buffer = try_err!(fs::read_to_string(css), css); - write_minify(out, &buffer, options.enable_minification)?; + write_minify(&cx.shared.fs, out, &buffer, options.enable_minification)?; } } - write_minify(cx.dst.join(&format!("normalize{}.css", cx.shared.resource_suffix)), + write_minify(&cx.shared.fs, cx.dst.join(&format!("normalize{}.css", cx.shared.resource_suffix)), static_files::NORMALIZE_CSS, options.enable_minification)?; write(cx.dst.join("FiraSans-Regular.woff"), @@ -999,7 +1013,6 @@ fn show_item(item: &IndexItem, krate: &str) -> String { let dst = cx.dst.join(&format!("aliases{}.js", cx.shared.resource_suffix)); { let (mut all_aliases, _, _) = try_err!(collect(&dst, &krate.name, "ALIASES", false), &dst); - let mut w = try_err!(File::create(&dst), &dst); let mut output = String::with_capacity(100); for (alias, items) in &cache.aliases { if items.is_empty() { @@ -1014,10 +1027,12 @@ fn show_item(item: &IndexItem, krate: &str) -> String { } all_aliases.push(format!("ALIASES[\"{}\"] = {{{}}};", krate.name, output)); all_aliases.sort(); - try_err!(writeln!(&mut w, "var ALIASES = {{}};"), &dst); + let mut v = Vec::new(); + try_err!(writeln!(&mut v, "var ALIASES = {{}};"), &dst); for aliases in &all_aliases { - try_err!(writeln!(&mut w, "{}", aliases), &dst); + try_err!(writeln!(&mut v, "{}", aliases), &dst); } + cx.shared.fs.write(&dst, &v)?; } use std::ffi::OsString; @@ -1101,11 +1116,12 @@ fn to_json_string(&self) -> String { &krate.name, hierarchy.to_json_string())); all_sources.sort(); - let mut w = try_err!(File::create(&dst), &dst); - try_err!(writeln!(&mut w, + let mut v = Vec::new(); + try_err!(writeln!(&mut v, "var N = null;var sourcesIndex = {{}};\n{}\ncreateSourceSidebar();", all_sources.join("\n")), &dst); + cx.shared.fs.write(&dst, &v)?; } // Update the search index @@ -1119,14 +1135,17 @@ fn to_json_string(&self) -> String { // Sort the indexes by crate so the file will be generated identically even // with rustdoc running in parallel. all_indexes.sort(); - let mut w = try_err!(File::create(&dst), &dst); - try_err!(writeln!(&mut w, "var N=null,E=\"\",T=\"t\",U=\"u\",searchIndex={{}};"), &dst); - try_err!(write_minify_replacer(&mut w, - &format!("{}\n{}", variables.join(""), all_indexes.join("\n")), - options.enable_minification), - &dst); - try_err!(write!(&mut w, "initSearch(searchIndex);addSearchOptions(searchIndex);"), &dst); - + { + let mut v = Vec::new(); + try_err!(writeln!(&mut v, "var N=null,E=\"\",T=\"t\",U=\"u\",searchIndex={{}};"), &dst); + try_err!(write_minify_replacer( + &mut v, + &format!("{}\n{}", variables.join(""), all_indexes.join("\n")), + options.enable_minification), + &dst); + try_err!(write!(&mut v, "initSearch(searchIndex);addSearchOptions(searchIndex);"), &dst); + cx.shared.fs.write(&dst, &v)?; + } if options.enable_index_page { if let Some(index_page) = options.index_page.clone() { let mut md_opts = options.clone(); @@ -1136,7 +1155,6 @@ fn to_json_string(&self) -> String { crate::markdown::render(index_page, md_opts, diag, cx.edition); } else { let dst = cx.dst.join("index.html"); - let mut w = BufWriter::new(try_err!(File::create(&dst), &dst)); let page = layout::Page { title: "Index of crates", css_class: "mod", @@ -1163,12 +1181,13 @@ fn to_json_string(&self) -> String { SlashChecker(s), s) }) .collect::()); - try_err!(layout::render(&mut w, &cx.shared.layout, + let mut v = Vec::new(); + try_err!(layout::render(&mut v, &cx.shared.layout, &page, &(""), &content, cx.shared.css_file_extension.is_some(), &cx.shared.themes, cx.shared.generate_search_filter), &dst); - try_err!(w.flush(), &dst); + cx.shared.fs.write(&dst, &v)?; } } @@ -1220,7 +1239,7 @@ fn to_json_string(&self) -> String { for part in &remote_path[..remote_path.len() - 1] { mydst.push(part); } - try_err!(fs::create_dir_all(&mydst), &mydst); + cx.shared.ensure_dir(&mydst)?; mydst.push(&format!("{}.{}.js", remote_item_type.css_class(), remote_path[remote_path.len() - 1])); @@ -1233,19 +1252,20 @@ fn to_json_string(&self) -> String { // identically even with rustdoc running in parallel. all_implementors.sort(); - let mut f = try_err!(File::create(&mydst), &mydst); - try_err!(writeln!(&mut f, "(function() {{var implementors = {{}};"), &mydst); + let mut v = Vec::new(); + try_err!(writeln!(&mut v, "(function() {{var implementors = {{}};"), &mydst); for implementor in &all_implementors { - try_err!(writeln!(&mut f, "{}", *implementor), &mydst); + try_err!(writeln!(&mut v, "{}", *implementor), &mydst); } - try_err!(writeln!(&mut f, "{}", r" + try_err!(writeln!(&mut v, "{}", r" if (window.register_implementors) { window.register_implementors(implementors); } else { window.pending_implementors = implementors; } "), &mydst); - try_err!(writeln!(&mut f, r"}})()"), &mydst); + try_err!(writeln!(&mut v, r"}})()"), &mydst); + cx.shared.fs.write(&mydst, &v)?; } Ok(()) } @@ -1254,7 +1274,7 @@ fn render_sources(dst: &Path, scx: &mut SharedContext, krate: clean::Crate) -> Result { info!("emitting source files"); let dst = dst.join("src").join(&krate.name); - try_err!(fs::create_dir_all(&dst), &dst); + scx.ensure_dir(&dst)?; let mut folder = SourceCollector { dst, scx, @@ -1262,22 +1282,17 @@ fn render_sources(dst: &Path, scx: &mut SharedContext, Ok(folder.fold_crate(krate)) } -/// Writes the entire contents of a string to a destination, not attempting to -/// catch any errors. -fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> { - Ok(try_err!(fs::write(&dst, contents), &dst)) -} - -fn write_minify(dst: PathBuf, contents: &str, enable_minification: bool) -> Result<(), Error> { +fn write_minify(fs:&DocFS, dst: PathBuf, contents: &str, enable_minification: bool + ) -> Result<(), Error> { if enable_minification { if dst.extension() == Some(&OsStr::new("css")) { let res = try_none!(minifier::css::minify(contents).ok(), &dst); - write(dst, res.as_bytes()) + fs.write(dst, res.as_bytes()) } else { - write(dst, minifier::js::minify(contents).as_bytes()) + fs.write(dst, minifier::js::minify(contents).as_bytes()) } } else { - write(dst, contents.as_bytes()) + fs.write(dst, contents.as_bytes()) } } @@ -1439,7 +1454,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option { impl<'a> SourceCollector<'a> { /// Renders the given filename into its corresponding HTML source file. - fn emit_source(&mut self, filename: &FileName) -> io::Result<()> { + fn emit_source(&mut self, filename: &FileName) -> Result<(), Error> { let p = match *filename { FileName::Real(ref file) => file, _ => return Ok(()), @@ -1449,7 +1464,7 @@ fn emit_source(&mut self, filename: &FileName) -> io::Result<()> { return Ok(()); } - let contents = fs::read_to_string(&p)?; + let contents = try_err!(fs::read_to_string(&p), &p); // Remove the utf-8 BOM if any let contents = if contents.starts_with("\u{feff}") { @@ -1468,7 +1483,7 @@ fn emit_source(&mut self, filename: &FileName) -> io::Result<()> { href.push_str(&component.to_string_lossy()); href.push('/'); }); - fs::create_dir_all(&cur)?; + self.scx.ensure_dir(&cur)?; let mut fname = p.file_name() .expect("source has no filename") .to_os_string(); @@ -1476,7 +1491,7 @@ fn emit_source(&mut self, filename: &FileName) -> io::Result<()> { cur.push(&fname); href.push_str(&fname.to_string_lossy()); - let mut w = BufWriter::new(File::create(&cur)?); + let mut v = Vec::new(); let title = format!("{} -- source", cur.file_name().expect("failed to get file name") .to_string_lossy()); let desc = format!("Source to the Rust file `{}`.", filename); @@ -1491,12 +1506,12 @@ fn emit_source(&mut self, filename: &FileName) -> io::Result<()> { extra_scripts: &[&format!("source-files{}", self.scx.resource_suffix)], static_extra_scripts: &[&format!("source-script{}", self.scx.resource_suffix)], }; - layout::render(&mut w, &self.scx.layout, + try_err!(layout::render(&mut v, &self.scx.layout, &page, &(""), &Source(contents), self.scx.css_file_extension.is_some(), &self.scx.themes, - self.scx.generate_search_filter)?; - w.flush()?; + self.scx.generate_search_filter), &cur); + self.scx.fs.write(&cur, &v)?; self.scx.local_sources.insert(p.clone(), href); Ok(()) } @@ -2073,7 +2088,6 @@ fn krate(self, mut krate: clean::Crate) -> Result<(), Error> { } } - let mut w = BufWriter::new(try_err!(File::create(&final_file), &final_file)); let mut root_path = self.dst.to_str().expect("invalid path").to_owned(); if !root_path.ends_with('/') { root_path.push('/'); @@ -2099,12 +2113,14 @@ fn krate(self, mut krate: clean::Crate) -> Result<(), Error> { } else { String::new() }; - try_err!(layout::render(&mut w, &self.shared.layout, + let mut v = Vec::new(); + try_err!(layout::render(&mut v, &self.shared.layout, &page, &sidebar, &all, self.shared.css_file_extension.is_some(), &self.shared.themes, self.shared.generate_search_filter), &final_file); + self.shared.fs.write(&final_file, &v)?; // Generating settings page. let settings = Settings::new(self.shared.static_root_path.deref().unwrap_or("./"), @@ -2113,17 +2129,18 @@ fn krate(self, mut krate: clean::Crate) -> Result<(), Error> { page.description = "Settings of Rustdoc"; page.root_path = "./"; - let mut w = BufWriter::new(try_err!(File::create(&settings_file), &settings_file)); let mut themes = self.shared.themes.clone(); let sidebar = "

Settings

"; themes.push(PathBuf::from("settings.css")); let layout = self.shared.layout.clone(); - try_err!(layout::render(&mut w, &layout, + let mut v = Vec::new(); + try_err!(layout::render(&mut v, &layout, &page, &sidebar, &settings, self.shared.css_file_extension.is_some(), &themes, self.shared.generate_search_filter), &settings_file); + self.shared.fs.write(&settings_file, &v)?; Ok(()) } @@ -2223,6 +2240,7 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result // recurse into the items of the module as well. let name = item.name.as_ref().unwrap().to_string(); let mut item = Some(item); + let scx = self.shared.clone(); self.recurse(name, |this| { let item = item.take().unwrap(); @@ -2230,9 +2248,9 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result this.render_item(&mut buf, &item, false).unwrap(); // buf will be empty if the module is stripped and there is no redirect for it if !buf.is_empty() { - try_err!(this.shared.ensure_dir(&this.dst), &this.dst); + this.shared.ensure_dir(&this.dst)?; let joint_dst = this.dst.join("index.html"); - try_err!(fs::write(&joint_dst, buf), &joint_dst); + scx.fs.write(&joint_dst, buf)?; } let m = match item.inner { @@ -2245,9 +2263,10 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result if !this.render_redirect_pages { let items = this.build_sidebar_items(&m); let js_dst = this.dst.join("sidebar-items.js"); - let mut js_out = BufWriter::new(try_err!(File::create(&js_dst), &js_dst)); - try_err!(write!(&mut js_out, "initSidebarItems({});", + let mut v = Vec::new(); + try_err!(write!(&mut v, "initSidebarItems({});", as_json(&items)), &js_dst); + scx.fs.write(&js_dst, &v)?; } for item in m.items { @@ -2264,9 +2283,9 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result let name = item.name.as_ref().unwrap(); let item_type = item.type_(); let file_name = &item_path(item_type, name); - try_err!(self.shared.ensure_dir(&self.dst), &self.dst); + self.shared.ensure_dir(&self.dst)?; let joint_dst = self.dst.join(file_name); - try_err!(fs::write(&joint_dst, buf), &joint_dst); + self.shared.fs.write(&joint_dst, buf)?; if !self.render_redirect_pages { all.append(full_path(self, &item), &item_type); @@ -2276,21 +2295,18 @@ fn item(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result // URL for the page. let redir_name = format!("{}.{}.html", name, item_type.name_space()); let redir_dst = self.dst.join(redir_name); - if let Ok(redirect_out) = OpenOptions::new().create_new(true) - .write(true) - .open(&redir_dst) { - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); - } + let mut v = Vec::new(); + try_err!(layout::redirect(&mut v, file_name), &redir_dst); + self.shared.fs.write(&redir_dst, &v)?; } // If the item is a macro, redirect from the old macro URL (with !) // to the new one (without). if item_type == ItemType::Macro { let redir_name = format!("{}.{}!.html", item_type, name); let redir_dst = self.dst.join(redir_name); - let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + let mut v = Vec::new(); + try_err!(layout::redirect(&mut v, file_name), &redir_dst); + self.shared.fs.write(&redir_dst, &v)?; } } } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 3b4d65352a3..7a8b088020c 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -59,6 +59,7 @@ mod clean; mod config; mod core; +mod docfs; mod doctree; mod fold; pub mod html { From 3eeb543504602d04c2f4374834ee9c67bb525300 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 26 May 2019 14:54:50 +0200 Subject: [PATCH 25/28] Handle fs errors through errors::Handler instead of eprintln and panic --- Cargo.lock | 1 + src/librustdoc/docfs.rs | 57 +++++++++++++++++++++++++++++------ src/librustdoc/html/render.rs | 22 +++++++++++--- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf448937e03..40b8cf507e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3254,6 +3254,7 @@ dependencies = [ "minifier 0.0.30 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index eddd426a920..96399b8e36f 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -9,9 +9,14 @@ //! needs to read-after-write from a file, then it would be added to this //! abstraction. +use errors; + +use std::cell::RefCell; use std::fs; use std::io; use std::path::Path; +use std::sync::Arc; +use std::sync::mpsc::{channel, Receiver, Sender}; macro_rules! try_err { ($e:expr, $file:expr) => {{ @@ -26,14 +31,45 @@ pub trait PathError { fn new>(e: io::Error, path: P) -> Self; } +pub struct ErrorStorage { + sender: Sender>, + receiver: Receiver>, +} + +impl ErrorStorage { + pub fn new() -> ErrorStorage { + let (sender, receiver) = channel(); + ErrorStorage { + sender, + receiver, + } + } + + /// Prints all stored errors. Returns the number of printed errors. + pub fn write_errors(&self, diag: &errors::Handler) -> usize { + let mut printed = 0; + drop(self.sender); + + for msg in self.receiver.iter() { + if let Some(ref error) = msg { + diag.struct_err(&error).emit(); + printed += 1; + } + } + printed + } +} + pub struct DocFS { sync_only: bool, + errors: Arc, } impl DocFS { - pub fn new() -> DocFS { + pub fn new(errors: &Arc) -> DocFS { DocFS { sync_only: false, + errors: Arc::clone(errors), } } @@ -59,16 +95,19 @@ pub fn write(&self, path: P, contents: C) -> Result<(), E> // be to create the file sync so errors are reported eagerly. let contents = contents.as_ref().to_vec(); let path = path.as_ref().to_path_buf(); - rayon::spawn(move || + let sender = self.errors.sender.clone(); + rayon::spawn(move || { match fs::write(&path, &contents) { - Ok(_) => (), - Err(e) => { - // In principle these should get displayed at the top - // level, but just in case, send to stderr as well. - eprintln!("\"{}\": {}", path.display(), e); - panic!("\"{}\": {}", path.display(), e); + Ok(_) => { + sender.send(None) + .expect(&format!("failed to send error on \"{}\"", path.display())); } - }); + Err(e) => { + sender.send(Some(format!("\"{}\": {}", path.display(), e))) + .expect(&format!("failed to send non-error on \"{}\"", path.display())); + } + } + }); Ok(()) } else { Ok(try_err!(fs::write(&path, contents), path)) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 8b514cb09ae..fe5fb4d73d8 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -61,7 +61,7 @@ use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, Mutability}; use crate::config::RenderOptions; -use crate::docfs::{DocFS, PathError}; +use crate::docfs::{DocFS, ErrorStorage, PathError}; use crate::doctree; use crate::fold::DocFolder; use crate::html::escape::Escape; @@ -104,7 +104,12 @@ fn description(&self) -> &str { impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "\"{}\": {}", self.file.display(), self.error) + let file = self.file.display().to_string(); + if file.is_empty() { + write!(f, "{}", self.error) + } else { + write!(f, "\"{}\": {}", self.file.display(), self.error) + } } } @@ -547,6 +552,7 @@ pub fn run(mut krate: clean::Crate, }, _ => PathBuf::new(), }; + let errors = Arc::new(ErrorStorage::new()); let mut scx = SharedContext { src_root, passes, @@ -567,7 +573,7 @@ pub fn run(mut krate: clean::Crate, static_root_path, generate_search_filter, generate_redirect_pages, - fs: DocFS::new(), + fs: DocFS::new(&errors), }; // If user passed in `--playground-url` arg, we fill in crate name here @@ -715,7 +721,15 @@ pub fn run(mut krate: clean::Crate, Arc::get_mut(&mut cx.shared).unwrap().fs.set_sync_only(false); // And finally render the whole crate's documentation - cx.krate(krate) + let ret = cx.krate(krate); + let nb_errors = errors.write_errors(diag); + if ret.is_err() { + ret + } else if nb_errors > 0 { + Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), "")) + } else { + Ok(()) + } } /// Builds the search index from the collected metadata From 65f12950b64cbea42e97f1425952c77cf024d5ed Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 21 Jun 2019 00:26:13 +0200 Subject: [PATCH 26/28] Better handling of the sender channel part in rustdoc file writing --- src/librustdoc/docfs.rs | 12 ++++++------ src/librustdoc/html/render.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index 96399b8e36f..740947fc3e3 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -11,7 +11,6 @@ use errors; -use std::cell::RefCell; use std::fs; use std::io; use std::path::Path; @@ -32,7 +31,7 @@ pub trait PathError { } pub struct ErrorStorage { - sender: Sender>, + sender: Option>>, receiver: Receiver>, } @@ -40,15 +39,16 @@ impl ErrorStorage { pub fn new() -> ErrorStorage { let (sender, receiver) = channel(); ErrorStorage { - sender, + sender: Some(sender), receiver, } } /// Prints all stored errors. Returns the number of printed errors. - pub fn write_errors(&self, diag: &errors::Handler) -> usize { + pub fn write_errors(&mut self, diag: &errors::Handler) -> usize { let mut printed = 0; - drop(self.sender); + // In order to drop the sender part of the channel. + self.sender = None; for msg in self.receiver.iter() { if let Some(ref error) = msg { @@ -95,7 +95,7 @@ pub fn write(&self, path: P, contents: C) -> Result<(), E> // be to create the file sync so errors are reported eagerly. let contents = contents.as_ref().to_vec(); let path = path.as_ref().to_path_buf(); - let sender = self.errors.sender.clone(); + let sender = self.errors.sender.clone().unwrap(); rayon::spawn(move || { match fs::write(&path, &contents) { Ok(_) => { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index fe5fb4d73d8..f0aff961c67 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -552,7 +552,7 @@ pub fn run(mut krate: clean::Crate, }, _ => PathBuf::new(), }; - let errors = Arc::new(ErrorStorage::new()); + let mut errors = Arc::new(ErrorStorage::new()); let mut scx = SharedContext { src_root, passes, @@ -722,7 +722,7 @@ pub fn run(mut krate: clean::Crate, // And finally render the whole crate's documentation let ret = cx.krate(krate); - let nb_errors = errors.write_errors(diag); + let nb_errors = Arc::get_mut(&mut errors).map_or_else(|| 0, |errors| errors.write_errors(diag)); if ret.is_err() { ret } else if nb_errors > 0 { From 54acbd96f989b7100d4f5184e56bfc6159dd2777 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 21 Jun 2019 22:12:07 +0800 Subject: [PATCH 27/28] changed expected output in tests so it now passes with changed output --- .../ui/traits/trait-alias/trait-alias-only-maybe-bound.stderr | 4 ++-- src/test/ui/traits/trait-object-macro-matcher.stderr | 2 +- src/test/ui/traits/trait-object-vs-lifetime-2.stderr | 2 +- src/test/ui/traits/trait-object-vs-lifetime.stderr | 4 ++-- src/test/ui/traits/wf-trait-object-only-maybe-bound.stderr | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.stderr b/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.stderr index d4f77200fd5..6de79fa917b 100644 --- a/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.stderr +++ b/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.stderr @@ -1,10 +1,10 @@ -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/trait-alias-only-maybe-bound.rs:13:12 | LL | type _T0 = dyn _1; | ^^^^^^ -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/trait-alias-only-maybe-bound.rs:19:12 | LL | type _T1 = dyn _2; diff --git a/src/test/ui/traits/trait-object-macro-matcher.stderr b/src/test/ui/traits/trait-object-macro-matcher.stderr index 0b84c3dfcb0..6b5effaad9b 100644 --- a/src/test/ui/traits/trait-object-macro-matcher.stderr +++ b/src/test/ui/traits/trait-object-macro-matcher.stderr @@ -1,4 +1,4 @@ -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/trait-object-macro-matcher.rs:11:8 | LL | m!(dyn 'static +); diff --git a/src/test/ui/traits/trait-object-vs-lifetime-2.stderr b/src/test/ui/traits/trait-object-vs-lifetime-2.stderr index ef5e2407b9a..014d380b63c 100644 --- a/src/test/ui/traits/trait-object-vs-lifetime-2.stderr +++ b/src/test/ui/traits/trait-object-vs-lifetime-2.stderr @@ -1,4 +1,4 @@ -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/trait-object-vs-lifetime-2.rs:7:5 | LL | dyn 'static +: 'static + Copy, diff --git a/src/test/ui/traits/trait-object-vs-lifetime.stderr b/src/test/ui/traits/trait-object-vs-lifetime.stderr index be1af59ed4f..be1958770a4 100644 --- a/src/test/ui/traits/trait-object-vs-lifetime.stderr +++ b/src/test/ui/traits/trait-object-vs-lifetime.stderr @@ -4,7 +4,7 @@ error: lifetime arguments must be declared prior to type arguments LL | let _: S; | ^^^^^^^ -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/trait-object-vs-lifetime.rs:9:23 | LL | let _: S<'static, dyn 'static +>; @@ -22,7 +22,7 @@ error[E0107]: wrong number of type arguments: expected 1, found 0 LL | let _: S<'static, 'static>; | ^^^^^^^^^^^^^^^^^^^ expected 1 type argument -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/trait-object-vs-lifetime.rs:14:14 | LL | let _: S; diff --git a/src/test/ui/traits/wf-trait-object-only-maybe-bound.stderr b/src/test/ui/traits/wf-trait-object-only-maybe-bound.stderr index 0cfb389fd89..8cc97addc7d 100644 --- a/src/test/ui/traits/wf-trait-object-only-maybe-bound.stderr +++ b/src/test/ui/traits/wf-trait-object-only-maybe-bound.stderr @@ -4,7 +4,7 @@ error: `?Trait` is not permitted in trait object types LL | type _0 = dyn ?Sized; | ^^^^^^ -error[E0224]: at least one non-builtin trait is required for an object type +error[E0224]: at least one trait is required for an object type --> $DIR/wf-trait-object-only-maybe-bound.rs:3:11 | LL | type _0 = dyn ?Sized; From f4cd3c205431e987504b5e3ca56de74fab49deb3 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 22 Jun 2019 00:12:28 +0800 Subject: [PATCH 28/28] adding in these files that didn't get added in previous commit --- .../ui/traits/trait-alias/trait-alias-only-maybe-bound.rs | 4 ++-- src/test/ui/traits/trait-object-macro-matcher.rs | 2 +- src/test/ui/traits/trait-object-vs-lifetime-2.rs | 2 +- src/test/ui/traits/trait-object-vs-lifetime.rs | 4 ++-- src/test/ui/traits/wf-trait-object-only-maybe-bound.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.rs b/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.rs index d6c611d2a4d..e4abf314e0a 100644 --- a/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.rs +++ b/src/test/ui/traits/trait-alias/trait-alias-only-maybe-bound.rs @@ -11,12 +11,12 @@ // Straight list expansion: type _T0 = dyn _1; -//~^ ERROR at least one non-builtin trait is required for an object type [E0224] +//~^ ERROR at least one trait is required for an object type [E0224] // Twice: trait _2 = _1 + _1; type _T1 = dyn _2; -//~^ ERROR at least one non-builtin trait is required for an object type [E0224] +//~^ ERROR at least one trait is required for an object type [E0224] fn main() {} diff --git a/src/test/ui/traits/trait-object-macro-matcher.rs b/src/test/ui/traits/trait-object-macro-matcher.rs index 5ec157275a6..a6852569f3a 100644 --- a/src/test/ui/traits/trait-object-macro-matcher.rs +++ b/src/test/ui/traits/trait-object-macro-matcher.rs @@ -8,5 +8,5 @@ fn main() { m!(dyn Copy + Send + 'static); //~^ ERROR the trait `std::marker::Copy` cannot be made into an object m!(dyn 'static + Send); - m!(dyn 'static +); //~ ERROR at least one non-builtin trait is required for an object type + m!(dyn 'static +); //~ ERROR at least one trait is required for an object type } diff --git a/src/test/ui/traits/trait-object-vs-lifetime-2.rs b/src/test/ui/traits/trait-object-vs-lifetime-2.rs index 8a9b8e79348..0b33dc7f69a 100644 --- a/src/test/ui/traits/trait-object-vs-lifetime-2.rs +++ b/src/test/ui/traits/trait-object-vs-lifetime-2.rs @@ -5,7 +5,7 @@ fn g() where 'static: 'static, dyn 'static +: 'static + Copy, - //~^ ERROR at least one non-builtin trait is required for an object type + //~^ ERROR at least one trait is required for an object type {} fn main() {} diff --git a/src/test/ui/traits/trait-object-vs-lifetime.rs b/src/test/ui/traits/trait-object-vs-lifetime.rs index 803b29367c8..e0ff7349483 100644 --- a/src/test/ui/traits/trait-object-vs-lifetime.rs +++ b/src/test/ui/traits/trait-object-vs-lifetime.rs @@ -7,11 +7,11 @@ fn main() { // `'static` is a lifetime argument, `'static +` is a type argument let _: S<'static, u8>; let _: S<'static, dyn 'static +>; - //~^ at least one non-builtin trait is required for an object type + //~^ at least one trait is required for an object type let _: S<'static, 'static>; //~^ ERROR wrong number of lifetime arguments: expected 1, found 2 //~| ERROR wrong number of type arguments: expected 1, found 0 let _: S; //~^ ERROR lifetime arguments must be declared prior to type arguments - //~| ERROR at least one non-builtin trait is required for an object type + //~| ERROR at least one trait is required for an object type } diff --git a/src/test/ui/traits/wf-trait-object-only-maybe-bound.rs b/src/test/ui/traits/wf-trait-object-only-maybe-bound.rs index 1b83d2487f4..3e6db3e997c 100644 --- a/src/test/ui/traits/wf-trait-object-only-maybe-bound.rs +++ b/src/test/ui/traits/wf-trait-object-only-maybe-bound.rs @@ -1,7 +1,7 @@ // Test that `dyn ?Sized` (i.e., a trait object with only a maybe buond) is not allowed. type _0 = dyn ?Sized; -//~^ ERROR at least one non-builtin trait is required for an object type [E0224] +//~^ ERROR at least one trait is required for an object type [E0224] //~| ERROR ?Trait` is not permitted in trait object types fn main() {}