Skip to content

Commit

Permalink
Automatic deploy to GitHub Pages: bfb87b9
Browse files Browse the repository at this point in the history
  • Loading branch information
GHA CI committed Dec 14, 2024
1 parent f319573 commit 476baeb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions master/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4450,35 +4450,40 @@ <h3>Configuration</h3>
</li>
</ul>
</div><div class="lint-additional-info-container"><div class="lint-additional-info-item"><span> Applicability: </span><span class="label label-default label-applicability">MaybeIncorrect</span><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.Applicability.html#variants">(?)</a></div><div class="lint-additional-info-item"><span>Added in: </span><span class="label label-default label-version">1.59.0</span></div><div class="lint-additional-info-item"><a href="https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+index_refutable_slice">Related Issues</a></div><div class="lint-additional-info-item"><a href="https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/index_refutable_slice.rs#L20">View Source</a></div></div></div></article><article class="panel panel-default" id="indexing_slicing"><input id="label-indexing_slicing" type="checkbox"><label for="label-indexing_slicing" onclick="highlightIfNeeded('indexing_slicing')"><header class="panel-heading"><h2 class="panel-title"><div class="panel-title-name" id="lint-indexing_slicing"><span>indexing_slicing</span> <a href="#indexing_slicing" onclick="lintAnchor(event)" class="anchor label label-default">&para;</a> <a href="" class="anchor label label-default" onclick="copyToClipboard(event)">&#128203;</a></div><div class="panel-title-addons"><span class="label label-lint-group label-default label-group-restriction">restriction</span> <span class="label label-lint-level label-lint-level-allow">allow</span> <span class="label label-doc-folding"></span></div></h2></header></label><div class="list-group lint-docs"><div class="list-group-item lint-doc-md"><h3>What it does</h3>
<p>Checks for usage of indexing or slicing. Arrays are special cases, this lint
does report on arrays if we can tell that slicing operations are in bounds and does not
lint on constant <code>usize</code> indexing on arrays because that is handled by rustc’s <code>const_err</code> lint.</p>
<p>Checks for usage of indexing or slicing that may panic at runtime.</p>
<p>This lint does not report on indexing or slicing operations
that always panic, clippy’s <code>out_of_bound_indexing</code> already
handles those cases.</p>
<h3>Why restrict this?</h3>
<p>To avoid implicit panics from indexing and slicing.
There are “checked” alternatives which do not panic, and can be used with <code>unwrap()</code> to make
<p>To avoid implicit panics from indexing and slicing.</p>
<p>There are “checked” alternatives which do not panic, and can be used with <code>unwrap()</code> to make
an explicit panic when it is desired.</p>
<h3>Limitations</h3>
<p>This lint does not check for the usage of indexing or slicing on strings. These are covered
by the more specific <code>string_slice</code> lint.</p>
<h3>Example</h3>
<pre><code class="language-rust">// Vector
let x = vec![0; 5];
let x = vec![0, 1, 2, 3];

x[2];
x[100];
&amp;x[2..100];

// Array
let y = [0, 1, 2, 3];

&amp;y[10..100];
&amp;y[10..];
let i = 10; // Could be a runtime value
let j = 20;
&amp;y[i..j];
</code></pre>
<p>Use instead:</p>
<pre><code class="language-rust">x.get(2);
x.get(100);
x.get(2..100);

y.get(10);
y.get(10..100);
let i = 10;
let j = 20;
y.get(i..j);
</code></pre>
<h3>Configuration</h3>
<ul>
Expand Down

0 comments on commit 476baeb

Please sign in to comment.