Skip to content

Commit 228987c

Browse files
committed
Rollup merge of rust-lang#24430 - laumann:trace-macros-flag, r=pnkfelix
This is the second attempt at turning the trace_macros macro into a compiler flag. See rust-lang#22619
2 parents 5300468 + c0139ca commit 228987c

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed

src/librustc/session/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
606606
"Force overflow checks on or off"),
607607
force_dropflag_checks: Option<bool> = (None, parse_opt_bool,
608608
"Force drop flag checks on or off"),
609+
trace_macros: bool = (false, parse_bool,
610+
"For every macro invocation, print its name and arguments"),
609611
}
610612

611613
pub fn default_lib_output() -> CrateType {
@@ -667,7 +669,7 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
667669
Ok(t) => t,
668670
Err(e) => {
669671
sp.handler().fatal(&format!("Error loading target specification: {}", e));
670-
}
672+
}
671673
};
672674

673675
let (int_type, uint_type) = match &target.target_pointer_width[..] {

src/librustc_driver/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
483483
crate_name: crate_name.to_string(),
484484
features: Some(&features),
485485
recursion_limit: sess.recursion_limit.get(),
486+
trace_mac: sess.opts.debugging_opts.trace_macros,
486487
};
487488
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
488489
cfg,

src/libsyntax/ext/base.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ pub struct ExtCtxt<'a> {
554554
pub use_std: bool,
555555

556556
pub mod_path: Vec<ast::Ident> ,
557-
pub trace_mac: bool,
558557
pub exported_macros: Vec<ast::MacroDef>,
559558

560559
pub syntax_env: SyntaxEnv,
@@ -572,7 +571,6 @@ impl<'a> ExtCtxt<'a> {
572571
mod_path: Vec::new(),
573572
ecfg: ecfg,
574573
use_std: true,
575-
trace_mac: false,
576574
exported_macros: Vec::new(),
577575
syntax_env: env,
578576
recursion_count: 0,
@@ -732,10 +730,10 @@ impl<'a> ExtCtxt<'a> {
732730
self.parse_sess.span_diagnostic.handler().bug(msg);
733731
}
734732
pub fn trace_macros(&self) -> bool {
735-
self.trace_mac
733+
self.ecfg.trace_mac
736734
}
737735
pub fn set_trace_macros(&mut self, x: bool) {
738-
self.trace_mac = x
736+
self.ecfg.trace_mac = x
739737
}
740738
pub fn ident_of(&self, st: &str) -> ast::Ident {
741739
str_to_ident(st)

src/libsyntax/ext/expand.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ pub struct ExpansionConfig<'feat> {
14061406
pub crate_name: String,
14071407
pub features: Option<&'feat Features>,
14081408
pub recursion_limit: usize,
1409+
pub trace_mac: bool,
14091410
}
14101411

14111412
macro_rules! feature_tests {
@@ -1427,6 +1428,7 @@ impl<'feat> ExpansionConfig<'feat> {
14271428
crate_name: crate_name,
14281429
features: None,
14291430
recursion_limit: 64,
1431+
trace_mac: false,
14301432
}
14311433
}
14321434

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This test verifies that "-Z trace-macros" works as it should. The traditional
2+
# "hello world" program provides a small example of this as not only println! is
3+
# listed, but also print! (since println! expands to this)
4+
5+
-include ../tools.mk
6+
7+
all:
8+
$(RUSTC) -Z trace-macros hello.rs > $(TMPDIR)/hello.out
9+
diff -u $(TMPDIR)/hello.out hello.trace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
println!("Hello, World!");
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
println! { "Hello, World!" }
2+
print! { concat ! ( "Hello, World!" , "\n" ) }

0 commit comments

Comments
 (0)