Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
max_width = 120
ideal_width = 100
fn_args_density = "Compressed"
fn_call_width = 80
fn_args_paren_newline = false
46 changes: 22 additions & 24 deletions src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ declare_lint! {
}

// Tuples are of the form (constant, name, min_digits)
const KNOWN_CONSTS : &'static [(f64, &'static str, usize)] = &[
(f64::E, "E", 4),
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
(f64::LN_10, "LN_10", 5),
(f64::LN_2, "LN_2", 5),
(f64::LOG10_E, "LOG10_E", 5),
(f64::LOG2_E, "LOG2_E", 5),
(f64::PI, "PI", 3),
(f64::SQRT_2, "SQRT_2", 5),
];
const KNOWN_CONSTS: &'static [(f64, &'static str, usize)] = &[(f64::E, "E", 4),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of change looks strange to me. It leaves tons of space on the left, and moves the important part quite a lot to the right.

Is there a rustfmt option to keep the original here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see one, but I could be wrong. Mostly okay with this formatting though.

(f64::FRAC_1_PI, "FRAC_1_PI", 4),
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
(f64::LN_10, "LN_10", 5),
(f64::LN_2, "LN_2", 5),
(f64::LOG10_E, "LOG10_E", 5),
(f64::LOG2_E, "LOG2_E", 5),
(f64::PI, "PI", 3),
(f64::SQRT_2, "SQRT_2", 5)];

#[derive(Copy,Clone)]
pub struct ApproxConstant;
Expand All @@ -61,19 +59,19 @@ fn check_lit(cx: &LateContext, lit: &Lit, e: &Expr) {
match lit.node {
LitFloat(ref s, TyF32) => check_known_consts(cx, e, s, "f32"),
LitFloat(ref s, TyF64) => check_known_consts(cx, e, s, "f64"),
LitFloatUnsuffixed(ref s) =>
check_known_consts(cx, e, s, "f{32, 64}"),
_ => ()
LitFloatUnsuffixed(ref s) => check_known_consts(cx, e, s, "f{32, 64}"),
_ => (),
}
}

fn check_known_consts(cx: &LateContext, e: &Expr, s: &str, module: &str) {
if let Ok(_) = s.parse::<f64>() {
for &(constant, name, min_digits) in KNOWN_CONSTS {
if is_approx_const(constant, s, min_digits) {
span_lint(cx, APPROX_CONSTANT, e.span, &format!(
"approximate value of `{}::{}` found. \
Consider using it directly", module, &name));
span_lint(cx,
APPROX_CONSTANT,
e.span,
&format!("approximate value of `{}::{}` found. Consider using it directly", module, &name));
return;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/array_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ impl LateLintPass for ArrayIndexing {
let index = eval_const_expr_partial(cx.tcx, &index, ExprTypeChecked, None);
if let Ok(ConstVal::Uint(index)) = index {
if size as u64 <= index {
span_lint(cx, OUT_OF_BOUNDS_INDEXING, e.span,
"const index-expr is out of bounds");
span_lint(cx, OUT_OF_BOUNDS_INDEXING, e.span, "const index-expr is out of bounds");
}
}
}
Expand Down
38 changes: 24 additions & 14 deletions src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ impl LateLintPass for AttrPass {
fn is_relevant_item(item: &Item) -> bool {
if let ItemFn(_, _, _, _, _, ref block) = item.node {
is_relevant_block(block)
} else { false }
} else {
false
}
}

fn is_relevant_impl(item: &ImplItem) -> bool {
match item.node {
ImplItemKind::Method(_, ref block) => is_relevant_block(block),
_ => false
_ => false,
}
}

fn is_relevant_trait(item: &TraitItem) -> bool {
match item.node {
MethodTraitItem(_, None) => true,
MethodTraitItem(_, Some(ref block)) => is_relevant_block(block),
_ => false
_ => false,
}
}

Expand All @@ -95,25 +97,33 @@ fn is_relevant_expr(expr: &Expr) -> bool {
ExprCall(ref path_expr, _) => {
if let ExprPath(_, ref path) = path_expr.node {
!match_path(path, &BEGIN_UNWIND)
} else { true }
} else {
true
}
}
_ => true
_ => true,
}
}

fn check_attrs(cx: &LateContext, span: Span, name: &Name,
attrs: &[Attribute]) {
if in_macro(cx, span) { return; }
fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
if in_macro(cx, span) {
return;
}

for attr in attrs {
if let MetaList(ref inline, ref values) = attr.node.value.node {
if values.len() != 1 || inline != &"inline" { continue; }
if values.len() != 1 || inline != &"inline" {
continue;
}
if let MetaWord(ref always) = values[0].node {
if always != &"always" { continue; }
span_lint(cx, INLINE_ALWAYS, attr.span, &format!(
"you have declared `#[inline(always)]` on `{}`. This \
is usually a bad idea",
name));
if always != &"always" {
continue;
}
span_lint(cx,
INLINE_ALWAYS,
attr.span,
&format!("you have declared `#[inline(always)]` on `{}`. This is usually a bad idea",
name));
}
}
}
Expand Down
Loading