diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 7a297f2c65f13..748704988627f 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -109,6 +109,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { ); } } + (GenericArg::Const(cnst), GenericParamDefKind::Type { .. }) => { + let body = tcx.hir().body(cnst.value.body); + if let rustc_hir::ExprKind::Path(rustc_hir::QPath::Resolved(_, path)) = + body.value.kind + { + if let Res::Def(DefKind::Fn { .. }, id) = path.res { + err.help(&format!( + "`{}` is a function item, not a type", + tcx.item_name(id) + )); + err.help("function item types cannot be named directly"); + } + } + } _ => {} } diff --git a/src/test/ui/generics/generic-function-item-where-type.rs b/src/test/ui/generics/generic-function-item-where-type.rs new file mode 100644 index 0000000000000..e1b0578cadbe9 --- /dev/null +++ b/src/test/ui/generics/generic-function-item-where-type.rs @@ -0,0 +1,6 @@ +fn foo() {} + +fn main() { + foo::
() + //~^ ERROR constant provided when a type was expected +} diff --git a/src/test/ui/generics/generic-function-item-where-type.stderr b/src/test/ui/generics/generic-function-item-where-type.stderr new file mode 100644 index 0000000000000..88594129caaba --- /dev/null +++ b/src/test/ui/generics/generic-function-item-where-type.stderr @@ -0,0 +1,12 @@ +error[E0747]: constant provided when a type was expected + --> $DIR/generic-function-item-where-type.rs:4:11 + | +LL | foo::
() + | ^^^^ + | + = help: `main` is a function item, not a type + = help: function item types cannot be named directly + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/privacy/privacy-ns1.stderr b/src/test/ui/privacy/privacy-ns1.stderr index 714f28941f11f..d09a8aae74801 100644 --- a/src/test/ui/privacy/privacy-ns1.stderr +++ b/src/test/ui/privacy/privacy-ns1.stderr @@ -57,6 +57,9 @@ error[E0747]: constant provided when a type was expected | LL | let _x: Box; | ^^^ + | + = help: `Bar` is a function item, not a type + = help: function item types cannot be named directly error: aborting due to 4 previous errors diff --git a/src/test/ui/privacy/privacy-ns2.stderr b/src/test/ui/privacy/privacy-ns2.stderr index c7ad8ec503654..fdf0549cf50bc 100644 --- a/src/test/ui/privacy/privacy-ns2.stderr +++ b/src/test/ui/privacy/privacy-ns2.stderr @@ -83,12 +83,18 @@ error[E0747]: constant provided when a type was expected | LL | let _x : Box; | ^^^ + | + = help: `Bar` is a function item, not a type + = help: function item types cannot be named directly error[E0747]: constant provided when a type was expected --> $DIR/privacy-ns2.rs:48:17 | LL | let _x: Box; | ^^^ + | + = help: `Bar` is a function item, not a type + = help: function item types cannot be named directly error: aborting due to 8 previous errors