Remove hir::GenericParam::is_*_param
This commit is contained in:
parent
c818a1df9b
commit
fba1fe2108
4 changed files with 101 additions and 97 deletions
|
@ -497,20 +497,6 @@ pub struct GenericParam {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GenericParam {
|
impl GenericParam {
|
||||||
pub fn is_lifetime_param(&self) -> bool {
|
|
||||||
match self.kind {
|
|
||||||
GenericParamKind::Lifetime { .. } => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_type_param(&self) -> bool {
|
|
||||||
match self.kind {
|
|
||||||
GenericParamKind::Type { .. } => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn name(&self) -> Name {
|
pub fn name(&self) -> Name {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
GenericParamKind::Lifetime { name, .. } => name.name(),
|
GenericParamKind::Lifetime { name, .. } => name.name(),
|
||||||
|
|
|
@ -29,7 +29,7 @@ use util::nodemap::{NodeSet, FxHashSet};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use hir;
|
use hir::{self, GenericParamKind};
|
||||||
use hir::def_id::LOCAL_CRATE;
|
use hir::def_id::LOCAL_CRATE;
|
||||||
use hir::intravisit::{Visitor, NestedVisitorMap};
|
use hir::intravisit::{Visitor, NestedVisitorMap};
|
||||||
use hir::itemlikevisit::ItemLikeVisitor;
|
use hir::itemlikevisit::ItemLikeVisitor;
|
||||||
|
@ -38,7 +38,13 @@ use hir::intravisit;
|
||||||
// Returns true if the given set of generics implies that the item it's
|
// Returns true if the given set of generics implies that the item it's
|
||||||
// associated with must be inlined.
|
// associated with must be inlined.
|
||||||
fn generics_require_inlining(generics: &hir::Generics) -> bool {
|
fn generics_require_inlining(generics: &hir::Generics) -> bool {
|
||||||
generics.params.iter().any(|param| param.is_type_param())
|
for param in &generics.params {
|
||||||
|
match param.kind {
|
||||||
|
GenericParamKind::Lifetime { .. } => {}
|
||||||
|
GenericParamKind::Type { .. } => return true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the given item must be inlined because it may be
|
// Returns true if the given item must be inlined because it may be
|
||||||
|
|
|
@ -532,21 +532,21 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
let mut next_early_index = index;
|
let mut type_count = 0;
|
||||||
let lifetimes = generics.params.iter().filter_map(|param| {
|
let lifetimes = generics.params.iter().filter_map(|param| {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
Some(Region::early(&self.tcx.hir, &mut index, param))
|
Some(Region::early(&self.tcx.hir, &mut index, param))
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
next_early_index += 1;
|
type_count += 1;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
let scope = Scope::Binder {
|
let scope = Scope::Binder {
|
||||||
lifetimes,
|
lifetimes,
|
||||||
next_early_index,
|
next_early_index: index + type_count,
|
||||||
abstract_type_parent: true,
|
abstract_type_parent: true,
|
||||||
track_lifetime_uses,
|
track_lifetime_uses,
|
||||||
s: ROOT_SCOPE,
|
s: ROOT_SCOPE,
|
||||||
|
@ -698,7 +698,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
|
|
||||||
let mut elision = None;
|
let mut elision = None;
|
||||||
let mut lifetimes = FxHashMap();
|
let mut lifetimes = FxHashMap();
|
||||||
let mut next_early_index = index;
|
let mut type_count = 0;
|
||||||
for param in &generics.params {
|
for param in &generics.params {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
|
@ -712,10 +712,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
next_early_index += 1;
|
type_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let next_early_index = index + type_count;
|
||||||
|
|
||||||
if let Some(elision_region) = elision {
|
if let Some(elision_region) = elision {
|
||||||
let scope = Scope::Elision {
|
let scope = Scope::Elision {
|
||||||
|
@ -773,7 +774,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
let generics = &trait_item.generics;
|
let generics = &trait_item.generics;
|
||||||
let mut index = self.next_early_index();
|
let mut index = self.next_early_index();
|
||||||
debug!("visit_ty: index = {}", index);
|
debug!("visit_ty: index = {}", index);
|
||||||
let mut next_early_index = index;
|
let mut type_count = 0;
|
||||||
let lifetimes = generics.params
|
let lifetimes = generics.params
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|param| {
|
.filter_map(|param| {
|
||||||
|
@ -782,7 +783,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
Some(Region::early(&self.tcx.hir, &mut index, param))
|
Some(Region::early(&self.tcx.hir, &mut index, param))
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
next_early_index += 1;
|
type_count += 1;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -791,7 +792,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
|
|
||||||
let scope = Scope::Binder {
|
let scope = Scope::Binder {
|
||||||
lifetimes,
|
lifetimes,
|
||||||
next_early_index,
|
next_early_index: index + type_count,
|
||||||
s: self.scope,
|
s: self.scope,
|
||||||
track_lifetime_uses: true,
|
track_lifetime_uses: true,
|
||||||
abstract_type_parent: true,
|
abstract_type_parent: true,
|
||||||
|
@ -896,7 +897,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
|
fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
|
||||||
|
|
||||||
check_mixed_explicit_and_in_band_defs(
|
check_mixed_explicit_and_in_band_defs(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
&generics.params.iter().filter_map(|param| {
|
&generics.params.iter().filter_map(|param| {
|
||||||
|
@ -925,12 +925,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
ref bound_generic_params,
|
ref bound_generic_params,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if bound_generic_params.iter().any(|p| p.is_lifetime_param()) {
|
let lifetimes: FxHashMap<_, _> = bound_generic_params.iter()
|
||||||
self.trait_ref_hack = true;
|
|
||||||
let next_early_index = self.next_early_index();
|
|
||||||
let scope = Scope::Binder {
|
|
||||||
lifetimes: bound_generic_params
|
|
||||||
.iter()
|
|
||||||
.filter_map(|param| {
|
.filter_map(|param| {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
|
@ -939,7 +934,12 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect();
|
||||||
|
if !lifetimes.is_empty() {
|
||||||
|
self.trait_ref_hack = true;
|
||||||
|
let next_early_index = self.next_early_index();
|
||||||
|
let scope = Scope::Binder {
|
||||||
|
lifetimes,
|
||||||
s: self.scope,
|
s: self.scope,
|
||||||
next_early_index,
|
next_early_index,
|
||||||
track_lifetime_uses: true,
|
track_lifetime_uses: true,
|
||||||
|
@ -990,7 +990,12 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
|| trait_ref
|
|| trait_ref
|
||||||
.bound_generic_params
|
.bound_generic_params
|
||||||
.iter()
|
.iter()
|
||||||
.any(|p| p.is_lifetime_param())
|
.any(|param| {
|
||||||
|
match param.kind {
|
||||||
|
GenericParamKind::Lifetime { .. } => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
})
|
||||||
{
|
{
|
||||||
if self.trait_ref_hack {
|
if self.trait_ref_hack {
|
||||||
span_err!(
|
span_err!(
|
||||||
|
@ -1259,10 +1264,15 @@ fn compute_object_lifetime_defaults(
|
||||||
let mut j = 0;
|
let mut j = 0;
|
||||||
generics.params.iter().find(|param| {
|
generics.params.iter().find(|param| {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { .. } => j += 1,
|
GenericParamKind::Lifetime { .. } => {
|
||||||
|
if i == j {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
i == j
|
false
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
.name()
|
.name()
|
||||||
.to_string()
|
.to_string()
|
||||||
|
@ -1530,10 +1540,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut next_early_index = index;
|
let mut type_count = 0;
|
||||||
let lifetimes = generics.params
|
let lifetimes = generics.params.iter().filter_map(|param| {
|
||||||
.iter()
|
|
||||||
.filter_map(|param| {
|
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Lifetime { .. } => {
|
GenericParamKind::Lifetime { .. } => {
|
||||||
if self.map.late_bound.contains(¶m.id) {
|
if self.map.late_bound.contains(¶m.id) {
|
||||||
|
@ -1543,12 +1551,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
next_early_index += 1;
|
type_count += 1;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}).collect();
|
||||||
.collect();
|
let next_early_index = index + type_count;
|
||||||
|
|
||||||
let scope = Scope::Binder {
|
let scope = Scope::Binder {
|
||||||
lifetimes,
|
lifetimes,
|
||||||
|
|
|
@ -810,9 +810,14 @@ impl LintPass for VariantSizeDifferences {
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
|
||||||
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
|
||||||
if let hir::ItemEnum(ref enum_definition, ref gens) = it.node {
|
if let hir::ItemEnum(ref enum_definition, ref generics) = it.node {
|
||||||
if gens.params.iter().all(|param| param.is_lifetime_param()) {
|
for param in &generics.params {
|
||||||
// sizes only make sense for non-generic types
|
match param.kind {
|
||||||
|
hir::GenericParamKind::Lifetime { .. } => {},
|
||||||
|
hir::GenericParamKind::Type { .. } => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Sizes only make sense for non-generic types.
|
||||||
let item_def_id = cx.tcx.hir.local_def_id(it.id);
|
let item_def_id = cx.tcx.hir.local_def_id(it.id);
|
||||||
let t = cx.tcx.type_of(item_def_id);
|
let t = cx.tcx.type_of(item_def_id);
|
||||||
let ty = cx.tcx.erase_regions(&t);
|
let ty = cx.tcx.erase_regions(&t);
|
||||||
|
@ -830,7 +835,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
|
||||||
.iter()
|
.iter()
|
||||||
.zip(variants)
|
.zip(variants)
|
||||||
.map(|(variant, variant_layout)| {
|
.map(|(variant, variant_layout)| {
|
||||||
// Subtract the size of the enum discriminant
|
// Subtract the size of the enum discriminant.
|
||||||
let bytes = variant_layout.size.bytes()
|
let bytes = variant_layout.size.bytes()
|
||||||
.saturating_sub(discr_size);
|
.saturating_sub(discr_size);
|
||||||
|
|
||||||
|
@ -846,7 +851,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
|
||||||
(l, s, li)
|
(l, s, li)
|
||||||
});
|
});
|
||||||
|
|
||||||
// we only warn if the largest variant is at least thrice as large as
|
// We only warn if the largest variant is at least thrice as large as
|
||||||
// the second-largest.
|
// the second-largest.
|
||||||
if largest > slargest * 3 && slargest > 0 {
|
if largest > slargest * 3 && slargest > 0 {
|
||||||
cx.span_lint(VARIANT_SIZE_DIFFERENCES,
|
cx.span_lint(VARIANT_SIZE_DIFFERENCES,
|
||||||
|
@ -858,5 +863,4 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue