Repository: rust-lang/rust
File: compiler/rustc_ast_lowering/src/lib.rs (Rust)

Code before:
                }

                overly_complex_const(self)
            }
            ExprKind::Lit(literal) => {
                let span = expr.span;
                let literal = self.lower_lit(literal, span);

                ConstArg {
                    hir_id: self.lower_node_id(expr.id),
                    kind: hir::ConstArgKind::Literal(literal.node),
                    span,
                }
            }
            _ => overly_complex_const(self),
        }
    }

    /// See [`hir::ConstArg`] for when to use this function vs
    /// [`Self::lower_anon_const_to_anon_const`].
    fn lower_anon_const_to_const_arg_and_alloc(
        &mut self,
        anon: &AnonConst,
    ) -> &'hir hir::ConstArg<'hir> {
        self.arena.alloc(self.lower_anon_const_to_const_arg(anon))
    }

    #[instrument(level = "debug", skip(self))]
    fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
        let tcx = self.tcx;

        // We cannot change parsing depending on feature gates available,
        // we can only require feature gates to be active as a delayed check.
        // Thus we just parse anon consts generally and make the real decision
        // making in ast lowering.
        // FIXME(min_generic_const_args): revisit once stable
        if tcx.features().min_generic_const_args() {
            return match anon.mgca_disambiguation {
                MgcaDisambiguation::AnonConst => {
                    let lowered_anon = self.lower_anon_const_to_anon_const(anon);
                    ConstArg {
                        hir_id: self.next_id(),
                        kind: hir::ConstArgKind::Anon(lowered_anon),
                        span: lowered_anon.span,
                    }
                }
                MgcaDisambiguation::Direct => self.lower_expr_to_const_arg_direct(&anon.value),
            };
        }

        // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments

Review comment (suggestion):
note to reviewers: in addition to nuking the FIXME in my last force-push, I changed the span for this `ConstArg` to **include** the negative sign in the span (before the push, it was excluded, just the inner_expr's span). Realized it was excluded when trying to add errors for `-1_usize`.

(the diff in the force push is rather unclear what's happening so I figured I'd point it out)

Code after:
                {
                    return self.lower_expr_to_const_arg_direct(expr);
                }

                overly_complex_const(self)
            }
            ExprKind::Lit(literal) => {
                let span = expr.span;
                let literal = self.lower_lit(literal, span);

                ConstArg {
                    hir_id: self.lower_node_id(expr.id),
                    kind: hir::ConstArgKind::Literal { lit: literal.node, negated: false },
                    span,
                }
            }
            ExprKind::Unary(UnOp::Neg, inner_expr)
                if let ExprKind::Lit(literal) = &inner_expr.kind =>
            {
                let span = expr.span;
                let literal = self.lower_lit(literal, span);

                ConstArg {
                    hir_id: self.lower_node_id(expr.id),
                    kind: hir::ConstArgKind::Literal { lit: literal.node, negated: true },
                    span,
                }
            }
            _ => overly_complex_const(self),
        }
    }

    /// See [`hir::ConstArg`] for when to use this function vs
    /// [`Self::lower_anon_const_to_anon_const`].
    fn lower_anon_const_to_const_arg_and_alloc(
        &mut self,
        anon: &AnonConst,
    ) -> &'hir hir::ConstArg<'hir> {
        self.arena.alloc(self.lower_anon_const_to_const_arg(anon))
    }

    #[instrument(level = "debug", skip(self))]
    fn lower_anon_const_to_const_arg(&mut self, anon: &AnonConst) -> hir::ConstArg<'hir> {
        let tcx = self.tcx;

        // We cannot change parsing depending on feature gates available,
        // we can only require feature gates to be active as a delayed check.
        // Thus we just parse anon consts generally and make the real decision
        // making in ast lowering.
        // FIXME(min_generic_const_args): revisit once stable
        if tcx.features().min_generic_const_args() {