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

Stabilise irrefutable if-let and while-let patterns #57535

Merged
merged 2 commits into from Jan 12, 2019

Conversation

Projects
None yet
4 participants
@varkor
Copy link
Member

varkor commented Jan 12, 2019

This stabilises RFC 2086 (#44495).

This replaces #55639, as we want to stabilise this in time for the beta cut-off.

Closes #55639.

r? @Centril

Stabilise irrefutable if-let and while-let patterns
This stabilises RFC 2086 (#44495).

Co-Authored-By: Sebastian Malton <sebastian@malton.name>
@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Jan 12, 2019

@bors r+ p=1

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 12, 2019

📌 Commit afcb938 has been approved by Centril

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jan 12, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:09f4ea60:start=1547262790484177184,finish=1547262792584946636,duration=2100769452
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[01:04:47] .................................................................................................... 4900/5297
[01:04:50] .................................................................................................... 5000/5297
[01:04:53] .................................................................................................... 5100/5297
[01:04:56] .................................................................................................... 5200/5297
[01:04:59] ....................................i.....................................................F......
[01:04:59] 
[01:04:59] ---- [ui] ui/while-let.rs stdout ----
[01:04:59] diff of stderr:
[01:04:59] 
[01:04:59] 
[01:04:59] 27    |
[01:04:59] 28 LL | /     while let a = 1 { //~ WARN irrefutable while-let
[01:04:59] 29 LL | |         println!("irrefutable pattern");
[01:04:59] + LL | |         break;
[01:04:59] 30 LL | |     }
[01:04:59] 32 
[01:04:59] 
[01:04:59] 
[01:04:59] The actual stderr differed from the expected stderr.
[01:04:59] The actual stderr differed from the expected stderr.
[01:04:59] Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/while-let/while-let.stderr
[01:04:59] To update references, rerun the tests and pass the `--bless` flag
[01:04:59] To only update this specific test, also pass `--test-args while-let.rs`
[01:04:59] error: 1 errors occurred comparing output.
[01:04:59] status: exit code: 0
[01:04:59] status: exit code: 0
[01:04:59] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/while-let.rs" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/while-let/a" "-Crpath" "-O" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/while-let/auxiliary" "-A" "unused"
[01:04:59] ------------------------------------------
[01:04:59] 
[01:04:59] ------------------------------------------
[01:04:59] stderr:
[01:04:59] stderr:
[01:04:59] ------------------------------------------
[01:04:59] {"message":"irrefutable while-let pattern","code":{"code":"irrefutable_let_patterns","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":103,"byte_end":108,"line_start":6,"line_end":6,"column_start":13,"column_end":18,"is_primary":true,"text":[{"text":"            while let $p = $e $b","highlight_start":13,"highlight_end":18}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":256,"byte_end":348,"line_start":15,"line_end":17,"column_start":5,"column_end":8,"is_primary":false,"text":[{"text":"    foo!(a, 1, { //~ WARN irrefutable while-let","highlight_start":5,"highlight_end":48},{"text":"        println!(\"irrefutable pattern\");","highlight_start":1,"highlight_end":41},{"text":"    });","highlight_start":1,"highlight_end":8}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"foo!","def_site_span":{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":31,"byte_end":140,"line_start":4,"line_end":8,"column_start":5,"column_end":6,"is_primary":false,"text":[{"text":"    macro_rules! foo{","highlight_start":5,"highlight_end":22},{"text":"        ($p:pat, $e:expr, $b:block) => {{","highlight_start":1,"highlight_end":42},{"text":"            while let $p = $e $b","highlight_start":1,"highlight_end":33},{"text":"        }}","highlight_start":1,"highlight_end":11},{"text":"    }","highlight_start":1,"highlight_end":6}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[{"message":"#[warn(irrefutable_let_patterns)] on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"warning: irrefutable while-let pattern\n  --> /checkout/src/test/ui/while-let.rs:6:13\n   |\nLL |               while let $p = $e $b\n   |               ^^^^^\n...\nLL | /     foo!(a, 1, { //~ WARN irrefutable while-let\nLL | |         println!(\"irrefutable pattern\");\nLL | |     });\n   | |_______- in this macro invocation\n   |\n   = note: #[warn(irrefutable_let_patterns)] on by default\n\n"}
[01:04:59] {"message":"irrefutable while-let pattern","code":{"code":"irrefutable_let_patterns","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":103,"byte_end":108,"line_start":6,"line_end":6,"column_start":13,"column_end":18,"is_primary":true,"text":[{"text":"            while let $p = $e $b","highlight_start":13,"highlight_end":18}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":217,"byte_end":233,"line_start":11,"line_end":11,"column_start":13,"column_end":29,"is_primary":false,"text":[{"text":"            foo!($p, $e, $b)","highlight_start":13,"highlight_end":29}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":353,"byte_end":445,"line_start":18,"line_end":20,"column_start":5,"column_end":8,"is_primary":false,"text":[{"text":"    bar!(a, 1, { //~ WARN irrefutable while-let","highlight_start":5,"highlight_end":48},{"text":"        println!(\"irrefutable pattern\");","highlight_start":1,"highlight_end":41},{"text":"    });","highlight_start":1,"highlight_end":8}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"bar!","def_site_span":{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":145,"byte_end":250,"line_start":9,"line_end":13,"column_start":5,"column_end":6,"is_primary":false,"text":[{"text":"    macro_rules! bar{","highlight_start":5,"highlight_end":22},{"text":"        ($p:pat, $e:expr, $b:block) => {{","highlight_start":1,"highlight_end":42},{"text":"            foo!($p, $e, $b)","highlight_start":1,"highlight_end":29},{"text":"        }}","highlight_start":1,"highlight_end":11},{"text":"    }","highlight_start":1,"highlight_end":6}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},"macro_decl_name":"foo!","def_site_span":{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":31,"byte_end":140,"line_start":4,"line_end":8,"column_start":5,"column_end":6,"is_primary":false,"text":[{"text":"    macro_rules! foo{","highlight_start":5,"highlight_end":22},{"text":"        ($p:pat, $e:expr, $b:block) => {{","highlight_start":1,"highlight_end":42},{"text":"            while let $p = $e $b","highlight_start":1,"highlight_end":33},{"text":"        }}","highlight_start":1,"highlight_end":11},{"text":"    }","highlight_start":1,"highlight_end":6}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[],"rendered":"warning: irrefutable while-let pattern\n  --> /checkout/src/test/ui/while-let.rs:6:13\n   |\nLL |               while let $p = $e $b\n   |               ^^^^^\n...\nLL | /     bar!(a, 1, { //~ WARN irrefutable while-let\nLL | |         println!(\"irrefutable pattern\");\nLL | |     });\n   | |_______- in this macro invocation\n\n"}
[01:04:59] {"message":"irrefutable while-let pattern","code":{"code":"irrefutable_let_patterns","explanation":null},"level":"warning","spans":[{"file_name":"/checkout/src/test/ui/while-let.rs","byte_start":469,"byte_end":579,"line_start":24,"line_end":27,"column_start":5,"column_end":6,"is_primary":true,"text":[{"text":"    while let a = 1 { //~ WARN irrefutable while-let","highlight_start":5,"highlight_end":53},{"text":"        println!(\"irrefutable pattern\");","highlight_start":1,"highlight_end":41},{"text":"        break;","highlight_start":1,"highlight_end":15},{"text":"    }","highlight_start":1,"highlight_end":6}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"warning: irrefutable while-let pattern\n  --> /checkout/src/test/ui/while-let.rs:24:5\n   |\nLL | /     while let a = 1 { //~ WARN irrefutable while-let\nLL | |         println!(\"irrefutable pattern\");\nLL | |         break;\nLL | |     }\n   | |_____^\n\n"}
[01:04:59] ------------------------------------------
[01:04:59] 
[01:04:59] thread '[ui] ui/while-let.rs' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3245:9
[01:04:59] 
---
[01:04:59] 
[01:04:59] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:495:22
[01:04:59] 
[01:04:59] 
[01:04:59] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:04:59] 
[01:04:59] 
[01:04:59] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:04:59] Build completed unsuccessfully in 0:04:13
[01:04:59] Build completed unsuccessfully in 0:04:13
[01:04:59] Makefile:48: recipe for target 'check' failed
[01:04:59] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0bd49ead
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sat Jan 12 04:18:23 UTC 2019

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 12, 2019

⌛️ Testing commit afcb938 with merge 854c924...

bors added a commit that referenced this pull request Jan 12, 2019

Auto merge of #57535 - varkor:stabilise-if-while-let-patterns, r=Centril
Stabilise irrefutable if-let and while-let patterns

This stabilises RFC 2086 (#44495).

This replaces #55639, as we want to stabilise this in time for the beta cut-off.

Closes #55639.

r? @Centril
@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Jan 12, 2019

@bors retry

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Jan 12, 2019

@bors r-

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Jan 12, 2019

@bors r+ p=1

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 12, 2019

📌 Commit 0e1402d has been approved by Centril

Centril added a commit to Centril/rust that referenced this pull request Jan 12, 2019

Rollup merge of rust-lang#57535 - varkor:stabilise-if-while-let-patte…
…rns, r=Centril

Stabilise irrefutable if-let and while-let patterns

This stabilises RFC 2086 (rust-lang#44495).

This replaces rust-lang#55639, as we want to stabilise this in time for the beta cut-off.

Closes rust-lang#55639.

r? @Centril

bors added a commit that referenced this pull request Jan 12, 2019

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

@bors bors merged commit 0e1402d into rust-lang:master Jan 12, 2019

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 3, 2019

he
Update rust to version 1.33.0.
Pkgsrc changes:
 * Bump required rust version to build to 1.32.0.
 * Adapt patches to changed file locations.
 * Since we now patch some more vendor/ modules, doctor the corresponding
   .cargo-checksum.json files accordingly

Upstream changes:

Version 1.33.0 (2019-02-28)
==========================

Language
--------
- [You can now use the `cfg(target_vendor)` attribute.][57465] E.g.
  `#[cfg(target_vendor="apple")] fn main() { println!("Hello Apple!"); }`
- [Integer patterns such as in a match expression can now be exhaustive.][56362]
  E.g. You can have match statement on a `u8` that covers `0..=255` and
  you would no longer be required to have a `_ => unreachable!()` case.
- [You can now have multiple patterns in `if let` and `while let`
  expressions.][57532] You can do this with the same syntax as a `match`
  expression. E.g.
  ```rust
  enum Creature {
      Crab(String),
      Lobster(String),
      Person(String),
  }

  fn main() {
      let state = Creature::Crab("Ferris");

      if let Creature::Crab(name) | Creature::Person(name) = state {
          println!("This creature's name is: {}", name);
      }
  }
  ```
- [You can now have irrefutable `if let` and `while let` patterns.][57535]
  Using this feature will by default produce a warning as this behaviour
  can be unintuitive. E.g. `if let _ = 5 {}`
- [You can now use `let` bindings, assignments, expression statements,
  and irrefutable pattern destructuring in const functions.][57175]
- [You can now call unsafe const functions.][57067] E.g.
  ```rust
  const unsafe fn foo() -> i32 { 5 }
  const fn bar() -> i32 {
      unsafe { foo() }
  }
  ```
- [You can now specify multiple attributes in a `cfg_attr` attribute.][57332]
  E.g. `#[cfg_attr(all(), must_use, optimize)]`
- [You can now specify a specific alignment with the `#[repr(packed)]`
  attribute.][57049] E.g. `#[repr(packed(2))] struct Foo(i16, i32);` is a
  struct with an alignment of 2 bytes and a size of 6 bytes.
- [You can now import an item from a module as an `_`.][56303] This allows you
  to import a trait's impls, and not have the name in the namespace. E.g.
  ```rust
  use std::io::Read as _;

  // Allowed as there is only one `Read` in the module.
  pub trait Read {}
  ```
- [You may now use `Rc`, `Arc`, and `Pin` as method receivers][56805].

Compiler
--------
- [You can now set a linker flavor for `rustc` with the `-Clinker-flavor`
  command line argument.][56351]
- [The mininum required LLVM version has been bumped to 6.0.][56642]
- [Added support for the PowerPC64 architecture on FreeBSD.][57615]
- [The `x86_64-fortanix-unknown-sgx` target support has been upgraded to
  tier 2 support.][57130] Visit the [platform support][platform-support]
  page for information on Rust's platform support.
- [Added support for the `thumbv7neon-linux-androideabi` and
  `thumbv7neon-unknown-linux-gnueabihf` targets.][56947]
- [Added support for the `x86_64-unknown-uefi` target.][56769]

Libraries
---------
- [The methods `overflowing_{add, sub, mul, shl, shr}` are now `const`
  functions for all numeric types.][57566]
- [The methods `rotate_left`, `rotate_right`, and `wrapping_{add, sub, mul,
  shl, shr}`
  are now `const` functions for all numeric types.][57105]
- [The methods `is_positive` and `is_negative` are now `const` functions for
  all signed numeric types.][57105]
- [The `get` method for all `NonZero` types is now `const`.][57167]
- [The methods `count_ones`, `count_zeros`, `leading_zeros`, `trailing_zeros`,
  `swap_bytes`, `from_be`, `from_le`, `to_be`, `to_le` are now `const` for all
  numeric types.][57234]
- [`Ipv4Addr::new` is now a `const` function][57234]

Stabilized APIs
---------------
- [`unix::FileExt::read_exact_at`]
- [`unix::FileExt::write_all_at`]
- [`Option::transpose`]
- [`Result::transpose`]
- [`convert::identity`]
- [`pin::Pin`]
- [`marker::Unpin`]
- [`marker::PhantomPinned`]
- [`Vec::resize_with`]
- [`VecDeque::resize_with`]
- [`Duration::as_millis`]
- [`Duration::as_micros`]
- [`Duration::as_nanos`]


Cargo
-----
- [Cargo should now rebuild a crate if a file was modified during the initial
  build.][cargo/6484]

Compatibility Notes
-------------------
- The methods `str::{trim_left, trim_right, trim_left_matches,
  trim_right_matches}` are now deprecated in the standard library, and their
  usage will now produce a warning.  Please use the `str::{trim_start,
  trim_end, trim_start_matches, trim_end_matches}` methods instead.
- The `Error::cause` method has been deprecated in favor of `Error::source`
  which supports downcasting.

[55982]: rust-lang/rust#55982
[56303]: rust-lang/rust#56303
[56351]: rust-lang/rust#56351
[56362]: rust-lang/rust#56362
[56642]: rust-lang/rust#56642
[56769]: rust-lang/rust#56769
[56805]: rust-lang/rust#56805
[56947]: rust-lang/rust#56947
[57049]: rust-lang/rust#57049
[57067]: rust-lang/rust#57067
[57105]: rust-lang/rust#57105
[57130]: rust-lang/rust#57130
[57167]: rust-lang/rust#57167
[57175]: rust-lang/rust#57175
[57234]: rust-lang/rust#57234
[57332]: rust-lang/rust#57332
[57465]: rust-lang/rust#57465
[57532]: rust-lang/rust#57532
[57535]: rust-lang/rust#57535
[57566]: rust-lang/rust#57566
[57615]: rust-lang/rust#57615
[cargo/6484]: rust-lang/cargo#6484
[`unix::FileExt::read_exact_at`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#method.read_exact_at
[`unix::FileExt::write_all_at`]: https://doc.rust-lang.org/std/os/unix/fs/trait.FileExt.html#method.write_all_at
[`Option::transpose`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.transpose
[`Result::transpose`]: https://doc.rust-lang.org/std/result/enum.Result.html#method.transpose
[`convert::identity`]: https://doc.rust-lang.org/std/convert/fn.identity.html
[`pin::Pin`]: https://doc.rust-lang.org/std/pin/struct.Pin.html
[`marker::Unpin`]: https://doc.rust-lang.org/stable/std/marker/trait.Unpin.html
[`marker::PhantomPinned`]: https://doc.rust-lang.org/nightly/std/marker/struct.PhantomPinned.html
[`Vec::resize_with`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.resize_with
[`VecDeque::resize_with`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.resize_with
[`Duration::as_millis`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_millis
[`Duration::as_micros`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_micros
[`Duration::as_nanos`]: https://doc.rust-lang.org/std/time/struct.Duration.html#method.as_nanos
[platform-support]: https://forge.rust-lang.org/platform-support.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.