diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 1cd77050217a2..b99d17250af93 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -196,6 +196,15 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { collect::test_opaque_hidden_types(tcx)?; } + tcx.hir().par_body_owners(|item_def_id| { + let def_kind = tcx.def_kind(item_def_id); + match def_kind { + DefKind::Static(_) => tcx.ensure().eval_static_initializer(item_def_id.into()), + DefKind::Const => tcx.ensure().const_eval_poly(item_def_id.into()), + _ => (), + } + }); + // Freeze definitions as we don't add new ones at this point. This improves performance by // allowing lock-free access to them. tcx.untracked().definitions.freeze(); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 6ee1d1ca92472..3c646d4ed2925 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1542,32 +1542,6 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds { } } -declare_lint_pass!( - /// Lint constants that are erroneous. - /// Without this lint, we might not get any diagnostic if the constant is - /// unused within this crate, even though downstream crates can't use it - /// without producing an error. - UnusedBrokenConst => [] -); - -impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst { - fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { - match it.kind { - hir::ItemKind::Const(_, _, body_id) => { - let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id(); - // trigger the query once for all constants since that will already report the errors - // FIXME(generic_const_items): Does this work properly with generic const items? - cx.tcx.ensure().const_eval_poly(def_id); - } - hir::ItemKind::Static(_, _, body_id) => { - let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id(); - cx.tcx.ensure().eval_static_initializer(def_id); - } - _ => {} - } - } -} - declare_lint! { /// The `trivial_bounds` lint detects trait bounds that don't depend on /// any type parameters. diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 5f769e9ad8a5b..abd84ec5966d8 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -212,8 +212,6 @@ late_lint_methods!( ExplicitOutlivesRequirements: ExplicitOutlivesRequirements, InvalidValue: InvalidValue, DerefNullPtr: DerefNullPtr, - // May Depend on constants elsewhere - UnusedBrokenConst: UnusedBrokenConst, UnstableFeatures: UnstableFeatures, UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller, ArrayIntoIter: ArrayIntoIter::default(), diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index e8aca5f2e7d85..d38e9a70480a2 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -192,6 +192,15 @@ impl<'tcx> TyCtxtAt<'tcx> { self, def_id: DefId, ) -> Result, ErrorHandled> { + if let Some(def_id) = def_id.as_local() { + if let Some(err) = self + .mir_borrowck(def_id) + .tainted_by_errors + .or(self.mir_const_qualif(def_id).tainted_by_errors) + { + return Err(err.into()); + } + } trace!("eval_static_initializer: Need to compute {:?}", def_id); assert!(self.is_static(def_id)); let instance = ty::Instance::mono(*self, def_id); diff --git a/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.rs b/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.rs index 3edb3a10b7695..4ae75544c60c4 100644 --- a/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.rs +++ b/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.rs @@ -13,8 +13,6 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. -const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. -//~^ ERROR: failed const fn idx() -> usize { 1 @@ -35,9 +33,6 @@ fn main() { x[const { idx() }]; // Ok, should not produce stderr. x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays. const { &ARR[idx()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - // - //~^^ ERROR: failed let y = &x; y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021 diff --git a/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr b/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr index 84e7eff45573e..d5ce891b6805a 100644 --- a/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr +++ b/src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.stderr @@ -1,17 +1,5 @@ -error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/test.rs:38:14 - | -LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 - -note: erroneous constant encountered - --> $DIR/test.rs:38:5 - | -LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true. - | ^^^^^^^^^^^^^^^^^^^^^^ - error: indexing may panic - --> $DIR/test.rs:29:5 + --> $DIR/test.rs:27:5 | LL | x[index]; | ^^^^^^^^ @@ -21,7 +9,7 @@ LL | x[index]; = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` error: indexing may panic - --> $DIR/test.rs:47:5 + --> $DIR/test.rs:42:5 | LL | v[0]; | ^^^^ @@ -29,7 +17,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:48:5 + --> $DIR/test.rs:43:5 | LL | v[10]; | ^^^^^ @@ -37,7 +25,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:49:5 + --> $DIR/test.rs:44:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -45,7 +33,7 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:55:5 + --> $DIR/test.rs:50:5 | LL | v[N]; | ^^^^ @@ -53,19 +41,12 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/test.rs:56:5 + --> $DIR/test.rs:51:5 | LL | v[M]; | ^^^^ | = help: consider using `.get(n)` or `.get_mut(n)` instead -error[E0080]: evaluation of constant value failed - --> $DIR/test.rs:16:24 - | -LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 - -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0080`. diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.rs b/src/tools/clippy/tests/ui/indexing_slicing_index.rs index 1ac0bb11014aa..2ababad7fc758 100644 --- a/src/tools/clippy/tests/ui/indexing_slicing_index.rs +++ b/src/tools/clippy/tests/ui/indexing_slicing_index.rs @@ -13,8 +13,6 @@ const ARR: [i32; 2] = [1, 2]; const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false. //~^ ERROR: indexing may panic -const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. -//~^ ERROR: indexing may panic const fn idx() -> usize { 1 diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr index 6d64fa1e6cf89..2996e31a1aa26 100644 --- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr +++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr @@ -9,29 +9,20 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re = note: `-D clippy::indexing-slicing` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]` -error: indexing may panic - --> $DIR/indexing_slicing_index.rs:16:24 - | -LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^ - | - = help: consider using `.get(n)` or `.get_mut(n)` instead - = note: the suggestion might not be applicable in constant blocks - error[E0080]: evaluation of `main::{constant#3}` failed - --> $DIR/indexing_slicing_index.rs:48:14 + --> $DIR/indexing_slicing_index.rs:46:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 note: erroneous constant encountered - --> $DIR/indexing_slicing_index.rs:48:5 + --> $DIR/indexing_slicing_index.rs:46:5 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^^^^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:29:5 + --> $DIR/indexing_slicing_index.rs:27:5 | LL | x[index]; | ^^^^^^^^ @@ -39,7 +30,7 @@ LL | x[index]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:32:5 + --> $DIR/indexing_slicing_index.rs:30:5 | LL | x[4]; | ^^^^ @@ -48,13 +39,13 @@ LL | x[4]; = help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]` error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:34:5 + --> $DIR/indexing_slicing_index.rs:32:5 | LL | x[1 << 3]; | ^^^^^^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:45:14 + --> $DIR/indexing_slicing_index.rs:43:14 | LL | const { &ARR[idx()] }; | ^^^^^^^^^^ @@ -63,7 +54,7 @@ LL | const { &ARR[idx()] }; = note: the suggestion might not be applicable in constant blocks error: indexing may panic - --> $DIR/indexing_slicing_index.rs:48:14 + --> $DIR/indexing_slicing_index.rs:46:14 | LL | const { &ARR[idx4()] }; | ^^^^^^^^^^^ @@ -72,13 +63,13 @@ LL | const { &ARR[idx4()] }; = note: the suggestion might not be applicable in constant blocks error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:55:5 + --> $DIR/indexing_slicing_index.rs:53:5 | LL | y[4]; | ^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:58:5 + --> $DIR/indexing_slicing_index.rs:56:5 | LL | v[0]; | ^^^^ @@ -86,7 +77,7 @@ LL | v[0]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:60:5 + --> $DIR/indexing_slicing_index.rs:58:5 | LL | v[10]; | ^^^^^ @@ -94,7 +85,7 @@ LL | v[10]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:62:5 + --> $DIR/indexing_slicing_index.rs:60:5 | LL | v[1 << 3]; | ^^^^^^^^^ @@ -102,13 +93,13 @@ LL | v[1 << 3]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:70:5 + --> $DIR/indexing_slicing_index.rs:68:5 | LL | x[N]; | ^^^^ error: indexing may panic - --> $DIR/indexing_slicing_index.rs:73:5 + --> $DIR/indexing_slicing_index.rs:71:5 | LL | v[N]; | ^^^^ @@ -116,7 +107,7 @@ LL | v[N]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: indexing may panic - --> $DIR/indexing_slicing_index.rs:75:5 + --> $DIR/indexing_slicing_index.rs:73:5 | LL | v[M]; | ^^^^ @@ -124,17 +115,11 @@ LL | v[M]; = help: consider using `.get(n)` or `.get_mut(n)` instead error: index is out of bounds - --> $DIR/indexing_slicing_index.rs:79:13 + --> $DIR/indexing_slicing_index.rs:77:13 | LL | let _ = x[4]; | ^^^^ -error[E0080]: evaluation of constant value failed - --> $DIR/indexing_slicing_index.rs:16:24 - | -LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts. - | ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4 - -error: aborting due to 17 previous errors +error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/src/tools/miri/tests/fail/stacked_borrows/static_memory_modification.rs b/src/tools/miri/tests/fail/stacked_borrows/static_memory_modification.rs index 84d7878b264e5..5fab2438d0864 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/static_memory_modification.rs +++ b/src/tools/miri/tests/fail/stacked_borrows/static_memory_modification.rs @@ -3,6 +3,6 @@ static X: usize = 5; #[allow(mutable_transmutes)] fn main() { let _x = unsafe { - std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR: writing to alloc1 which is read-only + std::mem::transmute::<&usize, &mut usize>(&X) //~ ERROR: writing to alloc2 which is read-only }; } diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 78410e49d2a49..b5a9189b3fc34 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -62,7 +62,7 @@ fn statics() { static RC: &E = &E::V2(4); - // CHECK: [[t:_.*]] = const {alloc2: &&E}; + // CHECK: [[t:_.*]] = const {alloc9: &&E}; // CHECK: [[e2]] = (*[[t]]); let e2 = RC; diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.rs b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.rs index 0315938a7eda6..be8162c86b947 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.rs +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.rs @@ -4,12 +4,12 @@ trait Foo { const BAR: u32; } -const IMPL_REF_BAR: u32 = GlobalImplRef::BAR; +const IMPL_REF_BAR: u32 = GlobalImplRef::BAR; //~ ERROR E0391 struct GlobalImplRef; impl GlobalImplRef { - const BAR: u32 = IMPL_REF_BAR; //~ ERROR E0391 + const BAR: u32 = IMPL_REF_BAR; } fn main() {} diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr index 88b17be601ceb..bf37f537a4976 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr @@ -1,14 +1,9 @@ -error[E0391]: cycle detected when elaborating drops for `::BAR` - --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:22 - | -LL | const BAR: u32 = IMPL_REF_BAR; - | ^^^^^^^^^^^^ - | -note: ...which requires simplifying constant for the type system `IMPL_REF_BAR`... +error[E0391]: cycle detected when simplifying constant for the type system `IMPL_REF_BAR` --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1 | LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR; | ^^^^^^^^^^^^^^^^^^^^^^^ + | note: ...which requires const-evaluating + checking `IMPL_REF_BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:27 | @@ -29,7 +24,12 @@ note: ...which requires caching mir of `::BAR`, completing the cycle +note: ...which requires elaborating drops for `::BAR`... + --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:22 + | +LL | const BAR: u32 = IMPL_REF_BAR; + | ^^^^^^^^^^^^ + = note: ...which again requires simplifying constant for the type system `IMPL_REF_BAR`, completing the cycle = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr index fd1b4f2f964b0..d0ada37b99edd 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr @@ -1,9 +1,14 @@ -error[E0391]: cycle detected when elaborating drops for `FooDefault::BAR` +error[E0391]: cycle detected when caching mir of `FooDefault::BAR` for CTFE + --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 + | +LL | const BAR: u32 = DEFAULT_REF_BAR; + | ^^^^^^^^^^^^^^ + | +note: ...which requires elaborating drops for `FooDefault::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:22 | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^^ - | note: ...which requires simplifying constant for the type system `DEFAULT_REF_BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1 | @@ -24,13 +29,12 @@ note: ...which requires const-evaluating + checking `FooDefault::BAR`... | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^ -note: ...which requires caching mir of `FooDefault::BAR` for CTFE... + = note: ...which again requires caching mir of `FooDefault::BAR` for CTFE, completing the cycle +note: cycle used when const-evaluating + checking `FooDefault::BAR` --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^ - = note: ...which again requires elaborating drops for `FooDefault::BAR`, completing the cycle - = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.rs b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.rs index 68b653ff3c52b..62af85343406f 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.rs +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.rs @@ -4,12 +4,12 @@ trait Foo { const BAR: u32; } -const TRAIT_REF_BAR: u32 = ::BAR; +const TRAIT_REF_BAR: u32 = ::BAR; //~ ERROR E0391 struct GlobalTraitRef; impl Foo for GlobalTraitRef { - const BAR: u32 = TRAIT_REF_BAR; //~ ERROR E0391 + const BAR: u32 = TRAIT_REF_BAR; } fn main() {} diff --git a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr index 303400f928e65..317af7975aa7e 100644 --- a/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr +++ b/tests/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr @@ -1,14 +1,9 @@ -error[E0391]: cycle detected when elaborating drops for `::BAR` - --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:22 - | -LL | const BAR: u32 = TRAIT_REF_BAR; - | ^^^^^^^^^^^^^ - | -note: ...which requires simplifying constant for the type system `TRAIT_REF_BAR`... +error[E0391]: cycle detected when simplifying constant for the type system `TRAIT_REF_BAR` --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1 | LL | const TRAIT_REF_BAR: u32 = ::BAR; | ^^^^^^^^^^^^^^^^^^^^^^^^ + | note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:28 | @@ -29,7 +24,12 @@ note: ...which requires caching mir of `::BAR`, completing the cycle +note: ...which requires elaborating drops for `::BAR`... + --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:22 + | +LL | const BAR: u32 = TRAIT_REF_BAR; + | ^^^^^^^^^^^^^ + = note: ...which again requires simplifying constant for the type system `TRAIT_REF_BAR`, completing the cycle = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/check-static-immutable-mut-slices.rs b/tests/ui/check-static-immutable-mut-slices.rs index 8f9680778aa03..2872b67e90e5f 100644 --- a/tests/ui/check-static-immutable-mut-slices.rs +++ b/tests/ui/check-static-immutable-mut-slices.rs @@ -2,5 +2,6 @@ static TEST: &'static mut [isize] = &mut []; //~^ ERROR mutable references are not allowed +//~| ERROR undefined behavior to use this value pub fn main() { } diff --git a/tests/ui/check-static-immutable-mut-slices.stderr b/tests/ui/check-static-immutable-mut-slices.stderr index 402f9032b640d..b8e3d53f2d97a 100644 --- a/tests/ui/check-static-immutable-mut-slices.stderr +++ b/tests/ui/check-static-immutable-mut-slices.stderr @@ -4,6 +4,18 @@ error[E0764]: mutable references are not allowed in the final value of statics LL | static TEST: &'static mut [isize] = &mut []; | ^^^^^^^ -error: aborting due to 1 previous error +error[E0080]: it is undefined behavior to use this value + --> $DIR/check-static-immutable-mut-slices.rs:3:1 + | +LL | static TEST: &'static mut [isize] = &mut []; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static` + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 16, align: 8) { + ╾ALLOC0╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........ + } + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0764`. +Some errors have detailed explanations: E0080, E0764. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/check-static-values-constraints.stderr b/tests/ui/check-static-values-constraints.stderr index 064eb4b8a5cee..e7532de5647ad 100644 --- a/tests/ui/check-static-values-constraints.stderr +++ b/tests/ui/check-static-values-constraints.stderr @@ -129,17 +129,6 @@ LL | static STATIC19: Vec = vec![3]; = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0507]: cannot move out of static item `x` - --> $DIR/check-static-values-constraints.rs:119:9 - | -LL | x - | ^ move occurs because `x` has type `Vec`, which does not implement the `Copy` trait - | -help: consider borrowing here - | -LL | &x - | + - error[E0010]: allocations are not allowed in statics --> $DIR/check-static-values-constraints.rs:117:32 | @@ -158,6 +147,17 @@ LL | static x: Vec = vec![3]; = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0507]: cannot move out of static item `x` + --> $DIR/check-static-values-constraints.rs:119:9 + | +LL | x + | ^ move occurs because `x` has type `Vec`, which does not implement the `Copy` trait + | +help: consider borrowing here + | +LL | &x + | + + error: aborting due to 17 previous errors Some errors have detailed explanations: E0010, E0015, E0493, E0507. diff --git a/tests/ui/const-generics/issues/issue-100313.rs b/tests/ui/const-generics/issues/issue-100313.rs index 9af9b5ca45851..4e9d3626aa89c 100644 --- a/tests/ui/const-generics/issues/issue-100313.rs +++ b/tests/ui/const-generics/issues/issue-100313.rs @@ -9,7 +9,6 @@ impl T { unsafe { *(B as *const bool as *mut bool) = false; //~^ ERROR evaluation of constant value failed [E0080] - //~| ERROR assigning to `&T` is undefined behavior } } } diff --git a/tests/ui/const-generics/issues/issue-100313.stderr b/tests/ui/const-generics/issues/issue-100313.stderr index 5832dbe1777de..a422764fe2c58 100644 --- a/tests/ui/const-generics/issues/issue-100313.stderr +++ b/tests/ui/const-generics/issues/issue-100313.stderr @@ -1,12 +1,3 @@ -error: assigning to `&T` is undefined behavior, consider using an `UnsafeCell` - --> $DIR/issue-100313.rs:10:13 - | -LL | *(B as *const bool as *mut bool) = false; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: for more information, visit - = note: `#[deny(invalid_reference_casting)]` on by default - error[E0080]: evaluation of constant value failed --> $DIR/issue-100313.rs:10:13 | @@ -19,11 +10,11 @@ note: inside `T::<&true>::set_false` LL | *(B as *const bool as *mut bool) = false; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: inside `_` - --> $DIR/issue-100313.rs:19:5 + --> $DIR/issue-100313.rs:18:5 | LL | x.set_false(); | ^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-array-oob.rs b/tests/ui/consts/const-array-oob.rs index c747ab50c16b8..cf3db077e36ee 100644 --- a/tests/ui/consts/const-array-oob.rs +++ b/tests/ui/consts/const-array-oob.rs @@ -1,5 +1,6 @@ const FOO: [usize; 3] = [1, 2, 3]; -const BAR: usize = FOO[5]; // no error, because the error below occurs before regular const eval +const BAR: usize = FOO[5]; +//~^ ERROR: evaluation of constant value failed const BLUB: [u32; FOO[4]] = [5, 6]; //~^ ERROR evaluation of constant value failed [E0080] diff --git a/tests/ui/consts/const-array-oob.stderr b/tests/ui/consts/const-array-oob.stderr index d481d7728940b..be31f183b9aa4 100644 --- a/tests/ui/consts/const-array-oob.stderr +++ b/tests/ui/consts/const-array-oob.stderr @@ -1,9 +1,15 @@ error[E0080]: evaluation of constant value failed - --> $DIR/const-array-oob.rs:4:19 + --> $DIR/const-array-oob.rs:5:19 | LL | const BLUB: [u32; FOO[4]] = [5, 6]; | ^^^^^^ index out of bounds: the length is 3 but the index is 4 -error: aborting due to 1 previous error +error[E0080]: evaluation of constant value failed + --> $DIR/const-array-oob.rs:2:20 + | +LL | const BAR: usize = FOO[5]; + | ^^^^^^ index out of bounds: the length is 3 but the index is 5 + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/const-eval-query-stack.stderr b/tests/ui/consts/const-eval/const-eval-query-stack.stderr index 2fcb3d41dd927..96fd9ed5f043b 100644 --- a/tests/ui/consts/const-eval/const-eval-query-stack.stderr +++ b/tests/ui/consts/const-eval/const-eval-query-stack.stderr @@ -7,6 +7,5 @@ LL | const X: i32 = 1 / 0; query stack during panic: #0 [eval_to_allocation_raw] const-evaluating + checking `X` #1 [eval_to_const_value_raw] simplifying constant for the type system `X` -#2 [lint_mod] linting top-level module -#3 [analysis] running analysis passes on this crate +#2 [analysis] running analysis passes on this crate end of query stack diff --git a/tests/ui/consts/const-eval/const_fn_ptr.stderr b/tests/ui/consts/const-eval/const_fn_ptr.stderr index ca1585f883759..682a5a23afc3f 100644 --- a/tests/ui/consts/const-eval/const_fn_ptr.stderr +++ b/tests/ui/consts/const-eval/const_fn_ptr.stderr @@ -1,10 +1,5 @@ warning: skipping const checks | -help: skipping check that does not even have a feature gate - --> $DIR/const_fn_ptr.rs:11:5 - | -LL | X(x) - | ^^^^ help: skipping check that does not even have a feature gate --> $DIR/const_fn_ptr.rs:15:5 | @@ -15,6 +10,11 @@ help: skipping check that does not even have a feature gate | LL | x(y) | ^^^^ +help: skipping check that does not even have a feature gate + --> $DIR/const_fn_ptr.rs:11:5 + | +LL | X(x) + | ^^^^ warning: 1 warning emitted diff --git a/tests/ui/consts/const-eval/generic-slice.stderr b/tests/ui/consts/const-eval/generic-slice.stderr index ff1dc29ccfdd0..8559f6d1a4422 100644 --- a/tests/ui/consts/const-eval/generic-slice.stderr +++ b/tests/ui/consts/const-eval/generic-slice.stderr @@ -1,3 +1,17 @@ +error[E0597]: `x` does not live long enough + --> $DIR/generic-slice.rs:27:5 + | +LL | let x: &[_] = &[]; + | - binding `x` declared here +LL | &x + | ^^ + | | + | borrowed value does not live long enough + | using this value as a static requires that `x` is borrowed for `'static` +LL | +LL | }; + | - `x` dropped here while still borrowed + error[E0597]: `x` does not live long enough --> $DIR/generic-slice.rs:15:9 | @@ -15,20 +29,6 @@ LL | LL | }; | - `x` dropped here while still borrowed -error[E0597]: `x` does not live long enough - --> $DIR/generic-slice.rs:27:5 - | -LL | let x: &[_] = &[]; - | - binding `x` declared here -LL | &x - | ^^ - | | - | borrowed value does not live long enough - | using this value as a static requires that `x` is borrowed for `'static` -LL | -LL | }; - | - `x` dropped here while still borrowed - error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/tests/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr b/tests/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr index b423edbdcec8d..5aba594f3b26f 100644 --- a/tests/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr +++ b/tests/ui/consts/const-eval/validate_uninhabited_zsts.64bit.stderr @@ -1,12 +1,3 @@ -warning: the type `!` does not permit zero-initialization - --> $DIR/validate_uninhabited_zsts.rs:4:14 - | -LL | unsafe { std::mem::transmute(()) } - | ^^^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed - | - = note: the `!` type has no valid value - = note: `#[warn(invalid_value)]` on by default - error[E0080]: evaluation of constant value failed --> $DIR/validate_uninhabited_zsts.rs:4:14 | @@ -19,34 +10,17 @@ note: inside `foo` LL | unsafe { std::mem::transmute(()) } | ^^^^^^^^^^^^^^^^^^^^^^^ note: inside `FOO` - --> $DIR/validate_uninhabited_zsts.rs:19:33 + --> $DIR/validate_uninhabited_zsts.rs:18:33 | LL | const FOO: [empty::Empty; 3] = [foo(); 3]; | ^^^^^ error[E0080]: evaluation of constant value failed - --> $DIR/validate_uninhabited_zsts.rs:21:42 + --> $DIR/validate_uninhabited_zsts.rs:20:42 | LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3]; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered a value of uninhabited type `Void` -warning: the type `empty::Empty` does not permit zero-initialization - --> $DIR/validate_uninhabited_zsts.rs:21:42 - | -LL | const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3]; - | ^^^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed - | -note: in this struct field - --> $DIR/validate_uninhabited_zsts.rs:16:22 - | -LL | pub struct Empty(Void); - | ^^^^ -note: enums with no inhabited variants have no valid value - --> $DIR/validate_uninhabited_zsts.rs:13:5 - | -LL | enum Void {} - | ^^^^^^^^^ - -error: aborting due to 2 previous errors; 2 warnings emitted +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const-eval/validate_uninhabited_zsts.rs b/tests/ui/consts/const-eval/validate_uninhabited_zsts.rs index b6783175dd379..b3bb39c554eb3 100644 --- a/tests/ui/consts/const-eval/validate_uninhabited_zsts.rs +++ b/tests/ui/consts/const-eval/validate_uninhabited_zsts.rs @@ -3,7 +3,6 @@ const fn foo() -> ! { unsafe { std::mem::transmute(()) } //~^ ERROR evaluation of constant value failed - //~| WARN the type `!` does not permit zero-initialization [invalid_value] } // Type defined in a submodule, so that it is not "visibly" @@ -20,7 +19,6 @@ const FOO: [empty::Empty; 3] = [foo(); 3]; const BAR: [empty::Empty; 3] = [unsafe { std::mem::transmute(()) }; 3]; //~^ ERROR evaluation of constant value failed -//~| WARN the type `empty::Empty` does not permit zero-initialization fn main() { FOO; diff --git a/tests/ui/consts/const-mut-refs/mut_ref_in_final.rs b/tests/ui/consts/const-mut-refs/mut_ref_in_final.rs index 93197d5bce494..8ba10de8ac169 100644 --- a/tests/ui/consts/const-mut-refs/mut_ref_in_final.rs +++ b/tests/ui/consts/const-mut-refs/mut_ref_in_final.rs @@ -8,6 +8,7 @@ const A: *const i32 = &4; // but we do not want to allow this to compile, // as that would be an enormous footgun in oli-obk's opinion. const B: *mut i32 = &mut 4; //~ ERROR mutable references are not allowed +//~^ ERROR: mutable pointer in final value of constant // Ok, no actual mutable allocation exists const B2: Option<&mut i32> = None; @@ -52,12 +53,16 @@ unsafe impl Sync for SyncPtr {} // However, we intern the inner memory as read-only, so this must be rejected. static RAW_MUT_CAST_S: SyncPtr = SyncPtr { x : &mut 42 as *mut _ as *const _ }; //~^ ERROR mutable references are not allowed +//~| ERROR encountered mutable pointer in final value of static static RAW_MUT_COERCE_S: SyncPtr = SyncPtr { x: &mut 0 }; //~^ ERROR mutable references are not allowed +//~| ERROR encountered mutable pointer in final value of static const RAW_MUT_CAST_C: SyncPtr = SyncPtr { x : &mut 42 as *mut _ as *const _ }; //~^ ERROR mutable references are not allowed +//~| ERROR: mutable pointer in final value of constant const RAW_MUT_COERCE_C: SyncPtr = SyncPtr { x: &mut 0 }; //~^ ERROR mutable references are not allowed +//~| ERROR: mutable pointer in final value of constant fn main() { println!("{}", unsafe { *A }); diff --git a/tests/ui/consts/const-mut-refs/mut_ref_in_final.stderr b/tests/ui/consts/const-mut-refs/mut_ref_in_final.stderr index 59e6aa4011c23..8203447a44141 100644 --- a/tests/ui/consts/const-mut-refs/mut_ref_in_final.stderr +++ b/tests/ui/consts/const-mut-refs/mut_ref_in_final.stderr @@ -4,8 +4,14 @@ error[E0764]: mutable references are not allowed in the final value of constants LL | const B: *mut i32 = &mut 4; | ^^^^^^ +error: encountered mutable pointer in final value of constant + --> $DIR/mut_ref_in_final.rs:10:1 + | +LL | const B: *mut i32 = &mut 4; + | ^^^^^^^^^^^^^^^^^ + error[E0716]: temporary value dropped while borrowed - --> $DIR/mut_ref_in_final.rs:16:40 + --> $DIR/mut_ref_in_final.rs:17:40 | LL | const B3: Option<&mut i32> = Some(&mut 42); | ----------^^- @@ -15,7 +21,7 @@ LL | const B3: Option<&mut i32> = Some(&mut 42); | using this value as a constant requires that borrow lasts for `'static` error[E0716]: temporary value dropped while borrowed - --> $DIR/mut_ref_in_final.rs:19:42 + --> $DIR/mut_ref_in_final.rs:20:42 | LL | const B4: Option<&mut i32> = helper(&mut 42); | ------------^^- @@ -25,7 +31,7 @@ LL | const B4: Option<&mut i32> = helper(&mut 42); | using this value as a constant requires that borrow lasts for `'static` error[E0716]: temporary value dropped while borrowed - --> $DIR/mut_ref_in_final.rs:34:65 + --> $DIR/mut_ref_in_final.rs:35:65 | LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42)); | -------------------------------^^-- @@ -35,7 +41,7 @@ LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42)); | using this value as a constant requires that borrow lasts for `'static` error[E0716]: temporary value dropped while borrowed - --> $DIR/mut_ref_in_final.rs:37:67 + --> $DIR/mut_ref_in_final.rs:38:67 | LL | static FOO2: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42)); | -------------------------------^^-- @@ -45,7 +51,7 @@ LL | static FOO2: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42)); | using this value as a static requires that borrow lasts for `'static` error[E0716]: temporary value dropped while borrowed - --> $DIR/mut_ref_in_final.rs:40:71 + --> $DIR/mut_ref_in_final.rs:41:71 | LL | static mut FOO3: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42)); | -------------------------------^^-- @@ -55,30 +61,54 @@ LL | static mut FOO3: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42)); | using this value as a static requires that borrow lasts for `'static` error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/mut_ref_in_final.rs:53:53 + --> $DIR/mut_ref_in_final.rs:54:53 | LL | static RAW_MUT_CAST_S: SyncPtr = SyncPtr { x : &mut 42 as *mut _ as *const _ }; | ^^^^^^^ +error: encountered mutable pointer in final value of static + --> $DIR/mut_ref_in_final.rs:54:1 + | +LL | static RAW_MUT_CAST_S: SyncPtr = SyncPtr { x : &mut 42 as *mut _ as *const _ }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/mut_ref_in_final.rs:55:54 + --> $DIR/mut_ref_in_final.rs:57:54 | LL | static RAW_MUT_COERCE_S: SyncPtr = SyncPtr { x: &mut 0 }; | ^^^^^^ +error: encountered mutable pointer in final value of static + --> $DIR/mut_ref_in_final.rs:57:1 + | +LL | static RAW_MUT_COERCE_S: SyncPtr = SyncPtr { x: &mut 0 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0764]: mutable references are not allowed in the final value of constants - --> $DIR/mut_ref_in_final.rs:57:52 + --> $DIR/mut_ref_in_final.rs:60:52 | LL | const RAW_MUT_CAST_C: SyncPtr = SyncPtr { x : &mut 42 as *mut _ as *const _ }; | ^^^^^^^ +error: encountered mutable pointer in final value of constant + --> $DIR/mut_ref_in_final.rs:60:1 + | +LL | const RAW_MUT_CAST_C: SyncPtr = SyncPtr { x : &mut 42 as *mut _ as *const _ }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0764]: mutable references are not allowed in the final value of constants - --> $DIR/mut_ref_in_final.rs:59:53 + --> $DIR/mut_ref_in_final.rs:63:53 | LL | const RAW_MUT_COERCE_C: SyncPtr = SyncPtr { x: &mut 0 }; | ^^^^^^ -error: aborting due to 10 previous errors +error: encountered mutable pointer in final value of constant + --> $DIR/mut_ref_in_final.rs:63:1 + | +LL | const RAW_MUT_COERCE_C: SyncPtr = SyncPtr { x: &mut 0 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 15 previous errors Some errors have detailed explanations: E0716, E0764. For more information about an error, try `rustc --explain E0716`. diff --git a/tests/ui/consts/const_cmp_type_id.stderr b/tests/ui/consts/const_cmp_type_id.stderr index 84be0b67307d8..98f5b3a5e90d3 100644 --- a/tests/ui/consts/const_cmp_type_id.stderr +++ b/tests/ui/consts/const_cmp_type_id.stderr @@ -4,6 +4,12 @@ error[E0131]: `main` function is not allowed to have generic parameters LL | const fn main() { | ^ `main` cannot have generic parameters +error[E0080]: evaluation of constant value failed + --> $DIR/const_cmp_type_id.rs:10:22 + | +LL | const _A: bool = TypeId::of::() < TypeId::of::(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ calling non-const function `::lt` + error[E0308]: mismatched types --> $DIR/const_cmp_type_id.rs:8:13 | @@ -22,7 +28,7 @@ LL | assert!(TypeId::of::<()>() != TypeId::of::()); = note: expected constant `host` found constant `true` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0131, E0308. -For more information about an error, try `rustc --explain E0131`. +Some errors have detailed explanations: E0080, E0131, E0308. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/const_let_assign3.stderr b/tests/ui/consts/const_let_assign3.stderr index 40c11acee5c9e..ae890131715e9 100644 --- a/tests/ui/consts/const_let_assign3.stderr +++ b/tests/ui/consts/const_let_assign3.stderr @@ -1,18 +1,18 @@ -error[E0658]: mutable references are not allowed in constant functions - --> $DIR/const_let_assign3.rs:6:18 +error[E0658]: mutable references are not allowed in constants + --> $DIR/const_let_assign3.rs:14:5 | -LL | const fn foo(&mut self, x: u32) { - | ^^^^^^^^^ +LL | s.foo(3); + | ^ | = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: mutable references are not allowed in constants - --> $DIR/const_let_assign3.rs:14:5 +error[E0658]: mutable references are not allowed in constant functions + --> $DIR/const_let_assign3.rs:6:18 | -LL | s.foo(3); - | ^ +LL | const fn foo(&mut self, x: u32) { + | ^^^^^^^^^ | = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable diff --git a/tests/ui/consts/const_refs_to_static_fail_invalid.stderr b/tests/ui/consts/const_refs_to_static_fail_invalid.stderr index 082f8532444ad..ec8af3af70101 100644 --- a/tests/ui/consts/const_refs_to_static_fail_invalid.stderr +++ b/tests/ui/consts/const_refs_to_static_fail_invalid.stderr @@ -9,12 +9,6 @@ LL | const C: &bool = unsafe { std::mem::transmute(&S) }; HEX_DUMP } -error: could not evaluate constant pattern - --> $DIR/const_refs_to_static_fail_invalid.rs:15:9 - | -LL | C => {} - | ^ - error[E0080]: it is undefined behavior to use this value --> $DIR/const_refs_to_static_fail_invalid.rs:25:5 | @@ -26,12 +20,6 @@ LL | const C: &i8 = unsafe { &S }; HEX_DUMP } -error: could not evaluate constant pattern - --> $DIR/const_refs_to_static_fail_invalid.rs:31:9 - | -LL | C => {} - | ^ - error[E0080]: it is undefined behavior to use this value --> $DIR/const_refs_to_static_fail_invalid.rs:39:5 | @@ -43,6 +31,18 @@ LL | const C: &i32 = unsafe { &S_MUT }; HEX_DUMP } +error: could not evaluate constant pattern + --> $DIR/const_refs_to_static_fail_invalid.rs:15:9 + | +LL | C => {} + | ^ + +error: could not evaluate constant pattern + --> $DIR/const_refs_to_static_fail_invalid.rs:31:9 + | +LL | C => {} + | ^ + error: could not evaluate constant pattern --> $DIR/const_refs_to_static_fail_invalid.rs:46:9 | diff --git a/tests/ui/consts/fn_trait_refs.stderr b/tests/ui/consts/fn_trait_refs.stderr index afe89461f031f..527579d99eaf9 100644 --- a/tests/ui/consts/fn_trait_refs.stderr +++ b/tests/ui/consts/fn_trait_refs.stderr @@ -74,6 +74,24 @@ LL | T: ~const FnMut<()> + ~const Destruct, | = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +error[E0015]: cannot call non-const operator in constants + --> $DIR/fn_trait_refs.rs:72:17 + | +LL | assert!(test_one == (1, 1, 1)); + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + = help: add `#![feature(effects)]` to the crate attributes to enable + +error[E0015]: cannot call non-const operator in constants + --> $DIR/fn_trait_refs.rs:75:17 + | +LL | assert!(test_two == (2, 2)); + | ^^^^^^^^^^^^^^^^^^ + | + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + = help: add `#![feature(effects)]` to the crate attributes to enable + error[E0015]: cannot call non-const closure in constant functions --> $DIR/fn_trait_refs.rs:17:5 | @@ -149,24 +167,6 @@ LL | const fn test_fn_mut(mut f: T) -> (T::Output, T::Output) LL | } | - value is dropped here -error[E0015]: cannot call non-const operator in constants - --> $DIR/fn_trait_refs.rs:72:17 - | -LL | assert!(test_one == (1, 1, 1)); - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable - -error[E0015]: cannot call non-const operator in constants - --> $DIR/fn_trait_refs.rs:75:17 - | -LL | assert!(test_two == (2, 2)); - | ^^^^^^^^^^^^^^^^^^ - | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable - error: aborting due to 20 previous errors Some errors have detailed explanations: E0015, E0493, E0635. diff --git a/tests/ui/consts/issue-16538.stderr b/tests/ui/consts/issue-16538.stderr index 834ffa8d3a0ee..3981b4ada4913 100644 --- a/tests/ui/consts/issue-16538.stderr +++ b/tests/ui/consts/issue-16538.stderr @@ -1,3 +1,12 @@ +error[E0015]: cannot call non-const fn `Y::foo` in statics + --> $DIR/issue-16538.rs:11:23 + | +LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: calls in statics are limited to constant functions, tuple structs and tuple variants + = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell + error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block --> $DIR/issue-16538.rs:11:22 | @@ -14,15 +23,6 @@ LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); | = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior -error[E0015]: cannot call non-const fn `Y::foo` in statics - --> $DIR/issue-16538.rs:11:23 - | -LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: calls in statics are limited to constant functions, tuple structs and tuple variants - = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell - error: aborting due to 3 previous errors Some errors have detailed explanations: E0015, E0133. diff --git a/tests/ui/consts/issue-17718-const-bad-values.rs b/tests/ui/consts/issue-17718-const-bad-values.rs index 0299bfef1b49a..dc74e0252ab7d 100644 --- a/tests/ui/consts/issue-17718-const-bad-values.rs +++ b/tests/ui/consts/issue-17718-const-bad-values.rs @@ -2,6 +2,7 @@ const C1: &'static mut [usize] = &mut []; //~^ ERROR: mutable references are not allowed +//~| ERROR: undefined behavior to use this value static mut S: usize = 3; const C2: &'static mut usize = unsafe { &mut S }; diff --git a/tests/ui/consts/issue-17718-const-bad-values.stderr b/tests/ui/consts/issue-17718-const-bad-values.stderr index 57fcb1c7e9a52..79af1e5888ade 100644 --- a/tests/ui/consts/issue-17718-const-bad-values.stderr +++ b/tests/ui/consts/issue-17718-const-bad-values.stderr @@ -4,8 +4,19 @@ error[E0764]: mutable references are not allowed in the final value of constants LL | const C1: &'static mut [usize] = &mut []; | ^^^^^^^ +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-17718-const-bad-values.rs:3:1 + | +LL | const C1: &'static mut [usize] = &mut []; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static` + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 16, align: 8) { + ╾ALLOC0╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........ + } + error[E0658]: referencing statics in constants is unstable - --> $DIR/issue-17718-const-bad-values.rs:7:46 + --> $DIR/issue-17718-const-bad-values.rs:8:46 | LL | const C2: &'static mut usize = unsafe { &mut S }; | ^ @@ -16,7 +27,7 @@ LL | const C2: &'static mut usize = unsafe { &mut S }; = note: `static` and `const` variables can refer to other `const` variables. A `const` variable, however, cannot refer to a `static` variable. = help: to fix this, the value can be extracted to a `const` and then used. -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0658, E0764. -For more information about an error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0080, E0658, E0764. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/issue-17718-const-borrow.rs b/tests/ui/consts/issue-17718-const-borrow.rs index 89316dbd5c41a..b1f88c61037e0 100644 --- a/tests/ui/consts/issue-17718-const-borrow.rs +++ b/tests/ui/consts/issue-17718-const-borrow.rs @@ -3,12 +3,17 @@ use std::cell::UnsafeCell; const A: UnsafeCell = UnsafeCell::new(1); const B: &'static UnsafeCell = &A; //~^ ERROR: cannot refer to interior mutable +//~| ERROR: mutable pointer in final value of constant -struct C { a: UnsafeCell } +struct C { + a: UnsafeCell, +} const D: C = C { a: UnsafeCell::new(1) }; const E: &'static UnsafeCell = &D.a; //~^ ERROR: cannot refer to interior mutable +//~| ERROR: mutable pointer in final value of constant const F: &'static C = &D; //~^ ERROR: cannot refer to interior mutable +//~| ERROR: mutable pointer in final value of constant fn main() {} diff --git a/tests/ui/consts/issue-17718-const-borrow.stderr b/tests/ui/consts/issue-17718-const-borrow.stderr index e3ff6c923ad7f..50292a98948db 100644 --- a/tests/ui/consts/issue-17718-const-borrow.stderr +++ b/tests/ui/consts/issue-17718-const-borrow.stderr @@ -4,18 +4,36 @@ error[E0492]: constants cannot refer to interior mutable data LL | const B: &'static UnsafeCell = &A; | ^^ this borrow of an interior mutable value may end up in the final value +error: encountered mutable pointer in final value of constant + --> $DIR/issue-17718-const-borrow.rs:4:1 + | +LL | const B: &'static UnsafeCell = &A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0492]: constants cannot refer to interior mutable data - --> $DIR/issue-17718-const-borrow.rs:9:39 + --> $DIR/issue-17718-const-borrow.rs:12:39 | LL | const E: &'static UnsafeCell = &D.a; | ^^^^ this borrow of an interior mutable value may end up in the final value +error: encountered mutable pointer in final value of constant + --> $DIR/issue-17718-const-borrow.rs:12:1 + | +LL | const E: &'static UnsafeCell = &D.a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0492]: constants cannot refer to interior mutable data - --> $DIR/issue-17718-const-borrow.rs:11:23 + --> $DIR/issue-17718-const-borrow.rs:15:23 | LL | const F: &'static C = &D; | ^^ this borrow of an interior mutable value may end up in the final value -error: aborting due to 3 previous errors +error: encountered mutable pointer in final value of constant + --> $DIR/issue-17718-const-borrow.rs:15:1 + | +LL | const F: &'static C = &D; + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0492`. diff --git a/tests/ui/consts/issue-66693.rs b/tests/ui/consts/issue-66693.rs index df45d01ec0299..416bd8ec72aef 100644 --- a/tests/ui/consts/issue-66693.rs +++ b/tests/ui/consts/issue-66693.rs @@ -12,9 +12,11 @@ const fn _foo() { //~^ ERROR: argument to `panic!()` in a const context must have type `&str` } -// ensure that conforming panics don't cause an error +// ensure that conforming panics don't cause an error beyond the failure to const eval const _: () = panic!(); +//~^ ERROR: evaluation of constant value failed static _BAR: () = panic!("panic in static"); +//~^ ERROR could not evaluate static initializer const fn _bar() { panic!("panic in const fn"); diff --git a/tests/ui/consts/issue-66693.stderr b/tests/ui/consts/issue-66693.stderr index f4898fd9732f5..a435ace477304 100644 --- a/tests/ui/consts/issue-66693.stderr +++ b/tests/ui/consts/issue-66693.stderr @@ -14,6 +14,22 @@ LL | static _FOO: () = panic!(true); | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) +error[E0080]: evaluation of constant value failed + --> $DIR/issue-66693.rs:16:15 + | +LL | const _: () = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-66693.rs:16:15 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: could not evaluate static initializer + --> $DIR/issue-66693.rs:18:19 + | +LL | static _BAR: () = panic!("panic in static"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'panic in static', $DIR/issue-66693.rs:18:19 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + error: argument to `panic!()` in a const context must have type `&str` --> $DIR/issue-66693.rs:11:5 | @@ -22,5 +38,6 @@ LL | panic!(&1); | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr index 200faf3558762..1a4fbaeeec535 100644 --- a/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr +++ b/tests/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr @@ -9,12 +9,6 @@ LL | const SLICE_MUT: &[u8; 1] = { ╾ALLOC0╼ │ ╾──────╼ } -error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:39:9 - | -LL | SLICE_MUT => true, - | ^^^^^^^^^ - error[E0080]: it is undefined behavior to use this value --> $DIR/const_refers_to_static_cross_crate.rs:16:1 | @@ -26,12 +20,6 @@ LL | const U8_MUT: &u8 = { ╾ALLOC0╼ │ ╾──────╼ } -error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:47:9 - | -LL | U8_MUT => true, - | ^^^^^^ - error[E0080]: it is undefined behavior to use this value --> $DIR/const_refers_to_static_cross_crate.rs:22:1 | @@ -43,18 +31,30 @@ LL | const U8_MUT2: &u8 = { ╾ALLOC0╼ │ ╾──────╼ } -error: could not evaluate constant pattern - --> $DIR/const_refers_to_static_cross_crate.rs:57:9 - | -LL | U8_MUT2 => true, - | ^^^^^^^ - error[E0080]: evaluation of constant value failed --> $DIR/const_refers_to_static_cross_crate.rs:28:15 | LL | match static_cross_crate::OPT_ZERO { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses mutable global memory +error: could not evaluate constant pattern + --> $DIR/const_refers_to_static_cross_crate.rs:39:9 + | +LL | SLICE_MUT => true, + | ^^^^^^^^^ + +error: could not evaluate constant pattern + --> $DIR/const_refers_to_static_cross_crate.rs:47:9 + | +LL | U8_MUT => true, + | ^^^^^^ + +error: could not evaluate constant pattern + --> $DIR/const_refers_to_static_cross_crate.rs:57:9 + | +LL | U8_MUT2 => true, + | ^^^^^^^ + error: could not evaluate constant pattern --> $DIR/const_refers_to_static_cross_crate.rs:64:9 | diff --git a/tests/ui/consts/miri_unleashed/mutable_references.rs b/tests/ui/consts/miri_unleashed/mutable_references.rs index 4e996464705f8..db3d81a4c438b 100644 --- a/tests/ui/consts/miri_unleashed/mutable_references.rs +++ b/tests/ui/consts/miri_unleashed/mutable_references.rs @@ -4,29 +4,27 @@ use std::cell::UnsafeCell; // a test demonstrating what things we could allow with a smarter const qualification -// this is fine because is not possible to mutate through an immutable reference. static FOO: &&mut u32 = &&mut 42; +//~^ ERROR encountered mutable pointer in final value of static -// this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR` -// which puts the mutable reference behind an immutable one. static BAR: &mut () = &mut (); +//~^ ERROR encountered mutable pointer in final value of static struct Foo(T); -// this is fine for the same reason as `BAR`. static BOO: &mut Foo<()> = &mut Foo(()); +//~^ ERROR encountered mutable pointer in final value of static // interior mutability is fine struct Meh { x: &'static UnsafeCell, } unsafe impl Sync for Meh {} -static MEH: Meh = Meh { - x: &UnsafeCell::new(42), -}; +static MEH: Meh = Meh { x: &UnsafeCell::new(42) }; +//~^ ERROR encountered mutable pointer in final value of static -// this is fine for the same reason as `BAR`. static OH_YES: &mut i32 = &mut 42; +//~^ ERROR encountered mutable pointer in final value of static fn main() { unsafe { diff --git a/tests/ui/consts/miri_unleashed/mutable_references.stderr b/tests/ui/consts/miri_unleashed/mutable_references.stderr index 39298842a33e7..1ba2f5893f174 100644 --- a/tests/ui/consts/miri_unleashed/mutable_references.stderr +++ b/tests/ui/consts/miri_unleashed/mutable_references.stderr @@ -1,5 +1,35 @@ +error: encountered mutable pointer in final value of static + --> $DIR/mutable_references.rs:7:1 + | +LL | static FOO: &&mut u32 = &&mut 42; + | ^^^^^^^^^^^^^^^^^^^^^ + +error: encountered mutable pointer in final value of static + --> $DIR/mutable_references.rs:10:1 + | +LL | static BAR: &mut () = &mut (); + | ^^^^^^^^^^^^^^^^^^^ + +error: encountered mutable pointer in final value of static + --> $DIR/mutable_references.rs:15:1 + | +LL | static BOO: &mut Foo<()> = &mut Foo(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: encountered mutable pointer in final value of static + --> $DIR/mutable_references.rs:23:1 + | +LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) }; + | ^^^^^^^^^^^^^^^ + +error: encountered mutable pointer in final value of static + --> $DIR/mutable_references.rs:26:1 + | +LL | static OH_YES: &mut i32 = &mut 42; + | ^^^^^^^^^^^^^^^^^^^^^^^ + error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item - --> $DIR/mutable_references.rs:35:5 + --> $DIR/mutable_references.rs:33:5 | LL | *OH_YES = 99; | ^^^^^^^^^^^^ cannot assign @@ -7,31 +37,31 @@ LL | *OH_YES = 99; warning: skipping const checks | help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:8:26 + --> $DIR/mutable_references.rs:7:26 | LL | static FOO: &&mut u32 = &&mut 42; | ^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:12:23 + --> $DIR/mutable_references.rs:10:23 | LL | static BAR: &mut () = &mut (); | ^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:17:28 + --> $DIR/mutable_references.rs:15:28 | LL | static BOO: &mut Foo<()> = &mut Foo(()); | ^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:25:8 + --> $DIR/mutable_references.rs:23:28 | -LL | x: &UnsafeCell::new(42), - | ^^^^^^^^^^^^^^^^^^^^ +LL | static MEH: Meh = Meh { x: &UnsafeCell::new(42) }; + | ^^^^^^^^^^^^^^^^^^^^ help: skipping check that does not even have a feature gate - --> $DIR/mutable_references.rs:29:27 + --> $DIR/mutable_references.rs:26:27 | LL | static OH_YES: &mut i32 = &mut 42; | ^^^^^^^ -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 6 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0594`. diff --git a/tests/ui/consts/partial_qualif.rs b/tests/ui/consts/partial_qualif.rs index 7c28b8b8a628e..d60b1219460ba 100644 --- a/tests/ui/consts/partial_qualif.rs +++ b/tests/ui/consts/partial_qualif.rs @@ -1,6 +1,7 @@ use std::cell::Cell; const FOO: &(Cell, bool) = { + //~^ ERROR: mutable pointer in final value of constant let mut a = (Cell::new(0), false); a.1 = true; // sets `qualif(a)` to `qualif(a) | qualif(true)` &{a} //~ ERROR cannot refer to interior mutable diff --git a/tests/ui/consts/partial_qualif.stderr b/tests/ui/consts/partial_qualif.stderr index 05e0eeee13329..4fd277907f4cf 100644 --- a/tests/ui/consts/partial_qualif.stderr +++ b/tests/ui/consts/partial_qualif.stderr @@ -1,9 +1,15 @@ error[E0492]: constants cannot refer to interior mutable data - --> $DIR/partial_qualif.rs:6:5 + --> $DIR/partial_qualif.rs:7:5 | LL | &{a} | ^^^^ this borrow of an interior mutable value may end up in the final value -error: aborting due to 1 previous error +error: encountered mutable pointer in final value of constant + --> $DIR/partial_qualif.rs:3:1 + | +LL | const FOO: &(Cell, bool) = { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0492`. diff --git a/tests/ui/consts/promote-not.stderr b/tests/ui/consts/promote-not.stderr index b93358e8dccea..524d69817217d 100644 --- a/tests/ui/consts/promote-not.stderr +++ b/tests/ui/consts/promote-not.stderr @@ -18,26 +18,6 @@ LL | x LL | }; | - temporary value is freed at the end of this statement -error[E0716]: temporary value dropped while borrowed - --> $DIR/promote-not.rs:20:32 - | -LL | let _x: &'static () = &foo(); - | ----------- ^^^^^ creates a temporary value which is freed while still in use - | | - | type annotation requires that borrow lasts for `'static` -LL | } - | - temporary value is freed at the end of this statement - -error[E0716]: temporary value dropped while borrowed - --> $DIR/promote-not.rs:28:29 - | -LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; - | ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use - | | - | type annotation requires that borrow lasts for `'static` -LL | } - | - temporary value is freed at the end of this statement - error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:33:29 | @@ -58,6 +38,26 @@ LL | let _val: &'static _ = &(Cell::new(1), 2).1; LL | }; | - temporary value is freed at the end of this statement +error[E0716]: temporary value dropped while borrowed + --> $DIR/promote-not.rs:20:32 + | +LL | let _x: &'static () = &foo(); + | ----------- ^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | } + | - temporary value is freed at the end of this statement + +error[E0716]: temporary value dropped while borrowed + --> $DIR/promote-not.rs:28:29 + | +LL | let _x: &'static i32 = &unsafe { U { x: 0 }.x }; + | ------------ ^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | } + | - temporary value is freed at the end of this statement + error[E0716]: temporary value dropped while borrowed --> $DIR/promote-not.rs:46:29 | diff --git a/tests/ui/consts/promoted_const_call2.stderr b/tests/ui/consts/promoted_const_call2.stderr index 13d864ed3dbbd..177f7aed17df2 100644 --- a/tests/ui/consts/promoted_const_call2.stderr +++ b/tests/ui/consts/promoted_const_call2.stderr @@ -18,6 +18,12 @@ LL | let _: &'static _ = &id(&String::new()); | | creates a temporary value which is freed while still in use | type annotation requires that borrow lasts for `'static` +error[E0493]: destructor of `String` cannot be evaluated at compile-time + --> $DIR/promoted_const_call2.rs:4:30 + | +LL | let _: &'static _ = &id(&String::new()); + | ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants + error[E0716]: temporary value dropped while borrowed --> $DIR/promoted_const_call2.rs:11:26 | @@ -38,12 +44,6 @@ LL | let _: &'static _ = &id(&String::new()); | | creates a temporary value which is freed while still in use | type annotation requires that borrow lasts for `'static` -error[E0493]: destructor of `String` cannot be evaluated at compile-time - --> $DIR/promoted_const_call2.rs:4:30 - | -LL | let _: &'static _ = &id(&String::new()); - | ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants - error: aborting due to 5 previous errors Some errors have detailed explanations: E0493, E0716. diff --git a/tests/ui/consts/qualif-indirect-mutation-fail.stderr b/tests/ui/consts/qualif-indirect-mutation-fail.stderr index 6379c00e4b434..458dc2071c48e 100644 --- a/tests/ui/consts/qualif-indirect-mutation-fail.stderr +++ b/tests/ui/consts/qualif-indirect-mutation-fail.stderr @@ -1,21 +1,55 @@ -error[E0493]: destructor of `(u32, Option)` cannot be evaluated at compile-time - --> $DIR/qualif-indirect-mutation-fail.rs:9:9 - | -LL | let mut a: (u32, Option) = (0, None); - | ^^^^^ the destructor for this type cannot be evaluated in constant functions - error[E0493]: destructor of `Option` cannot be evaluated at compile-time --> $DIR/qualif-indirect-mutation-fail.rs:15:9 | LL | let mut x = None; | ^^^^^ the destructor for this type cannot be evaluated in constants +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = note: calling non-const function ` as Drop>::drop` + | +note: inside `std::ptr::drop_in_place::> - shim(Some(Vec))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `std::ptr::drop_in_place:: - shim(Some(String))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `std::ptr::drop_in_place::> - shim(Some(Option))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `A1` + --> $DIR/qualif-indirect-mutation-fail.rs:21:1 + | +LL | }; + | ^ + error[E0493]: destructor of `Option` cannot be evaluated at compile-time --> $DIR/qualif-indirect-mutation-fail.rs:31:9 | LL | let _z = x; | ^^ the destructor for this type cannot be evaluated in constants +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = note: calling non-const function ` as Drop>::drop` + | +note: inside `std::ptr::drop_in_place::> - shim(Some(Vec))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `std::ptr::drop_in_place:: - shim(Some(String))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `std::ptr::drop_in_place::> - shim(Some(Option))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `A2` + --> $DIR/qualif-indirect-mutation-fail.rs:32:1 + | +LL | }; + | ^ + +error[E0493]: destructor of `(u32, Option)` cannot be evaluated at compile-time + --> $DIR/qualif-indirect-mutation-fail.rs:9:9 + | +LL | let mut a: (u32, Option) = (0, None); + | ^^^^^ the destructor for this type cannot be evaluated in constant functions + error[E0493]: destructor of `Option` cannot be evaluated at compile-time --> $DIR/qualif-indirect-mutation-fail.rs:36:9 | @@ -52,6 +86,7 @@ error[E0493]: destructor of `Option` cannot be evaluated at compile-time LL | let x: Option = None; | ^ the destructor for this type cannot be evaluated in constant functions -error: aborting due to 9 previous errors +error: aborting due to 11 previous errors -For more information about this error, try `rustc --explain E0493`. +Some errors have detailed explanations: E0080, E0493. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/qualif_overwrite.rs b/tests/ui/consts/qualif_overwrite.rs index aae4e41ffd7ee..07e0f81aba5d2 100644 --- a/tests/ui/consts/qualif_overwrite.rs +++ b/tests/ui/consts/qualif_overwrite.rs @@ -5,6 +5,7 @@ use std::cell::Cell; // We can fix this properly in the future by allowing constants that do not depend on generics // to be checked by an analysis on the final value instead of looking at the body. const FOO: &Option> = { + //~^ ERROR: mutable pointer in final value of constant let mut a = Some(Cell::new(0)); a = None; // sets `qualif(a)` to `qualif(a) | qualif(None)` &{a} //~ ERROR cannot refer to interior mutable diff --git a/tests/ui/consts/qualif_overwrite.stderr b/tests/ui/consts/qualif_overwrite.stderr index 976cf7bd79ebb..3a40bf2c83115 100644 --- a/tests/ui/consts/qualif_overwrite.stderr +++ b/tests/ui/consts/qualif_overwrite.stderr @@ -1,9 +1,15 @@ error[E0492]: constants cannot refer to interior mutable data - --> $DIR/qualif_overwrite.rs:10:5 + --> $DIR/qualif_overwrite.rs:11:5 | LL | &{a} | ^^^^ this borrow of an interior mutable value may end up in the final value -error: aborting due to 1 previous error +error: encountered mutable pointer in final value of constant + --> $DIR/qualif_overwrite.rs:7:1 + | +LL | const FOO: &Option> = { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0492`. diff --git a/tests/ui/consts/qualif_overwrite_2.rs b/tests/ui/consts/qualif_overwrite_2.rs index 1819d9a6d203d..95f952784a026 100644 --- a/tests/ui/consts/qualif_overwrite_2.rs +++ b/tests/ui/consts/qualif_overwrite_2.rs @@ -3,6 +3,7 @@ use std::cell::Cell; // const qualification is not smart enough to know about fields and always assumes that there might // be other fields that caused the qualification const FOO: &Option> = { + //~^ ERROR: mutable pointer in final value of constant let mut a = (Some(Cell::new(0)),); a.0 = None; // sets `qualif(a)` to `qualif(a) | qualif(None)` &{a.0} //~ ERROR cannot refer to interior mutable diff --git a/tests/ui/consts/qualif_overwrite_2.stderr b/tests/ui/consts/qualif_overwrite_2.stderr index a107c4a5c6dbf..ebaff3ef58d70 100644 --- a/tests/ui/consts/qualif_overwrite_2.stderr +++ b/tests/ui/consts/qualif_overwrite_2.stderr @@ -1,9 +1,15 @@ error[E0492]: constants cannot refer to interior mutable data - --> $DIR/qualif_overwrite_2.rs:8:5 + --> $DIR/qualif_overwrite_2.rs:9:5 | LL | &{a.0} | ^^^^^^ this borrow of an interior mutable value may end up in the final value -error: aborting due to 1 previous error +error: encountered mutable pointer in final value of constant + --> $DIR/qualif_overwrite_2.rs:5:1 + | +LL | const FOO: &Option> = { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0492`. diff --git a/tests/ui/consts/recursive-zst-static.default.stderr b/tests/ui/consts/recursive-zst-static.default.stderr index 5b4a0418b1e9a..243368edf6b56 100644 --- a/tests/ui/consts/recursive-zst-static.default.stderr +++ b/tests/ui/consts/recursive-zst-static.default.stderr @@ -5,15 +5,7 @@ LL | static FOO: () = FOO; | ^^^ | = note: ...which immediately requires const-evaluating + checking `FOO` again -note: cycle used when linting top-level module - --> $DIR/recursive-zst-static.rs:10:1 - | -LL | / static FOO: () = FOO; -LL | | -LL | | fn main() { -LL | | FOO -LL | | } - | |_^ + = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/consts/recursive-zst-static.unleash.stderr b/tests/ui/consts/recursive-zst-static.unleash.stderr index 5b4a0418b1e9a..243368edf6b56 100644 --- a/tests/ui/consts/recursive-zst-static.unleash.stderr +++ b/tests/ui/consts/recursive-zst-static.unleash.stderr @@ -5,15 +5,7 @@ LL | static FOO: () = FOO; | ^^^ | = note: ...which immediately requires const-evaluating + checking `FOO` again -note: cycle used when linting top-level module - --> $DIR/recursive-zst-static.rs:10:1 - | -LL | / static FOO: () = FOO; -LL | | -LL | | fn main() { -LL | | FOO -LL | | } - | |_^ + = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/consts/refs-to-cell-in-final.rs b/tests/ui/consts/refs-to-cell-in-final.rs index 6a849ff0df929..7c8cadde4041a 100644 --- a/tests/ui/consts/refs-to-cell-in-final.rs +++ b/tests/ui/consts/refs-to-cell-in-final.rs @@ -12,7 +12,9 @@ unsafe impl Sync for SyncPtr {} // by static const checks! static RAW_SYNC_S: SyncPtr> = SyncPtr { x: &Cell::new(42) }; //~^ ERROR: cannot refer to interior mutable data +//~| ERROR: encountered mutable pointer in final value of static const RAW_SYNC_C: SyncPtr> = SyncPtr { x: &Cell::new(42) }; //~^ ERROR: cannot refer to interior mutable data +//~| ERROR: mutable pointer in final value of constant fn main() {} diff --git a/tests/ui/consts/refs-to-cell-in-final.stderr b/tests/ui/consts/refs-to-cell-in-final.stderr index fae16fa01251c..e9334184df4ca 100644 --- a/tests/ui/consts/refs-to-cell-in-final.stderr +++ b/tests/ui/consts/refs-to-cell-in-final.stderr @@ -6,12 +6,24 @@ LL | static RAW_SYNC_S: SyncPtr> = SyncPtr { x: &Cell::new(42) }; | = help: to fix this, the value can be extracted to a separate `static` item and then referenced +error: encountered mutable pointer in final value of static + --> $DIR/refs-to-cell-in-final.rs:13:1 + | +LL | static RAW_SYNC_S: SyncPtr> = SyncPtr { x: &Cell::new(42) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0492]: constants cannot refer to interior mutable data - --> $DIR/refs-to-cell-in-final.rs:15:53 + --> $DIR/refs-to-cell-in-final.rs:16:53 | LL | const RAW_SYNC_C: SyncPtr> = SyncPtr { x: &Cell::new(42) }; | ^^^^^^^^^^^^^^ this borrow of an interior mutable value may end up in the final value -error: aborting due to 2 previous errors +error: encountered mutable pointer in final value of constant + --> $DIR/refs-to-cell-in-final.rs:16:1 + | +LL | const RAW_SYNC_C: SyncPtr> = SyncPtr { x: &Cell::new(42) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0492`. diff --git a/tests/ui/consts/static_mut_containing_mut_ref2.rs b/tests/ui/consts/static_mut_containing_mut_ref2.rs index e60a17922fd0c..365d7e28bc7b1 100644 --- a/tests/ui/consts/static_mut_containing_mut_ref2.rs +++ b/tests/ui/consts/static_mut_containing_mut_ref2.rs @@ -8,6 +8,7 @@ pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; //[mut_refs]~^ ERROR could not evaluate static initializer //[stock]~^^ ERROR mutation through a reference is not allowed in statics + //[stock]~| ERROR could not evaluate static initializer }; fn main() {} diff --git a/tests/ui/consts/static_mut_containing_mut_ref2.stock.stderr b/tests/ui/consts/static_mut_containing_mut_ref2.stock.stderr index 5ff9c0b6e2b90..457e38e8ffe3c 100644 --- a/tests/ui/consts/static_mut_containing_mut_ref2.stock.stderr +++ b/tests/ui/consts/static_mut_containing_mut_ref2.stock.stderr @@ -8,6 +8,13 @@ LL | *(&mut STDERR_BUFFER_SPACE) = 42; = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 1 previous error +error[E0080]: could not evaluate static initializer + --> $DIR/static_mut_containing_mut_ref2.rs:8:5 + | +LL | *(&mut STDERR_BUFFER_SPACE) = 42; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0080, E0658. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/write-to-static-mut-in-static.rs b/tests/ui/consts/write-to-static-mut-in-static.rs index 43c63fed8cef1..720d72666c2ed 100644 --- a/tests/ui/consts/write-to-static-mut-in-static.rs +++ b/tests/ui/consts/write-to-static-mut-in-static.rs @@ -6,5 +6,6 @@ pub static mut C: u32 = unsafe { C = 1; 0 }; //~^ ERROR cycle detected pub static D: u32 = D; +//~^ ERROR cycle detected fn main() {} diff --git a/tests/ui/consts/write-to-static-mut-in-static.stderr b/tests/ui/consts/write-to-static-mut-in-static.stderr index caee433a6813a..c1d8d43049c62 100644 --- a/tests/ui/consts/write-to-static-mut-in-static.stderr +++ b/tests/ui/consts/write-to-static-mut-in-static.stderr @@ -11,20 +11,20 @@ LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ^^^^^ | = note: ...which immediately requires const-evaluating + checking `C` again -note: cycle used when linting top-level module - --> $DIR/write-to-static-mut-in-static.rs:1:1 + = note: cycle used when running analysis passes on this crate + = 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 const-evaluating + checking `D` + --> $DIR/write-to-static-mut-in-static.rs:8:21 + | +LL | pub static D: u32 = D; + | ^ | -LL | / pub static mut A: u32 = 0; -LL | | pub static mut B: () = unsafe { A = 1; }; -LL | | -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which immediately requires const-evaluating + checking `D` again + = note: cycle used when running analysis passes on this crate = 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: aborting due to 3 previous errors Some errors have detailed explanations: E0080, E0391. For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/consts/write_to_static_via_mut_ref.rs b/tests/ui/consts/write_to_static_via_mut_ref.rs index 39b830ae4e915..41d4260e72917 100644 --- a/tests/ui/consts/write_to_static_via_mut_ref.rs +++ b/tests/ui/consts/write_to_static_via_mut_ref.rs @@ -1,6 +1,7 @@ #![feature(const_mut_refs)] static OH_NO: &mut i32 = &mut 42; //~ ERROR mutable references are not allowed +//~^ ERROR encountered mutable pointer in final value of static fn main() { assert_eq!(*OH_NO, 42); *OH_NO = 43; //~ ERROR cannot assign to `*OH_NO`, as `OH_NO` is an immutable static diff --git a/tests/ui/consts/write_to_static_via_mut_ref.stderr b/tests/ui/consts/write_to_static_via_mut_ref.stderr index f64f0db6b25a1..9ccc6031c168a 100644 --- a/tests/ui/consts/write_to_static_via_mut_ref.stderr +++ b/tests/ui/consts/write_to_static_via_mut_ref.stderr @@ -4,13 +4,19 @@ error[E0764]: mutable references are not allowed in the final value of statics LL | static OH_NO: &mut i32 = &mut 42; | ^^^^^^^ +error: encountered mutable pointer in final value of static + --> $DIR/write_to_static_via_mut_ref.rs:3:1 + | +LL | static OH_NO: &mut i32 = &mut 42; + | ^^^^^^^^^^^^^^^^^^^^^^ + error[E0594]: cannot assign to `*OH_NO`, as `OH_NO` is an immutable static item - --> $DIR/write_to_static_via_mut_ref.rs:6:5 + --> $DIR/write_to_static_via_mut_ref.rs:7:5 | LL | *OH_NO = 43; | ^^^^^^^^^^^ cannot assign -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0594, E0764. For more information about an error, try `rustc --explain E0594`. diff --git a/tests/ui/drop/repeat-drop-2.stderr b/tests/ui/drop/repeat-drop-2.stderr index f030228f71ae4..009a2057212f0 100644 --- a/tests/ui/drop/repeat-drop-2.stderr +++ b/tests/ui/drop/repeat-drop-2.stderr @@ -1,3 +1,12 @@ +error[E0493]: destructor of `String` cannot be evaluated at compile-time + --> $DIR/repeat-drop-2.rs:7:25 + | +LL | const _: [String; 0] = [String::new(); 0]; + | -^^^^^^^^^^^^^---- + | || + | |the destructor for this type cannot be evaluated in constants + | value is dropped here + error[E0382]: use of moved value: `foo` --> $DIR/repeat-drop-2.rs:4:17 | @@ -13,15 +22,6 @@ help: consider cloning the value if the performance cost is acceptable LL | let _bar = foo.clone(); | ++++++++ -error[E0493]: destructor of `String` cannot be evaluated at compile-time - --> $DIR/repeat-drop-2.rs:7:25 - | -LL | const _: [String; 0] = [String::new(); 0]; - | -^^^^^^^^^^^^^---- - | || - | |the destructor for this type cannot be evaluated in constants - | value is dropped here - error[E0381]: used binding `x` isn't initialized --> $DIR/repeat-drop-2.rs:12:14 | diff --git a/tests/ui/error-codes/E0017.rs b/tests/ui/error-codes/E0017.rs index 9d3433fa543fd..511043b4813c4 100644 --- a/tests/ui/error-codes/E0017.rs +++ b/tests/ui/error-codes/E0017.rs @@ -4,6 +4,7 @@ static mut M: i32 = 3; const CR: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed //~| WARN taking a mutable +//~| ERROR: mutable pointer in final value of constant static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0658 //~| ERROR cannot borrow @@ -11,8 +12,10 @@ static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0658 static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed //~| WARN taking a mutable +//~| ERROR encountered mutable pointer in final value of static static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR mutable references are not //~^ WARN mutable reference of mutable static is discouraged [static_mut_ref] +//~| ERROR it is undefined behavior to use this value fn main() {} diff --git a/tests/ui/error-codes/E0017.stderr b/tests/ui/error-codes/E0017.stderr index 2a70f2ee0ae82..bb53186b82af1 100644 --- a/tests/ui/error-codes/E0017.stderr +++ b/tests/ui/error-codes/E0017.stderr @@ -1,5 +1,5 @@ warning: mutable reference of mutable static is discouraged - --> $DIR/E0017.rs:15:52 + --> $DIR/E0017.rs:17:52 | LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; | ^^^^^^ mutable reference of mutable static @@ -34,8 +34,14 @@ error[E0764]: mutable references are not allowed in the final value of constants LL | const CR: &'static mut i32 = &mut C; | ^^^^^^ +error: encountered mutable pointer in final value of constant + --> $DIR/E0017.rs:5:1 + | +LL | const CR: &'static mut i32 = &mut C; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0658]: mutation through a reference is not allowed in statics - --> $DIR/E0017.rs:8:39 + --> $DIR/E0017.rs:9:39 | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ @@ -45,19 +51,19 @@ LL | static STATIC_REF: &'static mut i32 = &mut X; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/E0017.rs:8:39 + --> $DIR/E0017.rs:9:39 | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ error[E0596]: cannot borrow immutable static item `X` as mutable - --> $DIR/E0017.rs:8:39 + --> $DIR/E0017.rs:9:39 | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ cannot borrow as mutable warning: taking a mutable reference to a `const` item - --> $DIR/E0017.rs:12:38 + --> $DIR/E0017.rs:13:38 | LL | static CONST_REF: &'static mut i32 = &mut C; | ^^^^^^ @@ -71,18 +77,35 @@ LL | const C: i32 = 2; | ^^^^^^^^^^^^ error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/E0017.rs:12:38 + --> $DIR/E0017.rs:13:38 | LL | static CONST_REF: &'static mut i32 = &mut C; | ^^^^^^ +error: encountered mutable pointer in final value of static + --> $DIR/E0017.rs:13:1 + | +LL | static CONST_REF: &'static mut i32 = &mut C; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/E0017.rs:15:52 + --> $DIR/E0017.rs:17:52 | LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; | ^^^^^^ -error: aborting due to 6 previous errors; 3 warnings emitted +error[E0080]: it is undefined behavior to use this value + --> $DIR/E0017.rs:17:1 + | +LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static` + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 8, align: 8) { + ╾ALLOC0╼ │ ╾──────╼ + } + +error: aborting due to 9 previous errors; 3 warnings emitted -Some errors have detailed explanations: E0596, E0658, E0764. -For more information about an error, try `rustc --explain E0596`. +Some errors have detailed explanations: E0080, E0596, E0658, E0764. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/error-codes/E0388.rs b/tests/ui/error-codes/E0388.rs index 6049d95f0d277..66981a8a343c1 100644 --- a/tests/ui/error-codes/E0388.rs +++ b/tests/ui/error-codes/E0388.rs @@ -3,11 +3,13 @@ const C: i32 = 2; const CR: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed //~| WARN taking a mutable + //~| ERROR: mutable pointer in final value static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR cannot borrow //~| ERROR E0658 //~| ERROR mutable references are not allowed static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed //~| WARN taking a mutable + //~| ERROR mutable pointer in final value fn main() {} diff --git a/tests/ui/error-codes/E0388.stderr b/tests/ui/error-codes/E0388.stderr index 1f7b688899ed0..04a30d7b72394 100644 --- a/tests/ui/error-codes/E0388.stderr +++ b/tests/ui/error-codes/E0388.stderr @@ -19,8 +19,14 @@ error[E0764]: mutable references are not allowed in the final value of constants LL | const CR: &'static mut i32 = &mut C; | ^^^^^^ +error: encountered mutable pointer in final value of constant + --> $DIR/E0388.rs:4:1 + | +LL | const CR: &'static mut i32 = &mut C; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0658]: mutation through a reference is not allowed in statics - --> $DIR/E0388.rs:6:39 + --> $DIR/E0388.rs:7:39 | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ @@ -30,19 +36,19 @@ LL | static STATIC_REF: &'static mut i32 = &mut X; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/E0388.rs:6:39 + --> $DIR/E0388.rs:7:39 | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ error[E0596]: cannot borrow immutable static item `X` as mutable - --> $DIR/E0388.rs:6:39 + --> $DIR/E0388.rs:7:39 | LL | static STATIC_REF: &'static mut i32 = &mut X; | ^^^^^^ cannot borrow as mutable warning: taking a mutable reference to a `const` item - --> $DIR/E0388.rs:10:38 + --> $DIR/E0388.rs:11:38 | LL | static CONST_REF: &'static mut i32 = &mut C; | ^^^^^^ @@ -56,12 +62,18 @@ LL | const C: i32 = 2; | ^^^^^^^^^^^^ error[E0764]: mutable references are not allowed in the final value of statics - --> $DIR/E0388.rs:10:38 + --> $DIR/E0388.rs:11:38 | LL | static CONST_REF: &'static mut i32 = &mut C; | ^^^^^^ -error: aborting due to 5 previous errors; 2 warnings emitted +error: encountered mutable pointer in final value of static + --> $DIR/E0388.rs:11:1 + | +LL | static CONST_REF: &'static mut i32 = &mut C; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors; 2 warnings emitted Some errors have detailed explanations: E0596, E0658, E0764. For more information about an error, try `rustc --explain E0596`. diff --git a/tests/ui/error-codes/E0396.stderr b/tests/ui/error-codes/E0396.stderr index ac1e7d65ce841..8bc14139d63b1 100644 --- a/tests/ui/error-codes/E0396.stderr +++ b/tests/ui/error-codes/E0396.stderr @@ -8,42 +8,42 @@ LL | const VALUE: u8 = unsafe { *REG_ADDR }; = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: dereferencing raw mutable pointers in constant functions is unstable - --> $DIR/E0396.rs:10:11 +error[E0658]: dereferencing raw mutable pointers in constants is unstable + --> $DIR/E0396.rs:14:36 | -LL | match *INFALLIBLE {} - | ^^^^^^^^^^^ +LL | const BAD: () = unsafe { match *INFALLIBLE {} }; + | ^^^^^^^^^^^ | = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: dereferencing raw mutable pointers in constant functions is unstable - --> $DIR/E0396.rs:10:11 +error[E0658]: dereferencing raw mutable pointers in constants is unstable + --> $DIR/E0396.rs:14:36 | -LL | match *INFALLIBLE {} - | ^^^^^^^^^^^ +LL | const BAD: () = unsafe { match *INFALLIBLE {} }; + | ^^^^^^^^^^^ | = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0658]: dereferencing raw mutable pointers in constants is unstable - --> $DIR/E0396.rs:14:36 +error[E0658]: dereferencing raw mutable pointers in constant functions is unstable + --> $DIR/E0396.rs:10:11 | -LL | const BAD: () = unsafe { match *INFALLIBLE {} }; - | ^^^^^^^^^^^ +LL | match *INFALLIBLE {} + | ^^^^^^^^^^^ | = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: dereferencing raw mutable pointers in constants is unstable - --> $DIR/E0396.rs:14:36 +error[E0658]: dereferencing raw mutable pointers in constant functions is unstable + --> $DIR/E0396.rs:10:11 | -LL | const BAD: () = unsafe { match *INFALLIBLE {} }; - | ^^^^^^^^^^^ +LL | match *INFALLIBLE {} + | ^^^^^^^^^^^ | = note: see issue #57349 for more information = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable diff --git a/tests/ui/error-codes/E0492.rs b/tests/ui/error-codes/E0492.rs index 2c735fcc9f91c..478f8ef7656f1 100644 --- a/tests/ui/error-codes/E0492.rs +++ b/tests/ui/error-codes/E0492.rs @@ -2,7 +2,9 @@ use std::sync::atomic::AtomicUsize; const A: AtomicUsize = AtomicUsize::new(0); const B: &'static AtomicUsize = &A; //~ ERROR E0492 +//~^ ERROR: mutable pointer in final value of constant static C: &'static AtomicUsize = &A; //~ ERROR E0492 +//~^ ERROR: mutable pointer in final value of static const NONE: &'static Option = &None; diff --git a/tests/ui/error-codes/E0492.stderr b/tests/ui/error-codes/E0492.stderr index 557c977e87d9c..b5c18e5e935ba 100644 --- a/tests/ui/error-codes/E0492.stderr +++ b/tests/ui/error-codes/E0492.stderr @@ -4,14 +4,26 @@ error[E0492]: constants cannot refer to interior mutable data LL | const B: &'static AtomicUsize = &A; | ^^ this borrow of an interior mutable value may end up in the final value +error: encountered mutable pointer in final value of constant + --> $DIR/E0492.rs:4:1 + | +LL | const B: &'static AtomicUsize = &A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0492]: statics cannot refer to interior mutable data - --> $DIR/E0492.rs:5:34 + --> $DIR/E0492.rs:6:34 | LL | static C: &'static AtomicUsize = &A; | ^^ this borrow of an interior mutable value may end up in the final value | = help: to fix this, the value can be extracted to a separate `static` item and then referenced -error: aborting due to 2 previous errors +error: encountered mutable pointer in final value of static + --> $DIR/E0492.rs:6:1 + | +LL | static C: &'static AtomicUsize = &A; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0492`. diff --git a/tests/ui/extern/issue-28324.rs b/tests/ui/extern/issue-28324.rs index f74726e8166dc..a5e240fa283b7 100644 --- a/tests/ui/extern/issue-28324.rs +++ b/tests/ui/extern/issue-28324.rs @@ -4,5 +4,6 @@ extern "C" { pub static BAZ: u32 = *&error_message_count; //~^ ERROR use of extern static is unsafe and requires +//~| ERROR could not evaluate static initializer fn main() {} diff --git a/tests/ui/extern/issue-28324.stderr b/tests/ui/extern/issue-28324.stderr index 94ff21319939a..1fccb34fdf37b 100644 --- a/tests/ui/extern/issue-28324.stderr +++ b/tests/ui/extern/issue-28324.stderr @@ -1,3 +1,9 @@ +error[E0080]: could not evaluate static initializer + --> $DIR/issue-28324.rs:5:23 + | +LL | pub static BAZ: u32 = *&error_message_count; + | ^^^^^^^^^^^^^^^^^^^^^ cannot access extern static (DefId(0:4 ~ issue_28324[8ec4]::{extern#0}::error_message_count)) + error[E0133]: use of extern static is unsafe and requires unsafe function or block --> $DIR/issue-28324.rs:5:25 | @@ -6,6 +12,7 @@ LL | pub static BAZ: u32 = *&error_message_count; | = 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 -For more information about this error, try `rustc --explain E0133`. +Some errors have detailed explanations: E0080, E0133. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.rs b/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.rs index dd00b327d2d20..93f01c9577c04 100644 --- a/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.rs +++ b/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.rs @@ -3,7 +3,7 @@ // Ensure that we check if trivial bounds on const items hold or not. -const UNUSABLE: () = () +const UNUSABLE: () = () //~ ERROR evaluation of constant value failed where String: Copy; diff --git a/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.stderr b/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.stderr index 942e5dbd88ef4..407682fee5664 100644 --- a/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.stderr +++ b/tests/ui/generic-const-items/trivially-unsatisfied-bounds-0.stderr @@ -1,3 +1,11 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/trivially-unsatisfied-bounds-0.rs:6:1 + | +LL | / const UNUSABLE: () = () +LL | | where +LL | | String: Copy; + | |_________________^ entering unreachable code + error[E0277]: the trait bound `String: Copy` is not satisfied --> $DIR/trivially-unsatisfied-bounds-0.rs:11:13 | @@ -13,6 +21,7 @@ LL | where LL | String: Copy; | ^^^^ required by this bound in `UNUSABLE` -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0080, E0277. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/issues/issue-17252.rs b/tests/ui/issues/issue-17252.rs index 7141e4874c02d..5941e10f8b068 100644 --- a/tests/ui/issues/issue-17252.rs +++ b/tests/ui/issues/issue-17252.rs @@ -4,6 +4,7 @@ fn main() { let _x: [u8; FOO]; // caused stack overflow prior to fix let _y: usize = 1 + { const BAR: usize = BAR; + //~^ ERROR: cycle let _z: [u8; BAR]; // caused stack overflow prior to fix 1 }; diff --git a/tests/ui/issues/issue-17252.stderr b/tests/ui/issues/issue-17252.stderr index d898486045759..56bc32b19ab73 100644 --- a/tests/ui/issues/issue-17252.stderr +++ b/tests/ui/issues/issue-17252.stderr @@ -10,13 +10,24 @@ note: ...which requires const-evaluating + checking `FOO`... LL | const FOO: usize = FOO; | ^^^ = note: ...which again requires simplifying constant for the type system `FOO`, completing the cycle -note: cycle used when const-evaluating + checking `main::{constant#0}` - --> $DIR/issue-17252.rs:4:18 + = note: cycle used when running analysis passes on this crate + = 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 simplifying constant for the type system `main::BAR` + --> $DIR/issue-17252.rs:6:9 + | +LL | const BAR: usize = BAR; + | ^^^^^^^^^^^^^^^^ + | +note: ...which requires const-evaluating + checking `main::BAR`... + --> $DIR/issue-17252.rs:6:28 | -LL | let _x: [u8; FOO]; // caused stack overflow prior to fix - | ^^^ +LL | const BAR: usize = BAR; + | ^^^ + = note: ...which again requires simplifying constant for the type system `main::BAR`, completing the cycle + = note: cycle used when running analysis passes on this crate = 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 +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.stderr b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.stderr index e23957c6de754..8a152f5896634 100644 --- a/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.stderr +++ b/tests/ui/issues/issue-23302-enum-infinite-recursion/issue-23302-3.stderr @@ -20,15 +20,7 @@ note: ...which requires const-evaluating + checking `B`... LL | const B: i32 = A; | ^ = note: ...which again requires simplifying constant for the type system `A`, completing the cycle -note: cycle used when linting top-level module - --> $DIR/issue-23302-3.rs:1:1 - | -LL | / const A: i32 = B; -LL | | -LL | | const B: i32 = A; -LL | | -LL | | fn main() { } - | |_____________^ + = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/issues/issue-46604.rs b/tests/ui/issues/issue-46604.rs index 6ec6e7bdcb81e..90430ea5e2bb8 100644 --- a/tests/ui/issues/issue-46604.rs +++ b/tests/ui/issues/issue-46604.rs @@ -1,4 +1,5 @@ static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR mutable references are not allowed +//~^ ERROR encountered mutable pointer in final value of static fn write>(buffer: T) { } fn main() { diff --git a/tests/ui/issues/issue-46604.stderr b/tests/ui/issues/issue-46604.stderr index 7faa2d79ba483..d91e3e818556a 100644 --- a/tests/ui/issues/issue-46604.stderr +++ b/tests/ui/issues/issue-46604.stderr @@ -4,13 +4,19 @@ error[E0764]: mutable references are not allowed in the final value of statics LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; | ^^^^^^^^^^^^^^^^^^^^ +error: encountered mutable pointer in final value of static + --> $DIR/issue-46604.rs:1:1 + | +LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; + | ^^^^^^^^^^^^^^^^^^^^^ + error[E0594]: cannot assign to `buf[_]`, as `buf` is an immutable static item - --> $DIR/issue-46604.rs:6:5 + --> $DIR/issue-46604.rs:7:5 | LL | buf[0]=2; | ^^^^^^^^ cannot assign -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0594, E0764. For more information about an error, try `rustc --explain E0594`. diff --git a/tests/ui/issues/issue-76191.rs b/tests/ui/issues/issue-76191.rs index d9790d2b56e28..277624c005a56 100644 --- a/tests/ui/issues/issue-76191.rs +++ b/tests/ui/issues/issue-76191.rs @@ -6,6 +6,7 @@ use std::ops::RangeInclusive; const RANGE: RangeInclusive = 0..=255; const RANGE2: RangeInclusive = panic!(); +//~^ ERROR evaluation of constant value failed fn main() { let n: i32 = 1; diff --git a/tests/ui/issues/issue-76191.stderr b/tests/ui/issues/issue-76191.stderr index 32d9105b25997..3702bfb776991 100644 --- a/tests/ui/issues/issue-76191.stderr +++ b/tests/ui/issues/issue-76191.stderr @@ -1,5 +1,13 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/issue-76191.rs:8:37 + | +LL | const RANGE2: RangeInclusive = panic!(); + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-76191.rs:8:37 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0308]: mismatched types - --> $DIR/issue-76191.rs:13:9 + --> $DIR/issue-76191.rs:14:9 | LL | const RANGE: RangeInclusive = 0..=255; | -------------------------------- constant defined here @@ -20,7 +28,7 @@ LL | 0..=255 => {} | ~~~~~~~ error[E0308]: mismatched types - --> $DIR/issue-76191.rs:15:9 + --> $DIR/issue-76191.rs:16:9 | LL | const RANGE2: RangeInclusive = panic!(); | --------------------------------- constant defined here @@ -38,6 +46,7 @@ LL | RANGE2 => {} found struct `RangeInclusive` = note: constants only support matching by type, if you meant to match against a range of values, consider using a range pattern like `min ..= max` in the match block -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0308`. +Some errors have detailed explanations: E0080, E0308. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/liveness/liveness-consts.stderr b/tests/ui/liveness/liveness-consts.stderr index 016debdd39608..34ce39473379e 100644 --- a/tests/ui/liveness/liveness-consts.stderr +++ b/tests/ui/liveness/liveness-consts.stderr @@ -23,12 +23,6 @@ warning: unused variable: `z` LL | pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8; { let z = 18; 100 }] { | ^ help: if this is intentional, prefix it with an underscore: `_z` -warning: unused variable: `z` - --> $DIR/liveness-consts.rs:60:13 - | -LL | let z = 42; - | ^ help: if this is intentional, prefix it with an underscore: `_z` - warning: variable `a` is assigned to, but never used --> $DIR/liveness-consts.rs:7:13 | @@ -46,6 +40,12 @@ LL | b += 1; = help: maybe it is overwritten before being read? = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` +warning: unused variable: `z` + --> $DIR/liveness-consts.rs:60:13 + | +LL | let z = 42; + | ^ help: if this is intentional, prefix it with an underscore: `_z` + warning: value assigned to `t` is never read --> $DIR/liveness-consts.rs:42:9 | diff --git a/tests/ui/recursion/recursive-static-definition.stderr b/tests/ui/recursion/recursive-static-definition.stderr index 4fc3ee68ebc29..50b69689027c3 100644 --- a/tests/ui/recursion/recursive-static-definition.stderr +++ b/tests/ui/recursion/recursive-static-definition.stderr @@ -5,14 +5,7 @@ LL | pub static FOO: u32 = FOO; | ^^^ | = note: ...which immediately requires const-evaluating + checking `FOO` again -note: cycle used when linting top-level module - --> $DIR/recursive-static-definition.rs:1:1 - | -LL | / pub static FOO: u32 = FOO; -LL | | -LL | | -LL | | fn main() {} - | |____________^ + = note: cycle used when running analysis passes on this crate = 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 diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr index e72d259e8a561..f802841d2e468 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-pass.stderr @@ -1,12 +1,3 @@ -error[E0015]: cannot call non-const fn `::plus` in constant functions - --> $DIR/call-const-trait-method-pass.rs:36:7 - | -LL | a.plus(b) - | ^^^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = help: add `#![feature(effects)]` to the crate attributes to enable - error[E0015]: cannot call non-const operator in constants --> $DIR/call-const-trait-method-pass.rs:39:22 | @@ -21,6 +12,15 @@ LL | impl const std::ops::Add for Int { = note: calls in constants are limited to constant functions, tuple structs and tuple variants = help: add `#![feature(effects)]` to the crate attributes to enable +error[E0015]: cannot call non-const fn `::plus` in constant functions + --> $DIR/call-const-trait-method-pass.rs:36:7 + | +LL | a.plus(b) + | ^^^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + = help: add `#![feature(effects)]` to the crate attributes to enable + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr index b66b27ad2bdd5..a225125ef53d6 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-closures.stderr @@ -23,23 +23,23 @@ LL | const fn answer u8>(f: &F) -> u8 { | ^^^^^^^^^^ error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closures.rs:12:5 + --> $DIR/const-closures.rs:24:5 | -LL | f() * 7 +LL | f() + f() | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | -LL | F: ~const FnOnce() -> u8 + ~const std::ops::Fn<()>, - | +++++++++++++++++++++++++ +LL | const fn answer u8 + ~const std::ops::Fn<()>>(f: &F) -> u8 { + | +++++++++++++++++++++++++ error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closures.rs:24:5 + --> $DIR/const-closures.rs:24:11 | LL | f() + f() - | ^^^ + | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = help: add `#![feature(effects)]` to the crate attributes to enable @@ -49,17 +49,17 @@ LL | const fn answer u8 + ~const std::ops::Fn<()>>(f: &F) -> u | +++++++++++++++++++++++++ error[E0015]: cannot call non-const closure in constant functions - --> $DIR/const-closures.rs:24:11 + --> $DIR/const-closures.rs:12:5 | -LL | f() + f() - | ^^^ +LL | f() * 7 + | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants = help: add `#![feature(effects)]` to the crate attributes to enable help: consider further restricting this bound | -LL | const fn answer u8 + ~const std::ops::Fn<()>>(f: &F) -> u8 { - | +++++++++++++++++++++++++ +LL | F: ~const FnOnce() -> u8 + ~const std::ops::Fn<()>, + | +++++++++++++++++++++++++ error: aborting due to 7 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr index 8997e7ade6c17..9afa2072dde95 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr @@ -4,6 +4,57 @@ error[E0493]: destructor of `T` cannot be evaluated at compile-time LL | const fn check(_: T) {} | ^ the destructor for this type cannot be evaluated in constant functions -error: aborting due to 1 previous error +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = note: calling non-const function `::drop` + | +note: inside `std::ptr::drop_in_place:: - shim(Some(NonTrivialDrop))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `check::` + --> $DIR/const-drop-fail.rs:24:43 + | +LL | const fn check(_: T) {} + | ^ +note: inside `_` + --> $DIR/const-drop-fail.rs:28:23 + | +LL | const _: () = check($exp); + | ^^^^^^^^^^^ +... +LL | / check_all! { +LL | | NonTrivialDrop, +LL | | ConstImplWithDropGlue(NonTrivialDrop), +LL | | } + | |_- in this macro invocation + = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = note: calling non-const function `::drop` + | +note: inside `std::ptr::drop_in_place:: - shim(Some(ConstImplWithDropGlue))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `check::` + --> $DIR/const-drop-fail.rs:24:43 + | +LL | const fn check(_: T) {} + | ^ +note: inside `_` + --> $DIR/const-drop-fail.rs:28:23 + | +LL | const _: () = check($exp); + | ^^^^^^^^^^^ +... +LL | / check_all! { +LL | | NonTrivialDrop, +LL | | ConstImplWithDropGlue(NonTrivialDrop), +LL | | } + | |_- in this macro invocation + = note: this error originates in the macro `check_all` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0493`. +Some errors have detailed explanations: E0080, E0493. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr index f166bdf6cecce..5ff3be713a7ca 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr @@ -1,15 +1,92 @@ +error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time + --> $DIR/const-drop.rs:24:13 + | +LL | let _ = S(&mut c); + | ^^^^^^^^^ the destructor for this type cannot be evaluated in constant functions + +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = note: calling non-const function ` as Drop>::drop` + | +note: inside `std::ptr::drop_in_place::> - shim(Some(S<'_>))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `b` + --> $DIR/const-drop.rs:24:22 + | +LL | let _ = S(&mut c); + | ^ +note: inside `C` + --> $DIR/const-drop.rs:30:15 + | +LL | const C: u8 = b(); + | ^^^ + error[E0493]: destructor of `T` cannot be evaluated at compile-time --> $DIR/const-drop.rs:19:32 | LL | const fn a(_: T) {} | ^ the destructor for this type cannot be evaluated in constant functions -error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:24:13 +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL | -LL | let _ = S(&mut c); - | ^^^^^^^^^ the destructor for this type cannot be evaluated in constant functions + = note: calling non-const function `::drop` + | +note: inside `std::ptr::drop_in_place:: - shim(Some(t::ConstDrop))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `a::` + --> $DIR/const-drop.rs:19:39 + | +LL | const fn a(_: T) {} + | ^ +note: inside `_` + --> $DIR/const-drop.rs:35:27 + | +LL | const _: () = a($exp); + | ^^^^^^^ +... +LL | / implements_const_drop! { +LL | | 1u8, +LL | | 2, +LL | | 3.0, +... | +LL | | Result::::Ok(1), +LL | | } + | |_- in this macro invocation + = note: this error originates in the macro `implements_const_drop` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: evaluation of constant value failed + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL + | + = note: calling non-const function `::drop` + | +note: inside `std::ptr::drop_in_place:: - shim(Some(t::ConstDrop))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `std::ptr::drop_in_place:: - shim(Some(t::HasConstDrop))` + --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL +note: inside `a::` + --> $DIR/const-drop.rs:19:39 + | +LL | const fn a(_: T) {} + | ^ +note: inside `_` + --> $DIR/const-drop.rs:35:27 + | +LL | const _: () = a($exp); + | ^^^^^^^ +... +LL | / implements_const_drop! { +LL | | 1u8, +LL | | 2, +LL | | 3.0, +... | +LL | | Result::::Ok(1), +LL | | } + | |_- in this macro invocation + = note: this error originates in the macro `implements_const_drop` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 2 previous errors +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0493`. +Some errors have detailed explanations: E0080, E0493. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr index 23e368870258e..40e39cbefbc6d 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr @@ -1,11 +1,3 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> $DIR/const-drop.rs:19:32 - | -LL | const fn a(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - error[E0493]: destructor of `S<'_>` cannot be evaluated at compile-time --> $DIR/const-drop.rs:24:13 | @@ -14,6 +6,14 @@ LL | let _ = S(&mut c); | | | the destructor for this type cannot be evaluated in constant functions +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-drop.rs:19:32 + | +LL | const fn a(_: T) {} + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions + error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/static/static-drop-scope.stderr b/tests/ui/static/static-drop-scope.stderr index 2c55161628fb8..24658bc601e7b 100644 --- a/tests/ui/static/static-drop-scope.stderr +++ b/tests/ui/static/static-drop-scope.stderr @@ -30,6 +30,22 @@ LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1; | | | the destructor for this type cannot be evaluated in constants +error[E0493]: destructor of `(Option, i32)` cannot be evaluated at compile-time + --> $DIR/static-drop-scope.rs:27:34 + | +LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1; + | ^^^^^^^^^^^^^^^^^^^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constants + +error[E0493]: destructor of `(Option, i32)` cannot be evaluated at compile-time + --> $DIR/static-drop-scope.rs:32:43 + | +LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1; + | ^^^^^^^^^^^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constants + error[E0493]: destructor of `T` cannot be evaluated at compile-time --> $DIR/static-drop-scope.rs:19:24 | @@ -47,22 +63,6 @@ LL | LL | } | - value is dropped here -error[E0493]: destructor of `(Option, i32)` cannot be evaluated at compile-time - --> $DIR/static-drop-scope.rs:27:34 - | -LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1; - | ^^^^^^^^^^^^^^^^^^^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constants - -error[E0493]: destructor of `(Option, i32)` cannot be evaluated at compile-time - --> $DIR/static-drop-scope.rs:32:43 - | -LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1; - | ^^^^^^^^^^^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constants - error: aborting due to 8 previous errors For more information about this error, try `rustc --explain E0493`. diff --git a/tests/ui/statics/issue-14227.rs b/tests/ui/statics/issue-14227.rs index a1fde14600a10..8a70f51d3b4bb 100644 --- a/tests/ui/statics/issue-14227.rs +++ b/tests/ui/statics/issue-14227.rs @@ -3,5 +3,6 @@ extern "C" { } static CRASH: u32 = symbol; //~^ ERROR use of extern static is unsafe and requires +//~| ERROR could not evaluate static initializer fn main() {} diff --git a/tests/ui/statics/issue-14227.stderr b/tests/ui/statics/issue-14227.stderr index 085d6df9c41b2..0aeb973bff301 100644 --- a/tests/ui/statics/issue-14227.stderr +++ b/tests/ui/statics/issue-14227.stderr @@ -1,3 +1,9 @@ +error[E0080]: could not evaluate static initializer + --> $DIR/issue-14227.rs:4:21 + | +LL | static CRASH: u32 = symbol; + | ^^^^^^ cannot access extern static (DefId(0:4 ~ issue_14227[1133]::{extern#0}::symbol)) + error[E0133]: use of extern static is unsafe and requires unsafe function or block --> $DIR/issue-14227.rs:4:21 | @@ -6,6 +12,7 @@ LL | static CRASH: u32 = symbol; | = 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 -For more information about this error, try `rustc --explain E0133`. +Some errors have detailed explanations: E0080, E0133. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/statics/uninhabited-static.rs b/tests/ui/statics/uninhabited-static.rs index f5c6f444317fe..a0f83f450792a 100644 --- a/tests/ui/statics/uninhabited-static.rs +++ b/tests/ui/statics/uninhabited-static.rs @@ -12,10 +12,8 @@ extern { static VOID2: Void = unsafe { std::mem::transmute(()) }; //~ ERROR static of uninhabited type //~| WARN: previously accepted //~| ERROR could not evaluate static initializer -//~| WARN: type `Void` does not permit zero-initialization static NEVER2: Void = unsafe { std::mem::transmute(()) }; //~ ERROR static of uninhabited type //~| WARN: previously accepted //~| ERROR could not evaluate static initializer -//~| WARN: type `Void` does not permit zero-initialization fn main() {} diff --git a/tests/ui/statics/uninhabited-static.stderr b/tests/ui/statics/uninhabited-static.stderr index 9260930473fa8..f891c0ce25b55 100644 --- a/tests/ui/statics/uninhabited-static.stderr +++ b/tests/ui/statics/uninhabited-static.stderr @@ -34,7 +34,7 @@ LL | static VOID2: Void = unsafe { std::mem::transmute(()) }; = note: uninhabited statics cannot be initialized, and any access would be an immediate error error: static of uninhabited type - --> $DIR/uninhabited-static.rs:16:1 + --> $DIR/uninhabited-static.rs:15:1 | LL | static NEVER2: Void = unsafe { std::mem::transmute(()) }; | ^^^^^^^^^^^^^^^^^^^ @@ -49,37 +49,12 @@ error[E0080]: could not evaluate static initializer LL | static VOID2: Void = unsafe { std::mem::transmute(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a value of uninhabited type `Void` -warning: the type `Void` does not permit zero-initialization - --> $DIR/uninhabited-static.rs:12:31 - | -LL | static VOID2: Void = unsafe { std::mem::transmute(()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed - | -note: enums with no inhabited variants have no valid value - --> $DIR/uninhabited-static.rs:4:1 - | -LL | enum Void {} - | ^^^^^^^^^ - = note: `#[warn(invalid_value)]` on by default - error[E0080]: could not evaluate static initializer - --> $DIR/uninhabited-static.rs:16:32 + --> $DIR/uninhabited-static.rs:15:32 | LL | static NEVER2: Void = unsafe { std::mem::transmute(()) }; | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a value of uninhabited type `Void` -warning: the type `Void` does not permit zero-initialization - --> $DIR/uninhabited-static.rs:16:32 - | -LL | static NEVER2: Void = unsafe { std::mem::transmute(()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^ this code causes undefined behavior when executed - | -note: enums with no inhabited variants have no valid value - --> $DIR/uninhabited-static.rs:4:1 - | -LL | enum Void {} - | ^^^^^^^^^ - -error: aborting due to 6 previous errors; 2 warnings emitted +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/treat-err-as-bug/err.stderr b/tests/ui/treat-err-as-bug/err.stderr index f1b61c3607b77..bca48699489cb 100644 --- a/tests/ui/treat-err-as-bug/err.stderr +++ b/tests/ui/treat-err-as-bug/err.stderr @@ -8,5 +8,5 @@ error: the compiler unexpectedly panicked. this is a bug. query stack during panic: #0 [eval_to_allocation_raw] const-evaluating + checking `C` -#1 [lint_mod] linting top-level module +#1 [analysis] running analysis passes on this crate end of query stack diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 18f6edad5c094..c102926fcf562 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -666,12 +666,6 @@ LL | type F: std::ops::Fn(_); LL | impl Qux for Struct { | ^^^^^^^^^^^^^^^^^^^ missing `F` in implementation -error[E0515]: cannot return reference to function parameter `x` - --> $DIR/typeck_type_placeholder_item.rs:50:5 - | -LL | &x - | ^^ returns a reference to data owned by the current function - error[E0015]: cannot call non-const fn ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:230:29: 230:32}>` in constants --> $DIR/typeck_type_placeholder_item.rs:230:22 | @@ -690,6 +684,12 @@ LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); = note: calls in constants are limited to constant functions, tuple structs and tuple variants = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable +error[E0515]: cannot return reference to function parameter `x` + --> $DIR/typeck_type_placeholder_item.rs:50:5 + | +LL | &x + | ^^ returns a reference to data owned by the current function + error: aborting due to 75 previous errors Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403, E0515.