Skip to content

Commit 21d15db

Browse files
authored
Rollup merge of #108923 - spastorino:new-rpitit-9, r=compiler-errors
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`
2 parents 6e3a3de + a4e4037 commit 21d15db

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

compiler/rustc_hir/src/definitions.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,12 @@ impl DefPathData {
404404
match *self {
405405
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
406406

407+
// We use this name when collecting `ModChild`s.
408+
// FIXME this could probably be removed with some refactoring to the name resolver.
409+
ImplTraitAssocTy => Some(kw::Empty),
410+
407411
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
408-
| ImplTrait | ImplTraitAssocTy => None,
412+
| ImplTrait => None,
409413
}
410414
}
411415

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1356,13 +1356,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13561356
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
13571357
let tcx = self.tcx;
13581358

1359-
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
1360-
self.tables.impl_defaultness.set_some(def_id.index, ast_item.defaultness);
1359+
let defaultness = self.tcx.impl_defaultness(def_id.expect_local());
1360+
self.tables.impl_defaultness.set_some(def_id.index, defaultness);
13611361
let impl_item = self.tcx.associated_item(def_id);
13621362
self.tables.assoc_container.set_some(def_id.index, impl_item.container);
13631363

13641364
match impl_item.kind {
13651365
ty::AssocKind::Fn => {
1366+
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
13661367
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
13671368
self.tables.asyncness.set_some(def_id.index, sig.header.asyncness);
13681369
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));

compiler/rustc_ty_utils/src/assoc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ fn impl_associated_item_for_impl_trait_in_trait(
328328
// `opt_local_def_id_to_hir_id` with `None`.
329329
impl_assoc_ty.opt_local_def_id_to_hir_id(None);
330330

331+
// Copy span of the opaque.
332+
impl_assoc_ty.def_ident_span(Some(span));
333+
331334
impl_assoc_ty.associated_item(ty::AssocItem {
332335
name: kw::Empty,
333336
kind: ty::AssocKind::Type,
@@ -342,6 +345,9 @@ fn impl_associated_item_for_impl_trait_in_trait(
342345
// extra predicates to assume.
343346
impl_assoc_ty.param_env(tcx.param_env(impl_fn_def_id));
344347

348+
// Copy visility of the containing function.
349+
impl_assoc_ty.visibility(tcx.visibility(impl_fn_def_id));
350+
345351
// Copy impl_defaultness of the containing function.
346352
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));
347353

tests/ui/impl-trait/in-trait/foreign.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// check-pass
22
// aux-build: rpitit.rs
3+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
4+
// revisions: current next
35

46
extern crate rpitit;
57

0 commit comments

Comments
 (0)