From d14109ec7e90f42a7cb966415b96094b146d3706 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Tue, 14 Apr 2015 15:36:38 +0200 Subject: [PATCH 01/24] Add "trace-macros" as a compiler flag Fixes #22619 --- src/librustc/session/config.rs | 4 +++- src/librustc_driver/driver.rs | 1 + src/libsyntax/ext/base.rs | 6 ++---- src/libsyntax/ext/expand.rs | 2 ++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index a7d608d2c87..47049969f0c 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -606,6 +606,8 @@ fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool { "Force overflow checks on or off"), force_dropflag_checks: Option = (None, parse_opt_bool, "Force drop flag checks on or off"), + trace_macros: bool = (false, parse_bool, + "For every macro invocation, print its name and arguments"), } pub fn default_lib_output() -> CrateType { @@ -667,7 +669,7 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config { Ok(t) => t, Err(e) => { sp.handler().fatal(&format!("Error loading target specification: {}", e)); - } + } }; let (int_type, uint_type) = match &target.target_pointer_width[..] { diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index e310798b20a..f7815a58d06 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -482,6 +482,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, crate_name: crate_name.to_string(), features: Some(&features), recursion_limit: sess.recursion_limit.get(), + trace_mac: sess.opt.debugging_opts.trace_macros, }; let ret = syntax::ext::expand::expand_crate(&sess.parse_sess, cfg, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 9994fad3e31..9c2837d71ff 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -554,7 +554,6 @@ pub struct ExtCtxt<'a> { pub use_std: bool, pub mod_path: Vec , - pub trace_mac: bool, pub exported_macros: Vec, pub syntax_env: SyntaxEnv, @@ -572,7 +571,6 @@ pub fn new(parse_sess: &'a parse::ParseSess, cfg: ast::CrateConfig, mod_path: Vec::new(), ecfg: ecfg, use_std: true, - trace_mac: false, exported_macros: Vec::new(), syntax_env: env, recursion_count: 0, @@ -732,10 +730,10 @@ pub fn bug(&self, msg: &str) -> ! { self.parse_sess.span_diagnostic.handler().bug(msg); } pub fn trace_macros(&self) -> bool { - self.trace_mac + self.ecfg.trace_mac } pub fn set_trace_macros(&mut self, x: bool) { - self.trace_mac = x + self.ecfg.trace_mac = x } pub fn ident_of(&self, st: &str) -> ast::Ident { str_to_ident(st) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index b65798b8a49..c8ff08eeb94 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1406,6 +1406,7 @@ pub struct ExpansionConfig<'feat> { pub crate_name: String, pub features: Option<&'feat Features>, pub recursion_limit: usize, + pub trace_mac: bool, } macro_rules! feature_tests { @@ -1427,6 +1428,7 @@ pub fn default(crate_name: String) -> ExpansionConfig<'static> { crate_name: crate_name, features: None, recursion_limit: 64, + trace_mac: false, } } From bed2d33523be222195aff71bb813eb14a1faef97 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Tue, 14 Apr 2015 15:40:10 +0200 Subject: [PATCH 02/24] Add "run-make" test for trace-macros flag --- src/test/run-make/trace-macros-flag/Makefile | 9 +++++++++ src/test/run-make/trace-macros-flag/hello.rs | 13 +++++++++++++ src/test/run-make/trace-macros-flag/hello.trace | 2 ++ 3 files changed, 24 insertions(+) create mode 100644 src/test/run-make/trace-macros-flag/Makefile create mode 100644 src/test/run-make/trace-macros-flag/hello.rs create mode 100644 src/test/run-make/trace-macros-flag/hello.trace diff --git a/src/test/run-make/trace-macros-flag/Makefile b/src/test/run-make/trace-macros-flag/Makefile new file mode 100644 index 00000000000..fc49c8c900c --- /dev/null +++ b/src/test/run-make/trace-macros-flag/Makefile @@ -0,0 +1,9 @@ +# This test verifies that "-Z trace-macros" works as it should. The traditional +# "hello world" program provides a small example of this as not only println! is +# listed, but also print! (since println! expands to this) + +-include ../tools.mk + +all: + $(RUSTC) -o $(TMPDIR)/hello -Z trace-macros hello.rs &> $(TMPDIR)/hello.trace + diff -u $(TMPDIR)/hello.trace hello.trace diff --git a/src/test/run-make/trace-macros-flag/hello.rs b/src/test/run-make/trace-macros-flag/hello.rs new file mode 100644 index 00000000000..42d3d4c799d --- /dev/null +++ b/src/test/run-make/trace-macros-flag/hello.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + println!("Hello, World!"); +} diff --git a/src/test/run-make/trace-macros-flag/hello.trace b/src/test/run-make/trace-macros-flag/hello.trace new file mode 100644 index 00000000000..cf733339ead --- /dev/null +++ b/src/test/run-make/trace-macros-flag/hello.trace @@ -0,0 +1,2 @@ +println! { "Hello, World!" } +print! { concat ! ( "Hello, World!" , "\n" ) } From 35b49fe20604ee840246123acd44cf2f9a04ab08 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Tue, 14 Apr 2015 22:18:24 +0200 Subject: [PATCH 03/24] Fix: sess.opt should have been sess.opts --- src/librustc_driver/driver.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index f7815a58d06..f93c543543c 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -482,7 +482,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, crate_name: crate_name.to_string(), features: Some(&features), recursion_limit: sess.recursion_limit.get(), - trace_mac: sess.opt.debugging_opts.trace_macros, + trace_mac: sess.opts.debugging_opts.trace_macros, }; let ret = syntax::ext::expand::expand_crate(&sess.parse_sess, cfg, From 5e1505f82396d696fd11b28c2aae5b01c14ed3f9 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Tue, 14 Apr 2015 23:43:09 +0200 Subject: [PATCH 04/24] Remove -o flag from build command It generates a warning that --outdir argument is ignored, which is captured and spoils the output Also ensure that test output is captured in a different file than the expected output file --- src/test/run-make/trace-macros-flag/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/trace-macros-flag/Makefile b/src/test/run-make/trace-macros-flag/Makefile index fc49c8c900c..4dfa238413d 100644 --- a/src/test/run-make/trace-macros-flag/Makefile +++ b/src/test/run-make/trace-macros-flag/Makefile @@ -5,5 +5,5 @@ -include ../tools.mk all: - $(RUSTC) -o $(TMPDIR)/hello -Z trace-macros hello.rs &> $(TMPDIR)/hello.trace + $(RUSTC) -Z trace-macros hello.rs &> $(TMPDIR)/hello.trace diff -u $(TMPDIR)/hello.trace hello.trace From 53b7a06fafd00627d721d168bc993152a0f265c8 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 15 Apr 2015 09:52:08 +0200 Subject: [PATCH 05/24] Remove one allocation for the file path in file opening Fixes #22190. --- src/libstd/fs.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 914830d9dcf..a92ef2a2aef 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -51,7 +51,6 @@ #[stable(feature = "rust1", since = "1.0.0")] pub struct File { inner: fs_imp::File, - path: Option, } /// Metadata information about a file. @@ -193,12 +192,12 @@ pub fn create>(path: P) -> io::Result { OpenOptions::new().write(true).create(true).truncate(true).open(path) } - /// Returns the original path that was used to open this file. + /// Returns `None`. #[unstable(feature = "file_path", - reason = "this abstraction is imposed by this library instead \ - of the underlying OS and may be removed")] + reason = "this abstraction was imposed by this library and was removed")] + #[deprecated(since = "1.0.0", reason = "abstraction was removed")] pub fn path(&self) -> Option<&Path> { - self.path.as_ref().map(|p| &**p) + None } /// Attempt to sync all OS-internal metadata to disk. @@ -302,7 +301,7 @@ fn as_inner(&self) -> &fs_imp::File { &self.inner } } impl FromInner for File { fn from_inner(f: fs_imp::File) -> File { - File { inner: f, path: None } + File { inner: f } } } @@ -470,7 +469,7 @@ pub fn create(&mut self, create: bool) -> &mut OpenOptions { pub fn open>(&self, path: P) -> io::Result { let path = path.as_ref(); let inner = try!(fs_imp::File::open(path, &self.0)); - Ok(File { path: Some(path.to_path_buf()), inner: inner }) + Ok(File { inner: inner }) } } From 9891ea74d6f706cf38e91599f1e65816977cefdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20Ochagav=C3=ADa?= Date: Wed, 15 Apr 2015 11:17:58 +0200 Subject: [PATCH 06/24] Implement traits for parser error structs Implement `Debug`, `Display` and `Error` for `FatalError` and `ExplicitBug` --- src/libsyntax/diagnostic.rs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index f3715d765e3..e9af6c00995 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -13,17 +13,14 @@ pub use self::ColorConfig::*; use self::Destination::*; -use codemap::{COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span}; -use codemap; +use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span}; use diagnostics; use std::cell::{RefCell, Cell}; -use std::cmp; -use std::fmt; +use std::{cmp, error, fmt}; use std::io::prelude::*; use std::io; -use term::WriterWrapper; -use term; +use term::{self, WriterWrapper}; use libc; /// maximum number of lines we will print for each error; arbitrary. @@ -83,15 +80,39 @@ fn custom_emit(&mut self, cm: &codemap::CodeMap, /// Used as a return value to signify a fatal error occurred. (It is also /// used as the argument to panic at the moment, but that will eventually /// not be true.) -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] #[must_use] pub struct FatalError; +impl fmt::Display for FatalError { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "parser fatal error") + } +} + +impl error::Error for FatalError { + fn description(&self) -> &str { + "The parser has encountered a fatal error" + } +} + /// Signifies that the compiler died with an explicit call to `.bug` /// or `.span_bug` rather than a failed assertion, etc. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Debug)] pub struct ExplicitBug; +impl fmt::Display for ExplicitBug { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + write!(f, "parser internal bug") + } +} + +impl error::Error for ExplicitBug { + fn description(&self) -> &str { + "The parser has encountered an internal bug" + } +} + /// A span-handler is like a handler but also /// accepts span information for source-location /// reporting. From 3a203636e9f5c40cd8117b006ffa732f894c734c Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Wed, 15 Apr 2015 21:47:33 +0200 Subject: [PATCH 07/24] Make sure to disambiguate obtained out from expected output --- src/test/run-make/trace-macros-flag/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/run-make/trace-macros-flag/Makefile b/src/test/run-make/trace-macros-flag/Makefile index 4dfa238413d..88a52773c01 100644 --- a/src/test/run-make/trace-macros-flag/Makefile +++ b/src/test/run-make/trace-macros-flag/Makefile @@ -5,5 +5,5 @@ -include ../tools.mk all: - $(RUSTC) -Z trace-macros hello.rs &> $(TMPDIR)/hello.trace - diff -u $(TMPDIR)/hello.trace hello.trace + $(RUSTC) -Z trace-macros hello.rs &> $(TMPDIR)/hello.out + diff -u $(TMPDIR)/hello.out hello.trace From c1f6d6a13633d71845a84ffbe3709057be4e437c Mon Sep 17 00:00:00 2001 From: Luke Gallagher Date: Thu, 16 Apr 2015 17:18:29 +1000 Subject: [PATCH 08/24] Fix some documentation typos --- src/doc/reference.md | 6 +++--- src/libsyntax/feature_gate.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 0ed23dae9b5..3b3c4ea6412 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2368,7 +2368,7 @@ The currently implemented features of the reference compiler are: removed entirely for something more wholesome. * `custom_attribute` - Allows the usage of attributes unknown to the compiler - so that new attributes can be added in a bacwards compatible + so that new attributes can be added in a backwards compatible manner (RFC 572). * `custom_derive` - Allows the use of `#[derive(Foo,Bar)]` as sugar for @@ -2397,7 +2397,7 @@ The currently implemented features of the reference compiler are: nasty hack that will certainly be removed. * `main` - Allows use of the `#[main]` attribute, which changes the entry point - into a Rust program. This capabiilty is subject to change. + into a Rust program. This capability is subject to change. * `macro_reexport` - Allows macros to be re-exported from one crate after being imported from another. This feature was originally designed with the sole @@ -2453,7 +2453,7 @@ The currently implemented features of the reference compiler are: is unintuitive and suboptimal. * `start` - Allows use of the `#[start]` attribute, which changes the entry point - into a Rust program. This capabiilty, especially the signature for the + into a Rust program. This capability, especially the signature for the annotated function, is subject to change. * `struct_inherit` - Allows using struct inheritance, which is barely diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 659eb343232..d0975c76e93 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -10,7 +10,7 @@ //! Feature gating //! -//! This modules implements the gating necessary for preventing certain compiler +//! This module implements the gating necessary for preventing certain compiler //! features from being used by default. This module will crawl a pre-expanded //! AST to ensure that there are no features which are used that are not //! enabled. From 709b5e8c89a5cdce911b26d2617f08c481c26341 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Thu, 16 Apr 2015 10:02:22 +0200 Subject: [PATCH 09/24] Fix Debug impl for RangeFull The Debug impl was using quotes, which was inconsistent: => (.., 1.., 2..3, ..4) ("..", 1.., 2..3, ..4) Fix to use just .. --- src/libcore/ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 00039c4fcdf..adfbd14121f 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -969,7 +969,7 @@ pub trait IndexMut: Index { #[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for RangeFull { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt("..", fmt) + write!(fmt, "..") } } From 7d56fb214938c6e5334789c7ee37c08db417090b Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Thu, 16 Apr 2015 17:35:33 +0800 Subject: [PATCH 10/24] Fix link id for stackoverflow The document does not display properly if the link id contains a space. --- src/doc/trpl/installing-rust.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/installing-rust.md b/src/doc/trpl/installing-rust.md index 09b4495ffe9..58d9e57dc51 100644 --- a/src/doc/trpl/installing-rust.md +++ b/src/doc/trpl/installing-rust.md @@ -91,9 +91,9 @@ If not, there are a number of places where you can get help. The easiest is [Mibbit][mibbit]. Click that link, and you'll be chatting with other Rustaceans (a silly nickname we call ourselves), and we can help you out. Other great resources include [the user’s forum][users], and -[Stack Overflow][stack overflow]. +[Stack Overflow][stackoverflow]. [irc]: irc://irc.mozilla.org/#rust [mibbit]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust [users]: http://users.rust-lang.org/ -[stack overflow]: http://stackoverflow.com/questions/tagged/rust +[stackoverflow]: http://stackoverflow.com/questions/tagged/rust From 61ad9fe1a3a34d358c3922d77557f626e4a21232 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Thu, 16 Apr 2015 12:14:45 +0200 Subject: [PATCH 11/24] Use BTreeMap in build_sidebar_items This ensures that later when generating HTML, the JSON will be sorted aswell. We now have a deterministic build of sidebar-items.js --- src/librustdoc/html/render.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 5f4a3e74b65..54fbdc28968 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -37,7 +37,7 @@ use std::ascii::OwnedAsciiExt; use std::cell::RefCell; use std::cmp::Ordering; -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::default::Default; use std::fmt; use std::fs::{self, File}; @@ -1319,8 +1319,9 @@ fn render(w: File, cx: &Context, it: &clean::Item, } } - fn build_sidebar_items(&self, m: &clean::Module) -> HashMap> { - let mut map = HashMap::new(); + fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap> { + // BTreeMap instead of HashMap to get a sorted output + let mut map = BTreeMap::new(); for item in &m.items { if self.ignore_private_item(item) { continue } From d40e1cbfd856223fed8a8beb3b20da64965b53c5 Mon Sep 17 00:00:00 2001 From: Aram Visser Date: Thu, 16 Apr 2015 19:21:11 +0700 Subject: [PATCH 12/24] Fixed typo in hash_map::Entry documentation --- src/libstd/collections/hash/map.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index f554a4f4ed6..9b93066f9fb 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1469,7 +1469,6 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> { } impl<'a, K, V> Entry<'a, K, V> { - /// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant. #[unstable(feature = "std_misc", reason = "will soon be replaced by or_insert")] #[deprecated(since = "1.0", From c0139cafcdbe60e446b81dda78f3595fea3e3b8d Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Thu, 16 Apr 2015 14:57:31 +0200 Subject: [PATCH 13/24] Remove `&` from redirected output This seems to fix the test --- src/test/run-make/trace-macros-flag/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/trace-macros-flag/Makefile b/src/test/run-make/trace-macros-flag/Makefile index 88a52773c01..3338e394e0e 100644 --- a/src/test/run-make/trace-macros-flag/Makefile +++ b/src/test/run-make/trace-macros-flag/Makefile @@ -5,5 +5,5 @@ -include ../tools.mk all: - $(RUSTC) -Z trace-macros hello.rs &> $(TMPDIR)/hello.out + $(RUSTC) -Z trace-macros hello.rs > $(TMPDIR)/hello.out diff -u $(TMPDIR)/hello.out hello.trace From f20497ca857e3ef6a63d2abf8fa75569faad4008 Mon Sep 17 00:00:00 2001 From: Florian Hartwig Date: Thu, 16 Apr 2015 15:13:47 +0200 Subject: [PATCH 14/24] Fix some broken links in the book --- src/doc/trpl/concurrency.md | 4 ++-- src/doc/trpl/error-handling.md | 2 +- src/doc/trpl/macros.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/trpl/concurrency.md b/src/doc/trpl/concurrency.md index 159e04e9429..575dfc7417a 100644 --- a/src/doc/trpl/concurrency.md +++ b/src/doc/trpl/concurrency.md @@ -176,8 +176,8 @@ Here's the error: ^~~~~~~~~~~~~ ``` -You see, [`Mutex`](std/sync/struct.Mutex.html) has a -[`lock`](http://doc.rust-lang.org/nightly/std/sync/struct.Mutex.html#method.lock) +You see, [`Mutex`](../std/sync/struct.Mutex.html) has a +[`lock`](../std/sync/struct.Mutex.html#method.lock) method which has this signature: ```ignore diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 491f7b0c2a0..aaa43b33d3b 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -297,5 +297,5 @@ It's worth noting that you can only use `try!` from a function that returns a `Result`, which means that you cannot use `try!` inside of `main()`, because `main()` doesn't return anything. -`try!` makes use of [`From`](../std/convert/trait.From.hml) to determine +`try!` makes use of [`From`](../std/convert/trait.From.html) to determine what to return in the error case. diff --git a/src/doc/trpl/macros.md b/src/doc/trpl/macros.md index 6d21cb59383..713814d9147 100644 --- a/src/doc/trpl/macros.md +++ b/src/doc/trpl/macros.md @@ -33,7 +33,7 @@ mind. You may have seen the `vec!` macro, used to initialize a [vector][] with any number of elements. -[vector]: arrays-vectors-and-slices.html +[vector]: vectors.html ```rust let x: Vec = vec![1, 2, 3]; From 4436ade8ad62619dadd6033f116a831179b238d9 Mon Sep 17 00:00:00 2001 From: Philip Munksgaard Date: Thu, 16 Apr 2015 15:58:43 +0200 Subject: [PATCH 15/24] Add Debug to MethodCallee This fixes #24497 --- src/librustc/middle/ty.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 1e817890440..eab87dc846d 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -437,7 +437,7 @@ pub struct MethodObject<'tcx> { pub vtable_index: usize, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct MethodCallee<'tcx> { pub origin: MethodOrigin<'tcx>, pub ty: Ty<'tcx>, From 1c6ccd96ac4c03411283749687556f4ccbf3bce5 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 16 Apr 2015 11:53:17 -0400 Subject: [PATCH 16/24] Indicate None is code-like in doc comments --- src/libcore/iter.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index e44b0d1147c..16ee3889880 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -179,8 +179,8 @@ fn chain(self, other: U) -> Chain where /// Creates an iterator that iterates over both this and the specified /// iterators simultaneously, yielding the two elements as pairs. When - /// either iterator returns None, all further invocations of next() will - /// return None. + /// either iterator returns `None`, all further invocations of next() will + /// return `None`. /// /// # Examples /// @@ -254,7 +254,7 @@ fn filter

(self, predicate: P) -> Filter where } /// Creates an iterator that both filters and maps elements. - /// If the specified function returns None, the element is skipped. + /// If the specified function returns `None`, the element is skipped. /// Otherwise the option is unwrapped and the new value is yielded. /// /// # Examples @@ -403,7 +403,7 @@ fn take(self, n: usize) -> Take where Self: Sized, { /// Creates a new iterator that behaves in a similar fashion to fold. /// There is a state which is passed between each iteration and can be /// mutated as necessary. The yielded values from the closure are yielded - /// from the Scan instance when not None. + /// from the Scan instance when not `None`. /// /// # Examples /// @@ -701,7 +701,7 @@ fn position

(&mut self, mut predicate: P) -> Option where /// Returns the index of the last element satisfying the specified predicate /// - /// If no element matches, None is returned. + /// If no element matches, `None` is returned. /// /// Does not consume the iterator *before* the first found element. /// From 6de33c22e306505c95cc2f3b775e1a82925560fd Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Thu, 16 Apr 2015 19:53:19 +0200 Subject: [PATCH 17/24] Omit 'obsolete' note for warning if -Awarning --- src/libsyntax/parse/obsolete.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 3b21b5059da..00d9b7f4ea6 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -80,7 +80,8 @@ fn report(&mut self, self.span_warn(sp, &format!("obsolete syntax: {}", kind_str)); } - if !self.obsolete_set.contains(&kind) { + if !self.obsolete_set.contains(&kind) && + (error || self.sess.span_diagnostic.handler().can_emit_warnings) { self.sess .span_diagnostic .handler() From e6f1a4db5fb98407e33bfe33b2bb3debd686047f Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 16 Apr 2015 15:50:24 -0400 Subject: [PATCH 18/24] remove example usage of from_str in error docs Fixes #24185 --- src/doc/trpl/error-handling.md | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 491f7b0c2a0..492514456eb 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -20,18 +20,18 @@ panic. A *failure* is an error that can be recovered from in some way. A *panic* is an error that cannot be recovered from. What do we mean by "recover"? Well, in most cases, the possibility of an error -is expected. For example, consider the `from_str` function: +is expected. For example, consider the `parse` function: -```{rust,ignore} -from_str("5"); +```ignore +"5".parse(); ``` -This function takes a string argument and converts it into another type. But -because it's a string, you can't be sure that the conversion actually works. -For example, what should this convert to? +This method converts a string into another type. But because it's a string, you +can't be sure that the conversion actually works. For example, what should this +convert to? -```{rust,ignore} -from_str("hello5world"); +```ignore +"hello5world".parse(); ``` This won't work. So we know that this function will only work properly for some @@ -40,7 +40,8 @@ inputs. It's expected behavior. We call this kind of error a *failure*. On the other hand, sometimes, there are errors that are unexpected, or which we cannot recover from. A classic example is an `assert!`: -```{rust,ignore} +```rust +# let x = 5; assert!(x == 5); ``` @@ -119,17 +120,19 @@ Rust calls these sorts of errors *panics*. # Handling errors with `Option` and `Result` The simplest way to indicate that a function may fail is to use the `Option` -type. Remember our `from_str()` example? Here's its type signature: +type. For example, the `find` method on strings attempts to find a pattern +in a string, and returns an `Option`: -```{rust,ignore} -pub fn from_str(s: &str) -> Option +```rust +let s = "foo"; + +assert_eq!(s.find('f'), Some(0)); +assert_eq!(s.find('z'), None); ``` -`from_str()` returns an `Option`. If the conversion succeeds, it will return -`Some(value)`, and if it fails, it will return `None`. This is appropriate for the simplest of cases, but doesn't give us a lot of -information in the failure case. What if we wanted to know _why_ the conversion +information in the failure case. What if we wanted to know _why_ the function failed? For this, we can use the `Result` type. It looks like this: ```rust From c776d02d5da30ec4143406384f98852d8c6d0d81 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 16 Apr 2015 15:55:10 -0400 Subject: [PATCH 19/24] Make note of documentation tests and binaries Fixes #24228 --- src/doc/trpl/documentation.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/doc/trpl/documentation.md b/src/doc/trpl/documentation.md index 06071a8f15f..06db6385369 100644 --- a/src/doc/trpl/documentation.md +++ b/src/doc/trpl/documentation.md @@ -380,7 +380,10 @@ $ rustdoc --test path/to/my/crate/root.rs $ cargo test ``` -That's right, `cargo test` tests embedded documentation too. +That's right, `cargo test` tests embedded documentation too. However, +`cargo test` will not test binary crates, only library ones. This is +due to the way `rustdoc` works: it links against the library to be tested, +but with a binary, there’s nothing to link to. There are a few more annotations that are useful to help `rustdoc` do the right thing when testing your code: From dabc4864c07b2c31136b3c861c980c6ff72da11d Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 16 Apr 2015 16:12:47 -0400 Subject: [PATCH 20/24] Descripe tuple indexing in TRPL FIxes #23962 --- src/doc/trpl/primitive-types.md | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/doc/trpl/primitive-types.md b/src/doc/trpl/primitive-types.md index fcbe2b2f8bf..811080cd509 100644 --- a/src/doc/trpl/primitive-types.md +++ b/src/doc/trpl/primitive-types.md @@ -216,6 +216,18 @@ In systems programming languages, strings are a bit more complex than in other languages. For now, just read `&str` as a *string slice*, and we’ll learn more soon. +You can assign one tuple into another, if they have the same contained types +and [arity]. Tuples have the same arity when they have the same length. + +[arity]: glossary.html#arity + +```rust +let mut x = (1, 2); // x: (i32, i32) +let y = (2, 3); // y: (i32, i32) + +x = y; +``` + You can access the fields in a tuple through a *destructuring let*. Here’s an example: @@ -235,20 +247,24 @@ or "breaks up," the tuple, and assigns the bits to three bindings. This pattern is very powerful, and we’ll see it repeated more later. -There are also a few things you can do with a tuple as a whole, without -destructuring. You can assign one tuple into another, if they have the same -contained types and [arity]. Tuples have the same arity when they have the same -length. +## Tuple Indexing + +You can also access fields of a tuple with indexing syntax: -[arity]: glossary.html#arity ```rust -let mut x = (1, 2); // x: (i32, i32) -let y = (2, 3); // y: (i32, i32) +let tuple = (1, 2, 3); -x = y; +let x = tuple.0; +let y = tuple.1; +let z = tuple.2; + +println!("x is {}", x); ``` +Like array indexing, it starts at zero, but unlike array indexing, it uses a +`.`, rather than `[]`s. + You can find more documentation for tuples [in the standard library documentation][tuple]. From 6ac836f229b10d281c034dcf5acfff5003f86fba Mon Sep 17 00:00:00 2001 From: Florian Hartwig Date: Thu, 16 Apr 2015 22:12:13 +0200 Subject: [PATCH 21/24] Fix broken links in the docs --- src/doc/complement-design-faq.md | 4 ++-- src/doc/trpl/closures.md | 6 +++--- src/libcore/raw.rs | 4 ++-- src/libcore/result.rs | 4 ++-- src/librustc/plugin/mod.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/doc/complement-design-faq.md b/src/doc/complement-design-faq.md index 0f2c37a5abf..678c3970fe2 100644 --- a/src/doc/complement-design-faq.md +++ b/src/doc/complement-design-faq.md @@ -56,7 +56,7 @@ Types which are [`Sync`][sync] are thread-safe when multiple shared references to them are used concurrently. Types which are not `Sync` are not thread-safe, and thus when used in a global require unsafe code to use. -[sync]: core/kinds/trait.Sync.html +[sync]: core/marker/trait.Sync.html ### If mutable static items that implement `Sync` are safe, why is taking &mut SHARABLE unsafe? @@ -139,7 +139,7 @@ and explicitly calling the `clone` method. Making user-defined copy operators explicit surfaces the underlying complexity, forcing the developer to opt-in to potentially expensive operations. -[copy]: core/kinds/trait.Copy.html +[copy]: core/marker/trait.Copy.html [clone]: core/clone/trait.Clone.html ## No move constructors diff --git a/src/doc/trpl/closures.md b/src/doc/trpl/closures.md index e63331e5206..e3de8eb30be 100644 --- a/src/doc/trpl/closures.md +++ b/src/doc/trpl/closures.md @@ -205,11 +205,11 @@ you tons of control over what your code does, and closures are no different. Rust's implementation of closures is a bit different than other languages. They are effectively syntax sugar for traits. You'll want to make sure to have read -the [traits chapter][traits] before this one, as well as the chapter on [static -and dynamic dispatch][dispatch], which talks about trait objects. +the [traits chapter][traits] before this one, as well as the chapter on [trait +objects][trait-objects]. [traits]: traits.html -[dispatch]: static-and-dynamic-dispatch.html +[trait-objects]: trait-objects.html Got all that? Good. diff --git a/src/libcore/raw.rs b/src/libcore/raw.rs index ded52ff0778..685b3e5c546 100644 --- a/src/libcore/raw.rs +++ b/src/libcore/raw.rs @@ -71,11 +71,11 @@ fn clone(&self) -> Slice { *self } /// The representation of a trait object like `&SomeTrait`. /// /// This struct has the same layout as types like `&SomeTrait` and -/// `Box`. The [Static and Dynamic Dispatch chapter of the +/// `Box`. The [Trait Objects chapter of the /// Book][moreinfo] contains more details about the precise nature of /// these internals. /// -/// [moreinfo]: ../../book/static-and-dynamic-dispatch.html#representation +/// [moreinfo]: ../../book/trait-objects.html#representation /// /// `TraitObject` is guaranteed to match layouts, but it is not the /// type of trait objects (e.g. the fields are not directly accessible diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 4c74f4646ac..26bc653b26f 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -86,12 +86,12 @@ //! useful value. //! //! Consider the `write_all` method defined for I/O types -//! by the [`Write`](../io/trait.Write.html) trait: +//! by the [`Write`](../../std/io/trait.Write.html) trait: //! //! ``` //! use std::io; //! -//! trait Writer { +//! trait Write { //! fn write_all(&mut self, bytes: &[u8]) -> Result<(), io::Error>; //! } //! ``` diff --git a/src/librustc/plugin/mod.rs b/src/librustc/plugin/mod.rs index 3162c4fc570..4a85e1893f0 100644 --- a/src/librustc/plugin/mod.rs +++ b/src/librustc/plugin/mod.rs @@ -47,7 +47,7 @@ //! #![plugin(myplugin)] //! ``` //! -//! See the [Plugins Chapter](../../book/plugins.html) of the book +//! See the [Plugins Chapter](../../book/compiler-plugins.html) of the book //! for more examples. pub use self::registry::Registry; From d04b2047a7bd1e623875c7af91978a0194f3f2f1 Mon Sep 17 00:00:00 2001 From: Nelo Onyiah Date: Fri, 17 Apr 2015 00:02:17 +0100 Subject: [PATCH 22/24] Update hello-cargo.md --- src/doc/trpl/hello-cargo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/hello-cargo.md b/src/doc/trpl/hello-cargo.md index 8d8b1734334..6967532a447 100644 --- a/src/doc/trpl/hello-cargo.md +++ b/src/doc/trpl/hello-cargo.md @@ -89,7 +89,7 @@ we hadn’t changed the source file, and so it just ran the binary. If we had made a modification, we would have seen it do both: ```bash -$ cargo build +$ cargo run Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world) Running `target/debug/hello_world` Hello, world! From d9515ad40fe24feea4da0a740d9e0cfe0aa3814e Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 16 Apr 2015 23:17:36 -0400 Subject: [PATCH 23/24] Link up some stuff in the vectors chapter Fixes #24070 or rather, fixes it even though it's already been fixed: slices are before now. But the linking is nice anyway. --- src/doc/trpl/vectors.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/vectors.md b/src/doc/trpl/vectors.md index 0dfbfc11913..6fa5917ea99 100644 --- a/src/doc/trpl/vectors.md +++ b/src/doc/trpl/vectors.md @@ -1,13 +1,18 @@ % Vectors A *vector* is a dynamic or "growable" array, implemented as the standard -library type [`Vec`](../std/vec/) (Where `` is a [Generic](./generics.md) statement). Vectors always allocate their data on the heap. Vectors are to slices -what `String` is to `&str`. You can create them with the `vec!` macro: +library type [`Vec`](../std/vec/) (Where `` is a [Generic](./generics.md) +statement). Vectors always allocate their data on the heap. Vectors are to +[slices][slices] what [`String`][string] is to `&str`. You can +create them with the `vec!` macro: ```{rust} let v = vec![1, 2, 3]; // v: Vec ``` +[slices]: primitive-types.html#slices +[string]: strings.html + (Notice that unlike the `println!` macro we've used in the past, we use square brackets `[]` with `vec!`. Rust allows you to use either in either situation, this is just convention.) From c98115cefb1e10b582569404f6142a918f3ccbe5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 17 Apr 2015 15:47:38 +0530 Subject: [PATCH 24/24] Remove info for path (fixup #24452) --- src/librustdoc/html/render.rs | 1 - src/librustdoc/lib.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 250ec34edf7..3f3f8201b00 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1178,7 +1178,6 @@ fn item(&mut self, item: clean::Item, mut f: F) -> io::Result<()> where { fn render(w: File, cx: &Context, it: &clean::Item, pushname: bool) -> io::Result<()> { - info!("Rendering an item to {}", w.path().unwrap().display()); // A little unfortunate that this is done like this, but it sure // does make formatting *a lot* nicer. CURRENT_LOCATION_KEY.with(|slot| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2682bbf4662..e3b429a37d3 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -32,7 +32,6 @@ #![feature(test)] #![feature(unicode)] #![feature(str_words)] -#![feature(file_path)] #![feature(path_ext)] #![feature(path_relative_from)] #![feature(slice_patterns)]