diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 16033c6c50f..da47ccf38a0 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1902,7 +1902,18 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { ty, }; - let expr = &tcx.hir().body(ast_const.body).value; + let mut expr = &tcx.hir().body(ast_const.body).value; + + // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments + // currently have to be wrapped in curly brackets, so it's necessary to special-case. + if let ExprKind::Block(block, _) = &expr.node { + if block.stmts.is_empty() { + if let Some(trailing) = &block.expr { + expr = &trailing; + } + } + } + if let ExprKind::Path(ref qpath) = expr.node { if let hir::QPath::Resolved(_, ref path) = qpath { if let Res::Def(DefKind::ConstParam, def_id) = path.res { diff --git a/src/test/ui/const-generics/impl-const-generic-struct.rs b/src/test/ui/const-generics/impl-const-generic-struct.rs new file mode 100644 index 00000000000..7a0c0f2be5d --- /dev/null +++ b/src/test/ui/const-generics/impl-const-generic-struct.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +struct S; + +impl S<{X}> { + fn x() -> u32 { + X + } +} + +fn main() { + assert_eq!(S::<19>::x(), 19); +} diff --git a/src/test/ui/const-generics/impl-const-generic-struct.stderr b/src/test/ui/const-generics/impl-const-generic-struct.stderr new file mode 100644 index 00000000000..d443e060a97 --- /dev/null +++ b/src/test/ui/const-generics/impl-const-generic-struct.stderr @@ -0,0 +1,6 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/impl-const-generic-struct.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ +