Skip to content

Commit dcfb8d7

Browse files
committed
Auto merge of #32465 - steveklabnik:rollup, r=steveklabnik
Rollup of 6 pull requests - Successful merges: #32276, #32416, #32452, #32459, #32462, #32464 - Failed merges:
2 parents dc1f683 + b2dfb7c commit dcfb8d7

File tree

7 files changed

+120
-13
lines changed

7 files changed

+120
-13
lines changed

src/doc/book/drop.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ BOOM times 100!!!
5555
BOOM times 1!!!
5656
```
5757

58-
The TNT goes off before the firecracker does, because it was declared
58+
The `tnt` goes off before the `firecracker` does, because it was declared
5959
afterwards. Last in, first out.
6060

6161
So what is `Drop` good for? Generally, `Drop` is used to clean up any resources

src/libcore/clone.rs

+23
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@
1818
//! them cheap and safe to copy. For other types copies must be made
1919
//! explicitly, by convention implementing the `Clone` trait and calling
2020
//! the `clone` method.
21+
//!
22+
//! Basic usage example:
23+
//!
24+
//! ```
25+
//! let s = String::new(); // String type implements Clone
26+
//! let copy = s.clone(); // so we can clone it
27+
//! ```
28+
//!
29+
//! To easily implement the Clone trait, you can also use
30+
//! `#[derive(Clone)]`. Example:
31+
//!
32+
//! ```
33+
//! #[derive(Clone)] // we add the Clone trait to Morpheus struct
34+
//! struct Morpheus {
35+
//! blue_pill: f32,
36+
//! red_pill: i64,
37+
//! }
38+
//!
39+
//! fn main() {
40+
//! let f = Morpheus { blue_pill: 0.0, red_pill: 0 };
41+
//! let copy = f.clone(); // and now we can clone it!
42+
//! }
43+
//! ```
2144
2245
#![stable(feature = "rust1", since = "1.0.0")]
2346

src/libcore/option.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,12 @@
9393
//! let msg = Some("howdy");
9494
//!
9595
//! // Take a reference to the contained string
96-
//! match msg {
97-
//! Some(ref m) => println!("{}", *m),
98-
//! None => (),
96+
//! if let Some(ref m) = msg {
97+
//! println!("{}", *m);
9998
//! }
10099
//!
101100
//! // Remove the contained string, destroying the Option
102-
//! let unwrapped_msg = match msg {
103-
//! Some(m) => m,
104-
//! None => "default message",
105-
//! };
101+
//! let unwrapped_msg = msg.unwrap_or("default message");
106102
//! ```
107103
//!
108104
//! Initialize a result to `None` before a loop:

src/libstd/io/stdio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
141141
///
142142
/// Each handle is a shared reference to a global buffer of input data to this
143143
/// process. A handle can be `lock`'d to gain full access to [`BufRead`] methods
144-
/// (e.g. `.lines()`). Writes to this handle are otherwise locked with respect
145-
/// to other writes.
144+
/// (e.g. `.lines()`). Reads to this handle are otherwise locked with respect
145+
/// to other reads.
146146
///
147147
/// This handle implements the `Read` trait, but beware that concurrent reads
148148
/// of `Stdin` must be executed with care.

src/libstd/time/mod.rs

+50
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
// except according to those terms.
1010

1111
//! Temporal quantification.
12+
//!
13+
//! Example:
14+
//!
15+
//! ```
16+
//! use std::time::Duration;
17+
//!
18+
//! let five_seconds = Duration::new(5, 0);
19+
//! // both declarations are equivalent
20+
//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
21+
//! ```
1222
1323
#![stable(feature = "time", since = "1.3.0")]
1424

@@ -40,6 +50,22 @@ mod duration;
4050
/// no method to get "the number of seconds" from an instant. Instead, it only
4151
/// allows measuring the duration between two instants (or comparing two
4252
/// instants).
53+
///
54+
/// Example:
55+
///
56+
/// ```no_run
57+
/// use std::time::{Duration, Instant};
58+
/// use std::thread::sleep;
59+
///
60+
/// fn main() {
61+
/// let now = Instant::now();
62+
///
63+
/// // we sleep for 2 seconds
64+
/// sleep(Duration::new(2, 0));
65+
/// // it prints '2'
66+
/// println!("{}", now.elapsed().as_secs());
67+
/// }
68+
/// ```
4369
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
4470
#[stable(feature = "time2", since = "1.8.0")]
4571
pub struct Instant(time::Instant);
@@ -63,6 +89,30 @@ pub struct Instant(time::Instant);
6389
/// information about a `SystemTime`. By calculating the duration from this
6490
/// fixed point in time, a `SystemTime` can be converted to a human-readable time,
6591
/// or perhaps some other string representation.
92+
///
93+
/// Example:
94+
///
95+
/// ```no_run
96+
/// use std::time::{Duration, SystemTime};
97+
/// use std::thread::sleep;
98+
///
99+
/// fn main() {
100+
/// let now = SystemTime::now();
101+
///
102+
/// // we sleep for 2 seconds
103+
/// sleep(Duration::new(2, 0));
104+
/// match now.elapsed() {
105+
/// Ok(elapsed) => {
106+
/// // it prints '2'
107+
/// println!("{}", elapsed.as_secs());
108+
/// }
109+
/// Err(e) => {
110+
/// // an error occured!
111+
/// println!("Error: {:?}", e);
112+
/// }
113+
/// }
114+
/// }
115+
/// ```
66116
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
67117
#[stable(feature = "time2", since = "1.8.0")]
68118
pub struct SystemTime(time::SystemTime);

src/libsyntax/errors/json.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// FIXME spec the JSON output properly.
2121

2222

23-
use codemap::{MultiSpan, CodeMap};
23+
use codemap::{Span, MultiSpan, CodeMap};
2424
use diagnostics::registry::Registry;
2525
use errors::{Level, DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion};
2626
use errors::emitter::Emitter;
@@ -99,6 +99,16 @@ struct DiagnosticSpan {
9999
/// 1-based, character offset.
100100
column_start: usize,
101101
column_end: usize,
102+
/// Source text from the start of line_start to the end of line_end.
103+
text: Vec<DiagnosticSpanLine>,
104+
}
105+
106+
#[derive(RustcEncodable)]
107+
struct DiagnosticSpanLine {
108+
text: String,
109+
/// 1-based, character offset in self.text.
110+
highlight_start: usize,
111+
highlight_end: usize,
102112
}
103113

104114
#[derive(RustcEncodable)]
@@ -180,6 +190,7 @@ impl DiagnosticSpan {
180190
line_end: end.line,
181191
column_start: start.col.0 + 1,
182192
column_end: end.col.0 + 1,
193+
text: DiagnosticSpanLine::from_span(span, je),
183194
}
184195
}).collect()
185196
}
@@ -202,6 +213,7 @@ impl DiagnosticSpan {
202213
line_end: end.line,
203214
column_start: 0,
204215
column_end: end.col.0 + 1,
216+
text: DiagnosticSpanLine::from_span(span, je),
205217
}
206218
}).collect()
207219
}
@@ -217,13 +229,39 @@ impl DiagnosticSpan {
217229
line_end: end.line,
218230
column_start: 0,
219231
column_end: 0,
232+
text: DiagnosticSpanLine::from_span(span, je),
220233
}
221234
}).collect()
222235
}
223236
}
224237
}
225238
}
226239

240+
impl DiagnosticSpanLine {
241+
fn from_span(span: &Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> {
242+
let lines = match je.cm.span_to_lines(*span) {
243+
Ok(lines) => lines,
244+
Err(_) => {
245+
debug!("unprintable span");
246+
return Vec::new();
247+
}
248+
};
249+
250+
let mut result = Vec::new();
251+
let fm = &*lines.file;
252+
253+
for line in &lines.lines {
254+
result.push(DiagnosticSpanLine {
255+
text: fm.get_line(line.line_index).unwrap().to_owned(),
256+
highlight_start: line.start_col.0 + 1,
257+
highlight_end: line.end_col.0 + 1,
258+
});
259+
}
260+
261+
result
262+
}
263+
}
264+
227265
impl DiagnosticCode {
228266
fn map_opt_string(s: Option<String>, je: &JsonEmitter) -> Option<DiagnosticCode> {
229267
s.map(|s| {

src/test/run-make/json-errors/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ all:
66
cp foo.rs $(TMPDIR)
77
cd $(TMPDIR)
88
-$(RUSTC) -Z unstable-options --error-format=json foo.rs 2>$(LOG)
9-
grep -q '{"message":"unresolved name `y`","code":{"code":"E0425","explanation":"\\nAn unresolved name was used. Example of erroneous codes.*"},"level":"error","spans":\[{"file_name":"foo.rs","byte_start":496,"byte_end":497,"line_start":12,"line_end":12,"column_start":18,"column_end":19}\],"children":\[\]}' $(LOG)
10-
grep -q '{"message":".*","code":{"code":"E0277","explanation":"\\nYou tried.*"},"level":"error","spans":\[{.*}\],"children":\[{"message":"the .*","code":null,"level":"help","spans":\[{"file_name":"foo.rs","byte_start":504,"byte_end":516,"line_start":14,"line_end":14,"column_start":0,"column_end":0}\],"children":\[\]},{"message":" <u8 as core::ops::Add>","code":null,"level":"help",' $(LOG)
9+
grep -q '{"message":"unresolved name `y`","code":{"code":"E0425","explanation":"\\nAn unresolved name was used. Example of erroneous codes.*"},"level":"error","spans":\[{"file_name":"foo.rs","byte_start":496,"byte_end":497,"line_start":12,"line_end":12,"column_start":18,"column_end":19,"text":\[{"text":" let x = 42 + y;","highlight_start":18,"highlight_end":19}\]}\],"children":\[\]}' $(LOG)
10+
grep -q '{"message":".*","code":{"code":"E0277","explanation":"\\nYou tried.*"},"level":"error","spans":\[{.*}\],"children":\[{"message":"the .*","code":null,"level":"help","spans":\[{"file_name":"foo.rs","byte_start":504,"byte_end":516,"line_start":14,"line_end":14,"column_start":0,"column_end":0,"text":\[{.*}\]}\],"children":\[\]},{"message":" <u8 as core::ops::Add>","code":null,"level":"help",' $(LOG)

0 commit comments

Comments
 (0)