]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #32462 - tclfs:patch-1, r=steveklabnik
authorSteve Klabnik <steve@steveklabnik.com>
Thu, 24 Mar 2016 14:37:24 +0000 (10:37 -0400)
committerSteve Klabnik <steve@steveklabnik.com>
Thu, 24 Mar 2016 14:37:24 +0000 (10:37 -0400)
Docs: some tiny corrections

TNT->`tnt`
firecracker->`firecracker`

src/libcore/clone.rs
src/libstd/io/stdio.rs
src/libstd/time/mod.rs
src/libsyntax/errors/json.rs
src/test/run-make/json-errors/Makefile

index b1f63ad71ca3740d1989c7bdfbe96fbb00edb583..a793502e58d371e440d4743c1f54dced7f3d6331 100644 (file)
 //! them cheap and safe to copy. For other types copies must be made
 //! explicitly, by convention implementing the `Clone` trait and calling
 //! the `clone` method.
+//!
+//! Basic usage example:
+//!
+//! ```
+//! let s = String::new(); // String type implements Clone
+//! let copy = s.clone(); // so we can clone it
+//! ```
+//!
+//! To easily implement the Clone trait, you can also use
+//! `#[derive(Clone)]`. Example:
+//!
+//! ```
+//! #[derive(Clone)] // we add the Clone trait to Morpheus struct
+//! struct Morpheus {
+//!    blue_pill: f32,
+//!    red_pill: i64,
+//! }
+//!
+//! fn main() {
+//!    let f = Morpheus { blue_pill: 0.0, red_pill: 0 };
+//!    let copy = f.clone(); // and now we can clone it!
+//! }
+//! ```
 
 #![stable(feature = "rust1", since = "1.0.0")]
 
index e1a388c38c45334272b1bbdfbfc61f422ef37af2..c4b573db5f2dd41b44f4179cba30e5680ed88cfe 100644 (file)
@@ -141,8 +141,8 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
 ///
 /// Each handle is a shared reference to a global buffer of input data to this
 /// process. A handle can be `lock`'d to gain full access to [`BufRead`] methods
-/// (e.g. `.lines()`). Writes to this handle are otherwise locked with respect
-/// to other writes.
+/// (e.g. `.lines()`). Reads to this handle are otherwise locked with respect
+/// to other reads.
 ///
 /// This handle implements the `Read` trait, but beware that concurrent reads
 /// of `Stdin` must be executed with care.
index aa0a843dc9a548763d6a713538e39fbe7659f9d3..0c32feebecbca2be00439c029c41e9dc981509a0 100644 (file)
@@ -9,6 +9,16 @@
 // except according to those terms.
 
 //! Temporal quantification.
+//!
+//! Example:
+//!
+//! ```
+//! use std::time::Duration;
+//!
+//! let five_seconds = Duration::new(5, 0);
+//! // both declarations are equivalent
+//! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
+//! ```
 
 #![stable(feature = "time", since = "1.3.0")]
 
 /// no method to get "the number of seconds" from an instant. Instead, it only
 /// allows measuring the duration between two instants (or comparing two
 /// instants).
+///
+/// Example:
+///
+/// ```no_run
+/// use std::time::{Duration, Instant};
+/// use std::thread::sleep;
+///
+/// fn main() {
+///    let now = Instant::now();
+///
+///    // we sleep for 2 seconds
+///    sleep(Duration::new(2, 0));
+///    // it prints '2'
+///    println!("{}", now.elapsed().as_secs());
+/// }
+/// ```
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
 #[stable(feature = "time2", since = "1.8.0")]
 pub struct Instant(time::Instant);
 /// information about a `SystemTime`. By calculating the duration from this
 /// fixed point in time, a `SystemTime` can be converted to a human-readable time,
 /// or perhaps some other string representation.
+///
+/// Example:
+///
+/// ```no_run
+/// use std::time::{Duration, SystemTime};
+/// use std::thread::sleep;
+///
+/// fn main() {
+///    let now = SystemTime::now();
+///
+///    // we sleep for 2 seconds
+///    sleep(Duration::new(2, 0));
+///    match now.elapsed() {
+///        Ok(elapsed) => {
+///            // it prints '2'
+///            println!("{}", elapsed.as_secs());
+///        }
+///        Err(e) => {
+///            // an error occured!
+///            println!("Error: {:?}", e);
+///        }
+///    }
+/// }
+/// ```
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
 #[stable(feature = "time2", since = "1.8.0")]
 pub struct SystemTime(time::SystemTime);
index 5bb5f4757e013ad729d8cd389687e560254784d1..212a54447a8610d8ca95436b690487fd6acc923c 100644 (file)
@@ -20,7 +20,7 @@
 // FIXME spec the JSON output properly.
 
 
-use codemap::{MultiSpan, CodeMap};
+use codemap::{Span, MultiSpan, CodeMap};
 use diagnostics::registry::Registry;
 use errors::{Level, DiagnosticBuilder, SubDiagnostic, RenderSpan, CodeSuggestion};
 use errors::emitter::Emitter;
@@ -99,6 +99,16 @@ struct DiagnosticSpan {
     /// 1-based, character offset.
     column_start: usize,
     column_end: usize,
+    /// Source text from the start of line_start to the end of line_end.
+    text: Vec<DiagnosticSpanLine>,
+}
+
+#[derive(RustcEncodable)]
+struct DiagnosticSpanLine {
+    text: String,
+    /// 1-based, character offset in self.text.
+    highlight_start: usize,
+    highlight_end: usize,
 }
 
 #[derive(RustcEncodable)]
@@ -180,6 +190,7 @@ fn from_multispan(msp: &MultiSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
                 line_end: end.line,
                 column_start: start.col.0 + 1,
                 column_end: end.col.0 + 1,
+                text: DiagnosticSpanLine::from_span(span, je),
             }
         }).collect()
     }
@@ -202,6 +213,7 @@ fn from_render_span(rsp: &RenderSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
                         line_end: end.line,
                         column_start: 0,
                         column_end: end.col.0 + 1,
+                        text: DiagnosticSpanLine::from_span(span, je),
                     }
                 }).collect()
             }
@@ -217,6 +229,7 @@ fn from_render_span(rsp: &RenderSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
                         line_end: end.line,
                         column_start: 0,
                         column_end: 0,
+                        text: DiagnosticSpanLine::from_span(span, je),
                     }
                 }).collect()
             }
@@ -224,6 +237,31 @@ fn from_render_span(rsp: &RenderSpan, je: &JsonEmitter) -> Vec<DiagnosticSpan> {
     }
 }
 
+impl DiagnosticSpanLine {
+    fn from_span(span: &Span, je: &JsonEmitter) -> Vec<DiagnosticSpanLine> {
+        let lines = match je.cm.span_to_lines(*span) {
+            Ok(lines) => lines,
+            Err(_) => {
+                debug!("unprintable span");
+                return Vec::new();
+            }
+        };
+
+        let mut result = Vec::new();
+        let fm = &*lines.file;
+
+        for line in &lines.lines {
+            result.push(DiagnosticSpanLine {
+                text: fm.get_line(line.line_index).unwrap().to_owned(),
+                highlight_start: line.start_col.0 + 1,
+                highlight_end: line.end_col.0 + 1,
+            });
+        }
+
+        result
+    }
+}
+
 impl DiagnosticCode {
     fn map_opt_string(s: Option<String>, je: &JsonEmitter) -> Option<DiagnosticCode> {
         s.map(|s| {
index bf97f12055550e718052c939770180f7a5641889..cd3a2af30ab8fa62be91200080adea59307ae39d 100644 (file)
@@ -6,5 +6,5 @@ all:
        cp foo.rs $(TMPDIR)
        cd $(TMPDIR)
        -$(RUSTC) -Z unstable-options --error-format=json foo.rs 2>$(LOG)
-       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)
-       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)
+       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)
+       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)