use std::cmp;
-use crate::utils::{in_macro_or_desugar, is_copy, is_self_ty, snippet, span_lint_and_sugg};
+use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
use if_chain::if_chain;
use matches::matches;
use rustc::hir;
"functions taking small copyable arguments by reference"
}
+#[derive(Copy, Clone)]
pub struct TriviallyCopyPassByRef {
limit: u64,
}
// Use lifetimes to determine if we're returning a reference to the
// argument. In that case we can't switch to pass-by-value as the
// argument will not live long enough.
- let output_lts = match fn_sig.output().sty {
+ let output_lts = match fn_sig.output().kind {
ty::Ref(output_lt, _, _) => vec![output_lt],
ty::Adt(_, substs) => substs.regions().collect(),
_ => vec![],
}
if_chain! {
- if let ty::Ref(input_lt, ty, Mutability::MutImmutable) = ty.sty;
+ if let ty::Ref(input_lt, ty, Mutability::Immutable) = ty.kind;
if !output_lts.contains(&input_lt);
if is_copy(cx, ty);
if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());
if size <= self.limit;
- if let hir::TyKind::Rptr(_, MutTy { ty: ref decl_ty, .. }) = input.node;
+ if let hir::TyKind::Rptr(_, MutTy { ty: ref decl_ty, .. }) = input.kind;
then {
let value_type = if is_self_ty(decl_ty) {
"self".into()
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
- if in_macro_or_desugar(item.span) {
+ if item.span.from_expansion() {
return;
}
- if let hir::TraitItemKind::Method(method_sig, _) = &item.node {
+ if let hir::TraitItemKind::Method(method_sig, _) = &item.kind {
self.check_poly_fn(cx, item.hir_id, &*method_sig.decl, None);
}
}
span: Span,
hir_id: HirId,
) {
- if in_macro_or_desugar(span) {
+ if span.from_expansion() {
return;
}
// Exclude non-inherent impls
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(hir_id)) {
- if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
+ if matches!(item.kind, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
ItemKind::Trait(..))
{
return;