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:
commit
7d218fc72f
@ -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;
|
||||
}
|
||||
|
12
src/test/compile-fail/issue-51022.rs
Normal file
12
src/test/compile-fail/issue-51022.rs
Normal 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>() { }
|
Loading…
x
Reference in New Issue
Block a user