From 2fd874d0d5ec1618e488d0d10b8b67553aeaaf1e Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Tue, 3 Aug 2021 13:18:06 +0200 Subject: [PATCH 1/3] Fix overflow when calculating expected_min in generics diagnostics --- compiler/rustc_typeck/src/astconv/generics.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 9e700d9e8d8ba..64a6049ec5228 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -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()); From ae313da4ba50aa5f9edcdc647812da6489ffefd2 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Tue, 3 Aug 2021 13:38:48 +0200 Subject: [PATCH 2/3] Add regression tests --- .../issue-87718.rs | 9 ++++++++ .../not-enough-args.rs | 8 +++++++ .../not-enough-args.stderr | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs create mode 100644 src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs create mode 100644 src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs new file mode 100644 index 0000000000000..e2ee63821ae74 --- /dev/null +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs @@ -0,0 +1,9 @@ +// check-pass + +#![feature(explicit_generic_args_with_impl_trait)] + +fn f(_: impl AsRef, _: impl AsRef) {} + +fn main() { + f::<[u8]>("a", b"a"); +} diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs new file mode 100644 index 0000000000000..ffb0582fe8df4 --- /dev/null +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.rs @@ -0,0 +1,8 @@ +#![feature(explicit_generic_args_with_impl_trait)] + +fn f(_: impl AsRef, _: impl AsRef) {} + +fn main() { + f::<[u8]>("a", b"a"); + //~^ ERROR: this function takes 2 generic arguments but 1 generic argument was supplied +} diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr new file mode 100644 index 0000000000000..233b47445db02 --- /dev/null +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/not-enough-args.stderr @@ -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(_: impl AsRef, _: impl AsRef) {} + | ^ - - +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`. From e3389befe1655875ab2bfd83a9c44e507ec0ee5f Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Tue, 3 Aug 2021 14:04:50 +0200 Subject: [PATCH 3/3] Bless test --- .../explicit-generic-args-for-impl.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr index 739e55e294381..3add0429d2d58 100644 --- a/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr +++ b/src/test/ui/impl-trait/explicit-generic-args-with-impl-trait/explicit-generic-args-for-impl.stderr @@ -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::("".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(_f: impl AsRef) {}