mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
Merge branch 'master' of github.com:Manishearth/rust-clippy
This commit is contained in:
commit
b790b78eec
@ -10,6 +10,7 @@ Lints included in this crate:
|
|||||||
- `clippy_box_vec`: Warns on usage of `Box<Vec<T>>`
|
- `clippy_box_vec`: Warns on usage of `Box<Vec<T>>`
|
||||||
- `clippy_dlist`: Warns on usage of `DList`
|
- `clippy_dlist`: Warns on usage of `DList`
|
||||||
- `clippy_str_to_string`: Warns on usage of `str::to_string()`
|
- `clippy_str_to_string`: Warns on usage of `str::to_string()`
|
||||||
|
- `clippy_toplevel_ref_arg`: Warns when a function argument is declared `ref` (i.e. `fn foo(ref x: u8)`, but not `fn foo((ref x, ref y): (u8, u8))`).
|
||||||
|
|
||||||
More to come, please [file an issue](https://github.com/Manishearth/rust-clippy/issues) if you have ideas!
|
More to come, please [file an issue](https://github.com/Manishearth/rust-clippy/issues) if you have ideas!
|
||||||
|
|
||||||
|
14
examples/toplevel_ref_arg.rs
Normal file
14
examples/toplevel_ref_arg.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#![feature(phase)]
|
||||||
|
|
||||||
|
#[phase(plugin)]
|
||||||
|
extern crate rust_clippy;
|
||||||
|
|
||||||
|
fn the_answer(ref mut x: u8) {
|
||||||
|
*x = 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut x = 0;
|
||||||
|
the_answer(x);
|
||||||
|
println!("The answer is {}.", x);
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
#[phase(plugin,link)]
|
#[phase(plugin, link)]
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
#[phase(plugin, link)]
|
#[phase(plugin, link)]
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
@ -21,4 +21,5 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||||||
reg.register_lint_pass(box types::TypePass as LintPassObject);
|
reg.register_lint_pass(box types::TypePass as LintPassObject);
|
||||||
reg.register_lint_pass(box misc::MiscPass as LintPassObject);
|
reg.register_lint_pass(box misc::MiscPass as LintPassObject);
|
||||||
reg.register_lint_pass(box misc::StrToStringPass as LintPassObject);
|
reg.register_lint_pass(box misc::StrToStringPass as LintPassObject);
|
||||||
|
reg.register_lint_pass(box misc::TopLevelRefPass as LintPassObject);
|
||||||
}
|
}
|
||||||
|
24
src/misc.rs
24
src/misc.rs
@ -1,6 +1,7 @@
|
|||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::*;
|
use syntax::ast::*;
|
||||||
|
use syntax::visit::{FnKind};
|
||||||
use rustc::lint::{Context, LintPass, LintArray, Lint, Level};
|
use rustc::lint::{Context, LintPass, LintArray, Lint, Level};
|
||||||
use rustc::middle::ty::{mod, expr_ty, ty_str, ty_ptr, ty_rptr};
|
use rustc::middle::ty::{mod, expr_ty, ty_str, ty_ptr, ty_rptr};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
@ -83,3 +84,26 @@ impl LintPass for StrToStringPass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
declare_lint!(CLIPPY_TOPLEVEL_REF_ARG, Warn, "Warn about pattern matches with top-level `ref` bindings");
|
||||||
|
|
||||||
|
pub struct TopLevelRefPass;
|
||||||
|
|
||||||
|
impl LintPass for TopLevelRefPass {
|
||||||
|
fn get_lints(&self) -> LintArray {
|
||||||
|
lint_array!(CLIPPY_TOPLEVEL_REF_ARG)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_fn(&mut self, cx: &Context, _: FnKind, decl: &FnDecl, _: &Block, _: Span, _: NodeId) {
|
||||||
|
for ref arg in decl.inputs.iter() {
|
||||||
|
if let PatIdent(BindByRef(_), _, _) = arg.pat.node {
|
||||||
|
cx.span_lint(
|
||||||
|
CLIPPY_TOPLEVEL_REF_ARG,
|
||||||
|
arg.pat.span,
|
||||||
|
"`ref` directly on a function argument is ignored. Have you considered using a reference type instead?"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user