diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 9fcaf64317950..7f1445d7df7c6 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -716,6 +716,7 @@ pub fn create_global_ctxt<'tcx>( sess.time("setup_global_ctxt", || { gcx_cell.get_or_init(move || { + #[allow(large_assignments)] TyCtxt::create_global_ctxt( sess, crate_types, diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index e0d9998d919b1..21f448433687f 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -93,6 +93,7 @@ pub struct Queries<'tcx> { impl<'tcx> Queries<'tcx> { pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> { + #[allow(large_assignments)] Queries { compiler, gcx_cell: OnceLock::new(), diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index b53ba251bcd5b..032df14d584e8 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -1,4 +1,4 @@ -#![allow(rustc::bad_opt_access)] +#![allow(rustc::bad_opt_access, large_assignments)] use crate::interface::parse_cfgspecs; use rustc_data_structures::fx::FxHashSet; diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 5c9b39cdbe305..e5afe55cb55b5 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -126,6 +126,7 @@ pub fn create_session( sess.parse_sess.config = cfg; sess.parse_sess.check_config = check_cfg; + #[allow(large_assignments)] (sess, codegen_backend) } diff --git a/compiler/rustc_middle/src/middle/limits.rs b/compiler/rustc_middle/src/middle/limits.rs index d4f023958d6fd..faabe6e266a86 100644 --- a/compiler/rustc_middle/src/middle/limits.rs +++ b/compiler/rustc_middle/src/middle/limits.rs @@ -25,7 +25,15 @@ pub fn provide(providers: &mut Providers) { tcx.hir().krate_attrs(), tcx.sess, sym::move_size_limit, - tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(0), + // The check is enabled by default in nightly compilers without + // needing `#![feature(large_assignments)]` with a limit of 4096 + // bytes. But if the user wants to use adjust `#![move_size_limit]`, + // then `#![feature(large_assignments)]` is needed. + tcx.sess.opts.unstable_opts.move_size_limit.unwrap_or(if tcx.sess.is_nightly_build() { + 4096 + } else { + 0 + }), ), type_length_limit: get_limit( tcx.hir().krate_attrs(), diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 90d847804f0e5..801d4d276cd17 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -713,6 +713,7 @@ impl<'tcx> TyCtxt<'tcx> { let common_lifetimes = CommonLifetimes::new(&interners); let common_consts = CommonConsts::new(&interners, &common_types); + #[allow(large_assignments)] GlobalCtxt { sess: s, crate_types, diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 9a0fcbb37a724..beff26858de1e 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -209,6 +209,7 @@ pub fn query_system<'tcx>( on_disk_cache: Option>, incremental: bool, ) -> QuerySystem<'tcx> { + #[allow(large_assignments)] QuerySystem { states: Default::default(), arenas: Default::default(), diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 86db2edab7bed..051dd21c6d759 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1312,7 +1312,7 @@ fn default_emitter( } // JUSTIFICATION: literally session construction -#[allow(rustc::bad_opt_access)] +#[allow(rustc::bad_opt_access, large_assignments)] pub fn build_session( handler: &EarlyErrorHandler, sopts: config::Options, diff --git a/compiler/rustc_target/src/spec/apple/tests.rs b/compiler/rustc_target/src/spec/apple/tests.rs index 3b23ddadcc47c..5e9cd7f966014 100644 --- a/compiler/rustc_target/src/spec/apple/tests.rs +++ b/compiler/rustc_target/src/spec/apple/tests.rs @@ -1,3 +1,5 @@ +#![allow(large_assignments)] + use crate::spec::{ aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_watchos_sim, i686_apple_darwin, x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos, x86_64_apple_watchos_sim, diff --git a/library/alloc/benches/lib.rs b/library/alloc/benches/lib.rs index 638f343fb244b..15e21837a5081 100644 --- a/library/alloc/benches/lib.rs +++ b/library/alloc/benches/lib.rs @@ -8,6 +8,7 @@ #![feature(strict_provenance)] #![feature(test)] #![deny(fuzzy_provenance_casts)] +#![allow(large_assignments)] extern crate test; diff --git a/library/alloc/benches/vec_deque.rs b/library/alloc/benches/vec_deque.rs index 313a97ed1ffcc..b3e7354cb0997 100644 --- a/library/alloc/benches/vec_deque.rs +++ b/library/alloc/benches/vec_deque.rs @@ -1,3 +1,5 @@ +#![allow(large_assignments)] + use core::iter::Iterator; use std::{ collections::{vec_deque, VecDeque}, diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 96b93830f9600..9f29c2cc4135e 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -837,6 +837,7 @@ impl Box, A> { /// /// ``` /// #![feature(new_uninit)] + /// #![allow(large_assignments)] /// /// let big_box = Box::<[usize; 1024]>::new_uninit(); /// diff --git a/library/core/benches/array.rs b/library/core/benches/array.rs index d8cc44d05c4ba..239f42c4296c0 100644 --- a/library/core/benches/array.rs +++ b/library/core/benches/array.rs @@ -1,3 +1,5 @@ +#![allow(large_assignments)] + use test::black_box; use test::Bencher; diff --git a/library/core/benches/iter.rs b/library/core/benches/iter.rs index 05fec0c4b9d26..75d419a078df6 100644 --- a/library/core/benches/iter.rs +++ b/library/core/benches/iter.rs @@ -1,3 +1,5 @@ +#![allow(large_assignments)] + use core::borrow::Borrow; use core::iter::*; use core::mem; diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index d09a24b4b1d5b..558f51c02f991 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -97,6 +97,7 @@ use crate::slice; /// unnecessary moves. /// /// ``` +/// ##![allow(large_assignments)] /// use std::mem::MaybeUninit; /// /// unsafe fn make_vec(out: *mut Vec) { @@ -117,6 +118,7 @@ use crate::slice; /// `MaybeUninit` can be used to initialize a large array element-by-element: /// /// ``` +/// ##![allow(large_assignments)] /// use std::mem::{self, MaybeUninit}; /// /// let data = { @@ -145,6 +147,7 @@ use crate::slice; /// be found in low-level datastructures. /// /// ``` +/// ##![allow(large_assignments)] /// use std::mem::MaybeUninit; /// /// // Create an uninitialized array of `MaybeUninit`. The `assume_init` is diff --git a/tests/ui/async-await/large_moves.attribute.stderr b/tests/ui/async-await/large_moves.attribute.stderr index 1d1999462cedd..c8d272edab971 100644 --- a/tests/ui/async-await/large_moves.attribute.stderr +++ b/tests/ui/async-await/large_moves.attribute.stderr @@ -28,12 +28,60 @@ LL | let _ = NotBox::new([0; 9999]); = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` error: moving 9999 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 1500 bytes + --> $DIR/large_moves.rs:37:13 + | +LL | let _ = NotBox::new([0; 1500]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 2500 bytes --> $DIR/large_moves.rs:41:13 | +LL | let _ = NotBox::new([0; 2500]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 5000 bytes + --> $DIR/large_moves.rs:47:13 + | +LL | let _ = NotBox::new([0; 5000]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 1500 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 2500 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 5000 bytes + --> $DIR/large_moves.rs:63:13 + | LL | data, | ^^^^ value moved from here | = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` -error: aborting due to 4 previous errors +error: aborting due to 10 previous errors diff --git a/tests/ui/async-await/large_moves.nothing.stderr b/tests/ui/async-await/large_moves.nothing.stderr new file mode 100644 index 0000000000000..b33a90d3ba95b --- /dev/null +++ b/tests/ui/async-await/large_moves.nothing.stderr @@ -0,0 +1,55 @@ +error: moving 10024 bytes + --> $DIR/large_moves.rs:21:14 + | +LL | let z = (x, 42); + | ^ value moved from here + | + = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` +note: the lint level is defined here + --> $DIR/large_moves.rs:1:9 + | +LL | #![deny(large_assignments)] + | ^^^^^^^^^^^^^^^^^ + +error: moving 10024 bytes + --> $DIR/large_moves.rs:22:13 + | +LL | let a = z.0; + | ^^^ value moved from here + | + = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 9999 bytes + --> $DIR/large_moves.rs:27:13 + | +LL | let _ = NotBox::new([0; 9999]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 9999 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 5000 bytes + --> $DIR/large_moves.rs:47:13 + | +LL | let _ = NotBox::new([0; 5000]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 5000 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 4096, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: aborting due to 6 previous errors + diff --git a/tests/ui/async-await/large_moves.option.stderr b/tests/ui/async-await/large_moves.option.stderr index 1d1999462cedd..30835213f01f8 100644 --- a/tests/ui/async-await/large_moves.option.stderr +++ b/tests/ui/async-await/large_moves.option.stderr @@ -4,7 +4,7 @@ error: moving 10024 bytes LL | let z = (x, 42); | ^ value moved from here | - = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` note: the lint level is defined here --> $DIR/large_moves.rs:1:9 | @@ -17,7 +17,7 @@ error: moving 10024 bytes LL | let a = z.0; | ^^^ value moved from here | - = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` error: moving 9999 bytes --> $DIR/large_moves.rs:27:13 @@ -25,15 +25,47 @@ error: moving 9999 bytes LL | let _ = NotBox::new([0; 9999]); | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here | - = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` error: moving 9999 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 2500 bytes --> $DIR/large_moves.rs:41:13 | +LL | let _ = NotBox::new([0; 2500]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 5000 bytes + --> $DIR/large_moves.rs:47:13 + | +LL | let _ = NotBox::new([0; 5000]); + | ^^^^^^^^^^^^^^^^^^^^^^ value moved from here + | + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 2500 bytes + --> $DIR/large_moves.rs:63:13 + | +LL | data, + | ^^^^ value moved from here + | + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + +error: moving 5000 bytes + --> $DIR/large_moves.rs:63:13 + | LL | data, | ^^^^ value moved from here | - = note: The current maximum size is 1000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` + = note: The current maximum size is 2000, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` -error: aborting due to 4 previous errors +error: aborting due to 8 previous errors diff --git a/tests/ui/async-await/large_moves.rs b/tests/ui/async-await/large_moves.rs index 62b1210469410..1d1fc81f2a774 100644 --- a/tests/ui/async-await/large_moves.rs +++ b/tests/ui/async-await/large_moves.rs @@ -1,10 +1,10 @@ #![deny(large_assignments)] -#![feature(large_assignments)] +#![cfg_attr(attribute, feature(large_assignments))] #![cfg_attr(attribute, move_size_limit = "1000")] // build-fail // only-x86_64 -// revisions: attribute option -// [option]compile-flags: -Zmove-size-limit=1000 +// revisions: attribute option nothing +// [option]compile-flags: -Zmove-size-limit=2000 // edition:2018 // compile-flags: -Zmir-opt-level=0 @@ -25,20 +25,48 @@ fn main() { let _ = Box::new([0; 9999]); // OK! let _ = Rc::new([0; 9999]); // OK! let _ = NotBox::new([0; 9999]); //~ ERROR large_assignments + default_limits(); +} + +fn default_limits() { + // Moving 500 bytes is OK in all revisions + let _ = NotBox::new([0; 500]); + + // Moving 1500 bytes should fail only with the `attribute` revision because + // its limit is 1000 bytes + let _ = NotBox::new([0; 1500]); //[attribute]~ ERROR large_assignments + + // Moving 2500 bytes should fail with both `attribute` and `option` since + // their limits are 1000 and 2000 respectively. + let _ = NotBox::new([0; 2500]); + //[attribute]~^ ERROR large_assignments + //[option]~^^ ERROR large_assignments + + // With a nightly compiler the default limit is 4096. So 5000 should fail + // for all revisions + let _ = NotBox::new([0; 5000]); //~ ERROR large_assignments } async fn thing(y: &[u8]) { dbg!(y); } -struct NotBox { - data: [u8; 9999], +struct NotBox { + data: [u8; N], } -impl NotBox { - fn new(data: [u8; 9999]) -> Self { +impl NotBox { + fn new(data: [u8; N]) -> Self { + // FIXME: Each different instantiation of this generic type (with + // different N) results in a unique error message. Deduplicate somehow. Self { data, //~ ERROR large_assignments + //[nothing]~^ ERROR large_assignments + //[option]~| ERROR large_assignments + //[option]~| ERROR large_assignments + //[attribute]~| ERROR large_assignments + //[attribute]~| ERROR large_assignments + //[attribute]~| ERROR large_assignments } } } diff --git a/tests/ui/limits/huge-array.rs b/tests/ui/limits/huge-array.rs index 811cf25dd7681..08ced701c6fb1 100644 --- a/tests/ui/limits/huge-array.rs +++ b/tests/ui/limits/huge-array.rs @@ -1,3 +1,4 @@ +#![allow(large_assignments)] // build-fail fn generic(t: T) { diff --git a/tests/ui/limits/huge-array.stderr b/tests/ui/limits/huge-array.stderr index 24adb33b08891..2628554f16cbd 100644 --- a/tests/ui/limits/huge-array.stderr +++ b/tests/ui/limits/huge-array.stderr @@ -1,5 +1,5 @@ error: values of the type `[[u8; 1518599999]; 1518600000]` are too big for the current architecture - --> $DIR/huge-array.rs:4:9 + --> $DIR/huge-array.rs:5:9 | LL | let s: [T; 1518600000] = [t; 1518600000]; | ^ diff --git a/tests/ui/print_type_sizes/async.rs b/tests/ui/print_type_sizes/async.rs index f38a6e674da99..09cd0ffdc5d08 100644 --- a/tests/ui/print_type_sizes/async.rs +++ b/tests/ui/print_type_sizes/async.rs @@ -3,7 +3,7 @@ // build-pass // ignore-pass -#![allow(dropping_copy_types)] +#![allow(dropping_copy_types, large_assignments)] async fn wait() {} diff --git a/tests/ui/print_type_sizes/generator.rs b/tests/ui/print_type_sizes/generator.rs index d1cd36274ef3e..974326f1681bb 100644 --- a/tests/ui/print_type_sizes/generator.rs +++ b/tests/ui/print_type_sizes/generator.rs @@ -2,6 +2,7 @@ // build-pass // ignore-pass +#![allow(large_assignments)] #![feature(generators, generator_trait)] use std::ops::Generator; diff --git a/tests/ui/print_type_sizes/generator.stdout b/tests/ui/print_type_sizes/generator.stdout index 2dcadde9ec28b..6142879ed480e 100644 --- a/tests/ui/print_type_sizes/generator.stdout +++ b/tests/ui/print_type_sizes/generator.stdout @@ -1,4 +1,4 @@ -print-type-size type: `[generator@$DIR/generator.rs:10:5: 10:14]`: 8193 bytes, alignment: 1 bytes +print-type-size type: `[generator@$DIR/generator.rs:11:5: 11:14]`: 8193 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 8192 bytes print-type-size upvar `.array`: 8192 bytes diff --git a/tests/ui/structs-enums/align-struct.rs b/tests/ui/structs-enums/align-struct.rs index 54092542f98fa..b8d64df8a42b4 100644 --- a/tests/ui/structs-enums/align-struct.rs +++ b/tests/ui/structs-enums/align-struct.rs @@ -1,5 +1,5 @@ // run-pass -#![allow(dead_code, unused_allocation)] +#![allow(dead_code, unused_allocation, large_assignments)] use std::mem;