Auto merge of #50782 - matthewjasper:wheres-main, r=matthewjasper

Prevent main from having a where clause.

Closes #50714

Should this have a crater run?

cc #48557, #48214

r? @nikomatsakis
This commit is contained in:
bors 2018-05-19 20:10:34 +00:00
commit a3085756ed
10 changed files with 153 additions and 8 deletions

View File

@ -4519,6 +4519,32 @@ fn foo<U: Iterator>(&self, _: &U) { } // error method `foo` has incompatible
```
"##,
E0646: r##"
It is not possible to define `main` with a where clause.
Erroneous code example:
```compile_fail,E0646
fn main() where i32: Copy { // error: main function is not allowed to have
// a where clause
}
```
"##,
E0647: r##"
It is not possible to define `start` with a where clause.
Erroneous code example:
```compile_fail,E0647
#![feature(start)]
#[start]
fn start(_: isize, _: *const *const u8) -> isize where (): Copy {
//^ error: start function is not allowed to have a where clause
0
}
```
"##,
E0689: r##"
This error indicates that the numeric value for the method being passed exists
but the type of the numeric value or binding could not be identified.

View File

@ -194,6 +194,12 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
.emit();
return;
}
if !generics.where_clause.predicates.is_empty() {
struct_span_err!(tcx.sess, main_span, E0646,
"main function is not allowed to have a where clause")
.emit();
return;
}
}
_ => ()
}
@ -245,14 +251,21 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
match tcx.hir.find(start_id) {
Some(hir_map::NodeItem(it)) => {
match it.node {
hir::ItemFn(..,ref ps,_)
if !ps.params.is_empty() => {
struct_span_err!(tcx.sess, ps.span, E0132,
"start function is not allowed to have type parameters")
.span_label(ps.span,
"start function cannot have type parameters")
.emit();
return;
hir::ItemFn(..,ref ps,_) => {
if !ps.params.is_empty() {
struct_span_err!(tcx.sess, ps.span, E0132,
"start function is not allowed to have type parameters")
.span_label(ps.span,
"start function cannot have type parameters")
.emit();
return;
}
if !ps.where_clause.predicates.is_empty() {
struct_span_err!(tcx.sess, start_span, E0647,
"start function is not allowed to have a where clause")
.emit();
return;
}
}
_ => ()
}

View File

@ -0,0 +1,11 @@
// 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.
fn main() where (): Copy {} //~ ERROR [E0646]

View File

@ -0,0 +1,9 @@
error[E0646]: main function is not allowed to have a where clause
--> $DIR/E0646.rs:11:1
|
LL | fn main() where (): Copy {} //~ ERROR [E0646]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0646`.

View File

@ -0,0 +1,19 @@
// 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.
#![no_std]
#![feature(start)]
extern crate std;
#[start]
fn start(_: isize, _: *const *const u8) -> isize where (): Copy { //~ ERROR [E0647]
0
}

View File

@ -0,0 +1,11 @@
error[E0647]: start function is not allowed to have a where clause
--> $DIR/E0647.rs:17:1
|
LL | / fn start(_: isize, _: *const *const u8) -> isize where (): Copy { //~ ERROR [E0647]
LL | | 0
LL | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0647`.

View File

@ -0,0 +1,22 @@
// 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.
// Regression test for issue 50714, make sure that this isn't a linker error.
#![no_std]
#![feature(start)]
extern crate std;
#[start]
fn start(_: isize, _: *const *const u8) -> isize where fn(&()): Eq { //~ ERROR [E0647]
0
}

View File

@ -0,0 +1,11 @@
error[E0647]: start function is not allowed to have a where clause
--> $DIR/issue-50714-1.rs:19:1
|
LL | / fn start(_: isize, _: *const *const u8) -> isize where fn(&()): Eq { //~ ERROR [E0647]
LL | | 0
LL | | }
| |_^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0647`.

View File

@ -0,0 +1,14 @@
// 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.
// Regression test for issue 50714, make sure that this isn't a linker error.
fn main() where fn(&()): Eq {} //~ ERROR [E0646]

View File

@ -0,0 +1,9 @@
error[E0646]: main function is not allowed to have a where clause
--> $DIR/issue-50714.rs:13:1
|
LL | fn main() where fn(&()): Eq {} //~ ERROR [E0646]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0646`.