Skip to content

Commit

Permalink
add better example and change pedantic to restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
basil-cow committed Nov 25, 2019
1 parent f00f1db commit 9a2c011
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

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

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

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

Expand Down
21 changes: 16 additions & 5 deletions clippy_lints/src/as_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ declare_clippy_lint! {
///
/// **Why is this bad?** `as` conversions will perform many kinds of
/// conversions, including silently lossy conversions and dangerous coercions.
/// There are cases when it's necessary to use `as`, so the lint is
/// There are cases when it makes sense to use `as`, so the lint is
/// Allow by default.
///
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// let a: u32 = 0;
/// let p = &a as *const u32 as *mut u32;
/// ```rust,ignore
/// let a: u32;
/// ...
/// f(a as u16);
/// ```
///
/// Usually better represents the semantics you expect:
/// ```rust,ignore
/// f(a.try_into()?);
/// ```
/// or
/// ```rust,ignore
/// f(a.try_into().expect("Unexpected u16 overflow in f"));
/// ```
///
pub AS_CONVERSIONS,
pedantic,
restriction,
"using a potentially dangerous silent `as` conversion"
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
LintId::of(&arithmetic::INTEGER_ARITHMETIC),
LintId::of(&as_conversions::AS_CONVERSIONS),
LintId::of(&dbg_macro::DBG_MACRO),
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
LintId::of(&exit::EXIT),
Expand Down Expand Up @@ -998,7 +999,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
]);

store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
LintId::of(&as_conversions::AS_CONVERSIONS),
LintId::of(&attrs::INLINE_ALWAYS),
LintId::of(&checked_conversions::CHECKED_CONVERSIONS),
LintId::of(&copies::MATCH_SAME_ARMS),
Expand Down
6 changes: 3 additions & 3 deletions src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub use lint::Lint;
pub use lint::LINT_LEVELS;

// begin lint list, do not remove this comment, it’s used in `update_lints`
pub const ALL_LINTS: [Lint; 337] = [
pub const ALL_LINTS: [Lint; 338] = [
Lint {
name: "absurd_extreme_comparisons",
group: "correctness",
Expand All @@ -30,8 +30,8 @@ pub const ALL_LINTS: [Lint; 337] = [
},
Lint {
name: "as_conversions",
group: "pedantic",
desc: "a potentially dangerous silent `as` conversion",
group: "restriction",
desc: "using a potentially dangerous silent `as` conversion",
deprecation: None,
module: "as_conversions",
},
Expand Down

0 comments on commit 9a2c011

Please sign in to comment.