diff options
| author | bors <bors@rust-lang.org> | 2018-05-27 09:22:27 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-27 09:22:27 +0000 |
| commit | 7d218fc72fc68a8ef75c5b5f8bc651e18d83f23e (patch) | |
| tree | d75639747d8e01a73a6b5d1d88a31f1108716b21 | |
| parent | 3fd82a5e6b3a707610fdc878e2b5608340e4969a (diff) | |
| parent | 023137dc1e2c6430975dbaddddb7d0862b14f085 (diff) | |
| download | rust-7d218fc72fc68a8ef75c5b5f8bc651e18d83f23e.tar.gz rust-7d218fc72fc68a8ef75c5b5f8bc651e18d83f23e.zip | |
Auto merge of #51084 - simartin:issue_51022, r=estebank
Issue #51022: Improve E0131 message when lifetimes are involved. Fixes #51022
| -rw-r--r-- | src/librustc_typeck/lib.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-51022.rs | 12 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 0cd741a11d5..5b7d92944ed 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 00000000000..d4d2192b8ae --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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>() { } |
