Skip to content

Commit 442ae7f

Browse files
committed
Auto merge of #68893 - Dylan-DPC:rollup-3f2421a, r=Dylan-DPC
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
2 parents 1f8df25 + 1ad674a commit 442ae7f

File tree

75 files changed

+1205
-756
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1205
-756
lines changed

Diff for: src/librustc/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ rustc_queries! {
310310
/// Maps from a trait item to the trait item "descriptor".
311311
query associated_item(_: DefId) -> ty::AssocItem {}
312312

313+
/// Collects the associated items defined on a trait or impl.
314+
query associated_items(key: DefId) -> ty::AssocItemsIterator<'tcx> {
315+
desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
316+
}
317+
313318
query impl_trait_ref(_: DefId) -> Option<ty::TraitRef<'tcx>> {}
314319
query impl_polarity(_: DefId) -> ty::ImplPolarity {}
315320

Diff for: src/librustc/ty/mod.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -2743,19 +2743,6 @@ impl<'tcx> TyCtxt<'tcx> {
27432743
variant.fields.iter().position(|field| self.hygienic_eq(ident, field.ident, variant.def_id))
27442744
}
27452745

2746-
pub fn associated_items(self, def_id: DefId) -> AssocItemsIterator<'tcx> {
2747-
// Ideally, we would use `-> impl Iterator` here, but it falls
2748-
// afoul of the conservative "capture [restrictions]" we put
2749-
// in place, so we use a hand-written iterator.
2750-
//
2751-
// [restrictions]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
2752-
AssocItemsIterator {
2753-
tcx: self,
2754-
def_ids: self.associated_item_def_ids(def_id),
2755-
next_index: 0,
2756-
}
2757-
}
2758-
27592746
/// Returns `true` if the impls are the same polarity and the trait either
27602747
/// has no items or is annotated #[marker] and prevents item overrides.
27612748
pub fn impls_are_allowed_to_overlap(
@@ -2987,20 +2974,22 @@ impl<'tcx> TyCtxt<'tcx> {
29872974
}
29882975
}
29892976

2990-
#[derive(Clone)]
2977+
#[derive(Copy, Clone, HashStable)]
29912978
pub struct AssocItemsIterator<'tcx> {
2992-
tcx: TyCtxt<'tcx>,
2993-
def_ids: &'tcx [DefId],
2994-
next_index: usize,
2979+
pub items: &'tcx [AssocItem],
29952980
}
29962981

2997-
impl Iterator for AssocItemsIterator<'_> {
2982+
impl<'tcx> Iterator for AssocItemsIterator<'tcx> {
29982983
type Item = AssocItem;
29992984

2985+
#[inline]
30002986
fn next(&mut self) -> Option<AssocItem> {
3001-
let def_id = self.def_ids.get(self.next_index)?;
3002-
self.next_index += 1;
3003-
Some(self.tcx.associated_item(*def_id))
2987+
if let Some((first, rest)) = self.items.split_first() {
2988+
self.items = rest;
2989+
Some(*first)
2990+
} else {
2991+
None
2992+
}
30042993
}
30052994
}
30062995

Diff for: src/librustc_ast_lowering/item.rs

+22-26
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_target::spec::abi;
1414
use syntax::ast::*;
1515
use syntax::attr;
1616
use syntax::node_id::NodeMap;
17-
use syntax::visit::{self, Visitor};
17+
use syntax::visit::{self, AssocCtxt, Visitor};
1818

1919
use log::debug;
2020
use smallvec::{smallvec, SmallVec};
@@ -81,25 +81,23 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
8181
}
8282
}
8383

84-
fn visit_trait_item(&mut self, item: &'a AssocItem) {
85-
self.lctx.with_hir_id_owner(item.id, |lctx| {
86-
let hir_item = lctx.lower_trait_item(item);
87-
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
88-
lctx.trait_items.insert(id, hir_item);
89-
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
84+
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
85+
self.lctx.with_hir_id_owner(item.id, |lctx| match ctxt {
86+
AssocCtxt::Trait => {
87+
let hir_item = lctx.lower_trait_item(item);
88+
let id = hir::TraitItemId { hir_id: hir_item.hir_id };
89+
lctx.trait_items.insert(id, hir_item);
90+
lctx.modules.get_mut(&lctx.current_module).unwrap().trait_items.insert(id);
91+
}
92+
AssocCtxt::Impl => {
93+
let hir_item = lctx.lower_impl_item(item);
94+
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
95+
lctx.impl_items.insert(id, hir_item);
96+
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
97+
}
9098
});
9199

92-
visit::walk_trait_item(self, item);
93-
}
94-
95-
fn visit_impl_item(&mut self, item: &'a AssocItem) {
96-
self.lctx.with_hir_id_owner(item.id, |lctx| {
97-
let hir_item = lctx.lower_impl_item(item);
98-
let id = hir::ImplItemId { hir_id: hir_item.hir_id };
99-
lctx.impl_items.insert(id, hir_item);
100-
lctx.modules.get_mut(&lctx.current_module).unwrap().impl_items.insert(id);
101-
});
102-
visit::walk_impl_item(self, item);
100+
visit::walk_assoc_item(self, item, ctxt);
103101
}
104102
}
105103

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

305304
let (generics, decl) = this.add_in_band_defs(
306305
generics,
307306
fn_def_id,
308307
AnonymousLifetimeMode::PassThrough,
309308
|this, idty| {
310-
this.lower_fn_decl(
311-
&decl,
312-
Some((fn_def_id, idty)),
313-
true,
314-
header.asyncness.node.opt_return_id(),
315-
)
309+
let ret_id = asyncness.opt_return_id();
310+
this.lower_fn_decl(&decl, Some((fn_def_id, idty)), true, ret_id)
316311
},
317312
);
318313
let sig = hir::FnSig { decl, header: this.lower_fn_header(header) };
@@ -658,7 +653,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
658653
ident: i.ident,
659654
attrs: self.lower_attrs(&i.attrs),
660655
kind: match i.kind {
661-
ForeignItemKind::Fn(ref fdec, ref generics) => {
656+
ForeignItemKind::Fn(ref sig, ref generics, _) => {
657+
let fdec = &sig.decl;
662658
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
663659
generics,
664660
def_id,

Diff for: src/librustc_ast_lowering/lib.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
3333
#![feature(array_value_iter)]
3434
#![feature(crate_visibility_modifier)]
35+
#![recursion_limit = "256"]
3536

3637
use rustc::arena::Arena;
3738
use rustc::dep_graph::DepGraph;
@@ -63,7 +64,7 @@ use syntax::attr;
6364
use syntax::node_id::NodeMap;
6465
use syntax::token::{self, Nonterminal, Token};
6566
use syntax::tokenstream::{TokenStream, TokenTree};
66-
use syntax::visit::{self, Visitor};
67+
use syntax::visit::{self, AssocCtxt, Visitor};
6768
use syntax::walk_list;
6869

6970
use log::{debug, trace};
@@ -485,25 +486,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
485486
});
486487
}
487488

488-
fn visit_trait_item(&mut self, item: &'tcx AssocItem) {
489+
fn visit_assoc_item(&mut self, item: &'tcx AssocItem, ctxt: AssocCtxt) {
489490
self.lctx.allocate_hir_id_counter(item.id);
490-
491-
match item.kind {
492-
AssocItemKind::Fn(_, None) => {
493-
// Ignore patterns in trait methods without bodies
494-
self.with_hir_id_owner(None, |this| visit::walk_trait_item(this, item));
495-
}
496-
_ => self.with_hir_id_owner(Some(item.id), |this| {
497-
visit::walk_trait_item(this, item);
498-
}),
499-
}
500-
}
501-
502-
fn visit_impl_item(&mut self, item: &'tcx AssocItem) {
503-
self.lctx.allocate_hir_id_counter(item.id);
504-
self.with_hir_id_owner(Some(item.id), |this| {
505-
visit::walk_impl_item(this, item);
506-
});
491+
let owner = match (&item.kind, ctxt) {
492+
// Ignore patterns in trait methods without bodies.
493+
(AssocItemKind::Fn(_, None), AssocCtxt::Trait) => None,
494+
_ => Some(item.id),
495+
};
496+
self.with_hir_id_owner(owner, |this| visit::walk_assoc_item(this, item, ctxt));
507497
}
508498

509499
fn visit_foreign_item(&mut self, i: &'tcx ForeignItem) {

0 commit comments

Comments
 (0)