diff options
| author | bors <bors@rust-lang.org> | 2024-07-01 06:35:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-01 06:35:58 +0000 |
| commit | 7b21c18fe4de32a7d2faa468e6ef69abff013f85 (patch) | |
| tree | 038a7371e130281952f9c36b88d5e512c231fe54 /tests/ui/const-generics | |
| parent | f92a6c41e644d6222be77b20396daec5e77661f3 (diff) | |
| parent | bd111f5c4bbf3726ef0c9daf78c16c453bf5cb3d (diff) | |
| download | rust-7b21c18fe4de32a7d2faa468e6ef69abff013f85.tar.gz rust-7b21c18fe4de32a7d2faa468e6ef69abff013f85.zip | |
Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercote
Automatically taint InferCtxt when errors are emitted r? `@nnethercote` Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly. That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places. The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore. fixes #126485 (cc `@olafes)` There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
Diffstat (limited to 'tests/ui/const-generics')
14 files changed, 267 insertions, 79 deletions
diff --git a/tests/ui/const-generics/assoc_const_as_type_argument.rs b/tests/ui/const-generics/assoc_const_as_type_argument.rs index ffc7f116a94..bec6102417c 100644 --- a/tests/ui/const-generics/assoc_const_as_type_argument.rs +++ b/tests/ui/const-generics/assoc_const_as_type_argument.rs @@ -8,6 +8,7 @@ fn foo<T: Trait>() { bar::<<T as Trait>::ASSOC>(); //~^ ERROR: expected associated type, found associated constant `Trait::ASSOC` //~| ERROR: unresolved item provided when a constant was expected + //~| ERROR type annotations needed } fn main() {} diff --git a/tests/ui/const-generics/assoc_const_as_type_argument.stderr b/tests/ui/const-generics/assoc_const_as_type_argument.stderr index ac009546135..53edc19b28c 100644 --- a/tests/ui/const-generics/assoc_const_as_type_argument.stderr +++ b/tests/ui/const-generics/assoc_const_as_type_argument.stderr @@ -15,7 +15,19 @@ help: if this generic argument was intended as a const parameter, surround it wi LL | bar::<{ <T as Trait>::ASSOC }>(); | + + -error: aborting due to 2 previous errors +error[E0284]: type annotations needed + --> $DIR/assoc_const_as_type_argument.rs:8:5 + | +LL | bar::<<T as Trait>::ASSOC>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` + | +note: required by a const generic parameter in `bar` + --> $DIR/assoc_const_as_type_argument.rs:5:8 + | +LL | fn bar<const N: usize>() {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0575, E0747. -For more information about an error, try `rustc --explain E0575`. +Some errors have detailed explanations: E0284, E0575, E0747. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/const-arg-in-const-arg.min.stderr b/tests/ui/const-generics/const-arg-in-const-arg.min.stderr index ce7fce25993..2ea9d6b35b4 100644 --- a/tests/ui/const-generics/const-arg-in-const-arg.min.stderr +++ b/tests/ui/const-generics/const-arg-in-const-arg.min.stderr @@ -17,7 +17,7 @@ LL | let _: [u8; bar::<N>()]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:18:23 + --> $DIR/const-arg-in-const-arg.rs:19:23 | LL | let _: [u8; faz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -26,7 +26,7 @@ LL | let _: [u8; faz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:20:23 + --> $DIR/const-arg-in-const-arg.rs:21:23 | LL | let _: [u8; baz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -35,7 +35,7 @@ LL | let _: [u8; baz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:21:23 + --> $DIR/const-arg-in-const-arg.rs:22:23 | LL | let _: [u8; faz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -44,7 +44,7 @@ LL | let _: [u8; faz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:23:23 + --> $DIR/const-arg-in-const-arg.rs:24:23 | LL | let _: [u8; baz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -53,7 +53,7 @@ LL | let _: [u8; baz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:26:23 + --> $DIR/const-arg-in-const-arg.rs:27:23 | LL | let _ = [0; bar::<N>()]; | ^ cannot perform const operation using `N` @@ -62,7 +62,7 @@ LL | let _ = [0; bar::<N>()]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:28:23 + --> $DIR/const-arg-in-const-arg.rs:30:23 | LL | let _ = [0; faz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -71,7 +71,7 @@ LL | let _ = [0; faz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:30:23 + --> $DIR/const-arg-in-const-arg.rs:32:23 | LL | let _ = [0; baz::<'a>(&())]; | ^^ cannot perform const operation using `'a` @@ -80,7 +80,7 @@ LL | let _ = [0; baz::<'a>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:31:23 + --> $DIR/const-arg-in-const-arg.rs:33:23 | LL | let _ = [0; faz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -89,7 +89,7 @@ LL | let _ = [0; faz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:33:23 + --> $DIR/const-arg-in-const-arg.rs:35:23 | LL | let _ = [0; baz::<'b>(&())]; | ^^ cannot perform const operation using `'b` @@ -98,7 +98,7 @@ LL | let _ = [0; baz::<'b>(&())]; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:34:24 + --> $DIR/const-arg-in-const-arg.rs:36:24 | LL | let _: Foo<{ foo::<T>() }>; | ^ cannot perform const operation using `T` @@ -107,7 +107,7 @@ LL | let _: Foo<{ foo::<T>() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:35:24 + --> $DIR/const-arg-in-const-arg.rs:37:24 | LL | let _: Foo<{ bar::<N>() }>; | ^ cannot perform const operation using `N` @@ -116,7 +116,7 @@ LL | let _: Foo<{ bar::<N>() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:37:24 + --> $DIR/const-arg-in-const-arg.rs:40:24 | LL | let _: Foo<{ faz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -125,7 +125,7 @@ LL | let _: Foo<{ faz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:39:24 + --> $DIR/const-arg-in-const-arg.rs:42:24 | LL | let _: Foo<{ baz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -134,7 +134,7 @@ LL | let _: Foo<{ baz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:40:24 + --> $DIR/const-arg-in-const-arg.rs:43:24 | LL | let _: Foo<{ faz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -143,7 +143,7 @@ LL | let _: Foo<{ faz::<'b>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:42:24 + --> $DIR/const-arg-in-const-arg.rs:45:24 | LL | let _: Foo<{ baz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -152,7 +152,7 @@ LL | let _: Foo<{ baz::<'b>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:43:27 + --> $DIR/const-arg-in-const-arg.rs:46:27 | LL | let _ = Foo::<{ foo::<T>() }>; | ^ cannot perform const operation using `T` @@ -161,7 +161,7 @@ LL | let _ = Foo::<{ foo::<T>() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:44:27 + --> $DIR/const-arg-in-const-arg.rs:47:27 | LL | let _ = Foo::<{ bar::<N>() }>; | ^ cannot perform const operation using `N` @@ -170,7 +170,7 @@ LL | let _ = Foo::<{ bar::<N>() }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:46:27 + --> $DIR/const-arg-in-const-arg.rs:50:27 | LL | let _ = Foo::<{ faz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -179,7 +179,7 @@ LL | let _ = Foo::<{ faz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:48:27 + --> $DIR/const-arg-in-const-arg.rs:52:27 | LL | let _ = Foo::<{ baz::<'a>(&()) }>; | ^^ cannot perform const operation using `'a` @@ -188,7 +188,7 @@ LL | let _ = Foo::<{ baz::<'a>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:49:27 + --> $DIR/const-arg-in-const-arg.rs:53:27 | LL | let _ = Foo::<{ faz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -197,7 +197,7 @@ LL | let _ = Foo::<{ faz::<'b>(&()) }>; = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions error: generic parameters may not be used in const operations - --> $DIR/const-arg-in-const-arg.rs:51:27 + --> $DIR/const-arg-in-const-arg.rs:55:27 | LL | let _ = Foo::<{ baz::<'b>(&()) }>; | ^^ cannot perform const operation using `'b` @@ -216,8 +216,20 @@ help: if this generic argument was intended as a const parameter, surround it wi LL | let _: [u8; bar::<{ N }>()]; | + + +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:16:17 + | +LL | let _: [u8; bar::<N>()]; + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` + | +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 + | +LL | const fn bar<const N: usize>() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` + error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:18:23 + --> $DIR/const-arg-in-const-arg.rs:19:23 | LL | let _: [u8; faz::<'a>(&())]; | ^^ @@ -229,7 +241,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:21:23 + --> $DIR/const-arg-in-const-arg.rs:22:23 | LL | let _: [u8; faz::<'b>(&())]; | ^^ @@ -241,7 +253,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:35:24 + --> $DIR/const-arg-in-const-arg.rs:37:24 | LL | let _: Foo<{ bar::<N>() }>; | ^ @@ -251,8 +263,20 @@ help: if this generic argument was intended as a const parameter, surround it wi LL | let _: Foo<{ bar::<{ N }>() }>; | + + +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:37:18 + | +LL | let _: Foo<{ bar::<N>() }>; + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` + | +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 + | +LL | const fn bar<const N: usize>() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` + error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:37:24 + --> $DIR/const-arg-in-const-arg.rs:40:24 | LL | let _: Foo<{ faz::<'a>(&()) }>; | ^^ @@ -264,7 +288,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:40:24 + --> $DIR/const-arg-in-const-arg.rs:43:24 | LL | let _: Foo<{ faz::<'b>(&()) }>; | ^^ @@ -276,7 +300,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error: constant expression depends on a generic parameter - --> $DIR/const-arg-in-const-arg.rs:25:17 + --> $DIR/const-arg-in-const-arg.rs:26:17 | LL | let _ = [0; foo::<T>()]; | ^^^^^^^^^^ @@ -284,7 +308,7 @@ LL | let _ = [0; foo::<T>()]; = note: this may fail depending on what value the parameter takes error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:26:23 + --> $DIR/const-arg-in-const-arg.rs:27:23 | LL | let _ = [0; bar::<N>()]; | ^ @@ -294,8 +318,20 @@ help: if this generic argument was intended as a const parameter, surround it wi LL | let _ = [0; bar::<{ N }>()]; | + + +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:27:17 + | +LL | let _ = [0; bar::<N>()]; + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` + | +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 + | +LL | const fn bar<const N: usize>() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` + error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:28:23 + --> $DIR/const-arg-in-const-arg.rs:30:23 | LL | let _ = [0; faz::<'a>(&())]; | ^^ @@ -307,7 +343,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:31:23 + --> $DIR/const-arg-in-const-arg.rs:33:23 | LL | let _ = [0; faz::<'b>(&())]; | ^^ @@ -319,7 +355,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0747]: unresolved item provided when a constant was expected - --> $DIR/const-arg-in-const-arg.rs:44:27 + --> $DIR/const-arg-in-const-arg.rs:47:27 | LL | let _ = Foo::<{ bar::<N>() }>; | ^ @@ -329,8 +365,20 @@ help: if this generic argument was intended as a const parameter, surround it wi LL | let _ = Foo::<{ bar::<{ N }>() }>; | + + +error[E0284]: type annotations needed + --> $DIR/const-arg-in-const-arg.rs:47:21 + | +LL | let _ = Foo::<{ bar::<N>() }>; + | ^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `bar` + | +note: required by a const generic parameter in `bar` + --> $DIR/const-arg-in-const-arg.rs:9:14 + | +LL | const fn bar<const N: usize>() -> usize { N } + | ^^^^^^^^^^^^^^ required by this const generic parameter in `bar` + error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:46:27 + --> $DIR/const-arg-in-const-arg.rs:50:27 | LL | let _ = Foo::<{ faz::<'a>(&()) }>; | ^^ @@ -342,7 +390,7 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present - --> $DIR/const-arg-in-const-arg.rs:49:27 + --> $DIR/const-arg-in-const-arg.rs:53:27 | LL | let _ = Foo::<{ faz::<'b>(&()) }>; | ^^ @@ -353,7 +401,7 @@ note: the late bound lifetime parameter is introduced here LL | const fn faz<'a>(_: &'a ()) -> usize { 13 } | ^^ -error: aborting due to 36 previous errors +error: aborting due to 40 previous errors -Some errors have detailed explanations: E0747, E0794. -For more information about an error, try `rustc --explain E0747`. +Some errors have detailed explanations: E0284, E0747, E0794. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/const-arg-in-const-arg.rs b/tests/ui/const-generics/const-arg-in-const-arg.rs index 27b74489fe8..b95c63309f7 100644 --- a/tests/ui/const-generics/const-arg-in-const-arg.rs +++ b/tests/ui/const-generics/const-arg-in-const-arg.rs @@ -15,6 +15,7 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _: [u8; foo::<T>()]; //[min]~ ERROR generic parameters may not let _: [u8; bar::<N>()]; //[min]~ ERROR generic parameters may not //[min]~^ ERROR unresolved item provided when a constant was expected + //[min]~| ERROR type annotations needed let _: [u8; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _: [u8; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not @@ -25,6 +26,7 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _ = [0; foo::<T>()]; //[min]~ ERROR constant expression depends on a generic parameter let _ = [0; bar::<N>()]; //[min]~ ERROR generic parameters may not //[min]~^ ERROR unresolved item provided when a constant was expected + //[min]~| ERROR type annotations needed let _ = [0; faz::<'a>(&())]; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _ = [0; baz::<'a>(&())]; //[min]~ ERROR generic parameters may not @@ -34,6 +36,7 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _: Foo<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not let _: Foo<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not //[min]~^ ERROR unresolved item provided when a constant was expected + //[min]~| ERROR type annotations needed let _: Foo<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _: Foo<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not @@ -43,6 +46,7 @@ fn test<'a, 'b, T, const N: usize>() where &'b (): Sized { let _ = Foo::<{ foo::<T>() }>; //[min]~ ERROR generic parameters may not let _ = Foo::<{ bar::<N>() }>; //[min]~ ERROR generic parameters may not //[min]~^ ERROR unresolved item provided when a constant was expected + //[min]~| ERROR type annotations needed let _ = Foo::<{ faz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not //[min]~^ ERROR cannot specify lifetime arguments let _ = Foo::<{ baz::<'a>(&()) }>; //[min]~ ERROR generic parameters may not diff --git a/tests/ui/const-generics/generic_const_exprs/opaque_type.rs b/tests/ui/const-generics/generic_const_exprs/opaque_type.rs index 56b8acbf88c..7209290a36e 100644 --- a/tests/ui/const-generics/generic_const_exprs/opaque_type.rs +++ b/tests/ui/const-generics/generic_const_exprs/opaque_type.rs @@ -2,6 +2,7 @@ #![allow(incomplete_features)] type Foo = impl Sized; +//~^ ERROR: unconstrained opaque type fn with_bound<const N: usize>() -> Foo where diff --git a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr index e9fb8c0f403..c7a266205b4 100644 --- a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr +++ b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/opaque_type.rs:10:17 + --> $DIR/opaque_type.rs:11:17 | LL | type Foo = impl Sized; | ---------- the found opaque type @@ -11,12 +11,20 @@ LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize]; found opaque type `Foo` error[E0605]: non-primitive cast: `usize` as `Foo` - --> $DIR/opaque_type.rs:10:17 + --> $DIR/opaque_type.rs:11:17 | LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize]; | ^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object -error: aborting due to 2 previous errors +error: unconstrained opaque type + --> $DIR/opaque_type.rs:4:12 + | +LL | type Foo = impl Sized; + | ^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same module + +error: aborting due to 3 previous errors Some errors have detailed explanations: E0308, E0605. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/issues/issue-62878.min.stderr b/tests/ui/const-generics/issues/issue-62878.min.stderr index 5205726d738..3fd50bbe298 100644 --- a/tests/ui/const-generics/issues/issue-62878.min.stderr +++ b/tests/ui/const-generics/issues/issue-62878.min.stderr @@ -30,7 +30,31 @@ help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable LL + #![feature(generic_arg_infer)] | -error: aborting due to 3 previous errors +error[E0284]: type annotations needed + --> $DIR/issue-62878.rs:10:5 + | +LL | foo::<_, { [1] }>(); + | ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `foo` + | +note: required by a const generic parameter in `foo` + --> $DIR/issue-62878.rs:5:8 + | +LL | fn foo<const N: usize, const A: [u8; N]>() {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `foo` + +error[E0284]: type annotations needed + --> $DIR/issue-62878.rs:10:5 + | +LL | foo::<_, { [1] }>(); + | ^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `A` declared on the function `foo` + | +note: required by a const generic parameter in `foo` + --> $DIR/issue-62878.rs:5:24 + | +LL | fn foo<const N: usize, const A: [u8; N]>() {} + | ^^^^^^^^^^^^^^^^ required by this const generic parameter in `foo` + +error: aborting due to 5 previous errors -Some errors have detailed explanations: E0747, E0770. -For more information about an error, try `rustc --explain E0747`. +Some errors have detailed explanations: E0284, E0747, E0770. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/issues/issue-62878.rs b/tests/ui/const-generics/issues/issue-62878.rs index 0b5269df85e..c784e95edd8 100644 --- a/tests/ui/const-generics/issues/issue-62878.rs +++ b/tests/ui/const-generics/issues/issue-62878.rs @@ -9,4 +9,6 @@ fn foo<const N: usize, const A: [u8; N]>() {} fn main() { foo::<_, { [1] }>(); //[min]~^ ERROR: type provided when a constant was expected + //[min]~| ERROR type annotations needed + //[min]~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs b/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs index e12e07a28e7..497c020bde4 100644 --- a/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs +++ b/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.rs @@ -12,6 +12,7 @@ fn b() { //~^ ERROR expected trait, found constant `BAR` //~| ERROR expected trait, found constant `BAR` //~| ERROR type provided when a constant was expected + //~| ERROR type annotations needed } fn c() { foo::<3 + 3>(); //~ ERROR expressions must be enclosed in braces diff --git a/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr b/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr index d9bcc523b1f..c2ba517f609 100644 --- a/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr +++ b/tests/ui/const-generics/min_const_generics/const-expression-suggest-missing-braces.stderr @@ -10,7 +10,7 @@ LL | foo::<{ BAR + 3 }>(); | + + error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-suggest-missing-braces.rs:17:11 + --> $DIR/const-expression-suggest-missing-braces.rs:18:11 | LL | foo::<3 + 3>(); | ^^^^^ @@ -21,7 +21,7 @@ LL | foo::<{ 3 + 3 }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:20:15 + --> $DIR/const-expression-suggest-missing-braces.rs:21:15 | LL | foo::<BAR - 3>(); | ^ expected one of `,` or `>` @@ -32,7 +32,7 @@ LL | foo::<{ BAR - 3 }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:23:15 + --> $DIR/const-expression-suggest-missing-braces.rs:24:15 | LL | foo::<BAR - BAR>(); | ^ expected one of `,` or `>` @@ -43,7 +43,7 @@ LL | foo::<{ BAR - BAR }>(); | + + error: expressions must be enclosed in braces to be used as const generic arguments - --> $DIR/const-expression-suggest-missing-braces.rs:26:11 + --> $DIR/const-expression-suggest-missing-braces.rs:27:11 | LL | foo::<100 - BAR>(); | ^^^^^^^^^ @@ -54,7 +54,7 @@ LL | foo::<{ 100 - BAR }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:29:19 + --> $DIR/const-expression-suggest-missing-braces.rs:30:19 | LL | foo::<bar<i32>()>(); | ^ expected one of `,` or `>` @@ -65,7 +65,7 @@ LL | foo::<{ bar<i32>() }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:32:21 + --> $DIR/const-expression-suggest-missing-braces.rs:33:21 | LL | foo::<bar::<i32>()>(); | ^ expected one of `,` or `>` @@ -76,7 +76,7 @@ LL | foo::<{ bar::<i32>() }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:35:21 + --> $DIR/const-expression-suggest-missing-braces.rs:36:21 | LL | foo::<bar::<i32>() + BAR>(); | ^ expected one of `,` or `>` @@ -87,7 +87,7 @@ LL | foo::<{ bar::<i32>() + BAR }>(); | + + error: expected one of `,` or `>`, found `(` - --> $DIR/const-expression-suggest-missing-braces.rs:38:21 + --> $DIR/const-expression-suggest-missing-braces.rs:39:21 | LL | foo::<bar::<i32>() - BAR>(); | ^ expected one of `,` or `>` @@ -98,7 +98,7 @@ LL | foo::<{ bar::<i32>() - BAR }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:41:15 + --> $DIR/const-expression-suggest-missing-braces.rs:42:15 | LL | foo::<BAR - bar::<i32>()>(); | ^ expected one of `,` or `>` @@ -109,7 +109,7 @@ LL | foo::<{ BAR - bar::<i32>() }>(); | + + error: expected one of `,` or `>`, found `-` - --> $DIR/const-expression-suggest-missing-braces.rs:44:15 + --> $DIR/const-expression-suggest-missing-braces.rs:45:15 | LL | foo::<BAR - bar::<i32>()>(); | ^ expected one of `,` or `>` @@ -137,7 +137,19 @@ error[E0747]: type provided when a constant was expected LL | foo::<BAR + BAR>(); | ^^^^^^^^^ -error: aborting due to 14 previous errors +error[E0284]: type annotations needed + --> $DIR/const-expression-suggest-missing-braces.rs:11:5 + | +LL | foo::<BAR + BAR>(); + | ^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the function `foo` + | +note: required by a const generic parameter in `foo` + --> $DIR/const-expression-suggest-missing-braces.rs:1:8 + | +LL | fn foo<const C: usize>() {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `foo` + +error: aborting due to 15 previous errors -Some errors have detailed explanations: E0404, E0747. -For more information about an error, try `rustc --explain E0404`. +Some errors have detailed explanations: E0284, E0404, E0747. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/min_const_generics/macro-fail.rs b/tests/ui/const-generics/min_const_generics/macro-fail.rs index 2f101ecfb1f..25726490c2c 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail.rs +++ b/tests/ui/const-generics/min_const_generics/macro-fail.rs @@ -16,6 +16,7 @@ fn make_marker() -> impl Marker<gimme_a_const!(marker)> { //~| ERROR: type provided when a constant was expected Example::<gimme_a_const!(marker)> //~^ ERROR: type provided when a constant was expected + //~| ERROR type annotations needed } fn from_marker(_: impl Marker<{ @@ -35,9 +36,11 @@ fn main() { }>; let _fail = Example::<external_macro!()>; - //~^ ERROR: type provided when a constant was expected + //~^ ERROR: type provided when a constant + //~| ERROR type annotations needed let _fail = Example::<gimme_a_const!()>; //~^ ERROR unexpected end of macro invocation //~| ERROR: type provided when a constant was expected + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/min_const_generics/macro-fail.stderr b/tests/ui/const-generics/min_const_generics/macro-fail.stderr index 34764982bb0..4e183fe5b1c 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail.stderr +++ b/tests/ui/const-generics/min_const_generics/macro-fail.stderr @@ -1,5 +1,5 @@ error: expected type, found `{` - --> $DIR/macro-fail.rs:30:27 + --> $DIR/macro-fail.rs:31:27 | LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | ---------------------- @@ -13,7 +13,7 @@ LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} = note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected type, found `{` - --> $DIR/macro-fail.rs:30:27 + --> $DIR/macro-fail.rs:31:27 | LL | Example::<gimme_a_const!(marker)> | ---------------------- @@ -41,7 +41,7 @@ LL | let _fail = Example::<external_macro!()>; = note: this error originates in the macro `external_macro` (in Nightly builds, run with -Z macro-backtrace for more info) error: unexpected end of macro invocation - --> $DIR/macro-fail.rs:40:25 + --> $DIR/macro-fail.rs:42:25 | LL | macro_rules! gimme_a_const { | -------------------------- when calling this macro @@ -50,7 +50,7 @@ LL | let _fail = Example::<gimme_a_const!()>; | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments | note: while trying to match meta-variable `$rusty:ident` - --> $DIR/macro-fail.rs:30:8 + --> $DIR/macro-fail.rs:31:8 | LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} | ^^^^^^^^^^^^^ @@ -75,18 +75,63 @@ error[E0747]: type provided when a constant was expected LL | Example::<gimme_a_const!(marker)> | ^^^^^^^^^^^^^^^^^^^^^^ +error[E0284]: type annotations needed + --> $DIR/macro-fail.rs:17:3 + | +LL | Example::<gimme_a_const!(marker)> + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the struct `Example` + | +note: required by a const generic parameter in `Example` + --> $DIR/macro-fail.rs:1:16 + | +LL | struct Example<const N: usize>; + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Example` + error[E0747]: type provided when a constant was expected - --> $DIR/macro-fail.rs:37:25 + --> $DIR/macro-fail.rs:38:25 | LL | let _fail = Example::<external_macro!()>; | ^^^^^^^^^^^^^^^^^ error[E0747]: type provided when a constant was expected - --> $DIR/macro-fail.rs:40:25 + --> $DIR/macro-fail.rs:42:25 | LL | let _fail = Example::<gimme_a_const!()>; | ^^^^^^^^^^^^^^^^ -error: aborting due to 9 previous errors +error[E0284]: type annotations needed for `Example<_>` + --> $DIR/macro-fail.rs:38:7 + | +LL | let _fail = Example::<external_macro!()>; + | ^^^^^ ---------------------------- type must be known at this point + | +note: required by a const generic parameter in `Example` + --> $DIR/macro-fail.rs:1:16 + | +LL | struct Example<const N: usize>; + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Example` +help: consider giving `_fail` an explicit type, where the value of const parameter `N` is specified + | +LL | let _fail: Example<N> = Example::<external_macro!()>; + | ++++++++++++ + +error[E0284]: type annotations needed for `Example<_>` + --> $DIR/macro-fail.rs:42:7 + | +LL | let _fail = Example::<gimme_a_const!()>; + | ^^^^^ --------------------------- type must be known at this point + | +note: required by a const generic parameter in `Example` + --> $DIR/macro-fail.rs:1:16 + | +LL | struct Example<const N: usize>; + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Example` +help: consider giving `_fail` an explicit type, where the value of const parameter `N` is specified + | +LL | let _fail: Example<N> = Example::<gimme_a_const!()>; + | ++++++++++++ + +error: aborting due to 12 previous errors -For more information about this error, try `rustc --explain E0747`. +Some errors have detailed explanations: E0284, E0747. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/const-generics/suggest_const_for_array.rs b/tests/ui/const-generics/suggest_const_for_array.rs index f3e5a3186cd..4d29d069375 100644 --- a/tests/ui/const-generics/suggest_const_for_array.rs +++ b/tests/ui/const-generics/suggest_const_for_array.rs @@ -3,8 +3,10 @@ fn example<const N: usize>() {} fn other() { - example::<[usize; 3]>(); - //~^ ERROR type provided when a const - example::<[usize; 4+5]>(); - //~^ ERROR type provided when a const + example::<[usize; 3]>(); + //~^ ERROR type provided when a const + //~| ERROR type annotations needed + example::<[usize; 4 + 5]>(); + //~^ ERROR type provided when a const + //~| ERROR type annotations needed } diff --git a/tests/ui/const-generics/suggest_const_for_array.stderr b/tests/ui/const-generics/suggest_const_for_array.stderr index a617bf2bb0d..c867914070b 100644 --- a/tests/ui/const-generics/suggest_const_for_array.stderr +++ b/tests/ui/const-generics/suggest_const_for_array.stderr @@ -1,15 +1,40 @@ error[E0747]: type provided when a constant was expected - --> $DIR/suggest_const_for_array.rs:6:13 + --> $DIR/suggest_const_for_array.rs:6:15 | -LL | example::<[usize; 3]>(); - | ^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 3 }` +LL | example::<[usize; 3]>(); + | ^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 3 }` error[E0747]: type provided when a constant was expected - --> $DIR/suggest_const_for_array.rs:8:13 + --> $DIR/suggest_const_for_array.rs:9:15 | -LL | example::<[usize; 4+5]>(); - | ^^^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 4+5 }` +LL | example::<[usize; 4 + 5]>(); + | ^^^^^^^^^^^^^^ help: array type provided where a `usize` was expected, try: `{ 4 + 5 }` -error: aborting due to 2 previous errors +error[E0284]: type annotations needed + --> $DIR/suggest_const_for_array.rs:6:5 + | +LL | example::<[usize; 3]>(); + | ^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `example` + | +note: required by a const generic parameter in `example` + --> $DIR/suggest_const_for_array.rs:3:12 + | +LL | fn example<const N: usize>() {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `example` + +error[E0284]: type annotations needed + --> $DIR/suggest_const_for_array.rs:9:5 + | +LL | example::<[usize; 4 + 5]>(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the const parameter `N` declared on the function `example` + | +note: required by a const generic parameter in `example` + --> $DIR/suggest_const_for_array.rs:3:12 + | +LL | fn example<const N: usize>() {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `example` + +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0747`. +Some errors have detailed explanations: E0284, E0747. +For more information about an error, try `rustc --explain E0284`. |
