1
Fork 0

Retroactively feature gate ConstArgKind::Path

This commit is contained in:
Boxy 2024-08-19 01:14:09 +01:00
parent f04f6ca36d
commit b8eedfa3d2
41 changed files with 425 additions and 206 deletions

View file

@ -221,7 +221,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let parent_def_id = self.current_def_id_parent; let parent_def_id = self.current_def_id_parent;
let node_id = self.next_node_id(); let node_id = self.next_node_id();
// HACK(min_generic_const_args): see lower_anon_const // HACK(min_generic_const_args): see lower_anon_const
if !expr.is_potential_trivial_const_arg() { if !self.tcx.features().const_arg_path
|| !expr.is_potential_trivial_const_arg()
{
self.create_def( self.create_def(
parent_def_id, parent_def_id,
node_id, node_id,

View file

@ -387,7 +387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let node_id = self.next_node_id(); let node_id = self.next_node_id();
// HACK(min_generic_const_args): see lower_anon_const // HACK(min_generic_const_args): see lower_anon_const
if !arg.is_potential_trivial_const_arg() { if !self.tcx.features().const_arg_path || !arg.is_potential_trivial_const_arg() {
// Add a definition for the in-band const def. // Add a definition for the in-band const def.
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span); self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
} }

View file

@ -2358,7 +2358,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span, span: Span,
) -> &'hir hir::ConstArg<'hir> { ) -> &'hir hir::ConstArg<'hir> {
let ct_kind = match res { let ct_kind = match res {
Res::Def(DefKind::ConstParam, _) => { Res::Def(DefKind::ConstParam, _) if self.tcx.features().const_arg_path => {
let qpath = self.lower_qpath( let qpath = self.lower_qpath(
ty_id, ty_id,
&None, &None,
@ -2433,7 +2433,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res()); self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
debug!("res={:?}", maybe_res); debug!("res={:?}", maybe_res);
// FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path // FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
if let Some(res) = maybe_res if self.tcx.features().const_arg_path
&& let Some(res) = maybe_res
&& let Res::Def(DefKind::ConstParam, _) = res && let Res::Def(DefKind::ConstParam, _) = res
&& let ExprKind::Path(qself, path) = &expr.kind && let ExprKind::Path(qself, path) = &expr.kind
{ {
@ -2464,7 +2465,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// See [`hir::ConstArg`] for when to use this function vs /// See [`hir::ConstArg`] for when to use this function vs
/// [`Self::lower_anon_const_to_const_arg`]. /// [`Self::lower_anon_const_to_const_arg`].
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst { fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
if c.value.is_potential_trivial_const_arg() { if self.tcx.features().const_arg_path && c.value.is_potential_trivial_const_arg() {
// HACK(min_generic_const_args): see DefCollector::visit_anon_const // HACK(min_generic_const_args): see DefCollector::visit_anon_const
// Over there, we guess if this is a bare param and only create a def if // Over there, we guess if this is a bare param and only create a def if
// we think it's not. However we may can guess wrong (see there for example) // we think it's not. However we may can guess wrong (see there for example)

View file

@ -193,6 +193,8 @@ declare_features! (
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None), (unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
/// Allows identifying the `compiler_builtins` crate. /// Allows identifying the `compiler_builtins` crate.
(internal, compiler_builtins, "1.13.0", None), (internal, compiler_builtins, "1.13.0", None),
/// Gating for a new desugaring of const arguments of usages of const parameters
(internal, const_arg_path, "1.81.0", None),
/// Allows writing custom MIR /// Allows writing custom MIR
(internal, custom_mir, "1.65.0", None), (internal, custom_mir, "1.65.0", None),
/// Outputs useful `assert!` messages /// Outputs useful `assert!` messages

View file

@ -240,7 +240,7 @@ impl<'tcx> Const<'tcx> {
let ty = tcx.type_of(def).no_bound_vars().expect("const parameter types cannot be generic"); let ty = tcx.type_of(def).no_bound_vars().expect("const parameter types cannot be generic");
match Self::try_from_lit(tcx, ty, expr) { match Self::try_from_lit_or_param(tcx, ty, expr) {
Some(v) => v, Some(v) => v,
None => ty::Const::new_unevaluated( None => ty::Const::new_unevaluated(
tcx, tcx,
@ -281,7 +281,11 @@ impl<'tcx> Const<'tcx> {
} }
#[instrument(skip(tcx), level = "debug")] #[instrument(skip(tcx), level = "debug")]
fn try_from_lit(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, expr: &'tcx hir::Expr<'tcx>) -> Option<Self> { fn try_from_lit_or_param(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
expr: &'tcx hir::Expr<'tcx>,
) -> Option<Self> {
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments // 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. // currently have to be wrapped in curly brackets, so it's necessary to special-case.
let expr = match &expr.kind { let expr = match &expr.kind {
@ -291,6 +295,22 @@ impl<'tcx> Const<'tcx> {
_ => expr, _ => expr,
}; };
if let hir::ExprKind::Path(
qpath @ hir::QPath::Resolved(
_,
&hir::Path { res: Res::Def(DefKind::ConstParam, _), .. },
),
) = expr.kind
{
if tcx.features().const_arg_path {
span_bug!(
expr.span,
"try_from_lit: received const param which shouldn't be possible"
);
}
return Some(Const::from_param(tcx, qpath, expr.hir_id));
};
let lit_input = match expr.kind { let lit_input = match expr.kind {
hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }), hir::ExprKind::Lit(lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind { hir::ExprKind::Unary(hir::UnOp::Neg, expr) => match expr.kind {
@ -318,14 +338,6 @@ impl<'tcx> Const<'tcx> {
} }
} }
if let hir::ExprKind::Path(hir::QPath::Resolved(
_,
&hir::Path { res: Res::Def(DefKind::ConstParam, _), .. },
)) = expr.kind
{
span_bug!(expr.span, "try_from_lit: received const param which shouldn't be possible")
}
None None
} }

View file

@ -314,13 +314,15 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
} }
fn visit_anon_const(&mut self, constant: &'a AnonConst) { fn visit_anon_const(&mut self, constant: &'a AnonConst) {
// HACK(min_generic_const_args): don't create defs for anon consts if we think they will if self.resolver.tcx.features().const_arg_path
// later be turned into ConstArgKind::Path's. because this is before resolve is done, we && constant.value.is_potential_trivial_const_arg()
// may accidentally identify a construction of a unit struct as a param and not create a {
// def. we'll then create a def later in ast lowering in this case. the parent of nested // HACK(min_generic_const_args): don't create defs for anon consts if we think they will
// items will be messed up, but that's ok because there can't be any if we're just looking // later be turned into ConstArgKind::Path's. because this is before resolve is done, we
// for bare idents. // may accidentally identify a construction of a unit struct as a param and not create a
if constant.value.is_potential_trivial_const_arg() { // def. we'll then create a def later in ast lowering in this case. the parent of nested
// items will be messed up, but that's ok because there can't be any if we're just looking
// for bare idents.
visit::walk_anon_const(self, constant) visit::walk_anon_const(self, constant)
} else { } else {
let def = let def =

View file

@ -595,6 +595,7 @@ symbols! {
conservative_impl_trait, conservative_impl_trait,
console, console,
const_allocate, const_allocate,
const_arg_path,
const_async_blocks, const_async_blocks,
const_closures, const_closures,
const_compare_raw_pointers, const_compare_raw_pointers,

View file

@ -1,5 +1,5 @@
//@ known-bug: #127962 //@ known-bug: #127962
#![feature(generic_const_exprs)] #![feature(generic_const_exprs, const_arg_path)]
fn zero_init<const usize: usize>() -> Substs1<{ (N) }> { fn zero_init<const usize: usize>() -> Substs1<{ (N) }> {
Substs1([0; { (usize) }]) Substs1([0; { (usize) }])

View file

@ -1,10 +0,0 @@
//@ known-bug: #128016
macro_rules! len {
() => {
target
};
}
fn main() {
let val: [str; len!()] = [];
}

View file

@ -17,12 +17,14 @@ extern crate rustc_driver;
extern crate rustc_interface; extern crate rustc_interface;
extern crate stable_mir; extern crate stable_mir;
use mir::{mono::Instance, TerminatorKind::*}; use std::io::Write;
use std::ops::ControlFlow;
use mir::mono::Instance;
use mir::TerminatorKind::*;
use rustc_smir::rustc_internal; use rustc_smir::rustc_internal;
use stable_mir::ty::{RigidTy, TyKind}; use stable_mir::ty::{RigidTy, TyKind};
use stable_mir::*; use stable_mir::*;
use std::io::Write;
use std::ops::ControlFlow;
const CRATE_NAME: &str = "input"; const CRATE_NAME: &str = "input";
@ -33,7 +35,7 @@ fn test_stable_mir() -> ControlFlow<()> {
// Get all items and split generic vs monomorphic items. // Get all items and split generic vs monomorphic items.
let (generic, mono): (Vec<_>, Vec<_>) = let (generic, mono): (Vec<_>, Vec<_>) =
items.into_iter().partition(|item| item.requires_monomorphization()); items.into_iter().partition(|item| item.requires_monomorphization());
assert_eq!(mono.len(), 3, "Expected 3 mono functions"); assert_eq!(mono.len(), 4, "Expected 3 mono functions");
assert_eq!(generic.len(), 2, "Expected 2 generic functions"); assert_eq!(generic.len(), 2, "Expected 2 generic functions");
// For all monomorphic items, get the correspondent instances. // For all monomorphic items, get the correspondent instances.

View file

@ -5,7 +5,9 @@
#![feature(with_negative_coherence)] #![feature(with_negative_coherence)]
trait Trait {} trait Trait {}
impl<const N: u8> Trait for [(); N] {} impl<const N: u8> Trait for [(); N] {}
//~^ ERROR: mismatched types
impl<const N: i8> Trait for [(); N] {} impl<const N: i8> Trait for [(); N] {}
//~^ ERROR: conflicting implementations of trait `Trait` //~^ ERROR: conflicting implementations of trait `Trait`
//~| ERROR: mismatched types
fn main() {} fn main() {}

View file

@ -1,11 +1,25 @@
error[E0119]: conflicting implementations of trait `Trait` for type `[(); _]` error[E0119]: conflicting implementations of trait `Trait` for type `[(); _]`
--> $DIR/generic_const_type_mismatch.rs:8:1 --> $DIR/generic_const_type_mismatch.rs:9:1
| |
LL | impl<const N: u8> Trait for [(); N] {} LL | impl<const N: u8> Trait for [(); N] {}
| ----------------------------------- first implementation here | ----------------------------------- first implementation here
LL |
LL | impl<const N: i8> Trait for [(); N] {} LL | impl<const N: i8> Trait for [(); N] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); _]` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); _]`
error: aborting due to 1 previous error error[E0308]: mismatched types
--> $DIR/generic_const_type_mismatch.rs:7:34
|
LL | impl<const N: u8> Trait for [(); N] {}
| ^ expected `usize`, found `u8`
For more information about this error, try `rustc --explain E0119`. error[E0308]: mismatched types
--> $DIR/generic_const_type_mismatch.rs:9:34
|
LL | impl<const N: i8> Trait for [(); N] {}
| ^ expected `usize`, found `i8`
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0119, E0308.
For more information about an error, try `rustc --explain E0119`.

View file

@ -7,6 +7,7 @@ trait Q {
impl<const N: u64> Q for [u8; N] { impl<const N: u64> Q for [u8; N] {
//~^ ERROR: the constant `N` is not of type `usize` //~^ ERROR: the constant `N` is not of type `usize`
//~| ERROR: mismatched types
const ASSOC: usize = 1; const ASSOC: usize = 1;
} }

View file

@ -5,7 +5,7 @@ LL | impl<const N: u64> Q for [u8; N] {
| ^^^^^^^ expected `usize`, found `u64` | ^^^^^^^ expected `usize`, found `u64`
error: the constant `13` is not of type `u64` error: the constant `13` is not of type `u64`
--> $DIR/bad-subst-const-kind.rs:13:24 --> $DIR/bad-subst-const-kind.rs:14:24
| |
LL | pub fn test() -> [u8; <[u8; 13] as Q>::ASSOC] { LL | pub fn test() -> [u8; <[u8; 13] as Q>::ASSOC] {
| ^^^^^^^^ expected `u64`, found `usize` | ^^^^^^^^ expected `u64`, found `usize`
@ -18,5 +18,12 @@ LL | impl<const N: u64> Q for [u8; N] {
| | | |
| unsatisfied trait bound introduced here | unsatisfied trait bound introduced here
error: aborting due to 2 previous errors error[E0308]: mismatched types
--> $DIR/bad-subst-const-kind.rs:8:31
|
LL | impl<const N: u64> Q for [u8; N] {
| ^ expected `usize`, found `u64`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -0,0 +1,21 @@
//@ check-pass
// This is a regression test for #128016.
macro_rules! len_inner {
() => {
BAR
};
}
macro_rules! len {
() => {
len_inner!()
};
}
const BAR: usize = 0;
fn main() {
let val: [bool; len!()] = [];
}

View file

@ -0,0 +1,13 @@
//@ check-pass
macro_rules! len {
($x:ident) => {
$x
};
}
fn bar<const N: usize>() {
let val: [bool; len!(N)] = [true; N];
}
fn main() {}

View file

@ -0,0 +1,13 @@
// This is a regression test for #128016.
macro_rules! len {
() => {
target
//~^ ERROR cannot find value `target`
};
}
fn main() {
let val: [str; len!()] = [];
//~^ ERROR the size for values
}

View file

@ -0,0 +1,24 @@
error[E0425]: cannot find value `target` in this scope
--> $DIR/trivial-const-arg-macro-res-error.rs:5:9
|
LL | target
| ^^^^^^ not found in this scope
...
LL | let val: [str; len!()] = [];
| ------ in this macro invocation
|
= note: this error originates in the macro `len` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/trivial-const-arg-macro-res-error.rs:11:14
|
LL | let val: [str; len!()] = [];
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: slice and array elements must have `Sized` type
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`.

View file

@ -0,0 +1,15 @@
//@ check-pass
// This is a regression test for #128016.
macro_rules! len {
() => {
BAR
};
}
const BAR: usize = 0;
fn main() {
let val: [bool; len!()] = [];
}

View file

@ -8,6 +8,7 @@ trait Q {
impl<const N: u64> Q for [u8; N] {} impl<const N: u64> Q for [u8; N] {}
//~^ ERROR not all trait items implemented //~^ ERROR not all trait items implemented
//~| ERROR the constant `N` is not of type `usize` //~| ERROR the constant `N` is not of type `usize`
//~| ERROR mismatched types
pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {} pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
//~^ ERROR the constant `13` is not of type `u64` //~^ ERROR the constant `13` is not of type `u64`

View file

@ -14,7 +14,7 @@ LL | impl<const N: u64> Q for [u8; N] {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `ASSOC` in implementation | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `ASSOC` in implementation
error: the constant `13` is not of type `u64` error: the constant `13` is not of type `u64`
--> $DIR/type_mismatch.rs:12:26 --> $DIR/type_mismatch.rs:13:26
| |
LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {} LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
| ^^^^^^^^ expected `u64`, found `usize` | ^^^^^^^^ expected `u64`, found `usize`
@ -28,14 +28,20 @@ LL | impl<const N: u64> Q for [u8; N] {}
| unsatisfied trait bound introduced here | unsatisfied trait bound introduced here
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:12:20 --> $DIR/type_mismatch.rs:13:20
| |
LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {} LL | pub fn q_user() -> [u8; <[u8; 13] as Q>::ASSOC] {}
| ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; <[u8; 13] as Q>::ASSOC]`, found `()` | ------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; <[u8; 13] as Q>::ASSOC]`, found `()`
| | | |
| implicitly returns `()` as its body has no tail or `return` expression | implicitly returns `()` as its body has no tail or `return` expression
error: aborting due to 4 previous errors error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:8:31
|
LL | impl<const N: u64> Q for [u8; N] {}
| ^ expected `usize`, found `u64`
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0046, E0308. Some errors have detailed explanations: E0046, E0308.
For more information about an error, try `rustc --explain E0046`. For more information about an error, try `rustc --explain E0046`.

View file

@ -14,8 +14,8 @@ mod v20 {
//~^ ERROR cannot find value `v8` in this scope //~^ ERROR cannot find value `v8` in this scope
//~| ERROR cannot find function `v6` in this scope //~| ERROR cannot find function `v6` in this scope
pub struct v17<const v10: usize, const v7: v11> { pub struct v17<const v10: usize, const v7: v11> {
//~^ WARN type `v17` should have an upper camel case name //~^ WARN type `v17` should have an upper camel case name
//~| ERROR `[[usize; v4]; v4]` is forbidden as the type of a const generic parameter //~| ERROR `[[usize; v4]; v4]` is forbidden as the type of a const generic parameter
_p: (), _p: (),
} }
@ -25,10 +25,10 @@ mod v20 {
} }
impl<const v10: usize> v17<v10, v2> { impl<const v10: usize> v17<v10, v2> {
//~^ ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0} //~^ ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
//~| ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0} //~| ERROR maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
pub const fn v21() -> v18 { pub const fn v21() -> v18 {
//~^ ERROR cannot find type `v18` in this scope //~^ ERROR cannot find type `v18` in this scope
v18 { _p: () } v18 { _p: () }
//~^ ERROR cannot find struct, variant or union type `v18` in this scope //~^ ERROR cannot find struct, variant or union type `v18` in this scope
} }

View file

@ -72,13 +72,13 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
LL + #![feature(adt_const_params)] LL + #![feature(adt_const_params)]
| |
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0} error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
--> $DIR/unevaluated-const-ice-119731.rs:27:37 --> $DIR/unevaluated-const-ice-119731.rs:27:37
| |
LL | impl<const v10: usize> v17<v10, v2> { LL | impl<const v10: usize> v17<v10, v2> {
| ^^ | ^^
error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#0} error: maximum number of nodes exceeded in constant v20::v17::<v10, v2>::{constant#1}
--> $DIR/unevaluated-const-ice-119731.rs:27:37 --> $DIR/unevaluated-const-ice-119731.rs:27:37
| |
LL | impl<const v10: usize> v17<v10, v2> { LL | impl<const v10: usize> v17<v10, v2> {

View file

@ -2,108 +2,108 @@
#![feature(generic_const_exprs)] #![feature(generic_const_exprs)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
fn foo<const W: usize, const H: usize>(v: [[u32;H+1]; W]) -> [[u32; W+1]; H] { fn foo<const W: usize, const H: usize>(v: [[u32; H + 1]; W]) -> [[u32; W + 1]; H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR cannot transmute //~^ ERROR cannot transmute
} }
} }
fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] { fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
//~^ ERROR the constant `W` is not of type `usize` //~^ ERROR: the constant `W` is not of type `usize`
unsafe { //~| ERROR: mismatched types
std::mem::transmute(v) //~| ERROR: mismatched types
//~^ ERROR the constant `W` is not of type `usize` unsafe {
} std::mem::transmute(v)
//~^ ERROR: the constant `W` is not of type `usize`
}
} }
fn baz<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H * H] { fn baz<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H * H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR cannot transmute //~^ ERROR cannot transmute
} }
} }
fn overflow(v: [[[u32; 8888888]; 9999999]; 777777777]) -> [[[u32; 9999999]; 777777777]; 8888888] { fn overflow(v: [[[u32; 8888888]; 9999999]; 777777777]) -> [[[u32; 9999999]; 777777777]; 8888888] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR cannot transmute //~^ ERROR cannot transmute
} }
} }
fn transpose<const W: usize, const H: usize>(v: [[u32;H]; W]) -> [[u32; W]; H] { fn transpose<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn ident<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; H]; W] { fn ident<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; H]; W] {
unsafe { unsafe { std::mem::transmute(v) }
std::mem::transmute(v)
}
} }
fn flatten<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H] { fn flatten<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn coagulate<const W: usize, const H: usize>(v: [u32; H*W]) -> [[u32; W];H] { fn coagulate<const W: usize, const H: usize>(v: [u32; H * W]) -> [[u32; W]; H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn flatten_3d<const W: usize, const H: usize, const D: usize>( fn flatten_3d<const W: usize, const H: usize, const D: usize>(
v: [[[u32; D]; H]; W] v: [[[u32; D]; H]; W],
) -> [u32; D * W * H] { ) -> [u32; D * W * H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn flatten_somewhat<const W: usize, const H: usize, const D: usize>( fn flatten_somewhat<const W: usize, const H: usize, const D: usize>(
v: [[[u32; D]; H]; W] v: [[[u32; D]; H]; W],
) -> [[u32; D * W]; H] { ) -> [[u32; D * W]; H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn known_size<const L: usize>(v: [u16; L]) -> [u8; L * 2] { fn known_size<const L: usize>(v: [u16; L]) -> [u8; L * 2] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn condense_bytes<const L: usize>(v: [u8; L * 2]) -> [u16; L] { fn condense_bytes<const L: usize>(v: [u8; L * 2]) -> [u16; L] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn singleton_each<const L: usize>(v: [u8; L]) -> [[u8;1]; L] { fn singleton_each<const L: usize>(v: [u8; L]) -> [[u8; 1]; L] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn transpose_with_const<const W: usize, const H: usize>( fn transpose_with_const<const W: usize, const H: usize>(
v: [[u32; 2 * H]; W + W] v: [[u32; 2 * H]; W + W],
) -> [[u32; W + W]; 2 * H] { ) -> [[u32; W + W]; 2 * H] {
unsafe { unsafe {
std::mem::transmute(v) std::mem::transmute(v)
//~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types
} }
} }
fn main() {} fn main() {}

View file

@ -5,119 +5,132 @@ LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^^^^^^^^^^^^^ expected `usize`, found `bool` | ^^^^^^^^^^^^^ expected `usize`, found `bool`
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:7:5 --> $DIR/transmute-fail.rs:7:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[u32; H+1]; W]` (size can vary because of [u32; H+1]) = note: source type: `[[u32; H + 1]; W]` (size can vary because of [u32; H + 1])
= note: target type: `[[u32; W+1]; H]` (size can vary because of [u32; W+1]) = note: target type: `[[u32; W + 1]; H]` (size can vary because of [u32; W + 1])
error: the constant `W` is not of type `usize` error: the constant `W` is not of type `usize`
--> $DIR/transmute-fail.rs:15:5 --> $DIR/transmute-fail.rs:17:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `bool` | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `bool`
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:22:5 --> $DIR/transmute-fail.rs:24:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[u32; H]; W]` (size can vary because of [u32; H]) = note: source type: `[[u32; H]; W]` (size can vary because of [u32; H])
= note: target type: `[u32; W * H * H]` (this type does not have a fixed size) = note: target type: `[u32; W * H * H]` (this type does not have a fixed size)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:29:5 --> $DIR/transmute-fail.rs:31:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[u32; 8888888]; 9999999]` are too big for the current architecture) = note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[u32; 8888888]; 9999999]` are too big for the current architecture)
= note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture) = note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[u32; 9999999]; 777777777]` are too big for the current architecture)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:36:5 --> $DIR/transmute-fail.rs:38:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[u32; H]; W]` (size can vary because of [u32; H]) = note: source type: `[[u32; H]; W]` (size can vary because of [u32; H])
= note: target type: `[[u32; W]; H]` (size can vary because of [u32; W]) = note: target type: `[[u32; W]; H]` (size can vary because of [u32; W])
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:49:5 --> $DIR/transmute-fail.rs:49:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[u32; H]; W]` (size can vary because of [u32; H]) = note: source type: `[[u32; H]; W]` (size can vary because of [u32; H])
= note: target type: `[u32; W * H]` (this type does not have a fixed size) = note: target type: `[u32; W * H]` (this type does not have a fixed size)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:56:5 --> $DIR/transmute-fail.rs:56:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[u32; H*W]` (this type does not have a fixed size) = note: source type: `[u32; H * W]` (this type does not have a fixed size)
= note: target type: `[[u32; W]; H]` (size can vary because of [u32; W]) = note: target type: `[[u32; W]; H]` (size can vary because of [u32; W])
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:65:5 --> $DIR/transmute-fail.rs:65:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[[u32; D]; H]; W]` (size can vary because of [u32; D]) = note: source type: `[[[u32; D]; H]; W]` (size can vary because of [u32; D])
= note: target type: `[u32; D * W * H]` (this type does not have a fixed size) = note: target type: `[u32; D * W * H]` (this type does not have a fixed size)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:74:5 --> $DIR/transmute-fail.rs:74:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[[u32; D]; H]; W]` (size can vary because of [u32; D]) = note: source type: `[[[u32; D]; H]; W]` (size can vary because of [u32; D])
= note: target type: `[[u32; D * W]; H]` (size can vary because of [u32; D * W]) = note: target type: `[[u32; D * W]; H]` (size can vary because of [u32; D * W])
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:81:5 --> $DIR/transmute-fail.rs:81:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[u16; L]` (this type does not have a fixed size) = note: source type: `[u16; L]` (this type does not have a fixed size)
= note: target type: `[u8; L * 2]` (this type does not have a fixed size) = note: target type: `[u8; L * 2]` (this type does not have a fixed size)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:88:5 --> $DIR/transmute-fail.rs:88:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[u8; L * 2]` (this type does not have a fixed size) = note: source type: `[u8; L * 2]` (this type does not have a fixed size)
= note: target type: `[u16; L]` (this type does not have a fixed size) = note: target type: `[u16; L]` (this type does not have a fixed size)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:95:5 --> $DIR/transmute-fail.rs:95:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[u8; L]` (this type does not have a fixed size) = note: source type: `[u8; L]` (this type does not have a fixed size)
= note: target type: `[[u8; 1]; L]` (this type does not have a fixed size) = note: target type: `[[u8; 1]; L]` (this type does not have a fixed size)
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> $DIR/transmute-fail.rs:104:5 --> $DIR/transmute-fail.rs:104:9
| |
LL | std::mem::transmute(v) LL | std::mem::transmute(v)
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
= note: source type: `[[u32; 2 * H]; W + W]` (size can vary because of [u32; 2 * H]) = note: source type: `[[u32; 2 * H]; W + W]` (size can vary because of [u32; 2 * H])
= note: target type: `[[u32; W + W]; 2 * H]` (size can vary because of [u32; W + W]) = note: target type: `[[u32; W + W]; 2 * H]` (size can vary because of [u32; W + W])
error: aborting due to 14 previous errors error[E0308]: mismatched types
--> $DIR/transmute-fail.rs:12:53
|
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^ expected `usize`, found `bool`
For more information about this error, try `rustc --explain E0512`. error[E0308]: mismatched types
--> $DIR/transmute-fail.rs:12:67
|
LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
| ^ expected `usize`, found `bool`
error: aborting due to 16 previous errors
Some errors have detailed explanations: E0308, E0512.
For more information about an error, try `rustc --explain E0308`.

View file

@ -1,10 +1,12 @@
fn foo<const N: usize>() -> [u8; N] { fn foo<const N: usize>() -> [u8; N] {
bar::<N>() bar::<N>()
//~^ ERROR the constant `N` is not of type `u8` //~^ ERROR the constant `N` is not of type `u8`
//~| ERROR: mismatched types
} }
fn bar<const N: u8>() -> [u8; N] {} fn bar<const N: u8>() -> [u8; N] {}
//~^ ERROR the constant `N` is not of type `usize` //~^ ERROR the constant `N` is not of type `usize`
//~| ERROR: mismatched types
//~| ERROR mismatched types //~| ERROR mismatched types
fn main() {} fn main() {}

View file

@ -1,5 +1,5 @@
error: the constant `N` is not of type `usize` error: the constant `N` is not of type `usize`
--> $DIR/type_mismatch.rs:6:26 --> $DIR/type_mismatch.rs:7:26
| |
LL | fn bar<const N: u8>() -> [u8; N] {} LL | fn bar<const N: u8>() -> [u8; N] {}
| ^^^^^^^ expected `usize`, found `u8` | ^^^^^^^ expected `usize`, found `u8`
@ -11,19 +11,31 @@ LL | bar::<N>()
| ^ expected `u8`, found `usize` | ^ expected `u8`, found `usize`
| |
note: required by a const generic parameter in `bar` note: required by a const generic parameter in `bar`
--> $DIR/type_mismatch.rs:6:8 --> $DIR/type_mismatch.rs:7:8
| |
LL | fn bar<const N: u8>() -> [u8; N] {} LL | fn bar<const N: u8>() -> [u8; N] {}
| ^^^^^^^^^^^ required by this const generic parameter in `bar` | ^^^^^^^^^^^ required by this const generic parameter in `bar`
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:6:26 --> $DIR/type_mismatch.rs:7:26
| |
LL | fn bar<const N: u8>() -> [u8; N] {} LL | fn bar<const N: u8>() -> [u8; N] {}
| --- ^^^^^^^ expected `[u8; N]`, found `()` | --- ^^^^^^^ expected `[u8; N]`, found `()`
| | | |
| implicitly returns `()` as its body has no tail or `return` expression | implicitly returns `()` as its body has no tail or `return` expression
error: aborting due to 3 previous errors error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:2:11
|
LL | bar::<N>()
| ^ expected `u8`, found `usize`
error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:7:31
|
LL | fn bar<const N: u8>() -> [u8; N] {}
| ^ expected `usize`, found `u8`
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0308`. For more information about this error, try `rustc --explain E0308`.

View file

@ -1,10 +1,10 @@
error[E0391]: cycle detected when simplifying constant for the type system `Foo::{constant#0}` error[E0391]: cycle detected when simplifying constant for the type system `Foo::B::{constant#0}`
--> $DIR/issue-36163.rs:4:9 --> $DIR/issue-36163.rs:4:9
| |
LL | B = A, LL | B = A,
| ^ | ^
| |
note: ...which requires const-evaluating + checking `Foo::{constant#0}`... note: ...which requires const-evaluating + checking `Foo::B::{constant#0}`...
--> $DIR/issue-36163.rs:4:9 --> $DIR/issue-36163.rs:4:9
| |
LL | B = A, LL | B = A,
@ -19,7 +19,7 @@ note: ...which requires const-evaluating + checking `A`...
| |
LL | const A: isize = Foo::B as isize; LL | const A: isize = Foo::B as isize;
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
= note: ...which again requires simplifying constant for the type system `Foo::{constant#0}`, completing the cycle = note: ...which again requires simplifying constant for the type system `Foo::B::{constant#0}`, completing the cycle
note: cycle used when checking that `Foo` is well-formed note: cycle used when checking that `Foo` is well-formed
--> $DIR/issue-36163.rs:3:1 --> $DIR/issue-36163.rs:3:1
| |

View file

@ -0,0 +1,5 @@
//@ check-pass
// this doesn't really have any user facing impact....
fn main() {}

View file

@ -2,12 +2,13 @@ struct ErrorKind;
struct Error(ErrorKind); struct Error(ErrorKind);
impl Fn(&isize) for Error { impl Fn(&isize) for Error {
//~^ ERROR manual implementations of `Fn` are experimental [E0183] //~^ ERROR manual implementations of `Fn` are experimental [E0183]
//~^^ ERROR associated item constraints are not allowed here [E0229] //~| ERROR associated item constraints are not allowed here [E0229]
//~| ERROR not all trait items implemented //~| ERROR not all trait items implemented
//~| ERROR expected a `FnMut(&isize)` closure, found `Error` //~| ERROR expected a `FnMut(&isize)` closure, found `Error`
fn foo<const N: usize>(&self) -> Self::B<{ N }>; fn foo<const N: usize>(&self) -> Self::B<{ N }>;
//~^ ERROR associated function in `impl` without body //~^ ERROR associated function in `impl` without body
//~^^ ERROR method `foo` is not a member of trait `Fn` [E0407] //~| ERROR method `foo` is not a member of trait `Fn` [E0407]
//~^^^ ERROR associated type `B` not found for `Self` [E0220] //~| ERROR associated type `B` not found for `Self` [E0220]
//~| ERROR: associated type `B` not found for `Self`
} }
fn main() {} fn main() {}

View file

@ -56,7 +56,15 @@ error[E0220]: associated type `B` not found for `Self`
LL | fn foo<const N: usize>(&self) -> Self::B<{ N }>; LL | fn foo<const N: usize>(&self) -> Self::B<{ N }>;
| ^ help: `Self` has the following associated type: `Output` | ^ help: `Self` has the following associated type: `Output`
error: aborting due to 7 previous errors error[E0220]: associated type `B` not found for `Self`
--> $DIR/issue-95023.rs:8:44
|
LL | fn foo<const N: usize>(&self) -> Self::B<{ N }>;
| ^ help: `Self` has the following associated type: `Output`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0046, E0183, E0220, E0229, E0277, E0407. Some errors have detailed explanations: E0046, E0183, E0220, E0229, E0277, E0407.
For more information about an error, try `rustc --explain E0046`. For more information about an error, try `rustc --explain E0046`.

View file

@ -14,5 +14,6 @@ struct Wrapper<const C: <i32 as Trait>::Type> {}
impl<const C: usize> Wrapper<C> {} impl<const C: usize> Wrapper<C> {}
//~^ ERROR the constant `C` is not of type `<i32 as Trait>::Type` //~^ ERROR the constant `C` is not of type `<i32 as Trait>::Type`
//~| ERROR: mismatched types
fn main() {} fn main() {}

View file

@ -20,5 +20,17 @@ note: required by a const generic parameter in `Wrapper`
LL | struct Wrapper<const C: <i32 as Trait>::Type> {} LL | struct Wrapper<const C: <i32 as Trait>::Type> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `Wrapper` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `Wrapper`
error: aborting due to 2 previous errors error[E0308]: mismatched types
--> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:15:30
|
LL | impl<const C: usize> Wrapper<C> {}
| ^ expected associated type, found `usize`
|
= note: expected associated type `<i32 as Trait>::Type`
found type `usize`
= help: consider constraining the associated type `<i32 as Trait>::Type` to `usize`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -6,6 +6,7 @@
struct S<const L: usize>; struct S<const L: usize>;
impl<const N: i32> Copy for S<N> {} impl<const N: i32> Copy for S<N> {}
//~^ ERROR: mismatched types
impl<const M: usize> Copy for S<M> {} impl<const M: usize> Copy for S<M> {}
//~^ ERROR: conflicting implementations of trait `Copy` for type `S<_>` //~^ ERROR: conflicting implementations of trait `Copy` for type `S<_>`

View file

@ -1,11 +1,19 @@
error[E0119]: conflicting implementations of trait `Copy` for type `S<_>` error[E0119]: conflicting implementations of trait `Copy` for type `S<_>`
--> $DIR/bad-const-wf-doesnt-specialize.rs:9:1 --> $DIR/bad-const-wf-doesnt-specialize.rs:10:1
| |
LL | impl<const N: i32> Copy for S<N> {} LL | impl<const N: i32> Copy for S<N> {}
| -------------------------------- first implementation here | -------------------------------- first implementation here
LL |
LL | impl<const M: usize> Copy for S<M> {} LL | impl<const M: usize> Copy for S<M> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S<_>` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S<_>`
error: aborting due to 1 previous error error[E0308]: mismatched types
--> $DIR/bad-const-wf-doesnt-specialize.rs:8:31
|
LL | impl<const N: i32> Copy for S<N> {}
| ^ expected `usize`, found `i32`
For more information about this error, try `rustc --explain E0119`. error: aborting due to 2 previous errors
Some errors have detailed explanations: E0119, E0308.
For more information about an error, try `rustc --explain E0119`.

View file

@ -6,7 +6,8 @@ mod assert {
pub fn is_transmutable<Src, const ASSUME_ALIGNMENT: bool>() pub fn is_transmutable<Src, const ASSUME_ALIGNMENT: bool>()
where where
Dst: BikeshedIntrinsicFrom<Src, ASSUME_ALIGNMENT>, //~ ERROR cannot find type `Dst` in this scope Dst: BikeshedIntrinsicFrom<Src, ASSUME_ALIGNMENT>, //~ ERROR cannot find type `Dst` in this scope
//~^ the constant `ASSUME_ALIGNMENT` is not of type `Assume` //~| the constant `ASSUME_ALIGNMENT` is not of type `Assume`
//~| ERROR: mismatched types
{ {
} }
} }

View file

@ -13,6 +13,13 @@ LL | Dst: BikeshedIntrinsicFrom<Src, ASSUME_ALIGNMENT>,
note: required by a const generic parameter in `BikeshedIntrinsicFrom` note: required by a const generic parameter in `BikeshedIntrinsicFrom`
--> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL --> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL
error: aborting due to 2 previous errors error[E0308]: mismatched types
--> $DIR/issue-101739-1.rs:8:41
|
LL | Dst: BikeshedIntrinsicFrom<Src, ASSUME_ALIGNMENT>,
| ^^^^^^^^^^^^^^^^ expected `Assume`, found `bool`
For more information about this error, try `rustc --explain E0412`. error: aborting due to 3 previous errors
Some errors have detailed explanations: E0308, E0412.
For more information about an error, try `rustc --explain E0308`.

View file

@ -14,19 +14,23 @@ mod assert {
const ASSUME_VISIBILITY: bool, const ASSUME_VISIBILITY: bool,
>() >()
where where
Dst: BikeshedIntrinsicFrom< //~ ERROR trait takes at most 2 generic arguments but 5 generic arguments were supplied Dst: BikeshedIntrinsicFrom<
Src, //~^ ERROR trait takes at most 2 generic arguments but 5 generic arguments were supplied
ASSUME_ALIGNMENT, Src,
ASSUME_LIFETIMES, ASSUME_ALIGNMENT, //~ ERROR: mismatched types
ASSUME_VALIDITY, ASSUME_LIFETIMES,
ASSUME_VISIBILITY, ASSUME_VALIDITY,
>, ASSUME_VISIBILITY,
{} >,
{
}
} }
fn via_const() { fn via_const() {
#[repr(C)] struct Src; #[repr(C)]
#[repr(C)] struct Dst; struct Src;
#[repr(C)]
struct Dst;
const FALSE: bool = false; const FALSE: bool = false;

View file

@ -3,14 +3,21 @@ error[E0107]: trait takes at most 2 generic arguments but 5 generic arguments we
| |
LL | Dst: BikeshedIntrinsicFrom< LL | Dst: BikeshedIntrinsicFrom<
| ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments | ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments
LL | Src, ...
LL | ASSUME_ALIGNMENT, LL | ASSUME_ALIGNMENT,
| _____________________________- | _________________________________-
LL | | ASSUME_LIFETIMES, LL | | ASSUME_LIFETIMES,
LL | | ASSUME_VALIDITY, LL | | ASSUME_VALIDITY,
LL | | ASSUME_VISIBILITY, LL | | ASSUME_VISIBILITY,
| |_____________________________- help: remove the unnecessary generic arguments | |_________________________________- help: remove the unnecessary generic arguments
error: aborting due to 1 previous error error[E0308]: mismatched types
--> $DIR/issue-101739-2.rs:20:17
|
LL | ASSUME_ALIGNMENT,
| ^^^^^^^^^^^^^^^^ expected `Assume`, found `bool`
For more information about this error, try `rustc --explain E0107`. error: aborting due to 2 previous errors
Some errors have detailed explanations: E0107, E0308.
For more information about an error, try `rustc --explain E0107`.

View file

@ -3,16 +3,18 @@
// of an impl fn produces a type mismatch error instead of triggering // of an impl fn produces a type mismatch error instead of triggering
// a const eval cycle // a const eval cycle
trait Trait { trait Trait {
fn func<const N: u32>() -> [ (); N ]; //~ ERROR the constant `N` is not of type `usize` fn func<const N: u32>() -> [(); N];
//~^ ERROR: the constant `N` is not of type `usize`
//~| ERROR: mismatched types
} }
struct S {} struct S {}
#[allow(unused_braces)] #[allow(unused_braces)]
impl Trait for S { impl Trait for S {
fn func<const N: u32>() -> [ (); { () }] { //~ ERROR mismatched types fn func<const N: u32>() -> [(); { () }] {
//~^ ERROR mismatched types
N N
} }
} }

View file

@ -1,15 +1,21 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/const-in-impl-fn-return-type.rs:15:40 --> $DIR/const-in-impl-fn-return-type.rs:16:39
| |
LL | fn func<const N: u32>() -> [ (); { () }] { LL | fn func<const N: u32>() -> [(); { () }] {
| ^^ expected `usize`, found `()` | ^^ expected `usize`, found `()`
error: the constant `N` is not of type `usize` error: the constant `N` is not of type `usize`
--> $DIR/const-in-impl-fn-return-type.rs:8:32 --> $DIR/const-in-impl-fn-return-type.rs:7:32
| |
LL | fn func<const N: u32>() -> [ (); N ]; LL | fn func<const N: u32>() -> [(); N];
| ^^^^^^^^^ expected `usize`, found `u32` | ^^^^^^^ expected `usize`, found `u32`
error: aborting due to 2 previous errors error[E0308]: mismatched types
--> $DIR/const-in-impl-fn-return-type.rs:7:37
|
LL | fn func<const N: u32>() -> [(); N];
| ^ expected `usize`, found `u32`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`. For more information about this error, try `rustc --explain E0308`.