Skip to content

Commit 637b1e9

Browse files
authored
Rollup merge of rust-lang#84410 - BoxyUwU:blue, r=varkor
Fix generic arg mismatch errors being ignored with explicit late bound lifetimes Fixes rust-lang#83466 r? `@varkor`
2 parents 18371c8 + 3905433 commit 637b1e9

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

compiler/rustc_typeck/src/astconv/generics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
278278
// another. This is an error. However, if we already know that
279279
// the arguments don't match up with the parameters, we won't issue
280280
// an additional error, as the user already knows what's wrong.
281-
if arg_count.correct.is_ok()
282-
&& arg_count.explicit_late_bound == ExplicitLateBound::No
283-
{
281+
if arg_count.correct.is_ok() {
284282
// We're going to iterate over the parameters to sort them out, and
285283
// show that order to the user as a possible order for the parameters
286284
let mut param_types_present = defs
@@ -462,7 +460,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
462460
}
463461

464462
if silent {
465-
return false;
463+
return true;
466464
}
467465

468466
if provided > expected_max {

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12821282

12831283
let mut infer_args_for_err = FxHashSet::default();
12841284

1285+
let mut explicit_late_bound = ExplicitLateBound::No;
12851286
for &PathSeg(def_id, index) in &path_segs {
12861287
let seg = &segments[index];
12871288
let generics = tcx.generics_of(def_id);
@@ -1290,17 +1291,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12901291
// parameter internally, but we don't allow users to specify the
12911292
// parameter's value explicitly, so we have to do some error-
12921293
// checking here.
1293-
if let GenericArgCountResult {
1294-
correct: Err(GenericArgCountMismatch { reported: Some(_), .. }),
1295-
..
1296-
} = <dyn AstConv<'_>>::check_generic_arg_count_for_call(
1294+
let arg_count = <dyn AstConv<'_>>::check_generic_arg_count_for_call(
12971295
tcx,
12981296
span,
12991297
def_id,
13001298
&generics,
13011299
seg,
13021300
IsMethodCall::No,
1303-
) {
1301+
);
1302+
1303+
if let ExplicitLateBound::Yes = arg_count.explicit_late_bound {
1304+
explicit_late_bound = ExplicitLateBound::Yes;
1305+
}
1306+
1307+
if let Err(GenericArgCountMismatch { reported: Some(_), .. }) = arg_count.correct {
13041308
infer_args_for_err.insert(index);
13051309
self.set_tainted_by_errors(); // See issue #53251.
13061310
}
@@ -1357,7 +1361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13571361
let ty = tcx.type_of(def_id);
13581362

13591363
let arg_count = GenericArgCountResult {
1360-
explicit_late_bound: ExplicitLateBound::No,
1364+
explicit_late_bound,
13611365
correct: if infer_args_for_err.is_empty() {
13621366
Ok(())
13631367
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// regression test for #83466- tests that generic arg mismatch errors between
2+
// consts and types are not supressed when there are explicit late bound lifetimes
3+
4+
struct S;
5+
impl S {
6+
fn func<'a, U>(self) -> U {
7+
todo!()
8+
}
9+
}
10+
fn dont_crash<'a, U>() {
11+
S.func::<'a, 10_u32>()
12+
//~^ WARNING cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
13+
//~^^ WARNING this was previously accepted by
14+
//~^^^ ERROR constant provided when a type was expected [E0747]
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
2+
--> $DIR/issue-83466.rs:11:14
3+
|
4+
LL | fn func<'a, U>(self) -> U {
5+
| -- the late bound lifetime parameter is introduced here
6+
...
7+
LL | S.func::<'a, 10_u32>()
8+
| ^^
9+
|
10+
= note: `#[warn(late_bound_lifetime_arguments)]` on by default
11+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12+
= note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>
13+
14+
error[E0747]: constant provided when a type was expected
15+
--> $DIR/issue-83466.rs:11:18
16+
|
17+
LL | S.func::<'a, 10_u32>()
18+
| ^^^^^^
19+
20+
error: aborting due to previous error; 1 warning emitted
21+
22+
For more information about this error, try `rustc --explain E0747`.

0 commit comments

Comments
 (0)