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

Dogfood more or_patterns in the compiler #71231

Merged
merged 1 commit into from
Apr 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
test(attr(deny(warnings)))
)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(rustc_private)]
#![feature(unicode_internals)]
#![feature(bool_to_option)]
Expand Down Expand Up @@ -482,7 +483,7 @@ impl<'a> Parser<'a> {
// fill character
if let Some(&(_, c)) = self.cur.peek() {
match self.cur.clone().nth(1) {
Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
Some((_, '>' | '<' | '^')) => {
spec.fill = Some(c);
self.cur.next();
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_apfloat/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
Status::OK
}

(Category::Zero, _) | (_, Category::NaN) | (_, Category::Infinity) => {
(Category::Zero, _) | (_, Category::NaN | Category::Infinity) => {
self = rhs;
Status::OK
}
Expand Down Expand Up @@ -954,7 +954,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
Status::INVALID_OP.and(Self::NAN)
}

(Category::Infinity, _) | (Category::Zero, _) => Status::OK.and(self),
(Category::Infinity | Category::Zero, _) => Status::OK.and(self),

(Category::Normal, Category::Infinity) => {
self.category = Category::Zero;
Expand Down Expand Up @@ -989,8 +989,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
fn c_fmod(mut self, rhs: Self) -> StatusAnd<Self> {
match (self.category, rhs.category) {
(Category::NaN, _)
| (Category::Zero, Category::Infinity)
| (Category::Zero, Category::Normal)
| (Category::Zero, Category::Infinity | Category::Normal)
| (Category::Normal, Category::Infinity) => Status::OK.and(self),

(_, Category::NaN) => {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_apfloat/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#![no_std]
#![forbid(unsafe_code)]
#![feature(nll)]
#![feature(or_patterns)]

#[macro_use]
extern crate alloc;
Expand Down
8 changes: 3 additions & 5 deletions src/librustc_apfloat/ppc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ where
Status::OK.and(self)
}

(Category::Zero, _) | (_, Category::NaN) | (_, Category::Infinity) => {
Status::OK.and(rhs)
}
(Category::Zero, _) | (_, Category::NaN | Category::Infinity) => Status::OK.and(rhs),

(Category::Normal, Category::Normal) => {
let mut status = Status::OK;
Expand Down Expand Up @@ -288,9 +286,9 @@ where
Status::OK.and(Self::NAN)
}

(Category::Zero, _) | (Category::Infinity, _) => Status::OK.and(self),
(Category::Zero | Category::Infinity, _) => Status::OK.and(self),

(_, Category::Zero) | (_, Category::Infinity) => Status::OK.and(rhs),
(_, Category::Zero | Category::Infinity) => Status::OK.and(rhs),

(Category::Normal, Category::Normal) => {
let mut status = Status::OK;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,7 @@ impl LitKind {
pub fn is_suffixed(&self) -> bool {
match *self {
// suffixed variants
LitKind::Int(_, LitIntType::Signed(..))
| LitKind::Int(_, LitIntType::Unsigned(..))
LitKind::Int(_, LitIntType::Signed(..) | LitIntType::Unsigned(..))
| LitKind::Float(_, LitFloatType::Suffixed(..)) => true,
// unsuffixed variants
LitKind::Str(..)
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_ast/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,10 @@ impl MetaItem {
{
// FIXME: Share code with `parse_path`.
let path = match tokens.next().map(TokenTree::uninterpolate) {
Some(TokenTree::Token(Token { kind: kind @ token::Ident(..), span }))
| Some(TokenTree::Token(Token { kind: kind @ token::ModSep, span })) => 'arm: {
Some(TokenTree::Token(Token {
kind: kind @ (token::Ident(..) | token::ModSep),
span,
})) => 'arm: {
let mut segments = if let token::Ident(name, _) = kind {
if let Some(TokenTree::Token(Token { kind: token::ModSep, .. })) = tokens.peek()
{
Expand Down
1 change: 1 addition & 0 deletions src/librustc_ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![feature(crate_visibility_modifier)]
#![feature(label_break_value)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(try_trait)]
#![feature(unicode_internals)]
#![recursion_limit = "256"]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_ast/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
rustc_lexer::TokenKind::BlockComment { terminated: _ } => {
if !is_block_doc_comment(token_text) {
let code_to_the_right = match text[pos + token.len..].chars().next() {
Some('\r') | Some('\n') => false,
Some('\r' | '\n') => false,
_ => true,
};
let style = match (code_to_the_left, code_to_the_right) {
(true, true) | (false, true) => Mixed,
(_, true) => Mixed,
(false, false) => Isolated,
(true, false) => Trailing,
};
Expand Down
23 changes: 12 additions & 11 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,16 +1239,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let bounds =
this.arena.alloc_from_iter(bounds.iter().filter_map(
|bound| match *bound {
GenericBound::Trait(ref ty, TraitBoundModifier::None)
| GenericBound::Trait(ref ty, TraitBoundModifier::MaybeConst) => {
Some(this.lower_poly_trait_ref(ty, itctx.reborrow()))
}
GenericBound::Trait(
ref ty,
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
) => Some(this.lower_poly_trait_ref(ty, itctx.reborrow())),
// `?const ?Bound` will cause an error during AST validation
// anyways, so treat it like `?Bound` as compilation proceeds.
GenericBound::Trait(_, TraitBoundModifier::Maybe)
| GenericBound::Trait(_, TraitBoundModifier::MaybeConstMaybe) => {
None
}
GenericBound::Trait(
_,
TraitBoundModifier::Maybe | TraitBoundModifier::MaybeConstMaybe,
) => None,
GenericBound::Outlives(ref lifetime) => {
if lifetime_bound.is_none() {
lifetime_bound = Some(this.lower_lifetime(lifetime));
Expand Down Expand Up @@ -1740,8 +1740,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
c_variadic,
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
let is_mutable_pat = match arg.pat.kind {
PatKind::Ident(BindingMode::ByValue(mt), _, _)
| PatKind::Ident(BindingMode::ByRef(mt), _, _) => mt == Mutability::Mut,
PatKind::Ident(BindingMode::ByValue(mt) | BindingMode::ByRef(mt), _, _) => {
mt == Mutability::Mut
}
_ => false,
};

Expand Down Expand Up @@ -2468,7 +2469,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::QPath::Resolved(None, path) => {
// Turn trait object paths into `TyKind::TraitObject` instead.
match path.res {
Res::Def(DefKind::Trait, _) | Res::Def(DefKind::TraitAlias, _) => {
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
let principal = hir::PolyTraitRef {
bound_generic_params: &[],
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> hir::PatKind<'hir> {
match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) {
// `None` can occur in body-less function signatures
res @ None | res @ Some(Res::Local(_)) => {
res @ (None | Some(Res::Local(_))) => {
let canonical_id = match res {
Some(Res::Local(id)) => id,
_ => p.id,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_ast_pretty/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(or_patterns)]
#![recursion_limit = "256"]

mod helpers;
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,8 +1735,9 @@ impl<'a> State<'a> {
// These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is
// the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead
// of `(x as i32) < ...`. We need to convince it _not_ to do that.
(&ast::ExprKind::Cast { .. }, ast::BinOpKind::Lt)
| (&ast::ExprKind::Cast { .. }, ast::BinOpKind::Shl) => parser::PREC_FORCE_PAREN,
(&ast::ExprKind::Cast { .. }, ast::BinOpKind::Lt | ast::BinOpKind::Shl) => {
parser::PREC_FORCE_PAREN
}
// We are given `(let _ = a) OP b`.
//
// - When `OP <= LAnd` we should print `let _ = a OP b` to avoid redundant parens
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_builtin_macros/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ pub fn expand_concat(
ast::LitKind::Char(c) => {
accumulator.push(c);
}
ast::LitKind::Int(i, ast::LitIntType::Unsigned(_))
| ast::LitKind::Int(i, ast::LitIntType::Signed(_))
| ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
ast::LitKind::Int(
i,
ast::LitIntType::Unsigned(_)
| ast::LitIntType::Signed(_)
| ast::LitIntType::Unsuffixed,
) => {
accumulator.push_str(&i.to_string());
}
ast::LitKind::Bool(b) => {
Expand Down
15 changes: 3 additions & 12 deletions src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,24 +918,15 @@ pub fn expand_preparsed_format_args(
skips.push(*next_pos);
let _ = s.next();
}
('\\', Some((next_pos, '\n')))
| ('\\', Some((next_pos, 'n')))
| ('\\', Some((next_pos, 't')))
if eat_ws =>
{
('\\', Some((next_pos, '\n' | 'n' | 't'))) if eat_ws => {
skips.push(pos);
skips.push(*next_pos);
let _ = s.next();
}
(' ', _) | ('\n', _) | ('\t', _) if eat_ws => {
(' ' | '\n' | '\t', _) if eat_ws => {
skips.push(pos);
}
('\\', Some((next_pos, 'n')))
| ('\\', Some((next_pos, 't')))
| ('\\', Some((next_pos, '0')))
| ('\\', Some((next_pos, '\\')))
| ('\\', Some((next_pos, '\'')))
| ('\\', Some((next_pos, '\"'))) => {
('\\', Some((next_pos, 'n' | 't' | '0' | '\\' | '\'' | '\"'))) => {
skips.push(*next_pos);
let _ = s.next();
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub mod printf {
};

let alt = match type_ {
Some("x") | Some("X") => alt,
Some("x" | "X") => alt,
_ => false,
};

Expand Down Expand Up @@ -506,7 +506,7 @@ pub mod printf {
move_to!(next1);
}

('h', _) | ('l', _) | ('L', _) | ('z', _) | ('j', _) | ('t', _) | ('q', _) => {
('h' | 'l' | 'L' | 'z' | 'j' | 't' | 'q', _) => {
state = Type;
length = Some(at.slice_between(next).unwrap());
move_to!(next);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_builtin_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]

Expand Down
3 changes: 1 addition & 2 deletions src/librustc_builtin_macros/llvm_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ fn parse_inline_asm<'a>(
let first_colon = tts
.trees()
.position(|tt| match tt {
tokenstream::TokenTree::Token(Token { kind: token::Colon, .. })
| tokenstream::TokenTree::Token(Token { kind: token::ModSep, .. }) => true,
tokenstream::TokenTree::Token(Token { kind: token::Colon | token::ModSep, .. }) => true,
_ => false,
})
.unwrap_or(tts.len());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
// sanitizer and thread sanitizer. With asan we're already protected from
// stack overflow anyway so we don't really need stack probes regardless.
match cx.sess().opts.debugging_opts.sanitizer {
Some(Sanitizer::Address) | Some(Sanitizer::Thread) => return,
Some(Sanitizer::Address | Sanitizer::Thread) => return,
_ => {}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
let new_kind = match ty.kind {
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
ref t @ Uint(_) | ref t @ Int(_) => t.clone(),
ref t @ (Uint(_) | Int(_)) => t.clone(),
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
};

Expand Down Expand Up @@ -1247,7 +1247,7 @@ impl Builder<'a, 'll, 'tcx> {
let emit = match opts.debugging_opts.sanitizer {
// Some sanitizer use lifetime intrinsics. When they are in use,
// emit lifetime intrinsics regardless of optimization level.
Some(Sanitizer::Address) | Some(Sanitizer::Memory) => true,
Some(Sanitizer::Address | Sanitizer::Memory) => true,
_ => opts.optimize != config::OptLevel::No,
};
if !emit {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(trusted_len)]
#![recursion_limit = "256"]

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ pub fn each_linked_rlib(
};
for &(cnum, ref path) in crates {
match fmts.get(cnum.as_usize() - 1) {
Some(&Linkage::NotLinked) | Some(&Linkage::IncludedFromDylib) => continue,
Some(&Linkage::NotLinked | &Linkage::IncludedFromDylib) => continue,
Some(_) => {}
None => return Err("could not find formats for rlibs".to_string()),
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ fn reachable_non_generics_provider(
}

// Only consider nodes that actually have exported symbols.
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
Node::Item(&hir::Item {
kind: hir::ItemKind::Static(..) | hir::ItemKind::Fn(..),
..
})
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
let def_id = tcx.hir().local_def_id(hir_id);
let generics = tcx.generics_of(def_id);
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ pub fn unsize_thin_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
) -> (Bx::Value, Bx::Value) {
debug!("unsize_thin_ptr: {:?} => {:?}", src_ty, dst_ty);
match (&src_ty.kind, &dst_ty.kind) {
(&ty::Ref(_, a, _), &ty::Ref(_, b, _))
| (&ty::Ref(_, a, _), &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
(&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
assert!(bx.cx().type_is_sized(a));
let ptr_ty = bx.cx().type_ptr_to(bx.cx().backend_type(bx.cx().layout_of(b)));
Expand Down Expand Up @@ -232,9 +231,7 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let src_ty = src.layout.ty;
let dst_ty = dst.layout.ty;
match (&src_ty.kind, &dst_ty.kind) {
(&ty::Ref(..), &ty::Ref(..))
| (&ty::Ref(..), &ty::RawPtr(..))
| (&ty::RawPtr(..), &ty::RawPtr(..)) => {
(&ty::Ref(..), &ty::Ref(..) | &ty::RawPtr(..)) | (&ty::RawPtr(..), &ty::RawPtr(..)) => {
let (base, info) = match bx.load_operand(src).val {
OperandValue::Pair(base, info) => {
// fat-ptr to fat-ptr unsize preserves the vtable
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(or_patterns)]
#![feature(trusted_len)]
#![feature(associated_type_bounds)]
#![recursion_limit = "256"]
Expand Down
Loading