Skip to content

Commit

Permalink
Rollup merge of #108923 - spastorino:new-rpitit-9, r=compiler-errors
Browse files Browse the repository at this point in the history
Make fns from other crates with RPITIT work for -Zlower-impl-trait-in-trait-to-assoc-ty

Only the last two commits are meaningful.

r? `@compiler-errors`
  • Loading branch information
matthiaskrgr authored Mar 14, 2023
2 parents 6e3a3de + a4e4037 commit 21d15db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,12 @@ impl DefPathData {
match *self {
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),

// We use this name when collecting `ModChild`s.
// FIXME this could probably be removed with some refactoring to the name resolver.
ImplTraitAssocTy => Some(kw::Empty),

Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
| ImplTrait | ImplTraitAssocTy => None,
| ImplTrait => None,
}
}

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,13 +1356,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
let tcx = self.tcx;

let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
self.tables.impl_defaultness.set_some(def_id.index, ast_item.defaultness);
let defaultness = self.tcx.impl_defaultness(def_id.expect_local());
self.tables.impl_defaultness.set_some(def_id.index, defaultness);
let impl_item = self.tcx.associated_item(def_id);
self.tables.assoc_container.set_some(def_id.index, impl_item.container);

match impl_item.kind {
ty::AssocKind::Fn => {
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_ty_utils/src/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ fn impl_associated_item_for_impl_trait_in_trait(
// `opt_local_def_id_to_hir_id` with `None`.
impl_assoc_ty.opt_local_def_id_to_hir_id(None);

// Copy span of the opaque.
impl_assoc_ty.def_ident_span(Some(span));

impl_assoc_ty.associated_item(ty::AssocItem {
name: kw::Empty,
kind: ty::AssocKind::Type,
Expand All @@ -342,6 +345,9 @@ fn impl_associated_item_for_impl_trait_in_trait(
// extra predicates to assume.
impl_assoc_ty.param_env(tcx.param_env(impl_fn_def_id));

// Copy visility of the containing function.
impl_assoc_ty.visibility(tcx.visibility(impl_fn_def_id));

// Copy impl_defaultness of the containing function.
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/impl-trait/in-trait/foreign.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// check-pass
// aux-build: rpitit.rs
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

extern crate rpitit;

Expand Down

0 comments on commit 21d15db

Please sign in to comment.