Fix lines that exceed max width manually
This commit is contained in:
parent
7a06d312fd
commit
a6c71e9c0d
@ -143,7 +143,8 @@ macro_rules! ops {
|
|||||||
if_chain! {
|
if_chain! {
|
||||||
if parent_impl != ast::CRATE_NODE_ID;
|
if parent_impl != ast::CRATE_NODE_ID;
|
||||||
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
|
if let hir::map::Node::NodeItem(item) = cx.tcx.hir.get(parent_impl);
|
||||||
if let hir::Item_::ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) = item.node;
|
if let hir::Item_::ItemImpl(_, _, _, _, Some(ref trait_ref), _, _) =
|
||||||
|
item.node;
|
||||||
if trait_ref.path.def.def_id() == trait_id;
|
if trait_ref.path.def.def_id() == trait_id;
|
||||||
then { return; }
|
then { return; }
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
const ZERO_REF_SUMMARY: &str = "reference to zeroed memory";
|
const ZERO_REF_SUMMARY: &str = "reference to zeroed memory";
|
||||||
const UNINIT_REF_SUMMARY: &str = "reference to uninitialized memory";
|
const UNINIT_REF_SUMMARY: &str = "reference to uninitialized memory";
|
||||||
const HELP: &str =
|
const HELP: &str = "Creation of a null reference is undefined behavior; \
|
||||||
"Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html";
|
see https://doc.rust-lang.org/reference/behavior-considered-undefined.html";
|
||||||
|
|
||||||
pub struct InvalidRef;
|
pub struct InvalidRef;
|
||||||
|
|
||||||
@ -42,9 +42,13 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
|||||||
if let ty::TyRef(..) = cx.tables.expr_ty(expr).sty;
|
if let ty::TyRef(..) = cx.tables.expr_ty(expr).sty;
|
||||||
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
|
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
|
||||||
then {
|
then {
|
||||||
let msg = if match_def_path(cx.tcx, def_id, &paths::MEM_ZEROED) | match_def_path(cx.tcx, def_id, &paths::INIT) {
|
let msg = if match_def_path(cx.tcx, def_id, &paths::MEM_ZEROED) |
|
||||||
|
match_def_path(cx.tcx, def_id, &paths::INIT)
|
||||||
|
{
|
||||||
ZERO_REF_SUMMARY
|
ZERO_REF_SUMMARY
|
||||||
} else if match_def_path(cx.tcx, def_id, &paths::MEM_UNINIT) | match_def_path(cx.tcx, def_id, &paths::UNINIT) {
|
} else if match_def_path(cx.tcx, def_id, &paths::MEM_UNINIT) |
|
||||||
|
match_def_path(cx.tcx, def_id, &paths::UNINIT)
|
||||||
|
{
|
||||||
UNINIT_REF_SUMMARY
|
UNINIT_REF_SUMMARY
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
@ -782,7 +782,9 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::I
|
|||||||
for &(ref conv, self_kinds) in &CONVENTIONS {
|
for &(ref conv, self_kinds) in &CONVENTIONS {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if conv.check(&name.as_str());
|
if conv.check(&name.as_str());
|
||||||
if !self_kinds.iter().any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics));
|
if !self_kinds
|
||||||
|
.iter()
|
||||||
|
.any(|k| k.matches(first_arg_ty, first_arg, self_ty, is_copy, &implitem.generics));
|
||||||
then {
|
then {
|
||||||
let lint = if item.vis == hir::Visibility::Public {
|
let lint = if item.vis == hir::Visibility::Public {
|
||||||
WRONG_PUB_SELF_CONVENTION
|
WRONG_PUB_SELF_CONVENTION
|
||||||
@ -1039,12 +1041,15 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwr
|
|||||||
if let Def::Method(did) = cx.tables.qpath_def(path, fun.hir_id);
|
if let Def::Method(did) = cx.tables.qpath_def(path, fun.hir_id);
|
||||||
if match_def_path(cx.tcx, did, &paths::CSTRING_NEW);
|
if match_def_path(cx.tcx, did, &paths::CSTRING_NEW);
|
||||||
then {
|
then {
|
||||||
span_lint_and_then(cx, TEMPORARY_CSTRING_AS_PTR, expr.span,
|
span_lint_and_then(
|
||||||
"you are getting the inner pointer of a temporary `CString`",
|
cx,
|
||||||
|db| {
|
TEMPORARY_CSTRING_AS_PTR,
|
||||||
db.note("that pointer will be invalid outside this expression");
|
expr.span,
|
||||||
db.span_help(unwrap.span, "assign the `CString` to a variable to extend its lifetime");
|
"you are getting the inner pointer of a temporary `CString`",
|
||||||
});
|
|db| {
|
||||||
|
db.note("that pointer will be invalid outside this expression");
|
||||||
|
db.span_help(unwrap.span, "assign the `CString` to a variable to extend its lifetime");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,12 @@ fn check_fn(
|
|||||||
span,
|
span,
|
||||||
&format!("you should consider adding a `Default` implementation for `{}`", self_ty),
|
&format!("you should consider adding a `Default` implementation for `{}`", self_ty),
|
||||||
|db| {
|
|db| {
|
||||||
db.suggest_prepend_item(cx, span, "try this", &create_new_without_default_suggest_msg(self_ty));
|
db.suggest_prepend_item(
|
||||||
|
cx,
|
||||||
|
span,
|
||||||
|
"try this",
|
||||||
|
&create_new_without_default_suggest_msg(self_ty),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,11 @@ fn check_suspicious_swap(cx: &LateContext, block: &Block) {
|
|||||||
let lhs0 = Sugg::hir_opt(cx, lhs0);
|
let lhs0 = Sugg::hir_opt(cx, lhs0);
|
||||||
let rhs0 = Sugg::hir_opt(cx, rhs0);
|
let rhs0 = Sugg::hir_opt(cx, rhs0);
|
||||||
let (what, lhs, rhs) = if let (Some(first), Some(second)) = (lhs0, rhs0) {
|
let (what, lhs, rhs) = if let (Some(first), Some(second)) = (lhs0, rhs0) {
|
||||||
(format!(" `{}` and `{}`", first, second), first.mut_addr().to_string(), second.mut_addr().to_string())
|
(
|
||||||
|
format!(" `{}` and `{}`", first, second),
|
||||||
|
first.mut_addr().to_string(),
|
||||||
|
second.mut_addr().to_string(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
("".to_owned(), "".to_owned(), "".to_owned())
|
("".to_owned(), "".to_owned(), "".to_owned())
|
||||||
};
|
};
|
||||||
|
@ -166,11 +166,13 @@ fn check_ty(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool) {
|
|||||||
if let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, cx.tcx.hir.node_to_hir_id(vec.id)));
|
if let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, cx.tcx.hir.node_to_hir_id(vec.id)));
|
||||||
if match_def_path(cx.tcx, did, &paths::VEC);
|
if match_def_path(cx.tcx, did, &paths::VEC);
|
||||||
then {
|
then {
|
||||||
span_help_and_lint(cx,
|
span_help_and_lint(
|
||||||
BOX_VEC,
|
cx,
|
||||||
ast_ty.span,
|
BOX_VEC,
|
||||||
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
|
ast_ty.span,
|
||||||
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.");
|
"you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`",
|
||||||
|
"`Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation.",
|
||||||
|
);
|
||||||
return; // don't recurse into the type
|
return; // don't recurse into the type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,12 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
|||||||
if is_copy(cx, vec_type(cx.tables.expr_ty_adjusted(arg)));
|
if is_copy(cx, vec_type(cx.tables.expr_ty_adjusted(arg)));
|
||||||
then {
|
then {
|
||||||
// report the error around the `vec!` not inside `<std macros>:`
|
// report the error around the `vec!` not inside `<std macros>:`
|
||||||
let span = arg.span.ctxt().outer().expn_info().map(|info| info.call_site).expect("unable to get call_site");
|
let span = arg.span
|
||||||
|
.ctxt()
|
||||||
|
.outer()
|
||||||
|
.expn_info()
|
||||||
|
.map(|info| info.call_site)
|
||||||
|
.expect("unable to get call_site");
|
||||||
check_vec_macro(cx, &vec_args, span);
|
check_vec_macro(cx, &vec_args, span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,16 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
|||||||
| (_, FloatWidth::F64) => "f64",
|
| (_, FloatWidth::F64) => "f64",
|
||||||
_ => "f32"
|
_ => "f32"
|
||||||
};
|
};
|
||||||
span_help_and_lint(cx, ZERO_DIVIDED_BY_ZERO, expr.span,
|
span_help_and_lint(
|
||||||
|
cx,
|
||||||
|
ZERO_DIVIDED_BY_ZERO,
|
||||||
|
expr.span,
|
||||||
"constant division of 0.0 with 0.0 will always result in NaN",
|
"constant division of 0.0 with 0.0 will always result in NaN",
|
||||||
&format!("Consider using `std::{}::NAN` if you would like a constant representing NaN", float_type));
|
&format!(
|
||||||
|
"Consider using `std::{}::NAN` if you would like a constant representing NaN",
|
||||||
|
float_type,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user