]>
git.proxmox.com Git - rustc.git/blob - src/libsyntax/show_span.rs
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.
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.
13 //! This module shows spans for all expressions in the crate
14 //! to help with compiler debugging.
16 use std
::str::FromStr
;
29 impl FromStr
for Mode
{
31 fn from_str(s
: &str) -> Result
<Mode
, ()> {
33 "expr" => Mode
::Expression
,
34 "pat" => Mode
::Pattern
,
42 struct ShowSpanVisitor
<'a
> {
43 span_diagnostic
: &'a errors
::Handler
,
47 impl<'a
, 'v
> Visitor
<'v
> for ShowSpanVisitor
<'a
> {
48 fn visit_expr(&mut self, e
: &ast
::Expr
) {
49 if let Mode
::Expression
= self.mode
{
50 self.span_diagnostic
.span_warn(e
.span
, "expression");
52 visit
::walk_expr(self, e
);
55 fn visit_pat(&mut self, p
: &ast
::Pat
) {
56 if let Mode
::Pattern
= self.mode
{
57 self.span_diagnostic
.span_warn(p
.span
, "pattern");
59 visit
::walk_pat(self, p
);
62 fn visit_ty(&mut self, t
: &ast
::Ty
) {
63 if let Mode
::Type
= self.mode
{
64 self.span_diagnostic
.span_warn(t
.span
, "type");
66 visit
::walk_ty(self, t
);
69 fn visit_mac(&mut self, mac
: &ast
::Mac
) {
70 visit
::walk_mac(self, mac
);
74 pub fn run(span_diagnostic
: &errors
::Handler
,
77 let mode
= match mode
.parse().ok() {
81 let mut v
= ShowSpanVisitor
{
82 span_diagnostic
: span_diagnostic
,
85 visit
::walk_crate(&mut v
, krate
);