Skip to content

Set default move_size_limit to 4kB for large_assignments lint on nightly #115684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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;
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
2 changes: 2 additions & 0 deletions compiler/rustc_target/src/spec/apple/tests.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![feature(strict_provenance)]
#![feature(test)]
#![deny(fuzzy_provenance_casts)]
#![allow(large_assignments)]

extern crate test;

Expand Down
2 changes: 2 additions & 0 deletions library/alloc/benches/vec_deque.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use core::iter::Iterator;
use std::{
collections::{vec_deque, VecDeque},
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
///
/// ```
/// #![feature(new_uninit)]
/// #![allow(large_assignments)]
///
/// let big_box = Box::<[usize; 1024]>::new_uninit();
///
Expand Down
2 changes: 2 additions & 0 deletions library/core/benches/array.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use test::black_box;
use test::Bencher;

Expand Down
2 changes: 2 additions & 0 deletions library/core/benches/iter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(large_assignments)]

use core::borrow::Borrow;
use core::iter::*;
use core::mem;
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ use crate::slice;
/// unnecessary moves.
///
/// ```
/// ##![allow(large_assignments)]
/// use std::mem::MaybeUninit;
///
/// unsafe fn make_vec(out: *mut Vec<i32>) {
Expand All @@ -117,6 +118,7 @@ use crate::slice;
/// `MaybeUninit<T>` can be used to initialize a large array element-by-element:
///
/// ```
/// ##![allow(large_assignments)]
/// use std::mem::{self, MaybeUninit};
///
/// let data = {
Expand Down Expand Up @@ -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
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
Comment on lines -6 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this in a separate commit so I can see the changes from the code changes separately from the test changes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. I have now split this PR up into these three commits:

  • 2505a7d Add regression tests for new default move_size_limit = 4096
  • a9cb350 Set default move_size_limit to 4kB for large_assignments lint on nightly
  • 39a42c3 Mark #[allow(large_assignments)] for existing large moves


// 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
Loading