Skip to content

Commit 93c3da2

Browse files
authored
Rollup merge of #4331 - phansch:doctests_restriction, r=flip1995
Doctests: Enable running doc tests for restriction lints changelog: Enabled remaining doc tests for lint documentation page master: 202 passed; 0 failed; 122 ignored; 0 measured; 0 filtered out this PR: 231 passed; 0 failed; 123 ignored; 0 measured; 0 filtered out Closes #4319 (assuming this is merged after #4329 and #4330)
2 parents f5db24a + b608e02 commit 93c3da2

File tree

12 files changed

+57
-16
lines changed

12 files changed

+57
-16
lines changed

clippy_lints/src/arithmetic.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ declare_clippy_lint! {
1616
///
1717
/// **Example:**
1818
/// ```rust
19-
/// a + 1
19+
/// # let a = 0;
20+
/// a + 1;
2021
/// ```
2122
pub INTEGER_ARITHMETIC,
2223
restriction,
@@ -33,7 +34,8 @@ declare_clippy_lint! {
3334
///
3435
/// **Example:**
3536
/// ```rust
36-
/// a + 1.0
37+
/// # let a = 0.0;
38+
/// a + 1.0;
3739
/// ```
3840
pub FLOAT_ARITHMETIC,
3941
restriction,

clippy_lints/src/else_if_without_else.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ declare_clippy_lint! {
1616
///
1717
/// **Example:**
1818
/// ```rust
19+
/// # fn a() {}
20+
/// # fn b() {}
21+
/// # let x: i32 = 1;
1922
/// if x.is_positive() {
2023
/// a();
2124
/// } else if x.is_negative() {
@@ -26,6 +29,9 @@ declare_clippy_lint! {
2629
/// Could be written:
2730
///
2831
/// ```rust
32+
/// # fn a() {}
33+
/// # fn b() {}
34+
/// # let x: i32 = 1;
2935
/// if x.is_positive() {
3036
/// a();
3137
/// } else if x.is_negative() {

clippy_lints/src/indexing_slicing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ declare_clippy_lint! {
4747
/// **Known problems:** Hopefully none.
4848
///
4949
/// **Example:**
50-
/// ```rust
50+
/// ```rust,no_run
5151
/// // Vector
5252
/// let x = vec![0; 5];
5353
///

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ macro_rules! declare_clippy_lint {
115115
};
116116
{ $(#[$attr:meta])* pub $name:tt, restriction, $description:tt } => {
117117
declare_tool_lint! {
118-
pub clippy::$name, Allow, $description, report_in_external_macro: true
118+
$(#[$attr])* pub clippy::$name, Allow, $description, report_in_external_macro: true
119119
}
120120
};
121121
{ $(#[$attr:meta])* pub $name:tt, cargo, $description:tt } => {

clippy_lints/src/matches.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ declare_clippy_lint! {
211211
///
212212
/// **Example:**
213213
/// ```rust
214+
/// # enum Foo { A(usize), B(usize) }
215+
/// # let x = Foo::B(1);
214216
/// match x {
215217
/// A => {},
216218
/// _ => {},

clippy_lints/src/mem_forget.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ declare_clippy_lint! {
1414
///
1515
/// **Example:**
1616
/// ```rust
17+
/// # use std::mem;
18+
/// # use std::rc::Rc;
1719
/// mem::forget(Rc::new(55))
1820
/// ```
1921
pub MEM_FORGET,

clippy_lints/src/methods/mod.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,19 @@ declare_clippy_lint! {
4040
/// **Known problems:** None.
4141
///
4242
/// **Example:**
43+
///
44+
/// Using unwrap on an `Option`:
45+
///
4346
/// ```rust
44-
/// x.unwrap()
47+
/// let opt = Some(1);
48+
/// opt.unwrap();
49+
/// ```
50+
///
51+
/// Better:
52+
///
53+
/// ```rust
54+
/// let opt = Some(1);
55+
/// opt.expect("more helpful message");
4556
/// ```
4657
pub OPTION_UNWRAP_USED,
4758
restriction,
@@ -62,8 +73,18 @@ declare_clippy_lint! {
6273
/// **Known problems:** None.
6374
///
6475
/// **Example:**
76+
/// Using unwrap on an `Option`:
77+
///
6578
/// ```rust
66-
/// x.unwrap()
79+
/// let res: Result<usize, ()> = Ok(1);
80+
/// res.unwrap();
81+
/// ```
82+
///
83+
/// Better:
84+
///
85+
/// ```rust
86+
/// let res: Result<usize, ()> = Ok(1);
87+
/// res.expect("more helpful message");
6788
/// ```
6889
pub RESULT_UNWRAP_USED,
6990
restriction,
@@ -141,9 +162,10 @@ declare_clippy_lint! {
141162
///
142163
/// **Example:**
143164
/// ```rust
144-
/// impl X {
145-
/// pub fn as_str(self) -> &str {
146-
/// ..
165+
/// # struct X;
166+
/// impl<'a> X {
167+
/// pub fn as_str(self) -> &'a str {
168+
/// "foo"
147169
/// }
148170
/// }
149171
/// ```
@@ -474,7 +496,9 @@ declare_clippy_lint! {
474496
///
475497
/// **Example:**
476498
/// ```rust
477-
/// x.clone()
499+
/// # use std::rc::Rc;
500+
/// let x = Rc::new(1);
501+
/// x.clone();
478502
/// ```
479503
pub CLONE_ON_REF_PTR,
480504
restriction,

clippy_lints/src/misc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ declare_clippy_lint! {
226226
///
227227
/// **Example:**
228228
/// ```rust
229-
/// const ONE = 1.00f64;
230-
/// x == ONE // where both are floats
229+
/// let x: f64 = 1.0;
230+
/// const ONE: f64 = 1.00;
231+
/// x == ONE; // where both are floats
231232
/// ```
232233
pub FLOAT_CMP_CONST,
233234
restriction,

clippy_lints/src/missing_inline.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare_clippy_lint! {
3333
///
3434
/// struct Baz;
3535
/// impl Baz {
36-
/// fn priv() {} // ok
36+
/// fn private() {} // ok
3737
/// }
3838
///
3939
/// impl Bar for Baz {
@@ -42,8 +42,8 @@ declare_clippy_lint! {
4242
///
4343
/// pub struct PubBaz;
4444
/// impl PubBaz {
45-
/// fn priv() {} // ok
46-
/// pub not_ptriv() {} // missing #[inline]
45+
/// fn private() {} // ok
46+
/// pub fn not_ptrivate() {} // missing #[inline]
4747
/// }
4848
///
4949
/// impl Bar for PubBaz {

clippy_lints/src/shadow.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare_clippy_lint! {
2020
///
2121
/// **Example:**
2222
/// ```rust
23+
/// # let x = 1;
2324
/// let x = &x;
2425
/// ```
2526
pub SHADOW_SAME,
@@ -41,10 +42,12 @@ declare_clippy_lint! {
4142
///
4243
/// **Example:**
4344
/// ```rust
45+
/// let x = 2;
4446
/// let x = x + 1;
4547
/// ```
4648
/// use different variable name:
4749
/// ```rust
50+
/// let x = 2;
4851
/// let y = x + 1;
4952
/// ```
5053
pub SHADOW_REUSE,

clippy_lints/src/strings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ declare_clippy_lint! {
4848
///
4949
/// ```rust
5050
/// let x = "Hello".to_owned();
51-
/// x + ", World"
51+
/// x + ", World";
5252
/// ```
5353
pub STRING_ADD,
5454
restriction,

clippy_lints/src/write.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ declare_clippy_lint! {
7777
///
7878
/// **Example:**
7979
/// ```rust
80+
/// # let foo = "bar";
8081
/// println!("{:?}", foo);
8182
/// ```
8283
pub USE_DEBUG,

0 commit comments

Comments
 (0)