]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
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 | ||
1a4d82fc JJ |
11 | //! Support for parsing unsupported, old syntaxes, for the purpose of reporting errors. Parsing of |
12 | //! these syntaxes is tested by compile-test/obsolete-syntax.rs. | |
13 | //! | |
14 | //! Obsolete syntax that becomes too hard to parse can be removed. | |
223e47cc | 15 | |
1a4d82fc JJ |
16 | use codemap::Span; |
17 | use parse::parser; | |
223e47cc LB |
18 | |
19 | /// The specific types of unsupported syntax | |
c34b1796 | 20 | #[derive(Copy, Clone, PartialEq, Eq, Hash)] |
223e47cc | 21 | pub enum ObsoleteSyntax { |
85aaf69f | 22 | ClosureKind, |
c34b1796 | 23 | ExternCrateString, |
223e47cc LB |
24 | } |
25 | ||
970d7e83 | 26 | pub trait ParserObsoleteMethods { |
223e47cc | 27 | /// Reports an obsolete syntax non-fatal error. |
1a4d82fc | 28 | fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax); |
1a4d82fc JJ |
29 | fn report(&mut self, |
30 | sp: Span, | |
970d7e83 LB |
31 | kind: ObsoleteSyntax, |
32 | kind_str: &str, | |
85aaf69f SL |
33 | desc: &str, |
34 | error: bool); | |
970d7e83 LB |
35 | } |
36 | ||
1a4d82fc | 37 | impl<'a> ParserObsoleteMethods for parser::Parser<'a> { |
970d7e83 | 38 | /// Reports an obsolete syntax non-fatal error. |
1a4d82fc | 39 | fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) { |
85aaf69f | 40 | let (kind_str, desc, error) = match kind { |
85aaf69f SL |
41 | ObsoleteSyntax::ClosureKind => ( |
42 | "`:`, `&mut:`, or `&:`", | |
43 | "rely on inference instead", | |
44 | true, | |
970d7e83 | 45 | ), |
c34b1796 AL |
46 | ObsoleteSyntax::ExternCrateString => ( |
47 | "\"crate-name\"", | |
48 | "use an identifier not in quotes instead", | |
85aaf69f | 49 | false, // warning for now |
970d7e83 | 50 | ), |
223e47cc LB |
51 | }; |
52 | ||
85aaf69f | 53 | self.report(sp, kind, kind_str, desc, error); |
223e47cc LB |
54 | } |
55 | ||
1a4d82fc JJ |
56 | fn report(&mut self, |
57 | sp: Span, | |
970d7e83 LB |
58 | kind: ObsoleteSyntax, |
59 | kind_str: &str, | |
85aaf69f SL |
60 | desc: &str, |
61 | error: bool) { | |
62 | if error { | |
c34b1796 | 63 | self.span_err(sp, &format!("obsolete syntax: {}", kind_str)); |
85aaf69f | 64 | } else { |
c34b1796 | 65 | self.span_warn(sp, &format!("obsolete syntax: {}", kind_str)); |
85aaf69f | 66 | } |
223e47cc | 67 | |
d9579d0f AL |
68 | if !self.obsolete_set.contains(&kind) && |
69 | (error || self.sess.span_diagnostic.handler().can_emit_warnings) { | |
1a4d82fc JJ |
70 | self.sess |
71 | .span_diagnostic | |
72 | .handler() | |
c34b1796 | 73 | .note(&format!("{}", desc)); |
223e47cc LB |
74 | self.obsolete_set.insert(kind); |
75 | } | |
76 | } | |
223e47cc | 77 | } |