mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
update testcases, cleanup
This commit is contained in:
parent
3a91a11740
commit
79325604da
@ -32,8 +32,8 @@ pub(super) fn check(
|
||||
&& Some(def_id) == cx.tcx.lang_items().owned_box()
|
||||
// At this point, we know ty is Box<T>, now get T
|
||||
&& let Some(last) = last_path_segment(ty_qpath).args
|
||||
// extract allocator from thr Box for later
|
||||
&& let Some(GenericArg::Type(boxed_ty)) = last.args.first()
|
||||
// extract allocator from the Box for later
|
||||
&& let boxed_alloc_ty = last.args.get(1)
|
||||
&& let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty)
|
||||
&& !ty_ty.has_escaping_bound_vars()
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
#![feature(allocator_api)]
|
||||
|
||||
struct SizedStruct(i32);
|
||||
struct UnsizedStruct([i32]);
|
||||
@ -21,6 +22,8 @@ mod should_trigger {
|
||||
/// The following should not trigger the lint
|
||||
mod should_not_trigger {
|
||||
use super::{BigStruct, UnsizedStruct};
|
||||
use std::alloc::{Layout, AllocError, Allocator};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
struct C(Vec<Box<UnsizedStruct>>);
|
||||
struct D(Vec<Box<BigStruct>>);
|
||||
@ -33,6 +36,20 @@ mod should_not_trigger {
|
||||
// Regression test for #3720. This was causing an ICE.
|
||||
inner: Vec<Box<T>>,
|
||||
}
|
||||
|
||||
struct DummyAllocator;
|
||||
unsafe impl Allocator for DummyAllocator {
|
||||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||
todo!()
|
||||
}
|
||||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn allocator_mismatch() -> Vec<Box<i32, DummyAllocator>> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
mod inner_mod {
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![allow(dead_code)]
|
||||
#![feature(allocator_api)]
|
||||
|
||||
struct SizedStruct(i32);
|
||||
struct UnsizedStruct([i32]);
|
||||
@ -21,6 +22,8 @@ mod should_trigger {
|
||||
/// The following should not trigger the lint
|
||||
mod should_not_trigger {
|
||||
use super::{BigStruct, UnsizedStruct};
|
||||
use std::alloc::{Layout, AllocError, Allocator};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
struct C(Vec<Box<UnsizedStruct>>);
|
||||
struct D(Vec<Box<BigStruct>>);
|
||||
@ -33,6 +36,20 @@ mod should_not_trigger {
|
||||
// Regression test for #3720. This was causing an ICE.
|
||||
inner: Vec<Box<T>>,
|
||||
}
|
||||
|
||||
struct DummyAllocator;
|
||||
unsafe impl Allocator for DummyAllocator {
|
||||
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||
todo!()
|
||||
}
|
||||
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn allocator_mismatch() -> Vec<Box<i32, DummyAllocator>> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
mod inner_mod {
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:10:14
|
||||
--> $DIR/vec_box_sized.rs:11:14
|
||||
|
|
||||
LL | const C: Vec<Box<i32>> = Vec::new();
|
||||
| ^^^^^^^^^^^^^ help: try: `Vec<i32>`
|
||||
@ -8,31 +8,31 @@ LL | const C: Vec<Box<i32>> = Vec::new();
|
||||
= help: to override `-D warnings` add `#[allow(clippy::vec_box)]`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:11:15
|
||||
--> $DIR/vec_box_sized.rs:12:15
|
||||
|
|
||||
LL | static S: Vec<Box<i32>> = Vec::new();
|
||||
| ^^^^^^^^^^^^^ help: try: `Vec<i32>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:14:21
|
||||
--> $DIR/vec_box_sized.rs:15:21
|
||||
|
|
||||
LL | sized_type: Vec<Box<SizedStruct>>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:17:14
|
||||
--> $DIR/vec_box_sized.rs:18:14
|
||||
|
|
||||
LL | struct A(Vec<Box<SizedStruct>>);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:18:18
|
||||
--> $DIR/vec_box_sized.rs:19:18
|
||||
|
|
||||
LL | struct B(Vec<Vec<Box<(u32)>>>);
|
||||
| ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`
|
||||
|
||||
error: `Vec<T>` is already on the heap, the boxing is unnecessary
|
||||
--> $DIR/vec_box_sized.rs:46:23
|
||||
--> $DIR/vec_box_sized.rs:63:23
|
||||
|
|
||||
LL | pub fn f() -> Vec<Box<S>> {
|
||||
| ^^^^^^^^^^^ help: try: `Vec<S>`
|
||||
|
Loading…
Reference in New Issue
Block a user