From 05a50c5889e138f5f4b979010f4c94ce25c73943 Mon Sep 17 00:00:00 2001 From: Ben Lewis Date: Sun, 19 Jan 2020 11:37:48 +1300 Subject: [PATCH 1/2] Disallow generic type parameters from appearing within certain constants. Previously using generic type parameters within array length expressions/enum discriminants caused ICE's or confusing diagnostics. --- src/librustc_error_codes/error_codes.rs | 1 + src/librustc_error_codes/error_codes/E0747.md | 58 ++++++++++++ src/librustc_resolve/diagnostics.rs | 11 +++ src/librustc_resolve/late.rs | 92 +++++++++++++++---- src/librustc_resolve/lib.rs | 57 +++++++++++- ...ssociated-const-type-parameter-arrays-2.rs | 2 +- ...iated-const-type-parameter-arrays-2.stderr | 13 +-- .../associated-const-type-parameter-arrays.rs | 2 +- ...ociated-const-type-parameter-arrays.stderr | 13 +-- .../ui/consts/const-type-parameter-self.rs | 15 +++ src/test/ui/consts/const-type-parameter.rs | 32 +++++++ .../ui/consts/const-type-parameter.stderr | 71 ++++++++++++++ src/test/ui/consts/issue-67945.rs | 50 ++++++++++ src/test/ui/consts/issue-67945.stderr | 80 ++++++++++++++++ src/test/ui/issues/issue-39211.rs | 3 +- src/test/ui/issues/issue-39211.stderr | 8 +- src/test/ui/issues/issue-39559.rs | 2 +- src/test/ui/issues/issue-39559.stderr | 14 +-- 18 files changed, 466 insertions(+), 58 deletions(-) create mode 100644 src/librustc_error_codes/error_codes/E0747.md create mode 100644 src/test/ui/consts/const-type-parameter-self.rs create mode 100644 src/test/ui/consts/const-type-parameter.rs create mode 100644 src/test/ui/consts/const-type-parameter.stderr create mode 100644 src/test/ui/consts/issue-67945.rs create mode 100644 src/test/ui/consts/issue-67945.stderr diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 180ccb15977dd..35ae05c477626 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -415,6 +415,7 @@ E0743: include_str!("./error_codes/E0743.md"), E0744: include_str!("./error_codes/E0744.md"), E0745: include_str!("./error_codes/E0745.md"), E0746: include_str!("./error_codes/E0746.md"), +E0747: include_str!("./error_codes/E0747.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/src/librustc_error_codes/error_codes/E0747.md b/src/librustc_error_codes/error_codes/E0747.md new file mode 100644 index 0000000000000..dccc2308a1613 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0747.md @@ -0,0 +1,58 @@ +Any constant items, static items, array length expressions, or enum +discriminants can't refer to type parameters. + +Erroneous code example: + +```compile_fail,E0747 +use std::mem::size_of; + +fn foo() { + let _ = [0; size_of::()]; +} +``` + +A workaround for array length expressions is to use [`vec!`] instead, which +does support type parameters in it's length expression, though this does +perform dynamic memory allocation. Example: + +``` +use std::mem::size_of; + +fn foo() { + let _ = vec![0; size_of::()]; +} +``` + +Though enum discriminants can't refer to regular type parameters they can still +refer to the `Self` type parameter. Example: + +``` +#[repr(u8)] +enum Alpha { + V1 = 41, + V2 = Self::V1 as u8 + 1, +} +``` + +Note, associated constants do not have this limitation and they can refer to +type parameters. Example: + +``` +use std::mem::size_of; + +trait Foo { + const X: i32; +} + +struct Bar(T); + +impl Foo for Bar { + const X: i32 = size_of::(); +} +``` + +This is currently a limitation with the compiler and these restrictions may be +relaxed in the future, see [issue 43408] for more information. + +[`vec!`]: https://doc.rust-lang.org/std/vec/struct.Vec.html +[issue 43408]: https://github.com/rust-lang/rust/issues/43408 diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index a433ae8ed676a..c76b506f8f7bd 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -360,6 +360,17 @@ impl<'a> Resolver<'a> { err.span_label(span, "non-constant value"); err } + ResolutionError::GenericParamsInConst(source) => { + let mut err = struct_span_err!( + self.session, + span, + E0447, + "type parameters can't appear within {}", + source.descr() + ); + err.span_label(span, "type parameter"); + err + } ResolutionError::BindingShadowsSomethingUnacceptable(what_binding, name, binding) => { let res = binding.res(); let shadows_what = res.descr(); diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index defca4944bcd8..fa6675f788ff8 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -78,6 +78,36 @@ enum PatBoundCtx { Or, } +/// Denotes the location/usage of an anonymous constant. +#[derive(Copy, Clone, PartialEq, Debug)] +crate enum AnonConstUsage { + /// constant item, e.g., `const _: u8 = X;`. + Constant, + /// static item, e.g., `static _: u8 = X;`. + Static, + /// an array length expression, e.g., `[...; X]`. + ArrayLength, + /// an enum discriminant value, e.g., `enum Enum { V = X, }`. + EnumDiscriminant, + /// an associated constant in an impl or trait, e.g., `impl A { const _: u8 = X; }`. + AssocConstant, + /// a const generic argument, e.g., `Struct<{X}>`. + GenericArg, +} + +impl AnonConstUsage { + crate fn descr(self) -> &'static str { + match self { + AnonConstUsage::Constant => "a constant", + AnonConstUsage::Static => "a static", + AnonConstUsage::ArrayLength => "an array length expression", + AnonConstUsage::EnumDiscriminant => "an enum discriminant", + AnonConstUsage::AssocConstant => "an associated constant", + AnonConstUsage::GenericArg => "a const generic argument", + } + } +} + /// Does this the item (from the item rib scope) allow generic parameters? #[derive(Copy, Clone, Debug, Eq, PartialEq)] crate enum HasGenericParams { @@ -105,8 +135,8 @@ crate enum RibKind<'a> { /// We passed through an item scope. Disallow upvars. ItemRibKind(HasGenericParams), - /// We're in a constant item. Can't refer to dynamic stuff. - ConstantItemRibKind, + /// We're in a constant. Depending on it's usage, it may be able to refer to type parameters. + ConstantRibKind(AnonConstUsage), /// We passed through a module. ModuleRibKind(Module<'a>), @@ -125,7 +155,7 @@ impl RibKind<'_> { // variables. crate fn contains_params(&self) -> bool { match self { - NormalRibKind | FnItemRibKind | ConstantItemRibKind | ModuleRibKind(_) + NormalRibKind | FnItemRibKind | ConstantRibKind(_) | ModuleRibKind(_) | MacroDefinition(_) => false, AssocItemRibKind | ItemRibKind(_) | ForwardTyParamBanRibKind => true, } @@ -382,10 +412,18 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { } fn visit_anon_const(&mut self, constant: &'tcx AnonConst) { debug!("visit_anon_const {:?}", constant); - self.with_constant_rib(|this| { + self.with_constant_rib(AnonConstUsage::ArrayLength, |this| { visit::walk_anon_const(this, constant); }); } + fn visit_variant(&mut self, variant: &'tcx Variant) { + self.visit_variant_data(&variant.data); + if let Some(ref disr) = variant.disr_expr { + self.with_constant_rib(AnonConstUsage::EnumDiscriminant, |this| { + visit::walk_anon_const(this, disr); + }); + } + } fn visit_expr(&mut self, expr: &'tcx Expr) { self.resolve_expr(expr, None); } @@ -562,7 +600,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { if !check_ns(TypeNS) && check_ns(ValueNS) { // This must be equivalent to `visit_anon_const`, but we cannot call it // directly due to visitor lifetimes so we have to copy-paste some code. - self.with_constant_rib(|this| { + self.with_constant_rib(AnonConstUsage::GenericArg, |this| { this.smart_resolve_path( ty.id, qself.as_ref(), @@ -584,7 +622,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { self.visit_ty(ty); } GenericArg::Lifetime(lt) => self.visit_lifetime(lt), - GenericArg::Const(ct) => self.visit_anon_const(ct), + GenericArg::Const(ct) => { + self.with_constant_rib(AnonConstUsage::GenericArg, |this| { + visit::walk_anon_const(this, ct); + }); + } } } } @@ -829,9 +871,12 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { // ConstRibKind for an actual constant // expression in a provided default. if let Some(ref expr) = *default { - this.with_constant_rib(|this| { - this.visit_expr(expr); - }); + this.with_constant_rib( + AnonConstUsage::AssocConstant, + |this| { + this.visit_expr(expr); + }, + ); } } AssocItemKind::Fn(_, _) => { @@ -873,7 +918,12 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { debug!("resolve_item ItemKind::Const"); self.with_item_rib(HasGenericParams::No, |this| { this.visit_ty(ty); - this.with_constant_rib(|this| { + let usage = if let ItemKind::Static(..) = item.kind { + AnonConstUsage::Static + } else { + AnonConstUsage::Constant + }; + this.with_constant_rib(usage, |this| { this.visit_expr(expr); }); }); @@ -971,10 +1021,12 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f)) } - fn with_constant_rib(&mut self, f: impl FnOnce(&mut Self)) { + fn with_constant_rib(&mut self, usage: AnonConstUsage, f: impl FnOnce(&mut Self)) { debug!("with_constant_rib"); - self.with_rib(ValueNS, ConstantItemRibKind, |this| { - this.with_label_rib(ConstantItemRibKind, f); + self.with_rib(ValueNS, ConstantRibKind(usage), |this| { + this.with_rib(TypeNS, ConstantRibKind(usage), |this| { + this.with_label_rib(ConstantRibKind(usage), f); + }); }); } @@ -1106,7 +1158,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { |this| { use crate::ResolutionError::*; match impl_item.kind { - AssocItemKind::Const(..) => { + AssocItemKind::Const(ref ty, ref expr) => { debug!( "resolve_implementation AssocItemKind::Const", ); @@ -1119,9 +1171,15 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { |n, s| ConstNotMemberOfTrait(n, s), ); - this.with_constant_rib(|this| { - visit::walk_impl_item(this, impl_item) - }); + this.visit_ty(ty); + + // Only impose the restrictions of ConstRibKind for + // the actual constant expression. + if let Some(expr) = expr.as_deref() { + this.with_constant_rib(AnonConstUsage::AssocConstant, |this| { + this.visit_expr(expr) + }); + } } AssocItemKind::Fn(..) => { // If this is a trait impl, ensure the method diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 60a0049f5da37..deb69f824ab9c 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1,3 +1,4 @@ +// ignore-tidy-filelength //! This crate is responsible for the part of name resolution that doesn't require type checker. //! //! Module structure of the crate is built here. @@ -58,7 +59,7 @@ use std::{cmp, fmt, iter, ptr}; use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_next_binding}; use diagnostics::{ImportSuggestion, Suggestion}; use imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver, NameResolution}; -use late::{HasGenericParams, PathSource, Rib, RibKind::*}; +use late::{AnonConstUsage, HasGenericParams, PathSource, Rib, RibKind::*}; use macros::{LegacyBinding, LegacyScope}; use rustc_error_codes::*; @@ -203,6 +204,8 @@ enum ResolutionError<'a> { CannotCaptureDynamicEnvironmentInFnItem, /// Error E0435: attempt to use a non-constant value in a constant. AttemptToUseNonConstantValueInConstant, + /// Error E0747: type parameters can't appear within `{}`. + GenericParamsInConst(AnonConstUsage), /// Error E0530: `X` bindings cannot shadow `Y`s. BindingShadowsSomethingUnacceptable(&'a str, Name, &'a NameBinding<'a>), /// Error E0128: type parameters with a default cannot use forward-declared identifiers. @@ -2327,12 +2330,12 @@ impl<'a> Resolver<'a> { if record_used { // We don't immediately trigger a resolve error, because // we want certain other resolution errors (namely those - // emitted for `ConstantItemRibKind` below) to take + // emitted for `ConstantRibKind` below) to take // precedence. res_err = Some(CannotCaptureDynamicEnvironmentInFnItem); } } - ConstantItemRibKind => { + ConstantRibKind(_) => { // Still doesn't deal with upvars if record_used { self.report_error(span, AttemptToUseNonConstantValueInConstant); @@ -2353,11 +2356,55 @@ impl<'a> Resolver<'a> { | AssocItemRibKind | ModuleRibKind(..) | MacroDefinition(..) - | ForwardTyParamBanRibKind - | ConstantItemRibKind => { + | ForwardTyParamBanRibKind => { // Nothing to do. Continue. continue; } + ConstantRibKind(usage) => { + if self.session.features_untracked().const_generics { + // With const generics/lazy normalization any constants can depend + // on generic parameters, including type parameters. + continue; + }; + match usage { + AnonConstUsage::AssocConstant | AnonConstUsage::GenericArg => { + // Allowed to use any type parameters. + continue + }, + // Enum discriminants can use `Self` to refer to other variants in + // the same enum, but can refer to any other type parameters. + AnonConstUsage::EnumDiscriminant + // In most cases array lengths can't refer to type parameters but + // previously some usages involving `Self` did compile. Example: + // + // impl Foo { + // const A: usize = 32; + // + // pub fn bar() { + // let _ = [0; Self::A]; + // } + // } + // + // Though if `Foo` had a type parameter, + // e.g. `impl Foo { ... }` then is wouldn't compile with a + // confusing error message. + | AnonConstUsage::ArrayLength => { + if let Res::SelfTy(..) = res { + continue + } + } + // can't use any type parameters including `Self`. + AnonConstUsage::Constant | AnonConstUsage::Static => {} + } + + if record_used { + self.report_error( + span, + ResolutionError::GenericParamsInConst(usage), + ); + } + return Res::Err; + } // This was an attempt to use a type parameter outside its scope. ItemRibKind(has_generic_params) => has_generic_params, FnItemRibKind => HasGenericParams::Yes, diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs index f1f82caf7d40b..1891631b01173 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs @@ -14,7 +14,7 @@ impl Foo for Def { pub fn test() { let _array = [4; ::Y]; - //~^ ERROR the trait bound `A: Foo` is not satisfied [E0277] + //~^ ERROR type parameters can't appear within an array length expression [E0447] } fn main() { diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr index c258892057bf2..db681d0a73092 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr @@ -1,14 +1,9 @@ -error[E0277]: the trait bound `A: Foo` is not satisfied - --> $DIR/associated-const-type-parameter-arrays-2.rs:16:22 +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/associated-const-type-parameter-arrays-2.rs:16:23 | -LL | const Y: usize; - | --------------- required by `Foo::Y` -... -LL | pub fn test() { - | -- help: consider further restricting this bound: `A: Foo +` LL | let _array = [4; ::Y]; - | ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A` + | ^ type parameter error: aborting due to previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0447`. diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs b/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs index d51821059fc13..38eba8847d95e 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs @@ -14,7 +14,7 @@ impl Foo for Def { pub fn test() { let _array: [u32; ::Y]; - //~^ ERROR the trait bound `A: Foo` is not satisfied [E0277] + //~^ ERROR type parameters can't appear within an array length expression [E0447] } fn main() { diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr index f6c8e99e27a81..cf97ce197b755 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr @@ -1,14 +1,9 @@ -error[E0277]: the trait bound `A: Foo` is not satisfied - --> $DIR/associated-const-type-parameter-arrays.rs:16:23 +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/associated-const-type-parameter-arrays.rs:16:24 | -LL | const Y: usize; - | --------------- required by `Foo::Y` -... -LL | pub fn test() { - | -- help: consider further restricting this bound: `A: Foo +` LL | let _array: [u32; ::Y]; - | ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A` + | ^ type parameter error: aborting due to previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0447`. diff --git a/src/test/ui/consts/const-type-parameter-self.rs b/src/test/ui/consts/const-type-parameter-self.rs new file mode 100644 index 0000000000000..96275e9fe8504 --- /dev/null +++ b/src/test/ui/consts/const-type-parameter-self.rs @@ -0,0 +1,15 @@ +// check-pass + +struct Foo; + +impl Foo { + const A: usize = 37; + + fn bar() -> [u8; Self::A]{ + [0; Self::A] + } +} + +fn main() { + let _: [u8; 37] = Foo::bar(); +} diff --git a/src/test/ui/consts/const-type-parameter.rs b/src/test/ui/consts/const-type-parameter.rs new file mode 100644 index 0000000000000..6d264bdc683ed --- /dev/null +++ b/src/test/ui/consts/const-type-parameter.rs @@ -0,0 +1,32 @@ +use std::mem::size_of; + +trait Bar { + const A: usize; +} + +fn foo() { + const A: usize = size_of::(); + //~^ can't use generic parameters from outer function [E0401] + const B: usize = T::A; + //~^ can't use generic parameters from outer function [E0401] + static C: usize = size_of::(); + //~^ can't use generic parameters from outer function [E0401] + static D: usize = T::A; + //~^ can't use generic parameters from outer function [E0401] + + let _ = [0; size_of::()]; + //~^ ERROR type parameters can't appear within an array length expression [E0447] + let _ = [0; T::A]; + //~^ ERROR type parameters can't appear within an array length expression [E0447] +} + +#[repr(usize)] +enum Enum { + //~^ ERROR parameter `T` is never used [E0392] + V1 = size_of::(), + //~^ ERROR type parameters can't appear within an enum discriminant [E0447] + V2 = T::A, + //~^ ERROR type parameters can't appear within an enum discriminant [E0447] +} + +fn main() {} diff --git a/src/test/ui/consts/const-type-parameter.stderr b/src/test/ui/consts/const-type-parameter.stderr new file mode 100644 index 0000000000000..65cbebfae1da6 --- /dev/null +++ b/src/test/ui/consts/const-type-parameter.stderr @@ -0,0 +1,71 @@ +error[E0401]: can't use generic parameters from outer function + --> $DIR/const-type-parameter.rs:8:32 + | +LL | fn foo() { + | - type parameter from outer function +LL | const A: usize = size_of::(); + | ^ use of generic parameter from outer function + +error[E0401]: can't use generic parameters from outer function + --> $DIR/const-type-parameter.rs:10:22 + | +LL | fn foo() { + | - type parameter from outer function +... +LL | const B: usize = T::A; + | ^^^^ use of generic parameter from outer function + +error[E0401]: can't use generic parameters from outer function + --> $DIR/const-type-parameter.rs:12:33 + | +LL | fn foo() { + | - type parameter from outer function +... +LL | static C: usize = size_of::(); + | ^ use of generic parameter from outer function + +error[E0401]: can't use generic parameters from outer function + --> $DIR/const-type-parameter.rs:14:23 + | +LL | fn foo() { + | - type parameter from outer function +... +LL | static D: usize = T::A; + | ^^^^ use of generic parameter from outer function + +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/const-type-parameter.rs:17:27 + | +LL | let _ = [0; size_of::()]; + | ^ type parameter + +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/const-type-parameter.rs:19:17 + | +LL | let _ = [0; T::A]; + | ^^^^ type parameter + +error[E0447]: type parameters can't appear within an enum discriminant + --> $DIR/const-type-parameter.rs:26:20 + | +LL | V1 = size_of::(), + | ^ type parameter + +error[E0447]: type parameters can't appear within an enum discriminant + --> $DIR/const-type-parameter.rs:28:10 + | +LL | V2 = T::A, + | ^^^^ type parameter + +error[E0392]: parameter `T` is never used + --> $DIR/const-type-parameter.rs:24:11 + | +LL | enum Enum { + | ^ unused parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `std::marker::PhantomData` + +error: aborting due to 9 previous errors + +Some errors have detailed explanations: E0392, E0401, E0447. +For more information about an error, try `rustc --explain E0392`. diff --git a/src/test/ui/consts/issue-67945.rs b/src/test/ui/consts/issue-67945.rs new file mode 100644 index 0000000000000..9962e93bf3952 --- /dev/null +++ b/src/test/ui/consts/issue-67945.rs @@ -0,0 +1,50 @@ +#![feature(type_ascription)] + +use std::marker::PhantomData; +use std::mem::{self, MaybeUninit}; + +struct Bug1 { + //~^ ERROR parameter `S` is never used [E0392] + A: [(); { + let x: S = MaybeUninit::uninit(); + //~^ ERROR type parameters can't appear within an array length expression [E0447] + let b = &*(&x as *const _ as *const S); + //~^ ERROR type parameters can't appear within an array length expression [E0447] + 0 + }], +} + +struct Bug2 { + //~^ ERROR parameter `S` is never used [E0392] + A: [(); { + let x: Option = None; + //~^ ERROR type parameters can't appear within an array length expression [E0447] + 0 + }], +} + +struct Bug3 { + //~^ ERROR parameter `S` is never used [E0392] + A: [(); { + let x: Option> = None; + //~^ ERROR type parameters can't appear within an array length expression [E0447] + 0 + }], +} + +enum Bug4 { + //~^ ERROR parameter `S` is never used [E0392] + Var = { + let x: S = 0; + //~^ ERROR type parameters can't appear within an enum discriminant [E0447] + 0 + }, +} + +enum Bug5 { + //~^ ERROR parameter `S` is never used [E0392] + Var = 0: S, + //~^ ERROR type parameters can't appear within an enum discriminant [E0447] +} + +fn main() {} diff --git a/src/test/ui/consts/issue-67945.stderr b/src/test/ui/consts/issue-67945.stderr new file mode 100644 index 0000000000000..0ff01e07ab834 --- /dev/null +++ b/src/test/ui/consts/issue-67945.stderr @@ -0,0 +1,80 @@ +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/issue-67945.rs:9:16 + | +LL | let x: S = MaybeUninit::uninit(); + | ^ type parameter + +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/issue-67945.rs:11:45 + | +LL | let b = &*(&x as *const _ as *const S); + | ^ type parameter + +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/issue-67945.rs:20:23 + | +LL | let x: Option = None; + | ^ type parameter + +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/issue-67945.rs:29:27 + | +LL | let x: Option> = None; + | ^ type parameter + +error[E0447]: type parameters can't appear within an enum discriminant + --> $DIR/issue-67945.rs:38:16 + | +LL | let x: S = 0; + | ^ type parameter + +error[E0447]: type parameters can't appear within an enum discriminant + --> $DIR/issue-67945.rs:46:14 + | +LL | Var = 0: S, + | ^ type parameter + +error[E0392]: parameter `S` is never used + --> $DIR/issue-67945.rs:6:13 + | +LL | struct Bug1 { + | ^ unused parameter + | + = help: consider removing `S`, referring to it in a field, or using a marker such as `std::marker::PhantomData` + +error[E0392]: parameter `S` is never used + --> $DIR/issue-67945.rs:17:13 + | +LL | struct Bug2 { + | ^ unused parameter + | + = help: consider removing `S`, referring to it in a field, or using a marker such as `std::marker::PhantomData` + +error[E0392]: parameter `S` is never used + --> $DIR/issue-67945.rs:26:13 + | +LL | struct Bug3 { + | ^ unused parameter + | + = help: consider removing `S`, referring to it in a field, or using a marker such as `std::marker::PhantomData` + +error[E0392]: parameter `S` is never used + --> $DIR/issue-67945.rs:35:11 + | +LL | enum Bug4 { + | ^ unused parameter + | + = help: consider removing `S`, referring to it in a field, or using a marker such as `std::marker::PhantomData` + +error[E0392]: parameter `S` is never used + --> $DIR/issue-67945.rs:44:11 + | +LL | enum Bug5 { + | ^ unused parameter + | + = help: consider removing `S`, referring to it in a field, or using a marker such as `std::marker::PhantomData` + +error: aborting due to 11 previous errors + +Some errors have detailed explanations: E0392, E0447. +For more information about an error, try `rustc --explain E0392`. diff --git a/src/test/ui/issues/issue-39211.rs b/src/test/ui/issues/issue-39211.rs index db101ae248cb6..62a51de7154de 100644 --- a/src/test/ui/issues/issue-39211.rs +++ b/src/test/ui/issues/issue-39211.rs @@ -8,7 +8,8 @@ trait Mat { } fn m() { - let a = [3; M::Row::DIM]; //~ ERROR associated type `Row` not found for `M` + let a = [3; M::Row::DIM]; + //~^ ERROR type parameters can't appear within an array length expression [E0447] } fn main() { } diff --git a/src/test/ui/issues/issue-39211.stderr b/src/test/ui/issues/issue-39211.stderr index c14c663e5a1a9..a0b82075c2335 100644 --- a/src/test/ui/issues/issue-39211.stderr +++ b/src/test/ui/issues/issue-39211.stderr @@ -1,9 +1,9 @@ -error[E0220]: associated type `Row` not found for `M` - --> $DIR/issue-39211.rs:11:20 +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/issue-39211.rs:11:17 | LL | let a = [3; M::Row::DIM]; - | ^^^ associated type `Row` not found + | ^^^^^^^^^^^ type parameter error: aborting due to previous error -For more information about this error, try `rustc --explain E0220`. +For more information about this error, try `rustc --explain E0447`. diff --git a/src/test/ui/issues/issue-39559.rs b/src/test/ui/issues/issue-39559.rs index 3a75956af5280..d45e9b701ab4e 100644 --- a/src/test/ui/issues/issue-39559.rs +++ b/src/test/ui/issues/issue-39559.rs @@ -12,7 +12,7 @@ impl Dim for Dim3 { pub struct Vector { entries: [T; D::dim()], - //~^ ERROR no function or associated item named `dim` found + //~^ ERROR type parameters can't appear within an array length expression [E0447] _dummy: D, } diff --git a/src/test/ui/issues/issue-39559.stderr b/src/test/ui/issues/issue-39559.stderr index 0554b232c248b..5578ea4946e2f 100644 --- a/src/test/ui/issues/issue-39559.stderr +++ b/src/test/ui/issues/issue-39559.stderr @@ -1,15 +1,9 @@ -error[E0599]: no function or associated item named `dim` found for type parameter `D` in the current scope - --> $DIR/issue-39559.rs:14:21 +error[E0447]: type parameters can't appear within an array length expression + --> $DIR/issue-39559.rs:14:18 | LL | entries: [T; D::dim()], - | ^^^ function or associated item not found in `D` - | - = help: items from traits can only be used if the type parameter is bounded by the trait -help: the following trait defines an item `dim`, perhaps you need to restrict type parameter `D` with it: - | -LL | pub struct Vector { - | ^^^^^^^^ + | ^^^^^^ type parameter error: aborting due to previous error -For more information about this error, try `rustc --explain E0599`. +For more information about this error, try `rustc --explain E0447`. From 51e5f3b1961591fe86959ed2a9d58dc7ab5ff298 Mon Sep 17 00:00:00 2001 From: Ben Lewis Date: Sun, 19 Jan 2020 16:35:24 +1300 Subject: [PATCH 2/2] Code review changes. --- src/librustc_error_codes/error_codes/E0747.md | 10 ++-- src/librustc_resolve/diagnostics.rs | 4 +- src/librustc_resolve/late.rs | 48 +++++++++++++------ src/librustc_resolve/lib.rs | 6 ++- ...ssociated-const-type-parameter-arrays-2.rs | 2 +- ...iated-const-type-parameter-arrays-2.stderr | 4 +- .../associated-const-type-parameter-arrays.rs | 2 +- ...ociated-const-type-parameter-arrays.stderr | 4 +- src/test/ui/consts/const-type-parameter.rs | 8 ++-- .../ui/consts/const-type-parameter.stderr | 10 ++-- src/test/ui/consts/issue-67945.rs | 12 ++--- src/test/ui/consts/issue-67945.stderr | 14 +++--- src/test/ui/issues/issue-39211.rs | 2 +- src/test/ui/issues/issue-39211.stderr | 4 +- src/test/ui/issues/issue-39559.rs | 2 +- src/test/ui/issues/issue-39559.stderr | 4 +- 16 files changed, 78 insertions(+), 58 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0747.md b/src/librustc_error_codes/error_codes/E0747.md index dccc2308a1613..f337d11ebb6b4 100644 --- a/src/librustc_error_codes/error_codes/E0747.md +++ b/src/librustc_error_codes/error_codes/E0747.md @@ -1,5 +1,5 @@ -Any constant items, static items, array length expressions, or enum -discriminants can't refer to type parameters. +Any constant item, static item, array length expression, or enum +discriminant cannot refer to type parameters. Erroneous code example: @@ -23,7 +23,7 @@ fn foo() { } ``` -Though enum discriminants can't refer to regular type parameters they can still +While enum discriminants cannot refer to regular type parameters, they can still refer to the `Self` type parameter. Example: ``` @@ -34,7 +34,7 @@ enum Alpha { } ``` -Note, associated constants do not have this limitation and they can refer to +Note that associated constants do not have this limitation and can refer to type parameters. Example: ``` @@ -51,7 +51,7 @@ impl Foo for Bar { } ``` -This is currently a limitation with the compiler and these restrictions may be +This is currently a limitation with the compiler. These restrictions may be relaxed in the future, see [issue 43408] for more information. [`vec!`]: https://doc.rust-lang.org/std/vec/struct.Vec.html diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index c76b506f8f7bd..31cea2bb1f7b4 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -364,8 +364,8 @@ impl<'a> Resolver<'a> { let mut err = struct_span_err!( self.session, span, - E0447, - "type parameters can't appear within {}", + E0747, + "type parameters cannot appear within {}", source.descr() ); err.span_label(span, "type parameter"); diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index fa6675f788ff8..8413a18833abc 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -81,18 +81,20 @@ enum PatBoundCtx { /// Denotes the location/usage of an anonymous constant. #[derive(Copy, Clone, PartialEq, Debug)] crate enum AnonConstUsage { - /// constant item, e.g., `const _: u8 = X;`. + /// Constant item, e.g., `const _: u8 = X;`. Constant, - /// static item, e.g., `static _: u8 = X;`. + /// Static item, e.g., `static _: u8 = X;`. Static, - /// an array length expression, e.g., `[...; X]`. + /// An array length expression, e.g., `[...; X]`. ArrayLength, - /// an enum discriminant value, e.g., `enum Enum { V = X, }`. + /// An enum discriminant value, e.g., `enum Enum { V = X, }`. EnumDiscriminant, - /// an associated constant in an impl or trait, e.g., `impl A { const _: u8 = X; }`. + /// An associated constant in an impl or trait, e.g., `impl A { const _: u8 = X; }`. AssocConstant, - /// a const generic argument, e.g., `Struct<{X}>`. + /// A const generic argument, e.g., `Struct<{X}>`. GenericArg, + /// A typeof expression, which is an unimplemented feature. + Typeof, } impl AnonConstUsage { @@ -104,6 +106,7 @@ impl AnonConstUsage { AnonConstUsage::EnumDiscriminant => "an enum discriminant", AnonConstUsage::AssocConstant => "an associated constant", AnonConstUsage::GenericArg => "a const generic argument", + AnonConstUsage::Typeof => "a typeof expression", } } } @@ -411,10 +414,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { self.resolve_block(block); } fn visit_anon_const(&mut self, constant: &'tcx AnonConst) { - debug!("visit_anon_const {:?}", constant); - self.with_constant_rib(AnonConstUsage::ArrayLength, |this| { - visit::walk_anon_const(this, constant); - }); + // All constants should be handled by their parents, so that the applicable `AnonConstUsage` + // of the constant can be assigned. + bug!("unhandled constant: {:?}", constant); } fn visit_variant(&mut self, variant: &'tcx Variant) { self.visit_variant_data(&variant.data); @@ -445,6 +447,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { match ty.kind { TyKind::Path(ref qself, ref path) => { self.smart_resolve_path(ty.id, qself.as_ref(), path, PathSource::Type); + visit::walk_ty(self, ty); } TyKind::ImplicitSelf => { let self_ty = Ident::with_dummy_span(kw::SelfUpper); @@ -452,10 +455,21 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { .resolve_ident_in_lexical_scope(self_ty, TypeNS, Some(ty.id), ty.span) .map_or(Res::Err, |d| d.res()); self.r.record_partial_res(ty.id, PartialRes::new(res)); + visit::walk_ty(self, ty); } - _ => (), - } - visit::walk_ty(self, ty); + TyKind::Array(ref element_ty, ref count) => { + self.visit_ty(element_ty); + self.with_constant_rib(AnonConstUsage::ArrayLength, |this| { + visit::walk_anon_const(this, count); + }); + } + TyKind::Typeof(ref constant) => { + self.with_constant_rib(AnonConstUsage::Typeof, |this| { + visit::walk_anon_const(this, constant); + }); + } + _ => visit::walk_ty(self, ty), + }; } fn visit_poly_trait_ref(&mut self, tref: &'tcx PolyTraitRef, m: &'tcx TraitBoundModifier) { self.smart_resolve_path( @@ -598,8 +612,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> { }; if !check_ns(TypeNS) && check_ns(ValueNS) { - // This must be equivalent to `visit_anon_const`, but we cannot call it - // directly due to visitor lifetimes so we have to copy-paste some code. self.with_constant_rib(AnonConstUsage::GenericArg, |this| { this.smart_resolve_path( ty.id, @@ -2077,6 +2089,12 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> { } }); } + ExprKind::Repeat(ref element, ref count) => { + self.visit_expr(element); + self.with_constant_rib(AnonConstUsage::ArrayLength, |this| { + visit::walk_anon_const(this, count); + }); + } _ => { visit::walk_expr(self, expr); } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index deb69f824ab9c..743f6d34db7b8 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -204,7 +204,7 @@ enum ResolutionError<'a> { CannotCaptureDynamicEnvironmentInFnItem, /// Error E0435: attempt to use a non-constant value in a constant. AttemptToUseNonConstantValueInConstant, - /// Error E0747: type parameters can't appear within `{}`. + /// Error E0747: type parameters cannot appear within `{}`. GenericParamsInConst(AnonConstUsage), /// Error E0530: `X` bindings cannot shadow `Y`s. BindingShadowsSomethingUnacceptable(&'a str, Name, &'a NameBinding<'a>), @@ -2367,7 +2367,9 @@ impl<'a> Resolver<'a> { continue; }; match usage { - AnonConstUsage::AssocConstant | AnonConstUsage::GenericArg => { + AnonConstUsage::AssocConstant + | AnonConstUsage::GenericArg + | AnonConstUsage::Typeof => { // Allowed to use any type parameters. continue }, diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs index 1891631b01173..3b752bd2fe481 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.rs @@ -14,7 +14,7 @@ impl Foo for Def { pub fn test() { let _array = [4; ::Y]; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] } fn main() { diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr index db681d0a73092..721b3e6028280 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays-2.stderr @@ -1,4 +1,4 @@ -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/associated-const-type-parameter-arrays-2.rs:16:23 | LL | let _array = [4; ::Y]; @@ -6,4 +6,4 @@ LL | let _array = [4; ::Y]; error: aborting due to previous error -For more information about this error, try `rustc --explain E0447`. +For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs b/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs index 38eba8847d95e..64ec2075427c4 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays.rs @@ -14,7 +14,7 @@ impl Foo for Def { pub fn test() { let _array: [u32; ::Y]; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] } fn main() { diff --git a/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr b/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr index cf97ce197b755..33423c35b79ac 100644 --- a/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr +++ b/src/test/ui/associated-const/associated-const-type-parameter-arrays.stderr @@ -1,4 +1,4 @@ -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/associated-const-type-parameter-arrays.rs:16:24 | LL | let _array: [u32; ::Y]; @@ -6,4 +6,4 @@ LL | let _array: [u32; ::Y]; error: aborting due to previous error -For more information about this error, try `rustc --explain E0447`. +For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/consts/const-type-parameter.rs b/src/test/ui/consts/const-type-parameter.rs index 6d264bdc683ed..e9cf5a3c75860 100644 --- a/src/test/ui/consts/const-type-parameter.rs +++ b/src/test/ui/consts/const-type-parameter.rs @@ -15,18 +15,18 @@ fn foo() { //~^ can't use generic parameters from outer function [E0401] let _ = [0; size_of::()]; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] let _ = [0; T::A]; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] } #[repr(usize)] enum Enum { //~^ ERROR parameter `T` is never used [E0392] V1 = size_of::(), - //~^ ERROR type parameters can't appear within an enum discriminant [E0447] + //~^ ERROR type parameters cannot appear within an enum discriminant [E0747] V2 = T::A, - //~^ ERROR type parameters can't appear within an enum discriminant [E0447] + //~^ ERROR type parameters cannot appear within an enum discriminant [E0747] } fn main() {} diff --git a/src/test/ui/consts/const-type-parameter.stderr b/src/test/ui/consts/const-type-parameter.stderr index 65cbebfae1da6..2bb90dcb91f66 100644 --- a/src/test/ui/consts/const-type-parameter.stderr +++ b/src/test/ui/consts/const-type-parameter.stderr @@ -33,25 +33,25 @@ LL | fn foo() { LL | static D: usize = T::A; | ^^^^ use of generic parameter from outer function -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/const-type-parameter.rs:17:27 | LL | let _ = [0; size_of::()]; | ^ type parameter -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/const-type-parameter.rs:19:17 | LL | let _ = [0; T::A]; | ^^^^ type parameter -error[E0447]: type parameters can't appear within an enum discriminant +error[E0747]: type parameters cannot appear within an enum discriminant --> $DIR/const-type-parameter.rs:26:20 | LL | V1 = size_of::(), | ^ type parameter -error[E0447]: type parameters can't appear within an enum discriminant +error[E0747]: type parameters cannot appear within an enum discriminant --> $DIR/const-type-parameter.rs:28:10 | LL | V2 = T::A, @@ -67,5 +67,5 @@ LL | enum Enum { error: aborting due to 9 previous errors -Some errors have detailed explanations: E0392, E0401, E0447. +Some errors have detailed explanations: E0392, E0401, E0747. For more information about an error, try `rustc --explain E0392`. diff --git a/src/test/ui/consts/issue-67945.rs b/src/test/ui/consts/issue-67945.rs index 9962e93bf3952..04f53bb12e8e8 100644 --- a/src/test/ui/consts/issue-67945.rs +++ b/src/test/ui/consts/issue-67945.rs @@ -7,9 +7,9 @@ struct Bug1 { //~^ ERROR parameter `S` is never used [E0392] A: [(); { let x: S = MaybeUninit::uninit(); - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] let b = &*(&x as *const _ as *const S); - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] 0 }], } @@ -18,7 +18,7 @@ struct Bug2 { //~^ ERROR parameter `S` is never used [E0392] A: [(); { let x: Option = None; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] 0 }], } @@ -27,7 +27,7 @@ struct Bug3 { //~^ ERROR parameter `S` is never used [E0392] A: [(); { let x: Option> = None; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] 0 }], } @@ -36,7 +36,7 @@ enum Bug4 { //~^ ERROR parameter `S` is never used [E0392] Var = { let x: S = 0; - //~^ ERROR type parameters can't appear within an enum discriminant [E0447] + //~^ ERROR type parameters cannot appear within an enum discriminant [E0747] 0 }, } @@ -44,7 +44,7 @@ enum Bug4 { enum Bug5 { //~^ ERROR parameter `S` is never used [E0392] Var = 0: S, - //~^ ERROR type parameters can't appear within an enum discriminant [E0447] + //~^ ERROR type parameters cannot appear within an enum discriminant [E0747] } fn main() {} diff --git a/src/test/ui/consts/issue-67945.stderr b/src/test/ui/consts/issue-67945.stderr index 0ff01e07ab834..f5700dc5c266b 100644 --- a/src/test/ui/consts/issue-67945.stderr +++ b/src/test/ui/consts/issue-67945.stderr @@ -1,34 +1,34 @@ -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/issue-67945.rs:9:16 | LL | let x: S = MaybeUninit::uninit(); | ^ type parameter -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/issue-67945.rs:11:45 | LL | let b = &*(&x as *const _ as *const S); | ^ type parameter -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/issue-67945.rs:20:23 | LL | let x: Option = None; | ^ type parameter -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/issue-67945.rs:29:27 | LL | let x: Option> = None; | ^ type parameter -error[E0447]: type parameters can't appear within an enum discriminant +error[E0747]: type parameters cannot appear within an enum discriminant --> $DIR/issue-67945.rs:38:16 | LL | let x: S = 0; | ^ type parameter -error[E0447]: type parameters can't appear within an enum discriminant +error[E0747]: type parameters cannot appear within an enum discriminant --> $DIR/issue-67945.rs:46:14 | LL | Var = 0: S, @@ -76,5 +76,5 @@ LL | enum Bug5 { error: aborting due to 11 previous errors -Some errors have detailed explanations: E0392, E0447. +Some errors have detailed explanations: E0392, E0747. For more information about an error, try `rustc --explain E0392`. diff --git a/src/test/ui/issues/issue-39211.rs b/src/test/ui/issues/issue-39211.rs index 62a51de7154de..c5507fb90d5ba 100644 --- a/src/test/ui/issues/issue-39211.rs +++ b/src/test/ui/issues/issue-39211.rs @@ -9,7 +9,7 @@ trait Mat { fn m() { let a = [3; M::Row::DIM]; - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] } fn main() { } diff --git a/src/test/ui/issues/issue-39211.stderr b/src/test/ui/issues/issue-39211.stderr index a0b82075c2335..16f67d943ad94 100644 --- a/src/test/ui/issues/issue-39211.stderr +++ b/src/test/ui/issues/issue-39211.stderr @@ -1,4 +1,4 @@ -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/issue-39211.rs:11:17 | LL | let a = [3; M::Row::DIM]; @@ -6,4 +6,4 @@ LL | let a = [3; M::Row::DIM]; error: aborting due to previous error -For more information about this error, try `rustc --explain E0447`. +For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/issues/issue-39559.rs b/src/test/ui/issues/issue-39559.rs index d45e9b701ab4e..2621a691e5563 100644 --- a/src/test/ui/issues/issue-39559.rs +++ b/src/test/ui/issues/issue-39559.rs @@ -12,7 +12,7 @@ impl Dim for Dim3 { pub struct Vector { entries: [T; D::dim()], - //~^ ERROR type parameters can't appear within an array length expression [E0447] + //~^ ERROR type parameters cannot appear within an array length expression [E0747] _dummy: D, } diff --git a/src/test/ui/issues/issue-39559.stderr b/src/test/ui/issues/issue-39559.stderr index 5578ea4946e2f..e72b5d7a3f6c5 100644 --- a/src/test/ui/issues/issue-39559.stderr +++ b/src/test/ui/issues/issue-39559.stderr @@ -1,4 +1,4 @@ -error[E0447]: type parameters can't appear within an array length expression +error[E0747]: type parameters cannot appear within an array length expression --> $DIR/issue-39559.rs:14:18 | LL | entries: [T; D::dim()], @@ -6,4 +6,4 @@ LL | entries: [T; D::dim()], error: aborting due to previous error -For more information about this error, try `rustc --explain E0447`. +For more information about this error, try `rustc --explain E0747`.