diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 5fcc8f0161194..6d9fe9870c42e 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2683,7 +2683,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { 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 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> { 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(..)) { diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs new file mode 100644 index 0000000000000..74c945b0881a4 --- /dev/null +++ b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs @@ -0,0 +1,15 @@ +//! Regression test for +//! +//@ 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; +} diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr new file mode 100644 index 0000000000000..b09ac22240325 --- /dev/null +++ b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr @@ -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 +