forbid #[track_caller]
on main
This commit is contained in:
parent
d51b71a35a
commit
06dbd06e4d
5 changed files with 70 additions and 1 deletions
|
@ -100,7 +100,7 @@ use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_middle::util;
|
use rustc_middle::util;
|
||||||
use rustc_session::config::EntryFnType;
|
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_target::spec::abi::Abi;
|
||||||
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
|
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
|
||||||
use rustc_trait_selection::traits::{
|
use rustc_trait_selection::traits::{
|
||||||
|
@ -194,6 +194,23 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
|
||||||
.emit();
|
.emit();
|
||||||
error = true;
|
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 {
|
if error {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -274,6 +291,23 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) {
|
||||||
.emit();
|
.emit();
|
||||||
error = true;
|
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 {
|
if error {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
4
src/test/ui/rfc-2091-track-caller/error-with-main.rs
Normal file
4
src/test/ui/rfc-2091-track-caller/error-with-main.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#[track_caller] //~ ERROR `main` function is not allowed to be
|
||||||
|
fn main() {
|
||||||
|
panic!("{}: oh no", std::panic::Location::caller());
|
||||||
|
}
|
12
src/test/ui/rfc-2091-track-caller/error-with-main.stderr
Normal file
12
src/test/ui/rfc-2091-track-caller/error-with-main.stderr
Normal file
|
@ -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
src/test/ui/rfc-2091-track-caller/error-with-start.rs
Normal file
7
src/test/ui/rfc-2091-track-caller/error-with-start.rs
Normal file
|
@ -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
src/test/ui/rfc-2091-track-caller/error-with-start.stderr
Normal file
12
src/test/ui/rfc-2091-track-caller/error-with-start.stderr
Normal file
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue