Skip to content

Commit 0058748

Browse files
committed
Auto merge of rust-lang#109057 - compiler-errors:rpitit-info-again, r=spastorino
Don't `opt_rpitit_info` as a separate query ... another attempt to undo regressions r? `@ghost`
2 parents bd43458 + ce8dae5 commit 0058748

File tree

9 files changed

+31
-23
lines changed

9 files changed

+31
-23
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ impl<'tcx> Pick<'tcx> {
13391339
container: _,
13401340
trait_item_def_id: _,
13411341
fn_has_self_parameter: _,
1342+
opt_rpitit_info: _,
13421343
},
13431344
kind: _,
13441345
import_ids: _,

compiler/rustc_metadata/src/rmeta/decoder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10951095
trait_item_def_id: self.get_trait_item_def_id(id),
10961096
container,
10971097
fn_has_self_parameter: has_self,
1098+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): We need to encode this
1099+
opt_rpitit_info: None,
10981100
}
10991101
}
11001102

compiler/rustc_middle/src/hir/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ pub fn provide(providers: &mut Providers) {
177177
}
178178
};
179179
providers.opt_def_kind = |tcx, def_id| tcx.hir().opt_def_kind(def_id.expect_local());
180-
providers.opt_rpitit_info = |_, _| None;
181180
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
182181
providers.expn_that_defined = |tcx, id| {
183182
let id = id.expect_local();

compiler/rustc_middle/src/query/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1161,14 +1161,6 @@ rustc_queries! {
11611161
feedable
11621162
}
11631163

1164-
/// The `opt_rpitit_info` query returns the pair of the def id of the function where the RPIT
1165-
/// is defined and the opaque def id if any.
1166-
query opt_rpitit_info(def_id: DefId) -> Option<ty::ImplTraitInTraitData> {
1167-
desc { |tcx| "opt_rpitit_info `{}`", tcx.def_path_str(def_id) }
1168-
cache_on_disk_if { def_id.is_local() }
1169-
feedable
1170-
}
1171-
11721164
/// Gets the span for the definition.
11731165
query def_span(def_id: DefId) -> Span {
11741166
desc { |tcx| "looking up span for `{}`", tcx.def_path_str(def_id) }

compiler/rustc_middle/src/ty/assoc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ pub struct AssocItem {
3030
/// Whether this is a method with an explicit self
3131
/// as its first parameter, allowing method calls.
3232
pub fn_has_self_parameter: bool,
33+
34+
/// `Some` if the associated item (an associated type) comes from the
35+
/// return-position `impl Trait` in trait desugaring. The `ImplTraitInTraitData`
36+
/// provides additional information about its source.
37+
pub opt_rpitit_info: Option<ty::ImplTraitInTraitData>,
3338
}
3439

3540
impl AssocItem {

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,7 @@ impl<'tcx> TyCtxt<'tcx> {
24522452

24532453
pub fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
24542454
if self.lower_impl_trait_in_trait_to_assoc_ty() {
2455-
self.def_kind(def_id) == DefKind::AssocTy && self.opt_rpitit_info(def_id).is_some()
2455+
self.opt_rpitit_info(def_id).is_some()
24562456
} else {
24572457
self.def_kind(def_id) == DefKind::ImplTraitPlaceholder
24582458
}

compiler/rustc_middle/src/ty/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,9 @@ pub enum ImplOverlapKind {
20702070
Issue33140,
20712071
}
20722072

2073-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
2073+
/// Useful source information about where a desugared associated type for an
2074+
/// RPITIT originated from.
2075+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encodable, Decodable, HashStable)]
20742076
pub enum ImplTraitInTraitData {
20752077
Trait { fn_def_id: DefId, opaque_def_id: DefId },
20762078
Impl { fn_def_id: DefId },
@@ -2213,6 +2215,17 @@ impl<'tcx> TyCtxt<'tcx> {
22132215
}
22142216
}
22152217

2218+
/// If the def-id is an associated type that was desugared from a
2219+
/// return-position `impl Trait` from a trait, then provide the source info
2220+
/// about where that RPITIT came from.
2221+
pub fn opt_rpitit_info(self, def_id: DefId) -> Option<ImplTraitInTraitData> {
2222+
if let DefKind::AssocTy = self.def_kind(def_id) {
2223+
self.associated_item(def_id).opt_rpitit_info
2224+
} else {
2225+
None
2226+
}
2227+
}
2228+
22162229
pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<usize> {
22172230
variant
22182231
.fields

compiler/rustc_passes/src/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
244244
}
245245

246246
// Avoid accessing the HIR for the synthesized associated type generated for RPITITs.
247-
if self.tcx.opt_rpitit_info(id).is_some() {
247+
if self.tcx.opt_rpitit_info(id.to_def_id()).is_some() {
248248
self.live_symbols.insert(id);
249249
continue;
250250
}

compiler/rustc_ty_utils/src/assoc.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn associated_item_from_trait_item_ref(trait_item_ref: &hir::TraitItemRef) -> ty
153153
trait_item_def_id: Some(owner_id.to_def_id()),
154154
container: ty::TraitContainer,
155155
fn_has_self_parameter: has_self,
156+
opt_rpitit_info: None,
156157
}
157158
}
158159

@@ -171,6 +172,7 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
171172
trait_item_def_id: impl_item_ref.trait_item_def_id,
172173
container: ty::ImplContainer,
173174
fn_has_self_parameter: has_self,
175+
opt_rpitit_info: None,
174176
}
175177
}
176178

@@ -262,19 +264,17 @@ fn associated_item_for_impl_trait_in_trait(
262264
// Copy span of the opaque.
263265
trait_assoc_ty.def_ident_span(Some(span));
264266

265-
// Add the def_id of the function and opaque that generated this synthesized associated type.
266-
trait_assoc_ty.opt_rpitit_info(Some(ImplTraitInTraitData::Trait {
267-
fn_def_id,
268-
opaque_def_id: opaque_ty_def_id.to_def_id(),
269-
}));
270-
271267
trait_assoc_ty.associated_item(ty::AssocItem {
272268
name: kw::Empty,
273269
kind: ty::AssocKind::Type,
274270
def_id,
275271
trait_item_def_id: None,
276272
container: ty::TraitContainer,
277273
fn_has_self_parameter: false,
274+
opt_rpitit_info: Some(ImplTraitInTraitData::Trait {
275+
fn_def_id,
276+
opaque_def_id: opaque_ty_def_id.to_def_id(),
277+
}),
278278
});
279279

280280
// Copy visility of the containing function.
@@ -328,18 +328,14 @@ 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-
// Add the def_id of the function that generated this synthesized associated type.
332-
impl_assoc_ty.opt_rpitit_info(Some(ImplTraitInTraitData::Impl {
333-
fn_def_id: impl_fn_def_id.to_def_id(),
334-
}));
335-
336331
impl_assoc_ty.associated_item(ty::AssocItem {
337332
name: kw::Empty,
338333
kind: ty::AssocKind::Type,
339334
def_id,
340335
trait_item_def_id: Some(trait_assoc_def_id.to_def_id()),
341336
container: ty::ImplContainer,
342337
fn_has_self_parameter: false,
338+
opt_rpitit_info: Some(ImplTraitInTraitData::Impl { fn_def_id: impl_fn_def_id.to_def_id() }),
343339
});
344340

345341
// Copy param_env of the containing function. The synthesized associated type doesn't have

0 commit comments

Comments
 (0)