]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/lib.rs
Auto merge of #68277 - michaelwoerister:re-export-dylib-instances, r=alexcrichton
[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 #![feature(arbitrary_self_types)]
7 #![feature(box_patterns)]
8 #![feature(box_syntax)]
9 #![feature(core_intrinsics)]
10 #![feature(never_type)]
11 #![feature(nll)]
12 #![feature(in_band_lifetimes)]
13 #![recursion_limit = "256"]
14
15 #[macro_use]
16 extern crate rustc;
17
18 use rustc::ty::query::Providers;
19 use rustc::ty::TyCtxt;
20 use rustc_hir::def_id::{DefId, LOCAL_CRATE};
21 use rustc_span::symbol::sym;
22
23 pub mod codegen_backend;
24 pub mod link;
25 pub mod symbol_names;
26 pub mod symbol_names_test;
27
28 pub fn trigger_delay_span_bug(tcx: TyCtxt<'_>, key: DefId) {
29     tcx.sess.delay_span_bug(
30         tcx.def_span(key),
31         "delayed span bug triggered by #[rustc_error(delay_span_bug_from_inside_query)]",
32     );
33 }
34
35 /// check for the #[rustc_error] annotation, which forces an
36 /// error in codegen. This is used to write compile-fail tests
37 /// that actually test that compilation succeeds without
38 /// reporting an error.
39 pub fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
40     if let Some((def_id, _)) = tcx.entry_fn(LOCAL_CRATE) {
41         let attrs = &*tcx.get_attrs(def_id);
42         for attr in attrs {
43             if attr.check_name(sym::rustc_error) {
44                 match attr.meta_item_list() {
45                     // check if there is a #[rustc_error(delayed)]
46                     Some(list) => {
47                         if list.iter().any(|list_item| {
48                             list_item.ident().map(|i| i.name)
49                                 == Some(sym::delay_span_bug_from_inside_query)
50                         }) {
51                             tcx.ensure().trigger_delay_span_bug(def_id);
52                         }
53                     }
54                     // bare #[rustc_error]
55                     None => {
56                         tcx.sess.span_fatal(
57                             tcx.def_span(def_id),
58                             "fatal error triggered by #[rustc_error]",
59                         );
60                     }
61                 }
62             }
63         }
64     }
65 }
66
67 pub fn provide(providers: &mut Providers<'_>) {
68     crate::symbol_names::provide(providers);
69     *providers = Providers { trigger_delay_span_bug, ..*providers };
70 }