mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
Add make tidy fixes
This commit is contained in:
parent
23a8c7d4d9
commit
f75c8a98dd
@ -184,7 +184,10 @@ impl<'a> FnLikeNode<'a> {
|
||||
}
|
||||
|
||||
pub fn decl(self) -> &'a FnDecl {
|
||||
if let map::NodeInlinedItem(&InlinedItem { kind: InlinedItemKind::Fn(ref decl), .. }) = self.node {
|
||||
if let map::NodeInlinedItem(&InlinedItem {
|
||||
kind: InlinedItemKind::Fn(ref decl),
|
||||
..
|
||||
}) = self.node {
|
||||
return &decl;
|
||||
}
|
||||
self.handle(|i: ItemFnParts<'a>| &*i.decl,
|
||||
|
@ -601,7 +601,7 @@ impl<'ast> Map<'ast> {
|
||||
pub fn get_parent_did(&self, id: NodeId) -> DefId {
|
||||
let parent = self.get_parent(id);
|
||||
match self.find_entry(parent) {
|
||||
Some(RootInlinedParent(ii)) => ii.def_id, // TODO: is this wrong for items?
|
||||
Some(RootInlinedParent(ii)) => ii.def_id,
|
||||
_ => self.local_def_id(parent)
|
||||
}
|
||||
}
|
||||
|
@ -165,9 +165,13 @@ pub enum InlinedItemKindRef<'a> {
|
||||
}
|
||||
|
||||
impl<'a> InlinedItemRef<'a> {
|
||||
pub fn from_item<'ast: 'a>(def_id: DefId, item: &'a hir::Item, map: &hir_map::Map<'ast>) -> InlinedItemRef<'a> {
|
||||
pub fn from_item<'ast: 'a>(def_id: DefId,
|
||||
item: &'a hir::Item,
|
||||
map: &hir_map::Map<'ast>)
|
||||
-> InlinedItemRef<'a> {
|
||||
let (body, kind) = match item.node {
|
||||
hir::ItemFn(ref decl, _, _, _, _, body_id) => (map.expr(body_id), InlinedItemKindRef::Fn(&decl)),
|
||||
hir::ItemFn(ref decl, _, _, _, _, body_id) =>
|
||||
(map.expr(body_id), InlinedItemKindRef::Fn(&decl)),
|
||||
hir::ItemConst(ref ty, ref body) => (&**body, InlinedItemKindRef::Const(ty)),
|
||||
_ => bug!("InlinedItemRef::from_item wrong kind")
|
||||
};
|
||||
@ -178,10 +182,15 @@ impl<'a> InlinedItemRef<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_trait_item(def_id: DefId, item: &'a hir::TraitItem, _map: &hir_map::Map) -> InlinedItemRef<'a> {
|
||||
pub fn from_trait_item(def_id: DefId,
|
||||
item: &'a hir::TraitItem,
|
||||
_map: &hir_map::Map)
|
||||
-> InlinedItemRef<'a> {
|
||||
let (body, kind) = match item.node {
|
||||
hir::ConstTraitItem(ref ty, Some(ref body)) => (&**body, InlinedItemKindRef::Const(ty)),
|
||||
hir::ConstTraitItem(_, None) => bug!("InlinedItemRef::from_trait_item called for const without body"),
|
||||
hir::ConstTraitItem(_, None) => {
|
||||
bug!("InlinedItemRef::from_trait_item called for const without body")
|
||||
},
|
||||
_ => bug!("InlinedItemRef::from_trait_item wrong kind")
|
||||
};
|
||||
InlinedItemRef {
|
||||
@ -191,9 +200,13 @@ impl<'a> InlinedItemRef<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_impl_item<'ast: 'a>(def_id: DefId, item: &'a hir::ImplItem, map: &hir_map::Map<'ast>) -> InlinedItemRef<'a> {
|
||||
pub fn from_impl_item<'ast: 'a>(def_id: DefId,
|
||||
item: &'a hir::ImplItem,
|
||||
map: &hir_map::Map<'ast>)
|
||||
-> InlinedItemRef<'a> {
|
||||
let (body, kind) = match item.node {
|
||||
hir::ImplItemKind::Method(ref sig, body_id) => (map.expr(body_id), InlinedItemKindRef::Fn(&sig.decl)),
|
||||
hir::ImplItemKind::Method(ref sig, body_id) =>
|
||||
(map.expr(body_id), InlinedItemKindRef::Fn(&sig.decl)),
|
||||
hir::ImplItemKind::Const(ref ty, ref body) => (&**body, InlinedItemKindRef::Const(ty)),
|
||||
_ => bug!("InlinedItemRef::from_impl_item wrong kind")
|
||||
};
|
||||
|
@ -850,7 +850,8 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'tcx, 'a>, expr:
|
||||
visitor.cx = prev_cx;
|
||||
}
|
||||
|
||||
fn resolve_local<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'tcx, 'a>, local: &'tcx hir::Local) {
|
||||
fn resolve_local<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'tcx, 'a>,
|
||||
local: &'tcx hir::Local) {
|
||||
debug!("resolve_local(local.id={:?},local.init={:?})",
|
||||
local.id,local.init.is_some());
|
||||
|
||||
|
@ -109,7 +109,8 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
// or the default.
|
||||
let trait_id = tcx.map.get_parent(node_id);
|
||||
let trait_id = tcx.map.local_def_id(trait_id);
|
||||
let default_value = expr_option.as_ref().map(|expr| (&**expr, tcx.ast_ty_to_prim_ty(ty)));
|
||||
let default_value = expr_option.as_ref()
|
||||
.map(|expr| (&**expr, tcx.ast_ty_to_prim_ty(ty)));
|
||||
resolve_trait_associated_const(tcx, def_id, default_value, trait_id, substs)
|
||||
} else {
|
||||
// Technically, without knowing anything about the
|
||||
@ -141,7 +142,8 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
}
|
||||
let mut used_substs = false;
|
||||
let expr_ty = match tcx.sess.cstore.maybe_get_item_ast(tcx, def_id) {
|
||||
Some((&InlinedItem { body: ref const_expr, kind: InlinedItemKind::Const(ref ty), .. }, _)) => {
|
||||
Some((&InlinedItem { body: ref const_expr,
|
||||
kind: InlinedItemKind::Const(ref ty), .. }, _)) => {
|
||||
Some((&**const_expr, tcx.ast_ty_to_prim_ty(ty)))
|
||||
}
|
||||
_ => None
|
||||
@ -1057,12 +1059,13 @@ fn infer<'a, 'tcx>(i: ConstInt,
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
trait_item_id: DefId,
|
||||
default_value: Option<(&'tcx Expr, Option<ty::Ty<'tcx>>)>,
|
||||
trait_id: DefId,
|
||||
rcvr_substs: &'tcx Substs<'tcx>)
|
||||
-> Option<(&'tcx Expr, Option<ty::Ty<'tcx>>)>
|
||||
fn resolve_trait_associated_const<'a, 'tcx: 'a>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
trait_item_id: DefId,
|
||||
default_value: Option<(&'tcx Expr, Option<ty::Ty<'tcx>>)>,
|
||||
trait_id: DefId,
|
||||
rcvr_substs: &'tcx Substs<'tcx>
|
||||
) -> Option<(&'tcx Expr, Option<ty::Ty<'tcx>>)>
|
||||
{
|
||||
let trait_ref = ty::Binder(ty::TraitRef::new(trait_id, rcvr_substs));
|
||||
debug!("resolve_trait_associated_const: trait_ref={:?}",
|
||||
|
@ -153,7 +153,10 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
|
||||
self.calculate_def_hash(DepNode::HirBody(def_id), true, &mut walk_op);
|
||||
}
|
||||
|
||||
fn calculate_def_hash<W>(&mut self, dep_node: DepNode<DefId>, hash_bodies: bool, walk_op: &mut W)
|
||||
fn calculate_def_hash<W>(&mut self,
|
||||
dep_node: DepNode<DefId>,
|
||||
hash_bodies: bool,
|
||||
walk_op: &mut W)
|
||||
where W: for<'v> FnMut(&mut StrictVersionHashVisitor<'v, 'a, 'tcx>)
|
||||
{
|
||||
let mut state = IchHasher::new();
|
||||
|
@ -520,7 +520,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
// We only save the HIR for associated consts with bodies
|
||||
// (InlinedItemRef::from_trait_item panics otherwise)
|
||||
let trait_def_id = trait_item.container.id();
|
||||
Some(self.encode_inlined_item(InlinedItemRef::from_trait_item(trait_def_id, ast_item, &tcx.map)))
|
||||
Some(self.encode_inlined_item(
|
||||
InlinedItemRef::from_trait_item(trait_def_id, ast_item, &tcx.map)
|
||||
))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@ -591,7 +593,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
predicates: Some(self.encode_predicates(def_id)),
|
||||
|
||||
ast: if ast {
|
||||
Some(self.encode_inlined_item(InlinedItemRef::from_impl_item(impl_def_id, ast_item, &tcx.map)))
|
||||
Some(self.encode_inlined_item(
|
||||
InlinedItemRef::from_impl_item(impl_def_id, ast_item, &tcx.map)
|
||||
))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@ -821,7 +825,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
ast: match item.node {
|
||||
hir::ItemConst(..) |
|
||||
hir::ItemFn(_, _, hir::Constness::Const, ..) => {
|
||||
Some(self.encode_inlined_item(InlinedItemRef::from_item(def_id, item, &tcx.map)))
|
||||
Some(self.encode_inlined_item(
|
||||
InlinedItemRef::from_item(def_id, item, &tcx.map)
|
||||
))
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
|
@ -181,7 +181,8 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
|
||||
/// Returns true if the call is to a const fn or method.
|
||||
fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
|
||||
if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
|
||||
let qualif = match self.tcx.const_qualif_map.borrow_mut().entry(fn_like.body().node_id()) {
|
||||
let node_id = fn_like.body().node_id();
|
||||
let qualif = match self.tcx.const_qualif_map.borrow_mut().entry(node_id) {
|
||||
Entry::Occupied(entry) => Some(*entry.get()),
|
||||
_ => None
|
||||
};
|
||||
|
@ -143,7 +143,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
decl: &hir::FnDecl,
|
||||
body_id: hir::ExprId) {
|
||||
debug!("regionck_fn(id={})", fn_id);
|
||||
let mut rcx = RegionCtxt::new(self, RepeatingScope(body_id.node_id()), body_id.node_id(), Subject(fn_id));
|
||||
let node_id = body_id.node_id();
|
||||
let mut rcx = RegionCtxt::new(self, RepeatingScope(node_id), node_id, Subject(fn_id));
|
||||
|
||||
if self.err_count_since_creation() == 0 {
|
||||
// regionck assumes typeck succeeded
|
||||
|
Loading…
Reference in New Issue
Block a user