Skip to content

Commit 73c5ade

Browse files
committed
Add note about semantic difference between x[x.len() - 1] and x.last()
1 parent 5f7a9be commit 73c5ade

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

clippy_lints/src/use_last.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use if_chain::if_chain;
1111
///
1212
/// **Why is this bad?** Using `x.last()` is easier to read and has the same result.
1313
///
14+
/// Note that using x[x.len() - 1] is semantically different from x.last(),
15+
/// since indexing into the array will panic on out-of-bounds accesses, while
16+
/// x.get() and x.last() will return None.
17+
///
1418
/// **Known problems:** None.
1519
///
1620
/// **Example:**

0 commit comments

Comments
 (0)