Auto merge of #51084 - simartin:issue_51022, r=estebank

Issue #51022: Improve E0131 message when lifetimes are involved.

Fixes #51022
This commit is contained in:
bors 2018-05-27 09:22:27 +00:00
commit 7d218fc72f
2 changed files with 24 additions and 4 deletions

View File

@ -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;
}

View File

@ -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>() { }