Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #62119

Merged
merged 20 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
30b6c59
Prefer to use `has_errors` to `err_count`
matthewjasper Jun 22, 2019
95a3215
Count all errors for `track_errors`
matthewjasper Jun 22, 2019
e1d871e
Remove built-in derive macros `Send` and `Sync`
petrochenkov Jun 23, 2019
a257dff
Add test for issue-38591
JohnTitor Jun 23, 2019
c7e1f4d
HIR: remove the NodeId get_parent_node, HirIdify is_argument
ljedrz Jun 24, 2019
d08bd72
HIR: rename get_parent_node_by_hir_id to get_parent_node
ljedrz Jun 24, 2019
90de9ed
HIR: remove the NodeId find
ljedrz Jun 24, 2019
f05cbc9
HIR: rename find_by_hir_id to find
ljedrz Jun 24, 2019
d82a12f
HirIdify driver::pretty::HirPrinterSupport::node_path
ljedrz Jun 24, 2019
87438a1
HirIdification: miscellaneous bits
ljedrz Jun 24, 2019
b7a0e40
Fix an ICE with uninhabited consts
varkor Jun 25, 2019
e6ee8a0
rustc: produce AST instead of HIR from `hir::lowering::Resolver` meth…
eddyb Jun 20, 2019
099f9e4
Implement From<Local> for Place and PlaceBase
spastorino Jun 24, 2019
d0e926f
Rollup merge of #61814 - varkor:uninhabited-const-61744, r=oli-obk
Centril Jun 25, 2019
81be122
Rollup merge of #61987 - eddyb:hirless-resolver, r=petrochenkov
Centril Jun 25, 2019
c5e6069
Rollup merge of #62055 - matthewjasper:fix-error-counting, r=pnkfelix
Centril Jun 25, 2019
61fae23
Rollup merge of #62078 - petrochenkov:nosendync2, r=varkor
Centril Jun 25, 2019
6070e2e
Rollup merge of #62085 - JohnTitor:add-test-for-issue-38591, r=Centril
Centril Jun 25, 2019
abc7423
Rollup merge of #62091 - ljedrz:hiridification_almost_there, r=Zoxc
Centril Jun 25, 2019
d406d89
Rollup merge of #62096 - spastorino:impl-place-from, r=oli-obk,Centril
Centril Jun 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ pub struct LoweringContext<'a> {

pub trait Resolver {
/// Resolve a path generated by the lowerer when expanding `for`, `if let`, etc.
fn resolve_hir_path(
fn resolve_ast_path(
&mut self,
path: &ast::Path,
is_value: bool,
) -> hir::Path;
) -> Res<NodeId>;

/// Obtain resolution for a `NodeId` with a single resolution.
fn get_partial_res(&mut self, id: NodeId) -> Option<PartialRes>;
Expand All @@ -167,15 +167,15 @@ pub trait Resolver {
/// This should only return `None` during testing.
fn definitions(&mut self) -> &mut Definitions;

/// Given suffix `["b", "c", "d"]`, creates a HIR path for `[::crate_root]::b::c::d` and
/// Given suffix `["b", "c", "d"]`, creates an AST path for `[::crate_root]::b::c::d` and
/// resolves it based on `is_value`.
fn resolve_str_path(
&mut self,
span: Span,
crate_root: Option<Symbol>,
components: &[Symbol],
is_value: bool,
) -> hir::Path;
) -> (ast::Path, Res<NodeId>);
}

/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
Expand Down Expand Up @@ -5546,16 +5546,26 @@ impl<'a> LoweringContext<'a> {
params: Option<P<hir::GenericArgs>>,
is_value: bool,
) -> hir::Path {
let mut path = self.resolver
let (path, res) = self.resolver
.resolve_str_path(span, self.crate_root, components, is_value);
path.segments.last_mut().unwrap().args = params;

for seg in path.segments.iter_mut() {
if seg.hir_id.is_some() {
seg.hir_id = Some(self.next_id());
let mut segments: Vec<_> = path.segments.iter().map(|segment| {
let res = self.expect_full_res(segment.id);
hir::PathSegment {
ident: segment.ident,
hir_id: Some(self.lower_node_id(segment.id)),
res: Some(self.lower_res(res)),
infer_args: true,
args: None,
}
}).collect();
segments.last_mut().unwrap().args = params;

hir::Path {
span,
res: res.map_id(|_| panic!("unexpected node_id")),
segments: segments.into(),
}
path
}

fn ty_path(&mut self, mut hir_id: hir::HirId, span: Span, qpath: hir::QPath) -> hir::Ty {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'a> Code<'a> {
match map.get(id) {
map::Node::Block(_) => {
// Use the parent, hopefully an expression node.
Code::from_node(map, map.get_parent_node_by_hir_id(id))
Code::from_node(map, map.get_parent_node(id))
}
map::Node::Expr(expr) => Some(Code::Expr(expr)),
node => FnLikeNode::from_node(node).map(Code::FnLike)
Expand Down
63 changes: 25 additions & 38 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl<'hir> Map<'hir> {
}

fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
let node = if let Some(node) = self.find_by_hir_id(hir_id) {
let node = if let Some(node) = self.find(hir_id) {
node
} else {
return None
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<'hir> Map<'hir> {
if variant_data.ctor_hir_id().is_none() {
return None;
}
let ctor_of = match self.find_by_hir_id(self.get_parent_node_by_hir_id(hir_id)) {
let ctor_of = match self.find(self.get_parent_node(hir_id)) {
Some(Node::Item(..)) => def::CtorOf::Struct,
Some(Node::Variant(..)) => def::CtorOf::Variant,
_ => unreachable!(),
Expand Down Expand Up @@ -424,7 +424,7 @@ impl<'hir> Map<'hir> {
/// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
let parent = self.get_parent_node_by_hir_id(hir_id);
let parent = self.get_parent_node(hir_id);
assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id)));
parent
}
Expand Down Expand Up @@ -485,7 +485,7 @@ impl<'hir> Map<'hir> {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) |
Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id,
Node::GenericParam(_) => self.get_parent_node_by_hir_id(id),
Node::GenericParam(_) => self.get_parent_node(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id))
}
}
Expand Down Expand Up @@ -563,7 +563,7 @@ impl<'hir> Map<'hir> {
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
pub fn get(&self, id: HirId) -> Node<'hir> {
// read recorded by `find`
self.find_by_hir_id(id).unwrap_or_else(||
self.find(id).unwrap_or_else(||
bug!("couldn't find hir id {} in the HIR map", id))
}

Expand Down Expand Up @@ -595,13 +595,7 @@ impl<'hir> Map<'hir> {
}

/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
let hir_id = self.node_to_hir_id(id);
self.find_by_hir_id(hir_id)
}

// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn find_by_hir_id(&self, hir_id: HirId) -> Option<Node<'hir>> {
pub fn find(&self, hir_id: HirId) -> Option<Node<'hir>> {
let result = self.find_entry(hir_id).and_then(|entry| {
if let Node::Crate = entry.node {
None
Expand All @@ -615,24 +609,17 @@ impl<'hir> Map<'hir> {
result
}

/// Similar to `get_parent`; returns the parent node-ID, or just `hir_id` if there
/// is no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
/// Similar to `get_parent`; returns the parent HIR Id, or just `hir_id` if there
/// is no parent. Note that the parent may be `CRATE_HIR_ID`, which is not itself
/// present in the map, so passing the return value of `get_parent_node` to
/// `get` may in fact panic.
/// This function returns the immediate parent in the AST, whereas `get_parent`
/// This function returns the immediate parent in the HIR, whereas `get_parent`
/// returns the enclosing item. Note that this might not be the actual parent
/// node in the AST -- some kinds of nodes are not in the map and these will
/// node in the HIR -- some kinds of nodes are not in the map and these will
/// never appear as the parent node. Thus, you can always walk the parent nodes
/// from a node to the root of the AST (unless you get back the same ID here,
/// from a node to the root of the HIR (unless you get back the same ID here,
/// which can happen if the ID is not in the map itself or is just weird).
pub fn get_parent_node(&self, id: NodeId) -> NodeId {
let hir_id = self.node_to_hir_id(id);
let parent_hir_id = self.get_parent_node_by_hir_id(hir_id);
self.hir_to_node_id(parent_hir_id)
}

// FIXME(@ljedrz): replace the `NodeId` variant.
pub fn get_parent_node_by_hir_id(&self, hir_id: HirId) -> HirId {
pub fn get_parent_node(&self, hir_id: HirId) -> HirId {
if self.dep_graph.is_fully_enabled() {
let hir_id_owner = hir_id.owner;
let def_path_hash = self.definitions.def_path_hash(hir_id_owner);
Expand All @@ -646,7 +633,7 @@ impl<'hir> Map<'hir> {

/// Check if the node is an argument. An argument is a local variable whose
/// immediate parent is an item or a closure.
pub fn is_argument(&self, id: NodeId) -> bool {
pub fn is_argument(&self, id: HirId) -> bool {
match self.find(id) {
Some(Node::Binding(_)) => (),
_ => return false,
Expand Down Expand Up @@ -687,7 +674,7 @@ impl<'hir> Map<'hir> {
{
let mut id = start_id;
loop {
let parent_id = self.get_parent_node_by_hir_id(id);
let parent_id = self.get_parent_node(id);
if parent_id == CRATE_HIR_ID {
return Ok(CRATE_HIR_ID);
}
Expand Down Expand Up @@ -872,28 +859,28 @@ impl<'hir> Map<'hir> {
}

pub fn expect_item(&self, id: HirId) -> &'hir Item {
match self.find_by_hir_id(id) { // read recorded by `find`
match self.find(id) { // read recorded by `find`
Some(Node::Item(item)) => item,
_ => bug!("expected item, found {}", self.node_to_string(id))
}
}

pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::ImplItem(item)) => item,
_ => bug!("expected impl item, found {}", self.node_to_string(id))
}
}

pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::TraitItem(item)) => item,
_ => bug!("expected trait item, found {}", self.node_to_string(id))
}
}

pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::Item(i)) => {
match i.node {
ItemKind::Struct(ref struct_def, _) |
Expand All @@ -908,21 +895,21 @@ impl<'hir> Map<'hir> {
}

pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
}
}

pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
match self.find_by_hir_id(id) {
match self.find(id) {
Some(Node::ForeignItem(item)) => item,
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
}
}

pub fn expect_expr(&self, id: HirId) -> &'hir Expr {
match self.find_by_hir_id(id) { // read recorded by find
match self.find(id) { // read recorded by find
Some(Node::Expr(expr)) => expr,
_ => bug!("expected expr, found {}", self.node_to_string(id))
}
Expand Down Expand Up @@ -1028,8 +1015,8 @@ impl<'hir> Map<'hir> {
Some(Node::Pat(pat)) => pat.span,
Some(Node::Arm(arm)) => arm.span,
Some(Node::Block(block)) => block.span,
Some(Node::Ctor(..)) => match self.find_by_hir_id(
self.get_parent_node_by_hir_id(hir_id))
Some(Node::Ctor(..)) => match self.find(
self.get_parent_node(hir_id))
{
Some(Node::Item(item)) => item.span,
Some(Node::Variant(variant)) => variant.span,
Expand Down Expand Up @@ -1100,7 +1087,7 @@ impl<'a> NodesMatchingSuffix<'a> {
// chain, then returns `None`.
fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: HirId) -> Option<(HirId, Name)> {
loop {
if let Node::Item(item) = map.find_by_hir_id(id)? {
if let Node::Item(item) = map.find(id)? {
if item_is_mod(&item) {
return Some((id, item.ident.name))
}
Expand Down Expand Up @@ -1273,7 +1260,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
})
};

match map.find_by_hir_id(id) {
match map.find(id) {
Some(Node::Item(item)) => {
let item_str = match item.node {
ItemKind::ExternCrate(..) => "extern crate",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> {
)
};
let span = scope.span(self, region_scope_tree);
let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) {
let tag = match self.hir().find(scope.hir_id(region_scope_tree)) {
Some(Node::Block(_)) => "block",
Some(Node::Expr(expr)) => match expr.node {
hir::ExprKind::Call(..) => "call",
Expand Down Expand Up @@ -182,7 +182,7 @@ impl<'tcx> TyCtxt<'tcx> {

let scope = region.free_region_binding_scope(self);
let node = self.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID);
let tag = match self.hir().find_by_hir_id(node) {
let tag = match self.hir().find(node) {
Some(Node::Block(_)) | Some(Node::Expr(_)) => "body",
Some(Node::Item(it)) => Self::item_scope_tag(&it),
Some(Node::TraitItem(it)) => Self::trait_item_scope_tag(&it),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub struct InferCtxt<'a, 'tcx> {
/// Track how many errors were reported when this infcx is created.
/// If the number of errors increases, that's also a sign (line
/// `tained_by_errors`) to avoid reporting certain kinds of errors.
// FIXME(matthewjasper) Merge into `tainted_by_errors_flag`
err_count_on_creation: usize,

/// This flag is true while there is an active snapshot.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
.local_def_id_from_hir_id(opaque_parent_hir_id)
};
let (in_definition_scope, origin) =
match tcx.hir().find_by_hir_id(opaque_hir_id)
match tcx.hir().find(opaque_hir_id)
{
Some(Node::Item(item)) => match item.node {
// Anonymous `impl Trait`
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use syntax_pos;
// function, then we should explore its block to check for codes that
// may need to be marked as live.
fn should_explore<'tcx>(tcx: TyCtxt<'tcx>, hir_id: hir::HirId) -> bool {
match tcx.hir().find_by_hir_id(hir_id) {
match tcx.hir().find(hir_id) {
Some(Node::Item(..)) |
Some(Node::ImplItem(..)) |
Some(Node::ForeignItem(..)) |
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
// tuple struct constructor function
let id = self.struct_constructors.get(&id).cloned().unwrap_or(id);

if let Some(node) = self.tcx.hir().find_by_hir_id(id) {
if let Some(node) = self.tcx.hir().find(id) {
self.live_symbols.insert(id);
self.visit_node(node);
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ use std::{fmt, u32};
use std::io::prelude::*;
use std::io;
use std::rc::Rc;
use syntax::ast::{self, NodeId};
use syntax::ast;
use syntax::ptr::P;
use syntax::symbol::{kw, sym};
use syntax_pos::Span;
Expand Down Expand Up @@ -369,7 +369,7 @@ fn visit_fn<'tcx>(
// Don't run unused pass for #[derive()]
if let FnKind::Method(..) = fk {
let parent = ir.tcx.hir().get_parent_item(id);
if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) {
if let Some(Node::Item(i)) = ir.tcx.hir().find(parent) {
if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) {
return;
}
Expand Down Expand Up @@ -1327,12 +1327,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}

fn access_var(&mut self, hir_id: HirId, nid: NodeId, succ: LiveNode, acc: u32, span: Span)
fn access_var(&mut self, hir_id: HirId, var_hid: HirId, succ: LiveNode, acc: u32, span: Span)
-> LiveNode {
let ln = self.live_node(hir_id, span);
if acc != 0 {
self.init_from_succ(ln, succ);
let var_hid = self.ir.tcx.hir().node_to_hir_id(nid);
let var = self.variable(var_hid, span);
self.acc(ln, var, acc);
}
Expand All @@ -1345,8 +1344,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
Res::Local(hid) => {
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
if !upvars.map_or(false, |upvars| upvars.contains_key(&hid)) {
let nid = self.ir.tcx.hir().hir_to_node_id(hid);
self.access_var(hir_id, nid, succ, acc, path.span)
self.access_var(hir_id, hid, succ, acc, path.span)
} else {
succ
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ impl<'tcx> cmt_<'tcx> {
"non-place".into()
}
Categorization::Local(vid) => {
if tcx.hir().is_argument(tcx.hir().hir_to_node_id(vid)) {
if tcx.hir().is_argument(vid) {
"argument"
} else {
"local variable"
Expand Down
Loading