Skip to content

Commit

Permalink
Auto merge of #75130 - lcnr:array_chunks, r=ecstatic-morse
Browse files Browse the repository at this point in the history
forbid `#[track_caller]` on main

fixes #75125

cc @anp
  • Loading branch information
bors committed Aug 5, 2020
2 parents 07f1fde + 9127e27 commit 32d14eb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 6 deletions.
40 changes: 37 additions & 3 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::util;
use rustc_session::config::EntryFnType;
use rustc_span::{Span, DUMMY_SP};
use rustc_span::{symbol::sym, Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
use rustc_trait_selection::traits::{
Expand Down Expand Up @@ -194,6 +194,23 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
.emit();
error = true;
}

for attr in it.attrs {
if attr.check_name(sym::track_caller) {
tcx.sess
.struct_span_err(
attr.span,
"`main` function is not allowed to be `#[track_caller]`",
)
.span_label(
main_span,
"`main` function is not allowed to be `#[track_caller]`",
)
.emit();
error = true;
}
}

if error {
return;
}
Expand Down Expand Up @@ -268,12 +285,29 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
tcx.sess,
span,
E0752,
"start is not allowed to be `async`"
"`start` is not allowed to be `async`"
)
.span_label(span, "start is not allowed to be `async`")
.span_label(span, "`start` is not allowed to be `async`")
.emit();
error = true;
}

for attr in it.attrs {
if attr.check_name(sym::track_caller) {
tcx.sess
.struct_span_err(
attr.span,
"`start` is not allowed to be `#[track_caller]`",
)
.span_label(
start_span,
"`start` is not allowed to be `#[track_caller]`",
)
.emit();
error = true;
}
}

if error {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-68523-start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#[start]
pub async fn start(_: isize, _: *const *const u8) -> isize {
//~^ ERROR start is not allowed to be `async`
//~^ ERROR `start` is not allowed to be `async`
0
}
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issue-68523-start.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0752]: start is not allowed to be `async`
error[E0752]: `start` is not allowed to be `async`
--> $DIR/issue-68523-start.rs:6:1
|
LL | pub async fn start(_: isize, _: *const *const u8) -> isize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ start is not allowed to be `async`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `start` is not allowed to be `async`

error: aborting due to previous error

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/rfc-2091-track-caller/error-with-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[track_caller] //~ ERROR `main` function is not allowed to be
fn main() {
panic!("{}: oh no", std::panic::Location::caller());
}
12 changes: 12 additions & 0 deletions src/test/ui/rfc-2091-track-caller/error-with-main.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: `main` function is not allowed to be `#[track_caller]`
--> $DIR/error-with-main.rs:1:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
LL | / fn main() {
LL | | panic!("{}: oh no", std::panic::Location::caller());
LL | | }
| |_- `main` function is not allowed to be `#[track_caller]`

error: aborting due to previous error

7 changes: 7 additions & 0 deletions src/test/ui/rfc-2091-track-caller/error-with-start.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![feature(start)]

#[start]
#[track_caller] //~ ERROR `start` is not allowed to be `#[track_caller]`
fn start(_argc: isize, _argv: *const *const u8) -> isize {
panic!("{}: oh no", std::panic::Location::caller());
}
12 changes: 12 additions & 0 deletions src/test/ui/rfc-2091-track-caller/error-with-start.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: `start` is not allowed to be `#[track_caller]`
--> $DIR/error-with-start.rs:4:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
LL | / fn start(_argc: isize, _argv: *const *const u8) -> isize {
LL | | panic!("{}: oh no", std::panic::Location::caller());
LL | | }
| |_- `start` is not allowed to be `#[track_caller]`

error: aborting due to previous error

0 comments on commit 32d14eb

Please sign in to comment.