Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 66c9cd9

Browse files
committed
Remove OpaqueTyOrigin::Binding
1 parent eb0b95b commit 66c9cd9

33 files changed

+84
-734
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ enum ImplTraitContext<'b, 'a> {
264264
/// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
265265
origin: hir::OpaqueTyOrigin,
266266
},
267-
/// Impl trait in type aliases, consts and statics.
267+
/// Impl trait in type aliases.
268268
OtherOpaqueTy {
269269
/// Set of lifetimes that this opaque type can capture, if it uses
270270
/// them. This includes lifetimes bound since we entered this context.
@@ -1767,21 +1767,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17671767
}
17681768

17691769
fn lower_local(&mut self, l: &Local) -> hir::Local<'hir> {
1770-
let ty = l.ty.as_ref().map(|t| {
1771-
let mut capturable_lifetimes;
1772-
self.lower_ty(
1773-
t,
1774-
if self.sess.features_untracked().impl_trait_in_bindings {
1775-
capturable_lifetimes = FxHashSet::default();
1776-
ImplTraitContext::OtherOpaqueTy {
1777-
capturable_lifetimes: &mut capturable_lifetimes,
1778-
origin: hir::OpaqueTyOrigin::Binding,
1779-
}
1780-
} else {
1781-
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
1782-
},
1783-
)
1784-
});
1770+
let ty = l
1771+
.ty
1772+
.as_ref()
1773+
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Binding)));
17851774
let init = l.init.as_ref().map(|e| self.lower_expr(e));
17861775
let hir_id = self.lower_node_id(l.id);
17871776
self.lower_attrs(hir_id, &l.attrs);

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,8 +2270,6 @@ pub enum OpaqueTyOrigin {
22702270
FnReturn,
22712271
/// `async fn`
22722272
AsyncFn,
2273-
/// `let _: impl Trait = ...`
2274-
Binding,
22752273
/// type aliases: `type Foo = impl Trait;`
22762274
TyAlias,
22772275
/// Impl trait consts, statics, bounds.

compiler/rustc_trait_selection/src/opaque_types.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
402402
}
403403
// These opaque type inherit all lifetime parameters from their
404404
// parent, so we have to check them all.
405-
hir::OpaqueTyOrigin::Binding
406-
| hir::OpaqueTyOrigin::TyAlias
407-
| hir::OpaqueTyOrigin::Misc => 0,
405+
hir::OpaqueTyOrigin::TyAlias | hir::OpaqueTyOrigin::Misc => 0,
408406
};
409407

410408
let span = tcx.def_span(def_id);

compiler/rustc_typeck/src/check/check.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,9 @@ pub(super) fn check_opaque_for_cycles<'tcx>(
665665
span: Span,
666666
origin: &hir::OpaqueTyOrigin,
667667
) -> Result<(), ErrorReported> {
668-
if let Err(partially_expanded_type) = tcx.try_expand_impl_trait_type(def_id.to_def_id(), substs)
669-
{
668+
if tcx.try_expand_impl_trait_type(def_id.to_def_id(), substs).is_err() {
670669
match origin {
671670
hir::OpaqueTyOrigin::AsyncFn => async_opaque_type_cycle_error(tcx, span),
672-
hir::OpaqueTyOrigin::Binding => {
673-
binding_opaque_type_cycle_error(tcx, def_id, span, partially_expanded_type)
674-
}
675671
_ => opaque_type_cycle_error(tcx, def_id, span),
676672
}
677673
Err(ErrorReported)
@@ -704,8 +700,7 @@ fn check_opaque_meets_bounds<'tcx>(
704700
// Checked when type checking the function containing them.
705701
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => return,
706702
// Can have different predicates to their defining use
707-
hir::OpaqueTyOrigin::Binding | hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias => {
708-
}
703+
hir::OpaqueTyOrigin::Misc | hir::OpaqueTyOrigin::TyAlias => {}
709704
}
710705

711706
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -573,66 +573,6 @@ fn get_owner_return_paths(
573573
})
574574
}
575575

576-
/// Emit an error for recursive opaque types in a `let` binding.
577-
fn binding_opaque_type_cycle_error(
578-
tcx: TyCtxt<'tcx>,
579-
def_id: LocalDefId,
580-
span: Span,
581-
partially_expanded_type: Ty<'tcx>,
582-
) {
583-
let mut err = struct_span_err!(tcx.sess, span, E0720, "cannot resolve opaque type");
584-
err.span_label(span, "cannot resolve opaque type");
585-
// Find the owner that declared this `impl Trait` type.
586-
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
587-
let mut prev_hir_id = hir_id;
588-
let mut hir_id = tcx.hir().get_parent_node(hir_id);
589-
while let Some(node) = tcx.hir().find(hir_id) {
590-
match node {
591-
hir::Node::Local(hir::Local {
592-
pat,
593-
init: None,
594-
ty: Some(ty),
595-
source: hir::LocalSource::Normal,
596-
..
597-
}) => {
598-
err.span_label(pat.span, "this binding might not have a concrete type");
599-
err.span_suggestion_verbose(
600-
ty.span.shrink_to_hi(),
601-
"set the binding to a value for a concrete type to be resolved",
602-
" = /* value */".to_string(),
603-
Applicability::HasPlaceholders,
604-
);
605-
}
606-
hir::Node::Local(hir::Local {
607-
init: Some(expr),
608-
source: hir::LocalSource::Normal,
609-
..
610-
}) => {
611-
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
612-
let typeck_results =
613-
tcx.typeck(tcx.hir().local_def_id(tcx.hir().get_parent_item(hir_id)));
614-
if let Some(ty) = typeck_results.node_type_opt(expr.hir_id) {
615-
err.span_label(
616-
expr.span,
617-
&format!(
618-
"this is of type `{}`, which doesn't constrain \
619-
`{}` enough to arrive to a concrete type",
620-
ty, partially_expanded_type
621-
),
622-
);
623-
}
624-
}
625-
_ => {}
626-
}
627-
if prev_hir_id == hir_id {
628-
break;
629-
}
630-
prev_hir_id = hir_id;
631-
hir_id = tcx.hir().get_parent_node(hir_id);
632-
}
633-
err.emit();
634-
}
635-
636576
// Forbid defining intrinsics in Rust code,
637577
// as they must always be defined by the compiler.
638578
fn fn_maybe_err(tcx: TyCtxt<'_>, sp: Span, abi: Abi) {

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,6 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
356356
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
357357
tcx.mk_adt(def, substs)
358358
}
359-
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::Binding, .. }) => {
360-
let_position_impl_trait_type(tcx, def_id)
361-
}
362359
ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: None, .. }) => {
363360
find_opaque_ty_constraints(tcx, def_id)
364361
}
@@ -696,60 +693,6 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
696693
}
697694
}
698695

699-
/// Retrieve the inferred concrete type for let position impl trait.
700-
///
701-
/// This is different to other kinds of impl trait because:
702-
///
703-
/// 1. We know which function contains the defining use (the function that
704-
/// contains the let statement)
705-
/// 2. We do not currently allow (free) lifetimes in the return type. `let`
706-
/// statements in some statically unreachable code are removed from the MIR
707-
/// by the time we borrow check, and it's not clear how we should handle
708-
/// those.
709-
fn let_position_impl_trait_type(tcx: TyCtxt<'_>, opaque_ty_id: LocalDefId) -> Ty<'_> {
710-
let scope = tcx.hir().get_defining_scope(tcx.hir().local_def_id_to_hir_id(opaque_ty_id));
711-
let scope_def_id = tcx.hir().local_def_id(scope);
712-
713-
let opaque_ty_def_id = opaque_ty_id.to_def_id();
714-
715-
let owner_typeck_results = tcx.typeck(scope_def_id);
716-
let concrete_ty = owner_typeck_results
717-
.concrete_opaque_types
718-
.get_by(|(key, _)| key.def_id == opaque_ty_def_id)
719-
.map(|concrete_ty| *concrete_ty)
720-
.unwrap_or_else(|| {
721-
tcx.sess.delay_span_bug(
722-
DUMMY_SP,
723-
&format!(
724-
"owner {:?} has no opaque type for {:?} in its typeck results",
725-
scope_def_id, opaque_ty_id
726-
),
727-
);
728-
if let Some(ErrorReported) = owner_typeck_results.tainted_by_errors {
729-
// Some error in the owner fn prevented us from populating the
730-
// `concrete_opaque_types` table.
731-
tcx.ty_error()
732-
} else {
733-
// We failed to resolve the opaque type or it resolves to
734-
// itself. Return the non-revealed type, which should result in
735-
// E0720.
736-
tcx.mk_opaque(
737-
opaque_ty_def_id,
738-
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id),
739-
)
740-
}
741-
});
742-
debug!("concrete_ty = {:?}", concrete_ty);
743-
if concrete_ty.has_erased_regions() {
744-
// FIXME(impl_trait_in_bindings) Handle this case.
745-
tcx.sess.span_fatal(
746-
tcx.hir().span(tcx.hir().local_def_id_to_hir_id(opaque_ty_id)),
747-
"lifetimes in impl Trait types in bindings are not currently supported",
748-
);
749-
}
750-
concrete_ty
751-
}
752-
753696
fn infer_placeholder_type<'a>(
754697
tcx: TyCtxt<'a>,
755698
def_id: LocalDefId,

0 commit comments

Comments
 (0)