Skip to content

Commit 5b43960

Browse files
authored
Rollup merge of #87727 - SkiFire13:fix-87718, r=jackh726
explicit_generic_args_with_impl_trait: fix min expected number of generics Fixes #87718 The problem was that `synth_type_param_count` was already subtracted from `named_type_param_count`, so this ended up being subtracted again. This caused `expected_min` to overflow, and ultimately resulting in weird and wrong behaviour. I've also added another test not present in the original issue but caused by the same bug.
2 parents 772db06 + e3389be commit 5b43960

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

Diff for: compiler/rustc_typeck/src/astconv/generics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
613613
param_counts.consts + named_type_param_count
614614
- default_counts.types
615615
- default_counts.consts
616-
- synth_type_param_count
617616
};
618617
debug!("expected_min: {:?}", expected_min);
619618
debug!("arg_counts.lifetimes: {:?}", gen_args.num_lifetime_params());

Diff for: src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0107]: this function takes at most 1 generic argument but 2 generic arguments were supplied
1+
error[E0107]: this function takes 1 generic argument but 2 generic arguments were supplied
22
--> $DIR/explicit-generic-args-for-impl.rs:6:5
33
|
44
LL | foo::<str, String>("".to_string());
55
| ^^^ ------ help: remove this generic argument
66
| |
7-
| expected at most 1 generic argument
7+
| expected 1 generic argument
88
|
9-
note: function defined here, with at most 1 generic parameter: `T`
9+
note: function defined here, with 1 generic parameter: `T`
1010
--> $DIR/explicit-generic-args-for-impl.rs:3:4
1111
|
1212
LL | fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
3+
#![feature(explicit_generic_args_with_impl_trait)]
4+
5+
fn f<T: ?Sized>(_: impl AsRef<T>, _: impl AsRef<T>) {}
6+
7+
fn main() {
8+
f::<[u8]>("a", b"a");
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(explicit_generic_args_with_impl_trait)]
2+
3+
fn f<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}
4+
5+
fn main() {
6+
f::<[u8]>("a", b"a");
7+
//~^ ERROR: this function takes 2 generic arguments but 1 generic argument was supplied
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied
2+
--> $DIR/not-enough-args.rs:6:5
3+
|
4+
LL | f::<[u8]>("a", b"a");
5+
| ^ ---- supplied 1 generic argument
6+
| |
7+
| expected 2 generic arguments
8+
|
9+
note: function defined here, with 2 generic parameters: `T`, `U`
10+
--> $DIR/not-enough-args.rs:3:4
11+
|
12+
LL | fn f<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}
13+
| ^ - -
14+
help: add missing generic argument
15+
|
16+
LL | f::<[u8], U>("a", b"a");
17+
| ^^^
18+
19+
error: aborting due to previous error
20+
21+
For more information about this error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)