Skip to content

Commit 9a2c011

Browse files
committed
add better example and change pedantic to restriction
1 parent f00f1db commit 9a2c011

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
<<<<<<< HEAD
10-
[There are 337 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
11-
=======
12-
[There are 334 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
13-
>>>>>>> implemented `as_conversions` lint
9+
[There are 338 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1410

1511
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1612

clippy_lints/src/as_conversions.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,29 @@ declare_clippy_lint! {
99
///
1010
/// **Why is this bad?** `as` conversions will perform many kinds of
1111
/// conversions, including silently lossy conversions and dangerous coercions.
12-
/// There are cases when it's necessary to use `as`, so the lint is
12+
/// There are cases when it makes sense to use `as`, so the lint is
1313
/// Allow by default.
1414
///
1515
/// **Known problems:** None.
1616
///
1717
/// **Example:**
18-
/// ```rust
19-
/// let a: u32 = 0;
20-
/// let p = &a as *const u32 as *mut u32;
18+
/// ```rust,ignore
19+
/// let a: u32;
20+
/// ...
21+
/// f(a as u16);
2122
/// ```
23+
///
24+
/// Usually better represents the semantics you expect:
25+
/// ```rust,ignore
26+
/// f(a.try_into()?);
27+
/// ```
28+
/// or
29+
/// ```rust,ignore
30+
/// f(a.try_into().expect("Unexpected u16 overflow in f"));
31+
/// ```
32+
///
2233
pub AS_CONVERSIONS,
23-
pedantic,
34+
restriction,
2435
"using a potentially dangerous silent `as` conversion"
2536
}
2637

clippy_lints/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
966966
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
967967
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
968968
LintId::of(&arithmetic::INTEGER_ARITHMETIC),
969+
LintId::of(&as_conversions::AS_CONVERSIONS),
969970
LintId::of(&dbg_macro::DBG_MACRO),
970971
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
971972
LintId::of(&exit::EXIT),
@@ -998,7 +999,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
998999
]);
9991000

10001001
store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
1001-
LintId::of(&as_conversions::AS_CONVERSIONS),
10021002
LintId::of(&attrs::INLINE_ALWAYS),
10031003
LintId::of(&checked_conversions::CHECKED_CONVERSIONS),
10041004
LintId::of(&copies::MATCH_SAME_ARMS),

src/lintlist/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 337] = [
9+
pub const ALL_LINTS: [Lint; 338] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -30,8 +30,8 @@ pub const ALL_LINTS: [Lint; 337] = [
3030
},
3131
Lint {
3232
name: "as_conversions",
33-
group: "pedantic",
34-
desc: "a potentially dangerous silent `as` conversion",
33+
group: "restriction",
34+
desc: "using a potentially dangerous silent `as` conversion",
3535
deprecation: None,
3636
module: "as_conversions",
3737
},

0 commit comments

Comments
 (0)