Skip to content

Commit e32397a

Browse files
authored
Rollup merge of rust-lang#66060 - traxys:test_65401, r=michaelwoerister
Making ICEs and test them in incremental This adds: - A way to make the compiler ICE - A way to check for ICE in `cfail` tests with `should-ice` - A regression test for issue rust-lang#65401 I am not sure the attribute added `should-ice` is the best for this job
2 parents b9cf541 + e01d941 commit e32397a

31 files changed

+120
-37
lines changed

src/librustc/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ use syntax_pos::symbol::Symbol;
2929
// Queries marked with `fatal_cycle` do not need the latter implementation,
3030
// as they will raise an fatal error on query cycles instead.
3131
rustc_queries! {
32+
Other {
33+
query trigger_delay_span_bug(key: DefId) -> () {
34+
desc { "trigger a delay span bug" }
35+
}
36+
}
37+
3238
Other {
3339
/// Records the type of every item.
3440
query type_of(key: DefId) -> Ty<'tcx> {

src/librustc_codegen_utils/lib.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,58 @@ extern crate rustc;
1919

2020
use rustc::ty::TyCtxt;
2121
use rustc::ty::query::Providers;
22-
use rustc::hir::def_id::LOCAL_CRATE;
22+
use rustc::hir::def_id::{LOCAL_CRATE, DefId};
2323
use syntax::symbol::sym;
2424

2525
pub mod link;
2626
pub mod codegen_backend;
2727
pub mod symbol_names;
2828
pub mod symbol_names_test;
2929

30+
31+
pub fn trigger_delay_span_bug(tcx: TyCtxt<'_>, key: DefId) {
32+
tcx.sess.delay_span_bug(
33+
tcx.def_span(key),
34+
"delayed span bug triggered by #[rustc_error(delay_span_bug_from_inside_query)]"
35+
);
36+
}
37+
3038
/// check for the #[rustc_error] annotation, which forces an
3139
/// error in codegen. This is used to write compile-fail tests
3240
/// that actually test that compilation succeeds without
3341
/// reporting an error.
3442
pub fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
3543
if let Some((def_id, _)) = tcx.entry_fn(LOCAL_CRATE) {
36-
if tcx.has_attr(def_id, sym::rustc_error) {
37-
tcx.sess.span_fatal(tcx.def_span(def_id), "compilation successful");
44+
let attrs = &*tcx.get_attrs(def_id);
45+
for attr in attrs {
46+
if attr.check_name(sym::rustc_error) {
47+
match attr.meta_item_list() {
48+
// check if there is a #[rustc_error(delayed)]
49+
Some(list) => {
50+
if list.iter().any(|list_item| {
51+
list_item.ident().map(|i| i.name) ==
52+
Some(sym::delay_span_bug_from_inside_query)
53+
}) {
54+
tcx.ensure().trigger_delay_span_bug(def_id);
55+
}
56+
}
57+
// bare #[rustc_error]
58+
None => {
59+
tcx.sess.span_fatal(
60+
tcx.def_span(def_id),
61+
"fatal error triggered by #[rustc_error]"
62+
);
63+
}
64+
}
65+
}
3866
}
3967
}
4068
}
4169

4270
pub fn provide(providers: &mut Providers<'_>) {
4371
crate::symbol_names::provide(providers);
72+
*providers = Providers {
73+
trigger_delay_span_bug,
74+
..*providers
75+
};
4476
}

src/libsyntax/feature_gate/builtin_attrs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
543543
rustc_attr!(TEST, rustc_variance, Normal, template!(Word)),
544544
rustc_attr!(TEST, rustc_layout, Normal, template!(List: "field1, field2, ...")),
545545
rustc_attr!(TEST, rustc_regions, Normal, template!(Word)),
546-
rustc_attr!(TEST, rustc_error, Whitelisted, template!(Word)),
546+
rustc_attr!(
547+
TEST, rustc_error, Whitelisted,
548+
template!(Word, List: "delay_span_bug_from_inside_query")
549+
),
547550
rustc_attr!(TEST, rustc_dump_user_substs, Whitelisted, template!(Word)),
548551
rustc_attr!(TEST, rustc_if_this_changed, Whitelisted, template!(Word, List: "DepNode")),
549552
rustc_attr!(TEST, rustc_then_this_would_need, Whitelisted, template!(List: "DepNode")),

src/libsyntax_pos/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ symbols! {
236236
default_lib_allocator,
237237
default_type_parameter_fallback,
238238
default_type_params,
239+
delay_span_bug_from_inside_query,
239240
deny,
240241
deprecated,
241242
deref,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// revisions: cfail1 cfail2
2+
// should-ice
3+
// error-pattern: delayed span bug triggered by #[rustc_error(delay_span_bug_from_inside_query)]
4+
5+
#![feature(rustc_attrs)]
6+
7+
#[rustc_error(delay_span_bug_from_inside_query)]
8+
fn main() {}

src/test/ui/associated-types/bound-lifetime-constrained.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ fn clause2<T>() where T: for<'a> Fn() -> <() as Foo<'a>>::Item {
4545
}
4646

4747
#[rustc_error]
48-
fn main() { } //[ok]~ ERROR compilation successful
48+
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]

src/test/ui/associated-types/bound-lifetime-in-binding-only.ok.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: compilation successful
1+
error: fatal error triggered by #[rustc_error]
22
--> $DIR/bound-lifetime-in-binding-only.rs:71:1
33
|
44
LL | fn main() { }

src/test/ui/associated-types/bound-lifetime-in-binding-only.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@ fn ok3<T>() where for<'a> Parameterized<'a>: Foo<Item=&'a i32> {
6868
}
6969

7070
#[rustc_error]
71-
fn main() { } //[ok]~ ERROR compilation successful
71+
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]

src/test/ui/associated-types/bound-lifetime-in-return-only.ok.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: compilation successful
1+
error: fatal error triggered by #[rustc_error]
22
--> $DIR/bound-lifetime-in-return-only.rs:49:1
33
|
44
LL | fn main() { }

src/test/ui/associated-types/bound-lifetime-in-return-only.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ fn ok2(_: &dyn for<'a,'b> Fn<(&'b Parameterized<'a>,), Output=&'a i32>) {
4646
}
4747

4848
#[rustc_error]
49-
fn main() { } //[ok]~ ERROR compilation successful
49+
fn main() { } //[ok]~ ERROR fatal error triggered by #[rustc_error]

0 commit comments

Comments
 (0)