Skip to content

Commit a308575

Browse files
committed
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
2 parents 5c3960c + 218a81b commit a308575

File tree

10 files changed

+153
-8
lines changed

10 files changed

+153
-8
lines changed

Diff for: 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.

Diff for: src/librustc_typeck/lib.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
194194
.emit();
195195
return;
196196
}
197+
if !generics.where_clause.predicates.is_empty() {
198+
struct_span_err!(tcx.sess, main_span, E0646,
199+
"main function is not allowed to have a where clause")
200+
.emit();
201+
return;
202+
}
197203
}
198204
_ => ()
199205
}
@@ -245,14 +251,21 @@ fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
245251
match tcx.hir.find(start_id) {
246252
Some(hir_map::NodeItem(it)) => {
247253
match it.node {
248-
hir::ItemFn(..,ref ps,_)
249-
if !ps.params.is_empty() => {
250-
struct_span_err!(tcx.sess, ps.span, E0132,
251-
"start function is not allowed to have type parameters")
252-
.span_label(ps.span,
253-
"start function cannot have type parameters")
254-
.emit();
255-
return;
254+
hir::ItemFn(..,ref ps,_) => {
255+
if !ps.params.is_empty() {
256+
struct_span_err!(tcx.sess, ps.span, E0132,
257+
"start function is not allowed to have type parameters")
258+
.span_label(ps.span,
259+
"start function cannot have type parameters")
260+
.emit();
261+
return;
262+
}
263+
if !ps.where_clause.predicates.is_empty() {
264+
struct_span_err!(tcx.sess, start_span, E0647,
265+
"start function is not allowed to have a where clause")
266+
.emit();
267+
return;
268+
}
256269
}
257270
_ => ()
258271
}

Diff for: 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]

Diff for: 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`.

Diff for: 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+
}

Diff for: 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`.

Diff for: 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+

Diff for: 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`.

Diff for: 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+

Diff for: 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)