self_arg = None;
}
- ArgInfo(fn_sig.inputs()[index], opt_ty_info, Some(&*arg.pat), self_arg)
+ ArgInfo(fn_sig.inputs()[index], opt_ty_info, Some(&arg), self_arg)
});
let arguments = implicit_argument.into_iter().chain(explicit_arguments);
///////////////////////////////////////////////////////////////////////////
/// the main entry point for building MIR for a function
-struct ArgInfo<'tcx>(Ty<'tcx>, Option<Span>, Option<&'tcx hir::Pat>, Option<ImplicitSelfKind>);
+struct ArgInfo<'tcx>(Ty<'tcx>, Option<Span>, Option<&'tcx hir::Arg>, Option<ImplicitSelfKind>);
fn construct_fn<'a, 'tcx, A>(
hir: Cx<'a, 'tcx>,
-> BlockAnd<()>
{
// Allocate locals for the function arguments
- for &ArgInfo(ty, _, pattern, _) in arguments.iter() {
+ for &ArgInfo(ty, _, arg_opt, _) 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) = pattern {
- (pat.simple_ident().map(|ident| ident.name), pat.span)
+ let (name, span) = if let Some(arg) = arg_opt {
+ (arg.pat.simple_ident().map(|ident| ident.name), arg.pat.span)
} else {
(None, self.fn_span)
};
// Function arguments always get the first Local indices after the return place
let local = Local::new(index + 1);
let place = Place::from(local);
- let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info;
+ let &ArgInfo(ty, opt_ty_info, arg_opt, ref self_binding) = arg_info;
// Make sure we drop (parts of) the argument even when not matched on.
self.schedule_drop(
- pattern.as_ref().map_or(ast_body.span, |pat| pat.span),
+ arg_opt.as_ref().map_or(ast_body.span, |arg| arg.pat.span),
argument_scope, local, ty, DropKind::Value,
);
- if let Some(pattern) = pattern {
- let pattern = self.hir.pattern_from_hir(pattern);
+ if let Some(arg) = arg_opt {
+ let pattern = self.hir.pattern_from_hir(&arg.pat);
+ let original_source_scope = self.source_scope;
let span = pattern.span;
-
+ self.set_correct_source_scope_for_arg(arg.hir_id, original_source_scope, span);
match *pattern.kind {
// Don't introduce extra copies for simple bindings
PatternKind::Binding {
..
} => {
self.local_decls[local].mutability = mutability;
+ self.local_decls[local].source_info.scope = self.source_scope;
self.local_decls[local].is_user_variable =
if let Some(kind) = self_binding {
Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf(*kind)))
unpack!(block = self.place_into_pattern(block, pattern, &place, false));
}
}
+ self.source_scope = original_source_scope;
}
}
self.into(&Place::RETURN_PLACE, block, body)
}
+ fn set_correct_source_scope_for_arg(
+ &mut self,
+ arg_hir_id: hir::HirId,
+ original_source_scope: SourceScope,
+ pattern_span: Span
+ ) {
+ let tcx = self.hir.tcx();
+ let current_root = tcx.maybe_lint_level_root_bounded(
+ arg_hir_id,
+ self.hir.root_lint_level
+ );
+ let parent_root = tcx.maybe_lint_level_root_bounded(
+ self.source_scope_local_data[original_source_scope].lint_root,
+ self.hir.root_lint_level,
+ );
+ if current_root != parent_root {
+ self.source_scope = self.new_source_scope(
+ pattern_span,
+ LintLevel::Explicit(current_root),
+ None
+ );
+ }
+ }
+
fn get_unit_temp(&mut self) -> Place<'tcx> {
match self.unit_temp {
Some(ref tmp) => tmp.clone(),