Skip to content

Commit

Permalink
Enable large_assignments lint by default with move_size_limit = 4…
Browse files Browse the repository at this point in the history
…096 bytes

Only enable it by default in the nightly compiler. The limit can be
changed on a per-crate basis with:

    #![feature(large_assignments)]
    #![move_size_limit = "8192"]

or with

    -Zmove-size-limit=8192
  • Loading branch information
Enselic committed Sep 9, 2023
1 parent f06b7c5 commit a7d3667
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 19 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_middle/src/middle/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ pub fn query_system<'tcx>(
on_disk_cache: Option<OnDiskCache<'tcx>>,
incremental: bool,
) -> QuerySystem<'tcx> {
#[allow(large_assignments)]
QuerySystem {
states: Default::default(),
arenas: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,7 @@ impl<T> UnsafeCell<T> {
#[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")]
#[inline(always)]
pub const fn new(value: T) -> UnsafeCell<T> {
#[allow(large_assignments)]
UnsafeCell { value }
}

Expand Down
50 changes: 49 additions & 1 deletion tests/ui/async-await/large_moves.attribute.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

55 changes: 55 additions & 0 deletions tests/ui/async-await/large_moves.nothing.stderr
Original file line number Diff line number Diff line change
@@ -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

42 changes: 37 additions & 5 deletions tests/ui/async-await/large_moves.option.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -17,23 +17,55 @@ 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
|
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

42 changes: 35 additions & 7 deletions tests/ui/async-await/large_moves.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<const N: usize> {
data: [u8; N],
}

impl NotBox {
fn new(data: [u8; 9999]) -> Self {
impl<const N: usize> NotBox<N> {
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
}
}
}
1 change: 1 addition & 0 deletions tests/ui/limits/huge-array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(large_assignments)]
// build-fail

fn generic<T: Copy>(t: T) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/limits/huge-array.stderr
Original file line number Diff line number Diff line change
@@ -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];
| ^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/print_type_sizes/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// build-pass
// ignore-pass

#![allow(dropping_copy_types)]
#![allow(dropping_copy_types, large_assignments)]

async fn wait() {}

Expand Down
1 change: 1 addition & 0 deletions tests/ui/print_type_sizes/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// build-pass
// ignore-pass

#![allow(large_assignments)]
#![feature(generators, generator_trait)]

use std::ops::Generator;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/print_type_sizes/generator.stdout
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/structs-enums/align-struct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// run-pass
#![allow(dead_code, unused_allocation)]
#![allow(dead_code, unused_allocation, large_assignments)]

use std::mem;

Expand Down

0 comments on commit a7d3667

Please sign in to comment.