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`.
This commit is contained in:
David Wood 2019-06-02 19:03:17 +01:00
parent 1e5f496143
commit 5e3b41e0cb
No known key found for this signature in database
GPG Key ID: 01760B4F9F53F154
9 changed files with 27 additions and 74 deletions

View File

@ -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>,

View File

@ -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,

View File

@ -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.

View File

@ -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(),
};

View File

@ -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),

View File

@ -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)
};

View File

@ -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 {

View File

@ -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()

View File

@ -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