]>
git.proxmox.com Git - rustc.git/blob - vendor/chalk-macros/src/lib.rs
1 #![feature(crate_visibility_modifier)]
2 #![feature(macro_vis_matcher)]
4 use std
::cell
::RefCell
;
7 extern crate lazy_static
;
13 pub static ref DEBUG_ENABLED
: bool
= {
15 env
::var("CHALK_DEBUG")
17 .and_then(|s
| s
.parse
::<u32>().ok())
22 pub static ref INFO_ENABLED
: bool
= {
24 env
::var("CHALK_DEBUG")
26 .and_then(|s
| s
.parse
::<u32>().ok())
33 crate static INDENT
: RefCell
<Vec
<String
>> = RefCell
::new(vec
![]);
36 // When CHALK_DEBUG is enabled, we only allow this many frames of
37 // nested processing, at which point we assume something has gone
39 const OVERFLOW_DEPTH
: usize = 100;
44 if *$
crate::DEBUG_ENABLED
{
45 $
crate::dump(&format
!($
($t
)*), "");
51 macro_rules
! debug_heading
{
53 let _
= &if *$
crate::DEBUG_ENABLED
{
54 let string
= format
!($
($t
)*);
55 $
crate::dump(&string
, " {");
56 $
crate::Indent
::new(true, string
)
58 $
crate::Indent
::new(false, String
::new())
66 if *$
crate::INFO_ENABLED
{
67 $
crate::dump(&format
!($
($t
)*), "");
73 macro_rules
! info_heading
{
75 let _
= &if *$
crate::INFO_ENABLED
{
76 let string
= format
!($
($t
)*);
77 $
crate::dump(&string
, " {");
78 $
crate::Indent
::new(true, string
)
80 $
crate::Indent
::new(false, String
::new())
85 pub fn dump(string
: &str, suffix
: &str) {
86 let indent
= INDENT
.with(|i
| i
.borrow().len());
88 for line
in string
.lines() {
105 eprintln
!("{}", suffix
);
113 pub fn new(enabled
: bool
, value
: String
) -> Self {
116 i
.borrow_mut().push(value
);
117 if i
.borrow().len() > OVERFLOW_DEPTH
{
118 eprintln
!("CHALK_DEBUG OVERFLOW:");
119 for v
in i
.borrow().iter().rev() {
120 eprintln
!("- {}", v
);
122 panic
!("CHALK_DEBUG OVERFLOW")
130 impl Drop
for Indent
{
133 INDENT
.with(|i
| i
.borrow_mut().pop().unwrap());