Skip to content

Commit

Permalink
Auto merge of #68893 - Dylan-DPC:rollup-3f2421a, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #68691 (Remove `RefCell` usage from `ObligationForest`.)
 - #68751 (Implement `unused_parens` for `const` and `static` items)
 - #68788 (Towards unified `fn` grammar)
 - #68837 (Make associated item collection a query)
 - #68842 (or_patterns: add regression test for #68785)
 - #68844 (use def_path_str for missing_debug_impls message)
 - #68845 (stop using BytePos for computing spans in librustc_parse/parser/mod.rs)
 - #68869 (clean up E0271 explanation)
 - #68880 (Forbid using `0` as issue number)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Feb 6, 2020
2 parents 1f8df25 + 1ad674a commit 442ae7f
Show file tree
Hide file tree
Showing 75 changed files with 1,205 additions and 756 deletions.
5 changes: 5 additions & 0 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ rustc_queries! {
/// Maps from a trait item to the trait item "descriptor".
query associated_item(_: DefId) -> ty::AssocItem {}

/// Collects the associated items defined on a trait or impl.
query associated_items(key: DefId) -> ty::AssocItemsIterator<'tcx> {
desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
}

query impl_trait_ref(_: DefId) -> Option<ty::TraitRef<'tcx>> {}
query impl_polarity(_: DefId) -> ty::ImplPolarity {}

Expand Down
31 changes: 10 additions & 21 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2743,19 +2743,6 @@ impl<'tcx> TyCtxt<'tcx> {
variant.fields.iter().position(|field| self.hygienic_eq(ident, field.ident, variant.def_id))
}

pub fn associated_items(self, def_id: DefId) -> AssocItemsIterator<'tcx> {
// Ideally, we would use `-> impl Iterator` here, but it falls
// afoul of the conservative "capture [restrictions]" we put
// in place, so we use a hand-written iterator.
//
// [restrictions]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
AssocItemsIterator {
tcx: self,
def_ids: self.associated_item_def_ids(def_id),
next_index: 0,
}
}

/// Returns `true` if the impls are the same polarity and the trait either
/// has no items or is annotated #[marker] and prevents item overrides.
pub fn impls_are_allowed_to_overlap(
Expand Down Expand Up @@ -2987,20 +2974,22 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

#[derive(Clone)]
#[derive(Copy, Clone, HashStable)]
pub struct AssocItemsIterator<'tcx> {
tcx: TyCtxt<'tcx>,
def_ids: &'tcx [DefId],
next_index: usize,
pub items: &'tcx [AssocItem],
}

impl Iterator for AssocItemsIterator<'_> {
impl<'tcx> Iterator for AssocItemsIterator<'tcx> {
type Item = AssocItem;

#[inline]
fn next(&mut self) -> Option<AssocItem> {
let def_id = self.def_ids.get(self.next_index)?;
self.next_index += 1;
Some(self.tcx.associated_item(*def_id))
if let Some((first, rest)) = self.items.split_first() {
self.items = rest;
Some(*first)
} else {
None
}
}
}

Expand Down
48 changes: 22 additions & 26 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rustc_target::spec::abi;
use syntax::ast::*;
use syntax::attr;
use syntax::node_id::NodeMap;
use syntax::visit::{self, Visitor};
use syntax::visit::{self, AssocCtxt, Visitor};

use log::debug;
use smallvec::{smallvec, SmallVec};
Expand Down Expand Up @@ -81,25 +81,23 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
}
}

fn visit_trait_item(&mut self, item: &'a AssocItem) {
self.lctx.with_hir_id_owner(item.id, |lctx| {
let hir_item = lctx.lower_trait_item(item);
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
lctx.trait_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
self.lctx.with_hir_id_owner(item.id, |lctx| match ctxt {
AssocCtxt::Trait => {
let hir_item = lctx.lower_trait_item(item);
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
lctx.trait_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
}
AssocCtxt::Impl => {
let hir_item = lctx.lower_impl_item(item);
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
lctx.impl_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
}
});

visit::walk_trait_item(self, item);
}

fn visit_impl_item(&mut self, item: &'a AssocItem) {
self.lctx.with_hir_id_owner(item.id, |lctx| {
let hir_item = lctx.lower_impl_item(item);
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
lctx.impl_items.insert(id, hir_item);
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
});
visit::walk_impl_item(self, item);
visit::walk_assoc_item(self, item, ctxt);
}
}

Expand Down Expand Up @@ -299,20 +297,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `impl Future<Output = T>` here because lower_body
// only cares about the input argument patterns in the function
// declaration (decl), not the return types.
let asyncness = header.asyncness.node;
let body_id =
this.lower_maybe_async_body(span, &decl, header.asyncness.node, Some(body));
this.lower_maybe_async_body(span, &decl, asyncness, body.as_deref());

let (generics, decl) = this.add_in_band_defs(
generics,
fn_def_id,
AnonymousLifetimeMode::PassThrough,
|this, idty| {
this.lower_fn_decl(
&decl,
Some((fn_def_id, idty)),
true,
header.asyncness.node.opt_return_id(),
)
let ret_id = asyncness.opt_return_id();
this.lower_fn_decl(&decl, Some((fn_def_id, idty)), true, ret_id)
},
);
let sig = hir::FnSig { decl, header: this.lower_fn_header(header) };
Expand Down Expand Up @@ -658,7 +653,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
kind: match i.kind {
ForeignItemKind::Fn(ref fdec, ref generics) => {
ForeignItemKind::Fn(ref sig, ref generics, _) => {
let fdec = &sig.decl;
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
generics,
def_id,
Expand Down
28 changes: 9 additions & 19 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#![feature(array_value_iter)]
#![feature(crate_visibility_modifier)]
#![recursion_limit = "256"]

use rustc::arena::Arena;
use rustc::dep_graph::DepGraph;
Expand Down Expand Up @@ -63,7 +64,7 @@ use syntax::attr;
use syntax::node_id::NodeMap;
use syntax::token::{self, Nonterminal, Token};
use syntax::tokenstream::{TokenStream, TokenTree};
use syntax::visit::{self, Visitor};
use syntax::visit::{self, AssocCtxt, Visitor};
use syntax::walk_list;

use log::{debug, trace};
Expand Down Expand Up @@ -485,25 +486,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
});
}

fn visit_trait_item(&mut self, item: &'tcx AssocItem) {
fn visit_assoc_item(&mut self, item: &'tcx AssocItem, ctxt: AssocCtxt) {
self.lctx.allocate_hir_id_counter(item.id);

match item.kind {
AssocItemKind::Fn(_, None) => {
// Ignore patterns in trait methods without bodies
self.with_hir_id_owner(None, |this| visit::walk_trait_item(this, item));
}
_ => self.with_hir_id_owner(Some(item.id), |this| {
visit::walk_trait_item(this, item);
}),
}
}

fn visit_impl_item(&mut self, item: &'tcx AssocItem) {
self.lctx.allocate_hir_id_counter(item.id);
self.with_hir_id_owner(Some(item.id), |this| {
visit::walk_impl_item(this, item);
});
let owner = match (&item.kind, ctxt) {
// Ignore patterns in trait methods without bodies.
(AssocItemKind::Fn(_, None), AssocCtxt::Trait) => None,
_ => Some(item.id),
};
self.with_hir_id_owner(owner, |this| visit::walk_assoc_item(this, item, ctxt));
}

fn visit_foreign_item(&mut self, i: &'tcx ForeignItem) {
Expand Down
Loading

0 comments on commit 442ae7f

Please sign in to comment.