Skip to content

Commit cb7e369

Browse files
Use named fields for OpaqueTyOrigin
1 parent f95bdf4 commit cb7e369

19 files changed

Lines changed: 53 additions & 40 deletions

File tree

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15551555
.map(|(ident, id, _)| Lifetime{ id, ident })
15561556
.collect()
15571557
}
1558-
hir::OpaqueTyOrigin::FnReturn(..) => {
1558+
hir::OpaqueTyOrigin::FnReturn{ .. } => {
15591559
ifmatches!(
15601560
fn_kind.expect("expected RPITs to be lowered with a FnKind"),
15611561
FnDeclKind::Impl | FnDeclKind::Trait
@@ -1576,7 +1576,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15761576
lifetime_collector::lifetimes_in_bounds(self.resolver, bounds)
15771577
}
15781578
}
1579-
hir::OpaqueTyOrigin::AsyncFn(..) => {
1579+
hir::OpaqueTyOrigin::AsyncFn{ .. } => {
15801580
unreachable!("should be using `lower_async_fn_ret_ty`")
15811581
}
15821582
}
@@ -1867,7 +1867,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18671867
| FnDeclKind::Inherent
18681868
| FnDeclKind::Trait
18691869
| FnDeclKind::Impl => ImplTraitContext::OpaqueTy{
1870-
origin: hir::OpaqueTyOrigin::FnReturn(self.local_def_id(fn_node_id)),
1870+
origin: hir::OpaqueTyOrigin::FnReturn{
1871+
parent:self.local_def_id(fn_node_id),
1872+
},
18711873
fn_kind:Some(kind),
18721874
},
18731875
FnDeclKind::ExternFn => {
@@ -1952,7 +1954,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19521954

19531955
let opaque_ty_ref = self.lower_opaque_inner(
19541956
opaque_ty_node_id,
1955-
hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
1957+
hir::OpaqueTyOrigin::AsyncFn{parent:fn_def_id},
19561958
matches!(fn_kind,FnDeclKind::Trait),
19571959
captured_lifetimes,
19581960
span,
@@ -1963,7 +1965,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19631965
coro,
19641966
opaque_ty_span,
19651967
ImplTraitContext::OpaqueTy{
1966-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1968+
origin: hir::OpaqueTyOrigin::FnReturn{parent:fn_def_id},
19671969
fn_kind:Some(fn_kind),
19681970
},
19691971
);

‎compiler/rustc_borrowck/src/region_infer/opaque_types.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ impl<'tcx> LazyOpaqueTyEnv<'tcx> {
503503
let&Self{ tcx, def_id, .. } = self;
504504
let origin = tcx.opaque_type_origin(def_id);
505505
let parent = match origin {
506-
hir::OpaqueTyOrigin::FnReturn(parent)
507-
| hir::OpaqueTyOrigin::AsyncFn(parent)
506+
hir::OpaqueTyOrigin::FnReturn{parent}
507+
| hir::OpaqueTyOrigin::AsyncFn{parent}
508508
| hir::OpaqueTyOrigin::TyAlias{ parent, .. } => parent,
509509
};
510510
let param_env = tcx.param_env(parent);

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,9 +2806,15 @@ pub struct PreciseCapturingNonLifetimeArg {
28062806
#[derive(Copy,Clone,PartialEq,Eq,Debug,HashStable_Generic)]
28072807
pubenumOpaqueTyOrigin{
28082808
/// `-> impl Trait`
2809-
FnReturn(LocalDefId),
2809+
FnReturn{
2810+
/// The defining function.
2811+
parent:LocalDefId,
2812+
},
28102813
/// `async fn`
2811-
AsyncFn(LocalDefId),
2814+
AsyncFn{
2815+
/// The defining function.
2816+
parent:LocalDefId,
2817+
},
28122818
/// type aliases: `type Foo = impl Trait;`
28132819
TyAlias{
28142820
/// The type alias or associated type parent of the TAIT/ATPIT

‎compiler/rustc_hir_analysis/src/check/check.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,18 @@ fn check_opaque_meets_bounds<'tcx>(
336336
origin:&hir::OpaqueTyOrigin,
337337
) -> Result<(),ErrorGuaranteed>{
338338
let defining_use_anchor = match*origin {
339-
hir::OpaqueTyOrigin::FnReturn(did)
340-
| hir::OpaqueTyOrigin::AsyncFn(did)
341-
| hir::OpaqueTyOrigin::TyAlias{parent: did, .. } => did,
339+
hir::OpaqueTyOrigin::FnReturn{ parent }
340+
| hir::OpaqueTyOrigin::AsyncFn{ parent }
341+
| hir::OpaqueTyOrigin::TyAlias{ parent, .. } => parent,
342342
};
343343
let param_env = tcx.param_env(defining_use_anchor);
344344

345345
let infcx = tcx.infer_ctxt().with_opaque_type_inference(defining_use_anchor).build();
346346
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
347347

348348
let args = match*origin {
349-
hir::OpaqueTyOrigin::FnReturn(parent)
350-
| hir::OpaqueTyOrigin::AsyncFn(parent)
349+
hir::OpaqueTyOrigin::FnReturn{parent}
350+
| hir::OpaqueTyOrigin::AsyncFn{parent}
351351
| hir::OpaqueTyOrigin::TyAlias{ parent, .. } => GenericArgs::identity_for_item(
352352
tcx, parent,
353353
)
@@ -409,7 +409,7 @@ fn check_opaque_meets_bounds<'tcx>(
409409
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);
410410
ocx.resolve_regions_and_report_errors(defining_use_anchor,&outlives_env)?;
411411

412-
iflet hir::OpaqueTyOrigin::FnReturn(..)| hir::OpaqueTyOrigin::AsyncFn(..) = origin {
412+
iflet hir::OpaqueTyOrigin::FnReturn{ .. }| hir::OpaqueTyOrigin::AsyncFn{ .. } = origin {
413413
// HACK: this should also fall through to the hidden type check below, but the original
414414
// implementation had a bug where equivalent lifetimes are not identical. This caused us
415415
// to reject existing stable code that is otherwise completely fine. The real fix is to
@@ -736,8 +736,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
736736
check_opaque_precise_captures(tcx, def_id);
737737

738738
let origin = tcx.opaque_type_origin(def_id);
739-
iflet hir::OpaqueTyOrigin::FnReturn(fn_def_id)
740-
| hir::OpaqueTyOrigin::AsyncFn(fn_def_id) = origin
739+
iflet hir::OpaqueTyOrigin::FnReturn{parent:fn_def_id}
740+
| hir::OpaqueTyOrigin::AsyncFn{parent:fn_def_id} = origin
741741
&& let hir::Node::TraitItem(trait_item) = tcx.hir_node_by_def_id(fn_def_id)
742742
&& let(_, hir::TraitFn::Required(..)) = trait_item.expect_fn()
743743
{

‎compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
9494
if !tcx.hir().get_if_local(impl_opaque.def_id).is_some_and(|node| {
9595
matches!(
9696
node.expect_item().expect_opaque_ty().origin,
97-
hir::OpaqueTyOrigin::AsyncFn(def_id)| hir::OpaqueTyOrigin::FnReturn(def_id)
98-
ifdef_id == impl_m.def_id.expect_local()
97+
hir::OpaqueTyOrigin::AsyncFn{ parent }| hir::OpaqueTyOrigin::FnReturn{ parent }
98+
ifparent == impl_m.def_id.expect_local()
9999
)
100100
}){
101101
report_mismatched_rpitit_signature(

‎compiler/rustc_hir_analysis/src/collect/generics_of.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
210210
Node::Item(item) => match item.kind{
211211
ItemKind::OpaqueTy(&hir::OpaqueTy{
212212
origin:
213-
hir::OpaqueTyOrigin::FnReturn(fn_def_id) | hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
213+
hir::OpaqueTyOrigin::FnReturn{parent: fn_def_id }
214+
| hir::OpaqueTyOrigin::AsyncFn{parent: fn_def_id },
214215
in_trait,
215216
..
216217
}) => {

‎compiler/rustc_hir_analysis/src/collect/item_bounds.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ pub(super) fn explicit_item_bounds_with_filter(
388388
span,
389389
..
390390
}) => {
391-
let(hir::OpaqueTyOrigin::FnReturn(fn_def_id)
392-
| hir::OpaqueTyOrigin::AsyncFn(fn_def_id)) = *origin
391+
let(hir::OpaqueTyOrigin::FnReturn{parent:fn_def_id}
392+
| hir::OpaqueTyOrigin::AsyncFn{parent:fn_def_id}) = *origin
393393
else{
394394
span_bug!(*span,"RPITIT cannot be a TAIT, but got origin {origin:?}");
395395
};

‎compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
515515
}
516516
hir::ItemKind::OpaqueTy(&hir::OpaqueTy{
517517
origin:
518-
hir::OpaqueTyOrigin::FnReturn(parent)
519-
| hir::OpaqueTyOrigin::AsyncFn(parent)
518+
hir::OpaqueTyOrigin::FnReturn{parent}
519+
| hir::OpaqueTyOrigin::AsyncFn{parent}
520520
| hir::OpaqueTyOrigin::TyAlias{ parent, .. },
521521
generics,
522522
..

‎compiler/rustc_hir_analysis/src/collect/type_of.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,8 @@ pub(super) fn type_of_opaque(
618618
// Opaque types desugared from `impl Trait`.
619619
ItemKind::OpaqueTy(&OpaqueTy{
620620
origin:
621-
hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner),
621+
hir::OpaqueTyOrigin::FnReturn{parent: owner }
622+
| hir::OpaqueTyOrigin::AsyncFn{parent: owner },
622623
in_trait,
623624
..
624625
}) => {

‎compiler/rustc_hir_typeck/src/_match.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
602602
.map(|(k, _)| (k.def_id, k.args))?,
603603
_ => returnNone,
604604
};
605-
let hir::OpaqueTyOrigin::FnReturn(parent_def_id) = self.tcx.opaque_type_origin(def_id)
605+
let hir::OpaqueTyOrigin::FnReturn{parent: parent_def_id } =
606+
self.tcx.opaque_type_origin(def_id)
606607
else{
607608
returnNone;
608609
};

0 commit comments

Comments
 (0)