Skip to content

Issue #4830 fix #4861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/libsyntax/parse/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub enum ObsoleteSyntax {
ObsoleteFieldTerminator,
ObsoleteStructCtor,
ObsoleteWith,
ObsoleteClassMethod,
ObsoleteClassTraits,
ObsoletePrivSection,
ObsoleteModeInFnType,
Expand Down Expand Up @@ -85,10 +84,6 @@ pub impl Parser {
"record update is done with `..`, e.g. \
`MyStruct { foo: bar, .. baz }`"
),
ObsoleteClassMethod => (
"class method",
"methods should be defined inside impls"
),
ObsoleteClassTraits => (
"class traits",
"implemented traits are specified on the impl, as in \
Expand Down
71 changes: 24 additions & 47 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use parse::lexer::TokenAndSpan;
use parse::obsolete::{ObsoleteClassTraits, ObsoleteModeInFnType};
use parse::obsolete::{ObsoleteLet, ObsoleteFieldTerminator};
use parse::obsolete::{ObsoleteMoveInit, ObsoleteBinaryMove};
use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith, ObsoleteClassMethod};
use parse::obsolete::{ObsoleteStructCtor, ObsoleteWith};
use parse::obsolete::{ObsoleteSyntax, ObsoleteLowerCaseKindBounds};
use parse::obsolete::{ObsoleteUnsafeBlock};
use parse::prec::{as_prec, token_to_binop};
Expand Down Expand Up @@ -3002,52 +3002,29 @@ pub impl Parser {
}

fn parse_single_class_item(vis: visibility) -> @struct_field {
let obsolete_let = self.eat_obsolete_ident("let");
if obsolete_let { self.obsolete(copy self.last_span, ObsoleteLet) }

let parse_obsolete_method =
!((obsolete_let || self.is_keyword(~"mut") ||
!self.is_any_keyword(copy self.token))
&& !self.token_is_pound_or_doc_comment(copy self.token));
if self.eat_obsolete_ident("let") {
self.obsolete(copy self.last_span, ObsoleteLet);
}

if !parse_obsolete_method {
let a_var = self.parse_instance_var(vis);
match self.token {
token::SEMI => {
self.obsolete(copy self.span, ObsoleteFieldTerminator);
self.bump();
}
token::COMMA => {
self.bump();
}
token::RBRACE => {}
_ => {
self.span_fatal(copy self.span,
fmt!("expected `;`, `,`, or '}' but \
found `%s`",
token_to_str(self.reader,
self.token)));
}
}
a_var
} else {
self.obsolete(copy self.span, ObsoleteClassMethod);
self.parse_method();
// bogus value
@spanned(
self.span.lo,
self.span.hi,
ast::struct_field_ {
kind: unnamed_field,
id: self.get_id(),
ty: @ast::Ty {
id: self.get_id(),
node: ty_nil,
span: copy self.span,
}
}
)
let a_var = self.parse_instance_var(vis);
match self.token {
token::SEMI => {
self.obsolete(copy self.span, ObsoleteFieldTerminator);
self.bump();
}
token::COMMA => {
self.bump();
}
token::RBRACE => {}
_ => {
self.span_fatal(copy self.span,
fmt!("expected `;`, `,`, or '}' but \
found `%s`",
token_to_str(self.reader,
self.token)));
}
}
a_var
}

fn parse_dtor(attrs: ~[attribute]) -> class_contents {
Expand All @@ -3062,6 +3039,8 @@ pub impl Parser {
return members(~[]);
}

let attrs = self.parse_outer_attributes();

if self.eat_keyword(~"priv") {
return members(~[self.parse_single_class_item(private)])
}
Expand All @@ -3070,8 +3049,6 @@ pub impl Parser {
return members(~[self.parse_single_class_item(public)]);
}

let attrs = self.parse_outer_attributes();

if self.try_parse_obsolete_struct_ctor() {
return members(~[]);
}
Expand Down
8 changes: 0 additions & 8 deletions src/test/compile-fail/obsolete-syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ struct s {
//~^ ERROR obsolete syntax: struct constructor
}

struct ss {
fn foo() { }
//~^ ERROR obsolete syntax: class method
#[whatever]
fn foo() { }
//~^ ERROR obsolete syntax: class method
}

struct q : r {
//~^ ERROR obsolete syntax: class traits
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/issue-4830.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2012 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.

pub struct Scheduler {
/// The event loop used to drive the scheduler and perform I/O
priv event_loop: ~int
}

pub fn main() { }