File tree Expand file tree Collapse file tree 12 files changed +29
-98
lines changed Expand file tree Collapse file tree 12 files changed +29
-98
lines changed Original file line number Diff line number Diff line change @@ -585,7 +585,6 @@ checksum = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e"
585585name = " core"
586586version = " 0.0.0"
587587dependencies = [
588- " matches_macro" ,
589588 " rand 0.7.0" ,
590589]
591590
@@ -1901,10 +1900,6 @@ version = "0.1.8"
19011900source = " registry+https://github.com/rust-lang/crates.io-index"
19021901checksum = " 7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
19031902
1904- [[package ]]
1905- name = " matches_macro"
1906- version = " 0.0.0"
1907-
19081903[[package ]]
19091904name = " mdbook"
19101905version = " 0.3.1"
Original file line number Diff line number Diff line change @@ -20,9 +20,6 @@ path = "../libcore/tests/lib.rs"
2020name = " corebenches"
2121path = " ../libcore/benches/lib.rs"
2222
23- [dependencies ]
24- matches_macro = { path = " ../libmatches_macro" }
25-
2623[dev-dependencies ]
2724rand = " 0.7"
2825
Original file line number Diff line number Diff line change 8585#![ feature( iter_once_with) ]
8686#![ feature( lang_items) ]
8787#![ feature( link_llvm_intrinsics) ]
88- #![ feature( matches_macro) ]
8988#![ feature( never_type) ]
9089#![ feature( nll) ]
9190#![ feature( exhaustive_patterns) ]
135134use prelude:: v1:: * ;
136135
137136#[ macro_use]
138- #[ path = "macros.rs" ]
139- mod prelude_macros;
140-
141- /// Macros that are not in the prelude and need to be imported explicitly
142- #[ unstable( feature = "matches_macro" , issue = "0" ) ]
143- pub mod macros {
144- #[ unstable( feature = "matches_macro" , issue = "0" ) ]
145- #[ doc( inline) ]
146- pub use matches_macro:: matches;
147- }
137+ mod macros;
148138
149139#[ macro_use]
150140mod internal_macros;
Original file line number Diff line number Diff line change @@ -238,6 +238,30 @@ macro_rules! debug_assert_ne {
238238 ( $( $arg: tt) * ) => ( if $crate:: cfg!( debug_assertions) { $crate:: assert_ne!( $( $arg) * ) ; } )
239239}
240240
241+ /// Returns whether the given expression matches (any of) the given pattern(s).
242+ ///
243+ /// # Examples
244+ ///
245+ /// ```
246+ /// #![feature(matches_macro)]
247+ ///
248+ /// let foo = 'f';
249+ /// assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
250+ ///
251+ /// let bar = Some(4);
252+ /// assert!(matches!(bar, Some(x) if x > 2));
253+ /// ```
254+ #[ macro_export]
255+ #[ unstable( feature = "matches_macro" , issue = "0" ) ]
256+ macro_rules! matches {
257+ ( $expression: expr, $( $pattern: pat ) |+ $( if $guard: expr ) ?) => {
258+ match $expression {
259+ $( $pattern ) |+ $( if $guard ) ? => true ,
260+ _ => false
261+ }
262+ }
263+ }
264+
241265/// Unwraps a result or propagates its error.
242266///
243267/// The `?` operator was added to replace `try!` and should be used instead.
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ pub use crate::{
8282#[ stable( feature = "builtin_macro_prelude" , since = "1.38.0" ) ]
8383#[ allow( deprecated) ]
8484#[ doc( no_inline) ]
85- pub use crate :: prelude_macros :: builtin:: {
85+ pub use crate :: macros :: builtin:: {
8686 RustcDecodable ,
8787 RustcEncodable ,
8888 bench,
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -354,16 +354,7 @@ extern crate cfg_if;
354354
355355// The standard macros that are not built-in to the compiler.
356356#[ macro_use]
357- #[ path = "macros.rs" ]
358- mod prelude_macros;
359-
360- /// Macros that are not in the prelude and need to be imported explicitly
361- #[ unstable( feature = "matches_macro" , issue = "0" ) ]
362- pub mod macros {
363- #[ unstable( feature = "matches_macro" , issue = "0" ) ]
364- #[ doc( inline) ]
365- pub use core:: macros:: matches;
366- }
357+ mod macros;
367358
368359// The Rust prelude
369360pub mod prelude;
@@ -537,6 +528,7 @@ pub use core::{
537528 writeln,
538529 // Unstable
539530 todo,
531+ matches,
540532} ;
541533
542534// Re-export built-in macros defined through libcore.
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ LL | macro_rules! unknown { () => () }
55 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
77error: cannot find a built-in macro with name `line`
8- --> <::core::prelude_macros ::builtin::line macros>:1:1
8+ --> <::core::macros ::builtin::line macros>:1:1
99 |
1010LL | () => { }
1111 | ^^^^^^^^^
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments