Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Work around dead_code warning in tests
Browse files Browse the repository at this point in the history
    warning: field `0` is never read
      --> tests/test_error.rs:58:11
       |
    58 |         C(C),
       |         - ^
       |         |
       |         field in this variant
       |
       = note: `#[warn(dead_code)]` on by default
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
       |
    58 |         C(()),
       |           ~~

    warning: field `0` is never read
       --> tests/test_error.rs:165:11
        |
    165 |         V(usize),
        |         - ^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    165 |         V(()),
        |           ~~

    warning: field `0` is never read
       --> tests/test_error.rs:217:15
        |
    217 |         Inner(Inner),
        |         ----- ^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    217 |         Inner(()),
        |               ~~

    warning: field `0` is never read
       --> tests/test_error.rs:221:17
        |
    221 |         Variant(Vec<usize>),
        |         ------- ^^^^^^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    221 |         Variant(()),
        |                 ~~

    warning: field `0` is never read
       --> tests/test_error.rs:250:11
        |
    250 |         V(usize),
        |         - ^^^^^
        |         |
        |         field in this variant
        |
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    250 |         V(()),
        |           ~~

    warning: fields `0` and `1` are never read
       --> tests/test_error.rs:367:14
        |
    367 |     struct S(usize, Option<Box<S>>);
        |            - ^^^^^  ^^^^^^^^^^^^^^
        |            |
        |            fields in this struct
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
    help: consider changing the fields to be of unit type to suppress this warning while preserving the field numbering, or remove the fields
        |
    367 |     struct S((), ());
        |              ~~  ~~

    warning: field `0` is never read
       --> tests/test_error.rs:378:14
        |
    378 |     struct S(Option<Box<S>>);
        |            - ^^^^^^^^^^^^^^
        |            |
        |            field in this struct
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
    help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
        |
    378 |     struct S(());
        |              ~~

    warning: fields `0` and `1` are never read
       --> tests/test_error.rs:403:14
        |
    403 |     struct S(usize, Option<Box<S>>);
        |            - ^^^^^  ^^^^^^^^^^^^^^
        |            |
        |            fields in this struct
        |
        = note: `S` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
    help: consider changing the fields to be of unit type to suppress this warning while preserving the field numbering, or remove the fields
        |
    403 |     struct S((), ());
        |              ~~  ~~
  • Loading branch information
dtolnay committed Jan 6, 2024
1 parent 09ee251 commit 8b26413
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -15,13 +15,13 @@ rust-version = "1.64"
indexmap = "2"
itoa = "1.0"
ryu = "1.0"
serde = "1.0.194"
serde = "1.0.195"
unsafe-libyaml = "0.2.10"

[dev-dependencies]
anyhow = "1.0.79"
indoc = "2.0"
serde_derive = "1.0.194"
serde_derive = "1.0.195"

[lib]
doc-scrape-examples = false
Expand Down
65 changes: 28 additions & 37 deletions tests/test_error.rs
Expand Up @@ -49,18 +49,16 @@ fn test_incorrect_type() {
#[test]
fn test_incorrect_nested_type() {
#[derive(Deserialize, Debug)]
struct A {
#[allow(dead_code)]
b: Vec<B>,
pub struct A {
pub b: Vec<B>,
}
#[derive(Deserialize, Debug)]
enum B {
pub enum B {
C(C),
}
#[derive(Deserialize, Debug)]
struct C {
#[allow(dead_code)]
d: bool,
pub struct C {
pub d: bool,
}
let yaml = indoc! {"
b:
Expand All @@ -80,11 +78,9 @@ fn test_empty() {
#[test]
fn test_missing_field() {
#[derive(Deserialize, Debug)]
struct Basic {
#[allow(dead_code)]
v: bool,
#[allow(dead_code)]
w: bool,
pub struct Basic {
pub v: bool,
pub w: bool,
}
let yaml = indoc! {"
---
Expand All @@ -107,9 +103,8 @@ fn test_unknown_anchor() {
#[test]
fn test_ignored_unknown_anchor() {
#[derive(Deserialize, Debug)]
struct Wrapper {
#[allow(dead_code)]
c: (),
pub struct Wrapper {
pub c: (),
}
let yaml = indoc! {"
b: [*a]
Expand Down Expand Up @@ -161,7 +156,7 @@ fn test_second_document_syntax_error() {
#[test]
fn test_missing_enum_tag() {
#[derive(Deserialize, Debug)]
enum E {
pub enum E {
V(usize),
}
let yaml = indoc! {r#"
Expand All @@ -175,11 +170,11 @@ fn test_missing_enum_tag() {
#[test]
fn test_serialize_nested_enum() {
#[derive(Serialize, Debug)]
enum Outer {
pub enum Outer {
Inner(Inner),
}
#[derive(Serialize, Debug)]
enum Inner {
pub enum Inner {
Newtype(usize),
Tuple(usize, usize),
Struct { x: usize },
Expand Down Expand Up @@ -213,11 +208,11 @@ fn test_serialize_nested_enum() {
#[test]
fn test_deserialize_nested_enum() {
#[derive(Deserialize, Debug)]
enum Outer {
pub enum Outer {
Inner(Inner),
}
#[derive(Deserialize, Debug)]
enum Inner {
pub enum Inner {
Variant(Vec<usize>),
}

Expand Down Expand Up @@ -246,7 +241,7 @@ fn test_deserialize_nested_enum() {
#[test]
fn test_variant_not_a_seq() {
#[derive(Deserialize, Debug)]
enum E {
pub enum E {
V(usize),
}
let yaml = indoc! {"
Expand All @@ -260,11 +255,10 @@ fn test_variant_not_a_seq() {

#[test]
fn test_struct_from_sequence() {
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct Struct {
x: usize,
y: usize,
pub struct Struct {
pub x: usize,
pub y: usize,
}
let yaml = indoc! {"
[0, 0]
Expand Down Expand Up @@ -336,9 +330,8 @@ fn test_long_tuple() {
#[test]
fn test_invalid_scalar_type() {
#[derive(Deserialize, Debug)]
struct S {
#[allow(dead_code)]
x: [i32; 1],
pub struct S {
pub x: [i32; 1],
}

let yaml = "x: ''\n";
Expand All @@ -350,9 +343,8 @@ fn test_invalid_scalar_type() {
#[test]
fn test_infinite_recursion_objects() {
#[derive(Deserialize, Debug)]
struct S {
#[allow(dead_code)]
x: Option<Box<S>>,
pub struct S {
pub x: Option<Box<S>>,
}

let yaml = "&a {'x': *a}";
Expand All @@ -364,7 +356,7 @@ fn test_infinite_recursion_objects() {
#[test]
fn test_infinite_recursion_arrays() {
#[derive(Deserialize, Debug)]
struct S(usize, Option<Box<S>>);
pub struct S(pub usize, pub Option<Box<S>>);

let yaml = "&a [0, *a]";
let expected = "recursion limit exceeded";
Expand All @@ -375,7 +367,7 @@ fn test_infinite_recursion_arrays() {
#[test]
fn test_infinite_recursion_newtype() {
#[derive(Deserialize, Debug)]
struct S(Option<Box<S>>);
pub struct S(pub Option<Box<S>>);

let yaml = "&a [*a]";
let expected = "recursion limit exceeded";
Expand All @@ -386,9 +378,8 @@ fn test_infinite_recursion_newtype() {
#[test]
fn test_finite_recursion_objects() {
#[derive(Deserialize, Debug)]
struct S {
#[allow(dead_code)]
x: Option<Box<S>>,
pub struct S {
pub x: Option<Box<S>>,
}

let yaml = "{'x':".repeat(1_000) + &"}".repeat(1_000);
Expand All @@ -400,7 +391,7 @@ fn test_finite_recursion_objects() {
#[test]
fn test_finite_recursion_arrays() {
#[derive(Deserialize, Debug)]
struct S(usize, Option<Box<S>>);
pub struct S(pub usize, pub Option<Box<S>>);

let yaml = "[0, ".repeat(1_000) + &"]".repeat(1_000);
let expected = "recursion limit exceeded at line 1 column 513";
Expand Down

0 comments on commit 8b26413

Please sign in to comment.