diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 03c026cd6c89..07ca64e61445 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -767,7 +767,6 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Static { .. } => { check_static_inhabited(tcx, def_id); check_static_linkage(tcx, def_id); - res = res.and(wfcheck::check_static_item(tcx, def_id)); } DefKind::Const => res = res.and(wfcheck::check_const_item(tcx, def_id)), _ => unreachable!(), diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 14ec82ede1c5..e8d962467b37 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1180,12 +1180,12 @@ fn check_item_fn( } #[instrument(level = "debug", skip(tcx))] -pub(super) fn check_static_item( - tcx: TyCtxt<'_>, +pub(crate) fn check_static_item<'tcx>( + tcx: TyCtxt<'tcx>, item_id: LocalDefId, + ty: Ty<'tcx>, ) -> Result<(), ErrorGuaranteed> { enter_wf_checking_ctxt(tcx, item_id, |wfcx| { - let ty = tcx.type_of(item_id).instantiate_identity(); let span = tcx.ty_span(item_id); let item_ty = wfcx.deeply_normalize(span, Some(WellFormedLoc::Ty(item_id)), ty); diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 902a2e15dffd..f84bd2a5fb3e 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -14,6 +14,7 @@ use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span}; use super::{HirPlaceholderCollector, ItemCtxt, bad_placeholder}; +use crate::check::wfcheck::check_static_item; use crate::errors::TypeofReservedKeywordUsed; use crate::hir_ty_lowering::HirTyLowerer; @@ -217,7 +218,13 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ "static variable", ) } else { - icx.lower_ty(ty) + let ty = icx.lower_ty(ty); + // MIR relies on references to statics being scalars. + // Verify that here to avoid ill-formed MIR. + match check_static_item(tcx, def_id, ty) { + Ok(()) => ty, + Err(guar) => Ty::new_error(tcx, guar), + } } } ItemKind::Const(ident, _, ty, body_id) => { @@ -275,7 +282,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ let args = ty::GenericArgs::identity_for_item(tcx, def_id); Ty::new_fn_def(tcx, def_id.to_def_id(), args) } - ForeignItemKind::Static(t, _, _) => icx.lower_ty(t), + ForeignItemKind::Static(ty, _, _) => { + let ty = icx.lower_ty(ty); + // MIR relies on references to statics being scalars. + // Verify that here to avoid ill-formed MIR. + match check_static_item(tcx, def_id, ty) { + Ok(()) => ty, + Err(guar) => Ty::new_error(tcx, guar), + } + } ForeignItemKind::Type => Ty::new_foreign(tcx, def_id.to_def_id()), }, diff --git a/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs index ddb405acec74..9825b947fe09 100644 --- a/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/builder/custom/parse/instruction.rs @@ -309,7 +309,7 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> { | ExprKind::ConstParam { .. } | ExprKind::ConstBlock { .. } => { Ok(Operand::Constant(Box::new( - as_constant_inner(self.tcx, self.typing_env, expr, |_| None) + as_constant_inner(expr, |_| None, self.tcx) ))) }, _ => self.parse_place(expr_id).map(Operand::Copy), @@ -393,7 +393,7 @@ impl<'a, 'tcx> ParseCtxt<'a, 'tcx> { | ExprKind::NamedConst { .. } | ExprKind::NonHirLiteral { .. } | ExprKind::ConstBlock { .. } => Ok({ - let value = as_constant_inner(self.tcx, self.typing_env, expr, |_| None); + let value = as_constant_inner(expr, |_| None, self.tcx); value.const_.eval_bits(self.tcx, self.typing_env) }), ) diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs index 92935dfc97a2..0e0c7a7fa4f0 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs @@ -1,6 +1,6 @@ //! See docs in build/expr/mod.rs -use rustc_abi::{BackendRepr, Size}; +use rustc_abi::Size; use rustc_ast as ast; use rustc_hir::LangItem; use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, LitToConstInput, Scalar}; @@ -8,7 +8,7 @@ use rustc_middle::mir::*; use rustc_middle::thir::*; use rustc_middle::ty::{ self, CanonicalUserType, CanonicalUserTypeAnnotation, Ty, TyCtxt, TypeVisitableExt as _, - TypingEnv, UserTypeAnnotationIndex, + UserTypeAnnotationIndex, }; use rustc_middle::{bug, mir, span_bug}; use tracing::{instrument, trace}; @@ -19,27 +19,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// Compile `expr`, yielding a compile-time constant. Assumes that /// `expr` is a valid compile-time constant! pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> ConstOperand<'tcx> { + let this = self; + let tcx = this.tcx; let Expr { ty, temp_lifetime: _, span, ref kind } = *expr; match kind { ExprKind::Scope { region_scope: _, lint_level: _, value } => { - self.as_constant(&self.thir[*value]) + this.as_constant(&this.thir[*value]) } - _ => as_constant_inner(self.tcx, self.typing_env(), expr, |user_ty| { - Some(self.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { - span, - user_ty: user_ty.clone(), - inferred_ty: ty, - })) - }), + _ => as_constant_inner( + expr, + |user_ty| { + Some(this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + span, + user_ty: user_ty.clone(), + inferred_ty: ty, + })) + }, + tcx, + ), } } } pub(crate) fn as_constant_inner<'tcx>( - tcx: TyCtxt<'tcx>, - typing_env: TypingEnv<'tcx>, expr: &Expr<'tcx>, push_cuta: impl FnMut(&Box>) -> Option, + tcx: TyCtxt<'tcx>, ) -> ConstOperand<'tcx> { let Expr { ty, temp_lifetime: _, span, ref kind } = *expr; match *kind { @@ -83,23 +88,8 @@ pub(crate) fn as_constant_inner<'tcx>( ConstOperand { user_ty: None, span, const_ } } ExprKind::StaticRef { alloc_id, ty, .. } => { - let layout = tcx.layout_of(typing_env.as_query_input(ty)); - let const_ = if let Ok(layout) = layout - && let BackendRepr::Scalar(..) = layout.backend_repr - { - let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx)); - Const::Val(const_val, ty) - } else { - // Ill-formed code may produce instances where `pointee` is not `Sized`. - // This should be reported by wfcheck on the static itself. - // Still, producing a single scalar constant would be inconsistent, as pointers to - // non-`Sized` types are scalar pairs. Avoid an ICE by producing an error constant. - let guar = tcx.dcx().span_delayed_bug( - span, - format!("pointer to static's type `{ty}` is not scalar"), - ); - Const::Ty(ty, ty::Const::new_error(tcx, guar)) - }; + let const_val = ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &tcx)); + let const_ = Const::Val(const_val, ty); ConstOperand { span, user_ty: None, const_ } } diff --git a/tests/ui/consts/const-unsized.rs b/tests/ui/consts/const-unsized.rs index e8af3323cebf..4140563fa40e 100644 --- a/tests/ui/consts/const-unsized.rs +++ b/tests/ui/consts/const-unsized.rs @@ -10,14 +10,10 @@ const CONST_FOO: str = *"foo"; static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync)); //~^ ERROR the size for values of type -//~| ERROR cannot move out of a shared reference static STATIC_BAR: str = *"bar"; //~^ ERROR the size for values of type -//~| ERROR cannot move out of a shared reference fn main() { println!("{:?} {:?} {:?} {:?}", &CONST_0, &CONST_FOO, &STATIC_1, &STATIC_BAR); - //~^ ERROR: cannot move a value of type `str` - //~| ERROR: cannot move a value of type `dyn Debug + Sync` } diff --git a/tests/ui/consts/const-unsized.stderr b/tests/ui/consts/const-unsized.stderr index c92fbc17f9cd..a37a6df71f83 100644 --- a/tests/ui/consts/const-unsized.stderr +++ b/tests/ui/consts/const-unsized.stderr @@ -26,7 +26,7 @@ LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync)); = 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/const-unsized.rs:15:1 + --> $DIR/const-unsized.rs:14:1 | LL | static STATIC_BAR: str = *"bar"; | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -46,31 +46,7 @@ error[E0507]: cannot move out of a shared reference LL | const CONST_FOO: str = *"foo"; | ^^^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait -error[E0507]: cannot move out of a shared reference - --> $DIR/const-unsized.rs:11:37 - | -LL | static STATIC_1: dyn Debug + Sync = *(&1 as &(dyn Debug + Sync)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move occurs because value has type `dyn Debug + Sync`, which does not implement the `Copy` trait +error: aborting due to 6 previous errors -error[E0507]: cannot move out of a shared reference - --> $DIR/const-unsized.rs:15:26 - | -LL | static STATIC_BAR: str = *"bar"; - | ^^^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait - -error[E0161]: cannot move a value of type `dyn Debug + Sync` - --> $DIR/const-unsized.rs:20:38 - | -LL | println!("{:?} {:?} {:?} {:?}", &CONST_0, &CONST_FOO, &STATIC_1, &STATIC_BAR); - | ^^^^^^^ the size of `dyn Debug + Sync` cannot be statically determined - -error[E0161]: cannot move a value of type `str` - --> $DIR/const-unsized.rs:20:48 - | -LL | println!("{:?} {:?} {:?} {:?}", &CONST_0, &CONST_FOO, &STATIC_1, &STATIC_BAR); - | ^^^^^^^^^ the size of `str` cannot be statically determined - -error: aborting due to 10 previous errors - -Some errors have detailed explanations: E0161, E0277, E0507. -For more information about an error, try `rustc --explain E0161`. +Some errors have detailed explanations: E0277, E0507. +For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/coroutine/layout-error.rs b/tests/ui/coroutine/layout-error.rs index 2ee0bd816194..137c47490f60 100644 --- a/tests/ui/coroutine/layout-error.rs +++ b/tests/ui/coroutine/layout-error.rs @@ -17,7 +17,6 @@ impl Task { } pub type F = impl Future; -//~^ ERROR cycle detected when computing type of `F::{opaque#0}` #[define_opaque(F)] fn foo() @@ -33,5 +32,7 @@ where // Check that statics are inhabited computes they layout. static POOL: Task = Task::new(); +//~^ ERROR cycle detected when computing type of `POOL` +//~| ERROR cycle detected when computing type of `POOL` fn main() {} diff --git a/tests/ui/coroutine/layout-error.stderr b/tests/ui/coroutine/layout-error.stderr index 057ac36b849d..c0ededfd3fe0 100644 --- a/tests/ui/coroutine/layout-error.stderr +++ b/tests/ui/coroutine/layout-error.stderr @@ -1,55 +1,97 @@ error[E0425]: cannot find value `Foo` in this scope - --> $DIR/layout-error.rs:28:17 + --> $DIR/layout-error.rs:27:17 | LL | let a = Foo; | ^^^ not found in this scope -error[E0391]: cycle detected when computing type of `F::{opaque#0}` - --> $DIR/layout-error.rs:19:14 +error[E0391]: cycle detected when computing type of `POOL` + --> $DIR/layout-error.rs:34:14 | -LL | pub type F = impl Future; - | ^^^^^^^^^^^ +LL | static POOL: Task = Task::new(); + | ^^^^^^^ | + = note: ...which requires evaluating trait selection obligation `Task: core::marker::Sync`... note: ...which requires computing type of opaque `F::{opaque#0}`... --> $DIR/layout-error.rs:19:14 | LL | pub type F = impl Future; | ^^^^^^^^^^^ note: ...which requires borrow-checking `foo`... - --> $DIR/layout-error.rs:23:1 + --> $DIR/layout-error.rs:22:1 | LL | / fn foo() LL | | where LL | | F:, | |_______^ note: ...which requires promoting constants in MIR for `foo`... - --> $DIR/layout-error.rs:23:1 + --> $DIR/layout-error.rs:22:1 | LL | / fn foo() LL | | where LL | | F:, | |_______^ note: ...which requires checking if `foo` contains FFI-unwind calls... - --> $DIR/layout-error.rs:23:1 + --> $DIR/layout-error.rs:22:1 | LL | / fn foo() LL | | where LL | | F:, | |_______^ note: ...which requires building MIR for `foo`... - --> $DIR/layout-error.rs:23:1 + --> $DIR/layout-error.rs:22:1 | LL | / fn foo() LL | | where LL | | F:, | |_______^ - = note: ...which requires computing layout of `&Task`... - = note: ...which requires normalizing `&Task`... - = note: ...which again requires computing type of `F::{opaque#0}`, completing the cycle - = note: cycle used when normalizing `Task` +note: ...which requires match-checking `foo`... + --> $DIR/layout-error.rs:22:1 + | +LL | / fn foo() +LL | | where +LL | | F:, + | |_______^ +note: ...which requires type-checking `foo`... + --> $DIR/layout-error.rs:22:1 + | +LL | / fn foo() +LL | | where +LL | | F:, + | |_______^ + = note: ...which again requires computing type of `POOL`, completing the cycle +note: cycle used when checking that `POOL` is well-formed + --> $DIR/layout-error.rs:34:1 + | +LL | static POOL: Task = Task::new(); + | ^^^^^^^^^^^^^^^^^^^^ = 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[E0391]: cycle detected when computing type of `POOL` + --> $DIR/layout-error.rs:34:14 + | +LL | static POOL: Task = Task::new(); + | ^^^^^^^ + | + = note: ...which requires evaluating trait selection obligation `Task: core::marker::Sync`... +note: ...which requires computing type of opaque `F::{opaque#0}`... + --> $DIR/layout-error.rs:19:14 + | +LL | pub type F = impl Future; + | ^^^^^^^^^^^ +note: ...which requires computing the opaque types defined by `POOL`... + --> $DIR/layout-error.rs:34:1 + | +LL | static POOL: Task = Task::new(); + | ^^^^^^^^^^^^^^^^^^^^ + = note: ...which again requires computing type of `POOL`, completing the cycle +note: cycle used when checking that `POOL` is well-formed + --> $DIR/layout-error.rs:34:1 + | +LL | static POOL: Task = Task::new(); + | ^^^^^^^^^^^^^^^^^^^^ + = 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 3 previous errors Some errors have detailed explanations: E0391, E0425. For more information about an error, try `rustc --explain E0391`. diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.rs b/tests/ui/coroutine/metadata-sufficient-for-layout.rs index b7d8575c7617..0c074029faa9 100644 --- a/tests/ui/coroutine/metadata-sufficient-for-layout.rs +++ b/tests/ui/coroutine/metadata-sufficient-for-layout.rs @@ -4,7 +4,6 @@ // Regression test for #80998. // //@ aux-build:metadata-sufficient-for-layout.rs -//@ check-pass #![feature(type_alias_impl_trait, rustc_attrs)] #![feature(coroutine_trait)] @@ -23,5 +22,6 @@ mod helper { // Static queries the layout of the coroutine. static A: Option = None; +//~^ ERROR cycle detected when computing type of `A` fn main() {} diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.stderr b/tests/ui/coroutine/metadata-sufficient-for-layout.stderr new file mode 100644 index 000000000000..94f90098510b --- /dev/null +++ b/tests/ui/coroutine/metadata-sufficient-for-layout.stderr @@ -0,0 +1,38 @@ +error[E0391]: cycle detected when computing type of `A` + --> $DIR/metadata-sufficient-for-layout.rs:24:11 + | +LL | static A: Option = None; + | ^^^^^^^^^^^^^^^^^ + | + = note: ...which requires evaluating trait selection obligation `core::option::Option: core::marker::Sync`... +note: ...which requires computing type of opaque `helper::F::{opaque#0}`... + --> $DIR/metadata-sufficient-for-layout.rs:15:18 + | +LL | pub type F = impl Coroutine<(), Yield = (), Return = ()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires borrow-checking `helper::f`... + --> $DIR/metadata-sufficient-for-layout.rs:18:5 + | +LL | fn f() -> F { + | ^^^^^^^^^^^ +note: ...which requires computing type of opaque `helper::F::{opaque#0}` via HIR typeck... + --> $DIR/metadata-sufficient-for-layout.rs:15:18 + | +LL | pub type F = impl Coroutine<(), Yield = (), Return = ()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires computing the opaque types defined by `A`... + --> $DIR/metadata-sufficient-for-layout.rs:24:1 + | +LL | static A: Option = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which again requires computing type of `A`, completing the cycle +note: cycle used when checking that `A` is well-formed + --> $DIR/metadata-sufficient-for-layout.rs:24:1 + | +LL | static A: Option = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/dyn-compatibility/taint-const-eval.rs b/tests/ui/dyn-compatibility/taint-const-eval.rs index a5c01e1791e7..3d1b3b8fe618 100644 --- a/tests/ui/dyn-compatibility/taint-const-eval.rs +++ b/tests/ui/dyn-compatibility/taint-const-eval.rs @@ -6,6 +6,5 @@ trait Qux { static FOO: &(dyn Qux + Sync) = "desc"; //~^ ERROR the trait `Qux` is not dyn compatible -//~| ERROR the trait `Qux` is not dyn compatible fn main() {} diff --git a/tests/ui/dyn-compatibility/taint-const-eval.stderr b/tests/ui/dyn-compatibility/taint-const-eval.stderr index 585c1f012c78..e4be9870fdc4 100644 --- a/tests/ui/dyn-compatibility/taint-const-eval.stderr +++ b/tests/ui/dyn-compatibility/taint-const-eval.stderr @@ -21,30 +21,6 @@ help: alternatively, consider constraining `bar` so it does not apply to trait o LL | fn bar() where Self: Sized; | +++++++++++++++++ -error[E0038]: the trait `Qux` is not dyn compatible - --> $DIR/taint-const-eval.rs:7:15 - | -LL | static FOO: &(dyn Qux + Sync) = "desc"; - | ^^^^^^^^^^^^^^ `Qux` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $DIR/taint-const-eval.rs:4:8 - | -LL | trait Qux { - | --- this trait is not dyn compatible... -LL | fn bar(); - | ^^^ ...because associated function `bar` has no `self` parameter - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: consider turning `bar` into a method by giving it a `&self` argument - | -LL | fn bar(&self); - | +++++ -help: alternatively, consider constraining `bar` so it does not apply to trait objects - | -LL | fn bar() where Self: Sized; - | +++++++++++++++++ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/extern/issue-36122-accessing-externed-dst.rs b/tests/ui/extern/issue-36122-accessing-externed-dst.rs index 9fb7780e3d76..5f886ff57379 100644 --- a/tests/ui/extern/issue-36122-accessing-externed-dst.rs +++ b/tests/ui/extern/issue-36122-accessing-externed-dst.rs @@ -3,5 +3,4 @@ fn main() { static symbol: [usize]; //~ ERROR: the size for values of type } println!("{}", symbol[0]); - //~^ ERROR: extern static is unsafe } diff --git a/tests/ui/extern/issue-36122-accessing-externed-dst.stderr b/tests/ui/extern/issue-36122-accessing-externed-dst.stderr index 8007c3f13e5b..c617cf4e61bd 100644 --- a/tests/ui/extern/issue-36122-accessing-externed-dst.stderr +++ b/tests/ui/extern/issue-36122-accessing-externed-dst.stderr @@ -7,15 +7,6 @@ LL | static symbol: [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 - --> $DIR/issue-36122-accessing-externed-dst.rs:5:20 - | -LL | println!("{}", symbol[0]); - | ^^^^^^ use of extern static - | - = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior +error: aborting due to 1 previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0133, E0277. -For more information about an error, try `rustc --explain E0133`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/issues/issue-7364.rs b/tests/ui/issues/issue-7364.rs index 4ce9beb68cd3..79642bd411b3 100644 --- a/tests/ui/issues/issue-7364.rs +++ b/tests/ui/issues/issue-7364.rs @@ -3,6 +3,5 @@ use std::cell::RefCell; // Regression test for issue 7364 static boxed: Box> = Box::new(RefCell::new(0)); //~^ ERROR `RefCell` cannot be shared between threads safely [E0277] -//~| ERROR cannot call non-const associated function fn main() { } diff --git a/tests/ui/issues/issue-7364.stderr b/tests/ui/issues/issue-7364.stderr index a47a90c90ce1..7371e2105de8 100644 --- a/tests/ui/issues/issue-7364.stderr +++ b/tests/ui/issues/issue-7364.stderr @@ -11,16 +11,6 @@ note: required because it appears within the type `Box>` --> $SRC_DIR/alloc/src/boxed.rs:LL:COL = note: shared static variables must have a type that implements `Sync` -error[E0015]: cannot call non-const associated function `Box::>::new` in statics - --> $DIR/issue-7364.rs:4:37 - | -LL | static boxed: Box> = Box::new(RefCell::new(0)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` +error: aborting due to 1 previous error -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0015, E0277. -For more information about an error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/layout/issue-84108.rs b/tests/ui/layout/issue-84108.rs index 974d5310f6bb..33884617acbf 100644 --- a/tests/ui/layout/issue-84108.rs +++ b/tests/ui/layout/issue-84108.rs @@ -14,5 +14,3 @@ const BAR: (&Path, [u8], usize) = ("hello", [], 42); static BAZ: ([u8], usize) = ([], 0); //~^ ERROR the size for values of type `[u8]` cannot be known at compilation time -//~| ERROR the size for values of type `[u8]` cannot be known at compilation time -//~| ERROR mismatched types diff --git a/tests/ui/layout/issue-84108.stderr b/tests/ui/layout/issue-84108.stderr index e296abfc3b53..62a6ae341fa6 100644 --- a/tests/ui/layout/issue-84108.stderr +++ b/tests/ui/layout/issue-84108.stderr @@ -57,26 +57,7 @@ LL | const BAR: (&Path, [u8], usize) = ("hello", [], 42); = note: expected slice `[u8]` 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 - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0308]: mismatched types - --> $DIR/issue-84108.rs:15:30 - | -LL | static BAZ: ([u8], usize) = ([], 0); - | ^^ expected `[u8]`, found `[_; 0]` - | - = note: expected slice `[u8]` - found array `[_; 0]` - -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0277, E0308, E0412. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/mir/static-by-value-slice.rs b/tests/ui/mir/static-by-value-slice.rs index d4165781eae5..af98be6a74d6 100644 --- a/tests/ui/mir/static-by-value-slice.rs +++ b/tests/ui/mir/static-by-value-slice.rs @@ -4,10 +4,7 @@ static mut S: [i8] = ["Some thing"; 1]; //~^ ERROR the size for values of type `[i8]` cannot be known -//~| ERROR mismatched types -//~| ERROR mismatched types fn main() { assert_eq!(S, [0; 1]); - //~^ ERROR use of mutable static is unsafe } diff --git a/tests/ui/mir/static-by-value-slice.stderr b/tests/ui/mir/static-by-value-slice.stderr index c5c760b4fe50..2d0592943d0b 100644 --- a/tests/ui/mir/static-by-value-slice.stderr +++ b/tests/ui/mir/static-by-value-slice.stderr @@ -7,27 +7,6 @@ LL | static mut S: [i8] = ["Some thing"; 1]; = help: the trait `Sized` is not implemented for `[i8]` = note: statics and constants must have a statically known size -error[E0308]: mismatched types - --> $DIR/static-by-value-slice.rs:5:23 - | -LL | static mut S: [i8] = ["Some thing"; 1]; - | ^^^^^^^^^^^^ expected `i8`, found `&str` +error: aborting due to 1 previous error -error[E0308]: mismatched types - --> $DIR/static-by-value-slice.rs:5:22 - | -LL | static mut S: [i8] = ["Some thing"; 1]; - | ^^^^^^^^^^^^^^^^^ expected `[i8]`, found `[i8; 1]` - -error[E0133]: use of mutable static is unsafe and requires unsafe function or block - --> $DIR/static-by-value-slice.rs:11:16 - | -LL | assert_eq!(S, [0; 1]); - | ^ use of mutable static - | - = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0133, E0277, E0308. -For more information about an error, try `rustc --explain E0133`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/mir/static-by-value-str.rs b/tests/ui/mir/static-by-value-str.rs index 07de2a5e65c9..88b72f908190 100644 --- a/tests/ui/mir/static-by-value-str.rs +++ b/tests/ui/mir/static-by-value-str.rs @@ -9,8 +9,6 @@ enum E { static C: (E, u16, str) = (E::V16(0xDEAD), 0x600D, 0xBAD); //~^ ERROR the size for values of type `str` cannot be known -//~| ERROR the size for values of type `str` cannot be known -//~| ERROR mismatched types pub fn main() { let (_, n, _) = C; diff --git a/tests/ui/mir/static-by-value-str.stderr b/tests/ui/mir/static-by-value-str.stderr index 6988c7d8857a..6e046e005513 100644 --- a/tests/ui/mir/static-by-value-str.stderr +++ b/tests/ui/mir/static-by-value-str.stderr @@ -8,23 +8,6 @@ LL | static C: (E, u16, str) = (E::V16(0xDEAD), 0x600D, 0xBAD); = note: required because it appears within the type `(E, u16, str)` = note: statics and constants must have a statically known size -error[E0308]: mismatched types - --> $DIR/static-by-value-str.rs:10:52 - | -LL | static C: (E, u16, str) = (E::V16(0xDEAD), 0x600D, 0xBAD); - | ^^^^^ expected `str`, found integer +error: aborting due to 1 previous error -error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/static-by-value-str.rs:10:27 - | -LL | static C: (E, u16, str) = (E::V16(0xDEAD), 0x600D, 0xBAD); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time - | - = help: within `(E, u16, str)`, the trait `Sized` is not implemented for `str` - = note: required because it appears within the type `(E, u16, str)` - = note: tuples must have a statically known size to be initialized - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/static/issue-24446.rs b/tests/ui/static/issue-24446.rs index 830e373c189d..9ab952ade9cf 100644 --- a/tests/ui/static/issue-24446.rs +++ b/tests/ui/static/issue-24446.rs @@ -2,7 +2,6 @@ fn main() { static foo: dyn Fn() -> u32 = || -> u32 { //~^ ERROR the size for values of type //~| ERROR cannot be shared between threads safely - //~| ERROR mismatched types 0 }; } diff --git a/tests/ui/static/issue-24446.stderr b/tests/ui/static/issue-24446.stderr index ed195634f12c..359952dcf663 100644 --- a/tests/ui/static/issue-24446.stderr +++ b/tests/ui/static/issue-24446.stderr @@ -16,19 +16,6 @@ LL | static foo: dyn Fn() -> u32 = || -> u32 { = 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 - --> $DIR/issue-24446.rs:2:35 - | -LL | static foo: dyn Fn() -> u32 = || -> u32 { - | ___________________________________^ -... | -LL | | }; - | |_____^ expected `dyn Fn`, found closure - | - = note: expected trait object `(dyn Fn() -> u32 + 'static)` - found closure `{closure@$DIR/issue-24446.rs:2:35: 2:44}` +error: aborting due to 2 previous errors -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/bound/on-structs-and-enums-static.rs b/tests/ui/traits/bound/on-structs-and-enums-static.rs index d734893dd7c9..61e8e2ace607 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-static.rs +++ b/tests/ui/traits/bound/on-structs-and-enums-static.rs @@ -6,9 +6,7 @@ struct Foo { x: T, } -static X: Foo = Foo { -//~^ ERROR E0277 -//~| ERROR E0277 +static X: Foo = Foo { //~ ERROR E0277 x: 1, //~ ERROR: E0277 }; diff --git a/tests/ui/traits/bound/on-structs-and-enums-static.stderr b/tests/ui/traits/bound/on-structs-and-enums-static.stderr index 42ebcc07571f..1413422794a7 100644 --- a/tests/ui/traits/bound/on-structs-and-enums-static.stderr +++ b/tests/ui/traits/bound/on-structs-and-enums-static.stderr @@ -15,29 +15,11 @@ note: required by a bound in `Foo` LL | struct Foo { | ^^^^^ required by this bound in `Foo` -error[E0277]: the trait bound `usize: Trait` is not satisfied - --> $DIR/on-structs-and-enums-static.rs:9:11 - | -LL | static X: Foo = Foo { - | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize` - | -help: this trait has no implementations, consider adding one - --> $DIR/on-structs-and-enums-static.rs:1:1 - | -LL | trait Trait { - | ^^^^^^^^^^^ -note: required by a bound in `Foo` - --> $DIR/on-structs-and-enums-static.rs:5:14 - | -LL | struct Foo { - | ^^^^^ required by this bound in `Foo` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0277]: the trait bound `usize: Trait` is not satisfied - --> $DIR/on-structs-and-enums-static.rs:12:8 +error[E0277]: the trait bound `{integer}: Trait` is not satisfied + --> $DIR/on-structs-and-enums-static.rs:10:8 | LL | x: 1, - | ^ the trait `Trait` is not implemented for `usize` + | ^ the trait `Trait` is not implemented for `{integer}` | help: this trait has no implementations, consider adding one --> $DIR/on-structs-and-enums-static.rs:1:1 @@ -50,6 +32,6 @@ note: required by a bound in `Foo` LL | struct Foo { | ^^^^^ required by this bound in `Foo` -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs index e21627e14b09..bfe30f3706f1 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs @@ -1,5 +1,3 @@ -//@ check-pass - #![feature(type_alias_impl_trait)] use std::fmt::Debug; @@ -11,5 +9,8 @@ const _FOO: Foo = 5; #[define_opaque(Foo)] static _BAR: Foo = 22_i32; +//~^ ERROR cycle detected when computing type of `_BAR` +//~| ERROR cycle detected when computing type of `_BAR` +//~| ERROR cycle detected when computing type of `_BAR` fn main() {} diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr new file mode 100644 index 000000000000..6537f0f35a3b --- /dev/null +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr @@ -0,0 +1,113 @@ +error[E0391]: cycle detected when computing type of `_BAR` + --> $DIR/type-alias-impl-trait-const.rs:11:14 + | +LL | static _BAR: Foo = 22_i32; + | ^^^ + | + = note: ...which requires evaluating trait selection obligation `Foo: core::marker::Sync`... +note: ...which requires computing type of opaque `Foo::{opaque#0}`... + --> $DIR/type-alias-impl-trait-const.rs:5:16 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ +note: ...which requires borrow-checking `_FOO`... + --> $DIR/type-alias-impl-trait-const.rs:8:1 + | +LL | const _FOO: Foo = 5; + | ^^^^^^^^^^^^^^^ +note: ...which requires computing type of opaque `Foo::{opaque#0}` via HIR typeck... + --> $DIR/type-alias-impl-trait-const.rs:5:16 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ +note: ...which requires computing the opaque types defined by `_BAR`... + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ + = note: ...which again requires computing type of `_BAR`, completing the cycle +note: cycle used when checking that `_BAR` is well-formed + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ + = 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[E0391]: cycle detected when computing type of `_BAR` + --> $DIR/type-alias-impl-trait-const.rs:11:14 + | +LL | static _BAR: Foo = 22_i32; + | ^^^ + | + = note: ...which requires evaluating trait selection obligation `Foo: core::marker::Sync`... +note: ...which requires computing type of opaque `Foo::{opaque#0}`... + --> $DIR/type-alias-impl-trait-const.rs:5:16 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ +note: ...which requires borrow-checking `_FOO`... + --> $DIR/type-alias-impl-trait-const.rs:8:1 + | +LL | const _FOO: Foo = 5; + | ^^^^^^^^^^^^^^^ +note: ...which requires computing type of opaque `Foo::{opaque#0}` via HIR typeck... + --> $DIR/type-alias-impl-trait-const.rs:5:16 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ +note: ...which requires type-checking `_BAR`... + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ + = note: ...which again requires computing type of `_BAR`, completing the cycle +note: cycle used when checking that `_BAR` is well-formed + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ + = 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[E0391]: cycle detected when computing type of `_BAR` + --> $DIR/type-alias-impl-trait-const.rs:11:14 + | +LL | static _BAR: Foo = 22_i32; + | ^^^ + | + = note: ...which requires evaluating trait selection obligation `Foo: core::marker::Sync`... +note: ...which requires computing type of opaque `Foo::{opaque#0}`... + --> $DIR/type-alias-impl-trait-const.rs:5:16 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ +note: ...which requires borrow-checking `_BAR`... + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ +note: ...which requires promoting constants in MIR for `_BAR`... + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ +note: ...which requires const checking `_BAR`... + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ +note: ...which requires building MIR for `_BAR`... + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ + = note: ...which again requires computing type of `_BAR`, completing the cycle +note: cycle used when checking that `_BAR` is well-formed + --> $DIR/type-alias-impl-trait-const.rs:11:1 + | +LL | static _BAR: Foo = 22_i32; + | ^^^^^^^^^^^^^^^^ + = 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 3 previous errors + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/wf/wf-static-type.rs b/tests/ui/wf/wf-static-type.rs index 1980c5de40c8..1c35e1daf449 100644 --- a/tests/ui/wf/wf-static-type.rs +++ b/tests/ui/wf/wf-static-type.rs @@ -9,8 +9,6 @@ struct NotCopy; static FOO: IsCopy> = IsCopy { t: None }; //~^ ERROR E0277 -//~| ERROR E0277 -//~| ERROR E0277 fn main() { } diff --git a/tests/ui/wf/wf-static-type.stderr b/tests/ui/wf/wf-static-type.stderr index 53b90c69960b..2fa8ae06c459 100644 --- a/tests/ui/wf/wf-static-type.stderr +++ b/tests/ui/wf/wf-static-type.stderr @@ -16,43 +16,6 @@ LL + #[derive(Copy)] LL | struct NotCopy; | -error[E0277]: the trait bound `NotCopy: Copy` is not satisfied - --> $DIR/wf-static-type.rs:10:13 - | -LL | static FOO: IsCopy> = IsCopy { t: None }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy` - | - = note: required for `Option` to implement `Copy` -note: required by a bound in `IsCopy` - --> $DIR/wf-static-type.rs:7:17 - | -LL | struct IsCopy { t: T } - | ^^^^ required by this bound in `IsCopy` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -help: consider annotating `NotCopy` with `#[derive(Copy)]` - | -LL + #[derive(Copy)] -LL | struct NotCopy; - | - -error[E0277]: the trait bound `NotCopy: Copy` is not satisfied - --> $DIR/wf-static-type.rs:10:51 - | -LL | static FOO: IsCopy> = IsCopy { t: None }; - | ^^^^ the trait `Copy` is not implemented for `NotCopy` - | - = note: required for `Option` to implement `Copy` -note: required by a bound in `IsCopy` - --> $DIR/wf-static-type.rs:7:17 - | -LL | struct IsCopy { t: T } - | ^^^^ required by this bound in `IsCopy` -help: consider annotating `NotCopy` with `#[derive(Copy)]` - | -LL + #[derive(Copy)] -LL | struct NotCopy; - | - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0277`.