1
Fork 0

Rollup merge of #93628 - est31:stabilize_let_else, r=joshtriplett

Stabilize `let else`

🎉  **Stabilizes the `let else` feature, added by [RFC 3137](https://github.com/rust-lang/rfcs/pull/3137).** 🎉

Reference PR: https://github.com/rust-lang/reference/pull/1156

closes #87335 (`let else` tracking issue)

FCP: https://github.com/rust-lang/rust/pull/93628#issuecomment-1029383585

----------

## Stabilization report

### Summary

The feature allows refutable patterns in `let` statements if the expression is
followed by a diverging `else`:

```Rust
fn get_count_item(s: &str) -> (u64, &str) {
    let mut it = s.split(' ');
    let (Some(count_str), Some(item)) = (it.next(), it.next()) else {
        panic!("Can't segment count item pair: '{s}'");
    };
    let Ok(count) = u64::from_str(count_str) else {
        panic!("Can't parse integer: '{count_str}'");
    };
    (count, item)
}
assert_eq!(get_count_item("3 chairs"), (3, "chairs"));
```

### Differences from the RFC / Desugaring

Outside of desugaring I'm not aware of any differences between the implementation and the RFC. The chosen desugaring has been changed from the RFC's [original](https://rust-lang.github.io/rfcs/3137-let-else.html#reference-level-explanations). You can read a detailed discussion of the implementation history of it in `@cormacrelf` 's [summary](https://github.com/rust-lang/rust/pull/93628#issuecomment-1041143670) in this thread, as well as the [followup](https://github.com/rust-lang/rust/pull/93628#issuecomment-1046598419). Since that followup, further changes have happened to the desugaring, in #98574, #99518, #99954. The later changes were mostly about the drop order: On match, temporaries drop in the same order as they would for a `let` declaration. On mismatch, temporaries drop before the `else` block.

### Test cases

In chronological order as they were merged.

Added by df9a2e0687 (#87688):

* [`ui/pattern/usefulness/top-level-alternation.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/pattern/usefulness/top-level-alternation.rs) to ensure the unreachable pattern lint visits patterns inside `let else`.

Added by 5b95df4bdc (#87688):

* [`ui/let-else/let-else-bool-binop-init.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-bool-binop-init.rs) to ensure that no lazy boolean expressions (using `&&` or `||`) are allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-brace-before-else.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-brace-before-else.rs) to ensure that no `}` directly preceding the `else` is allowed in the expression, as the RFC mandates.
* [`ui/let-else/let-else-check.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-check.rs) to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for the `else` block.
* [`ui/let-else/let-else-irrefutable.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-irrefutable.rs) to ensure that the `irrefutable_let_patterns` lint fires.
* [`ui/let-else/let-else-missing-semicolon.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-missing-semicolon.rs) to ensure the presence of semicolons at the end of the `let` statement.
* [`ui/let-else/let-else-non-diverging.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-non-diverging.rs) to ensure the `else` block diverges.
* [`ui/let-else/let-else-run-pass.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-run-pass.rs) to ensure the feature works in some simple test case settings.
* [`ui/let-else/let-else-scope.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-scope.rs) to ensure the bindings created by the outer `let` expression are not available in the `else` block of it.

Added by bf7c32a447 (#89965):

* [`ui/let-else/issue-89960.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/issue-89960.rs) as a regression test for the ICE-on-error bug #89960 . Later in 102b9125e1 this got removed in favour of more comprehensive tests.

Added by 856541963c (#89974):

* [`ui/let-else/let-else-if.rs`](https://github.com/rust-lang/rust/blob/1.58.1/src/test/ui/let-else/let-else-if.rs) to test for the improved error message that points out that `let else if` is not possible.

Added by 9b45713b6c:

* [`ui/let-else/let-else-allow-unused.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-unused.rs) as a regression test for #89807, to ensure that `#[allow(...)]` attributes added to the entire `let` statement apply for bindings created by the `let else` pattern.

Added by 61bcd8d307 (#89841):

* [`ui/let-else/let-else-non-copy.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-non-copy.rs) to ensure that a copy is performed out of non-copy wrapper types. This mirrors `if let` behaviour. The test case bases on rustc internal changes originally meant for #89933 but then removed from the PR due to the error prior to the improvements of #89841.
* [`ui/let-else/let-else-source-expr-nomove-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-source-expr-nomove-pass.rs) to ensure that while there is a move of the binding in the successful case, the `else` case can still access the non-matching value. This mirrors `if let` behaviour.

Added by 102b9125e1 (#89841):

* [`ui/let-else/let-else-ref-bindings.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings.rs) and [`ui/let-else/let-else-ref-bindings-pass.rs `](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-ref-bindings-pass.rs) to check `ref` and `ref mut` keywords in the pattern work correctly and error when needed.

Added by 2715c5f984 (#89841):

* Match ergonomic tests adapted from the `rfc2005` test suite.

Added by fec8a507a2 (#89841):

* [`ui/let-else/let-else-deref-coercion-annotated.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion-annotated.rs) and [`ui/let-else/let-else-deref-coercion.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-deref-coercion.rs) to check deref coercions.

#### Added since this stabilization report was originally written (2022-02-09)

Added by 76ea566677 (#94211):

* [`ui/let-else/let-else-destructuring.rs`](https://github.com/rust-lang/rust/blob/1.63.0/src/test/ui/let-else/let-else-destructuring.rs) to give a nice error message if an user tries to do an assignment with a (possibly refutable) pattern and an `else` block, like asked for in #93995.

Added by e7730dcb7e (#94208):

* [`ui/let-else/let-else-allow-in-expr.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-allow-in-expr.rs) to test whether `#[allow(unused_variables)]` works in the expr, as well as its non presence, as well as putting it on the entire `let else` *affects* the expr, too. This was adding a missing test as pointed out by the stabilization report.
* Expansion of `ui/let-else/let-else-allow-unused.rs` and `ui/let-else/let-else-check.rs` to ensure that non-presence of `#[allow(unused)]` does issue the unused lint. This was adding a missing test case as pointed out by the stabilization report.

Added by 5bd71063b3 (#94208):

* [`ui/let-else/let-else-slicing-error.rs`](https://github.com/rust-lang/rust/blob/1.61.0/src/test/ui/let-else/let-else-slicing-error.rs), a regression test for #92069, which got fixed without addition of a regression test. This resolves a missing test as pointed out by the stabilization report.

Added by 5374688e1d (#98574):

* [`src/test/ui/async-await/async-await-let-else.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/async-await/async-await-let-else.rs) to test the interaction of async/await with `let else`

Added by 6c529ded86 (#98574):

* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) as a (partial) regression test for #98672

Added by 9b56640106 (#99518):

* [`src/test/ui/let-else/let-else-temp-borrowck.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) as a regression test for #93951
* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #98672 (especially regarding `else` drop order)

Added by baf9a7cb57 (#99518):

* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a partial regression test for #93951, similar to `let-else-temp-borrowck.rs`

Added by 60be2de8b7 (#99518):

* Extension of `src/test/ui/let-else/let-else-temporary-lifetime.rs` to include a program that can now be compiled thanks to borrow checker implications of #99518

Added by 47a7a91c96 (#100132):

* [`src/test/ui/let-else/issue-100103.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-100103.rs), as a regression test for #100103, to ensure that there is no ICE when doing `Err(...)?` inside else blocks.

Added by e3c5bd617d (#100443):

* [`src/test/ui/let-else/let-else-then-diverge.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-then-diverge.rs), to verify that there is no unreachable code error with the current desugaring.

Added by 981852677c (#100443):

* [`src/test/ui/let-else/issue-94176.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-94176.rs), to make sure that a correct span is emitted for a missing trailing expression error. Regression test for #94176.

Added by e182d12a84 (#100434):

* [src/test/ui/unpretty/pretty-let-else.rs](https://github.com/rust-lang/rust/blob/master/src/test/ui/unpretty/pretty-let-else.rs), as a regression test to ensure pretty printing works for `let else` (this bug surfaced in many different ways)

Added by e26285603c (#99954):

* [`src/test/ui/let-else/let-else-temporary-lifetime.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-temporary-lifetime.rs) extended to contain & borrows as well, as this was identified as an earlier issue with the desugaring: https://github.com/rust-lang/rust/issues/98672#issuecomment-1200196921

Added by 2d8460ef43 (#99291):

* [`src/test/ui/let-else/let-else-drop-order.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/let-else-drop-order.rs) a matrix based test for various drop order behaviour of `let else`. Especially, it verifies equality of `let` and `let else` drop orders, [resolving](https://github.com/rust-lang/rust/pull/93628#issuecomment-1238498468) a [stabilization blocker](https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523).

Added by 1b87ce0d40 (#101410):

* Edit to `src/test/ui/let-else/let-else-temporary-lifetime.rs` to add the `-Zvalidate-mir` flag, as a regression test for #99228

Added by af591ebe4d (#101410):

* [`src/test/ui/let-else/issue-99975.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui/let-else/issue-99975.rs) as a regression test for the ICE #99975.

Added by this PR:

* `ui/let-else/let-else.rs`, a simple run-pass check, similar to `ui/let-else/let-else-run-pass.rs`.

### Things not currently tested

* ~~The `#[allow(...)]` tests check whether allow works, but they don't check whether the non-presence of allow causes a lint to fire.~~ → *test added by e7730dcb7e*
* ~~There is no `#[allow(...)]` test for the expression, as there are tests for the pattern and the else block.~~ → *test added by e7730dcb7e*
* ~~`let-else-brace-before-else.rs` forbids the `let ... = {} else {}` pattern and there is a rustfix to obtain `let ... = ({}) else {}`. I'm not sure whether the `.fixed` files are checked by the tooling that they compile. But if there is no such check, it would be neat to make sure that `let ... = ({}) else {}` compiles.~~ → *test added by e7730dcb7e*
* ~~#92069 got closed as fixed, but no regression test was added. Not sure it's worth to add one.~~ → *test added by 5bd71063b3*
* ~~consistency between `let else` and `if let` regarding lifetimes and drop order: https://github.com/rust-lang/rust/pull/93628#issuecomment-1055738523~~ → *test added by 2d8460ef43*

Edit: they are all tested now.

### Possible future work / Refutable destructuring assignments

[RFC 2909](https://rust-lang.github.io/rfcs/2909-destructuring-assignment.html) specifies destructuring assignment, allowing statements like `FooBar { a, b, c } = foo();`.
As it was stabilized, destructuring assignment only allows *irrefutable* patterns, which before the advent of `let else` were the only patterns that `let` supported.
So the combination of `let else` and destructuring assignments gives reason to think about extensions of the destructuring assignments feature that allow refutable patterns, discussed in #93995.

A naive mapping of `let else` to destructuring assignments in the form of `Some(v) = foo() else { ... };` might not be the ideal way. `let else` needs a diverging `else` clause as it introduces new bindings, while assignments have a default behaviour to fall back to if the pattern does not match, in the form of not performing the assignment. Thus, there is no good case to require divergence, or even an `else` clause at all, beyond the need for having *some* introducer syntax so that it is clear to readers that the assignment is not a given (enums and structs look similar). There are better candidates for introducer syntax however than an empty `else {}` clause, like `maybe` which could be added as a keyword on an edition boundary:

```Rust
let mut v = 0;
maybe Some(v) = foo(&v);
maybe Some(v) = foo(&v) else { bar() };
```

Further design discussion is left to an RFC, or the linked issue.
This commit is contained in:
Dylan DPC 2022-09-17 15:31:06 +05:30 committed by GitHub
commit 3ad81e0dd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
114 changed files with 170 additions and 211 deletions

View file

@ -15,7 +15,7 @@
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![cfg_attr(bootstrap, feature(label_break_value))] #![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(negative_impls)] #![feature(negative_impls)]
#![feature(slice_internals)] #![feature(slice_internals)]

View file

@ -1,8 +1,6 @@
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext}; use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
use rustc_ast::{Block, BlockCheckMode, Local, LocalKind, Stmt, StmtKind}; use rustc_ast::{Block, BlockCheckMode, Local, LocalKind, Stmt, StmtKind};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_session::parse::feature_err;
use rustc_span::sym;
use smallvec::SmallVec; use smallvec::SmallVec;
@ -92,15 +90,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let hir_id = self.lower_node_id(l.id); let hir_id = self.lower_node_id(l.id);
let pat = self.lower_pat(&l.pat); let pat = self.lower_pat(&l.pat);
let els = if let LocalKind::InitElse(_, els) = &l.kind { let els = if let LocalKind::InitElse(_, els) = &l.kind {
if !self.tcx.features().let_else {
feature_err(
&self.tcx.sess.parse_sess,
sym::let_else,
l.span,
"`let...else` statements are unstable",
)
.emit();
}
Some(self.lower_block(els, false)) Some(self.lower_block(els, false))
} else { } else {
None None

View file

@ -32,7 +32,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(never_type)] #![feature(never_type)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]

View file

@ -9,7 +9,7 @@
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(iter_is_partitioned)] #![feature(iter_is_partitioned)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use] #[macro_use]

View file

@ -5,7 +5,7 @@
//! to this crate. //! to this crate.
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]

View file

@ -3,7 +3,7 @@
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]

View file

@ -9,7 +9,7 @@
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(is_sorted)] #![feature(is_sorted)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(proc_macro_internals)] #![feature(proc_macro_internals)]
#![feature(proc_macro_quote)] #![feature(proc_macro_quote)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -7,7 +7,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(hash_raw_entry)] #![feature(hash_raw_entry)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(extern_types)] #![feature(extern_types)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(iter_intersperse)] #![feature(iter_intersperse)]

View file

@ -1,7 +1,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(strict_provenance)] #![feature(strict_provenance)]

View file

@ -10,7 +10,7 @@ Rust MIR: a lowered representation of Rust.
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(map_try_insert)] #![feature(map_try_insert)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(slice_ptr_get)] #![feature(slice_ptr_get)]

View file

@ -13,7 +13,7 @@
#![feature(cell_leak)] #![feature(cell_leak)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(extend_one)] #![feature(extend_one)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(hash_raw_entry)] #![feature(hash_raw_entry)]
#![feature(hasher_prefixfree_extras)] #![feature(hasher_prefixfree_extras)]
#![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_uninit_array)]

View file

@ -5,7 +5,7 @@
//! This API is completely unstable and subject to change. //! This API is completely unstable and subject to change.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(once_cell)] #![feature(once_cell)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]

View file

@ -7,7 +7,7 @@
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(adt_const_params)] #![feature(adt_const_params)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(never_type)] #![feature(never_type)]
#![feature(result_option_inspect)] #![feature(result_option_inspect)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]

View file

@ -3,7 +3,7 @@
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(macro_metavar_expr)] #![feature(macro_metavar_expr)]
#![feature(proc_macro_diagnostic)] #![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)] #![feature(proc_macro_internals)]

View file

@ -190,6 +190,8 @@ declare_features! (
(accepted, item_like_imports, "1.15.0", Some(35120), None), (accepted, item_like_imports, "1.15.0", Some(35120), None),
/// Allows `'a: { break 'a; }`. /// Allows `'a: { break 'a; }`.
(accepted, label_break_value, "CURRENT_RUSTC_VERSION", Some(48594), None), (accepted, label_break_value, "CURRENT_RUSTC_VERSION", Some(48594), None),
/// Allows `let...else` statements.
(accepted, let_else, "CURRENT_RUSTC_VERSION", Some(87335), None),
/// Allows `break {expr}` with a value inside `loop`s. /// Allows `break {expr}` with a value inside `loop`s.
(accepted, loop_break_value, "1.19.0", Some(37339), None), (accepted, loop_break_value, "1.19.0", Some(37339), None),
/// Allows use of `?` as the Kleene "at most one" operator in macros. /// Allows use of `?` as the Kleene "at most one" operator in macros.

View file

@ -430,8 +430,6 @@ declare_features! (
(active, large_assignments, "1.52.0", Some(83518), None), (active, large_assignments, "1.52.0", Some(83518), None),
/// Allows `if/while p && let q = r && ...` chains. /// Allows `if/while p && let q = r && ...` chains.
(active, let_chains, "1.37.0", Some(53667), None), (active, let_chains, "1.37.0", Some(53667), None),
/// Allows `let...else` statements.
(active, let_else, "1.56.0", Some(87335), None),
/// Allows `#[link(..., cfg(..))]`. /// Allows `#[link(..., cfg(..))]`.
(active, link_cfg, "1.14.0", Some(37406), None), (active, link_cfg, "1.14.0", Some(37406), None),
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check. /// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.

View file

@ -5,7 +5,7 @@
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(closure_track_caller)] #![feature(closure_track_caller)]
#![feature(const_btree_new)] #![feature(const_btree_new)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]

View file

@ -2,7 +2,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]

View file

@ -3,7 +3,7 @@
#![feature(allow_internal_unstable)] #![feature(allow_internal_unstable)]
#![feature(bench_black_box)] #![feature(bench_black_box)]
#![feature(extend_one)] #![feature(extend_one)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(new_uninit)] #![feature(new_uninit)]
#![feature(step_trait)] #![feature(step_trait)]

View file

@ -19,7 +19,7 @@
#![feature(extend_one)] #![feature(extend_one)]
#![cfg_attr(bootstrap, feature(label_break_value))] #![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]
#![feature(try_blocks)] #![feature(try_blocks)]

View file

@ -1,5 +1,5 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(internal_output_capture)] #![feature(internal_output_capture)]
#![feature(thread_spawn_unchecked)] #![feature(thread_spawn_unchecked)]
#![feature(once_cell)] #![feature(once_cell)]

View file

@ -34,7 +34,7 @@
#![feature(iter_intersperse)] #![feature(iter_intersperse)]
#![feature(iter_order_by)] #![feature(iter_order_by)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -1,5 +1,5 @@
#![feature(allow_internal_unstable)] #![feature(allow_internal_unstable)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(never_type)] #![feature(never_type)]
#![feature(proc_macro_diagnostic)] #![feature(proc_macro_diagnostic)]
#![feature(proc_macro_span)] #![feature(proc_macro_span)]

View file

@ -5,7 +5,7 @@
#![cfg_attr(bootstrap, feature(generic_associated_types))] #![cfg_attr(bootstrap, feature(generic_associated_types))]
#![feature(iter_from_generator)] #![feature(iter_from_generator)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(proc_macro_internals)] #![feature(proc_macro_internals)]
#![feature(macro_metavar_expr)] #![feature(macro_metavar_expr)]

View file

@ -40,7 +40,7 @@
#![feature(new_uninit)] #![feature(new_uninit)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(trusted_len)] #![feature(trusted_len)]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]

View file

@ -6,7 +6,7 @@
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(once_cell)] #![feature(once_cell)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -491,8 +491,8 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
err.span_suggestion_verbose( err.span_suggestion_verbose(
semi_span.shrink_to_lo(), semi_span.shrink_to_lo(),
&format!( &format!(
"alternatively, on nightly, you might want to use \ "alternatively, you might want to use \
`#![feature(let_else)]` to handle the variant{} that {} matched", let else to handle the variant{} that {} matched",
pluralize!(witnesses.len()), pluralize!(witnesses.len()),
match witnesses.len() { match witnesses.len() {
1 => "isn't", 1 => "isn't",

View file

@ -1,7 +1,7 @@
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(exact_size_is_empty)] #![feature(exact_size_is_empty)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]

View file

@ -1,7 +1,7 @@
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(map_try_insert)] #![feature(map_try_insert)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]

View file

@ -1,6 +1,6 @@
#![feature(array_windows)] #![feature(array_windows)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]

View file

@ -4,7 +4,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(never_type)] #![feature(never_type)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -8,7 +8,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(iter_intersperse)] #![feature(iter_intersperse)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(map_try_insert)] #![feature(map_try_insert)]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(try_blocks)] #![feature(try_blocks)]

View file

@ -1,7 +1,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -1,7 +1,7 @@
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(hash_raw_entry)] #![feature(hash_raw_entry)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(extern_types)] #![feature(extern_types)]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]

View file

@ -12,7 +12,7 @@
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(iter_intersperse)] #![feature(iter_intersperse)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(never_type)] #![feature(never_type)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustdoc::private_intra_doc_links)] #![allow(rustdoc::private_intra_doc_links)]

View file

@ -1,6 +1,6 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![feature(never_type)] #![feature(never_type)]

View file

@ -14,7 +14,7 @@ Core encoding and decoding interfaces.
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(maybe_uninit_slice)] #![feature(maybe_uninit_slice)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(new_uninit)] #![feature(new_uninit)]
#![feature(allocator_api)] #![feature(allocator_api)]
#![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(test))]

View file

@ -1,6 +1,6 @@
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]
#![feature(once_cell)] #![feature(once_cell)]

View file

@ -15,7 +15,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_windows)] #![feature(array_windows)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(negative_impls)] #![feature(negative_impls)]
#![feature(min_specialization)] #![feature(min_specialization)]

View file

@ -11,7 +11,7 @@
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(associated_type_bounds)] #![feature(associated_type_bounds)]
#![feature(exhaustive_patterns)] #![feature(exhaustive_patterns)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]

View file

@ -18,7 +18,7 @@
#![feature(hash_drain_filter)] #![feature(hash_drain_filter)]
#![cfg_attr(bootstrap, feature(label_break_value))] #![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(never_type)] #![feature(never_type)]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]

View file

@ -3,7 +3,7 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use] #[macro_use]

View file

@ -6,7 +6,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(never_type)] #![feature(never_type)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![recursion_limit = "256"] #![recursion_limit = "256"]

View file

@ -66,7 +66,7 @@ This API is completely unstable and subject to change.
#![feature(iter_intersperse)] #![feature(iter_intersperse)]
#![cfg_attr(bootstrap, feature(label_break_value))] #![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(never_type)] #![feature(never_type)]
#![feature(once_cell)] #![feature(once_cell)]

View file

@ -169,7 +169,7 @@
#![cfg_attr(not(test), feature(generator_trait))] #![cfg_attr(not(test), feature(generator_trait))]
#![feature(hashmap_internals)] #![feature(hashmap_internals)]
#![feature(lang_items)] #![feature(lang_items)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(negative_impls)] #![feature(negative_impls)]
#![feature(never_type)] #![feature(never_type)]

View file

@ -255,7 +255,7 @@
#![cfg_attr(bootstrap, feature(label_break_value))] #![cfg_attr(bootstrap, feature(label_break_value))]
#![feature(lang_items)] #![feature(lang_items)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(linkage)] #![feature(linkage)]
#![feature(link_cfg)] #![feature(link_cfg)]
#![feature(min_specialization)] #![feature(min_specialization)]

View file

@ -9,7 +9,7 @@
#![feature(control_flow_enum)] #![feature(control_flow_enum)]
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(let_chains)] #![feature(let_chains)]
#![feature(let_else)] #![cfg_attr(bootstrap, feature(let_else))]
#![feature(test)] #![feature(test)]
#![feature(never_type)] #![feature(never_type)]
#![feature(once_cell)] #![feature(once_cell)]

View file

@ -2,7 +2,7 @@
// revisions: drop-tracking no-drop-tracking // revisions: drop-tracking no-drop-tracking
// [drop-tracking] compile-flags: -Zdrop-tracking=yes // [drop-tracking] compile-flags: -Zdrop-tracking=yes
// [no-drop-tracking] compile-flags: -Zdrop-tracking=no // [no-drop-tracking] compile-flags: -Zdrop-tracking=no
#![feature(let_else)]
use std::rc::Rc; use std::rc::Rc;
async fn foo(x: Option<bool>) { async fn foo(x: Option<bool>) {

View file

@ -18,7 +18,7 @@ help: you might want to use `if let` to ignore the variant that isn't matched
| |
LL | let u = if let Helper::U(u) = Helper::T(t, []) { u } else { todo!() }; LL | let u = if let Helper::U(u) = Helper::T(t, []) { u } else { todo!() };
| ++++++++++ ++++++++++++++++++++++ | ++++++++++ ++++++++++++++++++++++
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variant that isn't matched help: alternatively, you might want to use let else to handle the variant that isn't matched
| |
LL | let Helper::U(u) = Helper::T(t, []) else { todo!() }; LL | let Helper::U(u) = Helper::T(t, []) else { todo!() };
| ++++++++++++++++ | ++++++++++++++++

View file

@ -19,7 +19,7 @@ help: you might want to use `if let` to ignore the variant that isn't matched
| |
LL | let y = if let Some(y) = x { y } else { todo!() }; LL | let y = if let Some(y) = x { y } else { todo!() };
| ++++++++++ ++++++++++++++++++++++ | ++++++++++ ++++++++++++++++++++++
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variant that isn't matched help: alternatively, you might want to use let else to handle the variant that isn't matched
| |
LL | let Some(y) = x else { todo!() }; LL | let Some(y) = x else { todo!() };
| ++++++++++++++++ | ++++++++++++++++

View file

@ -19,7 +19,7 @@ help: you might want to use `if let` to ignore the variant that isn't matched
| |
LL | let _x = if let Ok(_x) = foo() { _x } else { todo!() }; LL | let _x = if let Ok(_x) = foo() { _x } else { todo!() };
| +++++++++++ +++++++++++++++++++++++ | +++++++++++ +++++++++++++++++++++++
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variant that isn't matched help: alternatively, you might want to use let else to handle the variant that isn't matched
| |
LL | let Ok(_x) = foo() else { todo!() }; LL | let Ok(_x) = foo() else { todo!() };
| ++++++++++++++++ | ++++++++++++++++

View file

@ -1,5 +0,0 @@
fn main() {
let Some(x) = Some(1) else { //~ ERROR `let...else` statements are unstable
return;
};
}

View file

@ -1,14 +0,0 @@
error[E0658]: `let...else` statements are unstable
--> $DIR/feature-gate-let_else.rs:2:5
|
LL | / let Some(x) = Some(1) else {
LL | | return;
LL | | };
| |______^
|
= note: see issue #87335 <https://github.com/rust-lang/rust/issues/87335> for more information
= help: add `#![feature(let_else)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -2,7 +2,7 @@
// check-pass // check-pass
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(let_else)]
fn main() { fn main() {
let _: Result<i32, i32> = try { let _: Result<i32, i32> = try {

View file

@ -1,6 +1,6 @@
// Issue #94176: wrong span for the error message of a mismatched type error, // Issue #94176: wrong span for the error message of a mismatched type error,
// if the function uses a `let else` construct. // if the function uses a `let else` construct.
#![feature(let_else)]
pub fn test(a: Option<u32>) -> Option<u32> { //~ ERROR mismatched types pub fn test(a: Option<u32>) -> Option<u32> { //~ ERROR mismatched types
let Some(_) = a else { return None; }; let Some(_) = a else { return None; };

View file

@ -1,7 +1,7 @@
// run-pass // run-pass
// compile-flags: -C opt-level=3 -Zvalidate-mir // compile-flags: -C opt-level=3 -Zvalidate-mir
#![feature(let_else)]
fn return_result() -> Option<String> { fn return_result() -> Option<String> {
Some("ok".to_string()) Some("ok".to_string())

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
#![deny(unused_variables)] #![deny(unused_variables)]
fn main() { fn main() {

View file

@ -1,17 +1,17 @@
error: unused variable: `x` error: unused variable: `x`
--> $DIR/let-else-allow-in-expr.rs:7:13 --> $DIR/let-else-allow-in-expr.rs:5:13
| |
LL | let x = 1; LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/let-else-allow-in-expr.rs:3:9 --> $DIR/let-else-allow-in-expr.rs:1:9
| |
LL | #![deny(unused_variables)] LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: unused variable: `x` error: unused variable: `x`
--> $DIR/let-else-allow-in-expr.rs:29:9 --> $DIR/let-else-allow-in-expr.rs:27:9
| |
LL | let x = 1; LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`

View file

@ -1,6 +1,6 @@
// issue #89807 // issue #89807
#![feature(let_else)]
#[deny(unused_variables)] #[deny(unused_variables)]

View file

@ -1,6 +1,6 @@
// from rfc2005 test suite // from rfc2005 test suite
#![feature(let_else)]
// Verify the binding mode shifts - only when no `&` are auto-dereferenced is the // Verify the binding mode shifts - only when no `&` are auto-dereferenced is the
// final default binding mode mutable. // final default binding mode mutable.

View file

@ -1,8 +1,8 @@
#![feature(let_else)]
// Slightly different from explicit-mut-annotated -- this won't show an error until borrowck. // Slightly different from explicit-mut-annotated -- this won't show an error until borrowck.
// Should it show a type error instead? // Should it show a type error instead?
fn main() { fn main() {
let Some(n): &mut Option<i32> = &mut &Some(5i32) else { let Some(n): &mut Option<i32> = &mut &Some(5i32) else {
//~^ ERROR cannot borrow data in a `&` reference as mutable //~^ ERROR cannot borrow data in a `&` reference as mutable

View file

@ -1,6 +1,6 @@
// check-pass // check-pass
#![feature(let_else)]
fn main() { fn main() {
let Some(n) = &mut &mut Some(5i32) else { return; }; let Some(n) = &mut &mut Some(5i32) else { return; };

View file

@ -1,6 +1,6 @@
// from rfc2005 test suite // from rfc2005 test suite
#![feature(let_else)]
// Verify the binding mode shifts - only when no `&` are auto-dereferenced is the // Verify the binding mode shifts - only when no `&` are auto-dereferenced is the
// final default binding mode mutable. // final default binding mode mutable.

View file

@ -1,6 +1,6 @@
// from rfc2005 test suite // from rfc2005 test suite
#![feature(let_else)]
pub fn main() { pub fn main() {
let Some(x) = &Some(3) else { let Some(x) = &Some(3) else {

View file

@ -1,6 +1,6 @@
// run-pass // run-pass
// adapted from src/test/ui/binding/if-let.rs // adapted from src/test/ui/binding/if-let.rs
#![feature(let_else)]
#![allow(dead_code)] #![allow(dead_code)]
fn none() -> bool { fn none() -> bool {

View file

@ -1,6 +1,6 @@
// run-rustfix // run-rustfix
#![feature(let_else)]
fn main() { fn main() {
let true = (true && false) else { return }; //~ ERROR a `&&` expression cannot be directly assigned in `let...else` let true = (true && false) else { return }; //~ ERROR a `&&` expression cannot be directly assigned in `let...else`

View file

@ -1,6 +1,6 @@
// run-rustfix // run-rustfix
#![feature(let_else)]
fn main() { fn main() {
let true = true && false else { return }; //~ ERROR a `&&` expression cannot be directly assigned in `let...else` let true = true && false else { return }; //~ ERROR a `&&` expression cannot be directly assigned in `let...else`

View file

@ -1,6 +1,6 @@
// run-rustfix // run-rustfix
#![feature(let_else)]
fn main() { fn main() {
let Some(1) = ({ Some(1) }) else { let Some(1) = ({ Some(1) }) else {

View file

@ -1,6 +1,6 @@
// run-rustfix // run-rustfix
#![feature(let_else)]
fn main() { fn main() {
let Some(1) = { Some(1) } else { let Some(1) = { Some(1) } else {

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
#![deny(unused_variables)] #![deny(unused_variables)]
fn main() { fn main() {

View file

@ -1,17 +1,17 @@
error: unused variable: `x` error: unused variable: `x`
--> $DIR/let-else-check.rs:14:13 --> $DIR/let-else-check.rs:12:13
| |
LL | let x = 1; LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/let-else-check.rs:3:9 --> $DIR/let-else-check.rs:1:9
| |
LL | #![deny(unused_variables)] LL | #![deny(unused_variables)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: unused variable: `x` error: unused variable: `x`
--> $DIR/let-else-check.rs:18:9 --> $DIR/let-else-check.rs:16:9
| |
LL | let x = 1; LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ^ help: if this is intentional, prefix it with an underscore: `_x`

View file

@ -6,7 +6,7 @@
// Deref/DerefMut to Bar. You can do this with an irrefutable binding, so it should work with // Deref/DerefMut to Bar. You can do this with an irrefutable binding, so it should work with
// let-else too. // let-else too.
#![feature(let_else)]
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
struct Foo(Bar); struct Foo(Bar);

View file

@ -3,7 +3,7 @@
// We attempt to `let Bar::Present(_) = foo else { ... }` where foo is meant to Deref/DerefMut to // We attempt to `let Bar::Present(_) = foo else { ... }` where foo is meant to Deref/DerefMut to
// Bar. This fails, you must add a type annotation like `let _: &mut Bar = _ else { ... }` // Bar. This fails, you must add a type annotation like `let _: &mut Bar = _ else { ... }`
#![feature(let_else)]
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
struct Foo(Bar); struct Foo(Bar);

View file

@ -1,4 +1,3 @@
#![feature(let_else)]
#[derive(Debug)] #[derive(Debug)]
enum Foo { enum Foo {
Done, Done,

View file

@ -1,11 +1,11 @@
error: <assignment> ... else { ... } is not allowed error: <assignment> ... else { ... } is not allowed
--> $DIR/let-else-destructuring.rs:11:9 --> $DIR/let-else-destructuring.rs:10:9
| |
LL | &Foo::Nested(Some(value)) = value else { break }; LL | &Foo::Nested(Some(value)) = value else { break };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0070]: invalid left-hand side of assignment error[E0070]: invalid left-hand side of assignment
--> $DIR/let-else-destructuring.rs:11:35 --> $DIR/let-else-destructuring.rs:10:35
| |
LL | &Foo::Nested(Some(value)) = value else { break }; LL | &Foo::Nested(Some(value)) = value else { break };
| ------------------------- ^ | ------------------------- ^

View file

@ -16,7 +16,7 @@
// This is important as it's easy to update the stdout file // This is important as it's easy to update the stdout file
// with a --bless and miss the impact of that change. // with a --bless and miss the impact of that change.
#![feature(let_else)]
#![allow(irrefutable_let_patterns)] #![allow(irrefutable_let_patterns)]
use std::cell::RefCell; use std::cell::RefCell;

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
fn main() { fn main() {
let Some(_) = Some(()) else if true { let Some(_) = Some(()) else if true {
//~^ ERROR conditional `else if` is not supported for `let...else` //~^ ERROR conditional `else if` is not supported for `let...else`

View file

@ -1,5 +1,5 @@
error: conditional `else if` is not supported for `let...else` error: conditional `else if` is not supported for `let...else`
--> $DIR/let-else-if.rs:4:33 --> $DIR/let-else-if.rs:2:33
| |
LL | let Some(_) = Some(()) else if true { LL | let Some(_) = Some(()) else if true {
| ^^ expected `{` | ^^ expected `{`

View file

@ -1,6 +1,6 @@
// check-pass // check-pass
#![feature(let_else)]
fn main() { fn main() {
let x = 1 else { return }; //~ WARN irrefutable `let...else` pattern let x = 1 else { return }; //~ WARN irrefutable `let...else` pattern

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
fn main() { fn main() {
let Some(x) = Some(1) else { let Some(x) = Some(1) else {
return; return;

View file

@ -1,5 +1,5 @@
error: expected `;`, found keyword `let` error: expected `;`, found keyword `let`
--> $DIR/let-else-missing-semicolon.rs:6:6 --> $DIR/let-else-missing-semicolon.rs:4:6
| |
LL | } LL | }
| ^ help: add `;` here | ^ help: add `;` here
@ -7,7 +7,7 @@ LL | let _ = "";
| --- unexpected token | --- unexpected token
error: expected `;`, found `}` error: expected `;`, found `}`
--> $DIR/let-else-missing-semicolon.rs:10:6 --> $DIR/let-else-missing-semicolon.rs:8:6
| |
LL | } LL | }
| ^ help: add `;` here | ^ help: add `;` here

View file

@ -1,6 +1,6 @@
// from rfc2005 test suite // from rfc2005 test suite
#![feature(let_else)]
// Without caching type lookups in FnCtxt.resolve_ty_and_def_ufcs // Without caching type lookups in FnCtxt.resolve_ty_and_def_ufcs
// the error below would be reported twice (once when checking // the error below would be reported twice (once when checking

View file

@ -10,7 +10,7 @@
// //
// The move was due to mir::Place being Copy, but mir::VarDebugInfoContents not being Copy. // The move was due to mir::Place being Copy, but mir::VarDebugInfoContents not being Copy.
#![feature(let_else)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct Copyable; struct Copyable;

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
fn main() { fn main() {
let Some(x) = Some(1) else { //~ ERROR does not diverge let Some(x) = Some(1) else { //~ ERROR does not diverge
Some(2) Some(2)

View file

@ -1,5 +1,5 @@
error[E0308]: `else` clause of `let...else` does not diverge error[E0308]: `else` clause of `let...else` does not diverge
--> $DIR/let-else-non-diverging.rs:4:32 --> $DIR/let-else-non-diverging.rs:2:32
| |
LL | let Some(x) = Some(1) else { LL | let Some(x) = Some(1) else {
| ________________________________^ | ________________________________^
@ -13,7 +13,7 @@ LL | | };
= help: ...or use `match` instead of `let...else` = help: ...or use `match` instead of `let...else`
error[E0308]: `else` clause of `let...else` does not diverge error[E0308]: `else` clause of `let...else` does not diverge
--> $DIR/let-else-non-diverging.rs:7:32 --> $DIR/let-else-non-diverging.rs:5:32
| |
LL | let Some(x) = Some(1) else { LL | let Some(x) = Some(1) else {
| ________________________________^ | ________________________________^
@ -29,7 +29,7 @@ LL | | };
= help: ...or use `match` instead of `let...else` = help: ...or use `match` instead of `let...else`
error[E0308]: `else` clause of `let...else` does not diverge error[E0308]: `else` clause of `let...else` does not diverge
--> $DIR/let-else-non-diverging.rs:12:32 --> $DIR/let-else-non-diverging.rs:10:32
| |
LL | let Some(x) = Some(1) else { Some(2) }; LL | let Some(x) = Some(1) else { Some(2) };
| ^^^^^^^^^^^ expected `!`, found enum `Option` | ^^^^^^^^^^^ expected `!`, found enum `Option`

View file

@ -1,6 +1,6 @@
// check-pass // check-pass
#![feature(let_else)]
#![allow(unused_variables)] #![allow(unused_variables)]
fn ref_() { fn ref_() {

View file

@ -1,6 +1,6 @@
#![feature(let_else)]
#![allow(unused_variables)] #![allow(unused_variables)]
fn ref_() { fn ref_() {
let bytes: Vec<u8> = b"Hello"[..].to_vec(); let bytes: Vec<u8> = b"Hello"[..].to_vec();
let some = Some(bytes); let some = Some(bytes);

View file

@ -1,6 +1,6 @@
// run-pass // run-pass
#![feature(let_else)]
fn main() { fn main() {
#[allow(dead_code)] #[allow(dead_code)]

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
fn main() { fn main() {
let Some(x) = Some(2) else { let Some(x) = Some(2) else {
panic!("{}", x); //~ ERROR cannot find value `x` in this scope panic!("{}", x); //~ ERROR cannot find value `x` in this scope

View file

@ -1,5 +1,5 @@
error[E0425]: cannot find value `x` in this scope error[E0425]: cannot find value `x` in this scope
--> $DIR/let-else-scope.rs:5:22 --> $DIR/let-else-scope.rs:3:22
| |
LL | panic!("{}", x); LL | panic!("{}", x);
| ^ not found in this scope | ^ not found in this scope

View file

@ -1,5 +1,5 @@
// issue #92069 // issue #92069
#![feature(let_else)]
fn main() { fn main() {
let nums = vec![5, 4, 3, 2, 1]; let nums = vec![5, 4, 3, 2, 1];

View file

@ -1,7 +1,7 @@
// run-pass // run-pass
// issue #89688 // issue #89688
#![feature(let_else)]
fn example_let_else(value: Option<String>) { fn example_let_else(value: Option<String>) {
let Some(inner) = value else { let Some(inner) = value else {

View file

@ -3,7 +3,7 @@
// from issue #93951, where borrowck complained the temporary that `foo(&x)` was stored in was to // from issue #93951, where borrowck complained the temporary that `foo(&x)` was stored in was to
// be dropped sometime after `x` was. It then suggested adding a semicolon that was already there. // be dropped sometime after `x` was. It then suggested adding a semicolon that was already there.
#![feature(let_else)]
use std::fmt::Debug; use std::fmt::Debug;
fn foo<'a>(x: &'a str) -> Result<impl Debug + 'a, ()> { fn foo<'a>(x: &'a str) -> Result<impl Debug + 'a, ()> {

View file

@ -1,6 +1,5 @@
// run-pass // run-pass
// compile-flags: -Zvalidate-mir // compile-flags: -Zvalidate-mir
#![feature(let_else)]
use std::fmt::Display; use std::fmt::Display;
use std::rc::Rc; use std::rc::Rc;

View file

@ -2,7 +2,7 @@
// popped up in in #94012, where an alternative desugaring was // popped up in in #94012, where an alternative desugaring was
// causing unreachable code errors // causing unreachable code errors
#![feature(let_else)]
#![deny(unused_variables)] #![deny(unused_variables)]
#![deny(unreachable_code)] #![deny(unreachable_code)]

View file

@ -0,0 +1,8 @@
// run-pass
fn main() {
let Some(x) = Some(1) else {
return;
};
assert_eq!(x, 1);
}

View file

@ -21,7 +21,7 @@ help: you might want to use `if let` to ignore the variants that aren't matched
| |
LL | let y = if let Thing::Foo(y) = Thing::Foo(1) { y } else { todo!() }; LL | let y = if let Thing::Foo(y) = Thing::Foo(1) { y } else { todo!() };
| ++++++++++ ++++++++++++++++++++++ | ++++++++++ ++++++++++++++++++++++
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched help: alternatively, you might want to use let else to handle the variants that aren't matched
| |
LL | let Thing::Foo(y) = Thing::Foo(1) else { todo!() }; LL | let Thing::Foo(y) = Thing::Foo(1) else { todo!() };
| ++++++++++++++++ | ++++++++++++++++

View file

@ -187,7 +187,7 @@ help: you might want to use `if let` to ignore the variant that isn't matched
| |
LL | let _x = if let Opt::Some(ref _x) = e { _x } else { todo!() }; LL | let _x = if let Opt::Some(ref _x) = e { _x } else { todo!() };
| +++++++++++ +++++++++++++++++++++++ | +++++++++++ +++++++++++++++++++++++
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variant that isn't matched help: alternatively, you might want to use let else to handle the variant that isn't matched
| |
LL | let Opt::Some(ref _x) = e else { todo!() }; LL | let Opt::Some(ref _x) = e else { todo!() };
| ++++++++++++++++ | ++++++++++++++++

View file

@ -1,5 +1,3 @@
#![feature(let_else)]
#![deny(unreachable_patterns)] #![deny(unreachable_patterns)]
fn main() { fn main() {

View file

@ -1,71 +1,71 @@
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:6:23 --> $DIR/top-level-alternation.rs:4:23
| |
LL | while let 0..=2 | 1 = 0 {} LL | while let 0..=2 | 1 = 0 {}
| ^ | ^
| |
note: the lint level is defined here note: the lint level is defined here
--> $DIR/top-level-alternation.rs:3:9 --> $DIR/top-level-alternation.rs:1:9
| |
LL | #![deny(unreachable_patterns)] LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:7:20 --> $DIR/top-level-alternation.rs:5:20
| |
LL | if let 0..=2 | 1 = 0 {} LL | if let 0..=2 | 1 = 0 {}
| ^ | ^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:11:15 --> $DIR/top-level-alternation.rs:9:15
| |
LL | | 0 => {} LL | | 0 => {}
| ^ | ^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:16:15 --> $DIR/top-level-alternation.rs:14:15
| |
LL | | Some(0) => {} LL | | Some(0) => {}
| ^^^^^^^ | ^^^^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:21:9 --> $DIR/top-level-alternation.rs:19:9
| |
LL | (0, 0) => {} LL | (0, 0) => {}
| ^^^^^^ | ^^^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:41:9 --> $DIR/top-level-alternation.rs:39:9
| |
LL | _ => {} LL | _ => {}
| ^ | ^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:45:9 --> $DIR/top-level-alternation.rs:43:9
| |
LL | Some(_) => {} LL | Some(_) => {}
| ^^^^^^^ | ^^^^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:46:9 --> $DIR/top-level-alternation.rs:44:9
| |
LL | None => {} LL | None => {}
| ^^^^ | ^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:51:9 --> $DIR/top-level-alternation.rs:49:9
| |
LL | None | Some(_) => {} LL | None | Some(_) => {}
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:55:9 --> $DIR/top-level-alternation.rs:53:9
| |
LL | 1..=2 => {}, LL | 1..=2 => {},
| ^^^^^ | ^^^^^
error: unreachable pattern error: unreachable pattern
--> $DIR/top-level-alternation.rs:58:14 --> $DIR/top-level-alternation.rs:56:14
| |
LL | let (0 | 0) = 0 else { return }; LL | let (0 | 0) = 0 else { return };
| ^ | ^

Some files were not shown because too many files have changed in this diff Show more