diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-08-06 17:44:07 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-08-06 18:01:26 -0700 |
| commit | a4cedd9598ec44d4f475adc3a9e62edcd08bc741 (patch) | |
| tree | 6e7019258860b52b9abc1efb727b16a52157b2b2 /src/libsyntax/parse | |
| parent | 253dfc338775570a76d6c68bf349b2026e700797 (diff) | |
| download | rust-a4cedd9598ec44d4f475adc3a9e62edcd08bc741.tar.gz rust-a4cedd9598ec44d4f475adc3a9e62edcd08bc741.zip | |
Disallow multiple constructors or destructors in the same class
Closes #2825
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 42bdab193be..41b8b8f27d4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -225,6 +225,9 @@ class parser { fn span_fatal(sp: span, m: ~str) -> ! { self.sess.span_diagnostic.span_fatal(sp, m) } + fn span_note(sp: span, m: ~str) { + self.sess.span_diagnostic.span_note(sp, m) + } fn bug(m: ~str) -> ! { self.sess.span_diagnostic.span_bug(copy self.span, m) } @@ -2529,10 +2532,30 @@ class parser { while self.token != token::RBRACE { match self.parse_class_item(class_path) { ctor_decl(a_fn_decl, attrs, blk, s) => { - the_ctor = some((a_fn_decl, attrs, blk, s)); + match the_ctor { + some((_, _, _, s_first)) => { + self.span_note(s, #fmt("Duplicate constructor \ + declaration for class %s", *class_name)); + self.span_fatal(copy s_first, ~"First constructor \ + declared here"); + } + none => { + the_ctor = some((a_fn_decl, attrs, blk, s)); + } + } } dtor_decl(blk, attrs, s) => { - the_dtor = some((blk, attrs, s)); + match the_dtor { + some((_, _, s_first)) => { + self.span_note(s, #fmt("Duplicate destructor \ + declaration for class %s", *class_name)); + self.span_fatal(copy s_first, ~"First destructor \ + declared here"); + } + none => { + the_dtor = some((blk, attrs, s)); + } + } } members(mms) => { ms = vec::append(ms, mms); } } @@ -2557,9 +2580,6 @@ class parser { span: ct_s}), actual_dtor), none) } - /* - Is it strange for the parser to check this? - */ none => { (class_name, item_class(ty_params, traits, ms, none, actual_dtor), |
