rustc_utils/
lib.rs

1//! `rustc_utils` provides a wide variety of utilities for working with the Rust compiler.
2//! We developed these functions in the course of building various research projects with
3//! rustc.
4//!
5//! Most of the functionality is organized into extension traits implemented for types
6//! in the compiler, such as one for MIR control-flow graphs ([`BodyExt`]) or one for
7//! text ranges ([`SpanExt`]).
8//!
9//! This crate is pinned to a specific nightly version of the Rust compiler.
10//! See the [`rustc_plugin` README](https://github.com/cognitive-engineering-lab/rustc_plugin)
11//! for details on how to add `rustc_utils` as a dependency.
12
13#![feature(
14  rustc_private,
15  negative_impls,        // for !Send
16  min_specialization,    // for rustc_index::newtype_index 
17  type_alias_impl_trait, // for iterators in traits
18  box_patterns,          // for ergonomics
19  exact_size_is_empty,   // for graphviz module
20  impl_trait_in_assoc_type,
21  doc_auto_cfg,          // for feature gates in documentation
22)]
23#![warn(clippy::pedantic)]
24#![allow(
25  clippy::len_zero,
26  clippy::len_without_is_empty,
27  clippy::must_use_candidate,
28  clippy::return_self_not_must_use,
29  clippy::missing_panics_doc,
30  clippy::missing_errors_doc,
31  clippy::doc_markdown,
32  clippy::single_match_else,
33  clippy::if_not_else,
34  clippy::map_unwrap_or,
35  clippy::match_wildcard_for_single_variants,
36  clippy::items_after_statements,
37  clippy::implicit_hasher,
38  clippy::wildcard_imports
39)]
40
41extern crate either;
42extern crate rustc_abi;
43extern crate rustc_borrowck;
44extern crate rustc_data_structures;
45extern crate rustc_driver;
46extern crate rustc_errors;
47extern crate rustc_graphviz;
48extern crate rustc_hir;
49extern crate rustc_index;
50extern crate rustc_infer;
51extern crate rustc_interface;
52extern crate rustc_lint_defs;
53extern crate rustc_macros;
54extern crate rustc_middle;
55extern crate rustc_mir_dataflow;
56extern crate rustc_mir_transform;
57extern crate rustc_serialize;
58extern crate rustc_session;
59extern crate rustc_span;
60extern crate rustc_target;
61extern crate rustc_trait_selection;
62extern crate rustc_type_ir;
63extern crate smallvec;
64
65pub mod cache;
66pub mod hir;
67pub mod mir;
68pub mod source_map;
69#[cfg(feature = "test")]
70pub mod test_utils;
71pub mod timer;
72
73pub use crate::{
74  hir::ty::TyExt,
75  mir::{
76    adt_def::AdtDefExt, body::BodyExt, mutability::MutabilityExt, operand::OperandExt,
77    place::PlaceExt,
78  },
79  source_map::span::{SpanDataExt, SpanExt},
80};
81
82/// Utility for hashset literals. Same as `maplit::hashset` but works with `FxHasher`.
83#[macro_export]
84macro_rules! hashset {
85  (@single $($x:tt)*) => (());
86  (@count $($rest:expr),*) => (<[()]>::len(&[$(hashset!(@single $rest)),*]));
87
88  ($($key:expr,)+) => { hashset!($($key),+) };
89  ($($key:expr),*) => {
90      {
91          let _cap = hashset!(@count $($key),*);
92          let mut _set = ::rustc_data_structures::fx::FxHashSet::default();
93          let _ = _set.try_reserve(_cap);
94          $(
95              let _ = _set.insert($key);
96          )*
97          _set
98      }
99  };
100}