1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! `rustc_utils` provides a wide variety of utilities for working with the Rust compiler.
//! We developed these functions in the course of building various research projects with
//! rustc.
//!
//! Most of the functionality is organized into extension traits implemented for types
//! in the compiler, such as one for MIR control-flow graphs ([`BodyExt`]) or one for
//! text ranges ([`SpanExt`]).
//!
//! This crate is pinned to a specific nightly version of the Rust compiler.
//! See the [`rustc_plugin` README](https://github.com/cognitive-engineering-lab/rustc_plugin)
//! for details on how to add `rustc_utils` as a dependency.

#![feature(
  rustc_private,
  negative_impls,        // for !Send
  min_specialization,    // for rustc_index::newtype_index 
  type_alias_impl_trait, // for iterators in traits
  lazy_cell,             // for global constants w/ heap allocation
  box_patterns,          // for ergonomics
  let_chains,            // for places_conflict module
  exact_size_is_empty,   // for graphviz module
  impl_trait_in_assoc_type,
  doc_auto_cfg,          // for feature gates in documentation
)]
#![allow(clippy::len_zero, clippy::len_without_is_empty)]

extern crate either;
extern crate rustc_borrowck;
extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_graphviz;
extern crate rustc_hir;
extern crate rustc_index;
extern crate rustc_infer;
extern crate rustc_interface;
extern crate rustc_macros;
extern crate rustc_middle;
extern crate rustc_mir_dataflow;
extern crate rustc_mir_transform;
extern crate rustc_serialize;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
extern crate rustc_trait_selection;
extern crate rustc_type_ir;
extern crate smallvec;

pub mod cache;
pub mod hir;
pub mod mir;
pub mod source_map;
#[cfg(feature = "test")]
pub mod test_utils;
pub mod timer;

pub use crate::{
  hir::ty::TyExt,
  mir::{
    adt_def::AdtDefExt, body::BodyExt, mutability::MutabilityExt, operand::OperandExt,
    place::PlaceExt,
  },
  source_map::span::{SpanDataExt, SpanExt},
};

/// Utility for hashset literals. Same as maplit::hashset but works with FxHasher.
#[macro_export]
macro_rules! hashset {
  (@single $($x:tt)*) => (());
  (@count $($rest:expr),*) => (<[()]>::len(&[$(hashset!(@single $rest)),*]));

  ($($key:expr,)+) => { hashset!($($key),+) };
  ($($key:expr),*) => {
      {
          let _cap = hashset!(@count $($key),*);
          let mut _set = ::rustc_data_structures::fx::FxHashSet::default();
          let _ = _set.try_reserve(_cap);
          $(
              let _ = _set.insert($key);
          )*
          _set
      }
  };
}