1 // Copyright 2012-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.
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.
14 //! Obsolete syntax that becomes too hard to parse can be removed.
19 /// The specific types of unsupported syntax
20 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
21 pub enum ObsoleteSyntax {
26 pub trait ParserObsoleteMethods {
27 /// Reports an obsolete syntax non-fatal error.
28 fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax);
37 impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
38 /// Reports an obsolete syntax non-fatal error.
39 fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
40 let (kind_str, desc, error) = match kind {
41 ObsoleteSyntax::ClosureKind => (
42 "`:`, `&mut:`, or `&:`",
43 "rely on inference instead",
46 ObsoleteSyntax::ExternCrateString => (
48 "use an identifier not in quotes instead",
49 false, // warning for now
53 self.report(sp, kind, kind_str, desc, error);
62 let mut err = if error {
63 self.diagnostic().struct_span_err(sp, &format!("obsolete syntax: {}", kind_str))
65 self.diagnostic().struct_span_warn(sp, &format!("obsolete syntax: {}", kind_str))
68 if !self.obsolete_set.contains(&kind) &&
69 (error || self.sess.span_diagnostic.can_emit_warnings) {
70 err.note(&format!("{}", desc));
71 self.obsolete_set.insert(kind);