Skip to content

Commit 32d14eb

Browse files
committed
Auto merge of #75130 - lcnr:array_chunks, r=ecstatic-morse
forbid `#[track_caller]` on main fixes #75125 cc @anp
2 parents 07f1fde + 9127e27 commit 32d14eb

File tree

7 files changed

+75
-6
lines changed

7 files changed

+75
-6
lines changed

src/librustc_typeck/lib.rs

+37-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ use rustc_middle::ty::query::Providers;
100100
use rustc_middle::ty::{self, Ty, TyCtxt};
101101
use rustc_middle::util;
102102
use rustc_session::config::EntryFnType;
103-
use rustc_span::{Span, DUMMY_SP};
103+
use rustc_span::{symbol::sym, Span, DUMMY_SP};
104104
use rustc_target::spec::abi::Abi;
105105
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
106106
use rustc_trait_selection::traits::{
@@ -194,6 +194,23 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
194194
.emit();
195195
error = true;
196196
}
197+
198+
for attr in it.attrs {
199+
if attr.check_name(sym::track_caller) {
200+
tcx.sess
201+
.struct_span_err(
202+
attr.span,
203+
"`main` function is not allowed to be `#[track_caller]`",
204+
)
205+
.span_label(
206+
main_span,
207+
"`main` function is not allowed to be `#[track_caller]`",
208+
)
209+
.emit();
210+
error = true;
211+
}
212+
}
213+
197214
if error {
198215
return;
199216
}
@@ -268,12 +285,29 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
268285
tcx.sess,
269286
span,
270287
E0752,
271-
"start is not allowed to be `async`"
288+
"`start` is not allowed to be `async`"
272289
)
273-
.span_label(span, "start is not allowed to be `async`")
290+
.span_label(span, "`start` is not allowed to be `async`")
274291
.emit();
275292
error = true;
276293
}
294+
295+
for attr in it.attrs {
296+
if attr.check_name(sym::track_caller) {
297+
tcx.sess
298+
.struct_span_err(
299+
attr.span,
300+
"`start` is not allowed to be `#[track_caller]`",
301+
)
302+
.span_label(
303+
start_span,
304+
"`start` is not allowed to be `#[track_caller]`",
305+
)
306+
.emit();
307+
error = true;
308+
}
309+
}
310+
277311
if error {
278312
return;
279313
}

src/test/ui/async-await/issue-68523-start.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
#[start]
66
pub async fn start(_: isize, _: *const *const u8) -> isize {
7-
//~^ ERROR start is not allowed to be `async`
7+
//~^ ERROR `start` is not allowed to be `async`
88
0
99
}

src/test/ui/async-await/issue-68523-start.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0752]: start is not allowed to be `async`
1+
error[E0752]: `start` is not allowed to be `async`
22
--> $DIR/issue-68523-start.rs:6:1
33
|
44
LL | pub async fn start(_: isize, _: *const *const u8) -> isize {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ start is not allowed to be `async`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `start` is not allowed to be `async`
66

77
error: aborting due to previous error
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[track_caller] //~ ERROR `main` function is not allowed to be
2+
fn main() {
3+
panic!("{}: oh no", std::panic::Location::caller());
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: `main` function is not allowed to be `#[track_caller]`
2+
--> $DIR/error-with-main.rs:1:1
3+
|
4+
LL | #[track_caller]
5+
| ^^^^^^^^^^^^^^^
6+
LL | / fn main() {
7+
LL | | panic!("{}: oh no", std::panic::Location::caller());
8+
LL | | }
9+
| |_- `main` function is not allowed to be `#[track_caller]`
10+
11+
error: aborting due to previous error
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(start)]
2+
3+
#[start]
4+
#[track_caller] //~ ERROR `start` is not allowed to be `#[track_caller]`
5+
fn start(_argc: isize, _argv: *const *const u8) -> isize {
6+
panic!("{}: oh no", std::panic::Location::caller());
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: `start` is not allowed to be `#[track_caller]`
2+
--> $DIR/error-with-start.rs:4:1
3+
|
4+
LL | #[track_caller]
5+
| ^^^^^^^^^^^^^^^
6+
LL | / fn start(_argc: isize, _argv: *const *const u8) -> isize {
7+
LL | | panic!("{}: oh no", std::panic::Location::caller());
8+
LL | | }
9+
| |_- `start` is not allowed to be `#[track_caller]`
10+
11+
error: aborting due to previous error
12+

0 commit comments

Comments
 (0)