Skip to content

Commit

Permalink
Improve error on const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 22, 2024
1 parent 6a3d6bc commit 2b880e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ pub fn no_panic(args: TokenStream, input: TokenStream) -> TokenStream {
fn parse(args: TokenStream2, input: TokenStream2) -> Result<ItemFn> {
let function: ItemFn = syn::parse2(input)?;
let _: Nothing = syn::parse2::<Nothing>(args)?;
if function.sig.constness.is_some() {
return Err(Error::new(
Span::call_site(),
"no_panic attribute on const fn is not supported",
));
}
if function.sig.asyncness.is_some() {
return Err(Error::new(
Span::call_site(),
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/const-fn.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
error[E0015]: cannot call non-const closure in constant functions
error: no_panic attribute on const fn is not supported
--> tests/ui/const-fn.rs:3:1
|
3 | #[no_panic]
| ^^^^^^^^^^^
|
= note: closures need an RFC before allowed to be called in constant functions
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the attribute macro `no_panic` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 2b880e6

Please sign in to comment.