about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2019-06-02 19:03:17 +0100
committerDavid Wood <david@davidtw.co>2019-06-03 14:02:21 +0100
commit5e3b41e0cb7f8acef84afe3e9d464e67e7b2c891 (patch)
treed53bc8969b5923da6342663f99362aa2b25b64ba
parent1e5f496143aabf1d4d158d99b73afee7b00f0650 (diff)
downloadrust-5e3b41e0cb7f8acef84afe3e9d464e67e7b2c891.tar.gz
rust-5e3b41e0cb7f8acef84afe3e9d464e67e7b2c891.zip
rustc: remove `HirId` from `ArgSource::AsyncFn`
This commit removes the `HirId` from `ArgSource::AsyncFn`, relying on
the fact that only `simple_ident` is used in each of the locations that
previously took the original pattern from the `ArgSource::AsyncFn`.
-rw-r--r--src/librustc/hir/lowering.rs2
-rw-r--r--src/librustc/hir/map/mod.rs13
-rw-r--r--src/librustc/hir/mod.rs4
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs6
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs3
-rw-r--r--src/librustc/middle/resolve_lifetime.rs8
-rw-r--r--src/librustc_mir/build/mod.rs60
-rw-r--r--src/librustdoc/clean/mod.rs3
-rw-r--r--src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr2
9 files changed, 27 insertions, 74 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index e82b3df8550..d6d8b60f21f 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -3092,7 +3092,7 @@ impl<'a> LoweringContext<'a> {
                                                    new_argument_id, ident, None),
                         span: desugared_span,
                     }),
-                    source: hir::ArgSource::AsyncFn(argument.pat.hir_id),
+                    source: hir::ArgSource::AsyncFn,
                 };
 
                 let construct_stmt = |this: &mut LoweringContext<'_>, pat: P<hir::Pat>,
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index 2d3de5af992..75799a19031 100644
--- a/src/librustc/hir/map/mod.rs
+++ b/src/librustc/hir/map/mod.rs
@@ -699,19 +699,6 @@ impl<'hir> Map<'hir> {
         }
     }
 
-    /// Returns the `HirId` of this pattern, or, if this is an `async fn` desugaring, the `HirId`
-    /// of the original pattern that the user wrote.
-    pub fn original_pat_of_argument(&self, arg: &'hir Arg) -> &'hir Pat {
-        match &arg.source {
-            ArgSource::Normal => &*arg.pat,
-            ArgSource::AsyncFn(hir_id) => match self.find_by_hir_id(*hir_id) {
-                Some(Node::Pat(pat)) | Some(Node::Binding(pat)) => &pat,
-                Some(Node::Local(local)) => &*local.pat,
-                x => bug!("ArgSource::AsyncFn HirId not a pattern/binding/local: {:?}", x),
-            },
-        }
-    }
-
     pub fn is_const_scope(&self, hir_id: HirId) -> bool {
         self.walk_parent_nodes(hir_id, |node| match *node {
             Node::Item(Item { node: ItemKind::Const(_, _), .. }) => true,
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index 817c4cb540f..eb338482eba 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -1937,8 +1937,8 @@ pub struct Arg {
 pub enum ArgSource {
     /// Argument as specified by the user.
     Normal,
-    /// Generated argument from `async fn` lowering, `HirId` is the original pattern.
-    AsyncFn(HirId),
+    /// Generated argument from `async fn` lowering.
+    AsyncFn,
 }
 
 /// Represents the header (not the body) of a function declaration.
diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
index 46785f7ada1..ecdcb4bbf11 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
@@ -86,14 +86,12 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         let sub_is_ret_type =
             self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
 
-        let arg_sup_pat = self.tcx().hir().original_pat_of_argument(anon_arg_sup);
-        let span_label_var1 = match arg_sup_pat.simple_ident() {
+        let span_label_var1 = match anon_arg_sup.pat.simple_ident() {
             Some(simple_ident) => format!(" from `{}`", simple_ident),
             None => String::new(),
         };
 
-        let arg_sub_pat = self.tcx().hir().original_pat_of_argument(anon_arg_sub);
-        let span_label_var2 = match arg_sub_pat.simple_ident() {
+        let span_label_var2 = match anon_arg_sub.pat.simple_ident() {
             Some(simple_ident) => format!(" into `{}`", simple_ident),
             None => String::new(),
         };
diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
index 1eb2af2bd58..0efc124e31f 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
@@ -95,8 +95,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
             }
         }
 
-        let arg_pat = self.tcx().hir().original_pat_of_argument(arg);
-        let (error_var, span_label_var) = match arg_pat.simple_ident() {
+        let (error_var, span_label_var) = match arg.pat.simple_ident() {
             Some(simple_ident) => (
                 format!("the type of `{}`", simple_ident),
                 format!("the type of `{}`", simple_ident),
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index f48da4762b7..7c57c50595b 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -2414,10 +2414,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
                 have_bound_regions,
             } = info;
 
-            let help_name = if let Some(body) = parent {
-                let arg = &self.tcx.hir().body(body).arguments[index];
-                let original_pat = self.tcx.hir().original_pat_of_argument(arg);
-                format!("`{}`", self.tcx.hir().hir_to_pretty_string(original_pat.hir_id))
+            let help_name = if let Some(ident) = parent.and_then(|body| {
+                self.tcx.hir().body(body).arguments[index].pat.simple_ident()
+            }) {
+                format!("`{}`", ident)
             } else {
                 format!("argument {}", index + 1)
             };
diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs
index a5d92d6c88f..91106ebd77e 100644
--- a/src/librustc_mir/build/mod.rs
+++ b/src/librustc_mir/build/mod.rs
@@ -84,23 +84,11 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'
                     // HACK(eddyb) Avoid having RustCall on closures,
                     // as it adds unnecessary (and wrong) auto-tupling.
                     abi = Abi::Rust;
-                    Some(ArgInfo {
-                        ty: liberated_closure_env_ty(tcx, id, body_id),
-                        span: None,
-                        pattern: None,
-                        user_pattern: None,
-                        self_kind: None,
-                    })
+                    Some(ArgInfo(liberated_closure_env_ty(tcx, id, body_id), None, None, None))
                 }
                 ty::Generator(..) => {
                     let gen_ty = tcx.body_tables(body_id).node_type(id);
-                    Some(ArgInfo {
-                        ty: gen_ty,
-                        span: None,
-                        pattern: None,
-                        user_pattern: None,
-                        self_kind: None,
-                    })
+                    Some(ArgInfo(gen_ty, None, None, None))
                 }
                 _ => None,
             };
@@ -139,14 +127,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'
                             self_arg = None;
                         }
 
-                        let original_pat = tcx.hir().original_pat_of_argument(arg);
-                        ArgInfo {
-                            ty: fn_sig.inputs()[index],
-                            span: opt_ty_info,
-                            pattern: Some(&*arg.pat),
-                            user_pattern: Some(&original_pat),
-                            self_kind: self_arg,
-                        }
+                        ArgInfo(fn_sig.inputs()[index], opt_ty_info, Some(&*arg.pat), self_arg)
                     });
 
             let arguments = implicit_argument.into_iter().chain(explicit_arguments);
@@ -634,13 +615,7 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
 ///////////////////////////////////////////////////////////////////////////
 /// the main entry point for building MIR for a function
 
-struct ArgInfo<'gcx> {
-    ty: Ty<'gcx>,
-    span: Option<Span>,
-    pattern: Option<&'gcx hir::Pat>,
-    user_pattern: Option<&'gcx hir::Pat>,
-    self_kind: Option<ImplicitSelfKind>,
-}
+struct ArgInfo<'gcx>(Ty<'gcx>, Option<Span>, Option<&'gcx hir::Pat>, Option<ImplicitSelfKind>);
 
 fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
                                    fn_id: hir::HirId,
@@ -901,18 +876,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
                      -> BlockAnd<()>
     {
         // Allocate locals for the function arguments
-        for &ArgInfo { ty, span: _, pattern, user_pattern, self_kind: _ } in arguments.iter() {
+        for &ArgInfo(ty, _, pattern, _) in arguments.iter() {
             // If this is a simple binding pattern, give the local a name for
             // debuginfo and so that error reporting knows that this is a user
             // variable. For any other pattern the pattern introduces new
             // variables which will be named instead.
-            let (name, span) = if let Some(pat) = user_pattern {
-                match pat.node {
-                    hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _)
-                    | hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, _) =>
-                        (Some(ident.name), pat.span),
-                    _ => (None, pattern.map_or(self.fn_span, |pat| pat.span))
-                }
+            let (name, span) = if let Some(pat) = pattern {
+                (pat.simple_ident().map(|ident| ident.name), pat.span)
             } else {
                 (None, self.fn_span)
             };
@@ -937,13 +907,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
             // Function arguments always get the first Local indices after the return place
             let local = Local::new(index + 1);
             let place = Place::Base(PlaceBase::Local(local));
-            let &ArgInfo {
-                ty,
-                span: opt_ty_info,
-                pattern,
-                user_pattern: _,
-                self_kind: ref self_binding
-            } = arg_info;
+            let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info;
 
             // Make sure we drop (parts of) the argument even when not matched on.
             self.schedule_drop(
@@ -958,7 +922,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
 
                 match *pattern.kind {
                     // Don't introduce extra copies for simple bindings
-                    PatternKind::Binding { mutability, var, mode: BindingMode::ByValue, .. } => {
+                    PatternKind::Binding {
+                        mutability,
+                        var,
+                        mode: BindingMode::ByValue,
+                        subpattern: None,
+                        ..
+                    } => {
                         self.local_decls[local].mutability = mutability;
                         self.local_decls[local].is_user_variable =
                             if let Some(kind) = self_binding {
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 319adea6b86..0c00b3b20b5 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2018,9 +2018,8 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
 
         Arguments {
             values: self.0.iter().enumerate().map(|(i, ty)| {
-                let original_pat = cx.tcx.hir().original_pat_of_argument(&body.arguments[i]);
                 Argument {
-                    name: name_from_pat(original_pat),
+                    name: name_from_pat(&body.arguments[i].pat),
                     type_: ty.clean(cx),
                 }
             }).collect()
diff --git a/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr b/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr
index 654f4285f65..ef9e7e39df0 100644
--- a/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr
+++ b/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr
@@ -30,7 +30,7 @@ error[E0106]: missing lifetime specifier
 LL | fn foo2(_: &'_ u8, y: &'_ u8) -> &'_ u8 { y }
    |                                   ^^ expected lifetime parameter
    |
-   = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `_` or `y`
+   = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from argument 1 or `y`
 
 error: aborting due to 5 previous errors