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