Skip to content

Commit

Permalink
Fix more code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibsG committed May 31, 2020
1 parent 38a93c7 commit 6d2dcca
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 21 deletions.
15 changes: 13 additions & 2 deletions clippy_lints/src/fallible_impl_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// struct Foo(i32);
///
/// // Bad
/// impl From<String> for Foo {
/// fn from(s: String) -> Self {
/// Foo(s.parse().unwrap())
/// }
/// }
///
/// // Good
/// use std::convert::TryFrom;
/// impl TryFrom<String> for Foo {
/// type Error = ();
/// fn try_from(s: String) -> Result<Self, Self::Error> {
/// s.parse()
/// }
/// }
/// ```
pub FALLIBLE_IMPL_FROM,
nursery,
Expand Down Expand Up @@ -120,7 +131,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
move |diag| {
diag.help(
"`From` is intended for infallible conversions only. \
Use `TryFrom` if there's a possibility for the conversion to fail.");
Use `TryFrom` if there's a possibility for the conversion to fail.");
diag.span_note(fpu.result, "potential failure(s)");
});
}
Expand Down
2 changes: 0 additions & 2 deletions clippy_lints/src/floating_point_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ declare_clippy_lint! {
/// **Example:**
///
/// ```rust
///
/// let a = 3f32;
/// let _ = a.powf(1.0 / 3.0);
/// let _ = (1.0 + a).ln();
Expand All @@ -38,7 +37,6 @@ declare_clippy_lint! {
/// is better expressed as
///
/// ```rust
///
/// let a = 3f32;
/// let _ = a.cbrt();
/// let _ = a.ln_1p();
Expand Down
6 changes: 5 additions & 1 deletion clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ declare_clippy_lint! {
///
/// **Examples:**
/// ```rust
///
/// // Bad
/// # let foo = "foo";
/// format!("foo");
/// format!("{}", foo);
///
/// // Good
/// format!("foo");
/// ```
pub USELESS_FORMAT,
complexity,
Expand Down
14 changes: 10 additions & 4 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ declare_clippy_lint! {
/// **Known problems:** None.
///
/// **Example:**
/// ``` rust
/// ```rust
/// fn im_too_long() {
/// println!("");
/// println!("");
/// // ... 100 more LoC
/// println!("");
/// println!("");
/// }
/// ```
pub TOO_MANY_LINES,
Expand All @@ -79,10 +79,16 @@ declare_clippy_lint! {
/// `some_argument.get_raw_ptr()`).
///
/// **Example:**
/// ```rust
/// ```rust,ignore
/// // Bad
/// pub fn foo(x: *const u8) {
/// println!("{}", unsafe { *x });
/// }
///
/// // Good
/// pub unsafe fn foo(x: *const u8) {
/// println!("{}", unsafe { *x });
/// }
/// ```
pub NOT_UNSAFE_PTR_ARG_DEREF,
correctness,
Expand Down
7 changes: 0 additions & 7 deletions clippy_lints/src/implicit_saturating_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ declare_clippy_lint! {
/// if i != 0 {
/// i -= 1;
/// }
/// ```
/// Use instead:
/// ```rust
/// let end: u32 = 10;
/// let start: u32 = 5;
///
/// let mut i: u32 = end - start;
///
/// // Good
/// i = i.saturating_sub(1);
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/int_plus_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::utils::{snippet_opt, span_lint_and_sugg};
declare_clippy_lint! {
/// **What it does:** Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block
///
///
/// **Why is this bad?** Readability -- better to use `> y` instead of `>= y + 1`.
///
/// **Known problems:** None.
Expand Down
11 changes: 7 additions & 4 deletions clippy_lints/src/integer_division.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// fn main() {
/// let x = 3 / 2;
/// println!("{}", x);
/// }
/// // Bad
/// let x = 3 / 2;
/// println!("{}", x);
///
/// // Good
/// let x = 3f32 / 2f32;
/// println!("{}", x);
/// ```
pub INTEGER_DIVISION,
restriction,
Expand Down
16 changes: 16 additions & 0 deletions clippy_lints/src/items_after_statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare_clippy_lint! {
///
/// **Example:**
/// ```rust
/// // Bad
/// fn foo() {
/// println!("cake");
/// }
Expand All @@ -28,6 +29,21 @@ declare_clippy_lint! {
/// foo(); // prints "foo"
/// }
/// ```
///
/// ```rust
/// // Good
/// fn foo() {
/// println!("cake");
/// }
///
/// fn main() {
/// fn foo() {
/// println!("foo");
/// }
/// foo(); // prints "foo"
/// foo(); // prints "foo"
/// }
/// ```
pub ITEMS_AFTER_STATEMENTS,
pedantic,
"blocks where an item comes after a statement"
Expand Down

0 comments on commit 6d2dcca

Please sign in to comment.