Skip to content

Commit bc6eecd

Browse files
authoredMar 17, 2017
Merge branch 'master' into frewsxcv-osstr
2 parents 6adbbfc + 0aeb9c1 commit bc6eecd

File tree

19 files changed

+244
-53
lines changed

19 files changed

+244
-53
lines changed
 

‎configure

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ opt dist-host-only 0 "only install bins for the host architecture"
445445
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
446446
opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
447447
opt codegen-tests 1 "run the src/test/codegen tests"
448+
opt save-analysis 0 "save API analysis data"
448449
opt option-checking 1 "complain about unrecognized options in this configure script"
449450
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
450451
opt locked-deps 0 "force Cargo.lock to be up to date"

‎src/bootstrap/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub struct Config {
7474
pub rustc_default_ar: Option<String>,
7575
pub rust_optimize_tests: bool,
7676
pub rust_debuginfo_tests: bool,
77+
pub rust_save_analysis: bool,
7778
pub rust_dist_src: bool,
7879

7980
pub build: String,
@@ -225,6 +226,7 @@ struct Rust {
225226
optimize_tests: Option<bool>,
226227
debuginfo_tests: Option<bool>,
227228
codegen_tests: Option<bool>,
229+
save_analysis: Option<bool>,
228230
}
229231

230232
/// TOML representation of how each build target is configured.
@@ -350,6 +352,7 @@ impl Config {
350352
set(&mut config.rust_optimize_tests, rust.optimize_tests);
351353
set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
352354
set(&mut config.codegen_tests, rust.codegen_tests);
355+
set(&mut config.rust_save_analysis, rust.save_analysis);
353356
set(&mut config.rust_rpath, rust.rpath);
354357
set(&mut config.debug_jemalloc, rust.debug_jemalloc);
355358
set(&mut config.use_jemalloc, rust.use_jemalloc);
@@ -457,6 +460,7 @@ impl Config {
457460
("LOCAL_REBUILD", self.local_rebuild),
458461
("NINJA", self.ninja),
459462
("CODEGEN_TESTS", self.codegen_tests),
463+
("SAVE_ANALYSIS", self.rust_save_analysis),
460464
("LOCKED_DEPS", self.locked_deps),
461465
("VENDOR", self.vendor),
462466
("FULL_BOOTSTRAP", self.full_bootstrap),

‎src/bootstrap/config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@
234234
# saying that the FileCheck executable is missing, you may want to disable this.
235235
#codegen-tests = true
236236

237+
# Flag indicating whether the API analysis data should be saved.
238+
#save-analysis = false
239+
237240
# =============================================================================
238241
# Options for specific targets
239242
#

‎src/bootstrap/dist.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,14 @@ pub fn rust_src_location(build: &Build) -> PathBuf {
311311

312312
/// Creates a tarball of save-analysis metadata, if available.
313313
pub fn analysis(build: &Build, compiler: &Compiler, target: &str) {
314+
if !build.config.rust_save_analysis {
315+
return
316+
}
317+
314318
println!("Dist analysis");
315319

316-
if build.config.channel != "nightly" {
317-
println!("\tskipping - not on nightly channel");
318-
return;
319-
}
320320
if compiler.host != build.config.build {
321-
println!("\tskipping - not a build host");
322-
return
323-
}
324-
if compiler.stage != 2 {
325-
println!("\tskipping - not stage2");
321+
println!("\tskipping, not a build host");
326322
return
327323
}
328324

‎src/bootstrap/install.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ pub fn install(build: &Build, stage: u32, host: &str) {
4949
install_sh(&build, "docs", "rust-docs", stage, host, &prefix,
5050
&docdir, &libdir, &mandir, &empty_dir);
5151
}
52+
if build.config.rust_save_analysis {
53+
install_sh(&build, "analysis", "rust-analysis", stage, host, &prefix,
54+
&docdir, &libdir, &mandir, &empty_dir);
55+
}
5256
install_sh(&build, "std", "rust-std", stage, host, &prefix,
5357
&docdir, &libdir, &mandir, &empty_dir);
5458
install_sh(&build, "rustc", "rustc", stage, host, &prefix,

‎src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl Build {
524524
.env(format!("CFLAGS_{}", target), self.cflags(target).join(" "));
525525
}
526526

527-
if self.config.channel == "nightly" && compiler.is_final_stage(self) {
527+
if self.config.rust_save_analysis && compiler.is_final_stage(self) {
528528
cargo.env("RUSTC_SAVE_ANALYSIS", "api".to_string());
529529
}
530530

‎src/ci/run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fi
4343
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
4444
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=nightly"
4545
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
46+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-save-analysis"
4647

4748
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
4849
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"

‎src/libcollections/string.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,22 @@ impl<'a> From<&'a str> for String {
19741974
}
19751975
}
19761976

1977+
// note: test pulls in libstd, which causes errors here
1978+
#[cfg(not(test))]
1979+
#[stable(feature = "string_from_box", since = "1.17.0")]
1980+
impl From<Box<str>> for String {
1981+
fn from(s: Box<str>) -> String {
1982+
s.into_string()
1983+
}
1984+
}
1985+
1986+
#[stable(feature = "box_from_str", since = "1.17.0")]
1987+
impl Into<Box<str>> for String {
1988+
fn into(self) -> Box<str> {
1989+
self.into_boxed_str()
1990+
}
1991+
}
1992+
19771993
#[stable(feature = "string_from_cow_str", since = "1.14.0")]
19781994
impl<'a> From<Cow<'a, str>> for String {
19791995
fn from(s: Cow<'a, str>) -> String {

‎src/libcollections/vec.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,22 @@ impl<'a, T> From<Cow<'a, [T]>> for Vec<T> where [T]: ToOwned<Owned=Vec<T>> {
18971897
}
18981898
}
18991899

1900+
// note: test pulls in libstd, which causes errors here
1901+
#[cfg(not(test))]
1902+
#[stable(feature = "vec_from_box", since = "1.17.0")]
1903+
impl<T> From<Box<[T]>> for Vec<T> {
1904+
fn from(s: Box<[T]>) -> Vec<T> {
1905+
s.into_vec()
1906+
}
1907+
}
1908+
1909+
#[stable(feature = "box_from_vec", since = "1.17.0")]
1910+
impl<T> Into<Box<[T]>> for Vec<T> {
1911+
fn into(self) -> Box<[T]> {
1912+
self.into_boxed_slice()
1913+
}
1914+
}
1915+
19001916
#[stable(feature = "rust1", since = "1.0.0")]
19011917
impl<'a> From<&'a str> for Vec<u8> {
19021918
fn from(s: &'a str) -> Vec<u8> {

‎src/libcollectionstest/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#![feature(test)]
2929
#![feature(unboxed_closures)]
3030
#![feature(unicode)]
31+
#![feature(utf8_error_error_len)]
3132

3233
extern crate collections;
3334
extern crate test;

‎src/libcollectionstest/str.rs

+30
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,36 @@ fn from_utf8_mostly_ascii() {
540540
}
541541
}
542542

543+
#[test]
544+
fn from_utf8_error() {
545+
macro_rules! test {
546+
($input: expr, $expected_valid_up_to: expr, $expected_error_len: expr) => {
547+
let error = from_utf8($input).unwrap_err();
548+
assert_eq!(error.valid_up_to(), $expected_valid_up_to);
549+
assert_eq!(error.error_len(), $expected_error_len);
550+
}
551+
}
552+
test!(b"A\xC3\xA9 \xFF ", 4, Some(1));
553+
test!(b"A\xC3\xA9 \x80 ", 4, Some(1));
554+
test!(b"A\xC3\xA9 \xC1 ", 4, Some(1));
555+
test!(b"A\xC3\xA9 \xC1", 4, Some(1));
556+
test!(b"A\xC3\xA9 \xC2", 4, None);
557+
test!(b"A\xC3\xA9 \xC2 ", 4, Some(1));
558+
test!(b"A\xC3\xA9 \xC2\xC0", 4, Some(1));
559+
test!(b"A\xC3\xA9 \xE0", 4, None);
560+
test!(b"A\xC3\xA9 \xE0\x9F", 4, Some(1));
561+
test!(b"A\xC3\xA9 \xE0\xA0", 4, None);
562+
test!(b"A\xC3\xA9 \xE0\xA0\xC0", 4, Some(2));
563+
test!(b"A\xC3\xA9 \xE0\xA0 ", 4, Some(2));
564+
test!(b"A\xC3\xA9 \xED\xA0\x80 ", 4, Some(1));
565+
test!(b"A\xC3\xA9 \xF1", 4, None);
566+
test!(b"A\xC3\xA9 \xF1\x80", 4, None);
567+
test!(b"A\xC3\xA9 \xF1\x80\x80", 4, None);
568+
test!(b"A\xC3\xA9 \xF1 ", 4, Some(1));
569+
test!(b"A\xC3\xA9 \xF1\x80 ", 4, Some(2));
570+
test!(b"A\xC3\xA9 \xF1\x80\x80 ", 4, Some(3));
571+
}
572+
543573
#[test]
544574
fn test_as_bytes() {
545575
// no null

‎src/libcore/str/mod.rs

+58-22
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ Section: Creating a string
125125
#[stable(feature = "rust1", since = "1.0.0")]
126126
pub struct Utf8Error {
127127
valid_up_to: usize,
128+
error_len: Option<u8>,
128129
}
129130

130131
impl Utf8Error {
131132
/// Returns the index in the given string up to which valid UTF-8 was
132133
/// verified.
133134
///
134-
/// It is the maximum index such that `from_utf8(input[..index])`
135+
/// It is the maximum index such that `from_utf8(&input[..index])`
135136
/// would return `Ok(_)`.
136137
///
137138
/// # Examples
@@ -152,6 +153,23 @@ impl Utf8Error {
152153
/// ```
153154
#[stable(feature = "utf8_error", since = "1.5.0")]
154155
pub fn valid_up_to(&self) -> usize { self.valid_up_to }
156+
157+
/// Provide more information about the failure:
158+
///
159+
/// * `None`: the end of the input was reached unexpectedly.
160+
/// `self.valid_up_to()` is 1 to 3 bytes from the end of the input.
161+
/// If a byte stream (such as a file or a network socket) is being decoded incrementally,
162+
/// this could be a valid `char` whose UTF-8 byte sequence is spanning multiple chunks.
163+
///
164+
/// * `Some(len)`: an unexpected byte was encountered.
165+
/// The length provided is that of the invalid byte sequence
166+
/// that starts at the index given by `valid_up_to()`.
167+
/// Decoding should resume after that sequence
168+
/// (after inserting a U+FFFD REPLACEMENT CHARACTER) in case of lossy decoding.
169+
#[unstable(feature = "utf8_error_error_len", reason ="new", issue = "40494")]
170+
pub fn error_len(&self) -> Option<usize> {
171+
self.error_len.map(|len| len as usize)
172+
}
155173
}
156174

157175
/// Converts a slice of bytes to a string slice.
@@ -300,7 +318,12 @@ pub unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
300318
#[stable(feature = "rust1", since = "1.0.0")]
301319
impl fmt::Display for Utf8Error {
302320
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
303-
write!(f, "invalid utf-8: invalid byte near index {}", self.valid_up_to)
321+
if let Some(error_len) = self.error_len {
322+
write!(f, "invalid utf-8 sequence of {} bytes from index {}",
323+
error_len, self.valid_up_to)
324+
} else {
325+
write!(f, "incomplete utf-8 byte sequence from index {}", self.valid_up_to)
326+
}
304327
}
305328
}
306329

@@ -1241,25 +1264,27 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
12411264

12421265
while index < len {
12431266
let old_offset = index;
1244-
macro_rules! err { () => {{
1245-
return Err(Utf8Error {
1246-
valid_up_to: old_offset
1247-
})
1248-
}}}
1267+
macro_rules! err {
1268+
($error_len: expr) => {
1269+
return Err(Utf8Error {
1270+
valid_up_to: old_offset,
1271+
error_len: $error_len,
1272+
})
1273+
}
1274+
}
12491275

12501276
macro_rules! next { () => {{
12511277
index += 1;
12521278
// we needed data, but there was none: error!
12531279
if index >= len {
1254-
err!()
1280+
err!(None)
12551281
}
12561282
v[index]
12571283
}}}
12581284

12591285
let first = v[index];
12601286
if first >= 128 {
12611287
let w = UTF8_CHAR_WIDTH[first as usize];
1262-
let second = next!();
12631288
// 2-byte encoding is for codepoints \u{0080} to \u{07ff}
12641289
// first C2 80 last DF BF
12651290
// 3-byte encoding is for codepoints \u{0800} to \u{ffff}
@@ -1279,25 +1304,36 @@ fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> {
12791304
// UTF8-4 = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
12801305
// %xF4 %x80-8F 2( UTF8-tail )
12811306
match w {
1282-
2 => if second & !CONT_MASK != TAG_CONT_U8 {err!()},
1307+
2 => if next!() & !CONT_MASK != TAG_CONT_U8 {
1308+
err!(Some(1))
1309+
},
12831310
3 => {
1284-
match (first, second, next!() & !CONT_MASK) {
1285-
(0xE0 , 0xA0 ... 0xBF, TAG_CONT_U8) |
1286-
(0xE1 ... 0xEC, 0x80 ... 0xBF, TAG_CONT_U8) |
1287-
(0xED , 0x80 ... 0x9F, TAG_CONT_U8) |
1288-
(0xEE ... 0xEF, 0x80 ... 0xBF, TAG_CONT_U8) => {}
1289-
_ => err!()
1311+
match (first, next!()) {
1312+
(0xE0 , 0xA0 ... 0xBF) |
1313+
(0xE1 ... 0xEC, 0x80 ... 0xBF) |
1314+
(0xED , 0x80 ... 0x9F) |
1315+
(0xEE ... 0xEF, 0x80 ... 0xBF) => {}
1316+
_ => err!(Some(1))
1317+
}
1318+
if next!() & !CONT_MASK != TAG_CONT_U8 {
1319+
err!(Some(2))
12901320
}
12911321
}
12921322
4 => {
1293-
match (first, second, next!() & !CONT_MASK, next!() & !CONT_MASK) {
1294-
(0xF0 , 0x90 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
1295-
(0xF1 ... 0xF3, 0x80 ... 0xBF, TAG_CONT_U8, TAG_CONT_U8) |
1296-
(0xF4 , 0x80 ... 0x8F, TAG_CONT_U8, TAG_CONT_U8) => {}
1297-
_ => err!()
1323+
match (first, next!()) {
1324+
(0xF0 , 0x90 ... 0xBF) |
1325+
(0xF1 ... 0xF3, 0x80 ... 0xBF) |
1326+
(0xF4 , 0x80 ... 0x8F) => {}
1327+
_ => err!(Some(1))
1328+
}
1329+
if next!() & !CONT_MASK != TAG_CONT_U8 {
1330+
err!(Some(2))
1331+
}
1332+
if next!() & !CONT_MASK != TAG_CONT_U8 {
1333+
err!(Some(3))
12981334
}
12991335
}
1300-
_ => err!()
1336+
_ => err!(Some(1))
13011337
}
13021338
index += 1;
13031339
} else {

‎src/libstd/ffi/c_str.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl CString {
325325
}
326326

327327
/// Converts this `CString` into a boxed `CStr`.
328-
#[unstable(feature = "into_boxed_c_str", issue = "0")]
328+
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
329329
pub fn into_boxed_c_str(self) -> Box<CStr> {
330330
unsafe { mem::transmute(self.into_inner()) }
331331
}
@@ -415,6 +415,20 @@ impl<'a> From<&'a CStr> for Box<CStr> {
415415
}
416416
}
417417

418+
#[stable(feature = "c_string_from_box", since = "1.17.0")]
419+
impl From<Box<CStr>> for CString {
420+
fn from(s: Box<CStr>) -> CString {
421+
s.into_c_string()
422+
}
423+
}
424+
425+
#[stable(feature = "box_from_c_string", since = "1.17.0")]
426+
impl Into<Box<CStr>> for CString {
427+
fn into(self) -> Box<CStr> {
428+
self.into_boxed_c_str()
429+
}
430+
}
431+
418432
#[stable(feature = "default_box_extra", since = "1.17.0")]
419433
impl Default for Box<CStr> {
420434
fn default() -> Box<CStr> {
@@ -728,6 +742,12 @@ impl CStr {
728742
pub fn to_string_lossy(&self) -> Cow<str> {
729743
String::from_utf8_lossy(self.to_bytes())
730744
}
745+
746+
/// Converts a `Box<CStr>` into a `CString` without copying or allocating.
747+
#[unstable(feature = "into_boxed_c_str", issue = "40380")]
748+
pub fn into_c_string(self: Box<CStr>) -> CString {
749+
unsafe { mem::transmute(self) }
750+
}
731751
}
732752

733753
#[stable(feature = "rust1", since = "1.0.0")]
@@ -922,12 +942,11 @@ mod tests {
922942
fn into_boxed() {
923943
let orig: &[u8] = b"Hello, world!\0";
924944
let cstr = CStr::from_bytes_with_nul(orig).unwrap();
925-
let cstring = cstr.to_owned();
926-
let box1: Box<CStr> = Box::from(cstr);
927-
let box2 = cstring.into_boxed_c_str();
928-
assert_eq!(cstr, &*box1);
929-
assert_eq!(box1, box2);
930-
assert_eq!(&*box2, cstr);
945+
let boxed: Box<CStr> = Box::from(cstr);
946+
let cstring = cstr.to_owned().into_boxed_c_str().into_c_string();
947+
assert_eq!(cstr, &*boxed);
948+
assert_eq!(&*boxed, &*cstring);
949+
assert_eq!(&*cstring, cstr);
931950
}
932951

933952
#[test]

0 commit comments

Comments
 (0)
Please sign in to comment.