Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b3d3251

Browse files
authored
Rollup merge of rust-lang#82215 - TaKO8Ki:replace-if-let-while-let, r=varkor
Replace if-let and while-let with `if let` and `while let` This pull request replaces if-let and while-let with `if let` and `while let`. closes rust-lang#82205
2 parents f01b339 + 0f04875 commit b3d3251

File tree

18 files changed

+45
-45
lines changed

18 files changed

+45
-45
lines changed

compiler/rustc_error_codes/src/error_codes/E0162.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#### Note: this error code is no longer emitted by the compiler.
22

3-
An if-let pattern attempts to match the pattern, and enters the body if the
3+
An `if let` pattern attempts to match the pattern, and enters the body if the
44
match was successful. If the match is irrefutable (when it cannot fail to
55
match), use a regular `let`-binding instead. For instance:
66

compiler/rustc_error_codes/src/error_codes/E0165.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#### Note: this error code is no longer emitted by the compiler.
22

3-
A while-let pattern attempts to match the pattern, and enters the body if the
3+
A `while let` pattern attempts to match the pattern, and enters the body if the
44
match was successful. If the match is irrefutable (when it cannot fail to
55
match), use a regular `let`-binding inside a `loop` instead. For instance:
66

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ declare_lint! {
18151815

18161816
declare_lint! {
18171817
/// The `irrefutable_let_patterns` lint detects detects [irrefutable
1818-
/// patterns] in [if-let] and [while-let] statements.
1818+
/// patterns] in [`if let`] and [`while let`] statements.
18191819
///
18201820
///
18211821
///
@@ -1832,7 +1832,7 @@ declare_lint! {
18321832
/// ### Explanation
18331833
///
18341834
/// There usually isn't a reason to have an irrefutable pattern in an
1835-
/// if-let or while-let statement, because the pattern will always match
1835+
/// `if let` or `while let` statement, because the pattern will always match
18361836
/// successfully. A [`let`] or [`loop`] statement will suffice. However,
18371837
/// when generating code with a macro, forbidding irrefutable patterns
18381838
/// would require awkward workarounds in situations where the macro
@@ -1843,14 +1843,14 @@ declare_lint! {
18431843
/// See [RFC 2086] for more details.
18441844
///
18451845
/// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1846-
/// [if-let]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1847-
/// [while-let]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1846+
/// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1847+
/// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
18481848
/// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
18491849
/// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
18501850
/// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
18511851
pub IRREFUTABLE_LET_PATTERNS,
18521852
Warn,
1853-
"detects irrefutable patterns in if-let and while-let statements"
1853+
"detects irrefutable patterns in `if let` and `while let` statements"
18541854
}
18551855

18561856
declare_lint! {

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ fn unreachable_pattern(tcx: TyCtxt<'_>, span: Span, id: HirId, catchall: Option<
368368
fn irrefutable_let_pattern(tcx: TyCtxt<'_>, span: Span, id: HirId, source: hir::MatchSource) {
369369
tcx.struct_span_lint_hir(IRREFUTABLE_LET_PATTERNS, id, span, |lint| {
370370
let msg = match source {
371-
hir::MatchSource::IfLetDesugar { .. } => "irrefutable if-let pattern",
372-
hir::MatchSource::WhileLetDesugar => "irrefutable while-let pattern",
373-
hir::MatchSource::IfLetGuardDesugar => "irrefutable if-let guard",
371+
hir::MatchSource::IfLetDesugar { .. } => "irrefutable `if let` pattern",
372+
hir::MatchSource::WhileLetDesugar => "irrefutable `while let` pattern",
373+
hir::MatchSource::IfLetGuardDesugar => "irrefutable `if let` guard",
374374
_ => bug!(),
375375
};
376376
lint.build(msg).emit()

compiler/rustc_passes/src/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl NonConstExpr {
4545
return None;
4646
}
4747

48-
Self::Match(IfLetGuardDesugar) => bug!("if-let guard outside a `match` expression"),
48+
Self::Match(IfLetGuardDesugar) => bug!("`if let` guard outside a `match` expression"),
4949

5050
// All other expressions are allowed.
5151
Self::Loop(Loop | While | WhileLet)

src/test/ui/binding/if-let.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn main() {
66
if let Some(y) = x {
77
assert_eq!(y, 3);
88
} else {
9-
panic!("if-let panicked");
9+
panic!("`if let` panicked");
1010
}
1111
let mut worked = false;
1212
if let Some(_) = x {
@@ -54,7 +54,7 @@ pub fn main() {
5454
if let Foo::Two(b) = a {
5555
assert_eq!(b, 42_usize);
5656
} else {
57-
panic!("panic in nested if-let");
57+
panic!("panic in nested `if let`");
5858
}
5959
}
6060
}

src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// FIXME(project-rfc-2229#24): Change this to be a destructure pattern
1717
// once this is fixed, to remove the warning.
1818
if let SingleVariant::Point(ref mut x, _) = point {
19-
//~^ WARNING: irrefutable if-let pattern
19+
//~^ WARNING: irrefutable `if let` pattern
2020
*x += 1;
2121
}
2222
};

src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-single-variant-diagnostics.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #![feature(capture_disjoint_fields)]
77
= note: `#[warn(incomplete_features)]` on by default
88
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
99

10-
warning: irrefutable if-let pattern
10+
warning: irrefutable `if let` pattern
1111
--> $DIR/closure-origin-single-variant-diagnostics.rs:18:9
1212
|
1313
LL | / if let SingleVariant::Point(ref mut x, _) = point {

src/test/ui/expr/if/if-let.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ fn macros() {
44
macro_rules! foo{
55
($p:pat, $e:expr, $b:block) => {{
66
if let $p = $e $b
7-
//~^ WARN irrefutable if-let
8-
//~| WARN irrefutable if-let
7+
//~^ WARN irrefutable `if let`
8+
//~| WARN irrefutable `if let`
99
}}
1010
}
1111
macro_rules! bar{
@@ -23,27 +23,27 @@ fn macros() {
2323
}
2424

2525
pub fn main() {
26-
if let a = 1 { //~ WARN irrefutable if-let
26+
if let a = 1 { //~ WARN irrefutable `if let`
2727
println!("irrefutable pattern");
2828
}
2929

30-
if let a = 1 { //~ WARN irrefutable if-let
30+
if let a = 1 { //~ WARN irrefutable `if let`
3131
println!("irrefutable pattern");
3232
} else if true {
33-
println!("else-if in irrefutable if-let");
33+
println!("else-if in irrefutable `if let`");
3434
} else {
35-
println!("else in irrefutable if-let");
35+
println!("else in irrefutable `if let`");
3636
}
3737

3838
if let 1 = 2 {
3939
println!("refutable pattern");
40-
} else if let a = 1 { //~ WARN irrefutable if-let
40+
} else if let a = 1 { //~ WARN irrefutable `if let`
4141
println!("irrefutable pattern");
4242
}
4343

4444
if true {
4545
println!("if");
46-
} else if let a = 1 { //~ WARN irrefutable if-let
46+
} else if let a = 1 { //~ WARN irrefutable `if let`
4747
println!("irrefutable pattern");
4848
}
4949
}

src/test/ui/expr/if/if-let.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: irrefutable if-let pattern
1+
warning: irrefutable `if let` pattern
22
--> $DIR/if-let.rs:6:13
33
|
44
LL | if let $p = $e $b
@@ -12,7 +12,7 @@ LL | | });
1212
= note: `#[warn(irrefutable_let_patterns)]` on by default
1313
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1414

15-
warning: irrefutable if-let pattern
15+
warning: irrefutable `if let` pattern
1616
--> $DIR/if-let.rs:6:13
1717
|
1818
LL | if let $p = $e $b
@@ -25,27 +25,27 @@ LL | | });
2525
|
2626
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
2727

28-
warning: irrefutable if-let pattern
28+
warning: irrefutable `if let` pattern
2929
--> $DIR/if-let.rs:26:5
3030
|
3131
LL | / if let a = 1 {
3232
LL | | println!("irrefutable pattern");
3333
LL | | }
3434
| |_____^
3535

36-
warning: irrefutable if-let pattern
36+
warning: irrefutable `if let` pattern
3737
--> $DIR/if-let.rs:30:5
3838
|
3939
LL | / if let a = 1 {
4040
LL | | println!("irrefutable pattern");
4141
LL | | } else if true {
42-
LL | | println!("else-if in irrefutable if-let");
42+
LL | | println!("else-if in irrefutable `if let`");
4343
LL | | } else {
44-
LL | | println!("else in irrefutable if-let");
44+
LL | | println!("else in irrefutable `if let`");
4545
LL | | }
4646
| |_____^
4747

48-
warning: irrefutable if-let pattern
48+
warning: irrefutable `if let` pattern
4949
--> $DIR/if-let.rs:40:12
5050
|
5151
LL | } else if let a = 1 {
@@ -54,7 +54,7 @@ LL | | println!("irrefutable pattern");
5454
LL | | }
5555
| |_____^
5656

57-
warning: irrefutable if-let pattern
57+
warning: irrefutable `if let` pattern
5858
--> $DIR/if-let.rs:46:12
5959
|
6060
LL | } else if let a = 1 {

0 commit comments

Comments
 (0)