Skip to content

Commit

Permalink
Be explicit about whether GenericArgCountMismatch arose from a fata…
Browse files Browse the repository at this point in the history
…l error
  • Loading branch information
varkor committed Feb 22, 2020
1 parent 104131c commit 33143fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -134,7 +134,8 @@ enum GenericArgPosition {

/// A marker denoting that the generic arguments that were
/// provided did not match the respective generic parameters.
pub struct GenericArgCountMismatch;
/// The field indicates whether a fatal error was reported (`Some`), or just a lint (`None`).
pub struct GenericArgCountMismatch(pub Option<ErrorReported>);

impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
pub fn ast_region_to_region(
Expand Down Expand Up @@ -320,18 +321,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let mut explicit_lifetimes = Ok(());
if !infer_lifetimes {
if let Some(span_late) = def.has_late_bound_regions {
explicit_lifetimes = Err(GenericArgCountMismatch);
let msg = "cannot specify lifetime arguments explicitly \
if late bound lifetime parameters are present";
let note = "the late bound lifetime parameter is introduced here";
let span = args.args[0].span();
if position == GenericArgPosition::Value
&& arg_counts.lifetimes != param_counts.lifetimes
{
explicit_lifetimes = Err(GenericArgCountMismatch(Some(ErrorReported)));
let mut err = tcx.sess.struct_span_err(span, msg);
err.span_note(span_late, note);
err.emit();
} else {
explicit_lifetimes = Err(GenericArgCountMismatch(None));
let mut multispan = MultiSpan::from_span(span);
multispan.push_span_label(span_late, note.to_string());
tcx.struct_span_lint_hir(
Expand Down Expand Up @@ -405,7 +407,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
err.emit();

Err(GenericArgCountMismatch)
Err(GenericArgCountMismatch(Some(ErrorReported)))
};

let mut arg_count_correct = explicit_lifetimes;
Expand Down
16 changes: 10 additions & 6 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -5452,11 +5452,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// parameter internally, but we don't allow users to specify the
// parameter's value explicitly, so we have to do some error-
// checking here.
let suppress_errors = AstConv::check_generic_arg_count_for_call(
tcx, span, &generics, &seg, false, // `is_method_call`
)
.is_err();
if suppress_errors {
if let Err(GenericArgCountMismatch(Some(ErrorReported))) =
AstConv::check_generic_arg_count_for_call(
tcx, span, &generics, &seg, false, // `is_method_call`
)
{
infer_args_for_err.insert(index);
self.set_tainted_by_errors(); // See issue #53251.
}
Expand Down Expand Up @@ -5521,7 +5521,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&[][..],
has_self,
self_ty,
if infer_args_for_err.is_empty() { Ok(()) } else { Err(GenericArgCountMismatch) },
if infer_args_for_err.is_empty() {
Ok(())
} else {
Err(GenericArgCountMismatch(Some(ErrorReported)))
},
// Provide the generic args, and whether types should be inferred.
|def_id| {
if let Some(&PathSeg(_, index)) =
Expand Down

0 comments on commit 33143fd

Please sign in to comment.