diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 0cd741a11d529..5b7d92944edf2 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -188,10 +188,18 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir::ItemFn(.., ref generics, _) => { let mut error = false; if !generics.params.is_empty() { - struct_span_err!(tcx.sess, generics.span, E0131, - "`main` function is not allowed to have type parameters") - .span_label(generics.span, - "`main` cannot have type parameters") + let param_type = if generics.is_lt_parameterized() { + "lifetime" + } else { + "type" + }; + let msg = + format!("`main` function is not allowed to have {} parameters", + param_type); + let label = + format!("`main` cannot have {} parameters", param_type); + struct_span_err!(tcx.sess, generics.span, E0131, "{}", msg) + .span_label(generics.span, label) .emit(); error = true; } diff --git a/src/test/compile-fail/issue-51022.rs b/src/test/compile-fail/issue-51022.rs new file mode 100644 index 0000000000000..d4d2192b8ae07 --- /dev/null +++ b/src/test/compile-fail/issue-51022.rs @@ -0,0 +1,12 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// error-pattern: `main` function is not allowed to have lifetime parameters +fn main<'a>() { }