Merge branch 'doc-comments'

This commit is contained in:
Brian Anderson
2012-07-02 15:31:33 -07:00
268 changed files with 1051 additions and 656 deletions

View File

@@ -21,14 +21,14 @@ fn load_errors(testfile: str) -> ~[expected_error] {
} }
fn parse_expected(line_num: uint, line: str) -> ~[expected_error] unsafe { fn parse_expected(line_num: uint, line: str) -> ~[expected_error] unsafe {
let error_tag = "//!"; let error_tag = "//~";
let mut idx; let mut idx;
alt str::find_str(line, error_tag) { alt str::find_str(line, error_tag) {
option::none { ret ~[]; } option::none { ret ~[]; }
option::some(nn) { idx = (nn as uint) + str::len(error_tag); } option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
} }
// "//!^^^ kind msg" denotes a message expected // "//~^^^ kind msg" denotes a message expected
// three lines above current line: // three lines above current line:
let mut adjust_line = 0u; let mut adjust_line = 0u;
let len = str::len(line); let len = str::len(line);

View File

@@ -0,0 +1,82 @@
#!/usr/bin/python
#
# this script attempts to turn doc comment attributes (#[doc = "..."])
# into sugared-doc-comments (/** ... */ and /// ...)
#
# it sugarises all .rs/.rc files underneath the working directory
#
import sys, os, fnmatch, re
DOC_PATTERN = '^(?P<indent>[\\t ]*)#\\[(\\s*)doc(\\s*)=' + \
'(\\s*)"(?P<text>(\\"|[^"])*?)"(\\s*)\\]' + \
'(?P<semi>;)?'
ESCAPES = [("\\'", "'"),
('\\"', '"'),
("\\n", "\n"),
("\\r", "\r"),
("\\t", "\t")]
def unescape(s):
for (find, repl) in ESCAPES:
s = s.replace(find, repl)
return s
def block_trim(s):
lns = s.splitlines()
# remove leading/trailing whitespace-lines
while lns and not lns[0].strip():
lns = lns[1:]
while lns and not lns[-1].strip():
lns = lns[:-1]
# remove leading horizontal whitespace
n = sys.maxint
for ln in lns:
if ln.strip():
n = min(n, len(re.search('^\s*', ln).group()))
if n != sys.maxint:
lns = [ln[n:] for ln in lns]
# strip trailing whitespace
lns = [ln.rstrip() for ln in lns]
return lns
def replace_doc(m):
indent = m.group('indent')
text = block_trim(unescape(m.group('text')))
if len(text) > 1:
inner = '!' if m.group('semi') else '*'
starify = lambda s: indent + ' *' + (' ' + s if s else '')
text = '\n'.join(map(starify, text))
repl = indent + '/*' + inner + '\n' + text + '\n' + indent + ' */'
else:
inner = '!' if m.group('semi') else '/'
repl = indent + '//' + inner + ' ' + text[0]
return repl
def sugarise_file(path):
s = open(path).read()
r = re.compile(DOC_PATTERN, re.MULTILINE | re.DOTALL)
ns = re.sub(r, replace_doc, s)
if s != ns:
open(path, 'w').write(ns)
for (dirpath, dirnames, filenames) in os.walk('.'):
for name in fnmatch.filter(filenames, '*.r[sc]'):
sugarise_file(os.path.join(dirpath, name))

View File

@@ -58,8 +58,8 @@ export
all, any, all, any,
all_between, any_between, all_between, any_between,
map, map,
each, each, eachi,
each_char, each_char, each_chari,
bytes_iter, bytes_iter,
chars_iter, chars_iter,
split_char_iter, split_char_iter,
@@ -73,7 +73,7 @@ export
find_char, find_char_from, find_char_between, find_char, find_char_from, find_char_between,
rfind_char, rfind_char_from, rfind_char_between, rfind_char, rfind_char_from, rfind_char_between,
find_str, find_str_from, find_str_between, find_str, find_str_from, find_str_between,
contains, contains, contains_char,
starts_with, starts_with,
ends_with, ends_with,
@@ -672,9 +672,15 @@ pure fn bytes_iter(ss: str/&, it: fn(u8)) {
#[doc = "Iterate over the bytes in a string"] #[doc = "Iterate over the bytes in a string"]
#[inline(always)] #[inline(always)]
pure fn each(s: str/&, it: fn(u8) -> bool) { pure fn each(s: str/&, it: fn(u8) -> bool) {
eachi(s, |_i, b| it(b) )
}
#[doc = "Iterate over the bytes in a string, with indices"]
#[inline(always)]
pure fn eachi(s: str/&, it: fn(uint, u8) -> bool) {
let mut i = 0u, l = len(s); let mut i = 0u, l = len(s);
while (i < l) { while (i < l) {
if !it(s[i]) { break; } if !it(i, s[i]) { break; }
i += 1u; i += 1u;
} }
} }
@@ -682,12 +688,19 @@ pure fn each(s: str/&, it: fn(u8) -> bool) {
#[doc = "Iterates over the chars in a string"] #[doc = "Iterates over the chars in a string"]
#[inline(always)] #[inline(always)]
pure fn each_char(s: str/&, it: fn(char) -> bool) { pure fn each_char(s: str/&, it: fn(char) -> bool) {
let mut pos = 0u; each_chari(s, |_i, c| it(c))
}
#[doc = "Iterates over the chars in a string, with indices"]
#[inline(always)]
pure fn each_chari(s: str/&, it: fn(uint, char) -> bool) {
let mut pos = 0u, ch_pos = 0u;
let len = len(s); let len = len(s);
while pos < len { while pos < len {
let {ch, next} = char_range_at(s, pos); let {ch, next} = char_range_at(s, pos);
pos = next; pos = next;
if !it(ch) { break; } if !it(ch_pos, ch) { break; }
ch_pos += 1u;
} }
} }
@@ -1146,6 +1159,18 @@ pure fn contains(haystack: str/&a, needle: str/&b) -> bool {
option::is_some(find_str(haystack, needle)) option::is_some(find_str(haystack, needle))
} }
#[doc = "
Returns true if a string contains a char.
# Arguments
* haystack - The string to look in
* needle - The char to look for
"]
pure fn contains_char(haystack: str/&, needle: char) -> bool {
option::is_some(find_char(haystack, needle))
}
#[doc = " #[doc = "
Returns true if one string starts with another Returns true if one string starts with another
@@ -1879,12 +1904,21 @@ impl extensions/& for str/& {
#[doc = "Returns true if one string contains another"] #[doc = "Returns true if one string contains another"]
#[inline] #[inline]
fn contains(needle: str/&a) -> bool { contains(self, needle) } fn contains(needle: str/&a) -> bool { contains(self, needle) }
#[doc = "Returns true if a string contains a char"]
#[inline]
fn contains_char(needle: char) -> bool { contains_char(self, needle) }
#[doc = "Iterate over the bytes in a string"] #[doc = "Iterate over the bytes in a string"]
#[inline] #[inline]
fn each(it: fn(u8) -> bool) { each(self, it) } fn each(it: fn(u8) -> bool) { each(self, it) }
#[doc = "Iterate over the bytes in a string, with indices"]
#[inline]
fn eachi(it: fn(uint, u8) -> bool) { eachi(self, it) }
#[doc = "Iterate over the chars in a string"] #[doc = "Iterate over the chars in a string"]
#[inline] #[inline]
fn each_char(it: fn(char) -> bool) { each_char(self, it) } fn each_char(it: fn(char) -> bool) { each_char(self, it) }
#[doc = "Iterate over the chars in a string, with indices"]
#[inline]
fn each_chari(it: fn(uint, char) -> bool) { each_chari(self, it) }
#[doc = "Returns true if one string ends with another"] #[doc = "Returns true if one string ends with another"]
#[inline] #[inline]
fn ends_with(needle: str/&) -> bool { ends_with(self, needle) } fn ends_with(needle: str/&) -> bool { ends_with(self, needle) }
@@ -2644,6 +2678,14 @@ mod tests {
assert !contains(data, "ไท华"); assert !contains(data, "ไท华");
} }
#[test]
fn test_contains_char() {
assert contains_char("abc", 'b');
assert contains_char("a", 'a');
assert !contains_char("abc", 'd');
assert !contains_char("", 'a');
}
#[test] #[test]
fn test_chars_iter() { fn test_chars_iter() {
let mut i = 0; let mut i = 0;

View File

@@ -652,8 +652,9 @@ type attribute = spanned<attribute_>;
#[auto_serialize] #[auto_serialize]
enum attr_style { attr_outer, attr_inner, } enum attr_style { attr_outer, attr_inner, }
// doc-comments are promoted to attributes that have is_sugared_doc = true
#[auto_serialize] #[auto_serialize]
type attribute_ = {style: attr_style, value: meta_item}; type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
/* /*
iface_refs appear in both impls and in classes that implement ifaces. iface_refs appear in both impls and in classes that implement ifaces.

View File

@@ -4,7 +4,8 @@ import std::map;
import std::map::hashmap; import std::map::hashmap;
import either::either; import either::either;
import diagnostic::span_handler; import diagnostic::span_handler;
import ast_util::dummy_spanned; import ast_util::{spanned, dummy_spanned};
import parse::comments::{doc_comment_style, strip_doc_comment_decoration};
// Constructors // Constructors
export mk_name_value_item_str; export mk_name_value_item_str;
@@ -12,10 +13,12 @@ export mk_name_value_item;
export mk_list_item; export mk_list_item;
export mk_word_item; export mk_word_item;
export mk_attr; export mk_attr;
export mk_sugared_doc_attr;
// Conversion // Conversion
export attr_meta; export attr_meta;
export attr_metas; export attr_metas;
export desugar_doc_attr;
// Accessors // Accessors
export get_attr_name; export get_attr_name;
@@ -66,9 +69,19 @@ fn mk_word_item(+name: ast::ident) -> @ast::meta_item {
} }
fn mk_attr(item: @ast::meta_item) -> ast::attribute { fn mk_attr(item: @ast::meta_item) -> ast::attribute {
ret dummy_spanned({style: ast::attr_inner, value: *item}); ret dummy_spanned({style: ast::attr_inner, value: *item,
is_sugared_doc: false});
} }
fn mk_sugared_doc_attr(text: str, lo: uint, hi: uint) -> ast::attribute {
let lit = spanned(lo, hi, ast::lit_str(@text));
let attr = {
style: doc_comment_style(text),
value: spanned(lo, hi, ast::meta_name_value(@"doc", lit)),
is_sugared_doc: true
};
ret spanned(lo, hi, attr);
}
/* Conversion */ /* Conversion */
@@ -81,6 +94,16 @@ fn attr_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
ret mitems; ret mitems;
} }
fn desugar_doc_attr(attr: ast::attribute) -> ast::attribute {
if attr.node.is_sugared_doc {
let comment = get_meta_item_value_str(@attr.node.value).get();
let meta = mk_name_value_item_str(@"doc",
strip_doc_comment_decoration(*comment));
ret mk_attr(meta);
} else {
attr
}
}
/* Accessors */ /* Accessors */

View File

@@ -102,7 +102,8 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
fn fold_attribute_(at: attribute, fld: ast_fold) -> fn fold_attribute_(at: attribute, fld: ast_fold) ->
attribute { attribute {
ret {node: {style: at.node.style, ret {node: {style: at.node.style,
value: *fold_meta_item_(@at.node.value, fld)}, value: *fold_meta_item_(@at.node.value, fld),
is_sugared_doc: at.node.is_sugared_doc },
span: fld.new_span(at.span)}; span: fld.new_span(at.span)};
} }
//used in noop_fold_foreign_item and noop_fold_fn_decl //used in noop_fold_foreign_item and noop_fold_fn_decl

View File

@@ -15,7 +15,8 @@ impl parser_attr for parser {
-> attr_or_ext -> attr_or_ext
{ {
let expect_item_next = vec::is_not_empty(first_item_attrs); let expect_item_next = vec::is_not_empty(first_item_attrs);
if self.token == token::POUND { alt self.token {
token::POUND {
let lo = self.span.lo; let lo = self.span.lo;
if self.look_ahead(1u) == token::LBRACKET { if self.look_ahead(1u) == token::LBRACKET {
self.bump(); self.bump();
@@ -30,15 +31,40 @@ impl parser_attr for parser {
self.bump(); self.bump();
ret some(right(self.parse_syntax_ext_naked(lo))); ret some(right(self.parse_syntax_ext_naked(lo)));
} else { ret none; } } else { ret none; }
} else { ret none; } }
token::DOC_COMMENT(_) {
ret some(left(self.parse_outer_attributes()));
}
_ {
ret none;
}
}
} }
// Parse attributes that appear before an item // Parse attributes that appear before an item
fn parse_outer_attributes() -> ~[ast::attribute] { fn parse_outer_attributes() -> ~[ast::attribute] {
let mut attrs: ~[ast::attribute] = ~[]; let mut attrs: ~[ast::attribute] = ~[];
while self.token == token::POUND loop {
&& self.look_ahead(1u) == token::LBRACKET { alt copy self.token {
vec::push(attrs, self.parse_attribute(ast::attr_outer)); token::POUND {
if self.look_ahead(1u) != token::LBRACKET {
break;
}
attrs += [self.parse_attribute(ast::attr_outer)]/~;
}
token::DOC_COMMENT(s) {
let attr = ::attr::mk_sugared_doc_attr(
*self.get_str(s), self.span.lo, self.span.hi);
if attr.node.style != ast::attr_outer {
self.fatal("expected outer comment");
}
attrs += [attr]/~;
self.bump();
}
_ {
break;
}
}
} }
ret attrs; ret attrs;
} }
@@ -55,7 +81,8 @@ impl parser_attr for parser {
let meta_item = self.parse_meta_item(); let meta_item = self.parse_meta_item();
self.expect(token::RBRACKET); self.expect(token::RBRACKET);
let mut hi = self.span.hi; let mut hi = self.span.hi;
ret spanned(lo, hi, {style: style, value: *meta_item}); ret spanned(lo, hi, {style: style, value: *meta_item,
is_sugared_doc: false});
} }
// Parse attributes that appear after the opening of an item, each // Parse attributes that appear after the opening of an item, each
@@ -68,7 +95,9 @@ impl parser_attr for parser {
{inner: ~[ast::attribute], next: ~[ast::attribute]} { {inner: ~[ast::attribute], next: ~[ast::attribute]} {
let mut inner_attrs: ~[ast::attribute] = ~[]; let mut inner_attrs: ~[ast::attribute] = ~[];
let mut next_outer_attrs: ~[ast::attribute] = ~[]; let mut next_outer_attrs: ~[ast::attribute] = ~[];
while self.token == token::POUND { loop {
alt copy self.token {
token::POUND {
if self.look_ahead(1u) != token::LBRACKET { if self.look_ahead(1u) != token::LBRACKET {
// This is an extension // This is an extension
break; break;
@@ -76,16 +105,33 @@ impl parser_attr for parser {
let attr = self.parse_attribute(ast::attr_inner); let attr = self.parse_attribute(ast::attr_inner);
if self.token == token::SEMI { if self.token == token::SEMI {
self.bump(); self.bump();
vec::push(inner_attrs, attr); inner_attrs += [attr]/~;
} else { } else {
// It's not really an inner attribute // It's not really an inner attribute
let outer_attr = let outer_attr =
spanned(attr.span.lo, attr.span.hi, spanned(attr.span.lo, attr.span.hi,
{style: ast::attr_outer, value: attr.node.value}); {style: ast::attr_outer, value: attr.node.value,
vec::push(next_outer_attrs, outer_attr); is_sugared_doc: false});
next_outer_attrs += [outer_attr]/~;
break; break;
} }
} }
token::DOC_COMMENT(s) {
let attr = ::attr::mk_sugared_doc_attr(
*self.get_str(s), self.span.lo, self.span.hi);
self.bump();
if attr.node.style == ast::attr_inner {
inner_attrs += [attr]/~;
} else {
next_outer_attrs += [attr]/~;
break;
}
}
_ {
break;
}
}
}
ret {inner: inner_attrs, next: next_outer_attrs}; ret {inner: inner_attrs, next: next_outer_attrs};
} }

View File

@@ -8,6 +8,7 @@ export cmnt;
export lit; export lit;
export cmnt_style; export cmnt_style;
export gather_comments_and_literals; export gather_comments_and_literals;
export is_doc_comment, doc_comment_style, strip_doc_comment_decoration;
enum cmnt_style { enum cmnt_style {
isolated, // No code on either side of each line of the comment isolated, // No code on either side of each line of the comment
@@ -18,6 +19,81 @@ enum cmnt_style {
type cmnt = {style: cmnt_style, lines: ~[str], pos: uint}; type cmnt = {style: cmnt_style, lines: ~[str], pos: uint};
fn is_doc_comment(s: str) -> bool {
s.starts_with("///") ||
s.starts_with("//!") ||
s.starts_with("/**") ||
s.starts_with("/*!")
}
fn doc_comment_style(comment: str) -> ast::attr_style {
assert is_doc_comment(comment);
if comment.starts_with("//!") || comment.starts_with("/*!") {
ast::attr_inner
} else {
ast::attr_outer
}
}
fn strip_doc_comment_decoration(comment: str) -> str {
/// remove whitespace-only lines from the start/end of lines
fn vertical_trim(lines: [str]/~) -> [str]/~ {
let mut i = 0u, j = lines.len();
while i < j && lines[i].trim().is_empty() {
i += 1u;
}
while j > i && lines[j - 1u].trim().is_empty() {
j -= 1u;
}
ret lines.slice(i, j);
}
// drop leftmost columns that contain only values in chars
fn block_trim(lines: [str]/~, chars: str, max: option<uint>) -> [str]/~ {
let mut i = max.get_default(uint::max_value);
for lines.each |line| {
if line.trim().is_empty() {
cont;
}
for line.each_chari |j, c| {
if j >= i {
break;
}
if !chars.contains_char(c) {
i = j;
break;
}
}
}
ret do lines.map |line| {
let chars = str::chars(line);
if i > chars.len() {
""
} else {
str::from_chars(chars.slice(i, chars.len()))
}
};
}
if comment.starts_with("//") {
ret comment.slice(3u, comment.len()).trim();
}
if comment.starts_with("/*") {
let lines = str::lines_any(comment.slice(3u, comment.len() - 2u));
let lines = vertical_trim(lines);
let lines = block_trim(lines, "\t ", none);
let lines = block_trim(lines, "*", some(1u));
let lines = block_trim(lines, "\t ", none);
ret str::connect(lines, "\n");
}
fail "not a doc-comment: " + comment;
}
fn read_to_eol(rdr: string_reader) -> str { fn read_to_eol(rdr: string_reader) -> str {
let mut val = ""; let mut val = "";
while rdr.curr != '\n' && !is_eof(rdr) { while rdr.curr != '\n' && !is_eof(rdr) {
@@ -57,29 +133,41 @@ fn consume_whitespace_counting_blank_lines(rdr: string_reader,
} }
} }
fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool) -> cmnt {
fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool,
&comments: [cmnt]/~) {
#debug(">>> shebang comment"); #debug(">>> shebang comment");
let p = rdr.chpos; let p = rdr.chpos;
#debug("<<< shebang comment"); #debug("<<< shebang comment");
ret {style: if code_to_the_left { trailing } else { isolated }, vec::push(comments, {
style: if code_to_the_left { trailing } else { isolated },
lines: ~[read_one_line_comment(rdr)], lines: ~[read_one_line_comment(rdr)],
pos: p}; pos: p
});
} }
fn read_line_comments(rdr: string_reader, code_to_the_left: bool) -> cmnt { fn read_line_comments(rdr: string_reader, code_to_the_left: bool,
&comments: [cmnt]/~) {
#debug(">>> line comments"); #debug(">>> line comments");
let p = rdr.chpos; let p = rdr.chpos;
let mut lines: ~[str] = ~[]; let mut lines: ~[str] = ~[];
while rdr.curr == '/' && nextch(rdr) == '/' { while rdr.curr == '/' && nextch(rdr) == '/' {
let line = read_one_line_comment(rdr); let line = read_one_line_comment(rdr);
log(debug, line); log(debug, line);
if is_doc_comment(line) { // doc-comments are not put in comments
break;
}
vec::push(lines, line); vec::push(lines, line);
consume_non_eol_whitespace(rdr); consume_non_eol_whitespace(rdr);
} }
#debug("<<< line comments"); #debug("<<< line comments");
ret {style: if code_to_the_left { trailing } else { isolated }, if !lines.is_empty() {
vec::push(comments, {
style: if code_to_the_left { trailing } else { isolated },
lines: lines, lines: lines,
pos: p}; pos: p
});
}
} }
fn all_whitespace(s: str, begin: uint, end: uint) -> bool { fn all_whitespace(s: str, begin: uint, end: uint) -> bool {
@@ -101,13 +189,27 @@ fn trim_whitespace_prefix_and_push_line(&lines: ~[str],
vec::push(lines, s1); vec::push(lines, s1);
} }
fn read_block_comment(rdr: string_reader, code_to_the_left: bool) -> cmnt { fn read_block_comment(rdr: string_reader, code_to_the_left: bool,
&comments: [cmnt]/~) {
#debug(">>> block comment"); #debug(">>> block comment");
let p = rdr.chpos; let p = rdr.chpos;
let mut lines: ~[str] = ~[]; let mut lines: ~[str] = ~[];
let mut col: uint = rdr.col; let mut col: uint = rdr.col;
bump(rdr); bump(rdr);
bump(rdr); bump(rdr);
// doc-comments are not really comments, they are attributes
if rdr.curr == '*' || rdr.curr == '!' {
while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
bump(rdr);
}
if !is_eof(rdr) {
bump(rdr);
bump(rdr);
}
ret;
}
let mut curr_line = "/*"; let mut curr_line = "/*";
let mut level: int = 1; let mut level: int = 1;
while level > 0 { while level > 0 {
@@ -143,7 +245,7 @@ fn read_block_comment(rdr: string_reader, code_to_the_left: bool) -> cmnt {
style = mixed; style = mixed;
} }
#debug("<<< block comment"); #debug("<<< block comment");
ret {style: style, lines: lines, pos: p}; vec::push(comments, {style: style, lines: lines, pos: p});
} }
fn peeking_at_comment(rdr: string_reader) -> bool { fn peeking_at_comment(rdr: string_reader) -> bool {
@@ -156,11 +258,11 @@ fn consume_comment(rdr: string_reader, code_to_the_left: bool,
&comments: ~[cmnt]) { &comments: ~[cmnt]) {
#debug(">>> consume comment"); #debug(">>> consume comment");
if rdr.curr == '/' && nextch(rdr) == '/' { if rdr.curr == '/' && nextch(rdr) == '/' {
vec::push(comments, read_line_comments(rdr, code_to_the_left)); read_line_comments(rdr, code_to_the_left, comments);
} else if rdr.curr == '/' && nextch(rdr) == '*' { } else if rdr.curr == '/' && nextch(rdr) == '*' {
vec::push(comments, read_block_comment(rdr, code_to_the_left)); read_block_comment(rdr, code_to_the_left, comments);
} else if rdr.curr == '#' && nextch(rdr) == '!' { } else if rdr.curr == '#' && nextch(rdr) == '!' {
vec::push(comments, read_shebang_comment(rdr, code_to_the_left)); read_shebang_comment(rdr, code_to_the_left, comments);
} else { fail; } } else { fail; }
#debug("<<< consume comment"); #debug("<<< consume comment");
} }

View File

@@ -161,7 +161,11 @@ impl tt_reader_as_reader of reader for tt_reader {
} }
fn string_advance_token(&&r: string_reader) { fn string_advance_token(&&r: string_reader) {
consume_whitespace_and_comments(r); for consume_whitespace_and_comments(r).each |comment| {
r.peek_tok = comment.tok;
r.peek_span = comment.sp;
ret;
}
if is_eof(r) { if is_eof(r) {
r.peek_tok = token::EOF; r.peek_tok = token::EOF;
@@ -277,22 +281,41 @@ fn is_hex_digit(c: char) -> bool {
fn is_bin_digit(c: char) -> bool { ret c == '0' || c == '1'; } fn is_bin_digit(c: char) -> bool { ret c == '0' || c == '1'; }
fn consume_whitespace_and_comments(rdr: string_reader) { // might return a sugared-doc-attr
fn consume_whitespace_and_comments(rdr: string_reader)
-> option<{tok: token::token, sp: span}> {
while is_whitespace(rdr.curr) { bump(rdr); } while is_whitespace(rdr.curr) { bump(rdr); }
ret consume_any_line_comment(rdr); ret consume_any_line_comment(rdr);
} }
fn consume_any_line_comment(rdr: string_reader) { // might return a sugared-doc-attr
fn consume_any_line_comment(rdr: string_reader)
-> option<{tok: token::token, sp: span}> {
if rdr.curr == '/' { if rdr.curr == '/' {
alt nextch(rdr) { alt nextch(rdr) {
'/' { '/' {
bump(rdr);
bump(rdr);
// line comments starting with "///" or "//!" are doc-comments
if rdr.curr == '/' || rdr.curr == '!' {
let start_chpos = rdr.chpos - 2u;
let mut acc = "//";
while rdr.curr != '\n' && !is_eof(rdr) {
str::push_char(acc, rdr.curr);
bump(rdr);
}
ret some({
tok: token::DOC_COMMENT(intern(*rdr.interner, @acc)),
sp: ast_util::mk_sp(start_chpos, rdr.chpos)
});
} else {
while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); } while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); }
// Restart whitespace munch. // Restart whitespace munch.
ret consume_whitespace_and_comments(rdr); ret consume_whitespace_and_comments(rdr);
} }
}
'*' { bump(rdr); bump(rdr); ret consume_block_comment(rdr); } '*' { bump(rdr); bump(rdr); ret consume_block_comment(rdr); }
_ { ret; } _ {}
} }
} else if rdr.curr == '#' { } else if rdr.curr == '#' {
if nextch(rdr) == '!' { if nextch(rdr) == '!' {
@@ -305,9 +328,34 @@ fn consume_any_line_comment(rdr: string_reader) {
} }
} }
} }
ret none;
} }
fn consume_block_comment(rdr: string_reader) { // might return a sugared-doc-attr
fn consume_block_comment(rdr: string_reader)
-> option<{tok: token::token, sp: span}> {
// block comments starting with "/**" or "/*!" are doc-comments
if rdr.curr == '*' || rdr.curr == '!' {
let start_chpos = rdr.chpos - 2u;
let mut acc = "/*";
while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
str::push_char(acc, rdr.curr);
bump(rdr);
}
if is_eof(rdr) {
rdr.fatal("unterminated block doc-comment");
} else {
acc += "*/";
bump(rdr);
bump(rdr);
ret some({
tok: token::DOC_COMMENT(intern(*rdr.interner, @acc)),
sp: ast_util::mk_sp(start_chpos, rdr.chpos)
});
}
}
let mut level: int = 1; let mut level: int = 1;
while level > 0 { while level > 0 {
if is_eof(rdr) { rdr.fatal("unterminated block comment"); } if is_eof(rdr) { rdr.fatal("unterminated block comment"); }

View File

@@ -80,6 +80,7 @@ enum token {
//ACTUALLY(whole_nonterminal), //ACTUALLY(whole_nonterminal),
DOC_COMMENT(str_num),
EOF, EOF,
} }
@@ -170,11 +171,15 @@ fn to_str(in: interner<@str>, t: token) -> str {
+ str::escape_default(*interner::get(in, s)) + str::escape_default(*interner::get(in, s))
+ "\"" + "\""
} }
/* Name components */ /* Name components */
IDENT(s, _) { IDENT(s, _) {
*interner::get(in, s) *interner::get(in, s)
} }
UNDERSCORE { "_" } UNDERSCORE { "_" }
/* Other */
DOC_COMMENT(s) { *interner::get(in, s) }
EOF { "<eof>" } EOF { "<eof>" }
} }
} }

View File

@@ -647,7 +647,9 @@ fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) {
alt attr.node.style { alt attr.node.style {
ast::attr_inner { ast::attr_inner {
print_attribute(s, attr); print_attribute(s, attr);
if !attr.node.is_sugared_doc {
word(s.s, ";"); word(s.s, ";");
}
count += 1; count += 1;
} }
_ {/* fallthrough */ } _ {/* fallthrough */ }
@@ -659,9 +661,15 @@ fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) {
fn print_attribute(s: ps, attr: ast::attribute) { fn print_attribute(s: ps, attr: ast::attribute) {
hardbreak_if_not_bol(s); hardbreak_if_not_bol(s);
maybe_print_comment(s, attr.span.lo); maybe_print_comment(s, attr.span.lo);
if attr.node.is_sugared_doc {
let meta = attr::attr_meta(attr);
let comment = attr::get_meta_item_value_str(meta).get();
word(s.s, *comment);
} else {
word(s.s, "#["); word(s.s, "#[");
print_meta_item(s, @attr.node.value); print_meta_item(s, @attr.node.value);
word(s.s, "]"); word(s.s, "]");
}
} }

View File

@@ -233,7 +233,8 @@ mod test {
ast::meta_name_value( ast::meta_name_value(
@"crate_type", @"crate_type",
ast_util::respan(ast_util::dummy_sp(), ast_util::respan(ast_util::dummy_sp(),
ast::lit_str(@t)))) ast::lit_str(@t)))),
is_sugared_doc: false
}) })
} }

View File

@@ -613,7 +613,8 @@ fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
assert (vec::len(meta_items) == 1u); assert (vec::len(meta_items) == 1u);
let meta_item = meta_items[0]; let meta_item = meta_items[0];
vec::push(attrs, vec::push(attrs,
{node: {style: ast::attr_outer, value: *meta_item}, {node: {style: ast::attr_outer, value: *meta_item,
is_sugared_doc: false},
span: ast_util::dummy_sp()}); span: ast_util::dummy_sp()});
}; };
} }

View File

@@ -44,7 +44,10 @@ fn doc_meta(
doc attribute"]; doc attribute"];
let doc_attrs = attr::find_attrs_by_name(attrs, "doc"); let doc_attrs = attr::find_attrs_by_name(attrs, "doc");
let doc_metas = attr::attr_metas(doc_attrs); let doc_metas = do doc_attrs.map |attr| {
attr::attr_meta(attr::desugar_doc_attr(attr))
};
if vec::is_not_empty(doc_metas) { if vec::is_not_empty(doc_metas) {
if vec::len(doc_metas) != 1u { if vec::len(doc_metas) != 1u {
#warn("ignoring %u doc attributes", vec::len(doc_metas) - 1u); #warn("ignoring %u doc attributes", vec::len(doc_metas) - 1u);

View File

@@ -6,6 +6,6 @@ fn my_fail() -> ! { fail; }
fn main() { fn main() {
alt true { false { my_fail(); } true { } } alt true { false { my_fail(); } true { } }
log(debug, x); //! ERROR unresolved name: x log(debug, x); //~ ERROR unresolved name: x
let x: int; let x: int;
} }

View File

@@ -10,7 +10,7 @@ fn main() {
rgb(_, _, _) { } rgb(_, _, _) { }
cmyk(_, _, _, _) { } cmyk(_, _, _, _) { }
no_color(_) { } no_color(_) { }
//!^ ERROR this pattern has 1 field, but the corresponding variant has no fields //~^ ERROR this pattern has 1 field, but the corresponding variant has no fields
} }
} }
} }

View File

@@ -8,7 +8,7 @@ fn main() {
fn foo(c: color) { fn foo(c: color) {
alt c { alt c {
rgb(_, _) { } rgb(_, _) { }
//!^ ERROR this pattern has 2 fields, but the corresponding variant has 3 fields //~^ ERROR this pattern has 2 fields, but the corresponding variant has 3 fields
cmyk(_, _, _, _) { } cmyk(_, _, _, _) { }
no_color { } no_color { }
} }

View File

@@ -1,3 +1,3 @@
impl methods1 for uint { fn me() -> uint { self } } //! NOTE candidate #1 is `methods1::me` impl methods1 for uint { fn me() -> uint { self } } //~ NOTE candidate #1 is `methods1::me`
impl methods2 for uint { fn me() -> uint { self } } //! NOTE candidate #2 is `methods2::me` impl methods2 for uint { fn me() -> uint { self } } //~ NOTE candidate #2 is `methods2::me`
fn main() { 1u.me(); } //! ERROR multiple applicable methods in scope fn main() { 1u.me(); } //~ ERROR multiple applicable methods in scope

View File

@@ -2,6 +2,6 @@
// aux-build:ambig_impl_2_lib.rs // aux-build:ambig_impl_2_lib.rs
use ambig_impl_2_lib; use ambig_impl_2_lib;
import ambig_impl_2_lib::methods1; import ambig_impl_2_lib::methods1;
impl methods2 for uint { fn me() -> uint { self } } //! NOTE candidate #2 is `methods2::me` impl methods2 for uint { fn me() -> uint { self } } //~ NOTE candidate #2 is `methods2::me`
fn main() { 1u.me(); } //! ERROR multiple applicable methods in scope fn main() { 1u.me(); } //~ ERROR multiple applicable methods in scope
//!^ NOTE candidate #1 is `ambig_impl_2_lib::methods1::me` //~^ NOTE candidate #1 is `ambig_impl_2_lib::methods1::me`

View File

@@ -2,9 +2,9 @@ iface A { fn foo(); }
iface B { fn foo(); } iface B { fn foo(); }
fn foo<T: A B>(t: T) { fn foo<T: A B>(t: T) {
t.foo(); //! ERROR multiple applicable methods in scope t.foo(); //~ ERROR multiple applicable methods in scope
//!^ NOTE candidate #1 derives from the bound `A` //~^ NOTE candidate #1 derives from the bound `A`
//!^^ NOTE candidate #2 derives from the bound `B` //~^^ NOTE candidate #2 derives from the bound `B`
} }
fn main() {} fn main() {}

View File

@@ -1,12 +1,12 @@
impl methods for ~[uint] { impl methods for ~[uint] {
fn foo() -> int {1} //! NOTE candidate #1 is `methods::foo` fn foo() -> int {1} //~ NOTE candidate #1 is `methods::foo`
} }
impl methods for ~[int] { impl methods for ~[int] {
fn foo() -> int {2} //! NOTE candidate #2 is `methods::foo` fn foo() -> int {2} //~ NOTE candidate #2 is `methods::foo`
} }
fn main() { fn main() {
let x = ~[]; let x = ~[];
x.foo(); //! ERROR multiple applicable methods in scope x.foo(); //~ ERROR multiple applicable methods in scope
} }

View File

@@ -1,8 +1,8 @@
fn test() { fn test() {
let v: int; let v: int;
v = 1; //! NOTE prior assignment occurs here v = 1; //~ NOTE prior assignment occurs here
#debug["v=%d", v]; #debug["v=%d", v];
v = 2; //! ERROR re-assignment of immutable variable v = 2; //~ ERROR re-assignment of immutable variable
#debug["v=%d", v]; #debug["v=%d", v];
} }

View File

@@ -1,5 +1,5 @@
fn main() { fn main() {
let mut x: ~[mut int] = ~[mut 3]; let mut x: ~[mut int] = ~[mut 3];
let y: ~[int] = ~[3]; let y: ~[int] = ~[3];
x = y; //! ERROR values differ in mutability x = y; //~ ERROR values differ in mutability
} }

View File

@@ -11,5 +11,5 @@ class cat {
fn main() { fn main() {
let nyan : cat = cat(52u, 99); let nyan : cat = cat(52u, 99);
nyan.speak = fn@() { #debug["meow"]; }; //! ERROR assigning to method nyan.speak = fn@() { #debug["meow"]; }; //~ ERROR assigning to method
} }

View File

@@ -1,6 +1,6 @@
// Check that bogus field access is non-fatal // Check that bogus field access is non-fatal
fn main() { fn main() {
let x = 0; let x = 0;
log(debug, x.foo); //! ERROR attempted access of field log(debug, x.foo); //~ ERROR attempted access of field
log(debug, x.bar); //! ERROR attempted access of field log(debug, x.bar); //~ ERROR attempted access of field
} }

View File

@@ -1,4 +1,4 @@
fn main() { fn main() {
#[attr] #[attr]
#debug("hi"); //! ERROR expected item #debug("hi"); //~ ERROR expected item
} }

View File

@@ -1,4 +1,4 @@
fn main() { fn main() {
#[attr] #[attr]
let _i = 0; //! ERROR expected item let _i = 0; //~ ERROR expected item
} }

View File

@@ -3,7 +3,7 @@
fn bad_bang(i: uint) -> ! { fn bad_bang(i: uint) -> ! {
ret 7u; ret 7u;
//!^ ERROR expected `_|_` but found `uint` //~^ ERROR expected `_|_` but found `uint`
} }
fn main() { bad_bang(5u); } fn main() { bad_bang(5u); }

View File

@@ -3,7 +3,7 @@
fn bad_bang(i: uint) -> ! { fn bad_bang(i: uint) -> ! {
if i < 0u { } else { fail; } if i < 0u { } else { fail; }
//!^ ERROR expected `_|_` but found `()` //~^ ERROR expected `_|_` but found `()`
} }
fn main() { bad_bang(5u); } fn main() { bad_bang(5u); }

View File

@@ -1,4 +1,4 @@
fn main() { fn main() {
fn baz(_x: fn() -> int) {} fn baz(_x: fn() -> int) {}
for baz |_e| { } //! ERROR should return `bool` for baz |_e| { } //~ ERROR should return `bool`
} }

View File

@@ -1,5 +1,5 @@
fn foo<T>() { fn foo<T>() {
1u.bar::<T>(); //! ERROR: missing `copy` 1u.bar::<T>(); //~ ERROR: missing `copy`
} }
impl methods for uint { impl methods for uint {

View File

@@ -1,2 +1,2 @@
fn false() { } //! ERROR found `false` in restricted position fn false() { } //~ ERROR found `false` in restricted position
fn main() { } fn main() { }

View File

@@ -1,2 +1,2 @@
fn true() { } //! ERROR found `true` in restricted position fn true() { } //~ ERROR found `true` in restricted position
fn main() { } fn main() { }

View File

@@ -2,6 +2,6 @@ fn main() {
let x = 3; let x = 3;
fn blah(_a: native fn()) {} fn blah(_a: native fn()) {}
blah(|| { blah(|| {
log(debug, x); //! ERROR attempted dynamic environment capture log(debug, x); //~ ERROR attempted dynamic environment capture
}); });
} }

View File

@@ -1,4 +1,4 @@
fn f() -> ! { fn f() -> ! {
3i //! ERROR expected `_|_` but found `int` 3i //~ ERROR expected `_|_` but found `int`
} }
fn main() { } fn main() { }

View File

@@ -4,5 +4,5 @@ fn main() {
let x = true; let x = true;
let y = 1; let y = 1;
let z = x + y; let z = x + y;
//!^ ERROR binary operation + cannot be applied to type `bool` //~^ ERROR binary operation + cannot be applied to type `bool`
} }

View File

@@ -3,7 +3,7 @@ fn compute1() -> float {
let v = ~[0f, 1f, 2f, 3f]; let v = ~[0f, 1f, 2f, 3f];
do vec::foldl(0f, v) |x, y| { x + y } - 10f do vec::foldl(0f, v) |x, y| { x + y } - 10f
//!^ ERROR mismatched types: expected `()` //~^ ERROR mismatched types: expected `()`
} }
fn main() { fn main() {

View File

@@ -9,5 +9,5 @@ fn main() {
} }
f(g); f(g);
//!^ ERROR mismatched types: expected `extern fn(extern fn(extern fn()))` //~^ ERROR mismatched types: expected `extern fn(extern fn(extern fn()))`
} }

View File

@@ -6,7 +6,7 @@ fn coerce(b: fn()) -> native fn() {
g: fn()) -> native fn() { ret f(g); } g: fn()) -> native fn() { ret f(g); }
fn fn_id(f: native fn()) -> native fn() { ret f } fn fn_id(f: native fn()) -> native fn() { ret f }
ret lol(fn_id, b); ret lol(fn_id, b);
//!^ ERROR mismatched types: expected `extern fn(fn()) -> extern fn()` //~^ ERROR mismatched types: expected `extern fn(fn()) -> extern fn()`
} }
fn main() { fn main() {

View File

@@ -4,9 +4,9 @@ fn a() {
let mut p = ~[mut 1]; let mut p = ~[mut 1];
// Create an immutable pointer into p's contents: // Create an immutable pointer into p's contents:
let _q: &int = &p[0]; //! NOTE loan of mutable vec content granted here let _q: &int = &p[0]; //~ NOTE loan of mutable vec content granted here
p[0] = 5; //! ERROR assigning to mutable vec content prohibited due to outstanding loan p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
} }
fn borrow(_x: &[int], _f: fn()) {} fn borrow(_x: &[int], _f: fn()) {}
@@ -17,8 +17,8 @@ fn b() {
let mut p = ~[mut 1]; let mut p = ~[mut 1];
do borrow(p) || { //! NOTE loan of mutable vec content granted here do borrow(p) || { //~ NOTE loan of mutable vec content granted here
p[0] = 5; //! ERROR assigning to mutable vec content prohibited due to outstanding loan p[0] = 5; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
} }
} }

View File

@@ -2,12 +2,12 @@ type point = { x: int, y: int };
fn a() { fn a() {
let mut p = {x: 3, y: 4}; let mut p = {x: 3, y: 4};
let _q = &p; //! NOTE loan of mutable local variable granted here let _q = &p; //~ NOTE loan of mutable local variable granted here
// This assignment is illegal because the field x is not // This assignment is illegal because the field x is not
// inherently mutable; since `p` was made immutable, `p.x` is now // inherently mutable; since `p` was made immutable, `p.x` is now
// immutable. Otherwise the type of &_q.x (&int) would be wrong. // immutable. Otherwise the type of &_q.x (&int) would be wrong.
p.x = 5; //! ERROR assigning to mutable field prohibited due to outstanding loan p.x = 5; //~ ERROR assigning to mutable field prohibited due to outstanding loan
} }
fn b() { fn b() {
@@ -24,8 +24,8 @@ fn c() {
// and then try to overwrite `p` as a whole. // and then try to overwrite `p` as a whole.
let mut p = {x: 3, mut y: 4}; let mut p = {x: 3, mut y: 4};
let _q = &p.y; //! NOTE loan of mutable local variable granted here let _q = &p.y; //~ NOTE loan of mutable local variable granted here
p = {x: 5, mut y: 7};//! ERROR assigning to mutable local variable prohibited due to outstanding loan p = {x: 5, mut y: 7};//~ ERROR assigning to mutable local variable prohibited due to outstanding loan
copy p; copy p;
} }
@@ -34,8 +34,8 @@ fn d() {
// address of a subcomponent and then modify that subcomponent: // address of a subcomponent and then modify that subcomponent:
let mut p = {x: 3, mut y: 4}; let mut p = {x: 3, mut y: 4};
let _q = &p.y; //! NOTE loan of mutable field granted here let _q = &p.y; //~ NOTE loan of mutable field granted here
p.y = 5; //! ERROR assigning to mutable field prohibited due to outstanding loan p.y = 5; //~ ERROR assigning to mutable field prohibited due to outstanding loan
copy p; copy p;
} }

View File

@@ -2,6 +2,6 @@ const foo: int = 5;
fn main() { fn main() {
// assigning to various global constants // assigning to various global constants
none = some(3); //! ERROR assigning to static item none = some(3); //~ ERROR assigning to static item
foo = 6; //! ERROR assigning to static item foo = 6; //~ ERROR assigning to static item
} }

View File

@@ -2,5 +2,5 @@ enum foo = int;
fn main() { fn main() {
let x = foo(3); let x = foo(3);
*x = 4; //! ERROR assigning to enum content *x = 4; //~ ERROR assigning to enum content
} }

View File

@@ -14,7 +14,7 @@ fn main() {
// in these cases we pass through a box, so the mut // in these cases we pass through a box, so the mut
// of the box is dominant // of the box is dominant
p.x.a = 2; //! ERROR assigning to immutable field p.x.a = 2; //~ ERROR assigning to immutable field
p.y.a = 2; //! ERROR assigning to const field p.y.a = 2; //~ ERROR assigning to const field
p.z.a = 2; p.z.a = 2;
} }

View File

@@ -6,8 +6,8 @@ fn main() {
alt x { alt x {
{f: v} => { {f: v} => {
impure(v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location impure(v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
} }
} }

View File

@@ -1,8 +1,8 @@
fn main() { fn main() {
let x = some(~1); let x = some(~1);
alt x { //! NOTE loan of immutable local variable granted here alt x { //~ NOTE loan of immutable local variable granted here
some(y) { some(y) {
let _a <- x; //! ERROR moving out of immutable local variable prohibited due to outstanding loan let _a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
} }
_ {} _ {}
} }

View File

@@ -2,7 +2,7 @@ fn main() {
let x = some(~1); let x = some(~1);
alt x { alt x {
some(y) { some(y) {
let _b <- y; //! ERROR moving out of pattern binding let _b <- y; //~ ERROR moving out of pattern binding
} }
_ {} _ {}
} }

View File

@@ -5,8 +5,8 @@ fn borrow_from_arg_imm_ref(&&v: ~int) {
} }
fn borrow_from_arg_mut_ref(&v: ~int) { fn borrow_from_arg_mut_ref(&v: ~int) {
borrow(v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn borrow_from_arg_move(-v: ~int) { fn borrow_from_arg_move(-v: ~int) {

View File

@@ -19,23 +19,23 @@ fn post_aliased_const() {
fn post_aliased_mut() { fn post_aliased_mut() {
// SPURIOUS--flow // SPURIOUS--flow
let mut v = ~3; let mut v = ~3;
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
let _w = &mut v; //! NOTE prior loan as mutable granted here let _w = &mut v; //~ NOTE prior loan as mutable granted here
} }
fn post_aliased_scope(cond: bool) { fn post_aliased_scope(cond: bool) {
// NDM--scope of & // NDM--scope of &
let mut v = ~3; let mut v = ~3;
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
if cond { inc(&mut v); } //! NOTE prior loan as mutable granted here if cond { inc(&mut v); } //~ NOTE prior loan as mutable granted here
} }
fn loop_aliased_mut() { fn loop_aliased_mut() {
let mut v = ~3, w = ~4; let mut v = ~3, w = ~4;
let mut _x = &mut w; let mut _x = &mut w;
loop { loop {
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
_x = &mut v; //! NOTE prior loan as mutable granted here _x = &mut v; //~ NOTE prior loan as mutable granted here
} }
} }
@@ -43,8 +43,8 @@ fn while_aliased_mut(cond: bool) {
let mut v = ~3, w = ~4; let mut v = ~3, w = ~4;
let mut _x = &mut w; let mut _x = &mut w;
while cond { while cond {
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
_x = &mut v; //! NOTE prior loan as mutable granted here _x = &mut v; //~ NOTE prior loan as mutable granted here
} }
} }
@@ -52,9 +52,9 @@ fn while_aliased_mut_cond(cond: bool, cond2: bool) {
let mut v = ~3, w = ~4; let mut v = ~3, w = ~4;
let mut _x = &mut w; let mut _x = &mut w;
while cond { while cond {
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
if cond2 { if cond2 {
_x = &mut v; //! NOTE prior loan as mutable granted here _x = &mut v; //~ NOTE prior loan as mutable granted here
} }
} }
} }
@@ -63,8 +63,8 @@ fn loop_in_block() {
let mut v = ~3, w = ~4; let mut v = ~3, w = ~4;
let mut _x = &mut w; let mut _x = &mut w;
for uint::range(0u, 10u) |_i| { for uint::range(0u, 10u) |_i| {
borrow(v); //! ERROR loan of mutable variable declared in an outer block as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable variable declared in an outer block as immutable conflicts with prior loan
_x = &mut v; //! NOTE prior loan as mutable granted here _x = &mut v; //~ NOTE prior loan as mutable granted here
} }
} }
@@ -77,8 +77,8 @@ fn at_most_once_block() {
let mut v = ~3, w = ~4; let mut v = ~3, w = ~4;
let mut _x = &mut w; let mut _x = &mut w;
do at_most_once || { do at_most_once || {
borrow(v); //! ERROR loan of mutable variable declared in an outer block as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable variable declared in an outer block as immutable conflicts with prior loan
_x = &mut v; //! NOTE prior loan as mutable granted here _x = &mut v; //~ NOTE prior loan as mutable granted here
} }
} }

View File

@@ -4,16 +4,16 @@ fn borrow(v: &int, f: fn(x: &int)) {
fn box_imm() { fn box_imm() {
let mut v = ~3; let mut v = ~3;
let _w = &mut v; //! NOTE loan of mutable local variable granted here let _w = &mut v; //~ NOTE loan of mutable local variable granted here
do task::spawn |move v| { do task::spawn |move v| {
//!^ ERROR moving out of mutable local variable prohibited due to outstanding loan //~^ ERROR moving out of mutable local variable prohibited due to outstanding loan
#debug["v=%d", *v]; #debug["v=%d", *v];
} }
let mut v = ~3; let mut v = ~3;
let _w = &mut v; //! NOTE loan of mutable local variable granted here let _w = &mut v; //~ NOTE loan of mutable local variable granted here
task::spawn(fn~(move v) { task::spawn(fn~(move v) {
//!^ ERROR moving out of mutable local variable prohibited due to outstanding loan //~^ ERROR moving out of mutable local variable prohibited due to outstanding loan
#debug["v=%d", *v]; #debug["v=%d", *v];
}); });
} }

View File

@@ -3,8 +3,8 @@ fn take(-_v: ~int) {
fn box_imm() { fn box_imm() {
let v = ~3; let v = ~3;
let _w = &v; //! NOTE loan of immutable local variable granted here let _w = &v; //~ NOTE loan of immutable local variable granted here
take(v); //! ERROR moving out of immutable local variable prohibited due to outstanding loan take(v); //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
} }
fn main() { fn main() {

View File

@@ -4,8 +4,8 @@ fn borrow(v: &int, f: fn(x: &int)) {
fn box_imm() { fn box_imm() {
let mut v = ~3; let mut v = ~3;
do borrow(v) |w| { //! NOTE loan of mutable local variable granted here do borrow(v) |w| { //~ NOTE loan of mutable local variable granted here
v = ~4; //! ERROR assigning to mutable variable declared in an outer block prohibited due to outstanding loan v = ~4; //~ ERROR assigning to mutable variable declared in an outer block prohibited due to outstanding loan
assert *v == 3; assert *v == 3;
assert *w == 4; assert *w == 4;
} }

View File

@@ -18,11 +18,11 @@ fn b() {
// Here I create an outstanding loan and check that we get conflicts: // Here I create an outstanding loan and check that we get conflicts:
&mut p; //! NOTE prior loan as mutable granted here &mut p; //~ NOTE prior loan as mutable granted here
//!^ NOTE prior loan as mutable granted here //~^ NOTE prior loan as mutable granted here
p + 3; //! ERROR loan of mutable local variable as immutable conflicts with prior loan p + 3; //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
p * 3; //! ERROR loan of mutable local variable as immutable conflicts with prior loan p * 3; //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
} }
fn c() { fn c() {
@@ -35,8 +35,8 @@ fn c() {
// ...but not impure fns // ...but not impure fns
*q * 3; //! ERROR illegal borrow unless pure: creating immutable alias to aliasable, mutable memory *q * 3; //~ ERROR illegal borrow unless pure: creating immutable alias to aliasable, mutable memory
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn main() { fn main() {

View File

@@ -19,8 +19,8 @@ fn a() {
p.impurem(); p.impurem();
// But in this case we do not honor the loan: // But in this case we do not honor the loan:
do p.blockm || { //! NOTE loan of mutable local variable granted here do p.blockm || { //~ NOTE loan of mutable local variable granted here
p.x = 10; //! ERROR assigning to mutable field prohibited due to outstanding loan p.x = 10; //~ ERROR assigning to mutable field prohibited due to outstanding loan
} }
} }
@@ -29,11 +29,11 @@ fn b() {
// Here I create an outstanding loan and check that we get conflicts: // Here I create an outstanding loan and check that we get conflicts:
&mut p; //! NOTE prior loan as mutable granted here &mut p; //~ NOTE prior loan as mutable granted here
//!^ NOTE prior loan as mutable granted here //~^ NOTE prior loan as mutable granted here
p.purem(); //! ERROR loan of mutable local variable as immutable conflicts with prior loan p.purem(); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
p.impurem(); //! ERROR loan of mutable local variable as immutable conflicts with prior loan p.impurem(); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
} }
fn c() { fn c() {
@@ -45,8 +45,8 @@ fn c() {
(*q).purem(); (*q).purem();
// ...but not impure fns // ...but not impure fns
(*q).impurem(); //! ERROR illegal borrow unless pure: creating immutable alias to aliasable, mutable memory (*q).impurem(); //~ ERROR illegal borrow unless pure: creating immutable alias to aliasable, mutable memory
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn main() { fn main() {

View File

@@ -14,8 +14,8 @@ fn has_mut_vec_and_does_not_try_to_change_it() {
fn has_mut_vec_but_tries_to_change_it() { fn has_mut_vec_but_tries_to_change_it() {
let v = ~[mut 1, 2, 3]; let v = ~[mut 1, 2, 3];
do takes_imm_elt(&v[0]) || { //! NOTE loan of mutable vec content granted here do takes_imm_elt(&v[0]) || { //~ NOTE loan of mutable vec content granted here
v[1] = 4; //! ERROR assigning to mutable vec content prohibited due to outstanding loan v[1] = 4; //~ ERROR assigning to mutable vec content prohibited due to outstanding loan
} }
} }

View File

@@ -1,5 +1,5 @@
fn foo(x: *~int) -> ~int { fn foo(x: *~int) -> ~int {
let y <- *x; //! ERROR dereference of unsafe pointer requires unsafe function or block let y <- *x; //~ ERROR dereference of unsafe pointer requires unsafe function or block
ret y; ret y;
} }

View File

@@ -1,6 +1,6 @@
fn main() { fn main() {
let x: int = 3; let x: int = 3;
let y: &mut int = &mut x; //! ERROR taking mut reference to immutable local variable let y: &mut int = &mut x; //~ ERROR taking mut reference to immutable local variable
*y = 5; *y = 5;
log (debug, *y); log (debug, *y);
} }

View File

@@ -5,8 +5,8 @@ fn want_slice(v: &[int]) -> int {
} }
fn has_mut_vec(+v: @~[mut int]) -> int { fn has_mut_vec(+v: @~[mut int]) -> int {
want_slice(*v) //! ERROR illegal borrow unless pure: creating immutable alias to aliasable, mutable memory want_slice(*v) //~ ERROR illegal borrow unless pure: creating immutable alias to aliasable, mutable memory
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn main() { fn main() {

View File

@@ -5,9 +5,9 @@ enum cycle {
fn main() { fn main() {
let x = ~node({mut a: ~empty}); let x = ~node({mut a: ~empty});
// Create a cycle! // Create a cycle!
alt check *x { //! NOTE loan of immutable local variable granted here alt check *x { //~ NOTE loan of immutable local variable granted here
node(y) { node(y) {
y.a <- x; //! ERROR moving out of immutable local variable prohibited due to outstanding loan y.a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
} }
}; };
} }

View File

@@ -27,8 +27,8 @@ fn process(_i: int) {}
fn match_const_box_and_do_bad_things(v: &const @const option<int>) { fn match_const_box_and_do_bad_things(v: &const @const option<int>) {
alt *v { alt *v {
@some(i) { //! ERROR illegal borrow unless pure: enum variant in aliasable, mutable location @some(i) { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
process(i) //! NOTE impure due to access to impure function process(i) //~ NOTE impure due to access to impure function
} }
@none {} @none {}
} }

View File

@@ -33,8 +33,8 @@ fn match_const_reg_unused(v: &const option<int>) {
fn match_const_reg_impure(v: &const option<int>) { fn match_const_reg_impure(v: &const option<int>) {
alt *v { alt *v {
some(i) {impure(i)} //! ERROR illegal borrow unless pure: enum variant in aliasable, mutable location some(i) {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
none {} none {}
} }
} }

View File

@@ -2,11 +2,11 @@
fn main() { fn main() {
let mut x: option<int> = none; let mut x: option<int> = none;
alt x { //! NOTE loan of mutable local variable granted here alt x { //~ NOTE loan of mutable local variable granted here
none {} none {}
some(i) { some(i) {
// Not ok: i is an outstanding ptr into x. // Not ok: i is an outstanding ptr into x.
x = some(i+1); //! ERROR assigning to mutable local variable prohibited due to outstanding loan x = some(i+1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
} }
} }
copy x; // just to prevent liveness warnings copy x; // just to prevent liveness warnings

View File

@@ -2,14 +2,14 @@
fn main() { fn main() {
let mut x = none; let mut x = none;
alt x { //! NOTE loan of mutable local variable granted here alt x { //~ NOTE loan of mutable local variable granted here
none { none {
// It is ok to reassign x here, because there is in // It is ok to reassign x here, because there is in
// fact no outstanding loan of x! // fact no outstanding loan of x!
x = some(0); x = some(0);
} }
some(i) { some(i) {
x = some(1); //! ERROR assigning to mutable local variable prohibited due to outstanding loan x = some(1); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
} }
} }
copy x; // just to prevent liveness warnings copy x; // just to prevent liveness warnings

View File

@@ -4,8 +4,8 @@ fn test1(x: @mut ~int) {
// Here, evaluating the second argument actually invalidates the // Here, evaluating the second argument actually invalidates the
// first borrow, even though it occurs outside of the scope of the // first borrow, even though it occurs outside of the scope of the
// borrow! // borrow!
pure_borrow(*x, *x = ~5); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location pure_borrow(*x, *x = ~5); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to assigning to dereference of mutable @ pointer //~^ NOTE impure due to assigning to dereference of mutable @ pointer
} }
fn test2() { fn test2() {
@@ -13,8 +13,8 @@ fn test2() {
// Same, but for loanable data: // Same, but for loanable data:
pure_borrow(x, x = ~5); //! ERROR assigning to mutable local variable prohibited due to outstanding loan pure_borrow(x, x = ~5); //~ ERROR assigning to mutable local variable prohibited due to outstanding loan
//!^ NOTE loan of mutable local variable granted here //~^ NOTE loan of mutable local variable granted here
copy x; copy x;
} }

View File

@@ -4,9 +4,9 @@ fn impure(_i: int) {}
fn foo(v: &const option<int>) { fn foo(v: &const option<int>) {
alt *v { alt *v {
some(i) { some(i) {
//!^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location //~^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
unchecked { unchecked {
impure(i); //! NOTE impure due to access to impure function impure(i); //~ NOTE impure due to access to impure function
} }
} }
none { none {

View File

@@ -1,23 +1,23 @@
fn borrow(_v: &int) {} fn borrow(_v: &int) {}
fn box_mut(v: @mut ~int) { fn box_mut(v: @mut ~int) {
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(*v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_rec_mut(v: @{mut f: ~int}) { fn box_rec_mut(v: @{mut f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_mut_rec(v: @mut {f: ~int}) { fn box_mut_rec(v: @mut {f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_mut_recs(v: @mut {f: {g: {h: ~int}}}) { fn box_mut_recs(v: @mut {f: {g: {h: ~int}}}) {
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f.g.h); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_imm(v: @~int) { fn box_imm(v: @~int) {
@@ -33,28 +33,28 @@ fn box_imm_recs(v: @{f: {g: {h: ~int}}}) {
} }
fn box_const(v: @const ~int) { fn box_const(v: @const ~int) {
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(*v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_rec_const(v: @{const f: ~int}) { fn box_rec_const(v: @{const f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_recs_const(v: @{f: {g: {const h: ~int}}}) { fn box_recs_const(v: @{f: {g: {const h: ~int}}}) {
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f.g.h); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_const_rec(v: @const {f: ~int}) { fn box_const_rec(v: @const {f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_const_recs(v: @const {f: {g: {h: ~int}}}) { fn box_const_recs(v: @const {f: {g: {h: ~int}}}) {
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f.g.h); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn main() { fn main() {

View File

@@ -29,8 +29,8 @@ fn aliased_const() {
fn aliased_mut() { fn aliased_mut() {
let mut v = ~3; let mut v = ~3;
let _w = &mut v; //! NOTE prior loan as mutable granted here let _w = &mut v; //~ NOTE prior loan as mutable granted here
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
} }
fn aliased_other() { fn aliased_other() {
@@ -42,8 +42,8 @@ fn aliased_other() {
fn aliased_other_reassign() { fn aliased_other_reassign() {
let mut v = ~3, w = ~4; let mut v = ~3, w = ~4;
let mut _x = &mut w; let mut _x = &mut w;
_x = &mut v; //! NOTE prior loan as mutable granted here _x = &mut v; //~ NOTE prior loan as mutable granted here
borrow(v); //! ERROR loan of mutable local variable as immutable conflicts with prior loan borrow(v); //~ ERROR loan of mutable local variable as immutable conflicts with prior loan
} }
fn main() { fn main() {

View File

@@ -1,23 +1,23 @@
fn borrow(_v: &int) {} fn borrow(_v: &int) {}
fn box_mut(v: &mut ~int) { fn box_mut(v: &mut ~int) {
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(*v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_rec_mut(v: &{mut f: ~int}) { fn box_rec_mut(v: &{mut f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_mut_rec(v: &mut {f: ~int}) { fn box_mut_rec(v: &mut {f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_mut_recs(v: &mut {f: {g: {h: ~int}}}) { fn box_mut_recs(v: &mut {f: {g: {h: ~int}}}) {
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f.g.h); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_imm(v: &~int) { fn box_imm(v: &~int) {
@@ -33,28 +33,28 @@ fn box_imm_recs(v: &{f: {g: {h: ~int}}}) {
} }
fn box_const(v: &const ~int) { fn box_const(v: &const ~int) {
borrow(*v); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(*v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_rec_const(v: &{const f: ~int}) { fn box_rec_const(v: &{const f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_recs_const(v: &{f: {g: {const h: ~int}}}) { fn box_recs_const(v: &{f: {g: {const h: ~int}}}) {
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f.g.h); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_const_rec(v: &const {f: ~int}) { fn box_const_rec(v: &const {f: ~int}) {
borrow(v.f); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn box_const_recs(v: &const {f: {g: {h: ~int}}}) { fn box_const_recs(v: &const {f: {g: {h: ~int}}}) {
borrow(v.f.g.h); //! ERROR illegal borrow unless pure: unique value in aliasable, mutable location borrow(v.f.g.h); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//!^ NOTE impure due to access to impure function //~^ NOTE impure due to access to impure function
} }
fn main() { fn main() {

View File

@@ -1,7 +1,7 @@
fn main() { fn main() {
let x = 5; let x = 5;
let _y = fn~(move x) -> int { let _y = fn~(move x) -> int {
let _z = fn~(move x) -> int { x }; //! ERROR moving out of variable declared in an outer block let _z = fn~(move x) -> int { x }; //~ ERROR moving out of variable declared in an outer block
22 22
}; };
} }

View File

@@ -6,9 +6,9 @@ fn main() {
foo(|| bar(x) ); foo(|| bar(x) );
let x = @3; let x = @3;
foo(|copy x| bar(x) ); //! ERROR cannot capture values explicitly with a block closure foo(|copy x| bar(x) ); //~ ERROR cannot capture values explicitly with a block closure
let x = @3; let x = @3;
foo(|move x| bar(x) ); //! ERROR cannot capture values explicitly with a block closure foo(|move x| bar(x) ); //~ ERROR cannot capture values explicitly with a block closure
} }

View File

@@ -1,4 +1,4 @@
class cat : int { //! ERROR can only implement interface types class cat : int { //~ ERROR can only implement interface types
let meows: uint; let meows: uint;
new(in_x : uint) { self.meows = in_x; } new(in_x : uint) { self.meows = in_x; }
} }

View File

@@ -4,8 +4,8 @@ class cat {
fn sleep() { loop{} } fn sleep() { loop{} }
fn meow() { fn meow() {
#error("Meow"); #error("Meow");
meows += 1u; //! ERROR unresolved name meows += 1u; //~ ERROR unresolved name
sleep(); //! ERROR unresolved name sleep(); //~ ERROR unresolved name
} }
} }

View File

@@ -1,5 +1,5 @@
fn main() { fn main() {
do something do something
|x| do somethingelse //! ERROR: expecting '{' but found 'do' |x| do somethingelse //~ ERROR: expecting '{' but found 'do'
|y| say(x, y) |y| say(x, y)
} }

View File

@@ -1,3 +1,3 @@
fn main() { fn main() {
let x = do y; //! ERROR: expecting '{' but found let x = do y; //~ ERROR: expecting '{' but found
} }

View File

@@ -1,5 +1,5 @@
fn f(f: fn@(int) -> bool) -> bool { f(10i) } fn f(f: fn@(int) -> bool) -> bool { f(10i) }
fn main() { fn main() {
assert do f() |i| { i == 10i } == 10i; //! ERROR: expected `bool` but found `int` assert do f() |i| { i == 10i } == 10i; //~ ERROR: expected `bool` but found `int`
} }

View File

@@ -1,3 +1,3 @@
fn main() { fn main() {
let v = ~[,]; //! ERROR unexpected token: ',' let v = ~[,]; //~ ERROR unexpected token: ','
} }

View File

@@ -1,5 +1,5 @@
enum hello = int; enum hello = int;
fn main() { fn main() {
let hello = 0; //!ERROR declaration of `hello` shadows an enum that's in let hello = 0; //~ERROR declaration of `hello` shadows an enum that's in
} }

View File

@@ -4,26 +4,26 @@ fn wants_three(x: str/3) { }
fn has_box(x: str/@) { fn has_box(x: str/@) {
wants_box(x); wants_box(x);
wants_uniq(x); //! ERROR str storage differs: expected ~ but found @ wants_uniq(x); //~ ERROR str storage differs: expected ~ but found @
wants_three(x); //! ERROR str storage differs: expected 3 but found @ wants_three(x); //~ ERROR str storage differs: expected 3 but found @
} }
fn has_uniq(x: str/~) { fn has_uniq(x: str/~) {
wants_box(x); //! ERROR str storage differs: expected @ but found ~ wants_box(x); //~ ERROR str storage differs: expected @ but found ~
wants_uniq(x); wants_uniq(x);
wants_three(x); //! ERROR str storage differs: expected 3 but found ~ wants_three(x); //~ ERROR str storage differs: expected 3 but found ~
} }
fn has_three(x: str/3) { fn has_three(x: str/3) {
wants_box(x); //! ERROR str storage differs: expected @ but found 3 wants_box(x); //~ ERROR str storage differs: expected @ but found 3
wants_uniq(x); //! ERROR str storage differs: expected ~ but found 3 wants_uniq(x); //~ ERROR str storage differs: expected ~ but found 3
wants_three(x); wants_three(x);
} }
fn has_four(x: str/4) { fn has_four(x: str/4) {
wants_box(x); //! ERROR str storage differs: expected @ but found 4 wants_box(x); //~ ERROR str storage differs: expected @ but found 4
wants_uniq(x); //! ERROR str storage differs: expected ~ but found 4 wants_uniq(x); //~ ERROR str storage differs: expected ~ but found 4
wants_three(x); //! ERROR str storage differs: expected 3 but found 4 wants_three(x); //~ ERROR str storage differs: expected 3 but found 4
} }
fn main() { fn main() {

View File

@@ -4,26 +4,26 @@ fn wants_three(x: [uint]/3) { }
fn has_box(x: @[uint]) { fn has_box(x: @[uint]) {
wants_box(x); wants_box(x);
wants_uniq(x); //! ERROR [] storage differs: expected ~ but found @ wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found @
wants_three(x); //! ERROR [] storage differs: expected 3 but found @ wants_three(x); //~ ERROR [] storage differs: expected 3 but found @
} }
fn has_uniq(x: ~[uint]) { fn has_uniq(x: ~[uint]) {
wants_box(x); //! ERROR [] storage differs: expected @ but found ~ wants_box(x); //~ ERROR [] storage differs: expected @ but found ~
wants_uniq(x); wants_uniq(x);
wants_three(x); //! ERROR [] storage differs: expected 3 but found ~ wants_three(x); //~ ERROR [] storage differs: expected 3 but found ~
} }
fn has_three(x: [uint]/3) { fn has_three(x: [uint]/3) {
wants_box(x); //! ERROR [] storage differs: expected @ but found 3 wants_box(x); //~ ERROR [] storage differs: expected @ but found 3
wants_uniq(x); //! ERROR [] storage differs: expected ~ but found 3 wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 3
wants_three(x); wants_three(x);
} }
fn has_four(x: [uint]/4) { fn has_four(x: [uint]/4) {
wants_box(x); //! ERROR [] storage differs: expected @ but found 4 wants_box(x); //~ ERROR [] storage differs: expected @ but found 4
wants_uniq(x); //! ERROR [] storage differs: expected ~ but found 4 wants_uniq(x); //~ ERROR [] storage differs: expected ~ but found 4
wants_three(x); //! ERROR [] storage differs: expected 3 but found 4 wants_three(x); //~ ERROR [] storage differs: expected 3 but found 4
} }
fn main() { fn main() {

View File

@@ -2,5 +2,5 @@ fn main() {
fn f() { } fn f() { }
fn g(i: int) { } fn g(i: int) { }
let x = f == g; let x = f == g;
//!^ ERROR expected `extern fn()` but found `extern fn(int)` //~^ ERROR expected `extern fn()` but found `extern fn(int)`
} }

View File

@@ -7,11 +7,11 @@ fn apply<T>(t: T, f: fn(T)) {
} }
fn main() { fn main() {
apply(@3, takes_mut); //! ERROR (values differ in mutability) apply(@3, takes_mut); //~ ERROR (values differ in mutability)
apply(@3, takes_const); apply(@3, takes_const);
apply(@3, takes_imm); apply(@3, takes_imm);
apply(@mut 3, takes_mut); apply(@mut 3, takes_mut);
apply(@mut 3, takes_const); apply(@mut 3, takes_const);
apply(@mut 3, takes_imm); //! ERROR (values differ in mutability) apply(@mut 3, takes_imm); //~ ERROR (values differ in mutability)
} }

View File

@@ -18,5 +18,5 @@ fn main() {
let g: @const int = r(); let g: @const int = r();
// Bad. // Bad.
let h: @int = r(); //! ERROR (values differ in mutability) let h: @int = r(); //~ ERROR (values differ in mutability)
} }

View File

@@ -20,5 +20,5 @@ fn main() {
// mutability check will fail, because the // mutability check will fail, because the
// type of r has been inferred to be // type of r has been inferred to be
// fn(@const int) -> @const int // fn(@const int) -> @const int
*r(@mut 3) = 4; //! ERROR assigning to dereference of const @ pointer *r(@mut 3) = 4; //~ ERROR assigning to dereference of const @ pointer
} }

View File

@@ -3,5 +3,5 @@
fn main() { fn main() {
let x: option<uint>; let x: option<uint>;
x = 5; x = 5;
//!^ ERROR mismatched types: expected `core::option::option<uint>` //~^ ERROR mismatched types: expected `core::option::option<uint>`
} }

View File

@@ -10,7 +10,7 @@ mod y {
fn bar(x: x::foo) -> y::foo { fn bar(x: x::foo) -> y::foo {
ret x; ret x;
//!^ ERROR mismatched types: expected `y::foo` but found `x::foo` //~^ ERROR mismatched types: expected `y::foo` but found `x::foo`
} }
fn main() { fn main() {

View File

@@ -5,7 +5,7 @@ type T2 = int;
fn bar(x: T1) -> T2 { fn bar(x: T1) -> T2 {
ret x; ret x;
//!^ ERROR mismatched types: expected `T2` but found `T1` //~^ ERROR mismatched types: expected `T2` but found `T1`
} }
fn main() { fn main() {

View File

@@ -4,7 +4,7 @@ import core::task::task;
fn bar(x: uint) -> task { fn bar(x: uint) -> task {
ret x; ret x;
//!^ ERROR mismatched types: expected `core::task::task` //~^ ERROR mismatched types: expected `core::task::task`
} }
fn main() { fn main() {

View File

@@ -2,7 +2,7 @@ iface foo<T> { }
fn bar(x: foo<uint>) -> foo<int> { fn bar(x: foo<uint>) -> foo<int> {
ret (x as foo::<int>); ret (x as foo::<int>);
//!^ ERROR mismatched types: expected `foo<int>` but found `foo<uint>` //~^ ERROR mismatched types: expected `foo<int>` but found `foo<uint>`
} }
fn main() {} fn main() {}

View File

@@ -3,7 +3,7 @@ iface foo {
} }
impl of foo for int { impl of foo for int {
fn bar() -> int { fn bar() -> int {
//!^ ERROR method `bar` has 0 parameters but the iface has 1 //~^ ERROR method `bar` has 0 parameters but the iface has 1
self self
} }
} }

View File

@@ -4,8 +4,8 @@ impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} } impl of bar for uint { fn dup() -> uint { self } fn blah<X>() {} }
fn main() { fn main() {
10.dup::<int>(); //! ERROR does not take type parameters 10.dup::<int>(); //~ ERROR does not take type parameters
10.blah::<int, int>(); //! ERROR incorrect number of type parameters 10.blah::<int, int>(); //~ ERROR incorrect number of type parameters
10u.dup(); //! ERROR multiple applicable methods 10u.dup(); //~ ERROR multiple applicable methods
(10 as bar).dup(); //! ERROR contains a self type (10 as bar).dup(); //~ ERROR contains a self type
} }

View File

@@ -1,9 +1,9 @@
iface foo { fn foo(); } iface foo { fn foo(); }
impl of foo for uint {} //! ERROR missing method `foo` impl of foo for uint {} //~ ERROR missing method `foo`
impl of foo for uint { fn foo() -> int {} } //! ERROR incompatible type impl of foo for uint { fn foo() -> int {} } //~ ERROR incompatible type
impl of int for uint { fn foo() {} } //! ERROR can only implement interface impl of int for uint { fn foo() {} } //~ ERROR can only implement interface
fn main() {} fn main() {}

View File

@@ -3,7 +3,7 @@
fn g() { } fn g() { }
pure fn f(_q: int) -> bool { pure fn f(_q: int) -> bool {
g(); //! ERROR access to impure function prohibited in pure context g(); //~ ERROR access to impure function prohibited in pure context
ret true; ret true;
} }

View File

@@ -1,4 +1,4 @@
fn main() { fn main() {
let z = (); let z = ();
log(debug, z[0]); //! ERROR cannot index a value of type `()` log(debug, z[0]); //~ ERROR cannot index a value of type `()`
} }

View File

@@ -29,62 +29,62 @@ fn main() {
fn id_u64(n: u64) -> u64 { n } fn id_u64(n: u64) -> u64 { n }
id_i8(a8); // ok id_i8(a8); // ok
id_i8(a16); //! ERROR mismatched types: expected `i8` but found `i16` id_i8(a16); //~ ERROR mismatched types: expected `i8` but found `i16`
id_i8(a32); //! ERROR mismatched types: expected `i8` but found `i32` id_i8(a32); //~ ERROR mismatched types: expected `i8` but found `i32`
id_i8(a64); //! ERROR mismatched types: expected `i8` but found `i64` id_i8(a64); //~ ERROR mismatched types: expected `i8` but found `i64`
id_i16(a8); //! ERROR mismatched types: expected `i16` but found `i8` id_i16(a8); //~ ERROR mismatched types: expected `i16` but found `i8`
id_i16(a16); // ok id_i16(a16); // ok
id_i16(a32); //! ERROR mismatched types: expected `i16` but found `i32` id_i16(a32); //~ ERROR mismatched types: expected `i16` but found `i32`
id_i16(a64); //! ERROR mismatched types: expected `i16` but found `i64` id_i16(a64); //~ ERROR mismatched types: expected `i16` but found `i64`
id_i32(a8); //! ERROR mismatched types: expected `i32` but found `i8` id_i32(a8); //~ ERROR mismatched types: expected `i32` but found `i8`
id_i32(a16); //! ERROR mismatched types: expected `i32` but found `i16` id_i32(a16); //~ ERROR mismatched types: expected `i32` but found `i16`
id_i32(a32); // ok id_i32(a32); // ok
id_i32(a64); //! ERROR mismatched types: expected `i32` but found `i64` id_i32(a64); //~ ERROR mismatched types: expected `i32` but found `i64`
id_i64(a8); //! ERROR mismatched types: expected `i64` but found `i8` id_i64(a8); //~ ERROR mismatched types: expected `i64` but found `i8`
id_i64(a16); //! ERROR mismatched types: expected `i64` but found `i16` id_i64(a16); //~ ERROR mismatched types: expected `i64` but found `i16`
id_i64(a32); //! ERROR mismatched types: expected `i64` but found `i32` id_i64(a32); //~ ERROR mismatched types: expected `i64` but found `i32`
id_i64(a64); // ok id_i64(a64); // ok
id_i8(c8); // ok id_i8(c8); // ok
id_i8(c16); //! ERROR mismatched types: expected `i8` but found `i16` id_i8(c16); //~ ERROR mismatched types: expected `i8` but found `i16`
id_i8(c32); //! ERROR mismatched types: expected `i8` but found `i32` id_i8(c32); //~ ERROR mismatched types: expected `i8` but found `i32`
id_i8(c64); //! ERROR mismatched types: expected `i8` but found `i64` id_i8(c64); //~ ERROR mismatched types: expected `i8` but found `i64`
id_i16(c8); //! ERROR mismatched types: expected `i16` but found `i8` id_i16(c8); //~ ERROR mismatched types: expected `i16` but found `i8`
id_i16(c16); // ok id_i16(c16); // ok
id_i16(c32); //! ERROR mismatched types: expected `i16` but found `i32` id_i16(c32); //~ ERROR mismatched types: expected `i16` but found `i32`
id_i16(c64); //! ERROR mismatched types: expected `i16` but found `i64` id_i16(c64); //~ ERROR mismatched types: expected `i16` but found `i64`
id_i32(c8); //! ERROR mismatched types: expected `i32` but found `i8` id_i32(c8); //~ ERROR mismatched types: expected `i32` but found `i8`
id_i32(c16); //! ERROR mismatched types: expected `i32` but found `i16` id_i32(c16); //~ ERROR mismatched types: expected `i32` but found `i16`
id_i32(c32); // ok id_i32(c32); // ok
id_i32(c64); //! ERROR mismatched types: expected `i32` but found `i64` id_i32(c64); //~ ERROR mismatched types: expected `i32` but found `i64`
id_i64(a8); //! ERROR mismatched types: expected `i64` but found `i8` id_i64(a8); //~ ERROR mismatched types: expected `i64` but found `i8`
id_i64(a16); //! ERROR mismatched types: expected `i64` but found `i16` id_i64(a16); //~ ERROR mismatched types: expected `i64` but found `i16`
id_i64(a32); //! ERROR mismatched types: expected `i64` but found `i32` id_i64(a32); //~ ERROR mismatched types: expected `i64` but found `i32`
id_i64(a64); // ok id_i64(a64); // ok
id_u8(b8); // ok id_u8(b8); // ok
id_u8(b16); //! ERROR mismatched types: expected `u8` but found `u16` id_u8(b16); //~ ERROR mismatched types: expected `u8` but found `u16`
id_u8(b32); //! ERROR mismatched types: expected `u8` but found `u32` id_u8(b32); //~ ERROR mismatched types: expected `u8` but found `u32`
id_u8(b64); //! ERROR mismatched types: expected `u8` but found `u64` id_u8(b64); //~ ERROR mismatched types: expected `u8` but found `u64`
id_u16(b8); //! ERROR mismatched types: expected `u16` but found `u8` id_u16(b8); //~ ERROR mismatched types: expected `u16` but found `u8`
id_u16(b16); // ok id_u16(b16); // ok
id_u16(b32); //! ERROR mismatched types: expected `u16` but found `u32` id_u16(b32); //~ ERROR mismatched types: expected `u16` but found `u32`
id_u16(b64); //! ERROR mismatched types: expected `u16` but found `u64` id_u16(b64); //~ ERROR mismatched types: expected `u16` but found `u64`
id_u32(b8); //! ERROR mismatched types: expected `u32` but found `u8` id_u32(b8); //~ ERROR mismatched types: expected `u32` but found `u8`
id_u32(b16); //! ERROR mismatched types: expected `u32` but found `u16` id_u32(b16); //~ ERROR mismatched types: expected `u32` but found `u16`
id_u32(b32); // ok id_u32(b32); // ok
id_u32(b64); //! ERROR mismatched types: expected `u32` but found `u64` id_u32(b64); //~ ERROR mismatched types: expected `u32` but found `u64`
id_u64(b8); //! ERROR mismatched types: expected `u64` but found `u8` id_u64(b8); //~ ERROR mismatched types: expected `u64` but found `u8`
id_u64(b16); //! ERROR mismatched types: expected `u64` but found `u16` id_u64(b16); //~ ERROR mismatched types: expected `u64` but found `u16`
id_u64(b32); //! ERROR mismatched types: expected `u64` but found `u32` id_u64(b32); //~ ERROR mismatched types: expected `u64` but found `u32`
id_u64(b64); // ok id_u64(b64); // ok
} }

View File

@@ -1,7 +1,7 @@
// Regression test for issue #1362 - without that fix the span will be bogus // Regression test for issue #1362 - without that fix the span will be bogus
// no-reformat // no-reformat
fn main() { fn main() {
let x: uint = 20i; //! ERROR mismatched types let x: uint = 20i; //~ ERROR mismatched types
} }
// NOTE: Do not add any extra lines as the line number the error is // NOTE: Do not add any extra lines as the line number the error is
// on is significant; an error later in the source file might not // on is significant; an error later in the source file might not

View File

@@ -3,5 +3,5 @@
fn main() { fn main() {
#macro[[#apply[f, [x, ...]], f(x, ...)]]; #macro[[#apply[f, [x, ...]], f(x, ...)]];
fn add(a: int, b: int) -> int { ret a + b; } fn add(a: int, b: int) -> int { ret a + b; }
assert (#apply[add, [y, 15]] == 16); //! ERROR unresolved name: y assert (#apply[add, [y, 15]] == 16); //~ ERROR unresolved name: y
} }

View File

@@ -1,5 +1,5 @@
// Regresion test for issue #1448 and #1386 // Regresion test for issue #1448 and #1386
fn main() { fn main() {
#debug["%u", 10i]; //! ERROR mismatched types #debug["%u", 10i]; //~ ERROR mismatched types
} }

View File

@@ -1,7 +1,7 @@
// Testing that we don't fail abnormally after hitting the errors // Testing that we don't fail abnormally after hitting the errors
import unresolved::*; //! ERROR unresolved modulename import unresolved::*; //~ ERROR unresolved modulename
//!^ ERROR unresolved does not name a module //~^ ERROR unresolved does not name a module
fn main() { fn main() {
} }

View File

@@ -1,6 +1,6 @@
// Issue #1763 - infer types correctly // Issue #1763 - infer types correctly
type actor<T> = { //! ERROR type parameter `T` is unused type actor<T> = { //~ ERROR type parameter `T` is unused
unused: bool unused: bool
}; };

View File

@@ -3,6 +3,6 @@ type t<T> = { f: fn() -> T };
fn f<T>(_x: t<T>) {} fn f<T>(_x: t<T>) {}
fn main() { fn main() {
let x: t<()> = { f: || () }; //! ERROR expressions with stack closure let x: t<()> = { f: || () }; //~ ERROR expressions with stack closure
f(x); f(x);
} }

Some files were not shown because too many files have changed in this diff Show More