Skip to content

Commit 218a81b

Browse files
committedMay 18, 2018
Prevent main and start from having a where clause.
1 parent 27acb9b commit 218a81b

File tree

10 files changed

+153
-8
lines changed

10 files changed

+153
-8
lines changed
 

‎src/librustc_typeck/diagnostics.rs

+26
Original file line numberDiff line numberDiff line change
@@ -4519,6 +4519,32 @@ impl Foo for () {
45194519
```
45204520
"##,
45214521

4522+
E0646: r##"
4523+
It is not possible to define `main` with a where clause.
4524+
Erroneous code example:
4525+
4526+
```compile_fail,E0646
4527+
fn main() where i32: Copy { // error: main function is not allowed to have
4528+
// a where clause
4529+
}
4530+
```
4531+
"##,
4532+
4533+
E0647: r##"
4534+
It is not possible to define `start` with a where clause.
4535+
Erroneous code example:
4536+
4537+
```compile_fail,E0647
4538+
#![feature(start)]
4539+
4540+
#[start]
4541+
fn start(_: isize, _: *const *const u8) -> isize where (): Copy {
4542+
//^ error: start function is not allowed to have a where clause
4543+
0
4544+
}
4545+
```
4546+
"##,
4547+
45224548
E0689: r##"
45234549
This error indicates that the numeric value for the method being passed exists
45244550
but the type of the numeric value or binding could not be identified.

‎src/librustc_typeck/lib.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
196196
.emit();
197197
return;
198198
}
199+
if !generics.where_clause.predicates.is_empty() {
200+
struct_span_err!(tcx.sess, main_span, E0646,
201+
"main function is not allowed to have a where clause")
202+
.emit();
203+
return;
204+
}
199205
}
200206
_ => ()
201207
}
@@ -247,14 +253,21 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
247253
match tcx.hir.find(start_id) {
248254
Some(hir_map::NodeItem(it)) => {
249255
match it.node {
250-
hir::ItemFn(..,ref ps,_)
251-
if !ps.params.is_empty() => {
252-
struct_span_err!(tcx.sess, ps.span, E0132,
253-
"start function is not allowed to have type parameters")
254-
.span_label(ps.span,
255-
"start function cannot have type parameters")
256-
.emit();
257-
return;
256+
hir::ItemFn(..,ref ps,_) => {
257+
if !ps.params.is_empty() {
258+
struct_span_err!(tcx.sess, ps.span, E0132,
259+
"start function is not allowed to have type parameters")
260+
.span_label(ps.span,
261+
"start function cannot have type parameters")
262+
.emit();
263+
return;
264+
}
265+
if !ps.where_clause.predicates.is_empty() {
266+
struct_span_err!(tcx.sess, start_span, E0647,
267+
"start function is not allowed to have a where clause")
268+
.emit();
269+
return;
270+
}
258271
}
259272
_ => ()
260273
}

‎src/test/ui/error-codes/E0646.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() where (): Copy {} //~ ERROR [E0646]

‎src/test/ui/error-codes/E0646.stderr

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

‎src/test/ui/error-codes/E0647.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![no_std]
12+
#![feature(start)]
13+
14+
extern crate std;
15+
16+
#[start]
17+
fn start(_: isize, _: *const *const u8) -> isize where (): Copy { //~ ERROR [E0647]
18+
0
19+
}

‎src/test/ui/error-codes/E0647.stderr

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

‎src/test/ui/issue-50714-1.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for issue 50714, make sure that this isn't a linker error.
12+
13+
#![no_std]
14+
#![feature(start)]
15+
16+
extern crate std;
17+
18+
#[start]
19+
fn start(_: isize, _: *const *const u8) -> isize where fn(&()): Eq { //~ ERROR [E0647]
20+
0
21+
}
22+

‎src/test/ui/issue-50714-1.stderr

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

‎src/test/ui/issue-50714.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for issue 50714, make sure that this isn't a linker error.
12+
13+
fn main() where fn(&()): Eq {} //~ ERROR [E0646]
14+

‎src/test/ui/issue-50714.stderr

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

0 commit comments

Comments
 (0)
Please sign in to comment.