diff options
| author | bors <bors@rust-lang.org> | 2019-01-12 11:22:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-12 11:22:20 +0000 |
| commit | d6525ef539a04cb43de40080bdabc5f2f5a4a197 (patch) | |
| tree | 8abef858718c138adecb80e45339ba8df8bf9f97 /src/test/ui/pattern | |
| parent | 1190f7cdf7a62e25c9a8eaf58e0906849692bf2b (diff) | |
| parent | 3117784c1846e8d45c711703d1693e835cf4679e (diff) | |
| download | rust-d6525ef539a04cb43de40080bdabc5f2f5a4a197.tar.gz rust-d6525ef539a04cb43de40080bdabc5f2f5a4a197.zip | |
Auto merge of #57542 - Centril:rollup, r=Centril
Rollup of 26 pull requests
Successful merges:
- #56425 (Redo the docs for Vec::set_len)
- #56906 (Issue #56905)
- #57042 (Don't call `FieldPlacement::count` when count is too large)
- #57175 (Stabilize `let` bindings and destructuring in constants and const fn)
- #57192 (Change std::error::Error trait documentation to talk about `source` instead of `cause`)
- #57296 (Fixed the link to the ? operator)
- #57368 (Use CMAKE_{C,CXX}_COMPILER_LAUNCHER for ccache)
- #57400 (Rustdoc: update Source Serif Pro and replace Heuristica italic)
- #57417 (rustdoc: use text-based doctest parsing if a macro is wrapping main)
- #57433 (Add link destination for `read-ownership`)
- #57434 (Remove `CrateNum::Invalid`.)
- #57441 (Supporting backtrace for x86_64-fortanix-unknown-sgx.)
- #57450 (actually take a slice in this example)
- #57459 (Reference tracking issue for inherent associated types in diagnostic)
- #57463 (docs: Fix some 'second-edition' links)
- #57466 (Remove outdated comment)
- #57493 (use structured suggestion when casting a reference)
- #57498 (make note of one more normalization that Paths do)
- #57499 (note that FromStr does not work for borrowed types)
- #57505 (Remove submodule step from README)
- #57510 (Add a profiles section to the manifest)
- #57511 (Fix undefined behavior)
- #57519 (Correct RELEASES.md for 1.32.0)
- #57522 (don't unwrap unexpected tokens in `format!`)
- #57530 (Fixing a typographical error.)
- #57535 (Stabilise irrefutable if-let and while-let patterns)
Failed merges:
r? @ghost
Diffstat (limited to 'src/test/ui/pattern')
4 files changed, 85 insertions, 0 deletions
diff --git a/src/test/ui/pattern/deny-irrefutable-let-patterns.rs b/src/test/ui/pattern/deny-irrefutable-let-patterns.rs new file mode 100644 index 00000000000..14040c8ada6 --- /dev/null +++ b/src/test/ui/pattern/deny-irrefutable-let-patterns.rs @@ -0,0 +1,9 @@ +#![deny(irrefutable_let_patterns)] + +fn main() { + if let _ = 5 {} //~ ERROR irrefutable if-let pattern + + while let _ = 5 { //~ ERROR irrefutable while-let pattern + break; + } +} diff --git a/src/test/ui/pattern/deny-irrefutable-let-patterns.stderr b/src/test/ui/pattern/deny-irrefutable-let-patterns.stderr new file mode 100644 index 00000000000..ad8cc2ef897 --- /dev/null +++ b/src/test/ui/pattern/deny-irrefutable-let-patterns.stderr @@ -0,0 +1,22 @@ +error: irrefutable if-let pattern + --> $DIR/deny-irrefutable-let-patterns.rs:4:5 + | +LL | if let _ = 5 {} //~ ERROR irrefutable if-let pattern + | ^^^^^^^^^^^^^^^ + | +note: lint level defined here + --> $DIR/deny-irrefutable-let-patterns.rs:1:9 + | +LL | #![deny(irrefutable_let_patterns)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: irrefutable while-let pattern + --> $DIR/deny-irrefutable-let-patterns.rs:6:5 + | +LL | / while let _ = 5 { //~ ERROR irrefutable while-let pattern +LL | | break; +LL | | } + | |_____^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/pattern/enum-variant-generic-args.rs b/src/test/ui/pattern/enum-variant-generic-args.rs new file mode 100644 index 00000000000..85599530ea6 --- /dev/null +++ b/src/test/ui/pattern/enum-variant-generic-args.rs @@ -0,0 +1,43 @@ +// run-pass + +#![feature(type_alias_enum_variants)] + +#![allow(irrefutable_let_patterns)] + +#[allow(dead_code)] +enum Enum<T> { TSVariant(T), SVariant { v: T } } +type Alias<T> = Enum<T>; +type AliasFixed = Enum<()>; + +macro_rules! is_variant { + (TSVariant, $expr:expr) => (is_variant!(@check TSVariant, (_), $expr)); + (SVariant, $expr:expr) => (is_variant!(@check SVariant, { v: _ }, $expr)); + (@check $variant:ident, $matcher:tt, $expr:expr) => ( + assert!(if let Enum::$variant::<()> $matcher = $expr { true } else { false }, + "expr does not have correct type"); + ); +} + +fn main() { + // Tuple struct variant + + is_variant!(TSVariant, Enum::TSVariant(())); + is_variant!(TSVariant, Enum::TSVariant::<()>(())); + is_variant!(TSVariant, Enum::<()>::TSVariant(())); + + is_variant!(TSVariant, Alias::TSVariant(())); + is_variant!(TSVariant, Alias::<()>::TSVariant(())); + + is_variant!(TSVariant, AliasFixed::TSVariant(())); + + // Struct variant + + is_variant!(SVariant, Enum::SVariant { v: () }); + is_variant!(SVariant, Enum::SVariant::<()> { v: () }); + is_variant!(SVariant, Enum::<()>::SVariant { v: () }); + + is_variant!(SVariant, Alias::SVariant { v: () }); + is_variant!(SVariant, Alias::<()>::SVariant { v: () }); + + is_variant!(SVariant, AliasFixed::SVariant { v: () }); +} diff --git a/src/test/ui/pattern/irrefutable-let-patterns.rs b/src/test/ui/pattern/irrefutable-let-patterns.rs new file mode 100644 index 00000000000..d400ef0bbd6 --- /dev/null +++ b/src/test/ui/pattern/irrefutable-let-patterns.rs @@ -0,0 +1,11 @@ +// run-pass + +#![allow(irrefutable_let_patterns)] + +fn main() { + if let _ = 5 {} + + while let _ = 5 { + break; + } +} |
