Skip to content

Commit ad48d52

Browse files
committed
Auto merge of #71231 - cuviper:rustc_or_patterns, r=Mark-Simulacrum
Dogfood more or_patterns in the compiler Another step toward the stabilization of `or_patterns`... cc #54883 @Centril r? @Mark-Simulacrum
2 parents 1b7dec9 + 7b005c5 commit ad48d52

File tree

125 files changed

+759
-688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+759
-688
lines changed

src/libfmt_macros/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
test(attr(deny(warnings)))
1111
)]
1212
#![feature(nll)]
13+
#![feature(or_patterns)]
1314
#![feature(rustc_private)]
1415
#![feature(unicode_internals)]
1516
#![feature(bool_to_option)]
@@ -482,7 +483,7 @@ impl<'a> Parser<'a> {
482483
// fill character
483484
if let Some(&(_, c)) = self.cur.peek() {
484485
match self.cur.clone().nth(1) {
485-
Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
486+
Some((_, '>' | '<' | '^')) => {
486487
spec.fill = Some(c);
487488
self.cur.next();
488489
}

src/librustc_apfloat/ieee.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
744744
Status::OK
745745
}
746746

747-
(Category::Zero, _) | (_, Category::NaN) | (_, Category::Infinity) => {
747+
(Category::Zero, _) | (_, Category::NaN | Category::Infinity) => {
748748
self = rhs;
749749
Status::OK
750750
}
@@ -954,7 +954,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
954954
Status::INVALID_OP.and(Self::NAN)
955955
}
956956

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

959959
(Category::Normal, Category::Infinity) => {
960960
self.category = Category::Zero;
@@ -989,8 +989,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
989989
fn c_fmod(mut self, rhs: Self) -> StatusAnd<Self> {
990990
match (self.category, rhs.category) {
991991
(Category::NaN, _)
992-
| (Category::Zero, Category::Infinity)
993-
| (Category::Zero, Category::Normal)
992+
| (Category::Zero, Category::Infinity | Category::Normal)
994993
| (Category::Normal, Category::Infinity) => Status::OK.and(self),
995994

996995
(_, Category::NaN) => {

src/librustc_apfloat/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#![no_std]
3535
#![forbid(unsafe_code)]
3636
#![feature(nll)]
37+
#![feature(or_patterns)]
3738

3839
#[macro_use]
3940
extern crate alloc;

src/librustc_apfloat/ppc.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ where
186186
Status::OK.and(self)
187187
}
188188

189-
(Category::Zero, _) | (_, Category::NaN) | (_, Category::Infinity) => {
190-
Status::OK.and(rhs)
191-
}
189+
(Category::Zero, _) | (_, Category::NaN | Category::Infinity) => Status::OK.and(rhs),
192190

193191
(Category::Normal, Category::Normal) => {
194192
let mut status = Status::OK;
@@ -288,9 +286,9 @@ where
288286
Status::OK.and(Self::NAN)
289287
}
290288

291-
(Category::Zero, _) | (Category::Infinity, _) => Status::OK.and(self),
289+
(Category::Zero | Category::Infinity, _) => Status::OK.and(self),
292290

293-
(_, Category::Zero) | (_, Category::Infinity) => Status::OK.and(rhs),
291+
(_, Category::Zero | Category::Infinity) => Status::OK.and(rhs),
294292

295293
(Category::Normal, Category::Normal) => {
296294
let mut status = Status::OK;

src/librustc_ast/ast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,7 @@ impl LitKind {
15691569
pub fn is_suffixed(&self) -> bool {
15701570
match *self {
15711571
// suffixed variants
1572-
LitKind::Int(_, LitIntType::Signed(..))
1573-
| LitKind::Int(_, LitIntType::Unsigned(..))
1572+
LitKind::Int(_, LitIntType::Signed(..) | LitIntType::Unsigned(..))
15741573
| LitKind::Float(_, LitFloatType::Suffixed(..)) => true,
15751574
// unsuffixed variants
15761575
LitKind::Str(..)

src/librustc_ast/attr/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,10 @@ impl MetaItem {
442442
{
443443
// FIXME: Share code with `parse_path`.
444444
let path = match tokens.next().map(TokenTree::uninterpolate) {
445-
Some(TokenTree::Token(Token { kind: kind @ token::Ident(..), span }))
446-
| Some(TokenTree::Token(Token { kind: kind @ token::ModSep, span })) => 'arm: {
445+
Some(TokenTree::Token(Token {
446+
kind: kind @ (token::Ident(..) | token::ModSep),
447+
span,
448+
})) => 'arm: {
447449
let mut segments = if let token::Ident(name, _) = kind {
448450
if let Some(TokenTree::Token(Token { kind: token::ModSep, .. })) = tokens.peek()
449451
{

src/librustc_ast/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(crate_visibility_modifier)]
1515
#![feature(label_break_value)]
1616
#![feature(nll)]
17+
#![feature(or_patterns)]
1718
#![feature(try_trait)]
1819
#![feature(unicode_internals)]
1920
#![recursion_limit = "256"]

src/librustc_ast/util/comments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ pub fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comme
226226
rustc_lexer::TokenKind::BlockComment { terminated: _ } => {
227227
if !is_block_doc_comment(token_text) {
228228
let code_to_the_right = match text[pos + token.len..].chars().next() {
229-
Some('\r') | Some('\n') => false,
229+
Some('\r' | '\n') => false,
230230
_ => true,
231231
};
232232
let style = match (code_to_the_left, code_to_the_right) {
233-
(true, true) | (false, true) => Mixed,
233+
(_, true) => Mixed,
234234
(false, false) => Isolated,
235235
(true, false) => Trailing,
236236
};

src/librustc_ast_lowering/lib.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1239,16 +1239,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12391239
let bounds =
12401240
this.arena.alloc_from_iter(bounds.iter().filter_map(
12411241
|bound| match *bound {
1242-
GenericBound::Trait(ref ty, TraitBoundModifier::None)
1243-
| GenericBound::Trait(ref ty, TraitBoundModifier::MaybeConst) => {
1244-
Some(this.lower_poly_trait_ref(ty, itctx.reborrow()))
1245-
}
1242+
GenericBound::Trait(
1243+
ref ty,
1244+
TraitBoundModifier::None | TraitBoundModifier::MaybeConst,
1245+
) => Some(this.lower_poly_trait_ref(ty, itctx.reborrow())),
12461246
// `?const ?Bound` will cause an error during AST validation
12471247
// anyways, so treat it like `?Bound` as compilation proceeds.
1248-
GenericBound::Trait(_, TraitBoundModifier::Maybe)
1249-
| GenericBound::Trait(_, TraitBoundModifier::MaybeConstMaybe) => {
1250-
None
1251-
}
1248+
GenericBound::Trait(
1249+
_,
1250+
TraitBoundModifier::Maybe | TraitBoundModifier::MaybeConstMaybe,
1251+
) => None,
12521252
GenericBound::Outlives(ref lifetime) => {
12531253
if lifetime_bound.is_none() {
12541254
lifetime_bound = Some(this.lower_lifetime(lifetime));
@@ -1740,8 +1740,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17401740
c_variadic,
17411741
implicit_self: decl.inputs.get(0).map_or(hir::ImplicitSelfKind::None, |arg| {
17421742
let is_mutable_pat = match arg.pat.kind {
1743-
PatKind::Ident(BindingMode::ByValue(mt), _, _)
1744-
| PatKind::Ident(BindingMode::ByRef(mt), _, _) => mt == Mutability::Mut,
1743+
PatKind::Ident(BindingMode::ByValue(mt) | BindingMode::ByRef(mt), _, _) => {
1744+
mt == Mutability::Mut
1745+
}
17451746
_ => false,
17461747
};
17471748

@@ -2468,7 +2469,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24682469
hir::QPath::Resolved(None, path) => {
24692470
// Turn trait object paths into `TyKind::TraitObject` instead.
24702471
match path.res {
2471-
Res::Def(DefKind::Trait, _) | Res::Def(DefKind::TraitAlias, _) => {
2472+
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
24722473
let principal = hir::PolyTraitRef {
24732474
bound_generic_params: &[],
24742475
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },

src/librustc_ast_lowering/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
194194
) -> hir::PatKind<'hir> {
195195
match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) {
196196
// `None` can occur in body-less function signatures
197-
res @ None | res @ Some(Res::Local(_)) => {
197+
res @ (None | Some(Res::Local(_))) => {
198198
let canonical_id = match res {
199199
Some(Res::Local(id)) => id,
200200
_ => p.id,

src/librustc_ast_pretty/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(bool_to_option)]
22
#![feature(crate_visibility_modifier)]
3+
#![feature(or_patterns)]
34
#![recursion_limit = "256"]
45

56
mod helpers;

src/librustc_ast_pretty/pprust.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,9 @@ impl<'a> State<'a> {
17351735
// These cases need parens: `x as i32 < y` has the parser thinking that `i32 < y` is
17361736
// the beginning of a path type. It starts trying to parse `x as (i32 < y ...` instead
17371737
// of `(x as i32) < ...`. We need to convince it _not_ to do that.
1738-
(&ast::ExprKind::Cast { .. }, ast::BinOpKind::Lt)
1739-
| (&ast::ExprKind::Cast { .. }, ast::BinOpKind::Shl) => parser::PREC_FORCE_PAREN,
1738+
(&ast::ExprKind::Cast { .. }, ast::BinOpKind::Lt | ast::BinOpKind::Shl) => {
1739+
parser::PREC_FORCE_PAREN
1740+
}
17401741
// We are given `(let _ = a) OP b`.
17411742
//
17421743
// - When `OP <= LAnd` we should print `let _ = a OP b` to avoid redundant parens

src/librustc_builtin_macros/concat.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ pub fn expand_concat(
2626
ast::LitKind::Char(c) => {
2727
accumulator.push(c);
2828
}
29-
ast::LitKind::Int(i, ast::LitIntType::Unsigned(_))
30-
| ast::LitKind::Int(i, ast::LitIntType::Signed(_))
31-
| ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => {
29+
ast::LitKind::Int(
30+
i,
31+
ast::LitIntType::Unsigned(_)
32+
| ast::LitIntType::Signed(_)
33+
| ast::LitIntType::Unsuffixed,
34+
) => {
3235
accumulator.push_str(&i.to_string());
3336
}
3437
ast::LitKind::Bool(b) => {

src/librustc_builtin_macros/format.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -918,24 +918,15 @@ pub fn expand_preparsed_format_args(
918918
skips.push(*next_pos);
919919
let _ = s.next();
920920
}
921-
('\\', Some((next_pos, '\n')))
922-
| ('\\', Some((next_pos, 'n')))
923-
| ('\\', Some((next_pos, 't')))
924-
if eat_ws =>
925-
{
921+
('\\', Some((next_pos, '\n' | 'n' | 't'))) if eat_ws => {
926922
skips.push(pos);
927923
skips.push(*next_pos);
928924
let _ = s.next();
929925
}
930-
(' ', _) | ('\n', _) | ('\t', _) if eat_ws => {
926+
(' ' | '\n' | '\t', _) if eat_ws => {
931927
skips.push(pos);
932928
}
933-
('\\', Some((next_pos, 'n')))
934-
| ('\\', Some((next_pos, 't')))
935-
| ('\\', Some((next_pos, '0')))
936-
| ('\\', Some((next_pos, '\\')))
937-
| ('\\', Some((next_pos, '\'')))
938-
| ('\\', Some((next_pos, '\"'))) => {
929+
('\\', Some((next_pos, 'n' | 't' | '0' | '\\' | '\'' | '\"'))) => {
939930
skips.push(*next_pos);
940931
let _ = s.next();
941932
}

src/librustc_builtin_macros/format_foreign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub mod printf {
149149
};
150150

151151
let alt = match type_ {
152-
Some("x") | Some("X") => alt,
152+
Some("x" | "X") => alt,
153153
_ => false,
154154
};
155155

@@ -506,7 +506,7 @@ pub mod printf {
506506
move_to!(next1);
507507
}
508508

509-
('h', _) | ('l', _) | ('L', _) | ('z', _) | ('j', _) | ('t', _) | ('q', _) => {
509+
('h' | 'l' | 'L' | 'z' | 'j' | 't' | 'q', _) => {
510510
state = Type;
511511
length = Some(at.slice_between(next).unwrap());
512512
move_to!(next);

src/librustc_builtin_macros/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(crate_visibility_modifier)]
77
#![feature(decl_macro)]
88
#![feature(nll)]
9+
#![feature(or_patterns)]
910
#![feature(proc_macro_internals)]
1011
#![feature(proc_macro_quote)]
1112

src/librustc_builtin_macros/llvm_asm.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ fn parse_inline_asm<'a>(
8686
let first_colon = tts
8787
.trees()
8888
.position(|tt| match tt {
89-
tokenstream::TokenTree::Token(Token { kind: token::Colon, .. })
90-
| tokenstream::TokenTree::Token(Token { kind: token::ModSep, .. }) => true,
89+
tokenstream::TokenTree::Token(Token { kind: token::Colon | token::ModSep, .. }) => true,
9190
_ => false,
9291
})
9392
.unwrap_or(tts.len());

src/librustc_codegen_llvm/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
124124
// sanitizer and thread sanitizer. With asan we're already protected from
125125
// stack overflow anyway so we don't really need stack probes regardless.
126126
match cx.sess().opts.debugging_opts.sanitizer {
127-
Some(Sanitizer::Address) | Some(Sanitizer::Thread) => return,
127+
Some(Sanitizer::Address | Sanitizer::Thread) => return,
128128
_ => {}
129129
}
130130

src/librustc_codegen_llvm/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
310310
let new_kind = match ty.kind {
311311
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
312312
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
313-
ref t @ Uint(_) | ref t @ Int(_) => t.clone(),
313+
ref t @ (Uint(_) | Int(_)) => t.clone(),
314314
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
315315
};
316316

@@ -1247,7 +1247,7 @@ impl Builder<'a, 'll, 'tcx> {
12471247
let emit = match opts.debugging_opts.sanitizer {
12481248
// Some sanitizer use lifetime intrinsics. When they are in use,
12491249
// emit lifetime intrinsics regardless of optimization level.
1250-
Some(Sanitizer::Address) | Some(Sanitizer::Memory) => true,
1250+
Some(Sanitizer::Address | Sanitizer::Memory) => true,
12511251
_ => opts.optimize != config::OptLevel::No,
12521252
};
12531253
if !emit {

src/librustc_codegen_llvm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(extern_types)]
1212
#![feature(in_band_lifetimes)]
1313
#![feature(nll)]
14+
#![feature(or_patterns)]
1415
#![feature(trusted_len)]
1516
#![recursion_limit = "256"]
1617

src/librustc_codegen_ssa/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub fn each_linked_rlib(
262262
};
263263
for &(cnum, ref path) in crates {
264264
match fmts.get(cnum.as_usize() - 1) {
265-
Some(&Linkage::NotLinked) | Some(&Linkage::IncludedFromDylib) => continue,
265+
Some(&Linkage::NotLinked | &Linkage::IncludedFromDylib) => continue,
266266
Some(_) => {}
267267
None => return Err("could not find formats for rlibs".to_string()),
268268
}

src/librustc_codegen_ssa/back/symbol_export.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ fn reachable_non_generics_provider(
8686
}
8787

8888
// Only consider nodes that actually have exported symbols.
89-
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
90-
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
89+
Node::Item(&hir::Item {
90+
kind: hir::ItemKind::Static(..) | hir::ItemKind::Fn(..),
91+
..
92+
})
9193
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
9294
let def_id = tcx.hir().local_def_id(hir_id);
9395
let generics = tcx.generics_of(def_id);

src/librustc_codegen_ssa/base.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ pub fn unsize_thin_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
182182
) -> (Bx::Value, Bx::Value) {
183183
debug!("unsize_thin_ptr: {:?} => {:?}", src_ty, dst_ty);
184184
match (&src_ty.kind, &dst_ty.kind) {
185-
(&ty::Ref(_, a, _), &ty::Ref(_, b, _))
186-
| (&ty::Ref(_, a, _), &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
185+
(&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
187186
| (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
188187
assert!(bx.cx().type_is_sized(a));
189188
let ptr_ty = bx.cx().type_ptr_to(bx.cx().backend_type(bx.cx().layout_of(b)));
@@ -232,9 +231,7 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
232231
let src_ty = src.layout.ty;
233232
let dst_ty = dst.layout.ty;
234233
match (&src_ty.kind, &dst_ty.kind) {
235-
(&ty::Ref(..), &ty::Ref(..))
236-
| (&ty::Ref(..), &ty::RawPtr(..))
237-
| (&ty::RawPtr(..), &ty::RawPtr(..)) => {
234+
(&ty::Ref(..), &ty::Ref(..) | &ty::RawPtr(..)) | (&ty::RawPtr(..), &ty::RawPtr(..)) => {
238235
let (base, info) = match bx.load_operand(src).val {
239236
OperandValue::Pair(base, info) => {
240237
// fat-ptr to fat-ptr unsize preserves the vtable

src/librustc_codegen_ssa/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(try_blocks)]
55
#![feature(in_band_lifetimes)]
66
#![feature(nll)]
7+
#![feature(or_patterns)]
78
#![feature(trusted_len)]
89
#![feature(associated_type_bounds)]
910
#![recursion_limit = "256"]

0 commit comments

Comments
 (0)