Skip to content
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

Rolling up PRs in the queue #15025

Merged
merged 25 commits into from
Jun 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
303cadf
vim: Add :Run and :Expand commands
lilyball May 27, 2014
bd3bebc
Rename :Run and :Expand to :RustRun and :RustExpand
lilyball May 30, 2014
918eda5
Write documentation for the Rust vim plugin
lilyball May 30, 2014
1273f94
Add commands :RustEmitIr and :RustEmitAsm
lilyball May 30, 2014
87c529c
Add a ByteOrder trait for abstracting over endian conversions
brendanzab Jun 15, 2014
b84d17d
Use ByteOrder methods instead of free-standing functions
brendanzab Jun 15, 2014
4c0f8f4
Fix comment formatting
brendanzab Jun 16, 2014
ff9f92c
Merge the Bitwise and ByteOrder traits into the Int trait
brendanzab Jun 16, 2014
779ca97
Remove `#[stable]` attribute from free-standing endian conversions an…
brendanzab Jun 16, 2014
cb8ca2d
Shorten endian conversion method names
brendanzab Jun 17, 2014
ae7006e
Update doc comment for Int trait
brendanzab Jun 17, 2014
8e9e17d
librustc: Use expr_ty_adjusted in trans_overloaded_call.
luqmana Jun 17, 2014
a23511a
Revamp TaskBuilder API
aturon Jun 17, 2014
f993495
Fallout from TaskBuilder changes
aturon Jun 16, 2014
90f7e3a
Reject double moves out of array elements
Jun 18, 2014
31dfcf9
Vim: highlight escapes for byte literals.
chris-morgan Jun 18, 2014
b0dff7a
Vim: highlight invalid characters in char literals.
chris-morgan Jun 18, 2014
bde851e
Fix FIXME #5275
Sawyer47 Jun 18, 2014
b1df9aa
Fix #14865
edwardw Jun 18, 2014
7cfdfa6
debuginfo: Add test case for issue 14411.
michaelwoerister Jun 18, 2014
ba863c8
(doc) Change search placeholder text.
zzmp Jun 18, 2014
abf7e93
Update compiler-rt to work for non-v7 arm.
luqmana Jun 18, 2014
108b8b6
Deprecate the bytes!() macro.
SimonSapin Jun 18, 2014
72f0d45
Revert bytes!() docstring change, and fix a typo.
SimonSapin Jun 18, 2014
2c3bf88
Merge conflicts from the rollup
alexcrichton Jun 19, 2014
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
2 changes: 1 addition & 1 deletion src/compiler-rt
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path {

fn aux_output_dir_name(config: &Config, testfile: &Path) -> Path {
let mut f = output_base_name(config, testfile);
match f.filename().map(|s| Vec::from_slice(s).append(bytes!(".libaux"))) {
match f.filename().map(|s| Vec::from_slice(s).append(b".libaux")) {
Some(v) => f.set_filename(v),
None => ()
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
(*p).clone()
} else {
let stem = p.filestem().unwrap();
p.with_filename(Vec::from_slice(stem).append(bytes!("-")).append(suffix.as_bytes()))
p.with_filename(Vec::from_slice(stem).append(b"-").append(suffix.as_bytes()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/doc/complement-cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ character.
~~~
use std::str;

let x = bytes!(72u8,"ello ",0xF0,0x90,0x80,"World!");
let x = b"Hello \xF0\x90\x80World!";
let y = str::from_utf8_lossy(x);
~~~

Expand Down
13 changes: 13 additions & 0 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,19 @@ the characters `U+0022` (double-quote) (except when followed by at least as
many `U+0023` (`#`) characters as were used to start the raw string literal) or
`U+005C` (`\`) do not have any special meaning.

Examples for byte string literals:

~~~~
b"foo"; br"foo"; // foo
b"\"foo\""; br#""foo""#; // "foo"

b"foo #\"# bar";
br##"foo #"# bar"##; // foo #"# bar

b"\x52"; b"R"; br"R"; // R
b"\\x52"; br"\x52"; // \x52
~~~~

#### Number literals

~~~~ {.ebnf .gram}
Expand Down
138 changes: 138 additions & 0 deletions src/etc/2014-06-rewrite-bytes-macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/env python
#
# 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.

import sys
import subprocess
import re


def main():
if len(sys.argv) <= 1:
print('Usage: %s [ --apply ] filename1.rs filename2.rs ...'
% sys.argv[0])
elif sys.argv[1] == '--apply':
for filename in sys.argv[2:]:
patch(filename)
else:
for filename in sys.argv[1:]:
diff(filename)


def patch(filename):
source = read(filename)
rewritten = rewrite_bytes_macros(source)
if rewritten is not None and rewritten != source:
write(filename, rewritten)


def diff(filename):
rewritten = rewrite_bytes_macros(read(filename))
if rewritten is not None:
p = subprocess.Popen(['diff', '-u', filename, '-'],
stdin=subprocess.PIPE)
p.stdin.write(rewritten)
p.stdin.close()
p.wait()


def read(filename):
with open(filename, 'rb') as f:
return f.read()


def write(filename, content):
with open(filename, 'wb') as f:
f.write(content)


def rewrite_bytes_macros(source):
rewritten, num_occurrences = BYTES_MACRO_RE.subn(rewrite_one_macro, source)
if num_occurrences > 0:
return rewritten


BYTES_MACRO_RE = re.compile(br'bytes!\( (?P<args> [^)]* ) \)', re.VERBOSE)


def rewrite_one_macro(match):
try:
bytes = parse_bytes(split_args(match.group('args')))
return b'b"' + b''.join(map(escape, bytes)) + b'"'
except SkipThisRewrite:
print('Skipped: %s' % match.group(0).decode('utf8', 'replace'))
return match.group(0)


class SkipThisRewrite(Exception):
pass


def split_args(args):
previous = b''
for arg in args.split(b','):
if previous:
arg = previous + b',' + arg
if arg.count(b'"') % 2 == 0:
yield arg
previous = b''
else:
previous = arg
if previous:
yield previous


def parse_bytes(args):
for arg in args:
arg = arg.strip()
if (arg.startswith(b'"') and arg.endswith(b'"')) or (
arg.startswith(b"'") and arg.endswith(b"'")):
# Escaped newline means something different in Rust and Python.
if b'\\\n' in arg:
raise SkipThisRewrite
for byte in eval(b'u' + arg).encode('utf8'):
yield ord(byte)
else:
if arg.endswith(b'u8'):
arg = arg[:-2]
# Assume that all Rust integer literals
# are valid Python integer literals
value = int(eval(arg))
assert value <= 0xFF
yield value


def escape(byte):
c = chr(byte)
escaped = {
b'\0': br'\0',
b'\t': br'\t',
b'\n': br'\n',
b'\r': br'\r',
b'\'': b'\\\'',
b'\\': br'\\',
}.get(c)
if escaped is not None:
return escaped
elif b' ' <= c <= b'~':
return chr(byte)
else:
return ('\\x%02X' % byte).encode('ascii')


if str is not bytes:
# Python 3.x
ord = lambda x: x
chr = lambda x: bytes([x])


if __name__ == '__main__':
main()
Loading