rustc: implement a pretty mode to print ident/name's ctxt & gensyms.
`--pretty expanded,hygiene` is helpful with debugging macro issues, since two identifiers/names can be textually the same, but different internally (resulting in weird "undefined variable" errors).
This commit is contained in:
parent
ddc8cc92c9
commit
32e437161d
6 changed files with 116 additions and 3 deletions
20
src/test/run-make/pretty-expanded-hygiene/Makefile
Normal file
20
src/test/run-make/pretty-expanded-hygiene/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
-include ../tools.mk
|
||||
|
||||
REPLACEMENT := s/[0-9][0-9]*\#[0-9][0-9]*/$(shell date)/g
|
||||
|
||||
all:
|
||||
$(RUSTC) -o $(TMPDIR)/input.out --pretty expanded,hygiene input.rs
|
||||
|
||||
# the name/ctxt numbers are very internals-dependent and thus
|
||||
# change relatively frequently, and testing for their exact values
|
||||
# them will fail annoyingly, so we just check their positions
|
||||
# (using a non-constant replacement like this will make it less
|
||||
# likely the compiler matches whatever other dummy value we
|
||||
# choose).
|
||||
#
|
||||
# (These need to be out-of-place because OSX/BSD & GNU sed
|
||||
# differ.)
|
||||
sed "$(REPLACEMENT)" input.pp.rs > $(TMPDIR)/input.pp.rs
|
||||
sed "$(REPLACEMENT)" $(TMPDIR)/input.out > $(TMPDIR)/input.out.replaced
|
||||
|
||||
diff -u $(TMPDIR)/input.out.replaced $(TMPDIR)/input.pp.rs
|
||||
16
src/test/run-make/pretty-expanded-hygiene/input.pp.rs
Executable file
16
src/test/run-make/pretty-expanded-hygiene/input.pp.rs
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(macro_rules)]
|
||||
// minimal junk
|
||||
#![no_std]
|
||||
|
||||
|
||||
fn bar /* 62#0 */() { let x /* 59#2 */ = 1; y /* 61#4 */ + x /* 59#5 */ }
|
||||
22
src/test/run-make/pretty-expanded-hygiene/input.rs
Executable file
22
src/test/run-make/pretty-expanded-hygiene/input.rs
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(macro_rules)]
|
||||
// minimal junk
|
||||
#![no_std]
|
||||
|
||||
macro_rules! foo {
|
||||
($x: ident) => { y + $x }
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
let x = 1;
|
||||
foo!(x)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue