Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mu001999 committed May 26, 2024
1 parent 9bc0e5b commit 272bae3
Show file tree
Hide file tree
Showing 30 changed files with 71 additions and 60 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/hir/nested_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_hir::intravisit::nested_filter::NestedFilter;
/// to use `visit_all_item_likes_in_crate()` as an outer loop,
/// and to have the visitor that visits the contents of each item
/// using this setting.
pub struct OnlyBodies(());
pub struct OnlyBodies;
impl<'hir> NestedFilter<'hir> for OnlyBodies {
type Map = crate::hir::map::Map<'hir>;
const INTER: bool = false;
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
if Some(adt_def.did()) == self.tcx.lang_items().dyn_metadata() {
self.fail(
location,
format!("You can't project to field {f:?} of `DynMetadata` because \
layout is weird and thinks it doesn't have fields."),
format!(
"You can't project to field {f:?} of `DynMetadata` because \
layout is weird and thinks it doesn't have fields."
),
);
}

Expand Down
3 changes: 3 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ pub struct FromUtf8Error {
///
/// assert!(String::from_utf16(v).is_err());
/// ```
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug)]
pub struct FromUtf16Error(());
Expand Down Expand Up @@ -2069,6 +2070,7 @@ impl fmt::Display for FromUtf8Error {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for FromUtf16Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -2084,6 +2086,7 @@ impl Error for FromUtf8Error {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl Error for FromUtf16Error {
#[allow(deprecated)]
Expand Down
8 changes: 2 additions & 6 deletions library/core/src/ptr/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,14 @@ impl<Dyn: ?Sized> DynMetadata<Dyn> {
// Consider a reference like `&(i32, dyn Send)`: the vtable will only store the size of the
// `Send` part!
// SAFETY: DynMetadata always contains a valid vtable pointer
return unsafe {
crate::intrinsics::vtable_size(self.vtable_ptr() as *const ())
};
return unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) };
}

/// Returns the alignment of the type associated with this vtable.
#[inline]
pub fn align_of(self) -> usize {
// SAFETY: DynMetadata always contains a valid vtable pointer
return unsafe {
crate::intrinsics::vtable_align(self.vtable_ptr() as *const ())
};
return unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) };
}

/// Returns the size and alignment together as a `Layout`
Expand Down
10 changes: 5 additions & 5 deletions tests/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ impl<T> Struct<T> {
}
}

pub struct LifeTimeOnly<'a> {
pub struct _LifeTimeOnly<'a> {
_a: &'a u32
}

impl<'a> LifeTimeOnly<'a> {
impl<'a> _LifeTimeOnly<'a> {

//~ MONO_ITEM fn LifeTimeOnly::<'_>::foo
//~ MONO_ITEM fn _LifeTimeOnly::<'_>::foo
pub fn foo(&self) {}
//~ MONO_ITEM fn LifeTimeOnly::<'_>::bar
//~ MONO_ITEM fn _LifeTimeOnly::<'_>::bar
pub fn bar(&'a self) {}
//~ MONO_ITEM fn LifeTimeOnly::<'_>::baz
//~ MONO_ITEM fn _LifeTimeOnly::<'_>::baz
pub fn baz<'b>(&'b self) {}

pub fn non_instantiated<T>(&self) {}
Expand Down
24 changes: 12 additions & 12 deletions tests/codegen-units/item-collection/overloaded-operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

use std::ops::{Index, IndexMut, Add, Deref};

pub struct Indexable {
pub struct _Indexable {
data: [u8; 3]
}

impl Index<usize> for Indexable {
impl Index<usize> for _Indexable {
type Output = u8;

//~ MONO_ITEM fn <Indexable as std::ops::Index<usize>>::index
//~ MONO_ITEM fn <_Indexable as std::ops::Index<usize>>::index
fn index(&self, index: usize) -> &Self::Output {
if index >= 3 {
&self.data[0]
Expand All @@ -22,8 +22,8 @@ impl Index<usize> for Indexable {
}
}

impl IndexMut<usize> for Indexable {
//~ MONO_ITEM fn <Indexable as std::ops::IndexMut<usize>>::index_mut
impl IndexMut<usize> for _Indexable {
//~ MONO_ITEM fn <_Indexable as std::ops::IndexMut<usize>>::index_mut
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
if index >= 3 {
&mut self.data[0]
Expand All @@ -34,25 +34,25 @@ impl IndexMut<usize> for Indexable {
}


//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::eq
//~ MONO_ITEM fn <Equatable as std::cmp::PartialEq>::ne
//~ MONO_ITEM fn <_Equatable as std::cmp::PartialEq>::eq
//~ MONO_ITEM fn <_Equatable as std::cmp::PartialEq>::ne
#[derive(PartialEq)]
pub struct Equatable(u32);
pub struct _Equatable(u32);


impl Add<u32> for Equatable {
impl Add<u32> for _Equatable {
type Output = u32;

//~ MONO_ITEM fn <Equatable as std::ops::Add<u32>>::add
//~ MONO_ITEM fn <_Equatable as std::ops::Add<u32>>::add
fn add(self, rhs: u32) -> u32 {
self.0 + rhs
}
}

impl Deref for Equatable {
impl Deref for _Equatable {
type Target = u32;

//~ MONO_ITEM fn <Equatable as std::ops::Deref>::deref
//~ MONO_ITEM fn <_Equatable as std::ops::Deref>::deref
fn deref(&self) -> &Self::Target {
&self.0
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/coherence/re-rebalance-coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
extern crate re_rebalance_coherence_lib as lib;
use lib::*;

#[allow(dead_code)]
struct Oracle;
impl Backend for Oracle {}
impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/const-generics/defaults/repr-c-issue-82792.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//@ run-pass

#[allow(dead_code)]
#[repr(C)]
pub struct Loaf<T: Sized, const N: usize = 1> {
head: [T; N],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ impl BlockCipher for BarCipher {
const BLOCK_SIZE: usize = 32;
}

pub struct Block<C>(#[allow(dead_code)] C);
#[allow(dead_code)]
pub struct Block<C>(C);

pub fn test<C: BlockCipher, const M: usize>()
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::mem::MaybeUninit;

#[allow(dead_code)]
#[repr(transparent)]
pub struct MaybeUninitWrapper<const N: usize>(MaybeUninit<[u64; N]>);

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/derives/clone-debug-dead-code-in-the-same-struct.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![forbid(dead_code)]

#[derive(Debug)]
pub struct Whatever {
pub struct Whatever { //~ ERROR struct `Whatever` is never constructed
pub field0: (),
field1: (), //~ ERROR fields `field1`, `field2`, `field3`, and `field4` are never read
field1: (),
field2: (),
field3: (),
field4: (),
Expand Down
16 changes: 3 additions & 13 deletions tests/ui/derives/clone-debug-dead-code-in-the-same-struct.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
error: fields `field1`, `field2`, `field3`, and `field4` are never read
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:6:5
error: struct `Whatever` is never constructed
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:4:12
|
LL | pub struct Whatever {
| -------- fields in this struct
LL | pub field0: (),
LL | field1: (),
| ^^^^^^
LL | field2: (),
| ^^^^^^
LL | field3: (),
| ^^^^^^
LL | field4: (),
| ^^^^^^
| ^^^^^^^^
|
= note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
note: the lint level is defined here
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:1:11
|
Expand Down
1 change: 1 addition & 0 deletions tests/ui/issues/issue-5708.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub trait MyTrait<T> {
fn dummy(&self, t: T) -> T { panic!() }
}

#[allow(dead_code)]
pub struct MyContainer<'a, T:'a> {
foos: Vec<&'a (dyn MyTrait<T>+'a)> ,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/dead-code/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl SemiUsedStruct {
struct StructUsedAsField;
pub struct StructUsedInEnum;
struct StructUsedInGeneric;
#[allow(dead_code)]
pub struct PubStruct2 {
#[allow(dead_code)]
struct_used_as_field: *const StructUsedAsField
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Regression test for issues #100790 and #106439.
//@ run-rustfix

pub struct Example(#[allow(dead_code)] usize)
#[allow(dead_code)]
pub struct Example(usize)
where
(): Sized;
//~^^^ ERROR where clauses are not allowed before tuple struct bodies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Regression test for issues #100790 and #106439.
//@ run-rustfix

#[allow(dead_code)]
pub struct Example
where
(): Sized,
(#[allow(dead_code)] usize);
(usize);
//~^^^ ERROR where clauses are not allowed before tuple struct bodies

struct _Demo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
error: where clauses are not allowed before tuple struct bodies
--> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:5:1
--> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:6:1
|
LL | pub struct Example
| ------- while parsing this tuple struct
LL | / where
LL | | (): Sized,
| |______________^ unexpected where clause
LL | (#[allow(dead_code)] usize);
| --------------------------- the struct body
LL | (usize);
| ------- the struct body
|
help: move the body before the where clause
|
LL ~ pub struct Example(#[allow(dead_code)] usize)
LL ~ pub struct Example(usize)
LL | where
LL ~ (): Sized;
|

error: where clauses are not allowed before tuple struct bodies
--> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:11:1
--> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:12:1
|
LL | struct _Demo
| ----- while parsing this tuple struct
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/pub/pub-ident-struct-4.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ run-rustfix

pub struct T(#[allow(dead_code)] String);
#[allow(dead_code)]
pub struct T(String);
//~^ ERROR missing `struct` for struct definition

fn main() {}
3 changes: 2 additions & 1 deletion tests/ui/pub/pub-ident-struct-4.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ run-rustfix

pub T(#[allow(dead_code)] String);
#[allow(dead_code)]
pub T(String);
//~^ ERROR missing `struct` for struct definition

fn main() {}
6 changes: 3 additions & 3 deletions tests/ui/pub/pub-ident-struct-4.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: missing `struct` for struct definition
--> $DIR/pub-ident-struct-4.rs:3:4
--> $DIR/pub-ident-struct-4.rs:4:4
|
LL | pub T(#[allow(dead_code)] String);
LL | pub T(String);
| ^
|
help: add `struct` here to parse `T` as a public struct
|
LL | pub struct T(#[allow(dead_code)] String);
LL | pub struct T(String);
| ++++++

error: aborting due to 1 previous error
Expand Down
1 change: 1 addition & 0 deletions tests/ui/regions/regions-issue-21422.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//@ pretty-expanded FIXME #23616

#[allow(dead_code)]
pub struct P<'a> {
_ptr: *const &'a u8,
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/structs-enums/newtype-struct-with-dtor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
#![allow(unused_variables)]
//@ pretty-expanded FIXME #23616

#[allow(dead_code)]
pub struct Fd(u32);

#[allow(dead_code)]
fn foo(a: u32) {}

impl Drop for Fd {
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/structs-enums/uninstantiable-struct.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-pass
pub struct Z(#[allow(dead_code)] &'static Z);
#[allow(dead_code)]
pub struct Z(&'static Z);

pub fn main() {}
1 change: 1 addition & 0 deletions tests/ui/suggestions/derive-clone-for-eq.fixed
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ run-rustfix
// https://github.com/rust-lang/rust/issues/79076

#[allow(dead_code)]
#[derive(Clone, Eq)] //~ ERROR [E0277]
pub struct Struct<T: std::clone::Clone>(T);

Expand Down
1 change: 1 addition & 0 deletions tests/ui/suggestions/derive-clone-for-eq.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ run-rustfix
// https://github.com/rust-lang/rust/issues/79076

#[allow(dead_code)]
#[derive(Clone, Eq)] //~ ERROR [E0277]
pub struct Struct<T>(T);

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suggestions/derive-clone-for-eq.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `T: Clone` is not satisfied
--> $DIR/derive-clone-for-eq.rs:4:17
--> $DIR/derive-clone-for-eq.rs:5:17
|
LL | #[derive(Clone, Eq)]
| ^^ the trait `Clone` is not implemented for `T`, which is required by `Struct<T>: PartialEq`
|
note: required for `Struct<T>` to implement `PartialEq`
--> $DIR/derive-clone-for-eq.rs:7:19
--> $DIR/derive-clone-for-eq.rs:8:19
|
LL | impl<T: Clone, U> PartialEq<U> for Struct<T>
| ----- ^^^^^^^^^^^^ ^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/suggestions/option-content-move.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ run-rustfix
#[allow(dead_code)]
pub struct LipogramCorpora {
selections: Vec<(char, Option<String>)>,
}
Expand All @@ -17,6 +18,7 @@ impl LipogramCorpora {
}
}

#[allow(dead_code)]
pub struct LipogramCorpora2 {
selections: Vec<(char, Result<String, String>)>,
}
Expand Down
Loading

0 comments on commit 272bae3

Please sign in to comment.