Skip to content

Commit

Permalink
Merge pull request #66 from dtolnay/exhaustive
Browse files Browse the repository at this point in the history
Pick up changes to non_exhaustive_omitted_patterns lint
  • Loading branch information
dtolnay authored Jan 4, 2024
2 parents 380c7b8 + bcbb5fc commit d54ac46
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 91 deletions.
94 changes: 49 additions & 45 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl Printer {
pub fn expr(&mut self, expr: &Expr) {
let beginning_of_line = false;
match expr {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Expr::Array(expr) => self.expr_array(expr),
Expr::Assign(expr) => self.expr_assign(expr),
Expr::Async(expr) => self.expr_async(expr),
Expand Down Expand Up @@ -59,7 +60,6 @@ impl Printer {
Expr::Verbatim(expr) => self.expr_verbatim(expr),
Expr::While(expr) => self.expr_while(expr),
Expr::Yield(expr) => self.expr_yield(expr),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown Expr"),
}
}
Expand Down Expand Up @@ -947,48 +947,52 @@ impl Printer {
}

fn binary_operator(&mut self, op: &BinOp) {
self.word(match op {
BinOp::Add(_) => "+",
BinOp::Sub(_) => "-",
BinOp::Mul(_) => "*",
BinOp::Div(_) => "/",
BinOp::Rem(_) => "%",
BinOp::And(_) => "&&",
BinOp::Or(_) => "||",
BinOp::BitXor(_) => "^",
BinOp::BitAnd(_) => "&",
BinOp::BitOr(_) => "|",
BinOp::Shl(_) => "<<",
BinOp::Shr(_) => ">>",
BinOp::Eq(_) => "==",
BinOp::Lt(_) => "<",
BinOp::Le(_) => "<=",
BinOp::Ne(_) => "!=",
BinOp::Ge(_) => ">=",
BinOp::Gt(_) => ">",
BinOp::AddAssign(_) => "+=",
BinOp::SubAssign(_) => "-=",
BinOp::MulAssign(_) => "*=",
BinOp::DivAssign(_) => "/=",
BinOp::RemAssign(_) => "%=",
BinOp::BitXorAssign(_) => "^=",
BinOp::BitAndAssign(_) => "&=",
BinOp::BitOrAssign(_) => "|=",
BinOp::ShlAssign(_) => "<<=",
BinOp::ShrAssign(_) => ">>=",
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown BinOp"),
});
self.word(
match op {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
BinOp::Add(_) => "+",
BinOp::Sub(_) => "-",
BinOp::Mul(_) => "*",
BinOp::Div(_) => "/",
BinOp::Rem(_) => "%",
BinOp::And(_) => "&&",
BinOp::Or(_) => "||",
BinOp::BitXor(_) => "^",
BinOp::BitAnd(_) => "&",
BinOp::BitOr(_) => "|",
BinOp::Shl(_) => "<<",
BinOp::Shr(_) => ">>",
BinOp::Eq(_) => "==",
BinOp::Lt(_) => "<",
BinOp::Le(_) => "<=",
BinOp::Ne(_) => "!=",
BinOp::Ge(_) => ">=",
BinOp::Gt(_) => ">",
BinOp::AddAssign(_) => "+=",
BinOp::SubAssign(_) => "-=",
BinOp::MulAssign(_) => "*=",
BinOp::DivAssign(_) => "/=",
BinOp::RemAssign(_) => "%=",
BinOp::BitXorAssign(_) => "^=",
BinOp::BitAndAssign(_) => "&=",
BinOp::BitOrAssign(_) => "|=",
BinOp::ShlAssign(_) => "<<=",
BinOp::ShrAssign(_) => ">>=",
_ => unimplemented!("unknown BinOp"),
},
);
}

fn unary_operator(&mut self, op: &UnOp) {
self.word(match op {
UnOp::Deref(_) => "*",
UnOp::Not(_) => "!",
UnOp::Neg(_) => "-",
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown UnOp"),
});
self.word(
match op {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
UnOp::Deref(_) => "*",
UnOp::Not(_) => "!",
UnOp::Neg(_) => "-",
_ => unimplemented!("unknown UnOp"),
},
);
}

fn zerobreak_unless_short_ident(&mut self, beginning_of_line: bool, expr: &Expr) {
Expand All @@ -1002,6 +1006,7 @@ impl Printer {
fn requires_terminator(expr: &Expr) -> bool {
// see https://github.com/rust-lang/rust/blob/a266f1199/compiler/rustc_ast/src/util/classify.rs#L7-L26
match expr {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Expr::If(_)
| Expr::Match(_)
| Expr::Block(_) | Expr::Unsafe(_) // both under ExprKind::Block in rustc
Expand Down Expand Up @@ -1042,7 +1047,6 @@ fn requires_terminator(expr: &Expr) -> bool {
| Expr::Verbatim(_)
| Expr::Yield(_) => true,

#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => true,
}
}
Expand All @@ -1053,6 +1057,7 @@ fn requires_terminator(expr: &Expr) -> bool {
// { y: 1 }) == foo` does not.
fn contains_exterior_struct_lit(expr: &Expr) -> bool {
match expr {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Expr::Struct(_) => true,

Expr::Assign(ExprAssign { left, right, .. })
Expand Down Expand Up @@ -1102,13 +1107,13 @@ fn contains_exterior_struct_lit(expr: &Expr) -> bool {
| Expr::While(_)
| Expr::Yield(_) => false,

#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => false,
}
}

fn needs_newline_if_wrap(expr: &Expr) -> bool {
match expr {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Expr::Array(_)
| Expr::Async(_)
| Expr::Block(_)
Expand Down Expand Up @@ -1155,7 +1160,6 @@ fn needs_newline_if_wrap(expr: &Expr) -> bool {
| Expr::Unary(ExprUnary { expr: e, .. })
| Expr::Yield(ExprYield { expr: Some(e), .. }) => needs_newline_if_wrap(e),

#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => false,
}
}
Expand All @@ -1174,6 +1178,7 @@ fn is_short_ident(expr: &Expr) -> bool {

fn is_blocklike(expr: &Expr) -> bool {
match expr {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Expr::Array(ExprArray { attrs, .. })
| Expr::Async(ExprAsync { attrs, .. })
| Expr::Block(ExprBlock { attrs, .. })
Expand Down Expand Up @@ -1215,7 +1220,6 @@ fn is_blocklike(expr: &Expr) -> bool {
| Expr::While(_)
| Expr::Yield(_) => false,

#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => false,
}
}
Expand All @@ -1226,6 +1230,7 @@ fn is_blocklike(expr: &Expr) -> bool {
// bitwise OR operators while `{ {} |x| x }` has a block followed by a closure.
fn parseable_as_stmt(expr: &Expr) -> bool {
match expr {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Expr::Array(_)
| Expr::Async(_)
| Expr::Block(_)
Expand Down Expand Up @@ -1270,7 +1275,6 @@ fn parseable_as_stmt(expr: &Expr) -> bool {
},
Expr::Try(expr) => parseable_as_stmt(&expr.expr),

#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => false,
}
}
4 changes: 2 additions & 2 deletions src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ impl Printer {

pub fn type_param_bound(&mut self, type_param_bound: &TypeParamBound) {
match type_param_bound {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
TypeParamBound::Trait(trait_bound) => {
let tilde_const = false;
self.trait_bound(trait_bound, tilde_const);
}
TypeParamBound::Lifetime(lifetime) => self.lifetime(lifetime),
TypeParamBound::Verbatim(bound) => self.type_param_bound_verbatim(bound),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown TypeParamBound"),
}
}
Expand Down Expand Up @@ -289,9 +289,9 @@ impl Printer {

fn where_predicate(&mut self, predicate: &WherePredicate) {
match predicate {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
WherePredicate::Type(predicate) => self.predicate_type(predicate),
WherePredicate::Lifetime(predicate) => self.predicate_lifetime(predicate),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown WherePredicate"),
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use syn::{
impl Printer {
pub fn item(&mut self, item: &Item) {
match item {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Item::Const(item) => self.item_const(item),
Item::Enum(item) => self.item_enum(item),
Item::ExternCrate(item) => self.item_extern_crate(item),
Expand All @@ -31,7 +32,6 @@ impl Printer {
Item::Union(item) => self.item_union(item),
Item::Use(item) => self.item_use(item),
Item::Verbatim(item) => self.item_verbatim(item),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown Item"),
}
}
Expand Down Expand Up @@ -775,12 +775,12 @@ impl Printer {

fn foreign_item(&mut self, foreign_item: &ForeignItem) {
match foreign_item {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
ForeignItem::Fn(item) => self.foreign_item_fn(item),
ForeignItem::Static(item) => self.foreign_item_static(item),
ForeignItem::Type(item) => self.foreign_item_type(item),
ForeignItem::Macro(item) => self.foreign_item_macro(item),
ForeignItem::Verbatim(item) => self.foreign_item_verbatim(item),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown ForeignItem"),
}
}
Expand Down Expand Up @@ -917,12 +917,12 @@ impl Printer {

fn trait_item(&mut self, trait_item: &TraitItem) {
match trait_item {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
TraitItem::Const(item) => self.trait_item_const(item),
TraitItem::Fn(item) => self.trait_item_fn(item),
TraitItem::Type(item) => self.trait_item_type(item),
TraitItem::Macro(item) => self.trait_item_macro(item),
TraitItem::Verbatim(item) => self.trait_item_verbatim(item),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown TraitItem"),
}
}
Expand Down Expand Up @@ -1107,12 +1107,12 @@ impl Printer {

fn impl_item(&mut self, impl_item: &ImplItem) {
match impl_item {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
ImplItem::Const(item) => self.impl_item_const(item),
ImplItem::Fn(item) => self.impl_item_fn(item),
ImplItem::Type(item) => self.impl_item_type(item),
ImplItem::Macro(item) => self.impl_item_macro(item),
ImplItem::Verbatim(item) => self.impl_item_verbatim(item),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown ImplItem"),
}
}
Expand Down Expand Up @@ -1362,9 +1362,9 @@ impl Printer {

fn static_mutability(&mut self, mutability: &StaticMutability) {
match mutability {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
StaticMutability::Mut(_) => self.word("mut "),
StaticMutability::None => {}
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown StaticMutability"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use syn::{Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr};
impl Printer {
pub fn lit(&mut self, lit: &Lit) {
match lit {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Lit::Str(lit) => self.lit_str(lit),
Lit::ByteStr(lit) => self.lit_byte_str(lit),
Lit::Byte(lit) => self.lit_byte(lit),
Expand All @@ -13,7 +14,6 @@ impl Printer {
Lit::Float(lit) => self.lit_float(lit),
Lit::Bool(lit) => self.lit_bool(lit),
Lit::Verbatim(lit) => self.lit_verbatim(lit),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown Lit"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use syn::{
impl Printer {
pub fn pat(&mut self, pat: &Pat) {
match pat {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
Pat::Const(pat) => self.expr_const(pat),
Pat::Ident(pat) => self.pat_ident(pat),
Pat::Lit(pat) => self.expr_lit(pat),
Expand All @@ -28,7 +29,6 @@ impl Printer {
Pat::Type(pat) => self.pat_type(pat),
Pat::Verbatim(pat) => self.pat_verbatim(pat),
Pat::Wild(pat) => self.pat_wild(pat),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown Pat"),
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ impl Printer {

fn generic_argument(&mut self, arg: &GenericArgument) {
match arg {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
GenericArgument::Lifetime(lifetime) => self.lifetime(lifetime),
GenericArgument::Type(ty) => self.ty(ty),
GenericArgument::Const(expr) => {
match expr {
#![cfg_attr(all(test, exhaustive), allow(non_exhaustive_omitted_patterns))]
Expr::Lit(expr) => self.expr_lit(expr),
Expr::Block(expr) => self.expr_block(expr),
// ERROR CORRECTION: Add braces to make sure that the
Expand All @@ -65,7 +67,6 @@ impl Printer {
GenericArgument::AssocType(assoc) => self.assoc_type(assoc),
GenericArgument::AssocConst(assoc) => self.assoc_const(assoc),
GenericArgument::Constraint(constraint) => self.constraint(constraint),
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => unimplemented!("unknown GenericArgument"),
}
}
Expand Down Expand Up @@ -95,13 +96,13 @@ impl Printer {
}
fn group(arg: &GenericArgument) -> Group {
match arg {
#![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
GenericArgument::Lifetime(_) => Group::First,
GenericArgument::Type(_)
| GenericArgument::Const(_)
| GenericArgument::AssocType(_)
| GenericArgument::AssocConst(_)
| GenericArgument::Constraint(_) => Group::Second,
#[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
_ => Group::Second,
}
}
Expand Down
Loading

0 comments on commit d54ac46

Please sign in to comment.