Repository: rust-lang/rust
File: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs (Rust)

Code before:
                    None
                } else {
                    Some(ResolvedArg::StaticLifetime)
                },
                s: self.scope,
            };
            // If the args are parenthesized, then this must be `feature(return_type_notation)`.
            // In that case, introduce a binder over all of the function's early and late bound vars.
            //
            // For example, given
            // ```
            // trait Foo {
            //     async fn x<'r, T>();
            // }
            // ```
            // and a bound that looks like:
            //    `for<'a> T::Trait<'a, x(..): for<'b> Other<'b>>`
            // this is going to expand to something like:
            //    `for<'a> for<'r> <T as Trait<'a>>::x::<'r, T>::{opaque#0}: for<'b> Other<'b>`.
            if constraint.gen_args.parenthesized == hir::GenericArgsParentheses::ReturnTypeNotation
            {
                let bound_vars = if let Some(type_def_id) = type_def_id
                    && matches!(
                        self.tcx.def_kind(type_def_id),
                        DefKind::Trait | DefKind::TraitAlias
                    )
                    && let Some((mut bound_vars, assoc_fn)) = BoundVarContext::supertrait_hrtb_vars(
                        self.tcx,
                        type_def_id,
                        constraint.ident,
                        ty::AssocTag::Fn,
                    ) {
                    bound_vars.extend(
                        self.tcx
                            .generics_of(assoc_fn.def_id)
                            .own_params
                            .iter()
                            .map(|param| generic_param_def_as_bound_arg(param)),
                    );
                    bound_vars.extend(
                        self.tcx.fn_sig(assoc_fn.def_id).instantiate_identity().bound_vars(),
                    );
                    bound_vars
                } else {
                    self.tcx
                        .dcx()
                        .span_delayed_bug(constraint.ident.span, "bad return type notation here");
                    vec![]
                };
                self.with(scope, |this| {
                    let scope = Scope::Supertrait { bound_vars, s: this.scope };

Review comment (suggestion):
```suggestion
                    && let DefKind::Trait | DefKind::TraitAlias = self.tcx.def_kind(type_def_id)
```

Code after:
                    None
                } else {
                    Some(ResolvedArg::StaticLifetime)
                },
                s: self.scope,
            };
            // If the args are parenthesized, then this must be `feature(return_type_notation)`.
            // In that case, introduce a binder over all of the function's early and late bound vars.
            //
            // For example, given
            // ```
            // trait Foo {
            //     async fn x<'r, T>();
            // }
            // ```
            // and a bound that looks like:
            //    `for<'a> T::Trait<'a, x(..): for<'b> Other<'b>>`
            // this is going to expand to something like:
            //    `for<'a> for<'r> <T as Trait<'a>>::x::<'r, T>::{opaque#0}: for<'b> Other<'b>`.
            if constraint.gen_args.parenthesized == hir::GenericArgsParentheses::ReturnTypeNotation
            {
                let bound_vars = if let Some(type_def_id) = type_def_id
                    && let DefKind::Trait | DefKind::TraitAlias = self.tcx.def_kind(type_def_id)
                    && let Some((mut bound_vars, assoc_fn)) = BoundVarContext::supertrait_hrtb_vars(
                        self.tcx,
                        type_def_id,
                        constraint.ident,
                        ty::AssocTag::Fn,
                    ) {
                    bound_vars.extend(
                        self.tcx
                            .generics_of(assoc_fn.def_id)
                            .own_params
                            .iter()
                            .map(|param| generic_param_def_as_bound_arg(param)),
                    );
                    bound_vars.extend(
                        self.tcx.fn_sig(assoc_fn.def_id).instantiate_identity().bound_vars(),
                    );
                    bound_vars
                } else {
                    self.tcx
                        .dcx()
                        .span_delayed_bug(constraint.ident.span, "bad return type notation here");
                    vec![]
                };
                self.with(scope, |this| {
                    let scope = Scope::Supertrait { bound_vars, s: this.scope };
                    this.with(scope, |this| {
                        let (bound_vars, _) = this.poly_trait_ref_binder_info();
                        this.record_late_bound_vars(constraint.hir_id, bound_vars);