Skip to content

Commit

Permalink
Auto merge of #84410 - BoxyUwU:blue, r=varkor
Browse files Browse the repository at this point in the history
Fix generic arg mismatch errors being ignored with explicit late bound lifetimes

Fixes #83466

r? `@varkor`
  • Loading branch information
bors committed May 1, 2021
2 parents 6e2a344 + 3905433 commit 4de7572
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_typeck/src/astconv/generics.rs
Expand Up @@ -278,9 +278,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// another. This is an error. However, if we already know that
// the arguments don't match up with the parameters, we won't issue
// an additional error, as the user already knows what's wrong.
if arg_count.correct.is_ok()
&& arg_count.explicit_late_bound == ExplicitLateBound::No
{
if arg_count.correct.is_ok() {
// We're going to iterate over the parameters to sort them out, and
// show that order to the user as a possible order for the parameters
let mut param_types_present = defs
Expand Down Expand Up @@ -462,7 +460,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}

if silent {
return false;
return true;
}

if provided > expected_max {
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Expand Up @@ -1282,6 +1282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let mut infer_args_for_err = FxHashSet::default();

let mut explicit_late_bound = ExplicitLateBound::No;
for &PathSeg(def_id, index) in &path_segs {
let seg = &segments[index];
let generics = tcx.generics_of(def_id);
Expand All @@ -1290,17 +1291,20 @@ 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.
if let GenericArgCountResult {
correct: Err(GenericArgCountMismatch { reported: Some(_), .. }),
..
} = <dyn AstConv<'_>>::check_generic_arg_count_for_call(
let arg_count = <dyn AstConv<'_>>::check_generic_arg_count_for_call(
tcx,
span,
def_id,
&generics,
seg,
IsMethodCall::No,
) {
);

if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
explicit_late_bound = ExplicitLateBound::Yes;
}

if let Err(GenericArgCountMismatch { reported: Some(_), .. }) = arg_count.correct {
infer_args_for_err.insert(index);
self.set_tainted_by_errors(); // See issue #53251.
}
Expand Down Expand Up @@ -1357,7 +1361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = tcx.type_of(def_id);

let arg_count = GenericArgCountResult {
explicit_late_bound: ExplicitLateBound::No,
explicit_late_bound,
correct: if infer_args_for_err.is_empty() {
Ok(())
} else {
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/const-generics/issues/issue-83466.rs
@@ -0,0 +1,17 @@
// regression test for #83466- tests that generic arg mismatch errors between
// consts and types are not supressed when there are explicit late bound lifetimes

struct S;
impl S {
fn func<'a, U>(self) -> U {
todo!()
}
}
fn dont_crash<'a, U>() {
S.func::<'a, 10_u32>()
//~^ WARNING cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
//~^^ WARNING this was previously accepted by
//~^^^ ERROR constant provided when a type was expected [E0747]
}

fn main() {}
22 changes: 22 additions & 0 deletions src/test/ui/const-generics/issues/issue-83466.stderr
@@ -0,0 +1,22 @@
warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/issue-83466.rs:11:14
|
LL | fn func<'a, U>(self) -> U {
| -- the late bound lifetime parameter is introduced here
...
LL | S.func::<'a, 10_u32>()
| ^^
|
= note: `#[warn(late_bound_lifetime_arguments)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>

error[E0747]: constant provided when a type was expected
--> $DIR/issue-83466.rs:11:18
|
LL | S.func::<'a, 10_u32>()
| ^^^^^^

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0747`.

0 comments on commit 4de7572

Please sign in to comment.