From 87790f1523bec5d6a0ca4def5e8e92ff1b036d00 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 13 Nov 2024 00:32:52 -0500 Subject: [PATCH] Add `min_generic_const_args` and gate new const path lowering with it --- compiler/rustc_ast_lowering/src/lib.rs | 12 ++- compiler/rustc_feature/src/unstable.rs | 2 + .../src/hir_ty_lowering/generics.rs | 10 +++ compiler/rustc_span/src/symbol.rs | 1 + .../non_valtreeable_const_arg-2.rs | 1 + .../non_valtreeable_const_arg-2.stderr | 22 ++++- .../bad-generic-in-copy-impl.rs | 5 +- .../bad-generic-in-copy-impl.stderr | 37 +++------ ...am-type-depends-on-const-param.full.stderr | 2 +- ...ram-type-depends-on-const-param.min.stderr | 28 ++++++- ...const-param-type-depends-on-const-param.rs | 2 + ...-const-param-infer.adt_const_params.stderr | 17 +++- .../fn-const-param-infer.full.stderr | 17 +++- .../fn-const-param-infer.min.stderr | 16 +++- .../ui/const-generics/fn-const-param-infer.rs | 2 +- .../generic_const_exprs/adt_wf_hang.rs | 2 +- .../generic_const_exprs/adt_wf_hang.stderr | 21 ++--- .../generic_const_exprs/error_in_ty.rs | 3 + .../generic_const_exprs/error_in_ty.stderr | 32 +++++++- .../type-alias-bounds.neg.stderr | 30 ++++--- .../generic_const_exprs/type-alias-bounds.rs | 1 + .../unevaluated-const-ice-119731.rs | 4 +- .../unevaluated-const-ice-119731.stderr | 28 +++---- tests/ui/const-generics/issue-97007.rs | 3 +- tests/ui/const-generics/issue-97007.stderr | 29 ------- .../issues/issue-62878.min.stderr | 16 +++- tests/ui/const-generics/issues/issue-62878.rs | 1 + .../issues/issue-71169.min.stderr | 14 +++- tests/ui/const-generics/issues/issue-71169.rs | 1 + .../const-generics/not_wf_param_in_rpitit.rs | 1 + .../not_wf_param_in_rpitit.stderr | 29 ++++++- tests/ui/const-generics/opaque_types2.rs | 2 +- tests/ui/const-generics/opaque_types2.stderr | 53 +++--------- .../using-static-as-const-arg.rs | 2 +- ...t-len-underflow-separate-spans.next.stderr | 6 ++ ...st-len-underflow-separate-spans.old.stderr | 6 ++ .../const-len-underflow-separate-spans.rs | 1 + tests/ui/consts/issue-39974.rs | 2 + tests/ui/consts/issue-39974.stderr | 8 +- .../refs_check_const_value_eq-issue-88876.rs | 2 +- tests/ui/issues/issue-27008.rs | 2 +- tests/ui/issues/issue-27008.stderr | 7 +- ...ce-hir-wf-check-anon-const-issue-122199.rs | 6 ++ ...ir-wf-check-anon-const-issue-122199.stderr | 80 ++++++++++++++++--- 44 files changed, 383 insertions(+), 183 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 012dce2dd8de2..835a1196bc86f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2063,8 +2063,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ty_id: NodeId, span: Span, ) -> &'hir hir::ConstArg<'hir> { + let tcx = self.tcx; + // FIXME(min_generic_const_args): we only allow one-segment const paths for now - let ct_kind = if path.is_potential_trivial_const_arg() { + let ct_kind = if path.is_potential_trivial_const_arg() + && (tcx.features().min_generic_const_args() + || matches!(res, Res::Def(DefKind::ConstParam, _))) + { let qpath = self.lower_qpath( ty_id, &None, @@ -2127,6 +2132,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { #[instrument(level = "debug", skip(self))] fn lower_anon_const_to_const_arg_direct(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> { + let tcx = self.tcx; // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments // currently have to be wrapped in curly brackets, so it's necessary to special-case. let expr = if let ExprKind::Block(block, _) = &anon.value.kind @@ -2138,9 +2144,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } else { &anon.value }; + let maybe_res = + self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res()); // FIXME(min_generic_const_args): we only allow one-segment const paths for now if let ExprKind::Path(None, path) = &expr.kind && path.is_potential_trivial_const_arg() + && (tcx.features().min_generic_const_args() + || matches!(maybe_res, Some(Res::Def(DefKind::ConstParam, _)))) { let qpath = self.lower_qpath( expr.id, diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 8326d0031ea60..a79bfeffc8444 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -529,6 +529,8 @@ declare_features! ( (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), + /// Enables the generic const args MVP (only bare paths, not arbitrary computation). + (incomplete, min_generic_const_args, "CURRENT_RUSTC_VERSION", Some(132980)), /// A minimal, sound subset of specialization intended to be used by the /// standard library until the soundness issues with specialization /// are fixed. diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index 05c1fb2c28905..ae1279d428c16 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -121,6 +121,16 @@ fn generic_arg_mismatch_err( { err.help(format!("`{}` is a function item, not a type", tcx.item_name(id))); err.help("function item types cannot be named directly"); + } else if let hir::ConstArgKind::Anon(anon) = cnst.kind + && let body = tcx.hir().body(anon.body) + && let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = + body.value.kind + && let Res::Def(DefKind::Fn { .. }, id) = path.res + { + // FIXME(min_generic_const_args): this branch is dead once new const path lowering + // (for single-segment paths) is no longer gated + err.help(format!("`{}` is a function item, not a type", tcx.item_name(id))); + err.help("function item types cannot be named directly"); } } _ => {} diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 42c6221dc573e..27da04b3a38bb 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1225,6 +1225,7 @@ symbols! { min_const_generics, min_const_unsafe_fn, min_exhaustive_patterns, + min_generic_const_args, min_specialization, min_type_alias_impl_trait, minnumf128, diff --git a/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.rs b/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.rs index 0912094cbadf0..6b87ad86d4bc2 100644 --- a/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.rs +++ b/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.rs @@ -15,4 +15,5 @@ impl Wrapper<{ bar() }> { fn main() { Wrapper::::call; + //~^ ERROR: the function or associated item `call` exists for struct `Wrapper`, } diff --git a/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.stderr b/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.stderr index 1e0122dc892f1..b13f76eabadbc 100644 --- a/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.stderr +++ b/tests/ui/const-generics/adt_const_params/non_valtreeable_const_arg-2.stderr @@ -15,7 +15,25 @@ error[E0741]: using function pointers as const generic parameters is forbidden LL | struct Wrapper; | ^^^^ -error: aborting due to 2 previous errors +error[E0599]: the function or associated item `call` exists for struct `Wrapper`, but its trait bounds were not satisfied + --> $DIR/non_valtreeable_const_arg-2.rs:17:26 + | +LL | struct Wrapper; + | ----------------------------- function or associated item `call` not found for this struct because it doesn't satisfy `Wrapper: Fn<_>` +... +LL | Wrapper::::call; + | ^^^^ function or associated item cannot be called on `Wrapper` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `Wrapper: Fn<_>` + which is required by `&Wrapper: Fn<_>` +note: the trait `Fn` must be implemented + --> $SRC_DIR/core/src/ops/function.rs:LL:COL + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `call`, perhaps you need to implement it: + candidate #1: `Fn` + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0425, E0741. +Some errors have detailed explanations: E0425, E0599, E0741. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/const-generics/bad-generic-in-copy-impl.rs b/tests/ui/const-generics/bad-generic-in-copy-impl.rs index 0d5e7c94d85ac..092a7af236bad 100644 --- a/tests/ui/const-generics/bad-generic-in-copy-impl.rs +++ b/tests/ui/const-generics/bad-generic-in-copy-impl.rs @@ -1,9 +1,8 @@ #[derive(Copy, Clone)] -//~^ ERROR the trait `Copy` cannot be implemented for this type pub struct Foo { x: [u8; SIZE], - //~^ ERROR the constant `1` is not of type `usize` - //~| ERROR the constant `1` is not of type `usize` + //~^ ERROR mismatched types + //~| ERROR mismatched types } const SIZE: u32 = 1; diff --git a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr index 0106f2fd70922..fbd546d42fb52 100644 --- a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr +++ b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr @@ -1,36 +1,17 @@ -error: the constant `1` is not of type `usize` - --> $DIR/bad-generic-in-copy-impl.rs:4:8 +error[E0308]: mismatched types + --> $DIR/bad-generic-in-copy-impl.rs:3:13 | LL | x: [u8; SIZE], - | ^^^^^^^^^^ expected `usize`, found `u32` + | ^^^^ expected `usize`, found `u32` -error[E0204]: the trait `Copy` cannot be implemented for this type - --> $DIR/bad-generic-in-copy-impl.rs:1:10 +error[E0308]: mismatched types + --> $DIR/bad-generic-in-copy-impl.rs:3:13 | -LL | #[derive(Copy, Clone)] - | ^^^^ -... LL | x: [u8; SIZE], - | ------------- this field does not implement `Copy` + | ^^^^ expected `usize`, found `u32` | -note: the `Copy` impl for `[u8; 1]` requires that `the constant `1` has type `usize`` - --> $DIR/bad-generic-in-copy-impl.rs:4:8 - | -LL | x: [u8; SIZE], - | ^^^^^^^^^^ - = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: the constant `1` is not of type `usize` - --> $DIR/bad-generic-in-copy-impl.rs:4:5 - | -LL | #[derive(Copy, Clone)] - | ----- in this derive macro expansion -... -LL | x: [u8; SIZE], - | ^^^^^^^^^^^^^ expected `usize`, found `u32` - | - = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0204`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/const-param-type-depends-on-const-param.full.stderr b/tests/ui/const-generics/const-param-type-depends-on-const-param.full.stderr index fe999f57254c4..539d840f0a803 100644 --- a/tests/ui/const-generics/const-param-type-depends-on-const-param.full.stderr +++ b/tests/ui/const-generics/const-param-type-depends-on-const-param.full.stderr @@ -7,7 +7,7 @@ LL | pub struct Dependent([(); N]); = note: const parameters may not be used in the type of const parameters error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/const-param-type-depends-on-const-param.rs:14:40 + --> $DIR/const-param-type-depends-on-const-param.rs:15:40 | LL | pub struct SelfDependent; | ^ the type must not depend on the parameter `N` diff --git a/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr b/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr index fe999f57254c4..18b8996326782 100644 --- a/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr +++ b/tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr @@ -7,13 +7,37 @@ LL | pub struct Dependent([(); N]); = note: const parameters may not be used in the type of const parameters error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/const-param-type-depends-on-const-param.rs:14:40 + --> $DIR/const-param-type-depends-on-const-param.rs:15:40 | LL | pub struct SelfDependent; | ^ the type must not depend on the parameter `N` | = note: const parameters may not be used in the type of const parameters -error: aborting due to 2 previous errors +error: `[u8; N]` is forbidden as the type of a const generic parameter + --> $DIR/const-param-type-depends-on-const-param.rs:11:47 + | +LL | pub struct Dependent([(); N]); + | ^^^^^^^ + | + = note: the only supported types are integers, `bool`, and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error: `[u8; N]` is forbidden as the type of a const generic parameter + --> $DIR/const-param-type-depends-on-const-param.rs:15:35 + | +LL | pub struct SelfDependent; + | ^^^^^^^ + | + = note: the only supported types are integers, `bool`, and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0770`. diff --git a/tests/ui/const-generics/const-param-type-depends-on-const-param.rs b/tests/ui/const-generics/const-param-type-depends-on-const-param.rs index 820d384aaa5a9..ee0e1326baa87 100644 --- a/tests/ui/const-generics/const-param-type-depends-on-const-param.rs +++ b/tests/ui/const-generics/const-param-type-depends-on-const-param.rs @@ -10,8 +10,10 @@ pub struct Dependent([(); N]); //~^ ERROR: the type of const parameters must not depend on other generic parameters +//[min]~^^ ERROR `[u8; N]` is forbidden pub struct SelfDependent; //~^ ERROR: the type of const parameters must not depend on other generic parameters +//[min]~^^ ERROR `[u8; N]` is forbidden fn main() {} diff --git a/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr b/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr index f5978d6ebc361..54f3bff172af6 100644 --- a/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.adt_const_params.stderr @@ -13,7 +13,18 @@ LL | let _ = Checked::<{ generic_arg:: }>; = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::}` -error: aborting due to 2 previous errors +error[E0282]: type annotations needed + --> $DIR/fn-const-param-infer.rs:35:23 + | +LL | let _ = Checked::; + | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` + | +help: consider specifying the generic argument + | +LL | let _ = Checked::>; + | +++++ + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0308, E0741. -For more information about an error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0282, E0308, E0741. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/fn-const-param-infer.full.stderr b/tests/ui/const-generics/fn-const-param-infer.full.stderr index f5978d6ebc361..54f3bff172af6 100644 --- a/tests/ui/const-generics/fn-const-param-infer.full.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.full.stderr @@ -13,7 +13,18 @@ LL | let _ = Checked::<{ generic_arg:: }>; = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::}` -error: aborting due to 2 previous errors +error[E0282]: type annotations needed + --> $DIR/fn-const-param-infer.rs:35:23 + | +LL | let _ = Checked::; + | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` + | +help: consider specifying the generic argument + | +LL | let _ = Checked::>; + | +++++ + +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0308, E0741. -For more information about an error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0282, E0308, E0741. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/fn-const-param-infer.min.stderr b/tests/ui/const-generics/fn-const-param-infer.min.stderr index f5da6af9383e4..5e08f71a26701 100644 --- a/tests/ui/const-generics/fn-const-param-infer.min.stderr +++ b/tests/ui/const-generics/fn-const-param-infer.min.stderr @@ -15,6 +15,18 @@ LL | let _ = Checked::<{ generic_arg:: }>; = note: expected fn pointer `fn(usize) -> _` found fn item `fn(u32) -> _ {generic_arg::}` -error: aborting due to 2 previous errors +error[E0282]: type annotations needed + --> $DIR/fn-const-param-infer.rs:35:23 + | +LL | let _ = Checked::; + | ^^^^^^^ cannot infer type of the type parameter `T` declared on the function `generic` + | +help: consider specifying the generic argument + | +LL | let _ = Checked::>; + | +++++ + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0282, E0308. +For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/const-generics/fn-const-param-infer.rs b/tests/ui/const-generics/fn-const-param-infer.rs index ea98b781b64d1..5f1958df26e05 100644 --- a/tests/ui/const-generics/fn-const-param-infer.rs +++ b/tests/ui/const-generics/fn-const-param-infer.rs @@ -32,7 +32,7 @@ fn main() { let _ = Checked::<{ generic_arg:: }>; let _ = Checked::<{ generic_arg:: }>; //~ ERROR: mismatched types - let _ = Checked::; + let _ = Checked::; //~ ERROR: type annotations needed let _ = Checked::<{ generic:: }>; let _: Checked<{ generic:: }> = Checked::<{ generic:: }>; let _: Checked<{ generic:: }> = Checked::<{ generic:: }>; diff --git a/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.rs b/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.rs index 3c62f6f6dbf3b..5d538d2679dd8 100644 --- a/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.rs +++ b/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.rs @@ -7,8 +7,8 @@ struct U; struct S() -//~^ ERROR: `U` must implement `ConstParamTy` to be used as the type of a const generic parameter where S<{ U }>:; +//~^ ERROR: overflow evaluating the requirement `S<{ U }> well-formed` fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.stderr b/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.stderr index ec711b4002dbb..b244acb37dde0 100644 --- a/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.stderr +++ b/tests/ui/const-generics/generic_const_exprs/adt_wf_hang.stderr @@ -1,15 +1,18 @@ -error[E0741]: `U` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/adt_wf_hang.rs:9:19 +error[E0275]: overflow evaluating the requirement `S<{ U }> well-formed` + --> $DIR/adt_wf_hang.rs:11:5 | -LL | struct S() - | ^ - | -help: add `#[derive(ConstParamTy)]` to the struct +LL | S<{ U }>:; + | ^^^^^^^^ | -LL + #[derive(ConstParamTy)] -LL | struct U; +note: required by a bound in `S` + --> $DIR/adt_wf_hang.rs:11:5 | +LL | struct S() + | - required by a bound in this struct +LL | where +LL | S<{ U }>:; + | ^^^^^^^^ required by this bound in `S` error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0741`. +For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs b/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs index 60cda101bc726..29ad935c0149c 100644 --- a/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs +++ b/tests/ui/const-generics/generic_const_exprs/error_in_ty.rs @@ -5,13 +5,16 @@ pub struct A {} //~^ ERROR: cannot find value `x` in this scope +//~| ERROR: `[usize; x]` is forbidden as the type of a const generic parameter impl A<2> { + //~^ ERROR: mismatched types pub const fn B() {} //~^ ERROR: duplicate definitions } impl A<2> { + //~^ ERROR: mismatched types pub const fn B() {} } diff --git a/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr b/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr index 41fec35f3fd7c..d822fa5894a5b 100644 --- a/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr +++ b/tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr @@ -6,8 +6,32 @@ LL | pub struct A {} | | | similarly named const parameter `z` defined here +error: `[usize; x]` is forbidden as the type of a const generic parameter + --> $DIR/error_in_ty.rs:6:23 + | +LL | pub struct A {} + | ^^^^^^^^^^ + | + = note: the only supported types are integers, `bool`, and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error[E0308]: mismatched types + --> $DIR/error_in_ty.rs:10:8 + | +LL | impl A<2> { + | ^ expected `[usize; x]`, found integer + +error[E0308]: mismatched types + --> $DIR/error_in_ty.rs:16:8 + | +LL | impl A<2> { + | ^ expected `[usize; x]`, found integer + error[E0592]: duplicate definitions with name `B` - --> $DIR/error_in_ty.rs:10:5 + --> $DIR/error_in_ty.rs:12:5 | LL | pub const fn B() {} | ^^^^^^^^^^^^^^^^ duplicate definitions for `B` @@ -15,7 +39,7 @@ LL | pub const fn B() {} LL | pub const fn B() {} | ---------------- other definition for `B` -error: aborting due to 2 previous errors +error: aborting due to 5 previous errors -Some errors have detailed explanations: E0425, E0592. -For more information about an error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0308, E0425, E0592. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr index 815cd5d714887..fa12dd14753f9 100644 --- a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr +++ b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr @@ -1,51 +1,63 @@ error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:30:12 + --> $DIR/type-alias-bounds.rs:23:12 + | +LL | let _: AliasConstUnused; + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound in `ct_unused_0::AliasConstUnused` + --> $DIR/type-alias-bounds.rs:20:30 + | +LL | type AliasConstUnused = (T, I32<{ DATA }>); + | ^^^^ required by this bound in `AliasConstUnused` + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/type-alias-bounds.rs:31:12 | LL | let _: AliasConstUnused; | ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `ct_unused_1::AliasConstUnused` - --> $DIR/type-alias-bounds.rs:28:41 + --> $DIR/type-alias-bounds.rs:29:41 | LL | type AliasConstUnused where String: Copy = I32<{ 0; 0 }>; | ^^^^ required by this bound in `AliasConstUnused` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:38:12 + --> $DIR/type-alias-bounds.rs:39:12 | LL | let _: AliasFnUnused; | ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `AliasFnUnused` - --> $DIR/type-alias-bounds.rs:35:27 + --> $DIR/type-alias-bounds.rs:36:27 | LL | type AliasFnUnused = (T, I32<{ code() }>); | ^^^^ required by this bound in `AliasFnUnused` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:56:12 + --> $DIR/type-alias-bounds.rs:57:12 | LL | let _: AliasAssocConstUsed; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `AliasAssocConstUsed` - --> $DIR/type-alias-bounds.rs:54:41 + --> $DIR/type-alias-bounds.rs:55:41 | LL | type AliasAssocConstUsed = I32<{ T::DATA }>; | ^^^^ required by this bound in `AliasAssocConstUsed` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:64:12 + --> $DIR/type-alias-bounds.rs:65:12 | LL | let _: AliasFnUsed; | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `AliasFnUsed` - --> $DIR/type-alias-bounds.rs:61:33 + --> $DIR/type-alias-bounds.rs:62:33 | LL | type AliasFnUsed = I32<{ code::() }>; | ^^^^ required by this bound in `AliasFnUsed` -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs index cdd7b08b26ca1..f16e646129c65 100644 --- a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs +++ b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs @@ -21,6 +21,7 @@ fn ct_unused_0() { const DATA: i32 = 0; #[cfg(neg)] let _: AliasConstUnused; + //[neg]~^ ERROR the trait bound `String: Copy` is not satisfied } fn ct_unused_1() { diff --git a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs index 4286e5ddc5549..a55be99fc0be5 100644 --- a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs +++ b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.rs @@ -9,8 +9,6 @@ mod v20 { pub type v11 = [[usize; v4]; v4]; //~^ WARN type `v11` should have an upper camel case name const v2: v11 = [[256; v4]; v4]; - //~^ ERROR maximum number of nodes exceeded in constant v20::v2 - //~| ERROR maximum number of nodes exceeded in constant v20::v2 const v0: [[usize; v4]; v4] = v6(v8); //~^ ERROR cannot find value `v8` in this scope @@ -28,6 +26,8 @@ mod v20 { } impl v17 { + //~^ ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} + //~| ERROR maximum number of nodes exceeded in constant v20::v17::::{constant#0} pub const fn v21() -> v18 { //~^ ERROR cannot find type `v18` in this scope v18 { _p: () } diff --git a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr index 22ef0f2dc8a82..30a45ce377e7e 100644 --- a/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr +++ b/tests/ui/const-generics/generic_const_exprs/unevaluated-const-ice-119731.stderr @@ -8,13 +8,13 @@ LL | pub use v20::{v13, v17}; | help: a similar name exists in the module: `v11` error[E0425]: cannot find value `v8` in this scope - --> $DIR/unevaluated-const-ice-119731.rs:15:38 + --> $DIR/unevaluated-const-ice-119731.rs:13:38 | LL | const v0: [[usize; v4]; v4] = v6(v8); | ^^ not found in this scope error[E0412]: cannot find type `v18` in this scope - --> $DIR/unevaluated-const-ice-119731.rs:25:31 + --> $DIR/unevaluated-const-ice-119731.rs:23:31 | LL | pub type v11 = [[usize; v4]; v4]; | --------------------------------- similarly named type alias `v11` defined here @@ -49,19 +49,19 @@ LL | pub type v11 = [[usize; v4]; v4]; = note: `#[warn(non_camel_case_types)]` on by default warning: type `v17` should have an upper camel case name - --> $DIR/unevaluated-const-ice-119731.rs:18:16 + --> $DIR/unevaluated-const-ice-119731.rs:16:16 | LL | pub struct v17 { | ^^^ help: convert the identifier to upper camel case (notice the capitalization): `V17` error[E0425]: cannot find function `v6` in this scope - --> $DIR/unevaluated-const-ice-119731.rs:15:35 + --> $DIR/unevaluated-const-ice-119731.rs:13:35 | LL | const v0: [[usize; v4]; v4] = v6(v8); | ^^ not found in this scope error: `[[usize; v4]; v4]` is forbidden as the type of a const generic parameter - --> $DIR/unevaluated-const-ice-119731.rs:18:48 + --> $DIR/unevaluated-const-ice-119731.rs:16:48 | LL | pub struct v17 { | ^^^ @@ -72,22 +72,22 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more LL + #![feature(adt_const_params)] | -error: maximum number of nodes exceeded in constant v20::v2 - --> $DIR/unevaluated-const-ice-119731.rs:11:5 +error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} + --> $DIR/unevaluated-const-ice-119731.rs:28:37 | -LL | const v2: v11 = [[256; v4]; v4]; - | ^^^^^^^^^^^^^ +LL | impl v17 { + | ^^ -error: maximum number of nodes exceeded in constant v20::v2 - --> $DIR/unevaluated-const-ice-119731.rs:11:5 +error: maximum number of nodes exceeded in constant v20::v17::::{constant#0} + --> $DIR/unevaluated-const-ice-119731.rs:28:37 | -LL | const v2: v11 = [[256; v4]; v4]; - | ^^^^^^^^^^^^^ +LL | impl v17 { + | ^^ | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0592]: duplicate definitions with name `v21` - --> $DIR/unevaluated-const-ice-119731.rs:25:9 + --> $DIR/unevaluated-const-ice-119731.rs:23:9 | LL | pub const fn v21() -> v18 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `v21` diff --git a/tests/ui/const-generics/issue-97007.rs b/tests/ui/const-generics/issue-97007.rs index 04b340e2b02c4..a099c423e6ddf 100644 --- a/tests/ui/const-generics/issue-97007.rs +++ b/tests/ui/const-generics/issue-97007.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(adt_const_params, generic_const_exprs)] #![allow(incomplete_features)] @@ -52,7 +54,6 @@ mod lib { pub fn proceed_to( self, ) -> Walk { - //~^ ERROR cycle detected when building an abstract representation for Walk { _p: () } } } diff --git a/tests/ui/const-generics/issue-97007.stderr b/tests/ui/const-generics/issue-97007.stderr index 135d2ff76f142..e69de29bb2d1d 100644 --- a/tests/ui/const-generics/issue-97007.stderr +++ b/tests/ui/const-generics/issue-97007.stderr @@ -1,29 +0,0 @@ -error[E0391]: cycle detected when building an abstract representation for `lib::::proceed_to::{constant#0}` - --> $DIR/issue-97007.rs:54:25 - | -LL | ) -> Walk { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: ...which requires building THIR for `lib::::proceed_to::{constant#0}`... - --> $DIR/issue-97007.rs:54:25 - | -LL | ) -> Walk { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires type-checking `lib::::proceed_to::{constant#0}`... - --> $DIR/issue-97007.rs:54:25 - | -LL | ) -> Walk { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires building an abstract representation for `lib::::proceed_to::{constant#0}`, completing the cycle -note: cycle used when checking that `lib::::proceed_to` is well-formed - --> $DIR/issue-97007.rs:52:9 - | -LL | / pub fn proceed_to( -LL | | self, -LL | | ) -> Walk { - | |___________________________________________________________^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/const-generics/issues/issue-62878.min.stderr b/tests/ui/const-generics/issues/issue-62878.min.stderr index cbd124af45952..bd17d70a50ba5 100644 --- a/tests/ui/const-generics/issues/issue-62878.min.stderr +++ b/tests/ui/const-generics/issues/issue-62878.min.stderr @@ -6,8 +6,20 @@ LL | fn foo() {} | = note: const parameters may not be used in the type of const parameters +error: `[u8; N]` is forbidden as the type of a const generic parameter + --> $DIR/issue-62878.rs:5:33 + | +LL | fn foo() {} + | ^^^^^^^ + | + = note: the only supported types are integers, `bool`, and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + error[E0747]: type provided when a constant was expected - --> $DIR/issue-62878.rs:9:11 + --> $DIR/issue-62878.rs:10:11 | LL | foo::<_, { [1] }>(); | ^ @@ -18,7 +30,7 @@ help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable LL + #![feature(generic_arg_infer)] | -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0747, E0770. For more information about an error, try `rustc --explain E0747`. diff --git a/tests/ui/const-generics/issues/issue-62878.rs b/tests/ui/const-generics/issues/issue-62878.rs index 6e22ef732eb84..0b5269df85ee1 100644 --- a/tests/ui/const-generics/issues/issue-62878.rs +++ b/tests/ui/const-generics/issues/issue-62878.rs @@ -4,6 +4,7 @@ fn foo() {} //~^ ERROR the type of const parameters must not +//[min]~| ERROR `[u8; N]` is forbidden as the type of a const generic parameter fn main() { foo::<_, { [1] }>(); diff --git a/tests/ui/const-generics/issues/issue-71169.min.stderr b/tests/ui/const-generics/issues/issue-71169.min.stderr index 9553be6fc07c7..2ecbc3379516b 100644 --- a/tests/ui/const-generics/issues/issue-71169.min.stderr +++ b/tests/ui/const-generics/issues/issue-71169.min.stderr @@ -6,6 +6,18 @@ LL | fn foo() {} | = note: const parameters may not be used in the type of const parameters -error: aborting due to 1 previous error +error: `[u8; LEN]` is forbidden as the type of a const generic parameter + --> $DIR/issue-71169.rs:5:38 + | +LL | fn foo() {} + | ^^^^^^^^^ + | + = note: the only supported types are integers, `bool`, and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0770`. diff --git a/tests/ui/const-generics/issues/issue-71169.rs b/tests/ui/const-generics/issues/issue-71169.rs index eb7f0a5a6b8ce..fdac0974d3476 100644 --- a/tests/ui/const-generics/issues/issue-71169.rs +++ b/tests/ui/const-generics/issues/issue-71169.rs @@ -4,6 +4,7 @@ fn foo() {} //~^ ERROR the type of const parameters must not +//[min]~^^ ERROR `[u8; LEN]` is forbidden as the type of a const generic parameter fn main() { const DATA: [u8; 4] = *b"ABCD"; foo::<4, DATA>(); diff --git a/tests/ui/const-generics/not_wf_param_in_rpitit.rs b/tests/ui/const-generics/not_wf_param_in_rpitit.rs index ce2b8f0026404..b454562ad497a 100644 --- a/tests/ui/const-generics/not_wf_param_in_rpitit.rs +++ b/tests/ui/const-generics/not_wf_param_in_rpitit.rs @@ -5,6 +5,7 @@ trait Trait { //~| ERROR: cycle detected when computing type of `Trait::N` //~| ERROR: the trait `Trait` cannot be made into an object //~| ERROR: the trait `Trait` cannot be made into an object + //~| ERROR: the trait `Trait` cannot be made into an object async fn a() {} } diff --git a/tests/ui/const-generics/not_wf_param_in_rpitit.stderr b/tests/ui/const-generics/not_wf_param_in_rpitit.stderr index a12fd6b5a5ef9..2500409e82858 100644 --- a/tests/ui/const-generics/not_wf_param_in_rpitit.stderr +++ b/tests/ui/const-generics/not_wf_param_in_rpitit.stderr @@ -18,6 +18,29 @@ LL | trait Trait { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +error[E0038]: the trait `Trait` cannot be made into an object + --> $DIR/not_wf_param_in_rpitit.rs:3:22 + | +LL | trait Trait { + | ^^^^^^^^^ `Trait` cannot be made into an object + | +note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/not_wf_param_in_rpitit.rs:9:14 + | +LL | trait Trait { + | ----- this trait cannot be made into an object... +... +LL | async fn a() {} + | ^ ...because associated function `a` has no `self` parameter +help: consider turning `a` into a method by giving it a `&self` argument + | +LL | async fn a(&self) {} + | +++++ +help: alternatively, consider constraining `a` so it does not apply to trait objects + | +LL | async fn a() where Self: Sized {} + | +++++++++++++++++ + error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/not_wf_param_in_rpitit.rs:3:13 | @@ -25,7 +48,7 @@ LL | trait Trait { | ^^^^^^^^^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/not_wf_param_in_rpitit.rs:8:14 + --> $DIR/not_wf_param_in_rpitit.rs:9:14 | LL | trait Trait { | ----- this trait cannot be made into an object... @@ -48,7 +71,7 @@ LL | trait Trait { | ^^^^^^^^^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/not_wf_param_in_rpitit.rs:8:14 + --> $DIR/not_wf_param_in_rpitit.rs:9:14 | LL | trait Trait { | ----- this trait cannot be made into an object... @@ -65,7 +88,7 @@ help: alternatively, consider constraining `a` so it does not apply to trait obj LL | async fn a() where Self: Sized {} | +++++++++++++++++ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0038, E0391, E0425. For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/const-generics/opaque_types2.rs b/tests/ui/const-generics/opaque_types2.rs index 552fc2653e027..fd57438bb6171 100644 --- a/tests/ui/const-generics/opaque_types2.rs +++ b/tests/ui/const-generics/opaque_types2.rs @@ -1,7 +1,6 @@ #![feature(type_alias_impl_trait)] type Foo = impl Sized; -//~^ ERROR: cycle detected when computing type of `Foo::{opaque#0}` fn foo() {} @@ -12,6 +11,7 @@ where Foo:, { foo::(); + //~^ ERROR: mismatched types } fn main() {} diff --git a/tests/ui/const-generics/opaque_types2.stderr b/tests/ui/const-generics/opaque_types2.stderr index e4a44aa849ece..2fb1669b7bfab 100644 --- a/tests/ui/const-generics/opaque_types2.stderr +++ b/tests/ui/const-generics/opaque_types2.stderr @@ -1,50 +1,15 @@ -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` - --> $DIR/opaque_types2.rs:3:12 +error[E0308]: mismatched types + --> $DIR/opaque_types2.rs:13:11 | LL | type Foo = impl Sized; - | ^^^^^^^^^^ + | ---------- the found opaque type +... +LL | foo::(); + | ^ expected `u32`, found opaque type | -note: ...which requires computing type of opaque `Foo::{opaque#0}`... - --> $DIR/opaque_types2.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ -note: ...which requires type-checking `bar`... - --> $DIR/opaque_types2.rs:10:1 - | -LL | / fn bar() -LL | | where -LL | | Foo:, - | |_________^ -note: ...which requires evaluating type-level constant... - --> $DIR/opaque_types2.rs:8:1 - | -LL | const C: Foo = 42; - | ^^^^^^^^^^^^ -note: ...which requires const-evaluating + checking `C`... - --> $DIR/opaque_types2.rs:8:1 - | -LL | const C: Foo = 42; - | ^^^^^^^^^^^^ -note: ...which requires caching mir of `C` for CTFE... - --> $DIR/opaque_types2.rs:8:1 - | -LL | const C: Foo = 42; - | ^^^^^^^^^^^^ -note: ...which requires elaborating drops for `C`... - --> $DIR/opaque_types2.rs:8:1 - | -LL | const C: Foo = 42; - | ^^^^^^^^^^^^ - = note: ...which requires normalizing `Foo`... - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking that `Foo::{opaque#0}` is well-formed - --> $DIR/opaque_types2.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + = note: expected type `u32` + found opaque type `Foo` error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/using-static-as-const-arg.rs b/tests/ui/const-generics/using-static-as-const-arg.rs index a58a2c4bbfba6..2e8a2a1448461 100644 --- a/tests/ui/const-generics/using-static-as-const-arg.rs +++ b/tests/ui/const-generics/using-static-as-const-arg.rs @@ -1,4 +1,4 @@ -// check-pass +//@ check-pass pub static STATIC: u32 = 0; pub struct Foo; diff --git a/tests/ui/consts/const-len-underflow-separate-spans.next.stderr b/tests/ui/consts/const-len-underflow-separate-spans.next.stderr index 59fb30400dc0b..bd2a81f514830 100644 --- a/tests/ui/consts/const-len-underflow-separate-spans.next.stderr +++ b/tests/ui/consts/const-len-underflow-separate-spans.next.stderr @@ -4,6 +4,12 @@ error[E0080]: evaluation of constant value failed LL | const LEN: usize = ONE - TWO; | ^^^^^^^^^ attempt to compute `1_usize - 2_usize`, which would overflow +note: erroneous constant encountered + --> $DIR/const-len-underflow-separate-spans.rs:14:17 + | +LL | let a: [i8; LEN] = unimplemented!(); + | ^^^ + error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-len-underflow-separate-spans.old.stderr b/tests/ui/consts/const-len-underflow-separate-spans.old.stderr index 59fb30400dc0b..bd2a81f514830 100644 --- a/tests/ui/consts/const-len-underflow-separate-spans.old.stderr +++ b/tests/ui/consts/const-len-underflow-separate-spans.old.stderr @@ -4,6 +4,12 @@ error[E0080]: evaluation of constant value failed LL | const LEN: usize = ONE - TWO; | ^^^^^^^^^ attempt to compute `1_usize - 2_usize`, which would overflow +note: erroneous constant encountered + --> $DIR/const-len-underflow-separate-spans.rs:14:17 + | +LL | let a: [i8; LEN] = unimplemented!(); + | ^^^ + error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-len-underflow-separate-spans.rs b/tests/ui/consts/const-len-underflow-separate-spans.rs index 030ea19182f5a..42314eed7aad6 100644 --- a/tests/ui/consts/const-len-underflow-separate-spans.rs +++ b/tests/ui/consts/const-len-underflow-separate-spans.rs @@ -12,4 +12,5 @@ const LEN: usize = ONE - TWO; fn main() { let a: [i8; LEN] = unimplemented!(); +//~^ constant } diff --git a/tests/ui/consts/issue-39974.rs b/tests/ui/consts/issue-39974.rs index 28e9f295e4ce3..9cb180014b86b 100644 --- a/tests/ui/consts/issue-39974.rs +++ b/tests/ui/consts/issue-39974.rs @@ -3,6 +3,8 @@ const LENGTH: f64 = 2; struct Thing { f: [[f64; 2]; LENGTH], + //~^ ERROR mismatched types + //~| expected `usize`, found `f64` } fn main() { diff --git a/tests/ui/consts/issue-39974.stderr b/tests/ui/consts/issue-39974.stderr index 928c2e33ad4b1..a371ea5709e1b 100644 --- a/tests/ui/consts/issue-39974.stderr +++ b/tests/ui/consts/issue-39974.stderr @@ -9,6 +9,12 @@ help: use a float literal LL | const LENGTH: f64 = 2.0; | ++ -error: aborting due to 1 previous error +error[E0308]: mismatched types + --> $DIR/issue-39974.rs:5:19 + | +LL | f: [[f64; 2]; LENGTH], + | ^^^^^^ expected `usize`, found `f64` + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs b/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs index d2ae6576617b8..33b6b7f52ca10 100644 --- a/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs +++ b/tests/ui/consts/refs_check_const_value_eq-issue-88876.rs @@ -3,7 +3,7 @@ #![allow(incomplete_features)] #![feature(adt_const_params, unsized_const_params)] -struct FooConst {} +struct FooConst {} const FOO_ARR: &[&'static str; 2] = &["Hello", "Friend"]; diff --git a/tests/ui/issues/issue-27008.rs b/tests/ui/issues/issue-27008.rs index 40a81cd80be66..adf8e779e0a04 100644 --- a/tests/ui/issues/issue-27008.rs +++ b/tests/ui/issues/issue-27008.rs @@ -2,6 +2,6 @@ struct S; fn main() { let b = [0; S]; - //~^ ERROR the constant `S` is not of type `usize` + //~^ ERROR mismatched types //~| expected `usize`, found `S` } diff --git a/tests/ui/issues/issue-27008.stderr b/tests/ui/issues/issue-27008.stderr index 0cde45a5c75f2..b4bfaa2786332 100644 --- a/tests/ui/issues/issue-27008.stderr +++ b/tests/ui/issues/issue-27008.stderr @@ -1,8 +1,9 @@ -error: the constant `S` is not of type `usize` - --> $DIR/issue-27008.rs:4:13 +error[E0308]: mismatched types + --> $DIR/issue-27008.rs:4:17 | LL | let b = [0; S]; - | ^^^^^^ expected `usize`, found `S` + | ^ expected `usize`, found `S` error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs index f41fb3e0443f7..53363319ba0e6 100644 --- a/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs +++ b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.rs @@ -3,6 +3,9 @@ trait Trait { //~| ERROR cycle detected when computing type of `Trait::N` //~| ERROR the trait `Trait` cannot be made into an object //~| ERROR the trait `Trait` cannot be made into an object + //~| ERROR the trait `Trait` cannot be made into an object + //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] + //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! fn fnc(&self) -> Trait { @@ -10,6 +13,9 @@ trait Trait { //~| ERROR expected value, found builtin type `u32` //~| ERROR defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~| ERROR associated item referring to unboxed trait object for its own trait + //~| ERROR the trait `Trait` cannot be made into an object + //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] + //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] diff --git a/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr index 0d9c0d0775b57..fefb788fac79c 100644 --- a/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr +++ b/tests/ui/wf/ice-hir-wf-check-anon-const-issue-122199.stderr @@ -1,5 +1,5 @@ error[E0403]: the name `N` is already used for a generic parameter in this item's generic parameters - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:18 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:18 | LL | trait Trait { | - first use of `N` @@ -14,13 +14,13 @@ LL | trait Trait { | ^^^ not found in this scope error[E0423]: expected value, found builtin type `u32` - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:29 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:29 | LL | fn fnc(&self) -> Trait { | ^^^ not a value error[E0425]: cannot find value `bar` in this scope - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:17:9 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:23:9 | LL | bar | ^^^ not found in this scope @@ -54,13 +54,13 @@ LL | trait Trait { = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:12 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:12 | LL | fn fnc(&self) -> Trait { | ^^^^^^^^^^^^^^^^^^^^ warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:21 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:21 | LL | fn fnc(&self) -> Trait { | ^^^^^ @@ -73,7 +73,7 @@ LL | fn fnc(&self) -> Trait { | +++ warning: trait objects without an explicit `dyn` are deprecated - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:44 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:44 | LL | fn fnc(&self) -> Trait { | ^^^^^ @@ -85,6 +85,36 @@ help: if this is a dyn-compatible trait, use `dyn` LL | fn fnc(&self) -> dyn Trait { | +++ +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:22 + | +LL | trait Trait { + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: if this is a dyn-compatible trait, use `dyn` + | +LL | trait Trait { + | +++ + +error[E0038]: the trait `Trait` cannot be made into an object + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:22 + | +LL | trait Trait { + | ^^^^^ `Trait` cannot be made into an object + | +note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:8 + | +LL | trait Trait { + | ----- this trait cannot be made into an object... +... +LL | fn fnc(&self) -> Trait { + | ^^^ ...because method `fnc` has generic type parameters + = help: consider moving `fnc` to another trait + error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:13 | @@ -92,7 +122,7 @@ LL | trait Trait { | ^^^^^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:8 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:8 | LL | trait Trait { | ----- this trait cannot be made into an object... @@ -102,7 +132,7 @@ LL | fn fnc(&self) -> Trait { = help: consider moving `fnc` to another trait error: associated item referring to unboxed trait object for its own trait - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:44 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:44 | LL | trait Trait { | ----- in this trait @@ -115,6 +145,36 @@ help: you might have meant to use `Self` to refer to the implementing type LL | fn fnc(&self) -> Self { | ~~~~ +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:21 + | +LL | fn fnc(&self) -> Trait { + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +help: if this is a dyn-compatible trait, use `dyn` + | +LL | fn fnc(&self) -> Trait { + | +++ + +error[E0038]: the trait `Trait` cannot be made into an object + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:21 + | +LL | fn fnc(&self) -> Trait { + | ^^^^^ `Trait` cannot be made into an object + | +note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:8 + | +LL | trait Trait { + | ----- this trait cannot be made into an object... +... +LL | fn fnc(&self) -> Trait { + | ^^^ ...because method `fnc` has generic type parameters + = help: consider moving `fnc` to another trait + error[E0038]: the trait `Trait` cannot be made into an object --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:1:13 | @@ -122,7 +182,7 @@ LL | trait Trait { | ^^^^^^^^^^^^^^^^^^^^ `Trait` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit - --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:8:8 + --> $DIR/ice-hir-wf-check-anon-const-issue-122199.rs:11:8 | LL | trait Trait { | ----- this trait cannot be made into an object... @@ -132,7 +192,7 @@ LL | fn fnc(&self) -> Trait { = help: consider moving `fnc` to another trait = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 9 previous errors; 3 warnings emitted +error: aborting due to 11 previous errors; 5 warnings emitted Some errors have detailed explanations: E0038, E0391, E0403, E0423, E0425. For more information about an error, try `rustc --explain E0038`.