Skip to content

Commit

Permalink
Rollup merge of rust-lang#87727 - SkiFire13:fix-87718, r=jackh726
Browse files Browse the repository at this point in the history
explicit_generic_args_with_impl_trait: fix min expected number of generics

Fixes rust-lang#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.
  • Loading branch information
JohnTitor authored Aug 6, 2021
2 parents f13c61d + e3389be commit 928c719
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
param_counts.consts + named_type_param_count
- default_counts.types
- default_counts.consts
- synth_type_param_count
};
debug!("expected_min: {:?}", expected_min);
debug!("arg_counts.lifetimes: {:?}", gen_args.num_lifetime_params());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0107]: this function takes at most 1 generic argument but 2 generic arguments were supplied
error[E0107]: this function takes 1 generic argument but 2 generic arguments were supplied
--> $DIR/explicit-generic-args-for-impl.rs:6:5
|
LL | foo::<str, String>("".to_string());
| ^^^ ------ help: remove this generic argument
| |
| expected at most 1 generic argument
| expected 1 generic argument
|
note: function defined here, with at most 1 generic parameter: `T`
note: function defined here, with 1 generic parameter: `T`
--> $DIR/explicit-generic-args-for-impl.rs:3:4
|
LL | fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// check-pass

#![feature(explicit_generic_args_with_impl_trait)]

fn f<T: ?Sized>(_: impl AsRef<T>, _: impl AsRef<T>) {}

fn main() {
f::<[u8]>("a", b"a");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(explicit_generic_args_with_impl_trait)]

fn f<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}

fn main() {
f::<[u8]>("a", b"a");
//~^ ERROR: this function takes 2 generic arguments but 1 generic argument was supplied
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied
--> $DIR/not-enough-args.rs:6:5
|
LL | f::<[u8]>("a", b"a");
| ^ ---- supplied 1 generic argument
| |
| expected 2 generic arguments
|
note: function defined here, with 2 generic parameters: `T`, `U`
--> $DIR/not-enough-args.rs:3:4
|
LL | fn f<T: ?Sized, U: ?Sized>(_: impl AsRef<T>, _: impl AsRef<U>) {}
| ^ - -
help: add missing generic argument
|
LL | f::<[u8], U>("a", b"a");
| ^^^

error: aborting due to previous error

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

0 comments on commit 928c719

Please sign in to comment.