Skip to content

Commit b3d3251

Browse files
authored
Rollup merge of #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 #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

+1-1
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

+1-1
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

+5-5
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

+3-3
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+8-8
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

+8-8
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 {

src/test/ui/issues/issue-19991.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Test if the sugared if-let construct correctly prints "missing an else clause" when an else
1+
// Test if the sugared `if let` construct correctly prints "missing an else clause" when an else
22
// clause does not exist, instead of the unsympathetic "`match` arms have incompatible types"
33

44
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![deny(irrefutable_let_patterns)]
22

33
fn main() {
4-
if let _ = 5 {} //~ ERROR irrefutable if-let pattern
4+
if let _ = 5 {} //~ ERROR irrefutable `if let` pattern
55

6-
while let _ = 5 { //~ ERROR irrefutable while-let pattern
6+
while let _ = 5 { //~ ERROR irrefutable `while let` pattern
77
break;
88
}
99
}

src/test/ui/pattern/usefulness/deny-irrefutable-let-patterns.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: irrefutable if-let pattern
1+
error: irrefutable `if let` pattern
22
--> $DIR/deny-irrefutable-let-patterns.rs:4:5
33
|
44
LL | if let _ = 5 {}
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(irrefutable_let_patterns)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: irrefutable while-let pattern
13+
error: irrefutable `while let` pattern
1414
--> $DIR/deny-irrefutable-let-patterns.rs:6:5
1515
|
1616
LL | / while let _ = 5 {

src/test/ui/rfc-2294-if-let-guard/warns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fn irrefutable_let_guard() {
66
match Some(()) {
77
Some(x) if let () = x => {}
8-
//~^ ERROR irrefutable if-let guard
8+
//~^ ERROR irrefutable `if let` guard
99
_ => {}
1010
}
1111
}

src/test/ui/rfc-2294-if-let-guard/warns.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: irrefutable if-let guard
1+
error: irrefutable `if let` guard
22
--> $DIR/warns.rs:7:24
33
|
44
LL | Some(x) if let () = x => {}

src/test/ui/while-let.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ fn macros() {
55
macro_rules! foo{
66
($p:pat, $e:expr, $b:block) => {{
77
while let $p = $e $b
8-
//~^ WARN irrefutable while-let
9-
//~| WARN irrefutable while-let
8+
//~^ WARN irrefutable `while let`
9+
//~| WARN irrefutable `while let`
1010
}}
1111
}
1212
macro_rules! bar{
@@ -24,7 +24,7 @@ fn macros() {
2424
}
2525

2626
pub fn main() {
27-
while let _a = 1 { //~ WARN irrefutable while-let
27+
while let _a = 1 { //~ WARN irrefutable `while let`
2828
println!("irrefutable pattern");
2929
break;
3030
}

src/test/ui/while-let.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: irrefutable while-let pattern
1+
warning: irrefutable `while let` pattern
22
--> $DIR/while-let.rs:7:13
33
|
44
LL | while 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 while-let pattern
15+
warning: irrefutable `while let` pattern
1616
--> $DIR/while-let.rs:7:13
1717
|
1818
LL | while let $p = $e $b
@@ -25,7 +25,7 @@ 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 while-let pattern
28+
warning: irrefutable `while let` pattern
2929
--> $DIR/while-let.rs:27:5
3030
|
3131
LL | / while let _a = 1 {

src/tools/clippy/clippy_lints/src/loops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ declare_clippy_lint! {
340340
/// ```
341341
pub WHILE_LET_ON_ITERATOR,
342342
style,
343-
"using a while-let loop instead of a for loop on an iterator"
343+
"using a `while let` loop instead of a for loop on an iterator"
344344
}
345345

346346
declare_clippy_lint! {

0 commit comments

Comments
 (0)