Skip to content

Forbid ~str and ~[] #16809

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

Merged
merged 1 commit into from
Aug 31, 2014
Merged
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
19 changes: 6 additions & 13 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,14 +1427,10 @@ impl<'a> Parser<'a> {
} else if self.token == token::TILDE {
// OWNED POINTER
self.bump();
let span = self.last_span;
let last_span = self.last_span;
match self.token {
token::IDENT(ref ident, _)
if "str" == token::get_ident(*ident).get() => {
// This is OK (for now).
}
token::LBRACKET => {} // Also OK.
_ => self.obsolete(span, ObsoleteOwnedType)
token::LBRACKET => self.obsolete(last_span, ObsoleteOwnedVector),
_ => self.obsolete(last_span, ObsoleteOwnedType)
}
TyUniq(self.parse_ty(false))
} else if self.token == token::BINOP(token::STAR) {
Expand Down Expand Up @@ -2563,13 +2559,10 @@ impl<'a> Parser<'a> {
}
token::TILDE => {
self.bump();
let span = self.last_span;
let last_span = self.last_span;
match self.token {
token::LIT_STR(_) => {
// This is OK (for now).
}
token::LBRACKET => {} // Also OK.
_ => self.obsolete(span, ObsoleteOwnedExpr)
token::LBRACKET => self.obsolete(last_span, ObsoleteOwnedVector),
_ => self.obsolete(last_span, ObsoleteOwnedExpr)
}

let e = self.parse_prefix_expr();
Expand Down
21 changes: 21 additions & 0 deletions src/test/compile-fail/obsolete-tilde.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2014 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.

// Test that ~ pointers give an obsolescence message.

fn foo(x: ~int) {} //~ ERROR obsolete syntax: `~` notation for owned pointers
fn bar(x: ~str) {} //~ ERROR obsolete syntax: `~` notation for owned pointers
fn baz(x: ~[int]) {} //~ ERROR obsolete syntax: `~[T]` is no longer a type

fn main() {
let x = ~4i; //~ ERROR obsolete syntax: `~` notation for owned pointer allocation
let y = ~"hello"; //~ ERROR obsolete syntax: `~` notation for owned pointer allocation
let z = ~[1i, 2, 3]; //~ ERROR obsolete syntax: `~[T]` is no longer a type
}