Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c1f62a7

Browse files
committedJun 18, 2024
Auto merge of #126049 - compiler-errors:rework-use, r=oli-obk
Rework `feature(precise_capturing)` to represent `use<...>` as a syntactical bound Reworks `precise_capturing` for a recent lang-team consensus. Specifically: > The conclusion of the team is that we'll make use<..> a bound. That is, we'll support impl use<..> + Trait, impl Trait + use<..>, etc. > For now, we will support at most one such bound in a list of bounds, and semantically we'll only support these bounds in the item bounds of RPIT-like impl Trait opaque types (i.e., in the places discussed in the RFC). Lang decision in favor of this approach: - #125836 (comment) Tracking: - #123432
2 parents f873ae0 + 2273747 commit c1f62a7

File tree

76 files changed

+628
-574
lines changed

Some content is hidden

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

76 files changed

+628
-574
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,16 @@ impl TraitBoundModifiers {
307307
pub enum GenericBound {
308308
Trait(PolyTraitRef, TraitBoundModifiers),
309309
Outlives(Lifetime),
310+
/// Precise capturing syntax: `impl Sized + use<'a>`
311+
Use(ThinVec<PreciseCapturingArg>, Span),
310312
}
311313

312314
impl GenericBound {
313315
pub fn span(&self) -> Span {
314316
match self {
315317
GenericBound::Trait(t, ..) => t.span,
316318
GenericBound::Outlives(l) => l.ident.span,
319+
GenericBound::Use(_, span) => *span,
317320
}
318321
}
319322
}
@@ -2162,7 +2165,7 @@ pub enum TyKind {
21622165
/// The `NodeId` exists to prevent lowering from having to
21632166
/// generate `NodeId`s on the fly, which would complicate
21642167
/// the generation of opaque `type Foo = impl Trait` items significantly.
2165-
ImplTrait(NodeId, GenericBounds, Option<P<(ThinVec<PreciseCapturingArg>, Span)>>),
2168+
ImplTrait(NodeId, GenericBounds),
21662169
/// No-op; kept solely so that we can pretty-print faithfully.
21672170
Paren(P<Ty>),
21682171
/// Unused for now.

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,9 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
523523
TyKind::TraitObject(bounds, _syntax) => {
524524
visit_vec(bounds, |bound| vis.visit_param_bound(bound))
525525
}
526-
TyKind::ImplTrait(id, bounds, precise_capturing) => {
526+
TyKind::ImplTrait(id, bounds) => {
527527
vis.visit_id(id);
528528
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
529-
if let Some((precise_capturing, _span)) = precise_capturing.as_deref_mut() {
530-
for arg in precise_capturing {
531-
vis.visit_precise_capturing_arg(arg);
532-
}
533-
}
534529
}
535530
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
536531
TyKind::AnonStruct(id, fields) | TyKind::AnonUnion(id, fields) => {
@@ -923,6 +918,11 @@ fn noop_visit_param_bound<T: MutVisitor>(pb: &mut GenericBound, vis: &mut T) {
923918
match pb {
924919
GenericBound::Trait(ty, _modifier) => vis.visit_poly_trait_ref(ty),
925920
GenericBound::Outlives(lifetime) => noop_visit_lifetime(lifetime, vis),
921+
GenericBound::Use(args, _) => {
922+
for arg in args {
923+
vis.visit_precise_capturing_arg(arg);
924+
}
925+
}
926926
}
927927
}
928928

0 commit comments

Comments
 (0)
Please sign in to comment.