mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Remove rarely used type_size
helper function
This commit is contained in:
parent
fc7b3955f8
commit
88970ec8cf
4 changed files with 12 additions and 19 deletions
|
@ -5,10 +5,11 @@ use rustc::lint::*;
|
||||||
use rustc::middle::expr_use_visitor::*;
|
use rustc::middle::expr_use_visitor::*;
|
||||||
use rustc::middle::mem_categorization::{cmt, Categorization};
|
use rustc::middle::mem_categorization::{cmt, Categorization};
|
||||||
use rustc::ty::{self, Ty};
|
use rustc::ty::{self, Ty};
|
||||||
|
use rustc::ty::layout::LayoutOf;
|
||||||
use rustc::util::nodemap::NodeSet;
|
use rustc::util::nodemap::NodeSet;
|
||||||
use syntax::ast::NodeId;
|
use syntax::ast::NodeId;
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use utils::{span_lint, type_size};
|
use utils::span_lint;
|
||||||
|
|
||||||
pub struct Pass {
|
pub struct Pass {
|
||||||
pub too_large_for_stack: u64,
|
pub too_large_for_stack: u64,
|
||||||
|
@ -164,7 +165,7 @@ impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
|
||||||
// Large types need to be boxed to avoid stack
|
// Large types need to be boxed to avoid stack
|
||||||
// overflows.
|
// overflows.
|
||||||
if ty.is_box() {
|
if ty.is_box() {
|
||||||
type_size(self.cx, ty.boxed_ty()).unwrap_or(0) > self.too_large_for_stack
|
self.cx.layout_of(ty.boxed_ty()).ok().map_or(0, |l| l.size.bytes()) > self.too_large_for_stack
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
use rustc::lint::*;
|
use rustc::lint::*;
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use utils::{snippet_opt, span_lint_and_then, type_size};
|
use utils::{snippet_opt, span_lint_and_then};
|
||||||
use rustc::ty::TypeFoldable;
|
use rustc::ty::layout::LayoutOf;
|
||||||
|
|
||||||
/// **What it does:** Checks for large size differences between variants on
|
/// **What it does:** Checks for large size differences between variants on
|
||||||
/// `enum`s.
|
/// `enum`s.
|
||||||
|
@ -61,13 +61,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
|
||||||
let size: u64 = variant
|
let size: u64 = variant
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| {
|
.filter_map(|f| {
|
||||||
let ty = cx.tcx.type_of(f.did);
|
let ty = cx.tcx.type_of(f.did);
|
||||||
if ty.needs_subst() {
|
// don't count generics by filtering out everything
|
||||||
0 // we can't reason about generics, so we treat them as zero sized
|
// that does not have a layout
|
||||||
} else {
|
cx.layout_of(ty).ok().map(|l| l.size.bytes())
|
||||||
type_size(cx, ty).expect("size should be computable for concrete type")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ use rustc::hir::*;
|
||||||
use rustc::hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
|
use rustc::hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
|
||||||
use rustc::lint::*;
|
use rustc::lint::*;
|
||||||
use rustc::ty::{self, Ty, TyCtxt, TypeckTables};
|
use rustc::ty::{self, Ty, TyCtxt, TypeckTables};
|
||||||
|
use rustc::ty::layout::LayoutOf;
|
||||||
use rustc::ty::subst::Substs;
|
use rustc::ty::subst::Substs;
|
||||||
use rustc_typeck::hir_ty_to_ty;
|
use rustc_typeck::hir_ty_to_ty;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
@ -15,7 +16,7 @@ use syntax::codemap::Span;
|
||||||
use syntax::errors::DiagnosticBuilder;
|
use syntax::errors::DiagnosticBuilder;
|
||||||
use utils::{comparisons, higher, in_constant, in_external_macro, in_macro, last_path_segment, match_def_path, match_path,
|
use utils::{comparisons, higher, in_constant, in_external_macro, in_macro, last_path_segment, match_def_path, match_path,
|
||||||
multispan_sugg, opt_def_id, same_tys, snippet, snippet_opt, span_help_and_lint, span_lint,
|
multispan_sugg, opt_def_id, same_tys, snippet, snippet_opt, span_help_and_lint, span_lint,
|
||||||
span_lint_and_sugg, span_lint_and_then, type_size};
|
span_lint_and_sugg, span_lint_and_then};
|
||||||
use utils::paths;
|
use utils::paths;
|
||||||
|
|
||||||
/// Handles all the linting of funky types
|
/// Handles all the linting of funky types
|
||||||
|
@ -1478,7 +1479,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(
|
||||||
let pre_cast_ty = cx.tables.expr_ty(cast_exp);
|
let pre_cast_ty = cx.tables.expr_ty(cast_exp);
|
||||||
let cast_ty = cx.tables.expr_ty(expr);
|
let cast_ty = cx.tables.expr_ty(expr);
|
||||||
// if it's a cast from i32 to u32 wrapping will invalidate all these checks
|
// if it's a cast from i32 to u32 wrapping will invalidate all these checks
|
||||||
if type_size(cx, pre_cast_ty) == type_size(cx, cast_ty) {
|
if cx.layout_of(pre_cast_ty).ok().map(|l| l.size) == cx.layout_of(cast_ty).ok().map(|l| l.size) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match pre_cast_ty.sty {
|
match pre_cast_ty.sty {
|
||||||
|
|
|
@ -9,7 +9,6 @@ use rustc::lint::{LateContext, Level, Lint, LintContext};
|
||||||
use rustc::session::Session;
|
use rustc::session::Session;
|
||||||
use rustc::traits;
|
use rustc::traits;
|
||||||
use rustc::ty::{self, Ty, TyCtxt};
|
use rustc::ty::{self, Ty, TyCtxt};
|
||||||
use rustc::ty::layout::LayoutOf;
|
|
||||||
use rustc_errors;
|
use rustc_errors;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -1048,12 +1047,6 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<u64> {
|
|
||||||
cx.layout_of(ty)
|
|
||||||
.ok()
|
|
||||||
.map(|layout| layout.size.bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the lint is allowed in the current context
|
/// Returns true if the lint is allowed in the current context
|
||||||
///
|
///
|
||||||
/// Useful for skipping long running code when it's unnecessary
|
/// Useful for skipping long running code when it's unnecessary
|
||||||
|
|
Loading…
Reference in a new issue