Rollup merge of #137298 - compiler-errors:mir-wf, r=lcnr
Check signature WF when lowering MIR body Alternative to #137233. https://github.com/rust-lang/rust/pull/137233#issuecomment-2667879143 Fixes https://github.com/rust-lang/rust/issues/137186 We do this check in `mir_drops_elaborated_and_const_checked` and not during `mir_promoted` because that may result in borrowck cycles if WF requires looking into an opaque hidden type. This causes some TAIT tests to fail unnecessarily. r? lcnr try-job: test-various
This commit is contained in:
commit
5df9a9f45c
33 changed files with 176 additions and 76 deletions
|
@ -745,14 +745,10 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
match tcx.def_kind(def_id) {
|
match tcx.def_kind(def_id) {
|
||||||
DefKind::Static { .. } => {
|
DefKind::Static { .. } => {
|
||||||
tcx.ensure_ok().typeck(def_id);
|
|
||||||
maybe_check_static_with_link_section(tcx, def_id);
|
|
||||||
check_static_inhabited(tcx, def_id);
|
check_static_inhabited(tcx, def_id);
|
||||||
check_static_linkage(tcx, def_id);
|
check_static_linkage(tcx, def_id);
|
||||||
}
|
}
|
||||||
DefKind::Const => {
|
DefKind::Const => {}
|
||||||
tcx.ensure_ok().typeck(def_id);
|
|
||||||
}
|
|
||||||
DefKind::Enum => {
|
DefKind::Enum => {
|
||||||
check_enum(tcx, def_id);
|
check_enum(tcx, def_id);
|
||||||
}
|
}
|
||||||
|
@ -766,7 +762,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||||
ExternAbi::Rust,
|
ExternAbi::Rust,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Everything else is checked entirely within check_item_body
|
|
||||||
}
|
}
|
||||||
DefKind::Impl { of_trait } => {
|
DefKind::Impl { of_trait } => {
|
||||||
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
|
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
|
||||||
|
|
|
@ -145,7 +145,7 @@ pub fn forbid_intrinsic_abi(tcx: TyCtxt<'_>, sp: Span, abi: ExternAbi) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
|
pub(super) fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
|
||||||
// Only restricted on wasm target for now
|
// Only restricted on wasm target for now
|
||||||
if !tcx.sess.target.is_like_wasm {
|
if !tcx.sess.target.is_like_wasm {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -201,7 +201,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
|
||||||
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
|
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
|
||||||
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
|
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
|
||||||
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)),
|
hir::Node::OpaqueTy(_) => Ok(crate::check::check::check_item_type(tcx, def_id)),
|
||||||
_ => unreachable!(),
|
_ => unreachable!("{node:?}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(generics) = node.generics() {
|
if let Some(generics) = node.generics() {
|
||||||
|
@ -1108,7 +1108,13 @@ fn check_associated_item(
|
||||||
let ty = tcx.type_of(item.def_id).instantiate_identity();
|
let ty = tcx.type_of(item.def_id).instantiate_identity();
|
||||||
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
|
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
|
||||||
wfcx.register_wf_obligation(span, loc, ty.into());
|
wfcx.register_wf_obligation(span, loc, ty.into());
|
||||||
check_sized_if_body(wfcx, item.def_id.expect_local(), ty, Some(span));
|
check_sized_if_body(
|
||||||
|
wfcx,
|
||||||
|
item.def_id.expect_local(),
|
||||||
|
ty,
|
||||||
|
Some(span),
|
||||||
|
ObligationCauseCode::SizedConstOrStatic,
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
ty::AssocKind::Fn => {
|
ty::AssocKind::Fn => {
|
||||||
|
@ -1354,7 +1360,7 @@ fn check_item_type(
|
||||||
traits::ObligationCause::new(
|
traits::ObligationCause::new(
|
||||||
ty_span,
|
ty_span,
|
||||||
wfcx.body_def_id,
|
wfcx.body_def_id,
|
||||||
ObligationCauseCode::WellFormed(None),
|
ObligationCauseCode::SizedConstOrStatic,
|
||||||
),
|
),
|
||||||
wfcx.param_env,
|
wfcx.param_env,
|
||||||
item_ty,
|
item_ty,
|
||||||
|
@ -1698,6 +1704,7 @@ fn check_fn_or_method<'tcx>(
|
||||||
hir::FnRetTy::Return(ty) => Some(ty.span),
|
hir::FnRetTy::Return(ty) => Some(ty.span),
|
||||||
hir::FnRetTy::DefaultReturn(_) => None,
|
hir::FnRetTy::DefaultReturn(_) => None,
|
||||||
},
|
},
|
||||||
|
ObligationCauseCode::SizedReturnType,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1706,13 +1713,14 @@ fn check_sized_if_body<'tcx>(
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
maybe_span: Option<Span>,
|
maybe_span: Option<Span>,
|
||||||
|
code: ObligationCauseCode<'tcx>,
|
||||||
) {
|
) {
|
||||||
let tcx = wfcx.tcx();
|
let tcx = wfcx.tcx();
|
||||||
if let Some(body) = tcx.hir_maybe_body_owned_by(def_id) {
|
if let Some(body) = tcx.hir_maybe_body_owned_by(def_id) {
|
||||||
let span = maybe_span.unwrap_or(body.value.span);
|
let span = maybe_span.unwrap_or(body.value.span);
|
||||||
|
|
||||||
wfcx.register_bound(
|
wfcx.register_bound(
|
||||||
ObligationCause::new(span, def_id, traits::ObligationCauseCode::SizedReturnType),
|
ObligationCause::new(span, def_id, code),
|
||||||
wfcx.param_env,
|
wfcx.param_env,
|
||||||
ty,
|
ty,
|
||||||
tcx.require_lang_item(LangItem::Sized, Some(span)),
|
tcx.require_lang_item(LangItem::Sized, Some(span)),
|
||||||
|
|
|
@ -212,7 +212,10 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||||
tcx.par_hir_body_owners(|item_def_id| {
|
tcx.par_hir_body_owners(|item_def_id| {
|
||||||
let def_kind = tcx.def_kind(item_def_id);
|
let def_kind = tcx.def_kind(item_def_id);
|
||||||
match def_kind {
|
match def_kind {
|
||||||
DefKind::Static { .. } => tcx.ensure_ok().eval_static_initializer(item_def_id),
|
DefKind::Static { .. } => {
|
||||||
|
tcx.ensure_ok().eval_static_initializer(item_def_id);
|
||||||
|
check::maybe_check_static_with_link_section(tcx, item_def_id);
|
||||||
|
}
|
||||||
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
|
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
|
||||||
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
|
let instance = ty::Instance::new(item_def_id.into(), ty::GenericArgs::empty());
|
||||||
let cid = GlobalId { instance, promoted: None };
|
let cid = GlobalId { instance, promoted: None };
|
||||||
|
@ -223,12 +226,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: Remove this when we implement creating `DefId`s
|
|
||||||
// for anon constants during their parents' typeck.
|
|
||||||
// Typeck all body owners in parallel will produce queries
|
|
||||||
// cycle errors because it may typeck on anon constants directly.
|
|
||||||
tcx.par_hir_body_owners(|item_def_id| {
|
tcx.par_hir_body_owners(|item_def_id| {
|
||||||
let def_kind = tcx.def_kind(item_def_id);
|
let def_kind = tcx.def_kind(item_def_id);
|
||||||
|
// Skip `AnonConst`s because we feed their `type_of`.
|
||||||
if !matches!(def_kind, DefKind::AnonConst) {
|
if !matches!(def_kind, DefKind::AnonConst) {
|
||||||
tcx.ensure_ok().typeck(item_def_id);
|
tcx.ensure_ok().typeck(item_def_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1806,7 +1806,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
crate::GatherLocalsVisitor::new(&fcx).visit_body(body);
|
crate::GatherLocalsVisitor::new(&fcx).visit_body(body);
|
||||||
|
|
||||||
let ty = fcx.check_expr_with_expectation(body.value, expected);
|
let ty = fcx.check_expr_with_expectation(body.value, expected);
|
||||||
fcx.require_type_is_sized(ty, body.value.span, ObligationCauseCode::ConstSized);
|
fcx.require_type_is_sized(ty, body.value.span, ObligationCauseCode::SizedConstOrStatic);
|
||||||
fcx.write_ty(block.hir_id, ty);
|
fcx.write_ty(block.hir_id, ty);
|
||||||
ty
|
ty
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,7 @@ pub enum ObligationCauseCode<'tcx> {
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Constant expressions must be sized.
|
/// Constant expressions must be sized.
|
||||||
ConstSized,
|
SizedConstOrStatic,
|
||||||
|
|
||||||
/// `static` items must have `Sync` type.
|
/// `static` items must have `Sync` type.
|
||||||
SharedStatic,
|
SharedStatic,
|
||||||
|
|
|
@ -513,6 +513,24 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
|
||||||
body.tainted_by_errors = Some(error_reported);
|
body.tainted_by_errors = Some(error_reported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Also taint the body if it's within a top-level item that is not well formed.
|
||||||
|
//
|
||||||
|
// We do this check here and not during `mir_promoted` because that may result
|
||||||
|
// in borrowck cycles if WF requires looking into an opaque hidden type.
|
||||||
|
let root = tcx.typeck_root_def_id(def.to_def_id());
|
||||||
|
match tcx.def_kind(root) {
|
||||||
|
DefKind::Fn
|
||||||
|
| DefKind::AssocFn
|
||||||
|
| DefKind::Static { .. }
|
||||||
|
| DefKind::Const
|
||||||
|
| DefKind::AssocConst => {
|
||||||
|
if let Err(guar) = tcx.check_well_formed(root.expect_local()) {
|
||||||
|
body.tainted_by_errors = Some(guar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
run_analysis_to_runtime_passes(tcx, &mut body);
|
run_analysis_to_runtime_passes(tcx, &mut body);
|
||||||
|
|
||||||
tcx.alloc_steal_mir(body)
|
tcx.alloc_steal_mir(body)
|
||||||
|
|
|
@ -3126,8 +3126,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ObligationCauseCode::ConstSized => {
|
ObligationCauseCode::SizedConstOrStatic => {
|
||||||
err.note("constant expressions must have a statically known size");
|
err.note("statics and constants must have a statically known size");
|
||||||
}
|
}
|
||||||
ObligationCauseCode::InlineAsmSized => {
|
ObligationCauseCode::InlineAsmSized => {
|
||||||
err.note("all inline asm arguments must have a statically known size");
|
err.note("all inline asm arguments must have a statically known size");
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
//@ known-bug: rust-lang/rust#129095
|
//@ known-bug: rust-lang/rust#129095
|
||||||
//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+Inline -Zvalidate-mir
|
//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+Inline -Zvalidate-mir
|
||||||
|
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
|
pub fn function_with_bytes<const BYTES: &'static [u8; 4]>() -> &'static [u8] {
|
||||||
BYTES
|
BYTES
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
assert_eq!(function_with_bytes::<b"AAAAb">(), &[0x41, 0x41, 0x41, 0x41]);
|
assert_eq!(function_with_bytes::<b"AAAAA">(), &[0x41, 0x41, 0x41, 0x41]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ known-bug: #132960
|
//@ known-bug: #132960
|
||||||
|
|
||||||
#![feature(adt_const_params, const_ptr_read, generic_const_exprs)]
|
#![feature(adt_const_params, const_ptr_read, generic_const_exprs, unsized_const_params)]
|
||||||
|
|
||||||
const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
|
const fn concat_strs<const A: &'static str, const B: &'static str>() -> &'static str
|
||||||
where
|
where
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+Inline -Zvalidate-mir
|
//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+Inline -Zvalidate-mir
|
||||||
//@ only-x86_64
|
//@ only-x86_64
|
||||||
|
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
fn function_with_bytes<const BYTES:
|
fn function_with_bytes<const BYTES:
|
||||||
&'static [u8; 0xa9008fb6c9d81e42_0e25730562a601c8_u128]>() -> &'static [u8] {
|
&'static [u8; 0xa9008fb6c9d81e42_0e25730562a601c8_u128]>() -> &'static [u8] {
|
||||||
BYTES
|
BYTES
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
//@ known-bug: #135128
|
//@ known-bug: #135128
|
||||||
//@ compile-flags: -Copt-level=1 --edition=2021
|
//@ compile-flags: -Copt-level=1 --edition=2021
|
||||||
|
|
||||||
|
#![feature(trivial_bounds)]
|
||||||
|
|
||||||
async fn return_str() -> str
|
async fn return_str() -> str
|
||||||
where
|
where
|
||||||
str: Sized,
|
str: Sized,
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
//@compile-flags: -Zvalidate-mir -Zmir-enable-passes=+Inline -Copt-level=0 -Zmir-enable-passes=+GVN
|
//@compile-flags: -Zvalidate-mir -Zmir-enable-passes=+Inline -Copt-level=0 -Zmir-enable-passes=+GVN
|
||||||
//@ only-x86_64
|
//@ only-x86_64
|
||||||
|
|
||||||
|
#![feature(adt_const_params, unsized_const_params)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_u128]>(
|
fn function_with_bytes<const BYTES: &'static [u8; 0xc7b889180b67b07d_bc1a3c88783d35b5_u128]>(
|
||||||
) -> &'static [u8] {
|
) -> &'static [u8] {
|
||||||
BYTES
|
BYTES
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
#![feature(const_transmute)]
|
#![feature(const_transmute)]
|
||||||
|
|
||||||
const ZST: &[u8] = unsafe { std::mem::transmute(1usize) }; //~ ERROR cannot transmute between types of different sizes, or dependently-sized types
|
pub const ZST: &[u8] = unsafe { std::mem::transmute(1usize) }; //~ ERROR cannot transmute between types of different sizes, or dependently-sized types
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
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/issue-79494.rs:5:29
|
--> $DIR/issue-79494.rs:5:33
|
||||||
|
|
|
|
||||||
LL | const ZST: &[u8] = unsafe { std::mem::transmute(1usize) };
|
LL | pub const ZST: &[u8] = unsafe { std::mem::transmute(1usize) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: source type: `usize` (64 bits)
|
= note: source type: `usize` (64 bits)
|
||||||
= note: target type: `&[u8]` (128 bits)
|
= note: target type: `&[u8]` (128 bits)
|
||||||
|
|
|
@ -7,4 +7,5 @@
|
||||||
|
|
||||||
struct A;
|
struct A;
|
||||||
struct B;
|
struct B;
|
||||||
const S: A = B;
|
|
||||||
|
pub const S: A = B;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/track-diagnostics.rs:LL:CC
|
--> $DIR/track-diagnostics.rs:LL:CC
|
||||||
|
|
|
|
||||||
LL | const S: A = B;
|
LL | pub const S: A = B;
|
||||||
| ^ expected `A`, found `B`
|
| ^ expected `A`, found `B`
|
||||||
-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs:LL:CC
|
-Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs:LL:CC
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
|
@ -54,12 +54,6 @@ warning: type `v17` should have an upper camel case name
|
||||||
LL | pub struct v17<const v10: usize, const v7: v11> {
|
LL | pub struct v17<const v10: usize, const v7: v11> {
|
||||||
| ^^^ help: convert the identifier to upper camel case (notice the capitalization): `V17`
|
| ^^^ help: convert the identifier to upper camel case (notice the capitalization): `V17`
|
||||||
|
|
||||||
error[E0425]: cannot find function `v6` in this scope
|
|
||||||
--> $DIR/unevaluated-const-ice-119731.rs:13:35
|
|
||||||
|
|
|
||||||
LL | const v0: [[usize; v4]; v4] = v6(v8);
|
|
||||||
| ^^ not found in this scope
|
|
||||||
|
|
||||||
error: `[[usize; v4]; v4]` is forbidden as the type of a const generic parameter
|
error: `[[usize; v4]; v4]` is forbidden as the type of a const generic parameter
|
||||||
--> $DIR/unevaluated-const-ice-119731.rs:16:48
|
--> $DIR/unevaluated-const-ice-119731.rs:16:48
|
||||||
|
|
|
|
||||||
|
@ -72,6 +66,12 @@ help: add `#![feature(adt_const_params)]` to the crate attributes to enable more
|
||||||
LL + #![feature(adt_const_params)]
|
LL + #![feature(adt_const_params)]
|
||||||
|
|
|
|
||||||
|
|
||||||
|
error[E0425]: cannot find function `v6` in this scope
|
||||||
|
--> $DIR/unevaluated-const-ice-119731.rs:13:35
|
||||||
|
|
|
||||||
|
LL | const v0: [[usize; v4]; v4] = v6(v8);
|
||||||
|
| ^^ not found in this scope
|
||||||
|
|
||||||
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#0}
|
||||||
--> $DIR/unevaluated-const-ice-119731.rs:28:37
|
--> $DIR/unevaluated-const-ice-119731.rs:28:37
|
||||||
|
|
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ LL | const ONE: [u16] = [1];
|
||||||
| ^^^^^ doesn't have a size known at compile-time
|
| ^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `[u16]`
|
= help: the trait `Sized` is not implemented for `[u16]`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/const-slice-array-deref.rs:1:20
|
--> $DIR/const-slice-array-deref.rs:1:20
|
||||||
|
|
|
@ -5,6 +5,7 @@ LL | const CONST_0: dyn Debug + Sync = *(&0 as &(dyn Debug + Sync));
|
||||||
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
|
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
--> $DIR/const-unsized.rs:7:18
|
--> $DIR/const-unsized.rs:7:18
|
||||||
|
@ -13,6 +14,7 @@ LL | const CONST_FOO: str = *"foo";
|
||||||
| ^^^ doesn't have a size known at compile-time
|
| ^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `str`
|
= help: the trait `Sized` is not implemented for `str`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
|
error[E0277]: the size for values of type `(dyn Debug + Sync + 'static)` cannot be known at compilation time
|
||||||
--> $DIR/const-unsized.rs:11:18
|
--> $DIR/const-unsized.rs:11:18
|
||||||
|
@ -21,6 +23,7 @@ LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync));
|
||||||
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
| ^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
|
= help: the trait `Sized` is not implemented for `(dyn Debug + Sync + 'static)`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
--> $DIR/const-unsized.rs:15:20
|
--> $DIR/const-unsized.rs:15:20
|
||||||
|
@ -29,6 +32,7 @@ LL | static STATIC_BAR: str = *"bar";
|
||||||
| ^^^ doesn't have a size known at compile-time
|
| ^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `str`
|
= help: the trait `Sized` is not implemented for `str`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0507]: cannot move out of a shared reference
|
error[E0507]: cannot move out of a shared reference
|
||||||
--> $DIR/const-unsized.rs:3:35
|
--> $DIR/const-unsized.rs:3:35
|
||||||
|
|
|
@ -30,6 +30,7 @@ LL | static FOO: Sync = AtomicUsize::new(0);
|
||||||
| ^^^^ doesn't have a size known at compile-time
|
| ^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `(dyn Sync + 'static)`
|
= help: the trait `Sized` is not implemented for `(dyn Sync + 'static)`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error: aborting due to 2 previous errors; 1 warning emitted
|
error: aborting due to 2 previous errors; 1 warning emitted
|
||||||
|
|
||||||
|
|
7
tests/ui/consts/dont-ctfe-unsized-initializer.rs
Normal file
7
tests/ui/consts/dont-ctfe-unsized-initializer.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
static S: str = todo!();
|
||||||
|
//~^ ERROR the size for values of type `str` cannot be known at compilation time
|
||||||
|
|
||||||
|
const C: str = todo!();
|
||||||
|
//~^ ERROR the size for values of type `str` cannot be known at compilation time
|
||||||
|
|
||||||
|
fn main() {}
|
21
tests/ui/consts/dont-ctfe-unsized-initializer.stderr
Normal file
21
tests/ui/consts/dont-ctfe-unsized-initializer.stderr
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
|
--> $DIR/dont-ctfe-unsized-initializer.rs:1:11
|
||||||
|
|
|
||||||
|
LL | static S: str = todo!();
|
||||||
|
| ^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
||||||
|
= help: the trait `Sized` is not implemented for `str`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
|
--> $DIR/dont-ctfe-unsized-initializer.rs:4:10
|
||||||
|
|
|
||||||
|
LL | const C: str = todo!();
|
||||||
|
| ^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
||||||
|
= help: the trait `Sized` is not implemented for `str`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
|
@ -1,3 +1,9 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/issue-39974.rs:5:19
|
||||||
|
|
|
||||||
|
LL | f: [[f64; 2]; LENGTH],
|
||||||
|
| ^^^^^^ expected `usize`, found `f64`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/issue-39974.rs:1:21
|
--> $DIR/issue-39974.rs:1:21
|
||||||
|
|
|
|
||||||
|
@ -9,12 +15,6 @@ help: use a float literal
|
||||||
LL | const LENGTH: f64 = 2.0;
|
LL | const LENGTH: f64 = 2.0;
|
||||||
| ++
|
| ++
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/issue-39974.rs:5:19
|
|
||||||
|
|
|
||||||
LL | f: [[f64; 2]; LENGTH],
|
|
||||||
| ^^^^^^ expected `usize`, found `f64`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0308`.
|
||||||
|
|
|
@ -5,6 +5,7 @@ LL | static symbol: [usize];
|
||||||
| ^^^^^^^ doesn't have a size known at compile-time
|
| ^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `[usize]`
|
= help: the trait `Sized` is not implemented for `[usize]`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0133]: use of extern static is unsafe and requires unsafe function or block
|
error[E0133]: use of extern static is unsafe and requires unsafe function or block
|
||||||
--> $DIR/issue-36122-accessing-externed-dst.rs:5:20
|
--> $DIR/issue-36122-accessing-externed-dst.rs:5:20
|
||||||
|
|
|
@ -5,6 +5,7 @@ LL | pub static mut symbol: [i8];
|
||||||
| ^^^^ doesn't have a size known at compile-time
|
| ^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `[i8]`
|
= help: the trait `Sized` is not implemented for `[i8]`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,15 @@ LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||||
= help: the trait `Sized` is not implemented for `[u8]`
|
= help: the trait `Sized` is not implemented for `[u8]`
|
||||||
= note: only the last element of a tuple may have a dynamically sized type
|
= note: only the last element of a tuple may have a dynamically sized type
|
||||||
|
|
||||||
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||||
|
--> $DIR/issue-84108.rs:15:13
|
||||||
|
|
|
||||||
|
LL | static BAZ: ([u8], usize) = ([], 0);
|
||||||
|
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
||||||
|
= help: the trait `Sized` is not implemented for `[u8]`
|
||||||
|
= note: only the last element of a tuple may have a dynamically sized type
|
||||||
|
|
||||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||||
--> $DIR/issue-84108.rs:9:12
|
--> $DIR/issue-84108.rs:9:12
|
||||||
|
|
|
|
||||||
|
@ -48,15 +57,6 @@ LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42);
|
||||||
= note: expected slice `[u8]`
|
= note: expected slice `[u8]`
|
||||||
found array `[_; 0]`
|
found array `[_; 0]`
|
||||||
|
|
||||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
|
||||||
--> $DIR/issue-84108.rs:15:13
|
|
||||||
|
|
|
||||||
LL | static BAZ: ([u8], usize) = ([], 0);
|
|
||||||
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
|
||||||
|
|
|
||||||
= help: the trait `Sized` is not implemented for `[u8]`
|
|
||||||
= note: only the last element of a tuple may have a dynamically sized type
|
|
||||||
|
|
||||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||||
--> $DIR/issue-84108.rs:15:13
|
--> $DIR/issue-84108.rs:15:13
|
||||||
|
|
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ LL | static foo: dyn Fn() -> u32 = || -> u32 {
|
||||||
| ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
| ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `(dyn Fn() -> u32 + 'static)`
|
= help: the trait `Sized` is not implemented for `(dyn Fn() -> u32 + 'static)`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/issue-24446.rs:2:35
|
--> $DIR/issue-24446.rs:2:35
|
||||||
|
|
|
@ -10,6 +10,7 @@ note: required because it appears within the type `Foo`
|
||||||
|
|
|
|
||||||
LL | pub struct Foo {
|
LL | pub struct Foo {
|
||||||
| ^^^
|
| ^^^
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/unsized_type2.rs:14:45
|
--> $DIR/unsized_type2.rs:14:45
|
||||||
|
|
|
@ -11,6 +11,7 @@ LL | const TEST: Fn = some_fn;
|
||||||
| ^^ doesn't have a size known at compile-time
|
| ^^ doesn't have a size known at compile-time
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `(dyn FnOnce() -> u8 + 'static)`
|
= help: the trait `Sized` is not implemented for `(dyn FnOnce() -> u8 + 'static)`
|
||||||
|
= note: statics and constants must have a statically known size
|
||||||
|
|
||||||
error[E0277]: the size for values of type `(dyn FnOnce() -> u8 + 'static)` cannot be known at compilation time
|
error[E0277]: the size for values of type `(dyn FnOnce() -> u8 + 'static)` cannot be known at compilation time
|
||||||
--> $DIR/ice-unsized-tuple-const-issue-121443.rs:11:14
|
--> $DIR/ice-unsized-tuple-const-issue-121443.rs:11:14
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
type Bug<T, U> = impl Fn(T) -> U + Copy;
|
type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
|
//~^ ERROR cycle detected
|
||||||
|
|
||||||
const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
||||||
//~^ ERROR cycle detected
|
//~^ ERROR item does not constrain `Bug::{opaque#0}`, but has it in its signature
|
||||||
//~| ERROR: non-defining opaque type use
|
//~| ERROR item does not constrain `Bug::{opaque#0}`, but has it in its signature
|
||||||
|
//~| ERROR non-defining opaque type use in defining scope
|
||||||
|
|
||||||
fn make_bug<T, U: From<T>>() -> Bug<T, U> {
|
fn make_bug<T, U: From<T>>() -> Bug<T, U> {
|
||||||
|x| x.into()
|
|x| x.into()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0792]: non-defining opaque type use in defining scope
|
error[E0792]: non-defining opaque type use in defining scope
|
||||||
--> $DIR/issue-53092-2.rs:6:18
|
--> $DIR/issue-53092-2.rs:7:18
|
||||||
|
|
|
|
||||||
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
||||||
| ^^^^^^^^^^^ argument `u8` is not a generic parameter
|
| ^^^^^^^^^^^ argument `u8` is not a generic parameter
|
||||||
|
@ -10,33 +10,59 @@ note: for this opaque type
|
||||||
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0391]: cycle detected when type-checking `CONST_BUG`
|
error[E0391]: cycle detected when computing type of `Bug::{opaque#0}`
|
||||||
--> $DIR/issue-53092-2.rs:6:1
|
|
||||||
|
|
|
||||||
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: ...which requires computing layout of `Bug<u8, ()>`...
|
|
||||||
= note: ...which requires normalizing `Bug<u8, ()>`...
|
|
||||||
note: ...which requires computing type of `Bug::{opaque#0}`...
|
|
||||||
--> $DIR/issue-53092-2.rs:4:18
|
--> $DIR/issue-53092-2.rs:4:18
|
||||||
|
|
|
|
||||||
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
note: ...which requires computing type of opaque `Bug::{opaque#0}`...
|
note: ...which requires computing type of opaque `Bug::{opaque#0}`...
|
||||||
--> $DIR/issue-53092-2.rs:4:18
|
--> $DIR/issue-53092-2.rs:4:18
|
||||||
|
|
|
|
||||||
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
= note: ...which again requires type-checking `CONST_BUG`, completing the cycle
|
note: ...which requires type-checking `CONST_BUG`...
|
||||||
note: cycle used when checking that `CONST_BUG` is well-formed
|
--> $DIR/issue-53092-2.rs:7:1
|
||||||
--> $DIR/issue-53092-2.rs:6:1
|
|
||||||
|
|
|
|
||||||
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
= note: ...which requires computing layout of `Bug<u8, ()>`...
|
||||||
|
= note: ...which requires normalizing `Bug<u8, ()>`...
|
||||||
|
= note: ...which again requires computing type of `Bug::{opaque#0}`, completing the cycle
|
||||||
|
note: cycle used when checking that `Bug::{opaque#0}` is well-formed
|
||||||
|
--> $DIR/issue-53092-2.rs:4:18
|
||||||
|
|
|
||||||
|
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: item does not constrain `Bug::{opaque#0}`, but has it in its signature
|
||||||
|
--> $DIR/issue-53092-2.rs:7:7
|
||||||
|
|
|
||||||
|
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: consider moving the opaque type's declaration and defining uses into a separate module
|
||||||
|
note: this opaque type is in the signature
|
||||||
|
--> $DIR/issue-53092-2.rs:4:18
|
||||||
|
|
|
||||||
|
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: item does not constrain `Bug::{opaque#0}`, but has it in its signature
|
||||||
|
--> $DIR/issue-53092-2.rs:7:61
|
||||||
|
|
|
||||||
|
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
= note: consider moving the opaque type's declaration and defining uses into a separate module
|
||||||
|
note: this opaque type is in the signature
|
||||||
|
--> $DIR/issue-53092-2.rs:4:18
|
||||||
|
|
|
||||||
|
LL | type Bug<T, U> = impl Fn(T) -> U + Copy;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0391, E0792.
|
Some errors have detailed explanations: E0391, E0792.
|
||||||
For more information about an error, try `rustc --explain E0391`.
|
For more information about an error, try `rustc --explain E0391`.
|
||||||
|
|
|
@ -7,16 +7,6 @@ LL | const _: <[[[[[[u8]]]]]] as WellUnformed>::RequestNormalize = ();
|
||||||
= help: the trait `Sized` is not implemented for `[[[[[u8]]]]]`
|
= help: the trait `Sized` is not implemented for `[[[[[u8]]]]]`
|
||||||
= note: slice and array elements must have `Sized` type
|
= note: slice and array elements must have `Sized` type
|
||||||
|
|
||||||
error[E0277]: the size for values of type `[[[[[u8]]]]]` cannot be known at compilation time
|
|
||||||
--> $DIR/wf-normalization-sized.rs:19:11
|
|
||||||
|
|
|
||||||
LL | const _: <[[[[[[u8]]]]]] as WellUnformed>::RequestNormalize = ();
|
|
||||||
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
|
||||||
|
|
|
||||||
= help: the trait `Sized` is not implemented for `[[[[[u8]]]]]`
|
|
||||||
= note: slice and array elements must have `Sized` type
|
|
||||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
--> $DIR/wf-normalization-sized.rs:22:11
|
--> $DIR/wf-normalization-sized.rs:22:11
|
||||||
|
|
|
|
||||||
|
@ -27,6 +17,16 @@ LL | const _: <Vec<str> as WellUnformed>::RequestNormalize = ();
|
||||||
note: required by an implicit `Sized` bound in `Vec`
|
note: required by an implicit `Sized` bound in `Vec`
|
||||||
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
|
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
|
||||||
|
|
||||||
|
error[E0277]: the size for values of type `[[[[[u8]]]]]` cannot be known at compilation time
|
||||||
|
--> $DIR/wf-normalization-sized.rs:19:11
|
||||||
|
|
|
||||||
|
LL | const _: <[[[[[[u8]]]]]] as WellUnformed>::RequestNormalize = ();
|
||||||
|
| ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
||||||
|
= help: the trait `Sized` is not implemented for `[[[[[u8]]]]]`
|
||||||
|
= note: slice and array elements must have `Sized` type
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
--> $DIR/wf-normalization-sized.rs:22:11
|
--> $DIR/wf-normalization-sized.rs:22:11
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue