Skip to content

Commit 09b88c9

Browse files
committed
---
yaml --- r: 210343 b: refs/heads/try c: 6c9f840 h: refs/heads/master i: 210341: 1950795 210339: 92ba656 210335: 27d3b97 v: v3
1 parent 5a3b8a1 commit 09b88c9

File tree

15 files changed

+310
-29
lines changed

15 files changed

+310
-29
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 29d7fed994bb35c1cf7e686a3fe967ddff734d01
5+
refs/heads/try: 6c9f8408d5cd07f3fd3b5136b4373dadd0edbf07
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/mk/crates.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \
5858
rustc_data_structures
5959
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros
6060
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
61-
TOOLS := compiletest rustdoc rustc rustbook
61+
TOOLS := compiletest rustdoc rustc rustbook error-index-generator
6262

6363
DEPS_core :=
6464
DEPS_libc := core
@@ -107,10 +107,12 @@ TOOL_DEPS_compiletest := test getopts
107107
TOOL_DEPS_rustdoc := rustdoc
108108
TOOL_DEPS_rustc := rustc_driver
109109
TOOL_DEPS_rustbook := std rustdoc
110+
TOOL_DEPS_error-index-generator := rustdoc syntax serialize
110111
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
111112
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
112113
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
113114
TOOL_SOURCE_rustbook := $(S)src/rustbook/main.rs
115+
TOOL_SOURCE_error-index-generator := $(S)src/error-index-generator/main.rs
114116

115117
ONLY_RLIB_core := 1
116118
ONLY_RLIB_libc := 1

branches/try/mk/docs.mk

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ RUSTBOOK_EXE = $(HBIN2_H_$(CFG_BUILD))/rustbook$(X_$(CFG_BUILD))
7171
# ./configure
7272
RUSTBOOK = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(RUSTBOOK_EXE)
7373

74+
# The error-index-generator executable...
75+
ERR_IDX_GEN_EXE = $(HBIN2_H_$(CFG_BUILD))/error-index-generator$(X_$(CFG_BUILD))
76+
ERR_IDX_GEN = $(RPATH_VAR2_T_$(CFG_BUILD)_H_$(CFG_BUILD)) $(ERR_IDX_GEN_EXE)
77+
7478
D := $(S)src/doc
7579

76-
DOC_TARGETS := trpl style
80+
DOC_TARGETS := trpl style error-index
7781
COMPILER_DOC_TARGETS :=
7882
DOC_L10N_TARGETS :=
7983

@@ -288,3 +292,9 @@ doc/style/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/style/*.md) | doc/
288292
@$(call E, rustbook: $@)
289293
$(Q)rm -rf doc/style
290294
$(Q)$(RUSTBOOK) build $(S)src/doc/style doc/style
295+
296+
error-index: doc/error-index.html
297+
298+
doc/error-index.html: $(ERR_IDX_GEN_EXE) | doc/
299+
$(Q)$(call E, error-index-generator: $@)
300+
$(Q)$(ERR_IDX_GEN)

branches/try/mk/prepare.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ define PREPARE_MAN
7070
$(Q)$(PREPARE_MAN_CMD) $(PREPARE_SOURCE_MAN_DIR)/$(1) $(PREPARE_DEST_MAN_DIR)/$(1)
7171
endef
7272

73-
PREPARE_TOOLS = $(filter-out compiletest rustbook, $(TOOLS))
73+
PREPARE_TOOLS = $(filter-out compiletest rustbook error-index-generator, $(TOOLS))
7474

7575

7676
# $(1) is tool
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_private, rustdoc)]
12+
13+
extern crate syntax;
14+
extern crate rustdoc;
15+
extern crate serialize as rustc_serialize;
16+
17+
use std::collections::BTreeMap;
18+
use std::fs::{read_dir, File};
19+
use std::io::{Read, Write};
20+
use std::path::Path;
21+
use std::error::Error;
22+
23+
use syntax::diagnostics::metadata::{get_metadata_dir, ErrorMetadataMap};
24+
25+
use rustdoc::html::markdown::Markdown;
26+
use rustc_serialize::json;
27+
28+
/// Load all the metadata files from `metadata_dir` into an in-memory map.
29+
fn load_all_errors(metadata_dir: &Path) -> Result<ErrorMetadataMap, Box<Error>> {
30+
let mut all_errors = BTreeMap::new();
31+
32+
for entry in try!(read_dir(metadata_dir)) {
33+
let path = try!(entry).path();
34+
35+
let mut metadata_str = String::new();
36+
try!(
37+
File::open(&path).and_then(|mut f|
38+
f.read_to_string(&mut metadata_str))
39+
);
40+
41+
let some_errors: ErrorMetadataMap = try!(json::decode(&metadata_str));
42+
43+
for (err_code, info) in some_errors {
44+
all_errors.insert(err_code, info);
45+
}
46+
}
47+
48+
Ok(all_errors)
49+
}
50+
51+
/// Output an HTML page for the errors in `err_map` to `output_path`.
52+
fn render_error_page(err_map: &ErrorMetadataMap, output_path: &Path) -> Result<(), Box<Error>> {
53+
let mut output_file = try!(File::create(output_path));
54+
55+
try!(write!(&mut output_file,
56+
r##"<!DOCTYPE html>
57+
<html>
58+
<head>
59+
<title>Rust Compiler Error Index</title>
60+
<meta charset="utf-8">
61+
<!-- Include rust.css after main.css so its rules take priority. -->
62+
<link rel="stylesheet" type="text/css" href="main.css"/>
63+
<link rel="stylesheet" type="text/css" href="rust.css"/>
64+
<style>
65+
.error-undescribed {{
66+
display: none;
67+
}}
68+
</style>
69+
</head>
70+
<body>
71+
"##
72+
));
73+
74+
try!(write!(&mut output_file, "<h1>Rust Compiler Error Index</h1>\n"));
75+
76+
for (err_code, info) in err_map.iter() {
77+
// Enclose each error in a div so they can be shown/hidden en masse.
78+
let desc_desc = match info.description {
79+
Some(_) => "error-described",
80+
None => "error-undescribed"
81+
};
82+
let use_desc = match info.use_site {
83+
Some(_) => "error-used",
84+
None => "error-unused"
85+
};
86+
try!(write!(&mut output_file, "<div class=\"{} {}\">", desc_desc, use_desc));
87+
88+
// Error title (with self-link).
89+
try!(write!(&mut output_file,
90+
"<h2 id=\"{0}\" class=\"section-header\"><a href=\"#{0}\">{0}</a></h2>\n",
91+
err_code
92+
));
93+
94+
// Description rendered as markdown.
95+
match info.description {
96+
Some(ref desc) => try!(write!(&mut output_file, "{}", Markdown(desc))),
97+
None => try!(write!(&mut output_file, "<p>No description.</p>\n"))
98+
}
99+
100+
try!(write!(&mut output_file, "</div>\n"));
101+
}
102+
103+
try!(write!(&mut output_file, "</body>\n</html>"));
104+
105+
Ok(())
106+
}
107+
108+
fn main_with_result() -> Result<(), Box<Error>> {
109+
let metadata_dir = get_metadata_dir();
110+
let err_map = try!(load_all_errors(&metadata_dir));
111+
try!(render_error_page(&err_map, Path::new("doc/error-index.html")));
112+
Ok(())
113+
}
114+
115+
fn main() {
116+
if let Err(e) = main_with_result() {
117+
panic!("{}", e.description());
118+
}
119+
}

branches/try/src/libcollections/slice.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,13 @@ impl<T> [T] {
996996
////////////////////////////////////////////////////////////////////////////////
997997
// Extension traits for slices over specific kinds of data
998998
////////////////////////////////////////////////////////////////////////////////
999-
#[unstable(feature = "collections", reason = "U should be an associated type")]
999+
#[unstable(feature = "collections", reason = "recently changed")]
10001000
/// An extension trait for concatenating slices
1001-
pub trait SliceConcatExt<T: ?Sized, U> {
1001+
pub trait SliceConcatExt<T: ?Sized> {
1002+
#[unstable(feature = "collections", reason = "recently changed")]
1003+
/// The resulting type after concatenation
1004+
type Output;
1005+
10021006
/// Flattens a slice of `T` into a single value `U`.
10031007
///
10041008
/// # Examples
@@ -1007,7 +1011,7 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10071011
/// assert_eq!(["hello", "world"].concat(), "helloworld");
10081012
/// ```
10091013
#[stable(feature = "rust1", since = "1.0.0")]
1010-
fn concat(&self) -> U;
1014+
fn concat(&self) -> Self::Output;
10111015

10121016
/// Flattens a slice of `T` into a single value `U`, placing a given separator between each.
10131017
///
@@ -1017,10 +1021,12 @@ pub trait SliceConcatExt<T: ?Sized, U> {
10171021
/// assert_eq!(["hello", "world"].connect(" "), "hello world");
10181022
/// ```
10191023
#[stable(feature = "rust1", since = "1.0.0")]
1020-
fn connect(&self, sep: &T) -> U;
1024+
fn connect(&self, sep: &T) -> Self::Output;
10211025
}
10221026

1023-
impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T, Vec<T>> for [V] {
1027+
impl<T: Clone, V: AsRef<[T]>> SliceConcatExt<T> for [V] {
1028+
type Output = Vec<T>;
1029+
10241030
fn concat(&self) -> Vec<T> {
10251031
let size = self.iter().fold(0, |acc, v| acc + v.as_ref().len());
10261032
let mut result = Vec::with_capacity(size);

branches/try/src/libcollections/str.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ pub use core::str::pattern;
8383
Section: Creating a string
8484
*/
8585

86-
impl<S: AsRef<str>> SliceConcatExt<str, String> for [S] {
86+
impl<S: AsRef<str>> SliceConcatExt<str> for [S] {
87+
type Output = String;
88+
8789
fn concat(&self) -> String {
8890
if self.is_empty() {
8991
return String::new();

branches/try/src/libstd/env.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn current_dir() -> io::Result<PathBuf> {
6666
/// println!("Successfully changed working directory to {}!", root.display());
6767
/// ```
6868
#[stable(feature = "env", since = "1.0.0")]
69-
pub fn set_current_dir<P: AsRef<Path> + ?Sized>(p: &P) -> io::Result<()> {
69+
pub fn set_current_dir<P: AsRef<Path>>(p: P) -> io::Result<()> {
7070
os_imp::chdir(p.as_ref())
7171
}
7272

@@ -175,7 +175,7 @@ impl Iterator for VarsOs {
175175
/// }
176176
/// ```
177177
#[stable(feature = "env", since = "1.0.0")]
178-
pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr> {
178+
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
179179
match var_os(key) {
180180
Some(s) => s.into_string().map_err(VarError::NotUnicode),
181181
None => Err(VarError::NotPresent)
@@ -197,7 +197,7 @@ pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr>
197197
/// }
198198
/// ```
199199
#[stable(feature = "env", since = "1.0.0")]
200-
pub fn var_os<K: ?Sized>(key: &K) -> Option<OsString> where K: AsRef<OsStr> {
200+
pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
201201
let _g = ENV_LOCK.lock();
202202
os_imp::getenv(key.as_ref())
203203
}
@@ -253,9 +253,7 @@ impl Error for VarError {
253253
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
254254
/// ```
255255
#[stable(feature = "env", since = "1.0.0")]
256-
pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
257-
where K: AsRef<OsStr>, V: AsRef<OsStr>
258-
{
256+
pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(k: K, v: V) {
259257
let _g = ENV_LOCK.lock();
260258
os_imp::setenv(k.as_ref(), v.as_ref())
261259
}
@@ -275,7 +273,7 @@ pub fn set_var<K: ?Sized, V: ?Sized>(k: &K, v: &V)
275273
/// assert!(env::var(key).is_err());
276274
/// ```
277275
#[stable(feature = "env", since = "1.0.0")]
278-
pub fn remove_var<K: ?Sized>(k: &K) where K: AsRef<OsStr> {
276+
pub fn remove_var<K: AsRef<OsStr>>(k: K) {
279277
let _g = ENV_LOCK.lock();
280278
os_imp::unsetenv(k.as_ref())
281279
}

branches/try/src/libstd/sync/rwlock.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,16 @@ impl<T: ?Sized> RwLock<T> {
171171
RwLockReadGuard::new(&*self.inner, &self.data)
172172
}
173173

174-
/// Attempts to acquire this lock with shared read access.
174+
/// Attempts to acquire this rwlock with shared read access.
175+
///
176+
/// If the access could not be granted at this time, then `Err` is returned.
177+
/// Otherwise, an RAII guard is returned which will release the shared access
178+
/// when it is dropped.
175179
///
176-
/// This function will never block and will return immediately if `read`
177-
/// would otherwise succeed. Returns `Some` of an RAII guard which will
178-
/// release the shared access of this thread when dropped, or `None` if the
179-
/// access could not be granted. This method does not provide any
180-
/// guarantees with respect to the ordering of whether contentious readers
181-
/// or writers will acquire the lock first.
180+
/// This function does not block.
181+
///
182+
/// This function does not provide any guarantees with respect to the ordering
183+
/// of whether contentious readers or writers will acquire the lock first.
182184
///
183185
/// # Failure
184186
///
@@ -219,9 +221,14 @@ impl<T: ?Sized> RwLock<T> {
219221

220222
/// Attempts to lock this rwlock with exclusive write access.
221223
///
222-
/// This function does not ever block, and it will return `None` if a call
223-
/// to `write` would otherwise block. If successful, an RAII guard is
224-
/// returned.
224+
/// If the lock could not be acquired at this time, then `Err` is returned.
225+
/// Otherwise, an RAII guard is returned which will release the lock when
226+
/// it is dropped.
227+
///
228+
/// This function does not block.
229+
///
230+
/// This function does not provide any guarantees with respect to the ordering
231+
/// of whether contentious readers or writers will acquire the lock first.
225232
///
226233
/// # Failure
227234
///
@@ -232,7 +239,7 @@ impl<T: ?Sized> RwLock<T> {
232239
#[inline]
233240
#[stable(feature = "rust1", since = "1.0.0")]
234241
pub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<T>> {
235-
if unsafe { self.inner.lock.try_read() } {
242+
if unsafe { self.inner.lock.try_write() } {
236243
Ok(try!(RwLockWriteGuard::new(&*self.inner, &self.data)))
237244
} else {
238245
Err(TryLockError::WouldBlock)
@@ -413,7 +420,7 @@ mod tests {
413420
use rand::{self, Rng};
414421
use sync::mpsc::channel;
415422
use thread;
416-
use sync::{Arc, RwLock, StaticRwLock, RW_LOCK_INIT};
423+
use sync::{Arc, RwLock, StaticRwLock, TryLockError, RW_LOCK_INIT};
417424

418425
#[test]
419426
fn smoke() {
@@ -577,4 +584,21 @@ mod tests {
577584
let comp: &[i32] = &[4, 2, 5];
578585
assert_eq!(&*rw.read().unwrap(), comp);
579586
}
587+
588+
#[test]
589+
fn test_rwlock_try_write() {
590+
use mem::drop;
591+
592+
let lock = RwLock::new(0isize);
593+
let read_guard = lock.read().unwrap();
594+
595+
let write_result = lock.try_write();
596+
match write_result {
597+
Err(TryLockError::WouldBlock) => (),
598+
Ok(_) => assert!(false, "try_write should not succeed while read_guard is in scope"),
599+
Err(_) => assert!(false, "unexpected error"),
600+
}
601+
602+
drop(read_guard);
603+
}
580604
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn f<F, R>(_: F) where F: Fn() -> R {
12+
}
13+
14+
fn main() {
15+
f(|| -> ! { () });
16+
//~^ ERROR: computation may converge in a function marked as diverging [E0270]
17+
}

0 commit comments

Comments
 (0)