Repository: rust-lang/rust
File: compiler/rustc_parse/src/parser/item.rs (Rust)

Code before:
        let ty = match (
            self.eat(exp!(Colon)),
            self.check(exp!(Eq)) | self.check(exp!(Semi)) | self.check_keyword(exp!(Where)),
        ) {
            (true, false) => self.parse_ty()?,
            // If there wasn't a `:` or the colon was followed by a `=`, `;` or `where`, recover a missing type.
            (colon, _) => self.recover_missing_global_item_type(colon, None),
        };

        // Proactively parse a where-clause to be able to provide a good error message in case we
        // encounter the item body following it.
        let before_where_clause =
            if self.may_recover() { self.parse_where_clause()? } else { WhereClause::default() };

        let rhs = if self.eat(exp!(Eq)) {
            if attr::contains_name(attrs, sym::type_const) {
                let ct = if self.eat_keyword(exp!(Const)) {
                    // While we could just disambiguate `Direct` from `AnonConst` by
                    // treating all const block exprs as `AnonConst`, that would
                    // complicate the DefCollector and likely all other visitors.
                    // So we strip the const blockiness and just store it as a block
                    // in the AST with the extra disambiguator on the AnonConst
                    self.parse_mgca_const_block(false)?
                } else {
                    self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?
                };
                Some(ConstItemRhs::TypeConst(ct))
            } else {
                Some(ConstItemRhs::Body(self.parse_expr()?))
            }
        } else {
            None
        };

        let after_where_clause = self.parse_where_clause()?;

        // Provide a nice error message if the user placed a where-clause before the item body.
        // Users may be tempted to write such code if they are still used to the deprecated
        // where-clause location on type aliases and associated types. See also #89122.
        if before_where_clause.has_where_token
            && let Some(rhs) = &rhs
        {
            self.dcx().emit_err(errors::WhereClauseBeforeConstBody {
                span: before_where_clause.span,
                name: ident.span,
                body: rhs.span(),
                sugg: if !after_where_clause.has_where_token {
                    self.psess.source_map().span_to_snippet(rhs.span()).ok().map(|body_s| {
                        errors::WhereClauseBeforeConstBodySugg {
                            left: before_where_clause.span.shrink_to_lo(),
                            snippet: body_s,

Review comment (suggestion):
```suggestion
                let ct = self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?;
```
see #152234

Code after:
        let ty = match (
            self.eat(exp!(Colon)),
            self.check(exp!(Eq)) | self.check(exp!(Semi)) | self.check_keyword(exp!(Where)),
        ) {
            (true, false) => self.parse_ty()?,
            // If there wasn't a `:` or the colon was followed by a `=`, `;` or `where`, recover a missing type.
            (colon, _) => self.recover_missing_global_item_type(colon, None),
        };

        // Proactively parse a where-clause to be able to provide a good error message in case we
        // encounter the item body following it.
        let before_where_clause =
            if self.may_recover() { self.parse_where_clause()? } else { WhereClause::default() };

        let rhs = if self.eat(exp!(Eq)) {
            if attr::contains_name(attrs, sym::type_const) {
                let ct =
                    self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?;
                Some(ConstItemRhs::TypeConst(ct))
            } else {
                Some(ConstItemRhs::Body(self.parse_expr()?))
            }
        } else {
            None
        };

        let after_where_clause = self.parse_where_clause()?;

        // Provide a nice error message if the user placed a where-clause before the item body.
        // Users may be tempted to write such code if they are still used to the deprecated
        // where-clause location on type aliases and associated types. See also #89122.
        if before_where_clause.has_where_token
            && let Some(rhs) = &rhs
        {
            self.dcx().emit_err(errors::WhereClauseBeforeConstBody {
                span: before_where_clause.span,
                name: ident.span,
                body: rhs.span(),
                sugg: if !after_where_clause.has_where_token {
                    self.psess.source_map().span_to_snippet(rhs.span()).ok().map(|body_s| {
                        errors::WhereClauseBeforeConstBodySugg {
                            left: before_where_clause.span.shrink_to_lo(),
                            snippet: body_s,
                            right: before_where_clause.span.shrink_to_hi().to(rhs.span()),
                        }
                    })
                } else {
                    // FIXME(generic_const_items): Provide a structured suggestion to merge the first
                    // where-clause into the second one.
                    None
                },