Skip to content
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

Try to catch clippy::pedantic violations in generated code #89

Merged
merged 7 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@clippy
- run: cargo clippy -- -Dclippy::all
- run: cargo clippy --tests -- -Dclippy::all
3 changes: 2 additions & 1 deletion impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn impl_struct(input: Struct) -> TokenStream {
let display_impl = display_body.map(|body| {
quote! {
impl #impl_generics std::fmt::Display for #ty #ty_generics #where_clause {
#[allow(clippy::used_underscore_binding)]
fn fmt(&self, __formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
#body
}
Expand Down Expand Up @@ -296,7 +297,7 @@ fn impl_enum(input: Enum) -> TokenStream {
impl #impl_generics std::fmt::Display for #ty #ty_generics #where_clause {
fn fmt(&self, __formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
#use_as_display
#[allow(unused_variables, deprecated)]
#[allow(unused_variables, deprecated, clippy::used_underscore_binding)]
match #void_deref self {
#(#arms,)*
}
Expand Down
2 changes: 2 additions & 0 deletions tests/compiletest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

#[rustversion::attr(not(nightly), ignore)]
#[test]
fn ui() {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_deprecated.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![deny(deprecated)]
#![deny(deprecated, clippy::all, clippy::pedantic)]

use thiserror::Error;

Expand Down
6 changes: 5 additions & 1 deletion tests/test_display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

use std::fmt::Display;
use thiserror::Error;

Expand Down Expand Up @@ -114,6 +116,7 @@ fn test_nested() {
#[error("!bool = {}", not(.0))]
struct Error(bool);

#[allow(clippy::trivially_copy_pass_by_ref)]
fn not(bool: &bool) -> bool {
!*bool
}
Expand All @@ -126,7 +129,7 @@ fn test_match() {
#[derive(Error, Debug)]
#[error("{}: {0}", match .1 {
Some(n) => format!("error occurred with {}", n),
None => format!("there was an empty error"),
None => "there was an empty error".to_owned(),
})]
struct Error(String, Option<usize>);

Expand All @@ -142,6 +145,7 @@ fn test_match() {

#[test]
fn test_void() {
#[allow(clippy::empty_enum)]
#[derive(Error, Debug)]
#[error("...")]
pub enum Error {}
Expand Down
1 change: 1 addition & 0 deletions tests/test_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(clippy::all, clippy::pedantic)]
#![allow(dead_code)]

use std::fmt::{self, Display};
Expand Down
5 changes: 3 additions & 2 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

use std::fmt::Display;
use thiserror::Error;

Expand Down Expand Up @@ -39,8 +41,7 @@ pub enum RustupError {
"toolchain '{name}' does not contain component {component}{}",
.suggestion
.as_ref()
.map(|s| format!("; did you mean '{}'?", s))
.unwrap_or_else(String::new),
.map_or_else(String::new, |s| format!("; did you mean '{}'?", s)),
)]
UnknownComponent {
name: String,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_from.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

use std::io;
use thiserror::Error;

Expand Down
1 change: 1 addition & 0 deletions tests/test_option.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(thiserror_nightly_testing, feature(backtrace))]
#![deny(clippy::all, clippy::pedantic)]

#[cfg(thiserror_nightly_testing)]
pub mod structs {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_path.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

use ref_cast::RefCast;
use std::fmt::Display;
use std::path::{Path, PathBuf};
Expand Down
2 changes: 2 additions & 0 deletions tests/test_source.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

use std::error::Error as StdError;
use std::io;
use thiserror::Error;
Expand Down
2 changes: 2 additions & 0 deletions tests/test_transparent.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]

use anyhow::anyhow;
use std::error::Error as _;
use std::io;
Expand Down