From 0801263279bbd44b7dbe88d5039a6b810a037f3b Mon Sep 17 00:00:00 2001 From: varkor Date: Fri, 2 Oct 2020 01:39:04 +0100 Subject: [PATCH] Fix missing diagnostic span for `impl Trait` with const generics --- compiler/rustc_typeck/src/astconv/generics.rs | 2 +- .../impl-trait-with-const-arguments.rs | 22 +++++++++++++++++++ .../impl-trait-with-const-arguments.stderr | 8 +++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.rs create mode 100644 src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.stderr diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index b54de1d091608..b867798c76cf7 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -562,7 +562,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .args .iter() .filter_map(|arg| match arg { - GenericArg::Type(_) => Some(arg.span()), + GenericArg::Type(_) | GenericArg::Const(_) => Some(arg.span()), _ => None, }) .collect::>(); diff --git a/src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.rs b/src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.rs new file mode 100644 index 0000000000000..97ae3b838a391 --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.rs @@ -0,0 +1,22 @@ +#![feature(min_const_generics)] + +trait Usizer { + fn m(self) -> usize; +} + +fn f(u: impl Usizer) -> usize { + N + u.m() +} + +struct Usizable; + +impl Usizer for Usizable { + fn m(self) -> usize { + 16 + } +} + +fn main() { + assert_eq!(f::<4usize>(Usizable), 20usize); +//~^ ERROR cannot provide explicit generic arguments when `impl Trait` is used in argument position +} diff --git a/src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.stderr b/src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.stderr new file mode 100644 index 0000000000000..0a6d350986368 --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/impl-trait-with-const-arguments.stderr @@ -0,0 +1,8 @@ +error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position + --> $DIR/impl-trait-with-const-arguments.rs:20:20 + | +LL | assert_eq!(f::<4usize>(Usizable), 20usize); + | ^^^^^^ explicit generic argument not allowed + +error: aborting due to previous error +