Skip to content

Commit da2ee5d

Browse files
committed
reject fn panic_impl<T>(_: &PanicInfo) -> !
1 parent 4c84d38 commit da2ee5d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/librustc_typeck/check/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ use syntax_pos::{self, BytePos, Span, MultiSpan};
130130
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
131131
use rustc::hir::itemlikevisit::ItemLikeVisitor;
132132
use rustc::hir::map::Node;
133-
use rustc::hir::{self, PatKind};
133+
use rustc::hir::{self, PatKind, Item_};
134134
use rustc::middle::lang_items;
135135

136136
mod autoderef;
@@ -1133,7 +1133,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11331133
if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() {
11341134
if panic_impl_did == fn_hir_id.owner_def_id() {
11351135
if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() {
1136-
if ret_ty.sty != ty::TyNever {
1136+
if declared_ret_ty.sty != ty::TyNever {
11371137
fcx.tcx.sess.span_err(
11381138
decl.output.span(),
11391139
"return type should be `!`",
@@ -1161,6 +1161,17 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11611161
"argument should be `&PanicInfo`",
11621162
);
11631163
}
1164+
1165+
if let Node::NodeItem(item) = fcx.tcx.hir.get(fn_id) {
1166+
if let Item_::ItemFn(_, _, _, _, ref generics, _) = item.node {
1167+
if !generics.params.is_empty() {
1168+
fcx.tcx.sess.span_err(
1169+
span,
1170+
"`#[panic_implementation]` function should have no type parameters",
1171+
);
1172+
}
1173+
}
1174+
}
11641175
} else {
11651176
fcx.tcx.sess.span_err(span, "function should have one argument");
11661177
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
// compile-flags:-C panic=abort
12+
13+
#![feature(panic_implementation)]
14+
#![no_std]
15+
#![no_main]
16+
17+
use core::panic::PanicInfo;
18+
19+
#[panic_implementation]
20+
fn panic<T>(pi: &PanicInfo) -> ! {
21+
//~^ ERROR `#[panic_implementation]` function should have no type parameters
22+
loop {}
23+
}

0 commit comments

Comments
 (0)