]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/lib.rs
Rollup merge of #67506 - qnighy:remove-iter-private, r=Dylan-DPC
[rust.git] / src / librustc_codegen_utils / lib.rs
1 //! # Note
2 //!
3 //! This API is completely unstable and subject to change.
4
5 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
6
7 #![feature(arbitrary_self_types)]
8 #![feature(box_patterns)]
9 #![feature(box_syntax)]
10 #![feature(core_intrinsics)]
11 #![feature(never_type)]
12 #![feature(nll)]
13 #![feature(in_band_lifetimes)]
14
15 #![recursion_limit="256"]
16
17 #[macro_use]
18 extern crate rustc;
19
20 use rustc::ty::TyCtxt;
21 use rustc::ty::query::Providers;
22 use rustc::hir::def_id::{LOCAL_CRATE, DefId};
23 use syntax::symbol::sym;
24
25 pub mod link;
26 pub mod codegen_backend;
27 pub mod symbol_names;
28 pub mod symbol_names_test;
29
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
38 /// check for the #[rustc_error] annotation, which forces an
39 /// error in codegen. This is used to write compile-fail tests
40 /// that actually test that compilation succeeds without
41 /// reporting an error.
42 pub fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
43     if let Some((def_id, _)) = tcx.entry_fn(LOCAL_CRATE) {
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             }
66         }
67     }
68 }
69
70 pub fn provide(providers: &mut Providers<'_>) {
71     crate::symbol_names::provide(providers);
72     *providers = Providers {
73         trigger_delay_span_bug,
74         ..*providers
75     };
76 }