Skip to content

Commit a72c360

Browse files
committed
Auto merge of #87141 - spastorino:remove_impl_trait_in_bindings, r=oli-obk
Remove impl trait in bindings Closes #86729 r? `@oli-obk`
2 parents c9aa259 + 3e857f5 commit a72c360

File tree

113 files changed

+536
-1950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+536
-1950
lines changed

compiler/rustc_ast_lowering/src/item.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
343343
// opaque type Foo1: Trait
344344
let ty = self.lower_ty(
345345
ty,
346-
ImplTraitContext::OtherOpaqueTy {
346+
ImplTraitContext::TypeAliasesOpaqueTy {
347347
capturable_lifetimes: &mut FxHashSet::default(),
348-
origin: hir::OpaqueTyOrigin::TyAlias,
349348
},
350349
);
351350
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
@@ -484,17 +483,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
484483
span: Span,
485484
body: Option<&Expr>,
486485
) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
487-
let mut capturable_lifetimes;
488-
let itctx = if self.sess.features_untracked().impl_trait_in_bindings {
489-
capturable_lifetimes = FxHashSet::default();
490-
ImplTraitContext::OtherOpaqueTy {
491-
capturable_lifetimes: &mut capturable_lifetimes,
492-
origin: hir::OpaqueTyOrigin::Misc,
493-
}
494-
} else {
495-
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
496-
};
497-
let ty = self.lower_ty(ty, itctx);
486+
let ty = self.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::Binding));
498487
(ty, self.lower_const_body(span, body))
499488
}
500489

@@ -926,9 +915,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
926915
Some(ty) => {
927916
let ty = self.lower_ty(
928917
ty,
929-
ImplTraitContext::OtherOpaqueTy {
918+
ImplTraitContext::TypeAliasesOpaqueTy {
930919
capturable_lifetimes: &mut FxHashSet::default(),
931-
origin: hir::OpaqueTyOrigin::TyAlias,
932920
},
933921
);
934922
hir::ImplItemKind::TyAlias(ty)

compiler/rustc_ast_lowering/src/lib.rs

+21-43
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ 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.
268-
OtherOpaqueTy {
267+
/// Impl trait in type aliases.
268+
TypeAliasesOpaqueTy {
269269
/// Set of lifetimes that this opaque type can capture, if it uses
270270
/// them. This includes lifetimes bound since we entered this context.
271271
/// For example:
@@ -280,8 +280,6 @@ enum ImplTraitContext<'b, 'a> {
280280
// FIXME(impl_trait): but `required_region_bounds` will ICE later
281281
// anyway.
282282
capturable_lifetimes: &'b mut FxHashSet<hir::LifetimeName>,
283-
/// Origin: Either OpaqueTyOrigin::Misc or OpaqueTyOrigin::Binding,
284-
origin: hir::OpaqueTyOrigin,
285283
},
286284
/// `impl Trait` is not accepted in this position.
287285
Disallowed(ImplTraitPosition),
@@ -310,8 +308,8 @@ impl<'a> ImplTraitContext<'_, 'a> {
310308
ReturnPositionOpaqueTy { fn_def_id, origin } => {
311309
ReturnPositionOpaqueTy { fn_def_id: *fn_def_id, origin: *origin }
312310
}
313-
OtherOpaqueTy { capturable_lifetimes, origin } => {
314-
OtherOpaqueTy { capturable_lifetimes, origin: *origin }
311+
TypeAliasesOpaqueTy { capturable_lifetimes } => {
312+
TypeAliasesOpaqueTy { capturable_lifetimes }
315313
}
316314
Disallowed(pos) => Disallowed(*pos),
317315
}
@@ -1126,7 +1124,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11261124
//
11271125
// fn foo() -> impl Iterator<Item = impl Debug>
11281126
ImplTraitContext::ReturnPositionOpaqueTy { .. }
1129-
| ImplTraitContext::OtherOpaqueTy { .. } => (true, itctx),
1127+
| ImplTraitContext::TypeAliasesOpaqueTy { .. } => (true, itctx),
11301128

11311129
// We are in the argument position, but within a dyn type:
11321130
//
@@ -1150,9 +1148,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11501148
capturable_lifetimes = FxHashSet::default();
11511149
(
11521150
true,
1153-
ImplTraitContext::OtherOpaqueTy {
1151+
ImplTraitContext::TypeAliasesOpaqueTy {
11541152
capturable_lifetimes: &mut capturable_lifetimes,
1155-
origin: hir::OpaqueTyOrigin::Misc,
11561153
},
11571154
)
11581155
}
@@ -1416,18 +1413,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14161413
None,
14171414
|this| this.lower_param_bounds(bounds, itctx),
14181415
),
1419-
ImplTraitContext::OtherOpaqueTy { ref capturable_lifetimes, origin } => {
1416+
ImplTraitContext::TypeAliasesOpaqueTy { ref capturable_lifetimes } => {
14201417
// Reset capturable lifetimes, any nested impl trait
14211418
// types will inherit lifetimes from this opaque type,
14221419
// so don't need to capture them again.
1423-
let nested_itctx = ImplTraitContext::OtherOpaqueTy {
1420+
let nested_itctx = ImplTraitContext::TypeAliasesOpaqueTy {
14241421
capturable_lifetimes: &mut FxHashSet::default(),
1425-
origin,
14261422
};
14271423
self.lower_opaque_impl_trait(
14281424
span,
14291425
None,
1430-
origin,
1426+
hir::OpaqueTyOrigin::TyAlias,
14311427
def_node_id,
14321428
Some(capturable_lifetimes),
14331429
|this| this.lower_param_bounds(bounds, nested_itctx),
@@ -1464,25 +1460,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14641460
}),
14651461
))
14661462
}
1467-
ImplTraitContext::Disallowed(pos) => {
1468-
let allowed_in = if self.sess.features_untracked().impl_trait_in_bindings {
1469-
"bindings or function and inherent method return types"
1470-
} else {
1471-
"function and inherent method return types"
1472-
};
1463+
ImplTraitContext::Disallowed(_) => {
14731464
let mut err = struct_span_err!(
14741465
self.sess,
14751466
t.span,
14761467
E0562,
14771468
"`impl Trait` not allowed outside of {}",
1478-
allowed_in,
1469+
"function and method return types",
14791470
);
1480-
if pos == ImplTraitPosition::Binding && self.sess.is_nightly_build() {
1481-
err.help(
1482-
"add `#![feature(impl_trait_in_bindings)]` to the crate \
1483-
attributes to enable",
1484-
);
1485-
}
14861471
err.emit();
14871472
hir::TyKind::Err
14881473
}
@@ -1767,21 +1752,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17671752
}
17681753

17691754
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-
});
1755+
let ty = l
1756+
.ty
1757+
.as_ref()
1758+
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Binding)));
17851759
let init = l.init.as_ref().map(|e| self.lower_expr(e));
17861760
let hir_id = self.lower_node_id(l.id);
17871761
self.lower_attrs(hir_id, &l.attrs);
@@ -2332,13 +2306,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23322306
)),
23332307
_ => None,
23342308
});
2335-
if let ImplTraitContext::OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx {
2309+
if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2310+
itctx
2311+
{
23362312
capturable_lifetimes.extend(lt_def_names.clone());
23372313
}
23382314

23392315
let res = this.lower_trait_ref(&p.trait_ref, itctx.reborrow());
23402316

2341-
if let ImplTraitContext::OtherOpaqueTy { ref mut capturable_lifetimes, .. } = itctx {
2317+
if let ImplTraitContext::TypeAliasesOpaqueTy { ref mut capturable_lifetimes, .. } =
2318+
itctx
2319+
{
23422320
for param in lt_def_names {
23432321
capturable_lifetimes.remove(&param);
23442322
}

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ declare_features! (
455455
/// Allows non-builtin attributes in inner attribute position.
456456
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
457457

458-
/// Allows `impl Trait` in bindings (`let`, `const`, `static`).
459-
(incomplete, impl_trait_in_bindings, "1.30.0", Some(63065), None),
460-
461458
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
462459
(active, lint_reasons, "1.31.0", Some(54503), None),
463460

compiler/rustc_feature/src/removed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ declare_features! (
148148
(removed, const_raw_ptr_to_usize_cast, "1.55.0", Some(51910), None,
149149
Some("at compile-time, pointers do not have an integer value, so these casts cannot be properly supported")),
150150

151+
/// Allows `impl Trait` in bindings (`let`, `const`, `static`).
152+
(removed, impl_trait_in_bindings, "1.55.0", Some(63065), None,
153+
Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),
154+
151155
// -------------------------------------------------------------------------
152156
// feature-group-end: removed features
153157
// -------------------------------------------------------------------------

compiler/rustc_hir/src/hir.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2264,18 +2264,14 @@ pub struct OpaqueTy<'hir> {
22642264
}
22652265

22662266
/// From whence the opaque type came.
2267-
#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)]
2267+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
22682268
pub enum OpaqueTyOrigin {
22692269
/// `-> impl Trait`
22702270
FnReturn,
22712271
/// `async fn`
22722272
AsyncFn,
2273-
/// `let _: impl Trait = ...`
2274-
Binding,
22752273
/// type aliases: `type Foo = impl Trait;`
22762274
TyAlias,
2277-
/// Impl trait consts, statics, bounds.
2278-
Misc,
22792275
}
22802276

22812277
/// The various kinds of types recognized by the compiler.

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
491491
span
492492
};
493493

494-
let is_named_and_not_impl_trait = |ty: Ty<'_>| {
495-
&ty.to_string() != "_" &&
496-
// FIXME: Remove this check after `impl_trait_in_bindings` is stabilized. #63527
497-
(!ty.is_impl_trait() || self.tcx.features().impl_trait_in_bindings)
498-
};
494+
let is_named_and_not_impl_trait =
495+
|ty: Ty<'_>| &ty.to_string() != "_" && !ty.is_impl_trait();
499496

500497
let ty_msg = match (local_visitor.found_node_ty, local_visitor.found_exact_method_call) {
501498
(_, Some(_)) => String::new(),

compiler/rustc_mir/src/borrow_check/member_constraints.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_data_structures::fx::FxHashMap;
2-
use rustc_hir::def_id::DefId;
32
use rustc_index::vec::IndexVec;
43
use rustc_middle::infer::MemberConstraint;
54
use rustc_middle::ty::{self, Ty};
@@ -32,9 +31,6 @@ where
3231
crate struct NllMemberConstraint<'tcx> {
3332
next_constraint: Option<NllMemberConstraintIndex>,
3433

35-
/// The opaque type whose hidden type is being inferred. (Used in error reporting.)
36-
crate opaque_type_def_id: DefId,
37-
3834
/// The span where the hidden type was instantiated.
3935
crate definition_span: Span,
4036

@@ -91,7 +87,6 @@ impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
9187
let constraint_index = self.constraints.push(NllMemberConstraint {
9288
next_constraint,
9389
member_region_vid,
94-
opaque_type_def_id: m_c.opaque_type_def_id,
9590
definition_span: m_c.definition_span,
9691
hidden_ty: m_c.hidden_ty,
9792
start_index,

compiler/rustc_mir/src/borrow_check/region_infer/mod.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
551551
polonius_output: Option<Rc<PoloniusOutput>>,
552552
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
553553
let mir_def_id = body.source.def_id();
554-
self.propagate_constraints(body, infcx.tcx);
554+
self.propagate_constraints(body);
555555

556556
let mut errors_buffer = RegionErrors::new();
557557

@@ -599,7 +599,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
599599
/// for each region variable until all the constraints are
600600
/// satisfied. Note that some values may grow **too** large to be
601601
/// feasible, but we check this later.
602-
fn propagate_constraints(&mut self, _body: &Body<'tcx>, tcx: TyCtxt<'tcx>) {
602+
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
603603
debug!("propagate_constraints()");
604604

605605
debug!("propagate_constraints: constraints={:#?}", {
@@ -617,7 +617,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
617617
// own.
618618
let constraint_sccs = self.constraint_sccs.clone();
619619
for scc in constraint_sccs.all_sccs() {
620-
self.compute_value_for_scc(scc, tcx);
620+
self.compute_value_for_scc(scc);
621621
}
622622

623623
// Sort the applied member constraints so we can binary search
@@ -629,7 +629,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
629629
/// computed, by unioning the values of its successors.
630630
/// Assumes that all successors have been computed already
631631
/// (which is assured by iterating over SCCs in dependency order).
632-
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex, tcx: TyCtxt<'tcx>) {
632+
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex) {
633633
let constraint_sccs = self.constraint_sccs.clone();
634634

635635
// Walk each SCC `B` such that `A: B`...
@@ -652,12 +652,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
652652
// Now take member constraints into account.
653653
let member_constraints = self.member_constraints.clone();
654654
for m_c_i in member_constraints.indices(scc_a) {
655-
self.apply_member_constraint(
656-
tcx,
657-
scc_a,
658-
m_c_i,
659-
member_constraints.choice_regions(m_c_i),
660-
);
655+
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
661656
}
662657

663658
debug!(
@@ -680,31 +675,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
680675
/// If we make any changes, returns true, else false.
681676
fn apply_member_constraint(
682677
&mut self,
683-
tcx: TyCtxt<'tcx>,
684678
scc: ConstraintSccIndex,
685679
member_constraint_index: NllMemberConstraintIndex,
686680
choice_regions: &[ty::RegionVid],
687681
) -> bool {
688682
debug!("apply_member_constraint(scc={:?}, choice_regions={:#?})", scc, choice_regions,);
689683

690-
if let Some(uh_oh) =
691-
choice_regions.iter().find(|&&r| !self.universal_regions.is_universal_region(r))
692-
{
693-
// FIXME(#61773): This case can only occur with
694-
// `impl_trait_in_bindings`, I believe, and we are just
695-
// opting not to handle it for now. See #61773 for
696-
// details.
697-
tcx.sess.delay_span_bug(
698-
self.member_constraints[member_constraint_index].definition_span,
699-
&format!(
700-
"member constraint for `{:?}` has an option region `{:?}` \
701-
that is not a universal region",
702-
self.member_constraints[member_constraint_index].opaque_type_def_id, uh_oh,
703-
),
704-
);
705-
return false;
706-
}
707-
708684
// Create a mutable vector of the options. We'll try to winnow
709685
// them down.
710686
let mut choice_regions: Vec<ty::RegionVid> = choice_regions.to_vec();

compiler/rustc_mir/src/borrow_check/type_check/input_output.rs

-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
122122
if let Err(terr) = self.eq_opaque_type_and_type(
123123
mir_output_ty,
124124
normalized_output_ty,
125-
mir_def_id,
126125
Locations::All(output_span),
127126
ConstraintCategory::BoringNoLocation,
128127
) {
@@ -145,7 +144,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
145144
if let Err(err) = self.eq_opaque_type_and_type(
146145
mir_output_ty,
147146
user_provided_output_ty,
148-
mir_def_id,
149147
Locations::All(output_span),
150148
ConstraintCategory::BoringNoLocation,
151149
) {

0 commit comments

Comments
 (0)