1
Fork 0

ensure arguments are included in count mismatch span

This commit is contained in:
Andy Russell 2020-09-23 22:43:32 -04:00
parent 95daa068f1
commit 14b2d16c5c
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
17 changed files with 239 additions and 88 deletions

View file

@ -285,10 +285,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
arg_exprs: &'tcx [hir::Expr<'tcx>],
expected: Expectation<'tcx>,
) -> Ty<'tcx> {
let (fn_sig, def_span) = match *callee_ty.kind() {
ty::FnDef(def_id, _) => {
(callee_ty.fn_sig(self.tcx), self.tcx.hir().span_if_local(def_id))
}
let (fn_sig, def_id) = match *callee_ty.kind() {
ty::FnDef(def_id, _) => (callee_ty.fn_sig(self.tcx), Some(def_id)),
ty::FnPtr(sig) => (sig, None),
ref t => {
let mut unit_variant = None;
@ -427,7 +425,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
arg_exprs,
fn_sig.c_variadic,
TupleArgumentsFlag::DontTupleArguments,
def_span,
def_id,
);
fn_sig.output()

View file

@ -19,7 +19,7 @@ use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, Ty};
use rustc_session::Session;
use rustc_span::symbol::{sym, Ident};
use rustc_span::{self, Span};
use rustc_span::{self, MultiSpan, Span};
use rustc_trait_selection::traits::{self, ObligationCauseCode};
use std::mem::replace;
@ -83,7 +83,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
args_no_rcvr,
method.sig.c_variadic,
tuple_arguments,
self.tcx.hir().span_if_local(method.def_id),
Some(method.def_id),
);
method.sig.output()
}
@ -99,7 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
args: &'tcx [hir::Expr<'tcx>],
c_variadic: bool,
tuple_arguments: TupleArgumentsFlag,
def_span: Option<Span>,
def_id: Option<DefId>,
) {
let tcx = self.tcx;
// Grab the argument types, supplying fresh type variables
@ -172,9 +172,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}
if let Some(def_s) = def_span.map(|sp| tcx.sess.source_map().guess_head_span(sp)) {
err.span_label(def_s, "defined here");
if let Some(def_id) = def_id {
if let Some(node) = tcx.hir().get_if_local(def_id) {
let mut spans: MultiSpan = node
.ident()
.map(|ident| ident.span)
.unwrap_or_else(|| tcx.hir().span(node.hir_id().unwrap()))
.into();
if let Some(id) = node.body_id() {
let body = tcx.hir().body(id);
for param in body.params {
spans.push_span_label(param.span, String::new());
}
}
let def_kind = tcx.def_kind(def_id);
err.span_note(spans, &format!("{} defined here", def_kind.descr(def_id)));
}
}
if sugg_unit {
let sugg_span = tcx.sess.source_map().end_point(expr.span);
// remove closing `)` from the span