Skip to content

Commit 5e3b41e

Browse files
committed
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`.
1 parent 1e5f496 commit 5e3b41e

File tree

9 files changed

+27
-74
lines changed

9 files changed

+27
-74
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3092,7 +3092,7 @@ impl<'a> LoweringContext<'a> {
30923092
new_argument_id, ident, None),
30933093
span: desugared_span,
30943094
}),
3095-
source: hir::ArgSource::AsyncFn(argument.pat.hir_id),
3095+
source: hir::ArgSource::AsyncFn,
30963096
};
30973097

30983098
let construct_stmt = |this: &mut LoweringContext<'_>, pat: P<hir::Pat>,

src/librustc/hir/map/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -699,19 +699,6 @@ impl<'hir> Map<'hir> {
699699
}
700700
}
701701

702-
/// Returns the `HirId` of this pattern, or, if this is an `async fn` desugaring, the `HirId`
703-
/// of the original pattern that the user wrote.
704-
pub fn original_pat_of_argument(&self, arg: &'hir Arg) -> &'hir Pat {
705-
match &arg.source {
706-
ArgSource::Normal => &*arg.pat,
707-
ArgSource::AsyncFn(hir_id) => match self.find_by_hir_id(*hir_id) {
708-
Some(Node::Pat(pat)) | Some(Node::Binding(pat)) => &pat,
709-
Some(Node::Local(local)) => &*local.pat,
710-
x => bug!("ArgSource::AsyncFn HirId not a pattern/binding/local: {:?}", x),
711-
},
712-
}
713-
}
714-
715702
pub fn is_const_scope(&self, hir_id: HirId) -> bool {
716703
self.walk_parent_nodes(hir_id, |node| match *node {
717704
Node::Item(Item { node: ItemKind::Const(_, _), .. }) => true,

src/librustc/hir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,8 +1937,8 @@ pub struct Arg {
19371937
pub enum ArgSource {
19381938
/// Argument as specified by the user.
19391939
Normal,
1940-
/// Generated argument from `async fn` lowering, `HirId` is the original pattern.
1941-
AsyncFn(HirId),
1940+
/// Generated argument from `async fn` lowering.
1941+
AsyncFn,
19421942
}
19431943

19441944
/// Represents the header (not the body) of a function declaration.

src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
8686
let sub_is_ret_type =
8787
self.is_return_type_anon(scope_def_id_sub, bregion_sub, ty_fndecl_sub);
8888

89-
let arg_sup_pat = self.tcx().hir().original_pat_of_argument(anon_arg_sup);
90-
let span_label_var1 = match arg_sup_pat.simple_ident() {
89+
let span_label_var1 = match anon_arg_sup.pat.simple_ident() {
9190
Some(simple_ident) => format!(" from `{}`", simple_ident),
9291
None => String::new(),
9392
};
9493

95-
let arg_sub_pat = self.tcx().hir().original_pat_of_argument(anon_arg_sub);
96-
let span_label_var2 = match arg_sub_pat.simple_ident() {
94+
let span_label_var2 = match anon_arg_sub.pat.simple_ident() {
9795
Some(simple_ident) => format!(" into `{}`", simple_ident),
9896
None => String::new(),
9997
};

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
9595
}
9696
}
9797

98-
let arg_pat = self.tcx().hir().original_pat_of_argument(arg);
99-
let (error_var, span_label_var) = match arg_pat.simple_ident() {
98+
let (error_var, span_label_var) = match arg.pat.simple_ident() {
10099
Some(simple_ident) => (
101100
format!("the type of `{}`", simple_ident),
102101
format!("the type of `{}`", simple_ident),

src/librustc/middle/resolve_lifetime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,10 +2414,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
24142414
have_bound_regions,
24152415
} = info;
24162416

2417-
let help_name = if let Some(body) = parent {
2418-
let arg = &self.tcx.hir().body(body).arguments[index];
2419-
let original_pat = self.tcx.hir().original_pat_of_argument(arg);
2420-
format!("`{}`", self.tcx.hir().hir_to_pretty_string(original_pat.hir_id))
2417+
let help_name = if let Some(ident) = parent.and_then(|body| {
2418+
self.tcx.hir().body(body).arguments[index].pat.simple_ident()
2419+
}) {
2420+
format!("`{}`", ident)
24212421
} else {
24222422
format!("argument {}", index + 1)
24232423
};

src/librustc_mir/build/mod.rs

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,11 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'
8484
// HACK(eddyb) Avoid having RustCall on closures,
8585
// as it adds unnecessary (and wrong) auto-tupling.
8686
abi = Abi::Rust;
87-
Some(ArgInfo {
88-
ty: liberated_closure_env_ty(tcx, id, body_id),
89-
span: None,
90-
pattern: None,
91-
user_pattern: None,
92-
self_kind: None,
93-
})
87+
Some(ArgInfo(liberated_closure_env_ty(tcx, id, body_id), None, None, None))
9488
}
9589
ty::Generator(..) => {
9690
let gen_ty = tcx.body_tables(body_id).node_type(id);
97-
Some(ArgInfo {
98-
ty: gen_ty,
99-
span: None,
100-
pattern: None,
101-
user_pattern: None,
102-
self_kind: None,
103-
})
91+
Some(ArgInfo(gen_ty, None, None, None))
10492
}
10593
_ => None,
10694
};
@@ -139,14 +127,7 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Body<'
139127
self_arg = None;
140128
}
141129

142-
let original_pat = tcx.hir().original_pat_of_argument(arg);
143-
ArgInfo {
144-
ty: fn_sig.inputs()[index],
145-
span: opt_ty_info,
146-
pattern: Some(&*arg.pat),
147-
user_pattern: Some(&original_pat),
148-
self_kind: self_arg,
149-
}
130+
ArgInfo(fn_sig.inputs()[index], opt_ty_info, Some(&*arg.pat), self_arg)
150131
});
151132

152133
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>,
634615
///////////////////////////////////////////////////////////////////////////
635616
/// the main entry point for building MIR for a function
636617
637-
struct ArgInfo<'gcx> {
638-
ty: Ty<'gcx>,
639-
span: Option<Span>,
640-
pattern: Option<&'gcx hir::Pat>,
641-
user_pattern: Option<&'gcx hir::Pat>,
642-
self_kind: Option<ImplicitSelfKind>,
643-
}
618+
struct ArgInfo<'gcx>(Ty<'gcx>, Option<Span>, Option<&'gcx hir::Pat>, Option<ImplicitSelfKind>);
644619

645620
fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
646621
fn_id: hir::HirId,
@@ -901,18 +876,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
901876
-> BlockAnd<()>
902877
{
903878
// Allocate locals for the function arguments
904-
for &ArgInfo { ty, span: _, pattern, user_pattern, self_kind: _ } in arguments.iter() {
879+
for &ArgInfo(ty, _, pattern, _) in arguments.iter() {
905880
// If this is a simple binding pattern, give the local a name for
906881
// debuginfo and so that error reporting knows that this is a user
907882
// variable. For any other pattern the pattern introduces new
908883
// variables which will be named instead.
909-
let (name, span) = if let Some(pat) = user_pattern {
910-
match pat.node {
911-
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, _)
912-
| hir::PatKind::Binding(hir::BindingAnnotation::Mutable, _, ident, _) =>
913-
(Some(ident.name), pat.span),
914-
_ => (None, pattern.map_or(self.fn_span, |pat| pat.span))
915-
}
884+
let (name, span) = if let Some(pat) = pattern {
885+
(pat.simple_ident().map(|ident| ident.name), pat.span)
916886
} else {
917887
(None, self.fn_span)
918888
};
@@ -937,13 +907,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
937907
// Function arguments always get the first Local indices after the return place
938908
let local = Local::new(index + 1);
939909
let place = Place::Base(PlaceBase::Local(local));
940-
let &ArgInfo {
941-
ty,
942-
span: opt_ty_info,
943-
pattern,
944-
user_pattern: _,
945-
self_kind: ref self_binding
946-
} = arg_info;
910+
let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info;
947911

948912
// Make sure we drop (parts of) the argument even when not matched on.
949913
self.schedule_drop(
@@ -958,7 +922,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
958922

959923
match *pattern.kind {
960924
// Don't introduce extra copies for simple bindings
961-
PatternKind::Binding { mutability, var, mode: BindingMode::ByValue, .. } => {
925+
PatternKind::Binding {
926+
mutability,
927+
var,
928+
mode: BindingMode::ByValue,
929+
subpattern: None,
930+
..
931+
} => {
962932
self.local_decls[local].mutability = mutability;
963933
self.local_decls[local].is_user_variable =
964934
if let Some(kind) = self_binding {

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,9 +2018,8 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
20182018

20192019
Arguments {
20202020
values: self.0.iter().enumerate().map(|(i, ty)| {
2021-
let original_pat = cx.tcx.hir().original_pat_of_argument(&body.arguments[i]);
20222021
Argument {
2023-
name: name_from_pat(original_pat),
2022+
name: name_from_pat(&body.arguments[i].pat),
20242023
type_: ty.clean(cx),
20252024
}
20262025
}).collect()

src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ error[E0106]: missing lifetime specifier
3030
LL | fn foo2(_: &'_ u8, y: &'_ u8) -> &'_ u8 { y }
3131
| ^^ expected lifetime parameter
3232
|
33-
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `_` or `y`
33+
= 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`
3434

3535
error: aborting due to 5 previous errors
3636

0 commit comments

Comments
 (0)