Rollup merge of #154469 - reddevilmidzy:mgca-lower, r=BoxyUwU

mGCA: Lower spans for literal const args

resolve: https://github.com/rust-lang/rust/issues/152653
resolve: https://github.com/rust-lang/rust/issues/154636
This commit is contained in:
Jonathan Brouwer
2026-04-02 22:13:54 +02:00
committed by GitHub
3 changed files with 43 additions and 2 deletions
+2 -2
View File
@@ -2683,7 +2683,7 @@ fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir>
overly_complex_const(self)
}
ExprKind::Lit(literal) => {
let span = expr.span;
let span = self.lower_span(expr.span);
let literal = self.lower_lit(literal, span);
ConstArg {
@@ -2695,7 +2695,7 @@ fn lower_expr_to_const_arg_direct(&mut self, expr: &Expr) -> hir::ConstArg<'hir>
ExprKind::Unary(UnOp::Neg, inner_expr)
if let ExprKind::Lit(literal) = &inner_expr.kind =>
{
let span = expr.span;
let span = self.lower_span(expr.span);
let literal = self.lower_lit(literal, span);
if !matches!(literal.node, LitKind::Int(..)) {
@@ -0,0 +1,15 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/152653>
//! <https://github.com/rust-lang/rust/issues/154636>
//@ incremental
#![feature(min_generic_const_args)]
type const R: usize = 1_i32; //~ ERROR: the constant `1` is not of type `usize`
type const U: usize = -1_i32; //~ ERROR: the constant `-1` is not of type `usize`
type const S: bool = 1i32; //~ ERROR: the constant `1` is not of type `bool`
type const T: bool = -1i32; //~ ERROR: the constant `-1` is not of type `bool`
fn main() {
R;
U;
S;
T;
}
@@ -0,0 +1,26 @@
error: the constant `1` is not of type `usize`
--> $DIR/type_const-mismatched-type-incremental.rs:5:1
|
LL | type const R: usize = 1_i32;
| ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32`
error: the constant `-1` is not of type `usize`
--> $DIR/type_const-mismatched-type-incremental.rs:6:1
|
LL | type const U: usize = -1_i32;
| ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32`
error: the constant `1` is not of type `bool`
--> $DIR/type_const-mismatched-type-incremental.rs:7:1
|
LL | type const S: bool = 1i32;
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32`
error: the constant `-1` is not of type `bool`
--> $DIR/type_const-mismatched-type-incremental.rs:8:1
|
LL | type const T: bool = -1i32;
| ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32`
error: aborting due to 4 previous errors