]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #24259 - lstat:needstest, r=alexcrichton
authorManish Goregaokar <manishsmail@gmail.com>
Sat, 11 Apr 2015 13:34:43 +0000 (19:04 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Sat, 11 Apr 2015 13:34:43 +0000 (19:04 +0530)
 Closes #20772
Closes #20939
Closes #21950
Closes #22034

216 files changed:
configure
mk/crates.mk
mk/docs.mk
mk/tests.mk
src/compiletest/common.rs
src/compiletest/compiletest.rs
src/compiletest/runtest.rs
src/doc/trpl/README.md
src/doc/trpl/SUMMARY.md
src/doc/trpl/academic-research.md [new file with mode: 0644]
src/doc/trpl/arrays.md [deleted file]
src/doc/trpl/effective-rust.md
src/doc/trpl/getting-started.md
src/doc/trpl/hello-cargo.md
src/doc/trpl/hello-world.md
src/doc/trpl/installing-rust.md
src/doc/trpl/learn-rust.md
src/doc/trpl/nightly-rust.md
src/doc/trpl/primitive-types.md
src/doc/trpl/slices.md [deleted file]
src/doc/trpl/syntax-and-semantics.md
src/doc/trpl/tuples.md [deleted file]
src/doc/trpl/variable-bindings.md
src/etc/htmldocck.py
src/etc/rustup.sh [deleted file]
src/libcollections/borrow.rs
src/libcore/any.rs
src/libcore/char.rs
src/libcore/convert.rs
src/libcore/fmt/float.rs
src/libcore/fmt/mod.rs
src/libcore/intrinsics.rs
src/libcore/iter.rs
src/libcore/lib.rs
src/libcore/macros.rs
src/libcore/num/mod.rs
src/libcore/ptr.rs
src/libcore/slice.rs
src/libcore/str/mod.rs
src/libcoretest/fmt/float.rs [new file with mode: 0644]
src/libcoretest/iter.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/traits/coherence.rs
src/librustc/middle/traits/util.rs
src/librustc/session/mod.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/diagnostics.rs [new file with mode: 0644]
src/librustc_borrowck/lib.rs
src/librustc_trans/trans/intrinsic.rs
src/librustc_typeck/check/mod.rs
src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/clean/simplify.rs [new file with mode: 0644]
src/librustdoc/core.rs
src/librustdoc/doctree.rs
src/librustdoc/fold.rs
src/librustdoc/html/format.rs
src/librustdoc/html/markdown.rs
src/librustdoc/html/render.rs
src/librustdoc/markdown.rs
src/librustdoc/test.rs
src/librustdoc/visit_ast.rs
src/libstd/collections/hash/set.rs
src/libstd/collections/mod.rs
src/libstd/fs.rs
src/libstd/io/prelude.rs
src/libstd/lib.rs
src/libstd/net/addr.rs
src/libstd/net/tcp.rs
src/libstd/net/udp.rs
src/libstd/num/f32.rs
src/libstd/num/mod.rs
src/libstd/old_io/mod.rs
src/libstd/old_io/net/ip.rs
src/libstd/old_io/net/pipe.rs
src/libstd/old_io/process.rs
src/libstd/old_path/mod.rs
src/libstd/process.rs
src/libstd/sync/mpsc/mod.rs
src/libstd/sys/unix/c.rs
src/libstd/sys/unix/fd.rs
src/libstd/sys/unix/fs2.rs
src/libstd/sys/unix/net.rs
src/libstd/sys/unix/pipe2.rs
src/libstd/sys/unix/process2.rs
src/libstd/sys/windows/pipe2.rs
src/libstd/sys/windows/process2.rs
src/libstd/thread/local.rs
src/libstd/thread/mod.rs
src/libstd/thread/scoped.rs
src/libsyntax/codemap.rs
src/libsyntax/diagnostic.rs
src/libsyntax/ext/base.rs
src/libsyntax/ext/deriving/generic/mod.rs
src/libsyntax/ext/expand.rs
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/util/small_vector.rs
src/rustbook/build.rs
src/rustbook/javascript.rs
src/test/auxiliary/inline-default-methods.rs [new file with mode: 0644]
src/test/auxiliary/issue-13698.rs [new file with mode: 0644]
src/test/auxiliary/issue-15318.rs [new file with mode: 0644]
src/test/auxiliary/issue-17476.rs [new file with mode: 0644]
src/test/auxiliary/issue-20646.rs [new file with mode: 0644]
src/test/auxiliary/issue-20727.rs [new file with mode: 0644]
src/test/auxiliary/issue-21092.rs [new file with mode: 0644]
src/test/auxiliary/issue-21801.rs [new file with mode: 0644]
src/test/auxiliary/issue-22025.rs [new file with mode: 0644]
src/test/auxiliary/issue-23207-1.rs [new file with mode: 0644]
src/test/auxiliary/issue-23207-2.rs [new file with mode: 0644]
src/test/auxiliary/rustdoc-default-impl.rs [new file with mode: 0644]
src/test/auxiliary/rustdoc-extern-default-method.rs [new file with mode: 0644]
src/test/auxiliary/rustdoc-extern-method.rs [new file with mode: 0644]
src/test/auxiliary/rustdoc-ffi.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-escaping-closure-error-1.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-escaping-closure-error-2.rs [new file with mode: 0644]
src/test/compile-fail/coherence-overlap-all-t-and-tuple.rs [new file with mode: 0644]
src/test/compile-fail/issue-16747.rs
src/test/compile-fail/issue-4335.rs
src/test/compile-fail/macro-incomplete-parse.rs
src/test/compile-fail/regions-nested-fns-2.rs
src/test/run-make/issue-22131/foo.rs
src/test/run-make/rustdoc-assoc-types/Makefile [deleted file]
src/test/run-make/rustdoc-assoc-types/lib.rs [deleted file]
src/test/run-make/rustdoc-default-impl/Makefile [deleted file]
src/test/run-make/rustdoc-default-impl/bar.rs [deleted file]
src/test/run-make/rustdoc-default-impl/foo.rs [deleted file]
src/test/run-make/rustdoc-extern-default-method/Makefile [deleted file]
src/test/run-make/rustdoc-extern-default-method/ext.rs [deleted file]
src/test/run-make/rustdoc-extern-default-method/lib.rs [deleted file]
src/test/run-make/rustdoc-extern-method/Makefile [deleted file]
src/test/run-make/rustdoc-extern-method/bar.rs [deleted file]
src/test/run-make/rustdoc-extern-method/foo.rs [deleted file]
src/test/run-make/rustdoc-ffi/Makefile [deleted file]
src/test/run-make/rustdoc-ffi/lib.rs [deleted file]
src/test/run-make/rustdoc-ffi/user.rs [deleted file]
src/test/run-make/rustdoc-hidden-line/Makefile [deleted file]
src/test/run-make/rustdoc-hidden-line/foo.rs [deleted file]
src/test/run-make/rustdoc-must-use/Makefile [deleted file]
src/test/run-make/rustdoc-must-use/lib.rs [deleted file]
src/test/run-make/rustdoc-negative-impl/Makefile [deleted file]
src/test/run-make/rustdoc-negative-impl/foo.rs [deleted file]
src/test/run-make/rustdoc-recursion/Makefile [deleted file]
src/test/run-make/rustdoc-recursion/foo.rs [deleted file]
src/test/run-make/rustdoc-recursion/foo2.rs [deleted file]
src/test/run-make/rustdoc-recursion/foo3.rs [deleted file]
src/test/run-make/rustdoc-search-index/Makefile [deleted file]
src/test/run-make/rustdoc-search-index/index.rs [deleted file]
src/test/run-make/rustdoc-smoke/Makefile [deleted file]
src/test/run-make/rustdoc-smoke/foo.rs [deleted file]
src/test/run-make/rustdoc-src-links/Makefile [deleted file]
src/test/run-make/rustdoc-src-links/foo.rs [deleted file]
src/test/run-make/rustdoc-src-links/qux/mod.rs [deleted file]
src/test/run-make/rustdoc-viewpath-self/Makefile [deleted file]
src/test/run-make/rustdoc-viewpath-self/foo.rs [deleted file]
src/test/run-make/rustdoc-where/Makefile [deleted file]
src/test/run-make/rustdoc-where/foo.rs [deleted file]
src/test/run-pass/discriminant_value.rs [new file with mode: 0644]
src/test/run-pass/fds-are-cloexec.rs [new file with mode: 0644]
src/test/run-pass/fmt-pointer-trait.rs
src/test/run-pass/ifmt.rs
src/test/run-pass/issue-15523-big.rs [new file with mode: 0644]
src/test/run-pass/issue-15523.rs [new file with mode: 0644]
src/test/run-pass/issue-18738.rs
src/test/run-pass/issue-19097.rs [new file with mode: 0644]
src/test/run-pass/issue-21291.rs [new file with mode: 0644]
src/test/run-pass/issue-21400.rs [new file with mode: 0644]
src/test/run-pass/issue-21486.rs [new file with mode: 0644]
src/test/run-pass/macro-nested_stmt_macros.rs [new file with mode: 0644]
src/test/run-pass/macro-stmt_macro_in_expr_macro.rs [new file with mode: 0644]
src/test/run-pass/while-prelude-drop.rs
src/test/rustdoc/assoc-types.rs [new file with mode: 0644]
src/test/rustdoc/default-impl.rs [new file with mode: 0644]
src/test/rustdoc/extern-default-method.rs [new file with mode: 0644]
src/test/rustdoc/extern-method.rs [new file with mode: 0644]
src/test/rustdoc/ffi.rs [new file with mode: 0644]
src/test/rustdoc/hidden-line.rs [new file with mode: 0644]
src/test/rustdoc/inline-default-methods.rs [new file with mode: 0644]
src/test/rustdoc/issue-13698.rs [new file with mode: 0644]
src/test/rustdoc/issue-15169.rs [new file with mode: 0644]
src/test/rustdoc/issue-15318-2.rs [new file with mode: 0644]
src/test/rustdoc/issue-15318-3.rs [new file with mode: 0644]
src/test/rustdoc/issue-15318.rs [new file with mode: 0644]
src/test/rustdoc/issue-15347.rs [new file with mode: 0644]
src/test/rustdoc/issue-16019.rs [new file with mode: 0644]
src/test/rustdoc/issue-16265-1.rs [new file with mode: 0644]
src/test/rustdoc/issue-16265-2.rs [new file with mode: 0644]
src/test/rustdoc/issue-17476.rs [new file with mode: 0644]
src/test/rustdoc/issue-18199.rs [new file with mode: 0644]
src/test/rustdoc/issue-19055.rs [new file with mode: 0644]
src/test/rustdoc/issue-20175.rs [new file with mode: 0644]
src/test/rustdoc/issue-20646.rs [new file with mode: 0644]
src/test/rustdoc/issue-20727-2.rs [new file with mode: 0644]
src/test/rustdoc/issue-20727-3.rs [new file with mode: 0644]
src/test/rustdoc/issue-20727-4.rs [new file with mode: 0644]
src/test/rustdoc/issue-20727.rs [new file with mode: 0644]
src/test/rustdoc/issue-21092.rs [new file with mode: 0644]
src/test/rustdoc/issue-21474.rs [new file with mode: 0644]
src/test/rustdoc/issue-21801.rs [new file with mode: 0644]
src/test/rustdoc/issue-22025.rs [new file with mode: 0644]
src/test/rustdoc/issue-22038.rs [new file with mode: 0644]
src/test/rustdoc/issue-23106.rs [new file with mode: 0644]
src/test/rustdoc/issue-23207.rs [new file with mode: 0644]
src/test/rustdoc/issue-23511.rs [new file with mode: 0644]
src/test/rustdoc/issue-23744.rs [new file with mode: 0644]
src/test/rustdoc/must-use.rs [new file with mode: 0644]
src/test/rustdoc/negative-impl.rs [new file with mode: 0644]
src/test/rustdoc/recursion1.rs [new file with mode: 0644]
src/test/rustdoc/recursion2.rs [new file with mode: 0644]
src/test/rustdoc/recursion3.rs [new file with mode: 0644]
src/test/rustdoc/search-index.rs [new file with mode: 0644]
src/test/rustdoc/smoke.rs [new file with mode: 0644]
src/test/rustdoc/src-links.rs [new file with mode: 0644]
src/test/rustdoc/src-links/mod.rs [new file with mode: 0644]
src/test/rustdoc/viewpath-self.rs [new file with mode: 0644]
src/test/rustdoc/where.rs [new file with mode: 0644]

index 4f809237bf85a22cac411ad865d6b6da975de153..8108e10752a2069ef9d94d12a2192c5484980360 100755 (executable)
--- a/configure
+++ b/configure
@@ -1128,6 +1128,7 @@ do
     make_dir $h/test/debuginfo-gdb
     make_dir $h/test/debuginfo-lldb
     make_dir $h/test/codegen
+    make_dir $h/test/rustdoc
 done
 
 # Configure submodules
index f594a6a19f1580ab9f5c489b7fcb969dc2ff4b7d..666d95b6d651d83a05b06f0302d395828cd16af1 100644 (file)
@@ -118,42 +118,13 @@ ONLY_RLIB_collections := 1
 ONLY_RLIB_unicode := 1
 ONLY_RLIB_rustc_bitflags := 1
 
+# Documented-by-default crates
+DOC_CRATES := std alloc collections core libc unicode
+
 ################################################################################
 # You should not need to edit below this line
 ################################################################################
 
-# On channels where the only usable crate is std, only build documentation for
-# std. This keeps distributions small and doesn't clutter up the API docs with
-# confusing internal details from the crates behind the facade.
-#
-# (Disabled while cmr figures out how to change rustdoc to make reexports work
-# slightly nicer. Otherwise, all cross-crate links to Vec will go to
-# libcollections, breaking them, and [src] links for anything reexported will
-# not work.)
-
-#ifeq ($(CFG_RELEASE_CHANNEL),stable)
-#DOC_CRATES := std
-#else
-#ifeq ($(CFG_RELEASE_CHANNEL),beta)
-#DOC_CRATES := std
-#else
-DOC_CRATES := $(filter-out rustc, \
-          $(filter-out rustc_trans, \
-          $(filter-out rustc_typeck, \
-          $(filter-out rustc_borrowck, \
-          $(filter-out rustc_resolve, \
-          $(filter-out rustc_driver, \
-          $(filter-out rustc_privacy, \
-          $(filter-out rustc_lint, \
-          $(filter-out log, \
-          $(filter-out getopts, \
-          $(filter-out syntax, $(CRATES))))))))))))
-#endif
-#endif
-COMPILER_DOC_CRATES := rustc rustc_trans rustc_borrowck rustc_resolve \
-                       rustc_typeck rustc_driver syntax rustc_privacy \
-                       rustc_lint
-
 # This macro creates some simple definitions for each crate being built, just
 # some munging of all of the parameters above.
 #
index d297055ba9acb6e3b5c2b322f38ddcccc3b35949..d179d337faa61215f8084ae9f4ca6215fc05199c 100644 (file)
@@ -250,18 +250,20 @@ endif
 doc/$(1)/:
        $$(Q)mkdir -p $$@
 
-$(2) += doc/$(1)/index.html
 doc/$(1)/index.html: CFG_COMPILER_HOST_TRIPLE = $(CFG_TARGET)
 doc/$(1)/index.html: $$(LIB_DOC_DEP_$(1)) doc/$(1)/
        @$$(call E, rustdoc: $$@)
        $$(Q)CFG_LLVM_LINKAGE_FILE=$$(LLVM_LINKAGE_PATH_$(CFG_BUILD)) \
-               $$(RUSTDOC) --cfg dox --cfg stage2 $$<
+               $$(RUSTDOC) --cfg dox --cfg stage2 $$(RUSTFLAGS_$(1)) $$<
 endef
 
-$(foreach crate,$(DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),DOC_TARGETS)))
+$(foreach crate,$(CRATES),$(eval $(call DEF_LIB_DOC,$(crate))))
 
+COMPILER_DOC_TARGETS := $(CRATES:%=doc/%/index.html)
 ifdef CFG_COMPILER_DOCS
-  $(foreach crate,$(COMPILER_DOC_CRATES),$(eval $(call DEF_LIB_DOC,$(crate),COMPILER_DOC_TARGETS)))
+  DOC_TARGETS += $(COMPILER_DOC_TARGETS)
+else
+  DOC_TARGETS += $(DOC_CRATES:%=doc/%/index.html)
 endif
 
 ifdef CFG_DISABLE_DOCS
index 48ebe4e540e3d008ea24f838939a0e23c06a8122..a540d2bace4c604fc6bcde29e4f651c5120911c3 100644 (file)
@@ -22,9 +22,11 @@ $(eval $(call RUST_CRATE,coretest))
 DEPS_collectionstest :=
 $(eval $(call RUST_CRATE,collectionstest))
 
-TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) collectionstest coretest
+TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) \
+                       collectionstest coretest
 TEST_DOC_CRATES = $(DOC_CRATES)
-TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve rustc_trans rustc_lint,\
+TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve \
+                               rustc_trans rustc_lint,\
                      $(HOST_CRATES))
 TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
 
@@ -304,6 +306,7 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
     check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
        check-stage$(1)-T-$(2)-H-$(3)-cfail-full-exec \
        check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
+       check-stage$(1)-T-$(2)-H-$(3)-rustdocck-exec \
         check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
         check-stage$(1)-T-$(2)-H-$(3)-doc-crates-exec \
        check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
@@ -471,6 +474,7 @@ DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
 DEBUGINFO_LLDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
 CODEGEN_RS := $(wildcard $(S)src/test/codegen/*.rs)
 CODEGEN_CC := $(wildcard $(S)src/test/codegen/*.cc)
+RUSTDOCCK_RS := $(wildcard $(S)src/test/rustdoc/*.rs)
 
 # perf tests are the same as bench tests only they run under
 # a performance monitor.
@@ -489,6 +493,7 @@ PRETTY_TESTS := $(PRETTY_RS)
 DEBUGINFO_GDB_TESTS := $(DEBUGINFO_GDB_RS)
 DEBUGINFO_LLDB_TESTS := $(DEBUGINFO_LLDB_RS)
 CODEGEN_TESTS := $(CODEGEN_RS) $(CODEGEN_CC)
+RUSTDOCCK_TESTS := $(RUSTDOCCK_RS)
 
 CTEST_SRC_BASE_rpass = run-pass
 CTEST_BUILD_BASE_rpass = run-pass
@@ -550,6 +555,11 @@ CTEST_BUILD_BASE_codegen = codegen
 CTEST_MODE_codegen = codegen
 CTEST_RUNTOOL_codegen = $(CTEST_RUNTOOL)
 
+CTEST_SRC_BASE_rustdocck = rustdoc
+CTEST_BUILD_BASE_rustdocck = rustdoc
+CTEST_MODE_rustdocck = rustdoc
+CTEST_RUNTOOL_rustdocck = $(CTEST_RUNTOOL)
+
 # CTEST_DISABLE_$(TEST_GROUP), if set, will cause the test group to be
 # disabled and the associated message to be printed as a warning
 # during attempts to run those tests.
@@ -618,12 +628,14 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
                --compile-lib-path $$(HLIB$(1)_H_$(3)) \
         --run-lib-path $$(TLIB$(1)_T_$(2)_H_$(3)) \
         --rustc-path $$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
+        --rustdoc-path $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
         --clang-path $(if $(CFG_CLANG),$(CFG_CLANG),clang) \
         --llvm-bin-path $(CFG_LLVM_INST_DIR_$(CFG_BUILD))/bin \
         --aux-base $$(S)src/test/auxiliary/ \
         --stage-id stage$(1)-$(2) \
         --target $(2) \
         --host $(3) \
+       --python $$(CFG_PYTHON) \
         --gdb-version="$(CFG_GDB_VERSION)" \
         --lldb-version="$(CFG_LLDB_VERSION)" \
         --android-cross-path=$(CFG_ANDROID_CROSS_PATH) \
@@ -660,6 +672,9 @@ CTEST_DEPS_debuginfo-lldb_$(1)-T-$(2)-H-$(3) = $$(DEBUGINFO_LLDB_TESTS) \
                                                $(S)src/etc/lldb_batchmode.py \
                                                $(S)src/etc/lldb_rust_formatters.py
 CTEST_DEPS_codegen_$(1)-T-$(2)-H-$(3) = $$(CODEGEN_TESTS)
+CTEST_DEPS_rustdocck_$(1)-T-$(2)-H-$(3) = $$(RUSTDOCCK_TESTS) \
+        $$(HBIN$(1)_H_$(3))/rustdoc$$(X_$(3)) \
+       $(S)src/etc/htmldocck.py
 
 endef
 
@@ -722,7 +737,8 @@ endif
 
 endef
 
-CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail pfail bench perf debuginfo-gdb debuginfo-lldb codegen
+CTEST_NAMES = rpass rpass-valgrind rpass-full cfail-full rfail cfail pfail \
+       bench perf debuginfo-gdb debuginfo-lldb codegen rustdocck
 
 $(foreach host,$(CFG_HOST), \
  $(eval $(foreach target,$(CFG_TARGET), \
@@ -890,6 +906,7 @@ TEST_GROUPS = \
        bench \
        perf \
        rmake \
+       rustdocck \
        debuginfo-gdb \
        debuginfo-lldb \
        codegen \
index fe556cecef6981eef5b856bb40ccc48d3250c272..dcac32ccb8a40564eb2217cca1c409f0ccdc7f3f 100644 (file)
@@ -23,7 +23,8 @@ pub enum Mode {
     Pretty,
     DebugInfoGdb,
     DebugInfoLldb,
-    Codegen
+    Codegen,
+    Rustdoc,
 }
 
 impl FromStr for Mode {
@@ -39,6 +40,7 @@ fn from_str(s: &str) -> Result<Mode, ()> {
           "debuginfo-lldb" => Ok(DebugInfoLldb),
           "debuginfo-gdb" => Ok(DebugInfoGdb),
           "codegen" => Ok(Codegen),
+          "rustdoc" => Ok(Rustdoc),
           _ => Err(()),
         }
     }
@@ -56,6 +58,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             DebugInfoGdb => "debuginfo-gdb",
             DebugInfoLldb => "debuginfo-lldb",
             Codegen => "codegen",
+            Rustdoc => "rustdoc",
         }, f)
     }
 }
@@ -71,6 +74,12 @@ pub struct Config {
     // The rustc executable
     pub rustc_path: PathBuf,
 
+    // The rustdoc executable
+    pub rustdoc_path: PathBuf,
+
+    // The python executable
+    pub python: String,
+
     // The clang executable
     pub clang_path: Option<PathBuf>,
 
index f00ff9bcbe5e5c4bec3ad7fbbd4336a72f1a2c55..e680be2a8c526bf0ec7263e6ee9fc9f609f3c1c7 100644 (file)
@@ -60,6 +60,8 @@ pub fn parse_config(args: Vec<String> ) -> Config {
         vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
           reqopt("", "run-lib-path", "path to target shared libraries", "PATH"),
           reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"),
+          reqopt("", "rustdoc-path", "path to rustdoc to use for compiling", "PATH"),
+          reqopt("", "python", "path to python to use for doc tests", "PATH"),
           optopt("", "clang-path", "path to  executable for codegen tests", "PATH"),
           optopt("", "valgrind-path", "path to Valgrind executable for Valgrind tests", "PROGRAM"),
           optflag("", "force-valgrind", "fail if Valgrind tests cannot be run under Valgrind"),
@@ -128,6 +130,8 @@ fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf {
         compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
         run_lib_path: matches.opt_str("run-lib-path").unwrap(),
         rustc_path: opt_path(matches, "rustc-path"),
+        rustdoc_path: opt_path(matches, "rustdoc-path"),
+        python: matches.opt_str("python").unwrap(),
         clang_path: matches.opt_str("clang-path").map(|s| PathBuf::from(&s)),
         valgrind_path: matches.opt_str("valgrind-path"),
         force_valgrind: matches.opt_present("force-valgrind"),
@@ -168,6 +172,7 @@ pub fn log_config(config: &Config) {
     logv(c, format!("compile_lib_path: {:?}", config.compile_lib_path));
     logv(c, format!("run_lib_path: {:?}", config.run_lib_path));
     logv(c, format!("rustc_path: {:?}", config.rustc_path.display()));
+    logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path.display()));
     logv(c, format!("src_base: {:?}", config.src_base.display()));
     logv(c, format!("build_base: {:?}", config.build_base.display()));
     logv(c, format!("stage_id: {}", config.stage_id));
index f387f83ad524635bd36eb570130495249816510d..daa53e2dbd596a4267ed22021f9e4833ce8d4693 100644 (file)
@@ -12,7 +12,7 @@
 
 use common::Config;
 use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
-use common::{Codegen, DebugInfoLldb, DebugInfoGdb};
+use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc};
 use errors;
 use header::TestProps;
 use header;
@@ -57,15 +57,16 @@ pub fn run_metrics(config: Config, testfile: &Path, mm: &mut MetricMap) {
     let props = header::load_props(&testfile);
     debug!("loaded props");
     match config.mode {
-      CompileFail => run_cfail_test(&config, &props, &testfile),
-      ParseFail => run_cfail_test(&config, &props, &testfile),
-      RunFail => run_rfail_test(&config, &props, &testfile),
-      RunPass => run_rpass_test(&config, &props, &testfile),
-      RunPassValgrind => run_valgrind_test(&config, &props, &testfile),
-      Pretty => run_pretty_test(&config, &props, &testfile),
-      DebugInfoGdb => run_debuginfo_gdb_test(&config, &props, &testfile),
-      DebugInfoLldb => run_debuginfo_lldb_test(&config, &props, &testfile),
-      Codegen => run_codegen_test(&config, &props, &testfile, mm),
+        CompileFail => run_cfail_test(&config, &props, &testfile),
+        ParseFail => run_cfail_test(&config, &props, &testfile),
+        RunFail => run_rfail_test(&config, &props, &testfile),
+        RunPass => run_rpass_test(&config, &props, &testfile),
+        RunPassValgrind => run_valgrind_test(&config, &props, &testfile),
+        Pretty => run_pretty_test(&config, &props, &testfile),
+        DebugInfoGdb => run_debuginfo_gdb_test(&config, &props, &testfile),
+        DebugInfoLldb => run_debuginfo_lldb_test(&config, &props, &testfile),
+        Codegen => run_codegen_test(&config, &props, &testfile, mm),
+        Rustdoc => run_rustdoc_test(&config, &props, &testfile),
     }
 }
 
@@ -725,32 +726,37 @@ fn run_lldb(config: &Config,
                 -> ProcRes {
         // Prepare the lldb_batchmode which executes the debugger script
         let lldb_script_path = rust_src_root.join("src/etc/lldb_batchmode.py");
+        cmd2procres(config,
+                    test_executable,
+                    Command::new(&config.python)
+                            .arg(&lldb_script_path)
+                            .arg(test_executable)
+                            .arg(debugger_script)
+                            .env("PYTHONPATH",
+                                 config.lldb_python_dir.as_ref().unwrap()))
+    }
+}
 
-        let mut cmd = Command::new("python");
-        cmd.arg(&lldb_script_path)
-           .arg(test_executable)
-           .arg(debugger_script)
-           .env("PYTHONPATH", config.lldb_python_dir.as_ref().unwrap());
-
-        let (status, out, err) = match cmd.output() {
-            Ok(Output { status, stdout, stderr }) => {
-                (status,
-                 String::from_utf8(stdout).unwrap(),
-                 String::from_utf8(stderr).unwrap())
-            },
-            Err(e) => {
-                fatal(&format!("Failed to setup Python process for \
-                                LLDB script: {}", e))
-            }
-        };
+fn cmd2procres(config: &Config, test_executable: &Path, cmd: &mut Command)
+              -> ProcRes {
+    let (status, out, err) = match cmd.output() {
+        Ok(Output { status, stdout, stderr }) => {
+            (status,
+             String::from_utf8(stdout).unwrap(),
+             String::from_utf8(stderr).unwrap())
+        },
+        Err(e) => {
+            fatal(&format!("Failed to setup Python process for \
+                            LLDB script: {}", e))
+        }
+    };
 
-        dump_output(config, test_executable, &out, &err);
-        return ProcRes {
-            status: Status::Normal(status),
-            stdout: out,
-            stderr: err,
-            cmdline: format!("{:?}", cmd)
-        };
+    dump_output(config, test_executable, &out, &err);
+    ProcRes {
+        status: Status::Normal(status),
+        stdout: out,
+        stderr: err,
+        cmdline: format!("{:?}", cmd)
     }
 }
 
@@ -1157,6 +1163,26 @@ fn compile_test_(config: &Config, props: &TestProps,
     compose_and_run_compiler(config, props, testfile, args, None)
 }
 
+fn document(config: &Config, props: &TestProps,
+            testfile: &Path, extra_args: &[String]) -> (ProcRes, PathBuf) {
+    let aux_dir = aux_output_dir_name(config, testfile);
+    let out_dir = output_base_name(config, testfile);
+    let _ = fs::remove_dir_all(&out_dir);
+    ensure_dir(&out_dir);
+    let mut args = vec!["-L".to_string(),
+                        aux_dir.to_str().unwrap().to_string(),
+                        "-o".to_string(),
+                        out_dir.to_str().unwrap().to_string(),
+                        testfile.to_str().unwrap().to_string()];
+    args.extend(extra_args.iter().cloned());
+    args.extend(split_maybe_args(&props.compile_flags).into_iter());
+    let args = ProcArgs {
+        prog: config.rustdoc_path.to_str().unwrap().to_string(),
+        args: args,
+    };
+    (compose_and_run_compiler(config, props, testfile, args, None), out_dir)
+}
+
 fn exec_compiled_test(config: &Config, props: &TestProps,
                       testfile: &Path) -> ProcRes {
 
@@ -1181,20 +1207,17 @@ fn exec_compiled_test(config: &Config, props: &TestProps,
     }
 }
 
-fn compose_and_run_compiler(
-    config: &Config,
-    props: &TestProps,
-    testfile: &Path,
-    args: ProcArgs,
-    input: Option<String>) -> ProcRes {
-
+fn compose_and_run_compiler(config: &Config, props: &TestProps,
+                            testfile: &Path, args: ProcArgs,
+                            input: Option<String>) -> ProcRes {
     if !props.aux_builds.is_empty() {
         ensure_dir(&aux_output_dir_name(config, testfile));
     }
 
     let aux_dir = aux_output_dir_name(config, testfile);
     // FIXME (#9639): This needs to handle non-utf8 paths
-    let extra_link_args = vec!("-L".to_string(), aux_dir.to_str().unwrap().to_string());
+    let extra_link_args = vec!["-L".to_string(),
+                               aux_dir.to_str().unwrap().to_string()];
 
     for rel_ab in &props.aux_builds {
         let abs_ab = config.aux_base.join(rel_ab);
@@ -1330,8 +1353,8 @@ fn make_exe_name(config: &Config, testfile: &Path) -> PathBuf {
     f
 }
 
-fn make_run_args(config: &Config, props: &TestProps, testfile: &Path) ->
-   ProcArgs {
+fn make_run_args(config: &Config, props: &TestProps, testfile: &Path)
+                 -> ProcArgs {
     // If we've got another tool to run under (valgrind),
     // then split apart its command
     let mut args = split_maybe_args(&config.runtool);
@@ -1797,3 +1820,21 @@ fn charset() -> &'static str {
         "UTF-8"
     }
 }
+
+fn run_rustdoc_test(config: &Config, props: &TestProps, testfile: &Path) {
+    let (proc_res, out_dir) = document(config, props, testfile, &[]);
+    if !proc_res.status.success() {
+        fatal_proc_rec("rustdoc failed!", &proc_res);
+    }
+    let root = find_rust_src_root(config).unwrap();
+
+    let res = cmd2procres(config,
+                          testfile,
+                          Command::new(&config.python)
+                                  .arg(root.join("src/etc/htmldocck.py"))
+                                  .arg(out_dir)
+                                  .arg(testfile));
+    if !res.status.success() {
+        fatal_proc_rec("htmldocck failed!", &res);
+    }
+}
index 6e8d394afa5b104c3b976814f8aa166ea8824640..b2e1a6ec0bc19a078d1d50921d03f721cfb4f413 100644 (file)
 % The Rust Programming Language
 
-Welcome! This book will teach you about [the Rust Programming
-Language](http://www.rust-lang.org/). Rust is a modern systems programming
-language focusing on safety and speed. It accomplishes these goals by being
-memory safe without using garbage collection.
+Welcome! This book will teach you about the [Rust Programming Language][rust].
+Rust is a systems programming language focused on three goals: safety, speed,
+and concurrency. It maintains these goals without having a garbage collector,
+making it a useful language for a number of use cases other languages aren’t
+good at: embedding in other languages, programs with specific space and time
+requirements, and writing low-level code, like device drivers and operating
+systems. It improves on current languages targeting this space by having a
+number of compile-time safety checks that produce no runtime overhead, while
+eliminating all data races. Rust also aims to achieve ‘zero-cost abstrations’
+even though some of these abstractions feel like those of a high-level
+language. Even then, Rust still allows precise control like a low-level
+language would.
 
-"The Rust Programming Language" is split into three sections, which you can
-navigate through the menu on the left.
+[rust]: http://rust-lang.org
 
-<h2 class="section-header"><a href="basic.html">Basics</a></h2>
+“The Rust Programming Language” is split into seven sections. This introduction
+is the first. After this:
 
-This section is a linear introduction to the basic syntax and semantics of
-Rust. It has individual sections on each part of Rust's syntax.
+* [Getting started][gs] - Set up your computer for Rust development.
+* [Learn Rust][lr] - Learn Rust programming through small projects.
+* [Effective Rust][er] - Higher-level concepts for writing excellent Rust code.
+* [Syntax and Semantics][ss] - Each bit of Rust, broken down into small chunks.
+* [Nightly Rust][nr] - Cutting-edge features that aren’t in stable builds yet.
+* [Glossary][gl] - A reference of terms used in the book.
 
-After reading "Basics," you will have a good foundation to learn more about
-Rust, and can write very simple programs.
+[gs]: getting-started.html
+[lr]: learn-rust.html
+[er]: effective-rust.html
+[ss]: syntax-and-semantics.html
+[nr]: nightly-rust.html
+[gl]: glossary.html
 
-<h2 class="section-header"><a href="intermediate.html">Intermediate</a></h2>
+After reading this introduction, you’ll want to dive into either ‘Learn Rust’
+or ‘Syntax and Semantics’, depending on your preference: ‘Learn Rust’ if you
+want to dive in with a project, or ‘Syntax and Semantics’ if you prefer to
+start small, and learn a single concept thoroughly before moving onto the next.
+Copious cross-linking connects these parts together.
 
-This section contains individual chapters, which are self-contained. They focus
-on specific topics, and can be read in any order.
+## A brief introduction to Rust
 
-After reading "Intermediate," you will have a solid understanding of Rust,
-and will be able to understand most Rust code and write more complex programs.
+Is Rust a language you might be interested in? Let’s examine a few small code
+samples to show off a few of its strengths.
 
-<h2 class="section-header"><a href="advanced.html">Advanced</a></h2>
+The main concept that makes Rust unique is called ‘ownership’. Consider this
+small example:
 
-In a similar fashion to "Intermediate," this section is full of individual,
-deep-dive chapters, which stand alone and can be read in any order. These
-chapters focus on Rust's most complex features.
+```rust
+fn main() {
+    let mut x = vec!["Hello", "world"];
+}
+```
 
-<h2 class="section-header"><a href="unstable.html">Unstable</a></h2>
+This program makes a [variable binding][var] named `x`. The value of this
+binding is a `Vec<T>`, a ‘vector’, that we create through a [macro][macro]
+defined in the standard library. This macro is called `vec`, and we invoke
+macros with a `!`. This follows a general principle of Rust: make things
+explicit. Macros can do significantly more complicated things than function
+calls, and so they’re visually distinct. The `!` also helps with parsing,
+making tooling easier to write, which is also important.
 
-In a similar fashion to "Intermediate," this section is full of individual,
-deep-dive chapters, which stand alone and can be read in any order.
+We used `mut` to make `x` mutable: bindings are immutable by default in Rust.
+We’ll be mutating this vector later in the example.
 
-This chapter contains things that are only available on the nightly channel of
-Rust.
+It’s also worth noting that we didn’t need a type annotation here: while Rust
+is statically typed, we didn’t need to explicitly annotate the type. Rust has
+type inference to balance out the power of static typing with the verbosity of
+annotating types.
+
+Rust prefers stack allocation to heap allocation: `x` is placed directly on the
+stack. However, the `Vec<T>` type allocates space for the elements of the
+vector on the heap. If you’re not familiar with this distinction, you can
+ignore it for now, or check out [‘The Stack and the Heap’][heap]. As a systems
+programming language, Rust gives you the ability to control how your memory is
+allocated, but when we’re getting started, it’s less of a big deal.
+
+[var]: variable-bindings.html
+[macro]: macros.html
+[heap]: the-stack-and-the-heap.html
+
+Earlier, we mentioned that ‘ownership’ is the key new concept in Rust. In Rust
+parlance, `x` is said to ‘own’ the vector. This means that when `x` goes out of
+scope, the vector’s memory will be de-allocated. This is done deterministically
+by the Rust compiler, rather than through a mechanism such as a garbage
+collector. In other words, in Rust, you don’t call functions like `malloc` and
+`free` yourself: the compiler statically determines when you need to allocate
+or deallocate memory, and inserts those calls itself. To err is to be human,
+but compilers never forget.
+
+Let’s add another line to our example:
+
+```rust
+fn main() {
+    let mut x = vec!["Hello", "world"];
+
+    let y = &x[0];
+}
+```
+
+We’ve introduced another binding, `y`. In this case, `y` is a ‘reference’ to
+the first element of the vector. Rust’s references are similar to pointers in
+other languages, but with additional compile-time safety checks. References
+interact with the ownership system by [‘borrowing’][borrowing] what they point
+to, rather than owning it. The difference is, when the reference goes out of
+scope, it will not deallocate the underlying memory. If it did, we’d
+de-allocate twice, which is bad!
+
+[borrowing]: references-and-borrowing.html
+
+Let’s add a third line. It looks innocent enough, but causes a compiler error:
+
+```rust,ignore
+fn main() {
+    let mut x = vec!["Hello", "world"];
+
+    let y = &x[0];
+
+    x.push(4);
+}
+```
+
+`push` is a method on vectors that appends another element to the end of the
+vector. When we try to compile this program, we get an error:
+
+```text
+error: cannot borrow `x` as mutable because it is also borrowed as immutable
+    x.push(4);
+    ^
+note: previous borrow of `x` occurs here; the immutable borrow prevents
+subsequent moves or mutable borrows of `x` until the borrow ends
+    let y = &x[0];
+             ^
+note: previous borrow ends here
+fn main() {
+
+}
+^
+```
+
+Whew! The Rust compiler gives quite detailed errors at times, and this is one
+of those times. As the error explains, while we made our binding mutable, we
+still cannot call `push`. This is because we already have a reference to an
+element of the vector, `y`. Mutating something while another reference exists
+is dangerous, because we may invalidate the reference. In this specific case,
+when we create the vector, we may have only allocated space for three elements.
+Adding a fourth would mean allocating a new chunk of memory for all those elements,
+copying the old values over, and updating the internal pointer to that memory.
+That all works just fine. The problem is that `y` wouldn’t get updated, and so
+we’d have a ‘dangling pointer’. That’s bad. Any use of `y` would be an error in
+this case, and so the compiler has caught this for us.
+
+So how do we solve this problem? There are two approaches we can take. The first
+is making a copy rather than using a reference:
+
+```rust
+fn main() {
+    let mut x = vec!["Hello", "world"];
+
+    let y = x[0].clone();
+
+    x.push(4);
+}
+```
+
+Rust has [move semantics][move] by default, so if we want to make a copy of some
+data, we call the `clone()` method. In this example, `y` is no longer a reference
+to the vector stored in `x`, but a copy of its first element, `"hello"`. Now
+that we don’t have a reference, our `push()` works just fine.
+
+[move]: move-semantics.html
+
+If we truly want a reference, we need the other option: ensure that our reference
+goes out of scope before we try to do the mutation. That looks like this:
+
+```rust
+fn main() {
+    let mut x = vec!["Hello", "world"];
+
+    {
+        let y = &x[0];
+    }
+
+    x.push(4);
+}
+```
+
+We created an inner scope with an additional set of curly braces. `y` will go out of
+scope before we call `push()`, and so we’re all good.
+
+This concept of ownership isn’t just good for preventing danging pointers, but an
+entire set of related problems, like iterator invalidation, concurrency, and more.
index d894e1c47253b7d12c2740df13dc4958f2db3788..029facdec762b3a0dd8d610b369f97aea01cab73 100644 (file)
@@ -17,8 +17,8 @@
     * [`Deref` coercions](deref-coercions.md)
 * [Syntax and Semantics](syntax-and-semantics.md)
     * [Variable Bindings](variable-bindings.md)
-    * [Primitive Types](primitive-types.md)
     * [Functions](functions.md)
+    * [Primitive Types](primitive-types.md)
     * [Comments](comments.md)
     * [Structs](structs.md)
     * [Mutability](mutability.md)
@@ -35,8 +35,6 @@
     * [Move semantics](move-semantics.md)
     * [Drop](drop.md)
     * [Vectors](vectors.md)
-    * [Arrays](arrays.md)
-    * [Slices](slices.md)
     * [Strings](strings.md)
     * [Traits](traits.md)
     * [Operators and Overloading](operators-and-overloading.md)
@@ -47,7 +45,6 @@
     * [Crates and Modules](crates-and-modules.md)
     * [`static`](static.md)
     * [`const`](const.md)
-    * [Tuples](tuples.md)
     * [Tuple Structs](tuple-structs.md)
     * [Attributes](attributes.md)
     * [Conditional Compilation](conditional-compilation.md)
@@ -67,3 +64,4 @@
     * [Benchmark Tests](benchmark-tests.md)
     * [Box Syntax and Patterns](box-syntax-and-patterns.md)
 * [Glossary](glossary.md)
+* [Academic Research](academic-research.md)
diff --git a/src/doc/trpl/academic-research.md b/src/doc/trpl/academic-research.md
new file mode 100644 (file)
index 0000000..f4f066f
--- /dev/null
@@ -0,0 +1,46 @@
+% Academic Research
+
+An incomplete list of papers that have had some influence in Rust.
+
+Recommended for inspiration and a better understanding of Rust's background.
+
+### Type system
+
+* [Region based memory management in Cyclone](http://209.68.42.137/ucsd-pages/Courses/cse227.w03/handouts/cyclone-regions.pdf)
+* [Safe manual memory management in Cyclone](http://www.cs.umd.edu/projects/PL/cyclone/scp.pdf)
+* [Typeclasses: making ad-hoc polymorphism less ad hoc](http://www.ps.uni-sb.de/courses/typen-ws99/class.ps.gz)
+* [Macros that work together](https://www.cs.utah.edu/plt/publications/jfp12-draft-fcdf.pdf)
+* [Traits: composable units of behavior](http://scg.unibe.ch/archive/papers/Scha03aTraits.pdf)
+* [Alias burying](http://www.cs.uwm.edu/faculty/boyland/papers/unique-preprint.ps) - We tried something similar and abandoned it.
+* [External uniqueness is unique enough](http://www.computingscience.nl/research/techreps/repo/CS-2002/2002-048.pdf)
+* [Uniqueness and Reference Immutability for Safe Parallelism](https://research.microsoft.com/pubs/170528/msr-tr-2012-79.pdf)
+* [Region Based Memory Management](http://www.cs.ucla.edu/~palsberg/tba/papers/tofte-talpin-iandc97.pdf)
+
+### Concurrency
+
+* [Singularity: rethinking the software stack](https://research.microsoft.com/pubs/69431/osr2007_rethinkingsoftwarestack.pdf)
+* [Language support for fast and reliable message passing in singularity OS](https://research.microsoft.com/pubs/67482/singsharp.pdf)
+* [Scheduling multithreaded computations by work stealing](http://supertech.csail.mit.edu/papers/steal.pdf)
+* [Thread scheduling for multiprogramming multiprocessors](http://www.eecis.udel.edu/%7Ecavazos/cisc879-spring2008/papers/arora98thread.pdf)
+* [The data locality of work stealing](http://www.aladdin.cs.cmu.edu/papers/pdfs/y2000/locality_spaa00.pdf)
+* [Dynamic circular work stealing deque](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.170.1097&rep=rep1&type=pdf) - The Chase/Lev deque
+* [Work-first and help-first scheduling policies for async-finish task parallelism](http://www.cs.rice.edu/%7Eyguo/pubs/PID824943.pdf) - More general than fully-strict work stealing
+* [A Java fork/join calamity](http://www.coopsoft.com/ar/CalamityArticle.html) - critique of Java's fork/join library, particularly its application of work stealing to non-strict computation
+* [Scheduling techniques for concurrent systems](http://www.ece.rutgers.edu/%7Eparashar/Classes/ece572-papers/05/ps-ousterhout.pdf)
+* [Contention aware scheduling](http://www.blagodurov.net/files/a8-blagodurov.pdf)
+* [Balanced work stealing for time-sharing multicores](http://www.cse.ohio-state.edu/hpcs/WWW/HTML/publications/papers/TR-12-1.pdf)
+* [Three layer cake](http://www.upcrc.illinois.edu/workshops/paraplop10/papers/paraplop10_submission_8.pdf)
+* [Non-blocking steal-half work queues](http://www.cs.bgu.ac.il/%7Ehendlerd/papers/p280-hendler.pdf)
+* [Reagents: expressing and composing fine-grained concurrency](http://www.mpi-sws.org/~turon/reagents.pdf)
+* [Algorithms for scalable synchronization of shared-memory multiprocessors](https://www.cs.rochester.edu/u/scott/papers/1991_TOCS_synch.pdf)
+
+### Others
+
+* [Crash-only software](https://www.usenix.org/legacy/events/hotos03/tech/full_papers/candea/candea.pdf)
+* [Composing High-Performance Memory Allocators](http://people.cs.umass.edu/~emery/pubs/berger-pldi2001.pdf)
+* [Reconsidering Custom Memory Allocation](http://people.cs.umass.edu/~emery/pubs/berger-oopsla2002.pdf)
+
+### Papers *about* Rust
+
+* [GPU programming in Rust](http://www.cs.indiana.edu/~eholk/papers/hips2013.pdf)
+* [Parallel closures: a new twist on an old idea](https://www.usenix.org/conference/hotpar12/parallel-closures-new-twist-old-idea) - not exactly about rust, but by nmatsakis
diff --git a/src/doc/trpl/arrays.md b/src/doc/trpl/arrays.md
deleted file mode 100644 (file)
index a6ecac9..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-% Arrays
-
-Like many programming languages, Rust has list types to represent a sequence of
-things. The most basic is the *array*, a fixed-size list of elements of the
-same type. By default, arrays are immutable.
-
-```{rust}
-let a = [1, 2, 3]; // a: [i32; 3]
-let mut m = [1, 2, 3]; // mut m: [i32; 3]
-```
-
-There's a shorthand for initializing each element of an array to the same
-value. In this example, each element of `a` will be initialized to `0`:
-
-```{rust}
-let a = [0; 20]; // a: [i32; 20]
-```
-
-Arrays have type `[T; N]`. We'll talk about this `T` notation later, when we
-cover generics.
-
-You can get the number of elements in an array `a` with `a.len()`, and use
-`a.iter()` to iterate over them with a for loop. This code will print each
-number in order:
-
-```{rust}
-let a = [1, 2, 3];
-
-println!("a has {} elements", a.len());
-for e in a.iter() {
-    println!("{}", e);
-}
-```
-
-You can access a particular element of an array with *subscript notation*:
-
-```{rust}
-let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3]
-
-println!("The second name is: {}", names[1]);
-```
-
-Subscripts start at zero, like in most programming languages, so the first name
-is `names[0]` and the second name is `names[1]`. The above example prints
-`The second name is: Brian`. If you try to use a subscript that is not in the
-array, you will get an error: array access is bounds-checked at run-time. Such
-errant access is the source of many bugs in other systems programming
-languages.
index 6ea0759e99d7b7a07dfae6fe9b7d9e621cd9aee7..582ed3b7e65c56a256c60f8a76e0fc3629328f5d 100644 (file)
@@ -1 +1,8 @@
 % Effective Rust
+
+So you’ve learned how to write some Rust code. But there’s a difference between
+writing *any* Rust code and writing *good* Rust code.
+
+This section consists of relatively independent tutorials which show you how to
+take your Rust to the next level. Common patterns and standard library features
+will be introduced. Read these sections in any order of your choosing.
index a164def516b93d90c34ef5a993190634a3d72e3c..555d40e65970618b2ed122362da5a15ec8159599 100644 (file)
@@ -1 +1,5 @@
 % Getting Started
+
+This first section of the book will get you going with Rust and its tooling.
+First, we’ll install Rust. Then: the classic ‘Hello World’ program. Finally,
+we’ll talk about Cargo, Rust’s build system and package manager.
index ae2a79bafecd52707417c980fb834700bd0c118d..8d8b17343343e08ed21e7cfbb3d6533650415622 100644 (file)
@@ -1,26 +1,27 @@
 % Hello, Cargo!
 
-[Cargo](http://crates.io) is a tool that Rustaceans use to help manage their
-Rust projects. Cargo is currently in a pre-1.0 state, just like Rust, and so it
-is still a work in progress. However, it is already good enough to use for many
-Rust projects, and so it is assumed that Rust projects will use Cargo from the
-beginning.
+[Cargo][cratesio] is a tool that Rustaceans use to help manage their Rust
+projects. Cargo is currently in a pre-1.0 state, and so it is still a work in
+progress. However, it is already good enough to use for many Rust projects, and
+so it is assumed that Rust projects will use Cargo from the beginning.
+
+[cratesio]: https://doc.crates.io
 
 Cargo manages three things: building your code, downloading the dependencies
 your code needs, and building those dependencies. At first, your
-program doesn't have any dependencies, so we'll only be using the first part of
-its functionality. Eventually, we'll add more. Since we started off by using
+program doesn’t have any dependencies, so we’ll only be using the first part of
+its functionality. Eventually, well add more. Since we started off by using
 Cargo, it'll be easy to add later.
 
-If you installed Rust via the official installers you will also have
-Cargo. If you installed Rust some other way, you may want to [check
-the Cargo
-README](https://github.com/rust-lang/cargo#installing-cargo-from-nightlies)
-for specific instructions about installing it.
+If you installed Rust via the official installers you will also have Cargo. If
+you installed Rust some other way, you may want to [check the Cargo
+README][cargoreadme] for specific instructions about installing it.
+
+[cargoreadme]: https://github.com/rust-lang/cargo#installing-cargo-from-nightlies
 
 ## Converting to Cargo
 
-Let's convert Hello World to Cargo.
+Lets convert Hello World to Cargo.
 
 To Cargo-ify our project, we need to do two things: Make a `Cargo.toml`
 configuration file, and put our source file in the right place. Let's
@@ -52,14 +53,9 @@ Put this inside:
 name = "hello_world"
 version = "0.0.1"
 authors = [ "Your name <you@example.com>" ]
-
-[[bin]]
-
-name = "hello_world"
 ```
 
-This file is in the [TOML](https://github.com/toml-lang/toml) format. Let's let
-it explain itself to you:
+This file is in the [TOML][toml] format. Let’s let it explain itself to you:
 
 > TOML aims to be a minimal configuration file format that's easy to read due
 > to obvious semantics. TOML is designed to map unambiguously to a hash table.
@@ -68,10 +64,7 @@ it explain itself to you:
 
 TOML is very similar to INI, but with some extra goodies.
 
-Anyway, there are two *tables* in this file: `package` and `bin`. The first
-tells Cargo metadata about your package. The second tells Cargo that we're
-interested in building a binary, not a library (though we could do both!), as
-well as what it is named.
+[toml]: https://github.com/toml-lang/toml
 
 Once you have this file in place, we should be ready to build! Try this:
 
@@ -83,13 +76,32 @@ Hello, world!
 ```
 
 Bam! We build our project with `cargo build`, and run it with
-`./target/debug/hello_world`. This hasn't bought us a whole lot over our simple use
-of `rustc`, but think about the future: when our project has more than one
-file, we would need to call `rustc` more than once and pass it a bunch of options to
-tell it to build everything together. With Cargo, as our project grows, we can
-just `cargo build`, and it'll work the right way. When your project is finally
-ready for release, you can use `cargo build --release` to compile your crates with
-optimizations.
+`./target/debug/hello_world`. We can do both in one step with `cargo run`:
+
+```bash
+$ cargo run
+     Running `target/debug/hello_world`
+Hello, world!
+```
+
+Notice that we didn’t re-build the project this time. Cargo figured out that
+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
+   Compiling hello_world v0.0.1 (file:///home/yourname/projects/hello_world)
+     Running `target/debug/hello_world`
+Hello, world!
+```
+
+This hasn’t bought us a whole lot over our simple use of `rustc`, but think
+about the future: when our project gets more complex, we would need to do more
+things to get all of the parts to properly compile. With Cargo, as our project
+grows, we can just `cargo build`, and it’ll work the right way.
+
+When your project is finally ready for release, you can use
+`cargo build --release` to compile your project with optimizations.
 
 You'll also notice that Cargo has created a new file: `Cargo.lock`.
 
@@ -100,18 +112,25 @@ version = "0.0.1"
 ```
 
 This file is used by Cargo to keep track of dependencies in your application.
-Right now, we don't have any, so it's a bit sparse. You won't ever need
+Right now, we don’t have any, so it’s a bit sparse. You won't ever need
 to touch this file yourself, just let Cargo handle it.
 
-That's it! We've successfully built `hello_world` with Cargo. Even though our
-program is simple, it's using much of the real tooling that you'll use for the
-rest of your Rust career.
+That’s it! We’ve successfully built `hello_world` with Cargo. Even though our
+program is simple, it’s using much of the real tooling that you’ll use for the
+rest of your Rust career. You can expect to do this to get started with
+virtually all Rust projects:
+
+```bash
+$ git clone someurl.com/foo
+$ cd foo
+$ cargo build
+```
 
 ## A New Project
 
-You don't have to go through this whole process every time you want to start a new
-project! Cargo has the ability to make a bare-bones project directory in which you
-can start developing right away.
+You don’t have to go through this whole process every time you want to start a
+new project! Cargo has the ability to make a bare-bones project directory in
+which you can start developing right away.
 
 To start a new project with Cargo, use `cargo new`:
 
@@ -119,8 +138,8 @@ To start a new project with Cargo, use `cargo new`:
 $ cargo new hello_world --bin
 ```
 
-We're passing `--bin` because we're making a binary program: if we
-were making a library, we'd leave it off.
+We’re passing `--bin` because we're making a binary program: if we were making
+a library, we'd leave it off.
 
 Let's check out what Cargo has generated for us:
 
@@ -135,10 +154,10 @@ $ tree .
 1 directory, 2 files
 ```
 
-If you don't have the `tree` command, you can probably get it from your distro's package
-manager. It's not necessary, but it's certainly useful.
+If you don't have the `tree` command, you can probably get it from your
+distribution’s package manager. It’s not necessary, but it’s certainly useful.
 
-This is all we need to get started. First, let's check out `Cargo.toml`:
+This is all we need to get started. First, lets check out `Cargo.toml`:
 
 ```toml
 [package]
@@ -148,11 +167,11 @@ version = "0.0.1"
 authors = ["Your Name <you@example.com>"]
 ```
 
-Cargo has populated this file with reasonable defaults based off the arguments you gave
-it and your `git` global configuration. You may notice that Cargo has also initialized
-the `hello_world` directory as a `git` repository.
+Cargo has populated this file with reasonable defaults based off the arguments
+you gave it and your `git` global configuration. You may notice that Cargo has
+also initialized the `hello_world` directory as a `git` repository.
 
-Here's what's in `src/main.rs`:
+Here’s what’s in `src/main.rs`:
 
 ```rust
 fn main() {
@@ -160,9 +179,20 @@ fn main() {
 }
 ```
 
-Cargo has generated a "Hello World!" for us, and you're ready to start coding! A
-much more in-depth guide to Cargo can be found [here](http://doc.crates.io/guide.html).
+Cargo has generated a "Hello World!" for us, and you’re ready to start coding! Cargo
+has its own [guide][guide] which covers Cargo’s features in much more depth.
 
-Now that you've got the tools down, let's actually learn more about the Rust
+[guide]: http://doc.crates.io/guide.html
+
+Now that you’ve got the tools down, let’s actually learn more about the Rust
 language itself. These are the basics that will serve you well through the rest
 of your time with Rust.
+
+You have two options: Dive into a project with ‘[Learn Rust][learnrust]’, or
+start from the bottom and work your way up with ‘[Syntax and
+Semantics][syntax]’. More experienced systems programmers will probably prefer
+‘Learn Rust’, while those from dynamic backgrounds may enjoy either. Different
+people learn differently! Choose whatever’s right for you.
+
+[learnrust]: learn-rust.html
+[syntax]: syntax-and-semantics.html
index f726f8627c929d24cf240f4b5a4b00e6f5bed732..6c320d27ba6548f234531dbde47ffb4c7abb6f1b 100644 (file)
@@ -1,9 +1,9 @@
 % Hello, world!
 
-Now that you have Rust installed, let's write your first Rust program. It's
+Now that you have Rust installed, let’s write your first Rust program. It’s
 traditional to make your first program in any new language one that prints the
-text "Hello, world!" to the screen. The nice thing about starting with such a
-simple program is that you can verify that your compiler isn't just installed,
+text “Hello, world!” to the screen. The nice thing about starting with such a
+simple program is that you can verify that your compiler isnt just installed,
 but also working properly. And printing information to the screen is a pretty
 common thing to do.
 
@@ -12,38 +12,37 @@ to make a `projects` directory in my home directory, and keep all my projects
 there. Rust does not care where your code lives.
 
 This actually leads to one other concern we should address: this guide will
-assume that you have basic familiarity with the command line. Rust does not
-require that you know a whole ton about the command line, but until the
-language is in a more finished state, IDE support is spotty. Rust makes no
-specific demands on your editing tooling, or where your code lives.
+assume that you have basic familiarity with the command line. Rust itself makes
+no specific demands on your editing tooling, or where your code lives. If you
+prefer an IDE to the command line, you may want to check out
+[SolidOak][solidoak], or wherever plugins are for your favorite IDE. There are
+a number of extensions of varying quality in development by the community. The
+Rust team also ships [plugins for various editors][plugins]. Configuring your
+editor or IDE is out of the scope of this tutorial, so check the documentation
+for your setup, specifically.
 
-With that said, let's make a directory in our projects directory.
+[solidoak]: https://github.com/oakes/SolidOak
+[plugins]: https://github.com/rust-lang/rust/blob/master/src/etc/CONFIGS.md
 
-```{bash}
+With that said, let’s make a directory in our projects directory.
+
+```bash
 $ mkdir ~/projects
 $ cd ~/projects
 $ mkdir hello_world
 $ cd hello_world
 ```
 
-If you're on Windows and not using PowerShell, the `~` may not work. Consult
+If youre on Windows and not using PowerShell, the `~` may not work. Consult
 the documentation for your shell for more details.
 
-Let's make a new source file next. I'm going to use the syntax `editor
-filename` to represent editing a file in these examples, but you should use
-whatever method you want. We'll call our file `main.rs`:
-
-```{bash}
-$ editor main.rs
-```
-
-Rust files always end in a `.rs` extension. If you're using more than one word
-in your filename, use an underscore. `hello_world.rs` rather than
-`helloworld.rs`.
+Let’s make a new source file next. We’ll call our file `main.rs`. Rust files
+always end in a `.rs` extension. If you’re using more than one word in your
+filename, use an underscore: `hello_world.rs` rather than `helloworld.rs`.
 
-Now that you've got your file open, type this in:
+Now that youve got your file open, type this in:
 
-```{rust}
+```rust
 fn main() {
     println!("Hello, world!");
 }
@@ -51,87 +50,90 @@ fn main() {
 
 Save the file, and then type this into your terminal window:
 
-```{bash}
+```bash
 $ rustc main.rs
 $ ./main # or main.exe on Windows
 Hello, world!
 ```
 
-You can also run these examples on [play.rust-lang.org](http://play.rust-lang.org/) by clicking on the arrow that appears in the upper right of the example when you mouse over the code.
-
-Success! Let's go over what just happened in detail.
+Success! Let’s go over what just happened in detail.
 
-```{rust}
+```rust
 fn main() {
 
 }
 ```
 
 These lines define a *function* in Rust. The `main` function is special:
-it's the beginning of every Rust program. The first line says "I'm declaring a
-function named `main`, which takes no arguments and returns nothing." If there
+it's the beginning of every Rust program. The first line says "Im declaring a
+function named `main` which takes no arguments and returns nothing." If there
 were arguments, they would go inside the parentheses (`(` and `)`), and because
-we aren't returning anything from this function, we can omit the return type
-entirely. We'll get to it later.
+we arent returning anything from this function, we can omit the return type
+entirely. Well get to it later.
 
-You'll also note that the function is wrapped in curly braces (`{` and `}`).
+Youll also note that the function is wrapped in curly braces (`{` and `}`).
 Rust requires these around all function bodies. It is also considered good
 style to put the opening curly brace on the same line as the function
 declaration, with one space in between.
 
 Next up is this line:
 
-```{rust}
+```rust
     println!("Hello, world!");
 ```
 
 This line does all of the work in our little program. There are a number of
-details that are important here. The first is that it's indented with four
+details that are important here. The first is that its indented with four
 spaces, not tabs. Please configure your editor of choice to insert four spaces
 with the tab key. We provide some [sample configurations for various
-editors](https://github.com/rust-lang/rust/tree/master/src/etc/CONFIGS.md).
+editors][configs].
+
+[configs]: https://github.com/rust-lang/rust/tree/master/src/etc/CONFIGS.md
 
-The second point is the `println!()` part. This is calling a Rust *macro*,
+The second point is the `println!()` part. This is calling a Rust [macro][macro],
 which is how metaprogramming is done in Rust. If it were a function instead, it
-would look like this: `println()`. For our purposes, we don't need to worry
-about this difference. Just know that sometimes, you'll see a `!`, and that
-means that you're calling a macro instead of a normal function. Rust implements
-`println!` as a macro rather than a function for good reasons, but that's a
-very advanced topic. You'll learn more when we talk about macros later. One
-last thing to mention: Rust's macros are significantly different from C macros,
-if you've used those. Don't be scared of using macros. We'll get to the details
-eventually, you'll just have to trust us for now.
-
-Next, `"Hello, world!"` is a *string*. Strings are a surprisingly complicated
-topic in a systems programming language, and this is a *statically allocated*
-string. We will talk more about different kinds of allocation later. We pass
-this string as an argument to `println!`, which prints the string to the
-screen. Easy enough!
-
-Finally, the line ends with a semicolon (`;`). Rust is an *expression
-oriented* language, which means that most things are expressions. The `;` is
-used to indicate that this expression is over, and the next one is ready to
-begin. Most lines of Rust code end with a `;`. We will cover this in-depth
-later in the guide.
-
-Finally, actually *compiling* and *running* our program. We can compile
-with our compiler, `rustc`, by passing it the name of our source file:
-
-```{bash}
+would look like this: `println()`. For our purposes, we don’t need to worry
+about this difference. Just know that sometimes, you’ll see a `!`, and that
+means that you’re calling a macro instead of a normal function. Rust implements
+`println!` as a macro rather than a function for good reasons, but that's an
+advanced topic. One last thing to mention: Rust’s macros are significantly
+different from C macros, if you’ve used those. Don’t be scared of using macros.
+We’ll get to the details eventually, you’ll just have to trust us for now.
+
+[macro]: macros.html
+
+Next, `"Hello, world!"` is a ‘string’. Strings are a surprisingly complicated
+topic in a systems programming language, and this is a ‘statically allocated’
+string. If you want to read further about allocation, check out [the stack and
+the heap], but you don’t need to right now if you don’t want to. We pass this
+string as an argument to `println!`, which prints the string to the screen.
+Easy enough!
+
+[allocation]: the-stack-and-the-heap.html
+
+Finally, the line ends with a semicolon (`;`). Rust is an ‘expression oriented’
+language, which means that most things are expressions, rather than statements.
+The `;` is used to indicate that this expression is over, and the next one is
+ready to begin. Most lines of Rust code end with a `;`.
+
+Finally, actually compiling and running our program. We can compile with our
+compiler, `rustc`, by passing it the name of our source file:
+
+```bash
 $ rustc main.rs
 ```
 
 This is similar to `gcc` or `clang`, if you come from a C or C++ background. Rust
 will output a binary executable. You can see it with `ls`:
 
-```{bash}
+```bash
 $ ls
 main  main.rs
 ```
 
 Or on Windows:
 
-```{bash}
+```bash
 $ dir
 main.exe  main.rs
 ```
@@ -139,7 +141,7 @@ main.exe  main.rs
 There are now two files: our source code, with the `.rs` extension, and the
 executable (`main.exe` on Windows, `main` everywhere else)
 
-```{bash}
+```bash
 $ ./main  # or main.exe on Windows
 ```
 
@@ -147,15 +149,15 @@ This prints out our `Hello, world!` text to our terminal.
 
 If you come from a dynamically typed language like Ruby, Python, or JavaScript,
 you may not be used to these two steps being separate. Rust is an
-*ahead-of-time compiled language*, which means that you can compile a
-program, give it to someone else, and they don't need to have Rust installed.
-If you give someone a `.rb` or `.py` or `.js` file, they need to have a
+‘ahead-of-time compiled language’, which means that you can compile a program,
+give it to someone else, and they don't need to have Rust installed. If you
+give someone a `.rb` or `.py` or `.js` file, they need to have a
 Ruby/Python/JavaScript implementation installed, but you just need one command
-to both compile and run your program. Everything is a tradeoff in language design,
-and Rust has made its choice.
+to both compile and run your program. Everything is a tradeoff in language
+design, and Rust has made its choice.
 
 Congratulations! You have officially written a Rust program. That makes you a
-Rust programmer! Welcome.
+Rust programmer! Welcome. 🎊🎉👍
 
 Next, I'd like to introduce you to another tool, Cargo, which is used to write
 real-world Rust programs. Just using `rustc` is nice for simple things, but as
index c839688047aa6b28013fbf413da3dfea04ea19f6..e4054a097989d203341f3cbe2d25e6d3f3f29f98 100644 (file)
@@ -1,27 +1,32 @@
 % Installing Rust
 
 The first step to using Rust is to install it! There are a number of ways to
-install Rust, but the easiest is to use the `rustup` script. If you're on
-Linux or a Mac, all you need to do is this (note that you don't need to type
-in the `$`s, they just indicate the start of each command):
+install Rust, but the easiest is to use the `rustup` script. If you're on Linux
+or a Mac, all you need to do is this (note that you don't need to type in the
+`$`s, they just indicate the start of each command):
 
 ```bash
 $ curl -sf -L https://static.rust-lang.org/rustup.sh | sudo sh
 ```
 
-If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`,
-please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script:
+If you're concerned about the [potential insecurity][insecurity] of using `curl
+| sudo sh`, please keep reading and see our disclaimer below. And feel free to
+use a two-step version of the installation and examine our installation script:
 
 ```bash
 $ curl -f -L https://static.rust-lang.org/rustup.sh -O
 $ sudo sh rustup.sh
 ```
 
-If you're on Windows, please download either the [32-bit
-installer](https://static.rust-lang.org/dist/rust-1.0.0-beta-i686-pc-windows-gnu.exe)
-or the [64-bit
-installer](https://static.rust-lang.org/dist/rust-1.0.0-beta-x86_64-pc-windows-gnu.exe)
-and run it.
+[insecurity]: http://curlpipesh.tumblr.com
+
+If you're on Windows, please download either the [32-bit installer][win32] or
+the [64-bit installer][win64] and run it.
+
+[win32]: https://static.rust-lang.org/dist/rust-1.0.0-beta-i686-pc-windows-gnu.msi
+[win64]: https://static.rust-lang.org/dist/rust-1.0.0-beta-x86_64-pc-windows-gnu.msi
+
+## Uninstalling
 
 If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay.
 Not every programming language is great for everyone. Just run the uninstall
@@ -31,22 +36,20 @@ script:
 $ sudo /usr/local/lib/rustlib/uninstall.sh
 ```
 
-If you used the Windows installer, just re-run the `.exe` and it will give you
+If you used the Windows installer, just re-run the `.msi` and it will give you
 an uninstall option.
 
-You can re-run this script any time you want to update Rust. Which, at this
-point, is often. Rust is still pre-1.0, and so people assume that you're using
-a very recent Rust.
+Some people, and somewhat rightfully so, get very upset when we tell you to
+`curl | sudo sh`. Basically, when you do this, you are trusting that the good
+people who maintain Rust aren't going to hack your computer and do bad things.
+That's a good instinct! If you're one of those people, please check out the
+documentation on [building Rust from Source][from source], or [the official
+binary downloads][install page]. And we promise that this method will not be
+the way to install Rust forever: it's just the easiest way to keep people
+updated while Rust is in its alpha state.
 
-This brings me to one other point: some people, and somewhat rightfully so, get
-very upset when we tell you to `curl | sudo sh`. And they should be! Basically,
-when you do this, you are trusting that the good people who maintain Rust
-aren't going to hack your computer and do bad things. That's a good instinct!
-If you're one of those people, please check out the documentation on [building
-Rust from Source](https://github.com/rust-lang/rust#building-from-source), or
-[the official binary downloads](http://www.rust-lang.org/install.html). And we
-promise that this method will not be the way to install Rust forever: it's just
-the easiest way to keep people updated while Rust is in its alpha state.
+[from source]: https://github.com/rust-lang/rust#building-from-source
+[install page]: http://www.rust-lang.org/install.html
 
 Oh, we should also mention the officially supported platforms:
 
@@ -73,7 +76,7 @@ $ rustc --version
 You should see the version number, commit hash, commit date and build date:
 
 ```bash
-rustc 1.0.0-nightly (f11f3e7ba 2015-01-04) (built 2015-01-06)
+rustc 1.0.0-beta (9854143cb 2015-04-02) (built 2015-04-02)
 ```
 
 If you did, Rust has been installed successfully! Congrats!
@@ -84,10 +87,13 @@ On Windows, it's in a `share/doc` directory, inside wherever you installed Rust
 to.
 
 If not, there are a number of places where you can get help. The easiest is
-[the #rust IRC channel on irc.mozilla.org](irc://irc.mozilla.org/#rust), which
-you can access through
-[Mibbit](http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust). 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
-/r/rust subreddit](http://www.reddit.com/r/rust), and [Stack
-Overflow](http://stackoverflow.com/questions/tagged/rust).
+[the #rust IRC channel on irc.mozilla.org][irc], which you can access through
+[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].
+
+[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
index e5482d3fb968185515661fe5f0486b32b8a803fd..3d8ef8090bfb79808745453b8c3b0ca9953fc24b 100644 (file)
@@ -1 +1,4 @@
 % Learn Rust
+
+This section is coming soon! It will eventually have a few tutorials with
+building real Rust projects, but they are under development.
index 1b58b73994dc93d763166638917ce00c91bf71cc..da6985da19f48987c6835ebfc9323f26f2de8655 100644 (file)
@@ -2,7 +2,9 @@
 
 Rust provides three distribution channels for Rust: nightly, beta, and stable.
 Unstable features are only available on nightly Rust. For more details on this
-process, see [this post](http://blog.rust-lang.org/2014/10/30/Stability.html).
+process, see ‘[Stability as a deliverable][stability]’.
+
+[stability]: http://blog.rust-lang.org/2014/10/30/Stability.html
 
 To install nightly Rust, you can use `rustup.sh`:
 
@@ -10,19 +12,24 @@ To install nightly Rust, you can use `rustup.sh`:
 $ curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=nightly
 ```
 
-If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`,
-please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script:
+If you're concerned about the [potential insecurity][insecurity] of using `curl
+| sudo sh`, please keep reading and see our disclaimer below. And feel free to
+use a two-step version of the installation and examine our installation script:
 
 ```bash
 $ curl -f -L https://static.rust-lang.org/rustup.sh -O
-$ sudo sh rustup.sh --channel=nightly
+$ sudo sh rustup.sh
 ```
 
-If you're on Windows, please download either the [32-bit
-installer](https://static.rust-lang.org/dist/rust-nightly-i686-pc-windows-gnu.exe)
-or the [64-bit
-installer](https://static.rust-lang.org/dist/rust-nightly-x86_64-pc-windows-gnu.exe)
-and run it.
+[insecurity]: http://curlpipesh.tumblr.com
+
+If you're on Windows, please download either the [32-bit installer][win32] or
+the [64-bit installer][win64] and run it.
+
+[win32]: https://static.rust-lang.org/dist/rust-1.0.0-beta-i686-pc-windows-gnu.msi
+[win64]: https://static.rust-lang.org/dist/rust-1.0.0-beta-x86_64-pc-windows-gnu.msi
+
+## Uninstalling
 
 If you decide you don't want Rust anymore, we'll be a bit sad, but that's okay.
 Not every programming language is great for everyone. Just run the uninstall
@@ -32,20 +39,64 @@ script:
 $ sudo /usr/local/lib/rustlib/uninstall.sh
 ```
 
-If you used the Windows installer, just re-run the `.exe` and it will give you
+If you used the Windows installer, just re-run the `.msi` and it will give you
 an uninstall option.
 
-You can re-run this script any time you want to update Rust. Which, at this
-point, is often. Rust is still pre-1.0, and so people assume that you're using
-a very recent Rust.
+Some people, and somewhat rightfully so, get very upset when we tell you to
+`curl | sudo sh`. Basically, when you do this, you are trusting that the good
+people who maintain Rust aren't going to hack your computer and do bad things.
+That's a good instinct! If you're one of those people, please check out the
+documentation on [building Rust from Source][from source], or [the official
+binary downloads][install page]. And we promise that this method will not be
+the way to install Rust forever: it's just the easiest way to keep people
+updated while Rust is in its alpha state.
+
+[from source]: https://github.com/rust-lang/rust#building-from-source
+[install page]: http://www.rust-lang.org/install.html
+
+Oh, we should also mention the officially supported platforms:
+
+* Windows (7, 8, Server 2008 R2)
+* Linux (2.6.18 or later, various distributions), x86 and x86-64
+* OSX 10.7 (Lion) or greater, x86 and x86-64
+
+We extensively test Rust on these platforms, and a few others, too, like
+Android. But these are the ones most likely to work, as they have the most
+testing.
+
+Finally, a comment about Windows. Rust considers Windows to be a first-class
+platform upon release, but if we're honest, the Windows experience isn't as
+integrated as the Linux/OS X experience is. We're working on it! If anything
+does not work, it is a bug. Please let us know if that happens. Each and every
+commit is tested against Windows just like any other platform.
+
+If you've got Rust installed, you can open up a shell, and type this:
+
+```bash
+$ rustc --version
+```
+
+You should see the version number, commit hash, commit date and build date:
+
+```bash
+rustc 1.0.0-nightly (f11f3e7ba 2015-01-04) (built 2015-01-06)
+```
+
+If you did, Rust has been installed successfully! Congrats!
+
+This installer also installs a copy of the documentation locally, so you can
+read it offline. On UNIX systems, `/usr/local/share/doc/rust` is the location.
+On Windows, it's in a `share/doc` directory, inside wherever you installed Rust
+to.
 
-This brings me to one other point: some people, and somewhat rightfully so, get
-very upset when we tell you to `curl | sudo sh`. And they should be! Basically,
-when you do this, you are trusting that the good people who maintain Rust
-aren't going to hack your computer and do bad things. That's a good instinct!
-If you're one of those people, please check out the documentation on [building
-Rust from Source](https://github.com/rust-lang/rust#building-from-source), or
-[the official binary downloads](http://www.rust-lang.org/install.html). And we
-promise that this method will not be the way to install Rust forever: it's just
-the easiest way to keep people updated while Rust is in its alpha state.
+If not, there are a number of places where you can get help. The easiest is
+[the #rust IRC channel on irc.mozilla.org][irc], which you can access through
+[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].
 
+[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
index 2878e7ce4754e6a51c6320710bae59039e0fcb14..fcbe2b2f8bf7073f4674c0dde222a3e88bed760d 100644 (file)
@@ -1,3 +1,268 @@
 % Primitive Types
 
-Coming Soon!
+The Rust language has a number of types that are considered ‘primitive’. This
+means that they’re built-in to the language. Rust is structured in such a way
+that the standard library also provides a number of useful types built on top
+of these ones, as well, but these are the most primitive.
+
+# Booleans
+
+Rust has a built in boolean type, named `bool`. It has two values, `true` and `false`:
+
+```rust
+let x = true;
+
+let y: bool = false;
+```
+
+A common use of booleans is in [`if` statements][if].
+
+[if]: if.html
+
+You can find more documentation for `bool`s [in the standard library
+documentation][bool].
+
+[bool]: ../std/primitive.bool.html
+
+# `char`
+
+The `char` type represents a single Unicode scalar value. You can create `char`s
+with a single tick: (`'`)
+
+```rust
+let x = 'x';
+let two_hearts = '💕';
+```
+
+Unlike some other languages, this means that Rust’s `char` is not a single byte,
+but four.
+
+You can find more documentation for `char`s [in the standard library
+documentation][char].
+
+[char]: ../std/primitive.char.html
+
+# Numeric types
+
+Rust has a variety of numeric types in a few categories: signed and unsigned,
+fixed and variable, floating-point and integer.
+
+These types consist of two parts: the category, and the size. For example,
+`u16` is an unsigned type with sixteen bits of size. More bits lets you have
+bigger numbers.
+
+If a number literal has nothing to cause its type to be inferred, it defaults:
+
+```rust
+let x = 42; // x has type i32
+
+let y = 1.0; // y has type f64
+```
+
+Here’s a list of the different numeric types, with links to their documentation
+in the standard library:
+
+* [i16](../std/primitive.i16.html)
+* [i32](../std/primitive.i32.html)
+* [i64](../std/primitive.i64.html)
+* [i8](../std/primitive.i8.html)
+* [u16](../std/primitive.u16.html)
+* [u32](../std/primitive.u32.html)
+* [u64](../std/primitive.u64.html)
+* [u8](../std/primitive.u8.html)
+* [isize](../std/primitive.isize.html)
+* [usize](../std/primitive.usize.html)
+* [f32](../std/primitive.f32.html)
+* [f64](../std/primitive.f64.html)
+
+Let’s go over them by category:
+
+## Signed and Unsigned
+
+Integer types come in two varieties: signed and unsigned. To understand the
+difference, let’s consider a number with four bits of size. A signed, four-bit
+number would let you store numbers from `-8` to `+7`. Signed numbers use
+‘two’s compliment representation’. An unsigned four bit number, since it does
+not need to store negatives, can store values from `0` to `+15`.
+
+Unsigned types use a `u` for their category, and signed types use `i`. The `i`
+is for ‘integer’. So `u8` is an eight-bit unsigned number, and `i8` is an
+eight-bit signed number. 
+
+## Fixed size types
+
+Fixed size types have a specific number of bits in their representation. Valid
+bit sizes are `8`, `16`, `32`, and `64`. So, `u32` is an unsigned, 32-bit integer,
+and `i64` is a signed, 64-bit integer.
+
+## Variable sized types
+
+Rust also provides types whose size depends on the size of a pointer of the
+underlying machine. These types have ‘size’ as the category, and come in signed
+and unsigned varieties. This makes for two types: `isize` and `usize`.
+
+## Floating-point types
+
+Rust also two floating point types: `f32` and `f64`. These correspond to 
+IEEE-754 single and double precision numbers.
+
+# Arrays
+
+Like many programming languages, Rust has list types to represent a sequence of
+things. The most basic is the *array*, a fixed-size list of elements of the
+same type. By default, arrays are immutable.
+
+```rust
+let a = [1, 2, 3]; // a: [i32; 3]
+let mut m = [1, 2, 3]; // m: [i32; 3]
+```
+
+Arrays have type `[T; N]`. We’ll talk about this `T` notation [in the generics
+section][generics]. The `N` is a compile-time constant, for the length of the
+array.
+
+There’s a shorthand for initializing each element of an array to the same
+value. In this example, each element of `a` will be initialized to `0`:
+
+```rust
+let a = [0; 20]; // a: [i32; 20]
+```
+
+You can get the number of elements in an array `a` with `a.len()`:
+
+```rust
+let a = [1, 2, 3];
+
+println!("a has {} elements", a.len());
+```
+
+You can access a particular element of an array with *subscript notation*:
+
+```rust
+let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3]
+
+println!("The second name is: {}", names[1]);
+```
+
+Subscripts start at zero, like in most programming languages, so the first name
+is `names[0]` and the second name is `names[1]`. The above example prints
+`The second name is: Brian`. If you try to use a subscript that is not in the
+array, you will get an error: array access is bounds-checked at run-time. Such
+errant access is the source of many bugs in other systems programming
+languages.
+
+You can find more documentation for `array`s [in the standard library
+documentation][array].
+
+[array]: ../std/primitive.array.html
+
+# Slices
+
+A ‘slice’ is a reference to (or “view” into) another data structure. They are
+useful for allowing safe, efficient access to a portion of an array without
+copying. For example, you might want to reference just one line of a file read
+into memory. By nature, a slice is not created directly, but from an existing
+variable. Slices have a length, can be mutable or not, and in many ways behave
+like arrays:
+
+```rust
+let a = [0, 1, 2, 3, 4];
+let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
+```
+
+Slices have type `&[T]`. We’ll talk about that `T` when we cover
+[generics][generics].
+
+[generics]: generics.html
+
+You can find more documentation for `slices`s [in the standard library
+documentation][slice].
+
+[slice]: ../std/primitive.slice.html
+
+# `str`
+
+Rust’s `str` type is the most primitive string type. As an [unsized type][dst],
+it’s not very useful by itself, but becomes useful when placed behind a reference,
+like [`&str`][strings]. As such, we’ll just leave it at that.
+
+[dst]: unsized-types.html
+[strings]: strings.html
+
+You can find more documentation for `str` [in the standard library
+documentation][str].
+
+[str]: ../std/primitive.str.html
+
+# Tuples
+
+A tuple is an ordered list of fixed size. Like this:
+
+```rust
+let x = (1, "hello");
+```
+
+The parentheses and commas form this two-length tuple. Here’s the same code, but
+with the type annotated:
+
+```rust
+let x: (i32, &str) = (1, "hello");
+```
+
+As you can see, the type of a tuple looks just like the tuple, but with each
+position having a type name rather than the value. Careful readers will also
+note that tuples are heterogeneous: we have an `i32` and a `&str` in this tuple.
+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 access the fields in a tuple through a *destructuring let*. Here’s
+an example:
+
+```rust
+let (x, y, z) = (1, 2, 3);
+
+println!("x is {}", x);
+```
+
+Remember [before][let] when I said the left-hand side of a `let` statement was more
+powerful than just assigning a binding? Here we are. We can put a pattern on
+the left-hand side of the `let`, and if it matches up to the right-hand side,
+we can assign multiple bindings at once. In this case, `let` "destructures,"
+or "breaks up," the tuple, and assigns the bits to three bindings.
+
+[let]: variable-bindings.html
+
+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.
+
+[arity]: glossary.html#arity
+
+```rust
+let mut x = (1, 2); // x: (i32, i32)
+let y = (2, 3); // y: (i32, i32)
+
+x = y;
+```
+
+You can find more documentation for tuples [in the standard library
+documentation][tuple].
+
+[tuple]: ../std/primitive.tuple.html
+
+# Functions
+
+Functions also have a type! They look like this:
+
+```
+fn foo(x: i32) -> i32 { x }
+
+let x: fn(i32) -> i32 = foo;
+```
+
+In this case, `x` is a ‘function pointer’ to a function that takes an `i32` and
+returns an `i32`.
diff --git a/src/doc/trpl/slices.md b/src/doc/trpl/slices.md
deleted file mode 100644 (file)
index a31c0ac..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-% Slices
-
-A *slice* is a reference to (or "view" into) an array. They are useful for
-allowing safe, efficient access to a portion of an array without copying. For
-example, you might want to reference just one line of a file read into memory.
-By nature, a slice is not created directly, but from an existing variable.
-Slices have a length, can be mutable or not, and in many ways behave like
-arrays:
-
-```{rust}
-let a = [0, 1, 2, 3, 4];
-let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3
-
-for e in middle.iter() {
-    println!("{}", e); // Prints 1, 2, 3
-}
-```
-
-You can also take a slice of a vector, `String`, or `&str`, because they are
-backed by arrays. Slices have type `&[T]`, which we'll talk about when we cover
-generics.
index 6f992cf6887362ac5b0b653311808f13038381db..cce985c9e484c1436179e5773e396b47a35ecad4 100644 (file)
@@ -1 +1,10 @@
 % Syntax and Semantics
+
+This section breaks Rust down into small chunks, one for each concept.
+
+If you’d like to learn Rust from the bottom up, reading this in order is a
+great way to do that.
+
+These sections also form a reference for each concept, so if you’re reading
+another tutorial and find something confusing, you can find it explained
+somewhere in here.
diff --git a/src/doc/trpl/tuples.md b/src/doc/trpl/tuples.md
deleted file mode 100644 (file)
index dd526d0..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-% Tuples
-
-The first compound data type we're going to talk about is called the *tuple*.
-A tuple is an ordered list of fixed size. Like this:
-
-```rust
-let x = (1, "hello");
-```
-
-The parentheses and commas form this two-length tuple. Here's the same code, but
-with the type annotated:
-
-```rust
-let x: (i32, &str) = (1, "hello");
-```
-
-As you can see, the type of a tuple looks just like the tuple, but with each
-position having a type name rather than the value. Careful readers will also
-note that tuples are heterogeneous: we have an `i32` and a `&str` in this tuple.
-You have briefly seen `&str` used as a type before, and we'll discuss the
-details of strings later. 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 access the fields in a tuple through a *destructuring let*. Here's
-an example:
-
-```rust
-let (x, y, z) = (1, 2, 3);
-
-println!("x is {}", x);
-```
-
-Remember before when I said the left-hand side of a `let` statement was more
-powerful than just assigning a binding? Here we are. We can put a pattern on
-the left-hand side of the `let`, and if it matches up to the right-hand side,
-we can assign multiple bindings at once. In this case, `let` "destructures,"
-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.
-
-```rust
-let mut x = (1, 2); // x: (i32, i32)
-let y = (2, 3); // y: (i32, i32)
-
-x = y;
-```
-
-You can also check for equality with `==`. Again, this will only compile if the
-tuples have the same type.
-
-```rust
-let x = (1, 2, 3);
-let y = (2, 2, 4);
-
-if x == y {
-    println!("yes");
-} else {
-    println!("no");
-}
-```
-
-This will print `no`, because some of the values aren't equal.
-
-Note that the order of the values is considered when checking for equality,
-so the following example will also print `no`.
-
-```rust
-let x = (1, 2, 3);
-let y = (2, 1, 3);
-
-if x == y {
-    println!("yes");
-} else {
-    println!("no");
-}
-```
-
-One other use of tuples is to return multiple values from a function:
-
-```rust
-fn next_two(x: i32) -> (i32, i32) { (x + 1, x + 2) }
-
-fn main() {
-    let (x, y) = next_two(5);
-    println!("x, y = {}, {}", x, y);
-}
-```
-
-Even though Rust functions can only return one value, a tuple *is* one value,
-that happens to be made up of more than one value. You can also see in this
-example how you can destructure a pattern returned by a function, as well.
index 88babd8659c2bb44a24e73f7825d292f1ba57b40..d971e557a9a2edba517ad91e859e4b8675f46ea3 100644 (file)
@@ -1,44 +1,48 @@
 % Variable Bindings
 
-The first thing we'll learn about are *variable bindings*. They look like this:
+Vitually every non-’Hello World’ Rust program uses *variable bindings*. They
+look like this:
 
-```{rust}
+```rust
 fn main() {
     let x = 5;
 }
 ```
 
-Putting `fn main() {` in each example is a bit tedious, so we'll leave that out
-in the future. If you're following along, make sure to edit your `main()`
-function, rather than leaving it off. Otherwise, you'll get an error.
+Putting `fn main() {` in each example is a bit tedious, so well leave that out
+in the future. If youre following along, make sure to edit your `main()`
+function, rather than leaving it off. Otherwise, youll get an error.
 
-In many languages, this is called a *variable*. But Rust's variable bindings
-have a few tricks up their sleeves. Rust has a very powerful feature called
-*pattern matching* that we'll get into detail with later, but the left
-hand side of a `let` expression is a full pattern, not just a variable name.
-This means we can do things like:
+In many languages, this is called a *variable*, but Rust’s variable bindings
+have a few tricks up their sleeves. For example the left-hand side of a `let`
+expression is a ‘[pattern][pattern]’, not just a variable name. This means we
+can do things like:
 
-```{rust}
+```rust
 let (x, y) = (1, 2);
 ```
 
 After this expression is evaluated, `x` will be one, and `y` will be two.
-Patterns are really powerful, but this is about all we can do with them so far.
-So let's just keep this in the back of our minds as we go forward.
+Patterns are really powerful, and have [their own section][pattern] in the
+book. We don’t need those features for now, so we’ll just keep this in the back
+of our minds as we go forward.
+
+[pattern]: patterns.html
 
 Rust is a statically typed language, which means that we specify our types up
-front. So why does our first example compile? Well, Rust has this thing called
-*type inference*. If it can figure out what the type of something is, Rust
-doesn't require you to actually type it out.
+front, and they’re checked at compile time. So why does our first example
+compile? Well, Rust has this thing called ‘type inference’. If it can figure
+out what the type of something is, Rust doesn’t require you to actually type it
+out.
 
 We can add the type if we want to, though. Types come after a colon (`:`):
 
-```{rust}
+```rust
 let x: i32 = 5;
 ```
 
-If I asked you to read this out loud to the rest of the class, you'd say "`x`
-is a binding with the type `i32` and the value `five`."
+If I asked you to read this out loud to the rest of the class, you’d say “`x`
+is a binding with the type `i32` and the value `five`.
 
 In this case we chose to represent `x` as a 32-bit signed integer. Rust has
 many different primitive integer types. They begin with `i` for signed integers
@@ -48,19 +52,20 @@ bits.
 In future examples, we may annotate the type in a comment. The examples will
 look like this:
 
-```{rust}
+```rust
 fn main() {
     let x = 5; // x: i32
 }
 ```
 
-Note the similarities between this annotation and the syntax you use with `let`.
-Including these kinds of comments is not idiomatic Rust, but we'll occasionally
-include them to help you understand what the types that Rust infers are.
+Note the similarities between this annotation and the syntax you use with
+`let`. Including these kinds of comments is not idiomatic Rust, but we'll
+occasionally include them to help you understand what the types that Rust
+infers are.
 
 By default, bindings are *immutable*. This code will not compile:
 
-```{ignore}
+```rust,ignore
 let x = 5;
 x = 10;
 ```
@@ -75,30 +80,30 @@ error: re-assignment of immutable variable `x`
 
 If you want a binding to be mutable, you can use `mut`:
 
-```{rust}
+```rust
 let mut x = 5; // mut x: i32
 x = 10;
 ```
 
 There is no single reason that bindings are immutable by default, but we can
-think about it through one of Rust's primary focuses: safety. If you forget to
+think about it through one of Rusts primary focuses: safety. If you forget to
 say `mut`, the compiler will catch it, and let you know that you have mutated
 something you may not have intended to mutate. If bindings were mutable by
 default, the compiler would not be able to tell you this. If you _did_ intend
 mutation, then the solution is quite easy: add `mut`.
 
-There are other good reasons to avoid mutable state when possible, but they're
+There are other good reasons to avoid mutable state when possible, but theyre
 out of the scope of this guide. In general, you can often avoid explicit
 mutation, and so it is preferable in Rust. That said, sometimes, mutation is
-what you need, so it's not verboten.
+what you need, so its not verboten.
 
-Let's get back to bindings. Rust variable bindings have one more aspect that
+Lets get back to bindings. Rust variable bindings have one more aspect that
 differs from other languages: bindings are required to be initialized with a
 value before you're allowed to use them.
 
-Let's try it out. Change your `src/main.rs` file to look like this:
+Lets try it out. Change your `src/main.rs` file to look like this:
 
-```{rust}
+```rust
 fn main() {
     let x: i32;
 
@@ -106,21 +111,22 @@ fn main() {
 }
 ```
 
-You can use `cargo build` on the command line to build it. You'll get a warning,
-but it will still print "Hello, world!":
+You can use `cargo build` on the command line to build it. You’ll get a
+warning, but it will still print "Hello, world!":
 
 ```text
    Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
-src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
+src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)]
+   on by default
 src/main.rs:2     let x: i32;
                       ^
 ```
 
-Rust warns us that we never use the variable binding, but since we never use it,
-no harm, no foul. Things change if we try to actually use this `x`, however. Let's
-do that. Change your program to look like this:
+Rust warns us that we never use the variable binding, but since we never use
+it, no harm, no foul. Things change if we try to actually use this `x`,
+however. Let’s do that. Change your program to look like this:
 
-```{rust,ignore}
+```rust,ignore
 fn main() {
     let x: i32;
 
@@ -128,9 +134,9 @@ fn main() {
 }
 ```
 
-And try to build it. You'll get an error:
+And try to build it. Youll get an error:
 
-```{bash}
+```bash
 $ cargo build
    Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
 src/main.rs:4:39: 4:40 error: use of possibly uninitialized variable: `x`
@@ -144,18 +150,20 @@ error: aborting due to previous error
 Could not compile `hello_world`.
 ```
 
-Rust will not let us use a value that has not been initialized. Next, let's
+Rust will not let us use a value that has not been initialized. Next, lets
 talk about this stuff we've added to `println!`.
 
 If you include two curly braces (`{}`, some call them moustaches...) in your
 string to print, Rust will interpret this as a request to interpolate some sort
 of value. *String interpolation* is a computer science term that means "stick
 in the middle of a string." We add a comma, and then `x`, to indicate that we
-want `x` to be the value we're interpolating. The comma is used to separate
-arguments we pass to functions and macros, if you're passing more than one.
-
-When you just use the curly braces, Rust will attempt to display the
-value in a meaningful way by checking out its type. If you want to specify the
-format in a more detailed manner, there are a [wide number of options
-available](../std/fmt/index.html). For now, we'll just stick to the default:
-integers aren't very complicated to print.
+want `x` to be the value we’re interpolating. The comma is used to separate
+arguments we pass to functions and macros, if you’re passing more than one.
+
+When you just use the curly braces, Rust will attempt to display the value in a
+meaningful way by checking out its type. If you want to specify the format in a
+more detailed manner, there are a [wide number of options available][format].
+For now, we'll just stick to the default: integers aren't very complicated to
+print.
+
+[format]: ../std/fmt/index.html
index a212e3a04357eccc564097ab90b203d1afc38a8f..2acee8a97f59f344a57f65f3b7fac89f0bf79d36 100644 (file)
@@ -186,7 +186,8 @@ def concat_multi_lines(f):
 
         firstlineno = firstlineno or lineno
         if line.endswith('\\'):
-            lastline = line[:-1]
+            if lastline is None:
+                lastline = line[:-1]
             catenated += line[:-1]
         else:
             yield firstlineno, catenated + line
diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh
deleted file mode 100755 (executable)
index 7c20738..0000000
+++ /dev/null
@@ -1,615 +0,0 @@
-#!/bin/sh
-# 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 <LICENSE-APACHE or
-# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-# option. This file may not be copied, modified, or distributed
-# except according to those terms.
-
-
-msg() {
-    echo "rustup: $1"
-}
-
-step_msg() {
-    msg
-    msg "$1"
-    msg
-}
-
-warn() {
-    echo "rustup: WARNING: $1"
-}
-
-err() {
-    echo "rustup: error: $1"
-    exit 1
-}
-
-need_ok() {
-    if [ $? -ne 0 ]
-    then
-        err "$1"
-    fi
-}
-
-
-putvar() {
-    local T
-    eval T=\$$1
-    eval TLEN=\${#$1}
-    if [ $TLEN -gt 35 ]
-    then
-        printf "rustup: %-20s := %.35s ...\n" $1 "$T"
-    else
-        printf "rustup: %-20s := %s %s\n" $1 "$T" "$2"
-    fi
-}
-
-probe() {
-    local V=$1
-    shift
-    local P
-    local T
-    for P
-    do
-        T=$(which $P 2>&1)
-        if [ $? -eq 0 ]
-        then
-            VER0=$($P --version 2>/dev/null | head -1 \
-                |  sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
-            if [ $? -eq 0 -a "x${VER0}" != "x" ]
-            then
-              VER="($VER0)"
-            else
-              VER=""
-            fi
-            break
-        else
-            VER=""
-            T=""
-        fi
-    done
-    eval $V=\$T
-    putvar $V "$VER"
-}
-
-probe_need() {
-    local V=$1
-    probe $*
-    eval VV=\$$V
-    if [ -z "$VV" ]
-    then
-        err "needed, but unable to find any of: $*"
-    fi
-}
-
-
-valopt() {
-    VAL_OPTIONS="$VAL_OPTIONS $1"
-
-    local OP=$1
-    local DEFAULT=$2
-    shift
-    shift
-    local DOC="$*"
-    if [ $HELP -eq 0 ]
-    then
-        local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
-        local V="CFG_${UOP}"
-        eval $V="$DEFAULT"
-        for arg in $CFG_ARGS
-        do
-            if echo "$arg" | grep -q -- "--$OP="
-            then
-                val=$(echo "$arg" | cut -f2 -d=)
-                eval $V=$val
-            fi
-        done
-        putvar $V
-    else
-        if [ -z "$DEFAULT" ]
-        then
-            DEFAULT="<none>"
-        fi
-        OP="${OP}=[${DEFAULT}]"
-        printf "    --%-30s %s\n" "$OP" "$DOC"
-    fi
-}
-
-opt() {
-    BOOL_OPTIONS="$BOOL_OPTIONS $1"
-
-    local OP=$1
-    local DEFAULT=$2
-    shift
-    shift
-    local DOC="$*"
-    local FLAG=""
-
-    if [ $DEFAULT -eq 0 ]
-    then
-        FLAG="enable"
-    else
-        FLAG="disable"
-        DOC="don't $DOC"
-    fi
-
-    if [ $HELP -eq 0 ]
-    then
-        for arg in $CFG_ARGS
-        do
-            if [ "$arg" = "--${FLAG}-${OP}" ]
-            then
-                OP=$(echo $OP | tr 'a-z-' 'A-Z_')
-                FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
-                local V="CFG_${FLAG}_${OP}"
-                eval $V=1
-                putvar $V
-            fi
-        done
-    else
-        if [ ! -z "$META" ]
-        then
-            OP="$OP=<$META>"
-        fi
-        printf "    --%-30s %s\n" "$FLAG-$OP" "$DOC"
-     fi
-}
-
-flag() {
-    BOOL_OPTIONS="$BOOL_OPTIONS $1"
-
-    local OP=$1
-    shift
-    local DOC="$*"
-
-    if [ $HELP -eq 0 ]
-    then
-        for arg in $CFG_ARGS
-        do
-            if [ "$arg" = "--${OP}" ]
-            then
-                OP=$(echo $OP | tr 'a-z-' 'A-Z_')
-                local V="CFG_${OP}"
-                eval $V=1
-                putvar $V
-            fi
-        done
-    else
-        if [ ! -z "$META" ]
-        then
-            OP="$OP=<$META>"
-        fi
-        printf "    --%-30s %s\n" "$OP" "$DOC"
-     fi
-}
-
-validate_opt() {
-    for arg in $CFG_ARGS
-    do
-        isArgValid=0
-        for option in $BOOL_OPTIONS
-        do
-            if test --disable-$option = $arg
-            then
-                isArgValid=1
-            fi
-            if test --enable-$option = $arg
-            then
-                isArgValid=1
-            fi
-            if test --$option = $arg
-            then
-                isArgValid=1
-            fi
-        done
-        for option in $VAL_OPTIONS
-        do
-            if echo "$arg" | grep -q -- "--$option="
-            then
-                isArgValid=1
-            fi
-        done
-        if [ "$arg" = "--help" ]
-        then
-            echo
-            echo "No more help available for Configure options,"
-            echo "check the Wiki or join our IRC channel"
-            break
-        else
-            if test $isArgValid -eq 0
-            then
-                err "Option '$arg' is not recognized"
-            fi
-        fi
-    done
-}
-
-create_tmp_dir() {
-    local TMP_DIR=`pwd`/rustup-tmp-install
-
-    rm -Rf "${TMP_DIR}"
-    need_ok "failed to remove temporary installation directory"
-
-    mkdir -p "${TMP_DIR}"
-    need_ok "failed to create create temporary installation directory"
-
-    echo $TMP_DIR
-}
-
-# Make `tr` locale independent
-LC_CTYPE=C
-
-probe_need CFG_CURL  curl
-probe_need CFG_TAR   tar
-probe_need CFG_FILE  file
-
-probe CFG_SHA256SUM sha256sum
-probe CFG_SHASUM shasum
-
-if [ -z "$CFG_SHA256SUM" -a -z "$CFG_SHASUM" ]; then
-    err "unable to find either sha256sum or shasum"
-fi
-
-calculate_hash() {
-    if [ -n "$CFG_SHA256SUM" ]; then
-        ${CFG_SHA256SUM} $@
-    else
-        ${CFG_SHASUM} -a 256 $@
-    fi
-}
-
-CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
-CFG_SELF="$0"
-CFG_ARGS="$@"
-
-HELP=0
-if [ "$1" = "--help" ]
-then
-    HELP=1
-    shift
-    echo
-    echo "Usage: $CFG_SELF [options]"
-    echo
-    echo "Options:"
-    echo
-else
-    step_msg "processing $CFG_SELF args"
-fi
-
-OPTIONS=""
-BOOL_OPTIONS=""
-VAL_OPTIONS=""
-
-flag uninstall "only uninstall from the installation prefix"
-valopt prefix "${RUSTUP_PREFIX}" "set installation prefix"
-valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly"
-valopt channel "beta" "use the selected release channel [beta]"
-flag save "save the downloaded nightlies to ~/.rustup"
-
-if [ $HELP -eq 1 ]
-then
-    echo
-    exit 0
-fi
-
-step_msg "validating $CFG_SELF args"
-validate_opt
-
-
-# Platform detection copied from `configure`
-
-CFG_OSTYPE=$(uname -s)
-CFG_CPUTYPE=$(uname -m)
-
-if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
-then
-    # Darwin's `uname -m` lies and always returns i386. We have to use sysctl
-    # instead.
-    if sysctl hw.optional.x86_64 | grep -q ': 1'
-    then
-        CFG_CPUTYPE=x86_64
-    fi
-fi
-
-# The goal here is to come up with the same triple as LLVM would,
-# at least for the subset of platforms we're willing to target.
-
-case $CFG_OSTYPE in
-
-    Linux)
-        CFG_OSTYPE=unknown-linux-gnu
-        ;;
-
-    FreeBSD)
-        CFG_OSTYPE=unknown-freebsd
-        ;;
-
-    Darwin)
-        CFG_OSTYPE=apple-darwin
-        ;;
-
-    MINGW32*)
-        CFG_OSTYPE=pc-mingw32
-        ;;
-# Thad's Cygwin identifiers below
-
-#   Vista 32 bit
-    CYGWIN_NT-6.0)
-        CFG_OSTYPE=pc-mingw32
-        CFG_CPUTYPE=i686
-        ;;
-
-#   Vista 64 bit
-    CYGWIN_NT-6.0-WOW64)
-        CFG_OSTYPE=w64-mingw32
-        CFG_CPUTYPE=x86_64
-        ;;
-
-#   Win 7 32 bit
-    CYGWIN_NT-6.1)
-        CFG_OSTYPE=pc-mingw32
-        CFG_CPUTYPE=i686
-        ;;
-
-#   Win 7 64 bit
-    CYGWIN_NT-6.1-WOW64)
-        CFG_OSTYPE=w64-mingw32
-        CFG_CPUTYPE=x86_64
-        ;;
-
-# We do not detect other OS such as XP/2003 using 64 bit using uname.
-# If we want to in the future, we will need to use Cygwin
-# Chuck's csih helper in /usr/lib/csih/winProductName.exe or alternative.
-    *)
-        err "unknown OS type: $CFG_OSTYPE"
-        ;;
-esac
-
-
-case $CFG_CPUTYPE in
-
-    i386 | i486 | i686 | i786 | x86)
-        CFG_CPUTYPE=i686
-        ;;
-
-    xscale | arm)
-        CFG_CPUTYPE=arm
-        ;;
-
-    x86_64 | x86-64 | x64 | amd64)
-        CFG_CPUTYPE=x86_64
-        ;;
-
-    *)
-        err "unknown CPU type: $CFG_CPUTYPE"
-esac
-
-# Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
-if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
-then
-    "${CFG_FILE}" -L "$SHELL" | grep -q "x86[_-]64"
-    if [ $? != 0 ]; then
-        CFG_CPUTYPE=i686
-    fi
-fi
-
-HOST_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"
-
-# Is this a triple we have nightlies for?
-case $HOST_TRIPLE in
-
-        x86_64-unknown-linux-gnu)
-                ;;
-
-        i686-unknown-linux-gnu)
-                ;;
-
-        x86_64-apple-darwin)
-                ;;
-
-        i686-apple-darwin)
-                ;;
-
-        *)
-                err "rustup.sh doesn't work for host $HOST_TRIPLE"
-
-esac
-
-msg "host triple: ${HOST_TRIPLE}"
-
-CFG_INSTALL_FLAGS=""
-if [ -n "${CFG_UNINSTALL}" ]
-then
-    CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --uninstall"
-fi
-
-if [ -n "${CFG_PREFIX}" ]
-then
-    CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --prefix=${CFG_PREFIX}"
-fi
-
-CFG_TMP_DIR=$(mktemp -d 2>/dev/null \
-           || mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
-           || create_tmp_dir)
-
-# If we're saving nightlies and we didn't specify which one, grab the latest
-# version from the perspective of the server. Buildbot has typically finished
-# building and uploading by ~8UTC, but we want to include a little buffer.
-#
-# FIXME It would be better to use the known most recent nightly that has been
-# built. This is waiting on a change to have buildbot publish metadata that
-# can be queried.
-if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ];
-then
-    CFG_DATE=`TZ=Etc/UTC+9 date "+%Y-%m-%d"`
-fi
-
-RUST_URL="https://static.rust-lang.org/dist"
-case "$CFG_CHANNEL" in
-    nightly)
-        # add a date suffix if we want a particular nightly.
-        if [ -n "${CFG_DATE}" ];
-        then
-            RUST_URL="${RUST_URL}/${CFG_DATE}"
-        fi
-
-        RUST_PACKAGE_NAME=rust-nightly
-        ;;
-    beta)
-        RUST_PACKAGE_NAME=rust-1.0.0-beta
-        ;;
-    *)
-        err "Currently 'beta' and 'nightly' are the only supported channels"
-esac
-
-RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
-RUST_TARBALL_NAME="${RUST_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
-RUST_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${RUST_PACKAGE_NAME_AND_TRIPLE}"
-RUST_LOCAL_INSTALL_SCRIPT="${RUST_LOCAL_INSTALL_DIR}/install.sh"
-
-download_hash() {
-    msg "Downloading ${remote_sha256}"
-    remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
-    if [ -n "${CFG_SAVE}" ]; then
-        echo "${remote_sha256}" > "${local_sha_file}"
-    fi
-    if [ "$?" -ne 0 ]; then
-        rm -Rf "${CFG_TMP_DIR}"
-        err "Failed to download ${remote_url}"
-    fi
-}
-
-verify_hash() {
-    remote_sha256="$1"
-    local_file="$2"
-    local_sha_file="${local_file}.sha256"
-
-    if [ -n "${CFG_SAVE}" ]; then
-        if [ -f "${local_sha_file}" ]; then
-            msg "Local ${local_sha_file} exists, treating as remote hash"
-            remote_sha256=`cat "${local_sha_file}"`
-        else
-            download_hash
-        fi
-    else
-        download_hash
-    fi
-
-    msg "Verifying hash"
-    local_sha256=$(calculate_hash "${local_file}")
-    if [ "$?" -ne 0 ]; then
-        rm -Rf "${CFG_TMP_DIR}"
-        err "Failed to compute hash for ${local_tarball}"
-    fi
-
-    # We only need the sha, not the filenames
-    remote_sha256=`echo ${remote_sha256} | cut -f 1 -d ' '`
-    local_sha256=`echo ${local_sha256} | cut -f 1 -d ' '`
-
-    if [ "${remote_sha256}" != "${local_sha256}" ]; then
-        rm -Rf "${CFG_TMP_DIR}"
-        errmsg="invalid sha256.\n"
-        errmsg="$errmsg ${remote_sha256}\t${remote_tarball}\n"
-        errmsg="$errmsg ${local_sha256}\t${local_tarball}"
-        err "$errmsg"
-    fi
-}
-
-# Fetch the package. Optionally caches the tarballs.
-download_package() {
-    remote_tarball="$1"
-    local_tarball="$2"
-    remote_sha256="${remote_tarball}.sha256"
-
-    # Check if we've already downloaded this file.
-    if [ -e "${local_tarball}.tmp" ]; then
-        msg "Resuming ${remote_tarball} to ${local_tarball}"
-
-        "${CFG_CURL}" -f -C - -o "${local_tarball}.tmp" "${remote_tarball}"
-        if [ $? -ne 0 ]
-        then
-            rm -Rf "${CFG_TMP_DIR}"
-            err "failed to download installer"
-        fi
-
-        mv "${local_tarball}.tmp" "${local_tarball}"
-    elif [ ! -e "${local_tarball}" ]; then
-        msg "Downloading ${remote_tarball} to ${local_tarball}"
-
-        "${CFG_CURL}" -f -o "${local_tarball}.tmp" "${remote_tarball}"
-        if [ $? -ne 0 ]
-        then
-            rm -Rf "${CFG_TMP_DIR}"
-            err "failed to download installer"
-        fi
-
-        mv "${local_tarball}.tmp" "${local_tarball}"
-    fi
-
-    verify_hash "${remote_sha256}" "${local_tarball}"
-}
-
-# Wrap all the commands needed to install a package.
-install_package() {
-    local_tarball="$1"
-    install_script="$2"
-
-    msg "Extracting ${local_tarball}"
-    (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${local_tarball}")
-    if [ $? -ne 0 ]; then
-        rm -Rf "${CFG_TMP_DIR}"
-        err "failed to unpack installer"
-    fi
-
-    sh "${install_script}" "${CFG_INSTALL_FLAGS}"
-    if [ $? -ne 0 ]
-    then
-        rm -Rf "${CFG_TMP_DIR}"
-        err "failed to install Rust"
-    fi
-}
-
-# It's possible that curl could be interrupted partway though downloading
-# `rustup.sh`, truncating the file. This could be especially bad if we were in
-# the middle of a line that would run "rm -rf ". To protect against this, we
-# wrap up the `rustup.sh` destructive functionality in this helper function,
-# which we call as the last thing we do. This means we will not do anything
-# unless we have the entire file downloaded.
-install_packages() {
-    rm -Rf "${CFG_TMP_DIR}"
-    need_ok "failed to remove temporary installation directory"
-
-    mkdir -p "${CFG_TMP_DIR}"
-    need_ok "failed to create create temporary installation directory"
-
-    # If we're saving our nightlies, put them in $HOME/.rustup.
-    if [ -n "${CFG_SAVE}" ]
-    then
-        RUST_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_DATE}"
-    else
-        RUST_DOWNLOAD_DIR="${CFG_TMP_DIR}"
-    fi
-
-    mkdir -p "${RUST_DOWNLOAD_DIR}"
-    need_ok "failed to create create download directory"
-
-    RUST_LOCAL_TARBALL="${RUST_DOWNLOAD_DIR}/${RUST_TARBALL_NAME}"
-
-    download_package \
-        "${RUST_URL}/${RUST_TARBALL_NAME}" \
-        "${RUST_LOCAL_TARBALL}"
-
-    install_package \
-        "${RUST_LOCAL_TARBALL}" \
-        "${RUST_LOCAL_INSTALL_SCRIPT}"
-
-    rm -Rf "${CFG_TMP_DIR}"
-    need_ok "couldn't rm temporary installation directory"
-}
-
-install_packages
index 4503ad14e92b49b9bea7b625a31289c131771fae..7332bf4670ae58efd9ce4c42a7143b2e6fc6d31c 100644 (file)
@@ -39,7 +39,7 @@
 /// Borrow<Vec<T>>` and `Vec<T>: Borrow<[T]>`.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait Borrow<Borrowed: ?Sized> {
-    /// Immutably borrow from an owned value.
+    /// Immutably borrows from an owned value.
     ///
     /// # Examples
     ///
@@ -67,7 +67,7 @@ pub trait Borrow<Borrowed: ?Sized> {
 /// Similar to `Borrow`, but for mutable borrows.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait BorrowMut<Borrowed: ?Sized> : Borrow<Borrowed> {
-    /// Mutably borrow from an owned value.
+    /// Mutably borrows from an owned value.
     ///
     /// # Examples
     ///
@@ -126,7 +126,7 @@ fn borrow(&self) -> &B {
     }
 }
 
-/// A generalization of Clone to borrowed data.
+/// A generalization of `Clone` to borrowed data.
 ///
 /// Some types make it possible to go from borrowed to owned, usually by
 /// implementing the `Clone` trait. But `Clone` works only for going from `&T`
@@ -137,7 +137,7 @@ pub trait ToOwned {
     #[stable(feature = "rust1", since = "1.0.0")]
     type Owned: Borrow<Self>;
 
-    /// Create owned data from borrowed data, usually by copying.
+    /// Creates owned data from borrowed data, usually by cloning.
     #[stable(feature = "rust1", since = "1.0.0")]
     fn to_owned(&self) -> Self::Owned;
 }
@@ -155,9 +155,9 @@ fn to_owned(&self) -> T { self.clone() }
 /// data lazily when mutation or ownership is required. The type is designed to
 /// work with general borrowed data via the `Borrow` trait.
 ///
-/// `Cow` implements both `Deref`, which means that you can call
+/// `Cow` implements `Deref`, which means that you can call
 /// non-mutating methods directly on the data it encloses. If mutation
-/// is desired, `to_mut` will obtain a mutable references to an owned
+/// is desired, `to_mut` will obtain a mutable reference to an owned
 /// value, cloning if necessary.
 ///
 /// # Examples
@@ -200,7 +200,7 @@ fn clone(&self) -> Cow<'a, B> {
 }
 
 impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
-    /// Acquire a mutable reference to the owned form of the data.
+    /// Acquires a mutable reference to the owned form of the data.
     ///
     /// Copies the data if it is not already owned.
     ///
@@ -226,7 +226,7 @@ pub fn to_mut(&mut self) -> &mut <B as ToOwned>::Owned {
         }
     }
 
-    /// Extract the owned data.
+    /// Extracts the owned data.
     ///
     /// Copies the data if it is not already owned.
     ///
@@ -327,7 +327,7 @@ fn hash<H: Hasher>(&self, state: &mut H) {
     }
 }
 
-/// Trait for moving into a `Cow`
+/// Trait for moving into a `Cow`.
 #[unstable(feature = "into_cow", reason = "may be replaced by `convert::Into`")]
 pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
     /// Moves `self` into `Cow`
index 687675f12ef64ff447432ac6302197892f703f0c..7025c76d92ce822c01fe4ae3498b0807d6e2fcf6 100644 (file)
@@ -114,6 +114,16 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+// Ensure that the result of e.g. joining a thread can be printed and
+// hence used with `unwrap`. May eventually no longer be needed if
+// dispatch works with upcasting.
+#[stable(feature = "rust1", since = "1.0.0")]
+impl fmt::Debug for Any + Send {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad("Any")
+    }
+}
+
 impl Any {
     /// Returns true if the boxed type is the same as `T`
     #[stable(feature = "rust1", since = "1.0.0")]
index 010415b364aa04a75506c86f7d6d82a83e3d0602..ba9748eea7146371ee1b6ac37ed960ba5711d54c 100644 (file)
@@ -139,6 +139,7 @@ pub fn from_digit(num: u32, radix: u32) -> Option<char> {
 // NB: the stabilization and documentation for this trait is in
 // unicode/char.rs, not here
 #[allow(missing_docs)] // docs in libunicode/u_char.rs
+#[doc(hidden)]
 pub trait CharExt {
     fn is_digit(self, radix: u32) -> bool;
     fn to_digit(self, radix: u32) -> Option<u32>;
index 85b648bbd59806072fcb1555a26a12255cedd6b7..1c1ad5fd33fb8bdfbaf142e4244853db5b469170 100644 (file)
 
 //! Traits for conversions between types.
 //!
-//! The traits in this module provide a general way to talk about
-//! conversions from one type to another. They follow the standard
-//! Rust conventions of `as`/`to`/`into`/`from`.
+//! The traits in this module provide a general way to talk about conversions from one type to
+//! another. They follow the standard Rust conventions of `as`/`to`/`into`/`from`.
+//!
+//! Like many traits, these are often used as bounds for generic functions, to support arguments of
+//! multiple types.
+//!
+//! See each trait for usage examples.
 
 #![stable(feature = "rust1", since = "1.0.0")]
 
 use marker::Sized;
 
 /// A cheap, reference-to-reference conversion.
+///
+/// # Examples
+///
+/// Both `String` and `&str` implement `AsRef<str>`:
+///
+/// ```
+/// fn is_hello<T: AsRef<str>>(s: T) {
+///    assert_eq!("hello", s.as_ref());
+/// }
+///
+/// let s = "hello";
+/// is_hello(s);
+///
+/// let s = "hello".to_string();
+/// is_hello(s);
+/// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait AsRef<T: ?Sized> {
     /// Performs the conversion.
@@ -34,8 +54,21 @@ pub trait AsMut<T: ?Sized> {
     fn as_mut(&mut self) -> &mut T;
 }
 
-/// A conversion that consumes `self`, which may or may not be
-/// expensive.
+/// A conversion that consumes `self`, which may or may not be expensive.
+///
+/// # Examples
+///
+/// `String` implements `Into<Vec<u8>>`:
+///
+/// ```
+/// fn is_hello<T: Into<Vec<u8>>>(s: T) {
+///    let bytes = b"hello".to_vec();
+///    assert_eq!(bytes, s.into());
+/// }
+///
+/// let s = "hello".to_string();
+/// is_hello(s);
+/// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait Into<T>: Sized {
     /// Performs the conversion.
@@ -44,6 +77,19 @@ pub trait Into<T>: Sized {
 }
 
 /// Construct `Self` via a conversion.
+///
+/// # Examples
+///
+/// `String` implements `From<&str>`:
+///
+/// ```
+/// let s = "hello";
+/// let string = "hello".to_string();
+///
+/// let other_string: String = From::from(s);
+///
+/// assert_eq!(string, other_string);
+/// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait From<T> {
     /// Performs the conversion.
index 6a5943265ca88fee04ccecb1ba986b6d7ab85ad0..5f19bc5be98cc95a838e0c7cdd9f42006f696164 100644 (file)
@@ -242,7 +242,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
                     if i < 0
                     || buf[i as usize] == b'-'
                     || buf[i as usize] == b'+' {
-                        for j in (i as usize + 1..end).rev() {
+                        for j in ((i + 1) as usize..end).rev() {
                             buf[j + 1] = buf[j];
                         }
                         buf[(i + 1) as usize] = value2ascii(1);
index be804327663e5b058196fd268b5d20d72f5f22eb..67781b73ae23c8b76e8941aa33dc84034a6d2182 100644 (file)
@@ -847,9 +847,32 @@ fn fmt(&self, f: &mut Formatter) -> Result {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T> Pointer for *const T {
     fn fmt(&self, f: &mut Formatter) -> Result {
+        let old_width = f.width;
+        let old_flags = f.flags;
+
+        // The alternate flag is already treated by LowerHex as being special-
+        // it denotes whether to prefix with 0x. We use it to work out whether
+        // or not to zero extend, and then unconditionally set it to get the
+        // prefix.
+        if f.flags & 1 << (FlagV1::Alternate as u32) > 0 {
+            f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
+
+            if let None = f.width {
+                // The formats need two extra bytes, for the 0x
+                if cfg!(target_pointer_width = "32") {
+                    f.width = Some(10);
+                } else {
+                    f.width = Some(18);
+                }
+            }
+        }
         f.flags |= 1 << (FlagV1::Alternate as u32);
+
         let ret = LowerHex::fmt(&(*self as usize), f);
-        f.flags &= !(1 << (FlagV1::Alternate as u32));
+
+        f.width = old_width;
+        f.flags = old_flags;
+
         ret
     }
 }
index 0e91eafce187f7b0ed2dd8160c7c4fe365669043..80f506ebc0643053bad8190a616e3d9550218dc6 100644 (file)
@@ -569,4 +569,10 @@ pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
     pub fn overflowing_sub<T>(a: T, b: T) -> T;
     /// Returns (a * b) mod 2^N, where N is the width of N in bits.
     pub fn overflowing_mul<T>(a: T, b: T) -> T;
+
+    /// Returns the value of the discriminant for the variant in 'v',
+    /// cast to a `u64`; if `T` has no discriminant, returns 0.
+    // SNAP 5520801
+    #[cfg(not(stage0))]
+    pub fn discriminant_value<T>(v: &T) -> u64;
 }
index 8cbdda758697b370bee105c7d5d409d6d9276c31..527a7297f85b9912142b20e9a459228acf7c20bc 100644 (file)
@@ -744,12 +744,12 @@ fn rposition<P>(&mut self, mut predicate: P) -> Option<usize> where
     #[stable(feature = "rust1", since = "1.0.0")]
     fn max(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
     {
-        self.fold(None, |max, y| {
-            match max {
-                None    => Some(y),
-                Some(x) => Some(cmp::max(x, y))
-            }
-        })
+        select_fold1(self,
+                     |_| (),
+                     // switch to y even if it is only equal, to preserve
+                     // stability.
+                     |_, x, _, y| *x <= *y)
+            .map(|(_, x)| x)
     }
 
     /// Consumes the entire iterator to return the minimum element.
@@ -767,12 +767,12 @@ fn max(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
     #[stable(feature = "rust1", since = "1.0.0")]
     fn min(self) -> Option<Self::Item> where Self: Sized, Self::Item: Ord
     {
-        self.fold(None, |min, y| {
-            match min {
-                None    => Some(y),
-                Some(x) => Some(cmp::min(x, y))
-            }
-        })
+        select_fold1(self,
+                     |_| (),
+                     // only switch to y if it is strictly smaller, to
+                     // preserve stability.
+                     |_, x, _, y| *x > *y)
+            .map(|(_, x)| x)
     }
 
     /// `min_max` finds the minimum and maximum elements in the iterator.
@@ -870,21 +870,16 @@ fn min_max(mut self) -> MinMaxResult<Self::Item> where Self: Sized, Self::Item:
     #[inline]
     #[unstable(feature = "core",
                reason = "may want to produce an Ordering directly; see #15311")]
-    fn max_by<B: Ord, F>(self, mut f: F) -> Option<Self::Item> where
+    fn max_by<B: Ord, F>(self, f: F) -> Option<Self::Item> where
         Self: Sized,
         F: FnMut(&Self::Item) -> B,
     {
-        self.fold(None, |max: Option<(Self::Item, B)>, y| {
-            let y_val = f(&y);
-            match max {
-                None             => Some((y, y_val)),
-                Some((x, x_val)) => if y_val >= x_val {
-                    Some((y, y_val))
-                } else {
-                    Some((x, x_val))
-                }
-            }
-        }).map(|(x, _)| x)
+        select_fold1(self,
+                     f,
+                     // switch to y even if it is only equal, to preserve
+                     // stability.
+                     |x_p, _, y_p, _| x_p <= y_p)
+            .map(|(_, x)| x)
     }
 
     /// Return the element that gives the minimum value from the
@@ -904,21 +899,16 @@ fn max_by<B: Ord, F>(self, mut f: F) -> Option<Self::Item> where
     #[inline]
     #[unstable(feature = "core",
                reason = "may want to produce an Ordering directly; see #15311")]
-    fn min_by<B: Ord, F>(self, mut f: F) -> Option<Self::Item> where
+    fn min_by<B: Ord, F>(self, f: F) -> Option<Self::Item> where
         Self: Sized,
         F: FnMut(&Self::Item) -> B,
     {
-        self.fold(None, |min: Option<(Self::Item, B)>, y| {
-            let y_val = f(&y);
-            match min {
-                None             => Some((y, y_val)),
-                Some((x, x_val)) => if x_val <= y_val {
-                    Some((x, x_val))
-                } else {
-                    Some((y, y_val))
-                }
-            }
-        }).map(|(x, _)| x)
+        select_fold1(self,
+                     f,
+                     // only switch to y if it is strictly smaller, to
+                     // preserve stability.
+                     |x_p, _, y_p, _| x_p > y_p)
+            .map(|(_, x)| x)
     }
 
     /// Change the direction of the iterator
@@ -1066,6 +1056,37 @@ fn product<P=<Self as Iterator>::Item>(self) -> P where
     }
 }
 
+/// Select an element from an iterator based on the given projection
+/// and "comparison" function.
+///
+/// This is an idiosyncratic helper to try to factor out the
+/// commonalities of {max,min}{,_by}. In particular, this avoids
+/// having to implement optimisations several times.
+#[inline]
+fn select_fold1<I,B, FProj, FCmp>(mut it: I,
+                                  mut f_proj: FProj,
+                                  mut f_cmp: FCmp) -> Option<(B, I::Item)>
+    where I: Iterator,
+          FProj: FnMut(&I::Item) -> B,
+          FCmp: FnMut(&B, &I::Item, &B, &I::Item) -> bool
+{
+    // start with the first element as our selection. This avoids
+    // having to use `Option`s inside the loop, translating to a
+    // sizeable performance gain (6x in one case).
+    it.next().map(|mut sel| {
+        let mut sel_p = f_proj(&sel);
+
+        for x in it {
+            let x_p = f_proj(&x);
+            if f_cmp(&sel_p,  &sel, &x_p, &x) {
+                sel = x;
+                sel_p = x_p;
+            }
+        }
+        (sel_p, sel)
+    })
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
     type Item = I::Item;
index 2189e2c3ad1baca6a42e615d71f4b3c26190f865..1b7311028f5ed6ae03a05d97ac9bdd5d70961404 100644 (file)
@@ -157,6 +157,7 @@ mod bool {
 
 #[doc(hidden)]
 mod core {
+    pub use intrinsics;
     pub use panicking;
     pub use fmt;
     pub use clone;
index c21898d088d669b82feb17075483a7078bd7d73e..ece419af9517239cc3e1cb954d475672aa80c4a4 100644 (file)
@@ -229,7 +229,6 @@ macro_rules! writeln {
 /// Iterators:
 ///
 /// ```
-/// # #![feature(core)]
 /// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
 ///     for i in 0.. {
 ///         if 3*i < i { panic!("u32 overflow"); }
index 7868e299cfcad4413c3f3c97e0995cee590e7a03..9007a5142c3c779d2659a11a783b768c4d52d969 100644 (file)
@@ -2490,6 +2490,7 @@ pub enum FpCategory {
 //               `unused_self`. Removing it requires #8888 to be fixed.
 #[unstable(feature = "core",
            reason = "distribution of methods between core/std is unclear")]
+#[doc(hidden)]
 pub trait Float
     : Copy + Clone
     + NumCast
index 36b33e7581dd98fb5a3d12a3c0f6380b56e70999..a622ef78a21a4d6235a9ee5ec25774b2e50d9528 100644 (file)
@@ -89,6 +89,7 @@
 //! of unsafe pointers in Rust.
 
 #![stable(feature = "rust1", since = "1.0.0")]
+#![doc(primitive = "pointer")]
 
 use mem;
 use clone::Clone;
index 70e60adf64c2a3649b9d2256a7eadd8a46ff7346..0e6acf0160d8121e466fafb82bbdfbfeab6d66c0 100644 (file)
@@ -63,6 +63,7 @@
 
 /// Extension methods for slices.
 #[allow(missing_docs)] // docs in libcollections
+#[doc(hidden)]
 pub trait SliceExt {
     type Item;
 
index 5c8b6a774cd8bdd9b55506f65b40ace0ce2f335e..9bc760b56ec43f0e6b76f0e43f24b38dae8b73c5 100644 (file)
@@ -1496,6 +1496,7 @@ fn as_slice(&self) -> &str { Str::as_slice(*self) }
 
 /// Methods for string slices
 #[allow(missing_docs)]
+#[doc(hidden)]
 pub trait StrExt {
     // NB there are no docs here are they're all located on the StrExt trait in
     // libcollections, not here.
diff --git a/src/libcoretest/fmt/float.rs b/src/libcoretest/fmt/float.rs
new file mode 100644 (file)
index 0000000..6b14fa8
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#[test]
+fn test_format_float() {
+    assert!("1" == format!("{:.0}", 1.0f64));
+    assert!("9" == format!("{:.0}", 9.4f64));
+    assert!("10" == format!("{:.0}", 9.9f64));
+    assert!("9.9" == format!("{:.1}", 9.85f64));
+}
index bfa9c798d357951782e4ea973fb0ad467741dd51..a56820c61ccbb061adfc1a264465114707c6993d 100644 (file)
@@ -901,3 +901,34 @@ fn bench_multiple_take(b: &mut Bencher) {
         }
     });
 }
+
+fn scatter(x: i32) -> i32 { (x * 31) % 127 }
+
+#[bench]
+fn bench_max_by(b: &mut Bencher) {
+    b.iter(|| {
+        let it = 0..100;
+        it.max_by(|&x| scatter(x))
+    })
+}
+
+// http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
+#[bench]
+fn bench_max_by2(b: &mut Bencher) {
+    fn max_index_iter(array: &[i32]) -> usize {
+        array.iter().enumerate().max_by(|&(_, item)| item).unwrap().0
+    }
+
+    let mut data = vec![0i32; 1638];
+    data[514] = 9999;
+
+    b.iter(|| max_index_iter(&data));
+}
+
+#[bench]
+fn bench_max(b: &mut Bencher) {
+    b.iter(|| {
+        let it = 0..100;
+        it.map(scatter).max()
+    })
+}
index b9559abbdf4c2a2794e66456b25c992af3eead4a..f9d3d707bb5ddc2e3ab8977dce5c380e9cb8c960 100644 (file)
@@ -1264,7 +1264,8 @@ fn add_to_index(item: &ast::Item, rbml_w: &mut Encoder,
         encode_paren_sugar(rbml_w, trait_def.paren_sugar);
         encode_defaulted(rbml_w, ty::trait_has_default_impl(tcx, def_id));
         encode_associated_type_names(rbml_w, &trait_def.associated_type_names);
-        encode_generics(rbml_w, ecx, &trait_def.generics, &trait_predicates, tag_item_generics);
+        encode_generics(rbml_w, ecx, &trait_def.generics, &trait_predicates,
+                        tag_item_generics);
         encode_predicates(rbml_w, ecx, &ty::lookup_super_predicates(tcx, def_id),
                           tag_item_super_predicates);
         encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
index 2f2db8f38bd87e00ee12b8373c8edb5b302943e7..d21891ab23f1ceb0e52cc37a05a64039db53266d 100644 (file)
@@ -26,7 +26,7 @@
 use util::ppaux::Repr;
 
 #[derive(Copy, Clone)]
-struct ParamIsLocal(bool);
+struct InferIsLocal(bool);
 
 /// True if there exist types that satisfy both of the two given impls.
 pub fn overlapping_impls(infcx: &InferCtxt,
@@ -60,7 +60,7 @@ fn overlap(selcx: &mut SelectionContext,
 
     let (a_trait_ref, a_obligations) = impl_trait_ref_and_oblig(selcx,
                                                                 a_def_id,
-                                                                util::free_substs_for_impl);
+                                                                util::fresh_type_vars_for_impl);
 
     let (b_trait_ref, b_obligations) = impl_trait_ref_and_oblig(selcx,
                                                                 b_def_id,
@@ -104,7 +104,7 @@ pub fn trait_ref_is_knowable<'tcx>(tcx: &ty::ctxt<'tcx>, trait_ref: &ty::TraitRe
 
     // if the orphan rules pass, that means that no ancestor crate can
     // impl this, so it's up to us.
-    if orphan_check_trait_ref(tcx, trait_ref, ParamIsLocal(false)).is_ok() {
+    if orphan_check_trait_ref(tcx, trait_ref, InferIsLocal(false)).is_ok() {
         debug!("trait_ref_is_knowable: orphan check passed");
         return true;
     }
@@ -126,7 +126,7 @@ pub fn trait_ref_is_knowable<'tcx>(tcx: &ty::ctxt<'tcx>, trait_ref: &ty::TraitRe
     // implemented by an upstream crate, which means that the impl
     // must be visible to us, and -- since the trait is fundamental
     // -- we can test.
-    orphan_check_trait_ref(tcx, trait_ref, ParamIsLocal(true)).is_err()
+    orphan_check_trait_ref(tcx, trait_ref, InferIsLocal(true)).is_err()
 }
 
 type SubstsFn = for<'a,'tcx> fn(infcx: &InferCtxt<'a, 'tcx>,
@@ -196,16 +196,16 @@ pub fn orphan_check<'tcx>(tcx: &ty::ctxt<'tcx>,
         return Ok(());
     }
 
-    orphan_check_trait_ref(tcx, &trait_ref, ParamIsLocal(false))
+    orphan_check_trait_ref(tcx, &trait_ref, InferIsLocal(false))
 }
 
 fn orphan_check_trait_ref<'tcx>(tcx: &ty::ctxt<'tcx>,
                                 trait_ref: &ty::TraitRef<'tcx>,
-                                param_is_local: ParamIsLocal)
+                                infer_is_local: InferIsLocal)
                                 -> Result<(), OrphanCheckErr<'tcx>>
 {
-    debug!("orphan_check_trait_ref(trait_ref={}, param_is_local={})",
-           trait_ref.repr(tcx), param_is_local.0);
+    debug!("orphan_check_trait_ref(trait_ref={}, infer_is_local={})",
+           trait_ref.repr(tcx), infer_is_local.0);
 
     // First, create an ordered iterator over all the type parameters to the trait, with the self
     // type appearing first.
@@ -215,12 +215,12 @@ fn orphan_check_trait_ref<'tcx>(tcx: &ty::ctxt<'tcx>,
     // Find the first input type that either references a type parameter OR
     // some local type.
     for input_ty in input_tys {
-        if ty_is_local(tcx, input_ty, param_is_local) {
+        if ty_is_local(tcx, input_ty, infer_is_local) {
             debug!("orphan_check_trait_ref: ty_is_local `{}`", input_ty.repr(tcx));
 
             // First local input type. Check that there are no
             // uncovered type parameters.
-            let uncovered_tys = uncovered_tys(tcx, input_ty, param_is_local);
+            let uncovered_tys = uncovered_tys(tcx, input_ty, infer_is_local);
             for uncovered_ty in uncovered_tys {
                 if let Some(param) = uncovered_ty.walk().find(|t| is_type_parameter(t)) {
                     debug!("orphan_check_trait_ref: uncovered type `{}`", param.repr(tcx));
@@ -234,7 +234,7 @@ fn orphan_check_trait_ref<'tcx>(tcx: &ty::ctxt<'tcx>,
 
         // Otherwise, enforce invariant that there are no type
         // parameters reachable.
-        if !param_is_local.0 {
+        if !infer_is_local.0 {
             if let Some(param) = input_ty.walk().find(|t| is_type_parameter(t)) {
                 debug!("orphan_check_trait_ref: uncovered type `{}`", param.repr(tcx));
                 return Err(OrphanCheckErr::UncoveredTy(param));
@@ -249,14 +249,14 @@ fn orphan_check_trait_ref<'tcx>(tcx: &ty::ctxt<'tcx>,
 
 fn uncovered_tys<'tcx>(tcx: &ty::ctxt<'tcx>,
                        ty: Ty<'tcx>,
-                       param_is_local: ParamIsLocal)
+                       infer_is_local: InferIsLocal)
                        -> Vec<Ty<'tcx>>
 {
-    if ty_is_local_constructor(tcx, ty, param_is_local) {
+    if ty_is_local_constructor(tcx, ty, infer_is_local) {
         vec![]
     } else if fundamental_ty(tcx, ty) {
         ty.walk_shallow()
-          .flat_map(|t| uncovered_tys(tcx, t, param_is_local).into_iter())
+          .flat_map(|t| uncovered_tys(tcx, t, infer_is_local).into_iter())
           .collect()
     } else {
         vec![ty]
@@ -271,10 +271,10 @@ fn is_type_parameter<'tcx>(ty: Ty<'tcx>) -> bool {
     }
 }
 
-fn ty_is_local<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>, param_is_local: ParamIsLocal) -> bool
+fn ty_is_local<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>, infer_is_local: InferIsLocal) -> bool
 {
-    ty_is_local_constructor(tcx, ty, param_is_local) ||
-        fundamental_ty(tcx, ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, param_is_local))
+    ty_is_local_constructor(tcx, ty, infer_is_local) ||
+        fundamental_ty(tcx, ty) && ty.walk_shallow().any(|t| ty_is_local(tcx, t, infer_is_local))
 }
 
 fn fundamental_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool
@@ -293,7 +293,7 @@ fn fundamental_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> bool
 
 fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
                                  ty: Ty<'tcx>,
-                                 param_is_local: ParamIsLocal)
+                                 infer_is_local: InferIsLocal)
                                  -> bool
 {
     debug!("ty_is_local_constructor({})", ty.repr(tcx));
@@ -310,13 +310,13 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>,
         ty::ty_ptr(..) |
         ty::ty_rptr(..) |
         ty::ty_tup(..) |
-        ty::ty_infer(..) |
+        ty::ty_param(..) |
         ty::ty_projection(..) => {
             false
         }
 
-        ty::ty_param(..) => {
-            param_is_local.0
+        ty::ty_infer(..) => {
+            infer_is_local.0
         }
 
         ty::ty_enum(def_id, _) |
index 297cea13207e57a99a5f9871db3e36b9e8a752dd..3a1be785580af1d4cb6746c04b6d97d88bb37dde 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use middle::region;
 use middle::subst::{Substs, VecPerParamSpace};
 use middle::infer::InferCtxt;
 use middle::ty::{self, Ty, AsPredicate, ToPolyTraitRef};
@@ -304,34 +303,6 @@ pub fn fresh_type_vars_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
     infcx.fresh_substs_for_generics(span, &impl_generics)
 }
 
-// determine the `self` type, using fresh variables for all variables
-// declared on the impl declaration e.g., `impl<A,B> for Box<[(A,B)]>`
-// would return ($0, $1) where $0 and $1 are freshly instantiated type
-// variables.
-pub fn free_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
-                                      _span: Span,
-                                      impl_def_id: ast::DefId)
-                                      -> Substs<'tcx>
-{
-    let tcx = infcx.tcx;
-    let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics;
-
-    let some_types = impl_generics.types.map(|def| {
-        ty::mk_param_from_def(tcx, def)
-    });
-
-    let some_regions = impl_generics.regions.map(|def| {
-        // FIXME. This destruction scope information is pretty darn
-        // bogus; after all, the impl might not even be in this crate!
-        // But given what we do in coherence, it is harmless enough
-        // for now I think. -nmatsakis
-        let extent = region::DestructionScopeData::new(ast::DUMMY_NODE_ID);
-        ty::free_region_from_def(extent, def)
-    });
-
-    Substs::new(some_types, some_regions)
-}
-
 impl<'tcx, N> fmt::Debug for VtableImplData<'tcx, N> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "VtableImpl({:?})", self.impl_def_id)
index 148f484b0ed5c487a5c1a045e1ab31ee67de1e95..88faf1cb68ae4db505359543eff52f5c592f25d1 100644 (file)
@@ -143,6 +143,13 @@ pub fn span_note(&self, sp: Span, msg: &str) {
     pub fn span_end_note(&self, sp: Span, msg: &str) {
         self.diagnostic().span_end_note(sp, msg)
     }
+
+    /// Prints out a message with a suggested edit of the code.
+    ///
+    /// See `diagnostic::RenderSpan::Suggestion` for more information.
+    pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
+        self.diagnostic().span_suggestion(sp, msg, suggestion)
+    }
     pub fn span_help(&self, sp: Span, msg: &str) {
         self.diagnostic().span_help(sp, msg)
     }
index c57cbcb929fbc8999d32287a047e78bad3b078b7..db947a27472ada5eb768cdf9ac7f1e6cb7e2448d 100644 (file)
@@ -522,6 +522,16 @@ pub fn is_subregion_of(&self, r_sub: ty::Region, r_sup: ty::Region)
     }
 
     pub fn report(&self, err: BckError<'tcx>) {
+        // Catch and handle some particular cases.
+        match (&err.code, &err.cause) {
+            (&err_out_of_scope(ty::ReScope(_), ty::ReStatic), &euv::ClosureCapture(span)) |
+            (&err_out_of_scope(ty::ReScope(_), ty::ReFree(..)), &euv::ClosureCapture(span)) => {
+                return self.report_out_of_scope_escaping_closure_capture(&err, span);
+            }
+            _ => { }
+        }
+
+        // General fallback.
         self.span_err(
             err.span,
             &self.bckerr_to_string(&err));
@@ -796,16 +806,10 @@ pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String {
                 format!("{} does not live long enough", msg)
             }
             err_borrowed_pointer_too_short(..) => {
-                let descr = match opt_loan_path(&err.cmt) {
-                    Some(lp) => {
-                        format!("`{}`", self.loan_path_to_string(&*lp))
-                    }
-                    None => self.cmt_to_string(&*err.cmt),
-                };
-
+                let descr = self.cmt_to_path_or_string(&err.cmt);
                 format!("lifetime of {} is too short to guarantee \
-                                its contents can be safely reborrowed",
-                               descr)
+                         its contents can be safely reborrowed",
+                        descr)
             }
         }
     }
@@ -888,6 +892,39 @@ pub fn report_aliasability_violation(&self,
         }
     }
 
+    fn report_out_of_scope_escaping_closure_capture(&self,
+                                                    err: &BckError<'tcx>,
+                                                    capture_span: Span)
+    {
+        let cmt_path_or_string = self.cmt_to_path_or_string(&err.cmt);
+
+        span_err!(
+            self.tcx.sess, err.span, E0373,
+            "closure may outlive the current function, \
+             but it borrows {}, \
+             which is owned by the current function",
+            cmt_path_or_string);
+
+        self.tcx.sess.span_note(
+            capture_span,
+            &format!("{} is borrowed here",
+                     cmt_path_or_string));
+
+        let suggestion =
+            match self.tcx.sess.codemap().span_to_snippet(err.span) {
+                Ok(string) => format!("move {}", string),
+                Err(_) => format!("move |<args>| <body>")
+            };
+
+        self.tcx.sess.span_suggestion(
+            err.span,
+            &format!("to force the closure to take ownership of {} \
+                      (and any other referenced variables), \
+                      use the `move` keyword, as shown:",
+                     cmt_path_or_string),
+            suggestion);
+    }
+
     pub fn note_and_explain_bckerr(&self, err: BckError<'tcx>) {
         let code = err.code;
         match code {
@@ -1035,6 +1072,13 @@ pub fn loan_path_to_string(&self, loan_path: &LoanPath<'tcx>) -> String {
     pub fn cmt_to_string(&self, cmt: &mc::cmt_<'tcx>) -> String {
         cmt.descriptive_string(self.tcx)
     }
+
+    pub fn cmt_to_path_or_string(&self, cmt: &mc::cmt<'tcx>) -> String {
+        match opt_loan_path(cmt) {
+            Some(lp) => format!("`{}`", self.loan_path_to_string(&lp)),
+            None => self.cmt_to_string(cmt),
+        }
+    }
 }
 
 fn is_statement_scope(tcx: &ty::ctxt, region: ty::Region) -> bool {
diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs
new file mode 100644 (file)
index 0000000..981b285
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![allow(non_snake_case)]
+
+register_diagnostics! {
+    E0373 // closure may outlive current fn, but it borrows {}, which is owned by current fn
+}
+
+__build_diagnostic_array! { DIAGNOSTICS }
index 54feed930a80d7b9766d1e54bade1090abcf5da6..647ea3555ba913984c8ed71be606c13e41851c86 100644 (file)
 pub use borrowck::build_borrowck_dataflow_data_for_fn;
 pub use borrowck::FnPartsWithCFG;
 
+// NB: This module needs to be declared first so diagnostics are
+// registered before they are used.
+pub mod diagnostics;
+
 mod borrowck;
 
 pub mod graphviz;
index 62a6ede4c2f936bdcdefaec91e8e21c5e12cca96..fc3c0841dd84e9a3c6f837dfe7c64cc84baaf862 100644 (file)
@@ -14,6 +14,7 @@
 use llvm::{SequentiallyConsistent, Acquire, Release, AtomicXchg, ValueRef, TypeKind};
 use middle::subst;
 use middle::subst::FnSpace;
+use trans::adt;
 use trans::base::*;
 use trans::build::*;
 use trans::callee;
@@ -683,6 +684,17 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
             }
         }
 
+        (_, "discriminant_value") => {
+            let val_ty = substs.types.get(FnSpace, 0);
+            match val_ty.sty {
+                ty::ty_enum(..) => {
+                    let repr = adt::represent_type(ccx, *val_ty);
+                    adt::trans_get_discr(bcx, &*repr, llargs[0], Some(llret_ty))
+                }
+                _ => C_null(llret_ty)
+            }
+        }
+
         // This requires that atomic intrinsics follow a specific naming pattern:
         // "atomic_<operation>[_<ordering>]", and no ordering means SeqCst
         (_, name) if name.starts_with("atomic_") => {
index f7bbc693ce59b9e3e285fab6c821e5286281946b..31039e3abca6eb6729f9c5d2b16fa2b1cdca9bae 100644 (file)
@@ -5073,6 +5073,12 @@ fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
 
             "assume" => (0, vec![tcx.types.bool], ty::mk_nil(tcx)),
 
+            "discriminant_value" => (1, vec![
+                    ty::mk_imm_rptr(tcx,
+                                    tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
+                                                                  ty::BrAnon(0))),
+                                    param(ccx, 0))], tcx.types.u64),
+
             ref other => {
                 span_err!(tcx.sess, it.span, E0093,
                     "unrecognized intrinsic function: `{}`", *other);
index aa17bf20d74bbe782e0896277a93106ee2225f93..f14437b71b47ae627abdb0bf91edc61e5b5799a8 100644 (file)
@@ -10,6 +10,8 @@
 
 //! Support for inlining external documentation into the current AST.
 
+use std::collections::HashSet;
+
 use syntax::ast;
 use syntax::ast_util;
 use syntax::attr::AttrMetaMethods;
@@ -150,18 +152,21 @@ pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt,
     let def = ty::lookup_trait_def(tcx, did);
     let trait_items = ty::trait_items(tcx, did).clean(cx);
     let predicates = ty::lookup_predicates(tcx, did);
+    let generics = (&def.generics, &predicates, subst::TypeSpace).clean(cx);
+    let generics = filter_non_trait_generics(did, generics);
+    let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
     clean::Trait {
         unsafety: def.unsafety,
-        generics: (&def.generics, &predicates, subst::TypeSpace).clean(cx),
+        generics: generics,
         items: trait_items,
-        bounds: vec![], // supertraits can be found in the list of predicates
+        bounds: supertrait_bounds,
     }
 }
 
 fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Function {
     let t = ty::lookup_item_type(tcx, did);
-    let (decl, style) = match t.ty.sty {
-        ty::ty_bare_fn(_, ref f) => ((did, &f.sig).clean(cx), f.unsafety),
+    let (decl, style, abi) = match t.ty.sty {
+        ty::ty_bare_fn(_, ref f) => ((did, &f.sig).clean(cx), f.unsafety, f.abi),
         _ => panic!("bad function"),
     };
     let predicates = ty::lookup_predicates(tcx, did);
@@ -169,6 +174,7 @@ fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) ->
         decl: decl,
         generics: (&t.generics, &predicates, subst::FnSpace).clean(cx),
         unsafety: style,
+        abi: abi,
     }
 }
 
@@ -331,9 +337,10 @@ fn build_impl(cx: &DocContext,
                 let did = assoc_ty.def_id;
                 let type_scheme = ty::lookup_item_type(tcx, did);
                 let predicates = ty::lookup_predicates(tcx, did);
-                // Not sure the choice of ParamSpace actually matters here, because an
-                // associated type won't have generics on the LHS
-                let typedef = (type_scheme, predicates, subst::ParamSpace::TypeSpace).clean(cx);
+                // Not sure the choice of ParamSpace actually matters here,
+                // because an associated type won't have generics on the LHS
+                let typedef = (type_scheme, predicates,
+                               subst::ParamSpace::TypeSpace).clean(cx);
                 Some(clean::Item {
                     name: Some(assoc_ty.name.clean(cx)),
                     inner: clean::TypedefItem(typedef),
@@ -395,16 +402,19 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
         is_crate: false,
     };
 
-    // FIXME: this doesn't handle reexports inside the module itself.
-    //        Should they be handled?
     fn fill_in(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId,
                items: &mut Vec<clean::Item>) {
+        // If we're reexporting a reexport it may actually reexport something in
+        // two namespaces, so the target may be listed twice. Make sure we only
+        // visit each node at most once.
+        let mut visited = HashSet::new();
         csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| {
             match def {
                 decoder::DlDef(def::DefForeignMod(did)) => {
                     fill_in(cx, tcx, did, items);
                 }
                 decoder::DlDef(def) if vis == ast::Public => {
+                    if !visited.insert(def) { return }
                     match try_inline_def(cx, tcx, def) {
                         Some(i) => items.extend(i.into_iter()),
                         None => {}
@@ -446,3 +456,48 @@ fn build_static(cx: &DocContext, tcx: &ty::ctxt,
         expr: "\n\n\n".to_string(), // trigger the "[definition]" links
     }
 }
+
+/// A trait's generics clause actually contains all of the predicates for all of
+/// its associated types as well. We specifically move these clauses to the
+/// associated types instead when displaying, so when we're genering the
+/// generics for the trait itself we need to be sure to remove them.
+///
+/// The inverse of this filtering logic can be found in the `Clean`
+/// implementation for `AssociatedType`
+fn filter_non_trait_generics(trait_did: ast::DefId, mut g: clean::Generics)
+                             -> clean::Generics {
+    g.where_predicates.retain(|pred| {
+        match *pred {
+            clean::WherePredicate::BoundPredicate {
+                ty: clean::QPath {
+                    self_type: box clean::Generic(ref s),
+                    trait_: box clean::ResolvedPath { did, .. },
+                    name: ref _name,
+                }, ..
+            } => *s != "Self" || did != trait_did,
+            _ => true,
+        }
+    });
+    return g;
+}
+
+/// Supertrait bounds for a trait are also listed in the generics coming from
+/// the metadata for a crate, so we want to separate those out and create a new
+/// list of explicit supertrait bounds to render nicely.
+fn separate_supertrait_bounds(mut g: clean::Generics)
+                              -> (clean::Generics, Vec<clean::TyParamBound>) {
+    let mut ty_bounds = Vec::new();
+    g.where_predicates.retain(|pred| {
+        match *pred {
+            clean::WherePredicate::BoundPredicate {
+                ty: clean::Generic(ref s),
+                ref bounds
+            } if *s == "Self" => {
+                ty_bounds.extend(bounds.iter().cloned());
+                false
+            }
+            _ => true,
+        }
+    });
+    (g, ty_bounds)
+}
index e0ed83f401945b11d07bfbaf5992fde6b75a3cff..38df0339e42503410c20b0bad656287f1961ec4e 100644 (file)
 use rustc::middle::ty;
 use rustc::middle::stability;
 
+use std::collections::HashMap;
+use std::path::PathBuf;
 use std::rc::Rc;
 use std::u32;
-use std::path::PathBuf;
 
 use core::DocContext;
 use doctree;
@@ -57,6 +58,7 @@
 pub static SCHEMA_VERSION: &'static str = "0.8.3";
 
 mod inline;
+mod simplify;
 
 // extract the stability index for a node from tcx, if possible
 fn get_stability(cx: &DocContext, def_id: ast::DefId) -> Option<Stability> {
@@ -119,6 +121,7 @@ pub struct Crate {
     pub module: Option<Item>,
     pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
     pub primitives: Vec<PrimitiveType>,
+    pub external_traits: HashMap<ast::DefId, Trait>,
 }
 
 impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
@@ -197,6 +200,8 @@ fn clean(&self, cx: &DocContext) -> Crate {
             module: Some(module),
             externs: externs,
             primitives: primitives,
+            external_traits: cx.external_traits.borrow_mut().take()
+                               .unwrap_or(HashMap::new()),
         }
     }
 }
@@ -493,6 +498,35 @@ pub enum TyParamBound {
     TraitBound(PolyTrait, ast::TraitBoundModifier)
 }
 
+impl TyParamBound {
+    fn maybe_sized(cx: &DocContext) -> TyParamBound {
+        use syntax::ast::TraitBoundModifier as TBM;
+        let mut sized_bound = ty::BuiltinBound::BoundSized.clean(cx);
+        if let TyParamBound::TraitBound(_, ref mut tbm) = sized_bound {
+            *tbm = TBM::Maybe
+        };
+        sized_bound
+    }
+
+    fn is_sized_bound(&self, cx: &DocContext) -> bool {
+        use syntax::ast::TraitBoundModifier as TBM;
+        if let Some(tcx) = cx.tcx_opt() {
+            let sized_did = match tcx.lang_items.sized_trait() {
+                Some(did) => did,
+                None => return false
+            };
+            if let TyParamBound::TraitBound(PolyTrait {
+                trait_: Type::ResolvedPath { did, .. }, ..
+            }, TBM::None) = *self {
+                if did == sized_did {
+                    return true
+                }
+            }
+        }
+        false
+    }
+}
+
 impl Clean<TyParamBound> for ast::TyParamBound {
     fn clean(&self, cx: &DocContext) -> TyParamBound {
         match *self {
@@ -830,7 +864,9 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
     fn clean(&self, cx: &DocContext) -> Type {
         let trait_ = match self.trait_ref.clean(cx) {
             TyParamBound::TraitBound(t, _) => t.trait_,
-            TyParamBound::RegionBound(_) => panic!("cleaning a trait got a region??"),
+            TyParamBound::RegionBound(_) => {
+                panic!("cleaning a trait got a region")
+            }
         };
         Type::QPath {
             name: self.item_name.clean(cx),
@@ -863,32 +899,13 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
                                     subst::ParamSpace) {
     fn clean(&self, cx: &DocContext) -> Generics {
         use std::collections::HashSet;
-        use syntax::ast::TraitBoundModifier as TBM;
         use self::WherePredicate as WP;
 
-        fn has_sized_bound(bounds: &[TyParamBound], cx: &DocContext) -> bool {
-            if let Some(tcx) = cx.tcx_opt() {
-                let sized_did = match tcx.lang_items.sized_trait() {
-                    Some(did) => did,
-                    None => return false
-                };
-                for bound in bounds {
-                    if let TyParamBound::TraitBound(PolyTrait {
-                        trait_: Type::ResolvedPath { did, .. }, ..
-                    }, TBM::None) = *bound {
-                        if did == sized_did {
-                            return true
-                        }
-                    }
-                }
-            }
-            false
-        }
-
         let (gens, preds, space) = *self;
 
-        // Bounds in the type_params and lifetimes fields are repeated in the predicates
-        // field (see rustc_typeck::collect::ty_generics), so remove them.
+        // Bounds in the type_params and lifetimes fields are repeated in the
+        // predicates field (see rustc_typeck::collect::ty_generics), so remove
+        // them.
         let stripped_typarams = gens.types.get_slice(space).iter().map(|tp| {
             tp.clean(cx)
         }).collect::<Vec<_>>();
@@ -898,33 +915,38 @@ fn has_sized_bound(bounds: &[TyParamBound], cx: &DocContext) -> bool {
             srp.clean(cx)
         }).collect::<Vec<_>>();
 
-        let where_predicates = preds.predicates.get_slice(space).to_vec().clean(cx);
+        let mut where_predicates = preds.predicates.get_slice(space)
+                                                   .to_vec().clean(cx);
 
-        // Type parameters have a Sized bound by default unless removed with ?Sized.
-        // Scan through the predicates and mark any type parameter with a Sized
-        // bound, removing the bounds as we find them.
+        // Type parameters and have a Sized bound by default unless removed with
+        // ?Sized.  Scan through the predicates and mark any type parameter with
+        // a Sized bound, removing the bounds as we find them.
+        //
+        // Note that associated types also have a sized bound by default, but we
+        // don't actually konw the set of associated types right here so that's
+        // handled in cleaning associated types
         let mut sized_params = HashSet::new();
-        let mut where_predicates = where_predicates.into_iter().filter_map(|pred| {
-            if let WP::BoundPredicate { ty: Type::Generic(ref g), ref bounds } = pred {
-                if has_sized_bound(&**bounds, cx) {
-                    sized_params.insert(g.clone());
-                    return None
+        where_predicates.retain(|pred| {
+            match *pred {
+                WP::BoundPredicate { ty: Generic(ref g), ref bounds } => {
+                    if bounds.iter().any(|b| b.is_sized_bound(cx)) {
+                        sized_params.insert(g.clone());
+                        false
+                    } else {
+                        true
+                    }
                 }
+                _ => true,
             }
-            Some(pred)
-        }).collect::<Vec<_>>();
+        });
 
-        // Finally, run through the type parameters again and insert a ?Sized unbound for
-        // any we didn't find to be Sized.
+        // Run through the type parameters again and insert a ?Sized
+        // unbound for any we didn't find to be Sized.
         for tp in &stripped_typarams {
             if !sized_params.contains(&tp.name) {
-                let mut sized_bound = ty::BuiltinBound::BoundSized.clean(cx);
-                if let TyParamBound::TraitBound(_, ref mut tbm) = sized_bound {
-                    *tbm = TBM::Maybe
-                };
                 where_predicates.push(WP::BoundPredicate {
                     ty: Type::Generic(tp.name.clone()),
-                    bounds: vec![sized_bound]
+                    bounds: vec![TyParamBound::maybe_sized(cx)],
                 })
             }
         }
@@ -934,9 +956,9 @@ fn has_sized_bound(bounds: &[TyParamBound], cx: &DocContext) -> bool {
         // and instead see `where T: Foo + Bar + Sized + 'a`
 
         Generics {
-            type_params: stripped_typarams,
+            type_params: simplify::ty_params(stripped_typarams),
             lifetimes: stripped_lifetimes,
-            where_predicates: where_predicates
+            where_predicates: simplify::where_clauses(cx, where_predicates),
         }
     }
 }
@@ -1032,6 +1054,7 @@ pub struct Function {
     pub decl: FnDecl,
     pub generics: Generics,
     pub unsafety: ast::Unsafety,
+    pub abi: abi::Abi
 }
 
 impl Clean<Item> for doctree::Function {
@@ -1047,6 +1070,7 @@ fn clean(&self, cx: &DocContext) -> Item {
                 decl: self.decl.clean(cx),
                 generics: self.generics.clean(cx),
                 unsafety: self.unsafety,
+                abi: self.abi,
             }),
         }
     }
@@ -1274,6 +1298,35 @@ fn clean(&self, cx: &DocContext) -> Item {
             }
         };
 
+        let generics = (&self.generics, &self.predicates,
+                        subst::FnSpace).clean(cx);
+        let decl = (self.def_id, &sig).clean(cx);
+        let provided = match self.container {
+            ty::ImplContainer(..) => false,
+            ty::TraitContainer(did) => {
+                ty::provided_trait_methods(cx.tcx(), did).iter().any(|m| {
+                    m.def_id == self.def_id
+                })
+            }
+        };
+        let inner = if provided {
+            MethodItem(Method {
+                unsafety: self.fty.unsafety,
+                generics: generics,
+                self_: self_,
+                decl: decl,
+                abi: self.fty.abi
+            })
+        } else {
+            TyMethodItem(TyMethod {
+                unsafety: self.fty.unsafety,
+                generics: generics,
+                self_: self_,
+                decl: decl,
+                abi: self.fty.abi
+            })
+        };
+
         Item {
             name: Some(self.name.clean(cx)),
             visibility: Some(ast::Inherited),
@@ -1281,13 +1334,7 @@ fn clean(&self, cx: &DocContext) -> Item {
             def_id: self.def_id,
             attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
             source: Span::empty(),
-            inner: TyMethodItem(TyMethod {
-                unsafety: self.fty.unsafety,
-                generics: (&self.generics, &self.predicates, subst::FnSpace).clean(cx),
-                self_: self_,
-                decl: (self.def_id, &sig).clean(cx),
-                abi: self.fty.abi
-            })
+            inner: inner,
         }
     }
 }
@@ -1365,6 +1412,7 @@ pub enum PrimitiveType {
     Slice,
     Array,
     PrimitiveTuple,
+    PrimitiveRawPointer,
 }
 
 #[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)]
@@ -1380,6 +1428,21 @@ pub enum TypeKind {
     TypeTypedef,
 }
 
+impl Type {
+    pub fn primitive_type(&self) -> Option<PrimitiveType> {
+        match *self {
+            Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p),
+            Vector(..) | BorrowedRef{ type_: box Vector(..), ..  } => Some(Slice),
+            FixedVector(..) | BorrowedRef { type_: box FixedVector(..), .. } => {
+                Some(Array)
+            }
+            Tuple(..) => Some(PrimitiveTuple),
+            RawPointer(..) => Some(PrimitiveRawPointer),
+            _ => None,
+        }
+    }
+}
+
 impl PrimitiveType {
     fn from_str(s: &str) -> Option<PrimitiveType> {
         match s {
@@ -1401,6 +1464,7 @@ fn from_str(s: &str) -> Option<PrimitiveType> {
             "array" => Some(Array),
             "slice" => Some(Slice),
             "tuple" => Some(PrimitiveTuple),
+            "pointer" => Some(PrimitiveRawPointer),
             _ => None,
         }
     }
@@ -1446,6 +1510,7 @@ pub fn to_string(&self) -> &'static str {
             Array => "array",
             Slice => "slice",
             PrimitiveTuple => "tuple",
+            PrimitiveRawPointer => "pointer",
         }
     }
 
@@ -1587,17 +1652,7 @@ fn clean(&self, cx: &DocContext) -> Type {
             }
             ty::ty_tup(ref t) => Tuple(t.clean(cx)),
 
-            ty::ty_projection(ref data) => {
-                let trait_ref = match data.trait_ref.clean(cx) {
-                    TyParamBound::TraitBound(t, _) => t.trait_,
-                    TyParamBound::RegionBound(_) => panic!("cleaning a trait got a region??"),
-                };
-                Type::QPath {
-                    name: data.item_name.clean(cx),
-                    self_type: box data.trait_ref.self_ty().clean(cx),
-                    trait_: box trait_ref,
-                }
-            }
+            ty::ty_projection(ref data) => data.clean(cx),
 
             ty::ty_param(ref p) => Generic(token::get_name(p.name).to_string()),
 
@@ -1871,6 +1926,22 @@ pub struct Path {
     pub segments: Vec<PathSegment>,
 }
 
+impl Path {
+    pub fn singleton(name: String) -> Path {
+        Path {
+            global: false,
+            segments: vec![PathSegment {
+                name: name,
+                params: PathParameters::AngleBracketed {
+                    lifetimes: Vec::new(),
+                    types: Vec::new(),
+                    bindings: Vec::new()
+                }
+            }]
+        }
+    }
+}
+
 impl Clean<Path> for ast::Path {
     fn clean(&self, cx: &DocContext) -> Path {
         Path {
@@ -2262,7 +2333,14 @@ fn clean(&self, cx: &DocContext) -> ViewListIdent {
 
 impl Clean<Vec<Item>> for ast::ForeignMod {
     fn clean(&self, cx: &DocContext) -> Vec<Item> {
-        self.items.clean(cx)
+        let mut items = self.items.clean(cx);
+        for item in &mut items {
+            match item.inner {
+                ForeignFunctionItem(ref mut f) => f.abi = self.abi,
+                _ => {}
+            }
+        }
+        items
     }
 }
 
@@ -2274,6 +2352,7 @@ fn clean(&self, cx: &DocContext) -> Item {
                     decl: decl.clean(cx),
                     generics: generics.clean(cx),
                     unsafety: ast::Unsafety::Unsafe,
+                    abi: abi::Rust,
                 })
             }
             ast::ForeignItemStatic(ref ty, mutbl) => {
@@ -2506,21 +2585,66 @@ fn clean(&self, _: &DocContext) -> Stability {
 
 impl Clean<Item> for ty::AssociatedType {
     fn clean(&self, cx: &DocContext) -> Item {
+        // When loading a cross-crate associated type, the bounds for this type
+        // are actually located on the trait/impl itself, so we need to load
+        // all of the generics from there and then look for bounds that are
+        // applied to this associated type in question.
+        let predicates = ty::lookup_predicates(cx.tcx(), self.container.id());
+        let generics = match self.container {
+            ty::TraitContainer(did) => {
+                let def = ty::lookup_trait_def(cx.tcx(), did);
+                (&def.generics, &predicates, subst::TypeSpace).clean(cx)
+            }
+            ty::ImplContainer(did) => {
+                let ty = ty::lookup_item_type(cx.tcx(), did);
+                (&ty.generics, &predicates, subst::TypeSpace).clean(cx)
+            }
+        };
+        let my_name = self.name.clean(cx);
+        let mut bounds = generics.where_predicates.iter().filter_map(|pred| {
+            let (name, self_type, trait_, bounds) = match *pred {
+                WherePredicate::BoundPredicate {
+                    ty: QPath { ref name, ref self_type, ref trait_ },
+                    ref bounds
+                } => (name, self_type, trait_, bounds),
+                _ => return None,
+            };
+            if *name != my_name { return None }
+            match **trait_ {
+                ResolvedPath { did, .. } if did == self.container.id() => {}
+                _ => return None,
+            }
+            match **self_type {
+                Generic(ref s) if *s == "Self" => {}
+                _ => return None,
+            }
+            Some(bounds)
+        }).flat_map(|i| i.iter().cloned()).collect::<Vec<_>>();
+
+        // Our Sized/?Sized bound didn't get handled when creating the generics
+        // because we didn't actually get our whole set of bounds until just now
+        // (some of them may have come from the trait). If we do have a sized
+        // bound, we remove it, and if we don't then we add the `?Sized` bound
+        // at the end.
+        match bounds.iter().position(|b| b.is_sized_bound(cx)) {
+            Some(i) => { bounds.remove(i); }
+            None => bounds.push(TyParamBound::maybe_sized(cx)),
+        }
+
         Item {
             source: DUMMY_SP.clean(cx),
             name: Some(self.name.clean(cx)),
-            attrs: Vec::new(),
-            // FIXME(#20727): bounds are missing and need to be filled in from the
-            // predicates on the trait itself
-            inner: AssociatedTypeItem(vec![], None),
-            visibility: None,
+            attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
+            inner: AssociatedTypeItem(bounds, None),
+            visibility: self.vis.clean(cx),
             def_id: self.def_id,
-            stability: None,
+            stability: stability::lookup(cx.tcx(), self.def_id).clean(cx),
         }
     }
 }
 
-impl<'a> Clean<Typedef> for (ty::TypeScheme<'a>, ty::GenericPredicates<'a>, ParamSpace) {
+impl<'a> Clean<Typedef> for (ty::TypeScheme<'a>, ty::GenericPredicates<'a>,
+                             ParamSpace) {
     fn clean(&self, cx: &DocContext) -> Typedef {
         let (ref ty_scheme, ref predicates, ps) = *self;
         Typedef {
diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs
new file mode 100644 (file)
index 0000000..03f056a
--- /dev/null
@@ -0,0 +1,180 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Simplification of where clauses and parameter bounds into a prettier and
+//! more canonical form.
+//!
+//! Currently all cross-crate-inlined function use `middle::ty` to reconstruct
+//! the AST (e.g. see all of `clean::inline`), but this is not always a
+//! non-lossy transformation. The current format of storage for where clauses
+//! for functions and such is simply a list of predicates. One example of this
+//! is that the AST predicate of:
+//!
+//!     where T: Trait<Foo=Bar>
+//!
+//! is encoded as:
+//!
+//!     where T: Trait, <T as Trait>::Foo = Bar
+//!
+//! This module attempts to reconstruct the original where and/or parameter
+//! bounds by special casing scenarios such as these. Fun!
+
+use std::mem;
+use std::collections::HashMap;
+
+use rustc::middle::subst;
+use rustc::middle::ty;
+use syntax::ast;
+
+use clean::PathParameters as PP;
+use clean::WherePredicate as WP;
+use clean::{self, Clean};
+use core::DocContext;
+
+pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
+    // First, partition the where clause into its separate components
+    let mut params = HashMap::new();
+    let mut lifetimes = Vec::new();
+    let mut equalities = Vec::new();
+    let mut tybounds = Vec::new();
+    for clause in clauses {
+        match clause {
+            WP::BoundPredicate { ty, bounds } => {
+                match ty {
+                    clean::Generic(s) => params.entry(s).or_insert(Vec::new())
+                                               .extend(bounds),
+                    t => tybounds.push((t, ty_bounds(bounds))),
+                }
+            }
+            WP::RegionPredicate { lifetime, bounds } => {
+                lifetimes.push((lifetime, bounds));
+            }
+            WP::EqPredicate { lhs, rhs } => equalities.push((lhs, rhs)),
+        }
+    }
+
+    // Simplify the type parameter bounds on all the generics
+    let mut params = params.into_iter().map(|(k, v)| {
+        (k, ty_bounds(v))
+    }).collect::<HashMap<_, _>>();
+
+    // Look for equality predicates on associated types that can be merged into
+    // general bound predicates
+    equalities.retain(|&(ref lhs, ref rhs)| {
+        let (self_, trait_, name) = match *lhs {
+            clean::QPath { ref self_type, ref trait_, ref name } => {
+                (self_type, trait_, name)
+            }
+            _ => return true,
+        };
+        let generic = match **self_ {
+            clean::Generic(ref s) => s,
+            _ => return true,
+        };
+        let trait_did = match **trait_ {
+            clean::ResolvedPath { did, .. } => did,
+            _ => return true,
+        };
+        let bounds = match params.get_mut(generic) {
+            Some(bound) => bound,
+            None => return true,
+        };
+        !bounds.iter_mut().any(|b| {
+            let trait_ref = match *b {
+                clean::TraitBound(ref mut tr, _) => tr,
+                clean::RegionBound(..) => return false,
+            };
+            let (did, path) = match trait_ref.trait_ {
+                clean::ResolvedPath { did, ref mut path, ..} => (did, path),
+                _ => return false,
+            };
+            // If this QPath's trait `trait_did` is the same as, or a supertrait
+            // of, the bound's trait `did` then we can keep going, otherwise
+            // this is just a plain old equality bound.
+            if !trait_is_same_or_supertrait(cx, did, trait_did) {
+                return false
+            }
+            let last = path.segments.last_mut().unwrap();
+            match last.params {
+                PP::AngleBracketed { ref mut bindings, .. } => {
+                    bindings.push(clean::TypeBinding {
+                        name: name.clone(),
+                        ty: rhs.clone(),
+                    });
+                }
+                PP::Parenthesized { ref mut output, .. } => {
+                    assert!(output.is_none());
+                    *output = Some(rhs.clone());
+                }
+            };
+            true
+        })
+    });
+
+    // And finally, let's reassemble everything
+    let mut clauses = Vec::new();
+    clauses.extend(lifetimes.into_iter().map(|(lt, bounds)| {
+        WP::RegionPredicate { lifetime: lt, bounds: bounds }
+    }));
+    clauses.extend(params.into_iter().map(|(k, v)| {
+        WP::BoundPredicate {
+            ty: clean::Generic(k),
+            bounds: v,
+        }
+    }));
+    clauses.extend(tybounds.into_iter().map(|(ty, bounds)| {
+        WP::BoundPredicate { ty: ty, bounds: bounds }
+    }));
+    clauses.extend(equalities.into_iter().map(|(lhs, rhs)| {
+        WP::EqPredicate { lhs: lhs, rhs: rhs }
+    }));
+    clauses
+}
+
+pub fn ty_params(mut params: Vec<clean::TyParam>) -> Vec<clean::TyParam> {
+    for param in params.iter_mut() {
+        param.bounds = ty_bounds(mem::replace(&mut param.bounds, Vec::new()));
+    }
+    return params;
+}
+
+fn ty_bounds(bounds: Vec<clean::TyParamBound>) -> Vec<clean::TyParamBound> {
+    bounds
+}
+
+fn trait_is_same_or_supertrait(cx: &DocContext, child: ast::DefId,
+                               trait_: ast::DefId) -> bool {
+    if child == trait_ {
+        return true
+    }
+    let def = ty::lookup_trait_def(cx.tcx(), child);
+    let predicates = ty::lookup_predicates(cx.tcx(), child);
+    let generics = (&def.generics, &predicates, subst::TypeSpace).clean(cx);
+    generics.where_predicates.iter().filter_map(|pred| {
+        match *pred {
+            clean::WherePredicate::BoundPredicate {
+                ty: clean::Generic(ref s),
+                ref bounds
+            } if *s == "Self" => Some(bounds),
+            _ => None,
+        }
+    }).flat_map(|bounds| bounds.iter()).any(|bound| {
+        let poly_trait = match *bound {
+            clean::TraitBound(ref t, _) => t,
+            _ => return false,
+        };
+        match poly_trait.trait_ {
+            clean::ResolvedPath { did, .. } => {
+                trait_is_same_or_supertrait(cx, did, trait_)
+            }
+            _ => false,
+        }
+    })
+}
index 113a622b07ae47cd2430288adc66c86313c02730..a637ba9f297068c8688fe2c73979d1f26f1d6b27 100644 (file)
@@ -75,7 +75,6 @@ pub struct CrateAnalysis {
     pub exported_items: privacy::ExportedItems,
     pub public_items: privacy::PublicItems,
     pub external_paths: ExternalPaths,
-    pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
     pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
     pub inlined: RefCell<Option<HashSet<ast::DefId>>>,
 }
@@ -155,7 +154,6 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
         exported_items: exported_items,
         public_items: public_items,
         external_paths: RefCell::new(None),
-        external_traits: RefCell::new(None),
         external_typarams: RefCell::new(None),
         inlined: RefCell::new(None),
     };
@@ -168,8 +166,6 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
 
     let external_paths = ctxt.external_paths.borrow_mut().take();
     *analysis.external_paths.borrow_mut() = external_paths;
-    let map = ctxt.external_traits.borrow_mut().take();
-    *analysis.external_traits.borrow_mut() = map;
     let map = ctxt.external_typarams.borrow_mut().take();
     *analysis.external_typarams.borrow_mut() = map;
     let map = ctxt.inlined.borrow_mut().take();
index c6d8b9428c5751c26a97f79c3b310c2d0fa4693f..862bca1b813386e30934d383b91e49f90a209ec9 100644 (file)
@@ -15,6 +15,7 @@
 
 use syntax;
 use syntax::codemap::Span;
+use syntax::abi;
 use syntax::ast;
 use syntax::attr;
 use syntax::ast::{Ident, NodeId};
@@ -134,6 +135,7 @@ pub struct Function {
     pub unsafety: ast::Unsafety,
     pub whence: Span,
     pub generics: ast::Generics,
+    pub abi: abi::Abi,
 }
 
 pub struct Typedef {
index cdeeacfb78397f0d6bc9028ebbeb093e1bfc6795..0a1860c66f273ff36be921c64251a48cfa238dfa 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use clean::*;
-use std::iter::Extend;
+use std::collections::HashMap;
 use std::mem::{replace, swap};
 
 pub trait DocFolder : Sized {
@@ -80,6 +80,13 @@ fn fold_crate(&mut self, mut c: Crate) -> Crate {
         c.module = match replace(&mut c.module, None) {
             Some(module) => self.fold_item(module), None => None
         };
+        let external_traits = replace(&mut c.external_traits, HashMap::new());
+        c.external_traits = external_traits.into_iter().map(|(k, mut v)| {
+            let items = replace(&mut v.items, Vec::new());
+            v.items = items.into_iter().filter_map(|i| self.fold_item(i))
+                           .collect();
+            (k, v)
+        }).collect();
         return c;
     }
 }
index ed37b973f787ec16e4d9f9497f89732351789657..f6215dcb00c54ba34a6d39df371fce0a66b99d7c 100644 (file)
@@ -18,6 +18,7 @@
 use std::fmt;
 use std::iter::repeat;
 
+use syntax::abi::Abi;
 use syntax::ast;
 use syntax::ast_util;
 
@@ -54,6 +55,7 @@
 pub struct TyParamBounds<'a>(pub &'a [clean::TyParamBound]);
 /// Wrapper struct for emitting a comma-separated list of items
 pub struct CommaSep<'a, T: 'a>(pub &'a [T]);
+pub struct AbiSpace(pub Abi);
 
 impl VisSpace {
     pub fn get(&self) -> Option<ast::Visibility> {
@@ -281,48 +283,46 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+pub fn href(did: ast::DefId) -> Option<(String, ItemType, Vec<String>)> {
+    let cache = cache();
+    let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
+    let &(ref fqp, shortty) = match cache.paths.get(&did) {
+        Some(p) => p,
+        None => return None,
+    };
+    let mut url = if ast_util::is_local(did) || cache.inlined.contains(&did) {
+        repeat("../").take(loc.len()).collect::<String>()
+    } else {
+        match cache.extern_locations[&did.krate] {
+            render::Remote(ref s) => s.to_string(),
+            render::Local => repeat("../").take(loc.len()).collect::<String>(),
+            render::Unknown => return None,
+        }
+    };
+    for component in &fqp[..fqp.len() - 1] {
+        url.push_str(component);
+        url.push_str("/");
+    }
+    match shortty {
+        ItemType::Module => {
+            url.push_str(fqp.last().unwrap());
+            url.push_str("/index.html");
+        }
+        _ => {
+            url.push_str(shortty.to_static_str());
+            url.push_str(".");
+            url.push_str(fqp.last().unwrap());
+            url.push_str(".html");
+        }
+    }
+    Some((url, shortty, fqp.to_vec()))
+}
+
 /// Used when rendering a `ResolvedPath` structure. This invokes the `path`
 /// rendering function with the necessary arguments for linking to a local path.
-fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
+fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, path: &clean::Path,
                  print_all: bool) -> fmt::Result {
-    path(w, p, print_all,
-        |cache, loc| {
-            if ast_util::is_local(did) || cache.inlined.contains(&did) {
-                Some(repeat("../").take(loc.len()).collect::<String>())
-            } else {
-                match cache.extern_locations[&did.krate] {
-                    render::Remote(ref s) => Some(s.to_string()),
-                    render::Local => {
-                        Some(repeat("../").take(loc.len()).collect::<String>())
-                    }
-                    render::Unknown => None,
-                }
-            }
-        },
-        |cache| {
-            match cache.paths.get(&did) {
-                None => None,
-                Some(&(ref fqp, shortty)) => Some((fqp.clone(), shortty))
-            }
-        })
-}
-
-fn path<F, G>(w: &mut fmt::Formatter,
-              path: &clean::Path,
-              print_all: bool,
-              root: F,
-              info: G)
-              -> fmt::Result where
-    F: FnOnce(&render::Cache, &[String]) -> Option<String>,
-    G: FnOnce(&render::Cache) -> Option<(Vec<String>, ItemType)>,
-{
-    // The generics will get written to both the title and link
     let last = path.segments.last().unwrap();
-    let generics = format!("{}", last.params);
-
-    let loc = CURRENT_LOCATION_KEY.with(|l| l.borrow().clone());
-    let cache = cache();
-    let abs_root = root(&*cache, &loc);
     let rel_root = match &*path.segments[0].name {
         "self" => Some("./".to_string()),
         _ => None,
@@ -334,8 +334,7 @@ fn path<F, G>(w: &mut fmt::Formatter,
             Some(root) => {
                 let mut root = String::from_str(&root);
                 for seg in &path.segments[..amt] {
-                    if "super" == seg.name ||
-                            "self" == seg.name {
+                    if "super" == seg.name || "self" == seg.name {
                         try!(write!(w, "{}::", seg.name));
                     } else {
                         root.push_str(&seg.name);
@@ -355,37 +354,14 @@ fn path<F, G>(w: &mut fmt::Formatter,
         }
     }
 
-    match info(&*cache) {
-        // This is a documented path, link to it!
-        Some((ref fqp, shortty)) if abs_root.is_some() => {
-            let mut url = String::from_str(&abs_root.unwrap());
-            let to_link = &fqp[..fqp.len() - 1];
-            for component in to_link {
-                url.push_str(component);
-                url.push_str("/");
-            }
-            match shortty {
-                ItemType::Module => {
-                    url.push_str(fqp.last().unwrap());
-                    url.push_str("/index.html");
-                }
-                _ => {
-                    url.push_str(shortty.to_static_str());
-                    url.push_str(".");
-                    url.push_str(fqp.last().unwrap());
-                    url.push_str(".html");
-                }
-            }
-
+    match href(did) {
+        Some((url, shortty, fqp)) => {
             try!(write!(w, "<a class='{}' href='{}' title='{}'>{}</a>",
                           shortty, url, fqp.connect("::"), last.name));
         }
-
-        _ => {
-            try!(write!(w, "{}", last.name));
-        }
+        _ => try!(write!(w, "{}", last.name)),
     }
-    try!(write!(w, "{}", generics));
+    try!(write!(w, "{}", last.params));
     Ok(())
 }
 
@@ -491,7 +467,8 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             }
             clean::Bottom => f.write_str("!"),
             clean::RawPointer(m, ref t) => {
-                write!(f, "*{}{}", RawMutableSpace(m), **t)
+                primitive_link(f, clean::PrimitiveType::PrimitiveRawPointer,
+                               &format!("*{}{}", RawMutableSpace(m), **t))
             }
             clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
                 let lt = match *l {
@@ -527,6 +504,29 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                 }
                 Ok(())
             }
+            // It's pretty unsightly to look at `<A as B>::C` in output, and
+            // we've got hyperlinking on our side, so try to avoid longer
+            // notation as much as possible by making `C` a hyperlink to trait
+            // `B` to disambiguate.
+            //
+            // FIXME: this is still a lossy conversion and there should probably
+            //        be a better way of representing this in general? Most of
+            //        the ugliness comes from inlining across crates where
+            //        everything comes in as a fully resolved QPath (hard to
+            //        look at).
+            clean::QPath {
+                ref name,
+                ref self_type,
+                trait_: box clean::ResolvedPath { did, ref typarams, .. },
+            } => {
+                try!(write!(f, "{}::", self_type));
+                let path = clean::Path::singleton(name.clone());
+                try!(resolved_path(f, did, &path, false));
+
+                // FIXME: `typarams` are not rendered, and this seems bad?
+                drop(typarams);
+                Ok(())
+            }
             clean::QPath { ref name, ref self_type, ref trait_ } => {
                 write!(f, "&lt;{} as {}&gt;::{}", self_type, trait_, name)
             }
@@ -661,17 +661,7 @@ impl fmt::Display for clean::ViewListIdent {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self.source {
             Some(did) => {
-                let path = clean::Path {
-                    global: false,
-                    segments: vec!(clean::PathSegment {
-                        name: self.name.clone(),
-                        params: clean::PathParameters::AngleBracketed {
-                            lifetimes: Vec::new(),
-                            types: Vec::new(),
-                            bindings: Vec::new()
-                        }
-                    })
-                };
+                let path = clean::Path::singleton(self.name.clone());
                 resolved_path(f, did, &path, false)
             }
             _ => write!(f, "{}", self.name),
@@ -703,6 +693,16 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+impl fmt::Display for AbiSpace {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self.0 {
+            Abi::Rust => Ok(()),
+            Abi::C => write!(f, "extern "),
+            abi => write!(f, "extern {} ", abi),
+        }
+    }
+}
+
 impl<'a> fmt::Display for Stability<'a> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         let Stability(stab) = *self;
index 49f6107869e27f60c94a2574b956ec4278effcbd..cb80d071ce47b2cd34c2df4e2a18ac0bb573aa24 100644 (file)
 
 use libc;
 use std::ascii::AsciiExt;
-use std::ffi::CString;
 use std::cell::RefCell;
 use std::collections::HashMap;
+use std::default::Default;
+use std::ffi::CString;
 use std::fmt;
 use std::slice;
 use std::str;
@@ -182,7 +183,9 @@ fn as_bytes(&self) -> &[u8] {
 /// left as-is.)
 fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
     let trimmed = s.trim();
-    if trimmed.starts_with("# ") {
+    if trimmed == "#" {
+        Some("")
+    } else if trimmed.starts_with("# ") {
         Some(&trimmed[2..])
     } else {
         None
@@ -244,7 +247,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
                         stripped_filtered_line(l).unwrap_or(l)
                     }).collect::<Vec<&str>>().connect("\n");
                     let krate = krate.as_ref().map(|s| &**s);
-                    let test = test::maketest(&test, krate, false, false, true);
+                    let test = test::maketest(&test, krate, false,
+                                              &Default::default());
                     s.push_str(&format!("<span class='rusttest'>{}</span>", Escape(&test)));
                 });
                 s.push_str(&highlight::highlight(&text,
index ac097d051b28673aad0bf492abf01a75a4a05778..8e33a9bd80ba76848b0d49a0194959db79bc8933 100644 (file)
@@ -44,6 +44,7 @@
 use std::io::prelude::*;
 use std::io::{self, BufWriter, BufReader};
 use std::iter::repeat;
+use std::mem;
 use std::path::{PathBuf, Path};
 use std::str;
 use std::sync::Arc;
@@ -61,7 +62,7 @@
 use doctree;
 use fold::DocFolder;
 use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace, Stability};
-use html::format::{ConciseStability, TyParamBounds, WhereClause};
+use html::format::{ConciseStability, TyParamBounds, WhereClause, href, AbiSpace};
 use html::highlight;
 use html::item_type::ItemType;
 use html::layout;
@@ -136,6 +137,14 @@ pub struct Impl {
     pub stability: Option<clean::Stability>,
 }
 
+impl Impl {
+    fn trait_did(&self) -> Option<ast::DefId> {
+        self.impl_.trait_.as_ref().and_then(|tr| {
+            if let clean::ResolvedPath { did, .. } = *tr {Some(did)} else {None}
+        })
+    }
+}
+
 /// This cache is used to store information about the `clean::Crate` being
 /// rendered in order to provide more useful documentation. This contains
 /// information like all implementors of a trait, all traits a type implements,
@@ -276,7 +285,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             return write!(f, "null")
         }
 
-        let inputs: Vec<String> = self.inputs.iter().map(|ref t| format!("{}", t)).collect();
+        let inputs: Vec<String> = self.inputs.iter().map(|ref t| {
+            format!("{}", t)
+        }).collect();
         try!(write!(f, "{{\"inputs\":[{}],\"output\":", inputs.connect(",")));
 
         match self.output {
@@ -383,9 +394,7 @@ pub fn run(mut krate: clean::Crate,
         privmod: false,
         public_items: public_items,
         orphan_methods: Vec::new(),
-        traits: analysis.as_ref().map(|a| {
-            a.external_traits.borrow_mut().take().unwrap()
-        }).unwrap_or(HashMap::new()),
+        traits: mem::replace(&mut krate.external_traits, HashMap::new()),
         typarams: analysis.as_ref().map(|a| {
             a.external_typarams.borrow_mut().take().unwrap()
         }).unwrap_or(HashMap::new()),
@@ -911,9 +920,10 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                         let path = match self.paths.get(&did) {
                             Some(&(_, ItemType::Trait)) =>
                                 Some(&self.stack[..self.stack.len() - 1]),
-                            // The current stack not necessarily has correlation for
-                            // where the type was defined. On the other hand,
-                            // `paths` always has the right information if present.
+                            // The current stack not necessarily has correlation
+                            // for where the type was defined. On the other
+                            // hand, `paths` always has the right
+                            // information if present.
                             Some(&(ref fqp, ItemType::Struct)) |
                             Some(&(ref fqp, ItemType::Enum)) =>
                                 Some(&fqp[..fqp.len() - 1]),
@@ -1015,7 +1025,16 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                         self.parent_stack.push(did);
                         true
                     }
-                    _ => false
+                    ref t => {
+                        match t.primitive_type() {
+                            Some(prim) => {
+                                let did = ast_util::local_def(prim.to_node_id());
+                                self.parent_stack.push(did);
+                                true
+                            }
+                            _ => false,
+                        }
+                    }
                 }
             }
             _ => false
@@ -1027,10 +1046,6 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
             Some(item) => {
                 match item {
                     clean::Item{ attrs, inner: clean::ImplItem(i), .. } => {
-                        use clean::{Primitive, Vector, ResolvedPath, BorrowedRef};
-                        use clean::PrimitiveType::{Array, Slice, PrimitiveTuple};
-                        use clean::{FixedVector, Tuple};
-
                         // extract relevant documentation for this impl
                         let dox = match attrs.into_iter().find(|a| {
                             match *a {
@@ -1048,37 +1063,18 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
                         // Figure out the id of this impl. This may map to a
                         // primitive rather than always to a struct/enum.
                         let did = match i.for_ {
-                            ResolvedPath { did, .. } => Some(did),
-
-                            // References to primitives are picked up as well to
-                            // recognize implementations for &str, this may not
-                            // be necessary in a DST world.
-                            Primitive(p) |
-                                BorrowedRef { type_: box Primitive(p), ..} =>
-                            {
-                                Some(ast_util::local_def(p.to_node_id()))
+                            clean::ResolvedPath { did, .. } |
+                            clean::BorrowedRef {
+                                type_: box clean::ResolvedPath { did, .. }, ..
+                            } => {
+                                Some(did)
                             }
 
-                            FixedVector(..) |
-                                BorrowedRef { type_: box FixedVector(..), .. } =>
-                            {
-                                Some(ast_util::local_def(Array.to_node_id()))
+                            ref t => {
+                                t.primitive_type().map(|p| {
+                                    ast_util::local_def(p.to_node_id())
+                                })
                             }
-
-                            // In a DST world, we may only need Vector, but for now we
-                            // also pick up borrowed references
-                            Vector(..) |
-                                BorrowedRef{ type_: box Vector(..), ..  } =>
-                            {
-                                Some(ast_util::local_def(Slice.to_node_id()))
-                            }
-
-                            Tuple(..) => {
-                                let id = PrimitiveTuple.to_node_id();
-                                Some(ast_util::local_def(id))
-                            }
-
-                            _ => None,
                         };
 
                         if let Some(did) = did {
@@ -1347,7 +1343,9 @@ fn build_sidebar_items(&self, m: &clean::Module) -> HashMap<String, Vec<NameDoc>
     fn ignore_private_item(&self, it: &clean::Item) -> bool {
         match it.inner {
             clean::ModuleItem(ref m) => {
-                (m.items.len() == 0 && it.doc_value().is_none()) ||
+                (m.items.len() == 0 &&
+                 it.doc_value().is_none() &&
+                 it.visibility != Some(ast::Public)) ||
                 (self.passes.contains("strip-private") && it.visibility != Some(ast::Public))
             }
             clean::PrimitiveItem(..) => it.visibility != Some(ast::Public),
@@ -1723,10 +1721,11 @@ fn item_static(w: &mut fmt::Formatter, it: &clean::Item,
 
 fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
                  f: &clean::Function) -> fmt::Result {
-    try!(write!(w, "<pre class='rust fn'>{vis}{unsafety}fn \
+    try!(write!(w, "<pre class='rust fn'>{vis}{unsafety}{abi}fn \
                     {name}{generics}{decl}{where_clause}</pre>",
            vis = VisSpace(it.visibility),
            unsafety = UnsafetySpace(f.unsafety),
+           abi = AbiSpace(f.abi),
            name = it.name.as_ref().unwrap(),
            generics = f.generics,
            where_clause = WhereClause(&f.generics),
@@ -1773,7 +1772,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         try!(write!(w, "{{\n"));
         for t in &types {
             try!(write!(w, "    "));
-            try!(render_method(w, t));
+            try!(render_method(w, t, MethodLink::Anchor));
             try!(write!(w, ";\n"));
         }
         if types.len() > 0 && required.len() > 0 {
@@ -1781,7 +1780,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         }
         for m in &required {
             try!(write!(w, "    "));
-            try!(render_method(w, m));
+            try!(render_method(w, m, MethodLink::Anchor));
             try!(write!(w, ";\n"));
         }
         if required.len() > 0 && provided.len() > 0 {
@@ -1789,7 +1788,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         }
         for m in &provided {
             try!(write!(w, "    "));
-            try!(render_method(w, m));
+            try!(render_method(w, m, MethodLink::Anchor));
             try!(write!(w, " {{ ... }}\n"));
         }
         try!(write!(w, "}}"));
@@ -1805,7 +1804,7 @@ fn trait_item(w: &mut fmt::Formatter, m: &clean::Item)
                     shortty(m),
                     *m.name.as_ref().unwrap(),
                     ConciseStability(&m.stability)));
-        try!(render_method(w, m));
+        try!(render_method(w, m, MethodLink::Anchor));
         try!(write!(w, "</code></h3>"));
         try!(document(w, m));
         Ok(())
@@ -1844,6 +1843,9 @@ fn trait_item(w: &mut fmt::Formatter, m: &clean::Item)
         try!(write!(w, "</div>"));
     }
 
+    // If there are methods directly on this trait object, render them here.
+    try!(render_methods(w, it));
+
     let cache = cache();
     try!(write!(w, "
         <h2 id='implementors'>Implementors</h2>
@@ -1889,14 +1891,23 @@ fn assoc_type(w: &mut fmt::Formatter, it: &clean::Item,
     Ok(())
 }
 
-fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
+fn render_method(w: &mut fmt::Formatter, meth: &clean::Item,
+                 link: MethodLink) -> fmt::Result {
     fn method(w: &mut fmt::Formatter, it: &clean::Item,
               unsafety: ast::Unsafety, abi: abi::Abi,
               g: &clean::Generics, selfty: &clean::SelfTy,
-              d: &clean::FnDecl) -> fmt::Result {
+              d: &clean::FnDecl, link: MethodLink) -> fmt::Result {
         use syntax::abi::Abi;
 
-        write!(w, "{}{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\
+        let name = it.name.as_ref().unwrap();
+        let anchor = format!("#{}.{}", shortty(it), name);
+        let href = match link {
+            MethodLink::Anchor => anchor,
+            MethodLink::GotoSource(did) => {
+                href(did).map(|p| format!("{}{}", p.0, anchor)).unwrap_or(anchor)
+            }
+        };
+        write!(w, "{}{}fn <a href='{href}' class='fnname'>{name}</a>\
                    {generics}{decl}{where_clause}",
                match unsafety {
                    ast::Unsafety::Unsafe => "unsafe ",
@@ -1906,18 +1917,20 @@ fn method(w: &mut fmt::Formatter, it: &clean::Item,
                    Abi::Rust => String::new(),
                    a => format!("extern {} ", a.to_string())
                },
-               ty = shortty(it),
-               name = it.name.as_ref().unwrap(),
+               href = href,
+               name = name,
                generics = *g,
                decl = Method(selfty, d),
                where_clause = WhereClause(g))
     }
     match meth.inner {
         clean::TyMethodItem(ref m) => {
-            method(w, meth, m.unsafety, m.abi, &m.generics, &m.self_, &m.decl)
+            method(w, meth, m.unsafety, m.abi, &m.generics, &m.self_, &m.decl,
+                   link)
         }
         clean::MethodItem(ref m) => {
-            method(w, meth, m.unsafety, m.abi, &m.generics, &m.self_, &m.decl)
+            method(w, meth, m.unsafety, m.abi, &m.generics, &m.self_, &m.decl,
+                   link)
         }
         clean::AssociatedTypeItem(ref bounds, ref default) => {
             assoc_type(w, meth, bounds, default)
@@ -2144,69 +2157,73 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item,
     Ok(())
 }
 
+#[derive(Copy, Clone)]
+enum MethodLink {
+    Anchor,
+    GotoSource(ast::DefId),
+}
+
 fn render_methods(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
-    match cache().impls.get(&it.def_id) {
-        Some(v) => {
-            let (non_trait, traits): (Vec<_>, _) = v.iter().cloned()
-                .partition(|i| i.impl_.trait_.is_none());
-            if non_trait.len() > 0 {
-                try!(write!(w, "<h2 id='methods'>Methods</h2>"));
-                for i in &non_trait {
-                    try!(render_impl(w, i));
-                }
-            }
-            if traits.len() > 0 {
-                try!(write!(w, "<h2 id='implementations'>Trait \
-                                  Implementations</h2>"));
-                let (derived, manual): (Vec<_>, _) = traits.into_iter()
-                    .partition(|i| i.impl_.derived);
-                for i in &manual {
-                    try!(render_impl(w, i));
-                }
-                if derived.len() > 0 {
-                    try!(write!(w, "<h3 id='derived_implementations'>Derived Implementations \
-                                </h3>"));
-                    for i in &derived {
-                        try!(render_impl(w, i));
-                    }
-                }
+    let v = match cache().impls.get(&it.def_id) {
+        Some(v) => v.clone(),
+        None => return Ok(()),
+    };
+    let (non_trait, traits): (Vec<_>, _) = v.into_iter()
+        .partition(|i| i.impl_.trait_.is_none());
+    if non_trait.len() > 0 {
+        try!(write!(w, "<h2 id='methods'>Methods</h2>"));
+        for i in &non_trait {
+            try!(render_impl(w, i, MethodLink::Anchor));
+        }
+    }
+    if traits.len() > 0 {
+        try!(write!(w, "<h2 id='implementations'>Trait \
+                          Implementations</h2>"));
+        let (derived, manual): (Vec<_>, _) = traits.into_iter()
+            .partition(|i| i.impl_.derived);
+        for i in &manual {
+            let did = i.trait_did().unwrap();
+            try!(render_impl(w, i, MethodLink::GotoSource(did)));
+        }
+        if derived.len() > 0 {
+            try!(write!(w, "<h3 id='derived_implementations'>\
+                Derived Implementations \
+            </h3>"));
+            for i in &derived {
+                let did = i.trait_did().unwrap();
+                try!(render_impl(w, i, MethodLink::GotoSource(did)));
             }
         }
-        None => {}
     }
     Ok(())
 }
 
-fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result {
+fn render_impl(w: &mut fmt::Formatter, i: &Impl, link: MethodLink)
+               -> fmt::Result {
     try!(write!(w, "<h3 class='impl'>{}<code>impl{} ",
                 ConciseStability(&i.stability),
                 i.impl_.generics));
-    match i.impl_.polarity {
-        Some(clean::ImplPolarity::Negative) => try!(write!(w, "!")),
-        _ => {}
+    if let Some(clean::ImplPolarity::Negative) = i.impl_.polarity {
+        try!(write!(w, "!"));
     }
-    match i.impl_.trait_ {
-        Some(ref ty) => try!(write!(w, "{} for ", *ty)),
-        None => {}
+    if let Some(ref ty) = i.impl_.trait_ {
+        try!(write!(w, "{} for ", *ty));
     }
-    try!(write!(w, "{}{}</code></h3>", i.impl_.for_, WhereClause(&i.impl_.generics)));
-    match i.dox {
-        Some(ref dox) => {
-            try!(write!(w, "<div class='docblock'>{}</div>",
-                          Markdown(dox)));
-        }
-        None => {}
+    try!(write!(w, "{}{}</code></h3>", i.impl_.for_,
+                WhereClause(&i.impl_.generics)));
+    if let Some(ref dox) = i.dox {
+        try!(write!(w, "<div class='docblock'>{}</div>", Markdown(dox)));
     }
 
-    fn doctraititem(w: &mut fmt::Formatter, item: &clean::Item, dox: bool)
-                    -> fmt::Result {
+    fn doctraititem(w: &mut fmt::Formatter, item: &clean::Item,
+                    dox: bool, link: MethodLink) -> fmt::Result {
         match item.inner {
             clean::MethodItem(..) | clean::TyMethodItem(..) => {
                 try!(write!(w, "<h4 id='method.{}' class='{}'>{}<code>",
                             *item.name.as_ref().unwrap(),
                             shortty(item),
                             ConciseStability(&item.stability)));
-                try!(render_method(w, item));
+                try!(render_method(w, item, link));
                 try!(write!(w, "</code></h4>\n"));
             }
             clean::TypedefItem(ref tydef) => {
@@ -2239,11 +2256,12 @@ fn doctraititem(w: &mut fmt::Formatter, item: &clean::Item, dox: bool)
     }
 
     try!(write!(w, "<div class='impl-items'>"));
-    for trait_item in &i.impl_.items {
-        try!(doctraititem(w, trait_item, true));
+    for trait_item in i.impl_.items.iter() {
+        try!(doctraititem(w, trait_item, true, link));
     }
 
     fn render_default_methods(w: &mut fmt::Formatter,
+                              did: ast::DefId,
                               t: &clean::Trait,
                               i: &clean::Impl) -> fmt::Result {
         for trait_item in &t.items {
@@ -2253,7 +2271,8 @@ fn render_default_methods(w: &mut fmt::Formatter,
                 None => {}
             }
 
-            try!(doctraititem(w, trait_item, false));
+            try!(doctraititem(w, trait_item, false,
+                              MethodLink::GotoSource(did)));
         }
         Ok(())
     }
@@ -2262,17 +2281,10 @@ fn render_default_methods(w: &mut fmt::Formatter,
     // default methods which weren't overridden in the implementation block.
     // FIXME: this also needs to be done for associated types, whenever defaults
     // for them work.
-    match i.impl_.trait_ {
-        Some(clean::ResolvedPath { did, .. }) => {
-            try!({
-                match cache().traits.get(&did) {
-                    Some(t) => try!(render_default_methods(w, t, &i.impl_)),
-                    None => {}
-                }
-                Ok(())
-            })
+    if let Some(clean::ResolvedPath { did, .. }) = i.impl_.trait_ {
+        if let Some(t) = cache().traits.get(&did) {
+            try!(render_default_methods(w, did, t, &i.impl_));
         }
-        Some(..) | None => {}
     }
     try!(write!(w, "</div>"));
     Ok(())
index a84da60b01831da1b6e7733ef105539a7d0dec0c..6541564d8e2b8d013743558e8ea415ab8bd62b8b 100644 (file)
@@ -8,9 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::default::Default;
 use std::fs::File;
-use std::io;
 use std::io::prelude::*;
+use std::io;
 use std::path::{PathBuf, Path};
 
 use core;
@@ -23,7 +24,7 @@
 use html::escape::Escape;
 use html::markdown;
 use html::markdown::{Markdown, MarkdownWithToc, find_testable_code, reset_headers};
-use test::Collector;
+use test::{TestOptions, Collector};
 
 /// Separate any lines at the start of the file that begin with `%`.
 fn extract_leading_metadata<'a>(s: &'a str) -> (Vec<&'a str>, &'a str) {
@@ -58,7 +59,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
     let input_str = load_or_return!(input, 1, 2);
     let playground = matches.opt_str("markdown-playground-url");
     if playground.is_some() {
-        markdown::PLAYGROUND_KRATE.with(|s| { *s.borrow_mut() = None; });
+        markdown::PLAYGROUND_KRATE.with(|s| { *s.borrow_mut() = Some(None); });
     }
     let playground = playground.unwrap_or("".to_string());
 
@@ -143,7 +144,10 @@ pub fn test(input: &str, libs: SearchPaths, externs: core::Externs,
             mut test_args: Vec<String>) -> isize {
     let input_str = load_or_return!(input, 1, 2);
 
-    let mut collector = Collector::new(input.to_string(), libs, externs, true, false);
+    let mut opts = TestOptions::default();
+    opts.no_crate_inject = true;
+    let mut collector = Collector::new(input.to_string(), libs, externs,
+                                       true, opts);
     find_testable_code(&input_str, &mut collector);
     test_args.insert(0, "rustdoctest".to_string());
     testing::test_main(&test_args, collector.tests);
index f5bee6240d46c80dc5ee321742b500cb958ec3c0..94b521a89cfbc96f1c30b401097e29be885bf658 100644 (file)
 use passes;
 use visit_ast::RustdocVisitor;
 
+#[derive(Clone, Default)]
+pub struct TestOptions {
+    pub no_crate_inject: bool,
+    pub attrs: Vec<String>,
+}
+
 pub fn run(input: &str,
            cfgs: Vec<String>,
            libs: SearchPaths,
@@ -75,7 +81,7 @@ pub fn run(input: &str,
                                                      "rustdoc-test", None)
         .expect("phase_2_configure_and_expand aborted in rustdoc!");
 
-    let inject_crate = should_inject_crate(&krate);
+    let opts = scrape_test_config(&krate);
 
     let ctx = core::DocContext {
         krate: &krate,
@@ -102,7 +108,7 @@ pub fn run(input: &str,
                                        libs,
                                        externs,
                                        false,
-                                       inject_crate);
+                                       opts);
     collector.fold_crate(krate);
 
     test_args.insert(0, "rustdoctest".to_string());
@@ -113,41 +119,44 @@ pub fn run(input: &str,
 }
 
 // Look for #![doc(test(no_crate_inject))], used by crates in the std facade
-fn should_inject_crate(krate: &::syntax::ast::Crate) -> bool {
+fn scrape_test_config(krate: &::syntax::ast::Crate) -> TestOptions {
     use syntax::attr::AttrMetaMethods;
+    use syntax::print::pprust;
 
-    let mut inject_crate = true;
-
-    for attr in &krate.attrs {
-        if attr.check_name("doc") {
-            for list in attr.meta_item_list().into_iter() {
-                for attr in list {
-                    if attr.check_name("test") {
-                        for list in attr.meta_item_list().into_iter() {
-                            for attr in list {
-                                if attr.check_name("no_crate_inject") {
-                                    inject_crate = false;
-                                }
-                            }
-                        }
-                    }
+    let mut opts = TestOptions {
+        no_crate_inject: false,
+        attrs: Vec::new(),
+    };
+
+    let attrs = krate.attrs.iter().filter(|a| a.check_name("doc"))
+                     .filter_map(|a| a.meta_item_list())
+                     .flat_map(|l| l.iter())
+                     .filter(|a| a.check_name("test"))
+                     .filter_map(|a| a.meta_item_list())
+                     .flat_map(|l| l.iter());
+    for attr in attrs {
+        if attr.check_name("no_crate_inject") {
+            opts.no_crate_inject = true;
+        }
+        if attr.check_name("attr") {
+            if let Some(l) = attr.meta_item_list() {
+                for item in l {
+                    opts.attrs.push(pprust::meta_item_to_string(item));
                 }
             }
         }
     }
 
-    return inject_crate;
+    return opts;
 }
 
-#[allow(deprecated)]
 fn runtest(test: &str, cratename: &str, libs: SearchPaths,
            externs: core::Externs,
            should_panic: bool, no_run: bool, as_test_harness: bool,
-           inject_crate: bool) {
+           opts: &TestOptions) {
     // the test harness wants its own `main` & top level functions, so
     // never wrap the test in `fn main() { ... }`
-    let test = maketest(test, Some(cratename), true, as_test_harness,
-                        inject_crate);
+    let test = maketest(test, Some(cratename), as_test_harness, opts);
     let input = config::Input::Str(test.to_string());
 
     let sessopts = config::Options {
@@ -250,8 +259,8 @@ fn drop(&mut self) {
     }
 }
 
-pub fn maketest(s: &str, cratename: Option<&str>, lints: bool,
-                dont_insert_main: bool, inject_crate: bool) -> String {
+pub fn maketest(s: &str, cratename: Option<&str>, dont_insert_main: bool,
+                opts: &TestOptions) -> String {
     let (crate_attrs, everything_else) = partition_source(s);
 
     let mut prog = String::new();
@@ -260,20 +269,18 @@ pub fn maketest(s: &str, cratename: Option<&str>, lints: bool,
     // are intended to be crate attributes.
     prog.push_str(&crate_attrs);
 
-    if lints {
-        prog.push_str(r"
-#![allow(unused_variables, unused_assignments, unused_mut, unused_attributes, dead_code)]
-");
+    // Next, any attributes for other aspects such as lints.
+    for attr in &opts.attrs {
+        prog.push_str(&format!("#![{}]\n", attr));
     }
 
     // Don't inject `extern crate std` because it's already injected by the
     // compiler.
-    if !s.contains("extern crate") && inject_crate {
+    if !s.contains("extern crate") && !opts.no_crate_inject {
         match cratename {
             Some(cratename) => {
                 if s.contains(cratename) {
-                    prog.push_str(&format!("extern crate {};\n",
-                                           cratename));
+                    prog.push_str(&format!("extern crate {};\n", cratename));
                 }
             }
             None => {}
@@ -325,12 +332,12 @@ pub struct Collector {
     use_headers: bool,
     current_header: Option<String>,
     cratename: String,
-    inject_crate: bool
+    opts: TestOptions,
 }
 
 impl Collector {
     pub fn new(cratename: String, libs: SearchPaths, externs: core::Externs,
-               use_headers: bool, inject_crate: bool) -> Collector {
+               use_headers: bool, opts: TestOptions) -> Collector {
         Collector {
             tests: Vec::new(),
             names: Vec::new(),
@@ -340,7 +347,7 @@ pub fn new(cratename: String, libs: SearchPaths, externs: core::Externs,
             use_headers: use_headers,
             current_header: None,
             cratename: cratename,
-            inject_crate: inject_crate
+            opts: opts,
         }
     }
 
@@ -357,13 +364,14 @@ pub fn add_test(&mut self, test: String,
         let libs = self.libs.clone();
         let externs = self.externs.clone();
         let cratename = self.cratename.to_string();
-        let inject_crate = self.inject_crate;
+        let opts = self.opts.clone();
         debug!("Creating test {}: {}", name, test);
         self.tests.push(testing::TestDescAndFn {
             desc: testing::TestDesc {
                 name: testing::DynTestName(name),
                 ignore: should_ignore,
-                should_panic: testing::ShouldPanic::No, // compiler failures are test failures
+                // compiler failures are test failures
+                should_panic: testing::ShouldPanic::No,
             },
             testfn: testing::DynTestFn(Box::new(move|| {
                 runtest(&test,
@@ -373,7 +381,7 @@ pub fn add_test(&mut self, test: String,
                         should_panic,
                         no_run,
                         as_test_harness,
-                        inject_crate);
+                        &opts);
             }))
         });
     }
index 3f813b30ecc1d748aad6cf52d173a93adc861de7..a1fa96322a4e3634aa4ad177edff412cfaac3955 100644 (file)
@@ -12,6 +12,7 @@
 //! usable for clean
 
 use std::collections::HashSet;
+use std::mem;
 
 use syntax::abi;
 use syntax::ast;
@@ -40,6 +41,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
     pub cx: &'a core::DocContext<'tcx>,
     pub analysis: Option<&'a core::CrateAnalysis>,
     view_item_stack: HashSet<ast::NodeId>,
+    inlining_from_glob: bool,
 }
 
 impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
@@ -54,6 +56,7 @@ pub fn new(cx: &'a core::DocContext<'tcx>,
             cx: cx,
             analysis: analysis,
             view_item_stack: stack,
+            inlining_from_glob: false,
         }
     }
 
@@ -120,7 +123,7 @@ pub fn visit_enum_def(&mut self, it: &ast::Item,
 
     pub fn visit_fn(&mut self, item: &ast::Item,
                     name: ast::Ident, fd: &ast::FnDecl,
-                    unsafety: &ast::Unsafety, _abi: &abi::Abi,
+                    unsafety: &ast::Unsafety, abi: &abi::Abi,
                     gen: &ast::Generics) -> Function {
         debug!("Visiting fn");
         Function {
@@ -133,6 +136,7 @@ pub fn visit_fn(&mut self, item: &ast::Item,
             whence: item.span,
             generics: gen.clone(),
             unsafety: *unsafety,
+            abi: *abi,
         }
     }
 
@@ -209,6 +213,7 @@ fn resolve_id(&mut self, id: ast::NodeId, renamed: Option<ast::Ident>,
         let ret = match tcx.map.get(def.node) {
             ast_map::NodeItem(it) => {
                 if glob {
+                    let prev = mem::replace(&mut self.inlining_from_glob, true);
                     match it.node {
                         ast::ItemMod(ref m) => {
                             for i in &m.items {
@@ -218,6 +223,7 @@ fn resolve_id(&mut self, id: ast::NodeId, renamed: Option<ast::Ident>,
                         ast::ItemEnum(..) => {}
                         _ => { panic!("glob not mapped to a module or enum"); }
                     }
+                    self.inlining_from_glob = prev;
                 } else {
                     self.visit_item(it, renamed, om);
                 }
@@ -356,7 +362,11 @@ pub fn visit_item(&mut self, item: &ast::Item,
                     vis: item.vis,
                     stab: self.stability(item.id),
                 };
-                om.impls.push(i);
+                // Don't duplicate impls when inlining glob imports, we'll pick
+                // them up regardless of where they're located.
+                if !self.inlining_from_glob {
+                    om.impls.push(i);
+                }
             },
             ast::ItemDefaultImpl(unsafety, ref trait_ref) => {
                 let i = DefaultImpl {
@@ -366,7 +376,10 @@ pub fn visit_item(&mut self, item: &ast::Item,
                     attrs: item.attrs.clone(),
                     whence: item.span,
                 };
-                om.def_traits.push(i);
+                // see comment above about ItemImpl
+                if !self.inlining_from_glob {
+                    om.def_traits.push(i);
+                }
             }
             ast::ItemForeignMod(ref fm) => {
                 om.foreigns.push(fm.clone());
index 5fbc21797ab5a0442d82ebd5fc2254f54219b9fb..f897d565321dabe638452b90b644a1b1ece30e6b 100644 (file)
@@ -304,7 +304,6 @@ fn first<A, B>((a, _): (A, B)) -> A { a }
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
     /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -335,7 +334,6 @@ pub fn difference<'a>(&'a self, other: &'a HashSet<T, S>) -> Difference<'a, T, S
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
     /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -362,7 +360,6 @@ pub fn symmetric_difference<'a>(&'a self, other: &'a HashSet<T, S>)
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
     /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -388,7 +385,6 @@ pub fn intersection<'a>(&'a self, other: &'a HashSet<T, S>) -> Intersection<'a,
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
     /// let b: HashSet<_> = [4, 2, 3, 4].iter().cloned().collect();
@@ -471,7 +467,6 @@ pub fn clear(&mut self) { self.map.clear() }
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     ///
     /// let set: HashSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -491,7 +486,6 @@ pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     ///
     /// let a: HashSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -513,7 +507,6 @@ pub fn is_disjoint(&self, other: &HashSet<T, S>) -> bool {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     ///
     /// let sup: HashSet<_> = [1, 2, 3].iter().cloned().collect();
@@ -535,7 +528,6 @@ pub fn is_subset(&self, other: &HashSet<T, S>) -> bool {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::collections::HashSet;
     ///
     /// let sub: HashSet<_> = [1, 2].iter().cloned().collect();
index 0ac97b71298b85df6c737c6bec041bb512522544..48b95ce6439c9c4ceba4683cb8759225a01f113e 100644 (file)
 
 //! Collection types.
 //!
-//! Rust's standard collection library provides efficient implementations of the most common
-//! general purpose programming data structures. By using the standard implementations,
-//! it should be possible for two libraries to communicate without significant data conversion.
-//!
-//! To get this out of the way: you should probably just use `Vec` or `HashMap`. These two
-//! collections cover most use cases for generic data storage and processing. They are
-//! exceptionally good at doing what they do. All the other collections in the standard
-//! library have specific use cases where they are the optimal choice, but these cases are
-//! borderline *niche* in comparison. Even when `Vec` and `HashMap` are technically suboptimal,
-//! they're probably a good enough choice to get started.
+//! Rust's standard collection library provides efficient implementations of the
+//! most common general purpose programming data structures. By using the
+//! standard implementations, it should be possible for two libraries to
+//! communicate without significant data conversion.
+//!
+//! To get this out of the way: you should probably just use `Vec` or `HashMap`.
+//! These two collections cover most use cases for generic data storage and
+//! processing. They are exceptionally good at doing what they do. All the other
+//! collections in the standard library have specific use cases where they are
+//! the optimal choice, but these cases are borderline *niche* in comparison.
+//! Even when `Vec` and `HashMap` are technically suboptimal, they're probably a
+//! good enough choice to get started.
 //!
 //! Rust's collections can be grouped into four major categories:
 //!
 //!
 //! # When Should You Use Which Collection?
 //!
-//! These are fairly high-level and quick break-downs of when each collection should be
-//! considered. Detailed discussions of strengths and weaknesses of individual collections
-//! can be found on their own documentation pages.
+//! These are fairly high-level and quick break-downs of when each collection
+//! should be considered. Detailed discussions of strengths and weaknesses of
+//! individual collections can be found on their own documentation pages.
 //!
 //! ### Use a `Vec` when:
-//! * You want to collect items up to be processed or sent elsewhere later, and don't care about
-//! any properties of the actual values being stored.
-//! * You want a sequence of elements in a particular order, and will only be appending to
-//! (or near) the end.
+//! * You want to collect items up to be processed or sent elsewhere later, and
+//!   don't care about any properties of the actual values being stored.
+//! * You want a sequence of elements in a particular order, and will only be
+//!   appending to (or near) the end.
 //! * You want a stack.
 //! * You want a resizable array.
 //! * You want a heap-allocated array.
 //!
 //! ### Use a `VecDeque` when:
-//! * You want a `Vec` that supports efficient insertion at both ends of the sequence.
+//! * You want a `Vec` that supports efficient insertion at both ends of the
+//!   sequence.
 //! * You want a queue.
 //! * You want a double-ended queue (deque).
 //!
 //! ### Use a `LinkedList` when:
-//! * You want a `Vec` or `VecDeque` of unknown size, and can't tolerate amortization.
+//! * You want a `Vec` or `VecDeque` of unknown size, and can't tolerate
+//!   amortization.
 //! * You want to efficiently split and append lists.
-//! * You are *absolutely* certain you *really*, *truly*, want a doubly linked list.
+//! * You are *absolutely* certain you *really*, *truly*, want a doubly linked
+//!   list.
 //!
 //! ### Use a `HashMap` when:
 //! * You want to associate arbitrary keys with an arbitrary value.
@@ -60,7 +65,8 @@
 //!
 //! ### Use a `BTreeMap` when:
 //! * You're interested in what the smallest or largest key-value pair is.
-//! * You want to find the largest or smallest key that is smaller or larger than something
+//! * You want to find the largest or smallest key that is smaller or larger
+//!   than something
 //! * You want to be able to get all of the entries in order on-demand.
 //! * You want a sorted map.
 //!
 //! * You want a `BitVec`, but want `Set` properties
 //!
 //! ### Use a `BinaryHeap` when:
-//! * You want to store a bunch of elements, but only ever want to process the "biggest"
-//! or "most important" one at any given time.
+//!
+//! * You want to store a bunch of elements, but only ever want to process the
+//!   "biggest" or "most important" one at any given time.
 //! * You want a priority queue.
 //!
 //! # Performance
 //!
-//! Choosing the right collection for the job requires an understanding of what each collection
-//! is good at. Here we briefly summarize the performance of different collections for certain
-//! important operations. For further details, see each type's documentation, and note that the
-//! names of actual methods may differ from the tables below on certain collections.
+//! Choosing the right collection for the job requires an understanding of what
+//! each collection is good at. Here we briefly summarize the performance of
+//! different collections for certain important operations. For further details,
+//! see each type's documentation, and note that the names of actual methods may
+//! differ from the tables below on certain collections.
 //!
-//! Throughout the documentation, we will follow a few conventions. For all operations,
-//! the collection's size is denoted by n. If another collection is involved in the operation, it
-//! contains m elements. Operations which have an *amortized* cost are suffixed with a `*`.
-//! Operations with an *expected* cost are suffixed with a `~`.
+//! Throughout the documentation, we will follow a few conventions. For all
+//! operations, the collection's size is denoted by n. If another collection is
+//! involved in the operation, it contains m elements. Operations which have an
+//! *amortized* cost are suffixed with a `*`.  Operations with an *expected*
+//! cost are suffixed with a `~`.
 //!
-//! All amortized costs are for the potential need to resize when capacity is exhausted.
-//! If a resize occurs it will take O(n) time. Our collections never automatically shrink,
-//! so removal operations aren't amortized. Over a sufficiently large series of
-//! operations, the average cost per operation will deterministically equal the given cost.
+//! All amortized costs are for the potential need to resize when capacity is
+//! exhausted.  If a resize occurs it will take O(n) time. Our collections never
+//! automatically shrink, so removal operations aren't amortized. Over a
+//! sufficiently large series of operations, the average cost per operation will
+//! deterministically equal the given cost.
 //!
-//! Only HashMap has expected costs, due to the probabilistic nature of hashing. It is
-//! theoretically possible, though very unlikely, for HashMap to experience worse performance.
+//! Only HashMap has expected costs, due to the probabilistic nature of hashing.
+//! It is theoretically possible, though very unlikely, for HashMap to
+//! experience worse performance.
 //!
 //! ## Sequences
 //!
 //!
 //! ## Maps
 //!
-//! For Sets, all operations have the cost of the equivalent Map operation. For BitSet,
+//! For Sets, all operations have the cost of the equivalent Map operation. For
+//! BitSet,
 //! refer to VecMap.
 //!
 //! |          | get       | insert   | remove   | predecessor |
 //! | BTreeMap | O(log n)  | O(log n) | O(log n) | O(log n)    |
 //! | VecMap   | O(1)      | O(1)?    | O(1)     | O(n)        |
 //!
-//! Note that VecMap is *incredibly* inefficient in terms of space. The O(1) insertion time
-//! assumes space for the element is already allocated. Otherwise, a large key may require a
-//! massive reallocation, with no direct relation to the number of elements in the collection.
-//! VecMap should only be seriously considered for small keys.
+//! Note that VecMap is *incredibly* inefficient in terms of space. The O(1)
+//! insertion time assumes space for the element is already allocated.
+//! Otherwise, a large key may require a massive reallocation, with no direct
+//! relation to the number of elements in the collection.  VecMap should only be
+//! seriously considered for small keys.
 //!
 //! Note also that BTreeMap's precise preformance depends on the value of B.
 //!
 //! # Correct and Efficient Usage of Collections
 //!
-//! Of course, knowing which collection is the right one for the job doesn't instantly
-//! permit you to use it correctly. Here are some quick tips for efficient and correct
-//! usage of the standard collections in general. If you're interested in how to use a
-//! specific collection in particular, consult its documentation for detailed discussion
-//! and code examples.
+//! Of course, knowing which collection is the right one for the job doesn't
+//! instantly permit you to use it correctly. Here are some quick tips for
+//! efficient and correct usage of the standard collections in general. If
+//! you're interested in how to use a specific collection in particular, consult
+//! its documentation for detailed discussion and code examples.
 //!
 //! ## Capacity Management
 //!
-//! Many collections provide several constructors and methods that refer to "capacity".
-//! These collections are generally built on top of an array. Optimally, this array would be
-//! exactly the right size to fit only the elements stored in the collection, but for the
-//! collection to do this would be very inefficient. If the backing array was exactly the
-//! right size at all times, then every time an element is inserted, the collection would
-//! have to grow the array to fit it. Due to the way memory is allocated and managed on most
-//! computers, this would almost surely require allocating an entirely new array and
-//! copying every single element from the old one into the new one. Hopefully you can
-//! see that this wouldn't be very efficient to do on every operation.
-//!
-//! Most collections therefore use an *amortized* allocation strategy. They generally let
-//! themselves have a fair amount of unoccupied space so that they only have to grow
-//! on occasion. When they do grow, they allocate a substantially larger array to move
-//! the elements into so that it will take a while for another grow to be required. While
-//! this strategy is great in general, it would be even better if the collection *never*
-//! had to resize its backing array. Unfortunately, the collection itself doesn't have
-//! enough information to do this itself. Therefore, it is up to us programmers to give it
-//! hints.
-//!
-//! Any `with_capacity` constructor will instruct the collection to allocate enough space
-//! for the specified number of elements. Ideally this will be for exactly that many
-//! elements, but some implementation details may prevent this. `Vec` and `VecDeque` can
-//! be relied on to allocate exactly the requested amount, though. Use `with_capacity`
-//! when you know exactly how many elements will be inserted, or at least have a
-//! reasonable upper-bound on that number.
-//!
-//! When anticipating a large influx of elements, the `reserve` family of methods can
-//! be used to hint to the collection how much room it should make for the coming items.
-//! As with `with_capacity`, the precise behavior of these methods will be specific to
-//! the collection of interest.
-//!
-//! For optimal performance, collections will generally avoid shrinking themselves.
-//! If you believe that a collection will not soon contain any more elements, or
-//! just really need the memory, the `shrink_to_fit` method prompts the collection
-//! to shrink the backing array to the minimum size capable of holding its elements.
-//!
-//! Finally, if ever you're interested in what the actual capacity of the collection is,
-//! most collections provide a `capacity` method to query this information on demand.
-//! This can be useful for debugging purposes, or for use with the `reserve` methods.
+//! Many collections provide several constructors and methods that refer to
+//! "capacity".  These collections are generally built on top of an array.
+//! Optimally, this array would be exactly the right size to fit only the
+//! elements stored in the collection, but for the collection to do this would
+//! be very inefficient. If the backing array was exactly the right size at all
+//! times, then every time an element is inserted, the collection would have to
+//! grow the array to fit it. Due to the way memory is allocated and managed on
+//! most computers, this would almost surely require allocating an entirely new
+//! array and copying every single element from the old one into the new one.
+//! Hopefully you can see that this wouldn't be very efficient to do on every
+//! operation.
+//!
+//! Most collections therefore use an *amortized* allocation strategy. They
+//! generally let themselves have a fair amount of unoccupied space so that they
+//! only have to grow on occasion. When they do grow, they allocate a
+//! substantially larger array to move the elements into so that it will take a
+//! while for another grow to be required. While this strategy is great in
+//! general, it would be even better if the collection *never* had to resize its
+//! backing array. Unfortunately, the collection itself doesn't have enough
+//! information to do this itself. Therefore, it is up to us programmers to give
+//! it hints.
+//!
+//! Any `with_capacity` constructor will instruct the collection to allocate
+//! enough space for the specified number of elements. Ideally this will be for
+//! exactly that many elements, but some implementation details may prevent
+//! this. `Vec` and `VecDeque` can be relied on to allocate exactly the
+//! requested amount, though. Use `with_capacity` when you know exactly how many
+//! elements will be inserted, or at least have a reasonable upper-bound on that
+//! number.
+//!
+//! When anticipating a large influx of elements, the `reserve` family of
+//! methods can be used to hint to the collection how much room it should make
+//! for the coming items.  As with `with_capacity`, the precise behavior of
+//! these methods will be specific to the collection of interest.
+//!
+//! For optimal performance, collections will generally avoid shrinking
+//! themselves.  If you believe that a collection will not soon contain any more
+//! elements, or just really need the memory, the `shrink_to_fit` method prompts
+//! the collection to shrink the backing array to the minimum size capable of
+//! holding its elements.
+//!
+//! Finally, if ever you're interested in what the actual capacity of the
+//! collection is, most collections provide a `capacity` method to query this
+//! information on demand.  This can be useful for debugging purposes, or for
+//! use with the `reserve` methods.
 //!
 //! ## Iterators
 //!
-//! Iterators are a powerful and robust mechanism used throughout Rust's standard
-//! libraries. Iterators provide a sequence of values in a generic, safe, efficient
-//! and convenient way. The contents of an iterator are usually *lazily* evaluated,
-//! so that only the values that are actually needed are ever actually produced, and
-//! no allocation need be done to temporarily store them. Iterators are primarily
-//! consumed using a `for` loop, although many functions also take iterators where
-//! a collection or sequence of values is desired.
-//!
-//! All of the standard collections provide several iterators for performing bulk
-//! manipulation of their contents. The three primary iterators almost every collection
-//! should provide are `iter`, `iter_mut`, and `into_iter`. Some of these are not
-//! provided on collections where it would be unsound or unreasonable to provide them.
+//! Iterators are a powerful and robust mechanism used throughout Rust's
+//! standard libraries. Iterators provide a sequence of values in a generic,
+//! safe, efficient and convenient way. The contents of an iterator are usually
+//! *lazily* evaluated, so that only the values that are actually needed are
+//! ever actually produced, and no allocation need be done to temporarily store
+//! them. Iterators are primarily consumed using a `for` loop, although many
+//! functions also take iterators where a collection or sequence of values is
+//! desired.
+//!
+//! All of the standard collections provide several iterators for performing
+//! bulk manipulation of their contents. The three primary iterators almost
+//! every collection should provide are `iter`, `iter_mut`, and `into_iter`.
+//! Some of these are not provided on collections where it would be unsound or
+//! unreasonable to provide them.
 //!
 //! `iter` provides an iterator of immutable references to all the contents of a
-//! collection in the most "natural" order. For sequence collections like `Vec`, this
-//! means the items will be yielded in increasing order of index starting at 0. For ordered
-//! collections like `BTreeMap`, this means that the items will be yielded in sorted order.
-//! For unordered collections like `HashMap`, the items will be yielded in whatever order
-//! the internal representation made most convenient. This is great for reading through
-//! all the contents of the collection.
+//! collection in the most "natural" order. For sequence collections like `Vec`,
+//! this means the items will be yielded in increasing order of index starting
+//! at 0. For ordered collections like `BTreeMap`, this means that the items
+//! will be yielded in sorted order.  For unordered collections like `HashMap`,
+//! the items will be yielded in whatever order the internal representation made
+//! most convenient. This is great for reading through all the contents of the
+//! collection.
 //!
 //! ```
 //! let vec = vec![1, 2, 3, 4];
 //! }
 //! ```
 //!
-//! `iter_mut` provides an iterator of *mutable* references in the same order as `iter`.
-//! This is great for mutating all the contents of the collection.
+//! `iter_mut` provides an iterator of *mutable* references in the same order as
+//! `iter`.  This is great for mutating all the contents of the collection.
 //!
 //! ```
 //! let mut vec = vec![1, 2, 3, 4];
 //! }
 //! ```
 //!
-//! `into_iter` transforms the actual collection into an iterator over its contents
-//! by-value. This is great when the collection itself is no longer needed, and the
-//! values are needed elsewhere. Using `extend` with `into_iter` is the main way that
-//! contents of one collection are moved into another. Calling `collect` on an iterator
-//! itself is also a great way to convert one collection into another. Both of these
-//! methods should internally use the capacity management tools discussed in the
-//! previous section to do this as efficiently as possible.
+//! `into_iter` transforms the actual collection into an iterator over its
+//! contents by-value. This is great when the collection itself is no longer
+//! needed, and the values are needed elsewhere. Using `extend` with `into_iter`
+//! is the main way that contents of one collection are moved into another.
+//! Calling `collect` on an iterator itself is also a great way to convert one
+//! collection into another. Both of these methods should internally use the
+//! capacity management tools discussed in the previous section to do this as
+//! efficiently as possible.
 //!
 //! ```
 //! let mut vec1 = vec![1, 2, 3, 4];
 //! let buf: VecDeque<_> = vec.into_iter().collect();
 //! ```
 //!
-//! Iterators also provide a series of *adapter* methods for performing common tasks to
-//! sequences. Among the adapters are functional favorites like `map`, `fold`, `skip`,
-//! and `take`. Of particular interest to collections is the `rev` adapter, that
-//! reverses any iterator that supports this operation. Most collections provide reversible
-//! iterators as the way to iterate over them in reverse order.
+//! Iterators also provide a series of *adapter* methods for performing common
+//! tasks to sequences. Among the adapters are functional favorites like `map`,
+//! `fold`, `skip`, and `take`. Of particular interest to collections is the
+//! `rev` adapter, that reverses any iterator that supports this operation. Most
+//! collections provide reversible iterators as the way to iterate over them in
+//! reverse order.
 //!
 //! ```
 //! let vec = vec![1, 2, 3, 4];
 //! }
 //! ```
 //!
-//! Several other collection methods also return iterators to yield a sequence of results
-//! but avoid allocating an entire collection to store the result in. This provides maximum
-//! flexibility as `collect` or `extend` can be called to "pipe" the sequence into any
-//! collection if desired. Otherwise, the sequence can be looped over with a `for` loop. The
-//! iterator can also be discarded after partial use, preventing the computation of the unused
-//! items.
+//! Several other collection methods also return iterators to yield a sequence
+//! of results but avoid allocating an entire collection to store the result in.
+//! This provides maximum flexibility as `collect` or `extend` can be called to
+//! "pipe" the sequence into any collection if desired. Otherwise, the sequence
+//! can be looped over with a `for` loop. The iterator can also be discarded
+//! after partial use, preventing the computation of the unused items.
 //!
 //! ## Entries
 //!
-//! The `entry` API is intended to provide an efficient mechanism for manipulating
-//! the contents of a map conditionally on the presence of a key or not. The primary
-//! motivating use case for this is to provide efficient accumulator maps. For instance,
-//! if one wishes to maintain a count of the number of times each key has been seen,
-//! they will have to perform some conditional logic on whether this is the first time
-//! the key has been seen or not. Normally, this would require a `find` followed by an
-//! `insert`, effectively duplicating the search effort on each insertion.
-//!
-//! When a user calls `map.entry(&key)`, the map will search for the key and then yield
-//! a variant of the `Entry` enum.
-//!
-//! If a `Vacant(entry)` is yielded, then the key *was not* found. In this case the
-//! only valid operation is to `insert` a value into the entry. When this is done,
-//! the vacant entry is consumed and converted into a mutable reference to the
-//! the value that was inserted. This allows for further manipulation of the value
-//! beyond the lifetime of the search itself. This is useful if complex logic needs to
-//! be performed on the value regardless of whether the value was just inserted.
-//!
-//! If an `Occupied(entry)` is yielded, then the key *was* found. In this case, the user
-//! has several options: they can `get`, `insert`, or `remove` the value of the occupied
-//! entry. Additionally, they can convert the occupied entry into a mutable reference
-//! to its value, providing symmetry to the vacant `insert` case.
+//! The `entry` API is intended to provide an efficient mechanism for
+//! manipulating the contents of a map conditionally on the presence of a key or
+//! not. The primary motivating use case for this is to provide efficient
+//! accumulator maps. For instance, if one wishes to maintain a count of the
+//! number of times each key has been seen, they will have to perform some
+//! conditional logic on whether this is the first time the key has been seen or
+//! not. Normally, this would require a `find` followed by an `insert`,
+//! effectively duplicating the search effort on each insertion.
+//!
+//! When a user calls `map.entry(&key)`, the map will search for the key and
+//! then yield a variant of the `Entry` enum.
+//!
+//! If a `Vacant(entry)` is yielded, then the key *was not* found. In this case
+//! the only valid operation is to `insert` a value into the entry. When this is
+//! done, the vacant entry is consumed and converted into a mutable reference to
+//! the the value that was inserted. This allows for further manipulation of the
+//! value beyond the lifetime of the search itself. This is useful if complex
+//! logic needs to be performed on the value regardless of whether the value was
+//! just inserted.
+//!
+//! If an `Occupied(entry)` is yielded, then the key *was* found. In this case,
+//! the user has several options: they can `get`, `insert`, or `remove` the
+//! value of the occupied entry. Additionally, they can convert the occupied
+//! entry into a mutable reference to its value, providing symmetry to the
+//! vacant `insert` case.
 //!
 //! ### Examples
 //!
-//! Here are the two primary ways in which `entry` is used. First, a simple example
-//! where the logic performed on the values is trivial.
+//! Here are the two primary ways in which `entry` is used. First, a simple
+//! example where the logic performed on the values is trivial.
 //!
 //! #### Counting the number of times each character in a string occurs
 //!
 //! ```
-//! # #![feature(collections)]
-//! use std::collections::btree_map::{BTreeMap, Entry};
+//! use std::collections::btree_map::BTreeMap;
 //!
 //! let mut count = BTreeMap::new();
 //! let message = "she sells sea shells by the sea shore";
 //! }
 //! ```
 //!
-//! When the logic to be performed on the value is more complex, we may simply use
-//! the `entry` API to ensure that the value is initialized, and perform the logic
-//! afterwards.
+//! When the logic to be performed on the value is more complex, we may simply
+//! use the `entry` API to ensure that the value is initialized, and perform the
+//! logic afterwards.
 //!
 //! #### Tracking the inebriation of customers at a bar
 //!
 //! ```
-//! # #![feature(collections)]
-//! use std::collections::btree_map::{BTreeMap, Entry};
+//! use std::collections::btree_map::BTreeMap;
 //!
 //! // A client of the bar. They have an id and a blood alcohol level.
 //! struct Person { id: u32, blood_alcohol: f32 }
index 4e2dade9a3ca862cdacb7b2eb5e80929f6536fa8..914830d9dcfea20a84c4681e9409b90e419c62bd 100644 (file)
@@ -96,14 +96,16 @@ pub struct WalkDir {
 
 /// Options and flags which can be used to configure how a file is opened.
 ///
-/// This builder exposes the ability to configure how a `File` is opened and what operations are
-/// permitted on the open file. The `File::open` and `File::create` methods are aliases for
-/// commonly used options using this builder.
+/// This builder exposes the ability to configure how a `File` is opened and
+/// what operations are permitted on the open file. The `File::open` and
+/// `File::create` methods are aliases for commonly used options using this
+/// builder.
 ///
-/// Generally speaking, when using `OpenOptions`, you'll first call `new()`, then chain calls to
-/// methods to set each option, then call `open()`, passing the path of the file you're trying to
-/// open. This will give you a [`io::Result`][result] with a [`File`][file] inside that you can
-/// further operate on.
+/// Generally speaking, when using `OpenOptions`, you'll first call `new()`,
+/// then chain calls to methods to set each option, then call `open()`, passing
+/// the path of the file you're trying to open. This will give you a
+/// [`io::Result`][result] with a [`File`][file] inside that you can further
+/// operate on.
 ///
 /// [result]: ../io/type.Result.html
 /// [file]: struct.File.html
@@ -113,16 +115,15 @@ pub struct WalkDir {
 /// Opening a file to read:
 ///
 /// ```no_run
-/// use std::fs;
 /// use std::fs::OpenOptions;
 ///
 /// let file = OpenOptions::new().read(true).open("foo.txt");
 /// ```
 ///
-/// Opening a file for both reading and writing, as well as creating it if it doesn't exist:
+/// Opening a file for both reading and writing, as well as creating it if it
+/// doesn't exist:
 ///
 /// ```
-/// use std::fs;
 /// use std::fs::OpenOptions;
 ///
 /// let file = OpenOptions::new()
@@ -771,7 +772,9 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
 /// ```no_run
 /// use std::fs;
 ///
-/// fs::copy("foo.txt", "bar.txt");
+/// # fn foo() -> std::io::Result<()> {
+/// try!(fs::copy("foo.txt", "bar.txt"));
+/// # Ok(()) }
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
index 333ae8f26a0d7fa028429ebedeca4218b96cb6a6..880770eb41485b15f05427f5ebf4a5aa84e2eec5 100644 (file)
@@ -14,6 +14,7 @@
 //! by adding a glob import to the top of I/O heavy modules:
 //!
 //! ```
+//! # #![allow(unused_imports)]
 //! use std::io::prelude::*;
 //! ```
 //!
index df81981c3f4451eb2f9e8dd4c8963fff82a37d80..b329494a0526bccfa827c18259e1295c927a6cbd 100644 (file)
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
        html_root_url = "http://doc.rust-lang.org/nightly/",
        html_playground_url = "http://play.rust-lang.org/")]
-#![doc(test(no_crate_inject))]
+#![doc(test(no_crate_inject, attr(deny(warnings))))]
+#![doc(test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
 
 #![feature(alloc)]
 #![feature(box_syntax)]
index 18d8fcc8a5288966bccca93ce5043cadcd409cc5..702b76e7d1c46dfd56a7c4f249336f14b0cfca1e 100644 (file)
@@ -281,7 +281,6 @@ fn hash<H: hash::Hasher>(&self, s: &mut H) {
 /// Some examples:
 ///
 /// ```no_run
-/// # #![feature(net)]
 /// use std::net::{SocketAddrV4, TcpStream, UdpSocket, TcpListener, Ipv4Addr};
 ///
 /// fn main() {
@@ -302,7 +301,7 @@ fn hash<H: hash::Hasher>(&self, s: &mut H) {
 ///     let tcp_l = TcpListener::bind("localhost:12345");
 ///
 ///     let mut udp_s = UdpSocket::bind(("127.0.0.1", port)).unwrap();
-///     udp_s.send_to(&[7], (ip, 23451));
+///     udp_s.send_to(&[7], (ip, 23451)).unwrap();
 /// }
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
index 04d1013af1faec67fd37be4cd91415bad249241f..2da6f7420ac9d31b7e7f26dbb94b992f8ebdd268 100644 (file)
@@ -27,7 +27,6 @@
 /// # Examples
 ///
 /// ```no_run
-/// # #![feature(net)]
 /// use std::io::prelude::*;
 /// use std::net::TcpStream;
 ///
@@ -47,7 +46,6 @@
 /// # Examples
 ///
 /// ```no_run
-/// # #![feature(net)]
 /// use std::net::{TcpListener, TcpStream};
 /// use std::thread;
 ///
index 7b14e4dbea6788420954a43731d8853ddb154a66..bec9c09bc314676ec35fb91f8d373d3d033f3fbe 100644 (file)
@@ -27,7 +27,6 @@
 /// # Examples
 ///
 /// ```no_run
-/// # #![feature(net)]
 /// use std::net::UdpSocket;
 ///
 /// # fn foo() -> std::io::Result<()> {
index 0ae4d3c5bd66b13f269729986f6d510911187bed..6128469c60e50cb2b4f39d45445637b7500c7686 100644 (file)
@@ -422,7 +422,6 @@ pub fn is_finite(self) -> bool { num::Float::is_finite(self) }
     /// [subnormal][subnormal], or `NaN`.
     ///
     /// ```
-    /// # #![feature(std_misc)]
     /// use std::f32;
     ///
     /// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32
@@ -856,7 +855,7 @@ pub fn log10(self) -> f32 { num::Float::log10(self) }
     /// Convert radians to degrees.
     ///
     /// ```
-    /// # #![feature(std_misc, core)]
+    /// # #![feature(std_misc)]
     /// use std::f32::{self, consts};
     ///
     /// let angle = consts::PI;
@@ -987,7 +986,6 @@ pub fn min(self, other: f32) -> f32 {
     /// * Else: `self - other`
     ///
     /// ```
-    /// # #![feature(std_misc)]
     /// use std::f32;
     ///
     /// let x = 3.0f32;
@@ -1008,7 +1006,6 @@ pub fn abs_sub(self, other: f32) -> f32 {
     /// Take the cubic root of a number.
     ///
     /// ```
-    /// # #![feature(std_misc)]
     /// use std::f32;
     ///
     /// let x = 8.0f32;
@@ -1210,8 +1207,6 @@ pub fn sin_cos(self) -> (f32, f32) {
     /// number is close to zero.
     ///
     /// ```
-    /// use std::f64;
-    ///
     /// let x = 7.0f64;
     ///
     /// // e^(ln(7)) - 1
index 2de03e2e72d664c41b3bde2324c33f9659a7b00e..ea516e5b20b7a35199395f6a6dab0dfd8d6f50eb 100644 (file)
@@ -280,7 +280,6 @@ pub trait Float
     /// [subnormal][subnormal], or `NaN`.
     ///
     /// ```
-    /// # #![feature(std_misc)]
     /// use std::num::Float;
     /// use std::f32;
     ///
@@ -307,7 +306,6 @@ pub trait Float
     /// predicate instead.
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::{Float, FpCategory};
     /// use std::f32;
     ///
@@ -417,7 +415,6 @@ pub trait Float
     /// number is `Float::nan()`.
     ///
     /// ```
-    /// # #![feature(std_misc)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -441,7 +438,6 @@ pub trait Float
     /// - `Float::nan()` if the number is `Float::nan()`
     ///
     /// ```
-    /// # #![feature(std_misc)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -686,7 +682,6 @@ pub trait Float
     /// Convert radians to degrees.
     ///
     /// ```
-    /// # #![feature(std_misc, core)]
     /// use std::num::Float;
     /// use std::f64::consts;
     ///
@@ -701,7 +696,7 @@ pub trait Float
     /// Convert degrees to radians.
     ///
     /// ```
-    /// # #![feature(std_misc, core)]
+    /// # #![feature(std_misc)]
     /// use std::num::Float;
     /// use std::f64::consts;
     ///
@@ -849,7 +844,6 @@ pub trait Float
     /// Computes the sine of a number (in radians).
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -864,7 +858,6 @@ pub trait Float
     /// Computes the cosine of a number (in radians).
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -879,7 +872,6 @@ pub trait Float
     /// Computes the tangent of a number (in radians).
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -895,7 +887,6 @@ pub trait Float
     /// [-1, 1].
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -913,7 +904,6 @@ pub trait Float
     /// [-1, 1].
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -949,7 +939,6 @@ pub trait Float
     /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -975,7 +964,6 @@ pub trait Float
     /// `(sin(x), cos(x))`.
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -1011,7 +999,6 @@ pub trait Float
     /// the operations were performed separately.
     ///
     /// ```
-    /// # #![feature(std_misc, core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -1028,7 +1015,6 @@ pub trait Float
     /// Hyperbolic sine function.
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -1047,7 +1033,6 @@ pub trait Float
     /// Hyperbolic cosine function.
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -1066,7 +1051,6 @@ pub trait Float
     /// Hyperbolic tangent function.
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
@@ -1113,7 +1097,6 @@ pub trait Float
     /// Inverse hyperbolic tangent function.
     ///
     /// ```
-    /// # #![feature(core)]
     /// use std::num::Float;
     /// use std::f64;
     ///
index 5e93757668cbd45e3c4dc78bce1b4cdf826d8a1f..f62b1a836fd10201a4452780afe93d0427245efc 100644 (file)
@@ -48,7 +48,7 @@
 //! * Read lines from stdin
 //!
 //!     ```rust
-//!     # #![feature(old_io, old_path)]
+//!     # #![feature(old_io)]
 //!     use std::old_io as io;
 //!     use std::old_io::*;
 //!
index 099fe657f2602b761d74e3cffb955240b54a4434..f5310292b911b8c4f15a204263c849a3179e3341 100644 (file)
@@ -414,7 +414,7 @@ fn from_str(s: &str) -> Result<SocketAddr, ParseError> {
 /// Some examples:
 ///
 /// ```rust,no_run
-/// # #![feature(old_io, core, convert)]
+/// # #![feature(old_io)]
 /// # #![allow(unused_must_use)]
 ///
 /// use std::old_io::{TcpStream, TcpListener};
index 3a071e832af64baa01133cc934eb18ae775becd2..7b23c3e1d03f21f8f60be42924fc1608f3d84f5d 100644 (file)
@@ -191,7 +191,7 @@ impl UnixListener {
     /// let server = Path::new("/path/to/my/socket");
     /// let stream = UnixListener::bind(&server);
     /// for mut client in stream.listen().incoming() {
-    ///     client.write(&[1, 2, 3, 4]);
+    ///     let _ = client.write(&[1, 2, 3, 4]);
     /// }
     /// # }
     /// ```
index ad2d5b4681978c99e5231f20cacdaad5eb4ee7c8..b55d1f4db07f78e6e5c57480c557d4192828dca1 100644 (file)
@@ -367,7 +367,7 @@ pub fn spawn(&self) -> IoResult<Process> {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(old_io, core, convert)]
+    /// # #![feature(old_io)]
     /// use std::old_io::Command;
     ///
     /// let output = match Command::new("cat").arg("foot.txt").output() {
index 9c88533d3bac605cb55b328b7265b8cb98a9ab5b..2dee90e9a6660daad699813cf8bac4ab0923bae6 100644 (file)
@@ -48,7 +48,7 @@
 //!
 //! ## Examples
 //!
-//! ```rust
+//! ```rust,ignore
 //! # #![feature(old_path, old_io)]
 //! use std::old_io::fs::PathExtensions;
 //! use std::old_path::{Path, GenericPath};
@@ -144,12 +144,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```no_run
     /// # #![feature(old_path)]
-    /// use std::old_path::{Path, GenericPath};
-    /// # foo();
-    /// # #[cfg(windows)] fn foo() {}
-    /// # #[cfg(unix)] fn foo() {
+    /// # fn main() {
+    /// use std::old_path::Path;
     /// let path = Path::new("foo/bar");
     /// # }
     /// ```
@@ -170,12 +168,10 @@ fn new<T: BytesContainer>(path: T) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```no_run
     /// # #![feature(old_path)]
-    /// use std::old_path::{Path, GenericPath};
-    /// # foo();
-    /// # #[cfg(windows)] fn foo() {}
-    /// # #[cfg(unix)] fn foo() {
+    /// # fn main() {
+    /// use std::old_path::Path;
     /// let x: &[u8] = b"foo\0";
     /// assert!(Path::new_opt(x).is_none());
     /// # }
@@ -194,7 +190,7 @@ fn new_opt<T: BytesContainer>(path: T) -> Option<Self> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -213,7 +209,7 @@ fn as_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -229,7 +225,7 @@ fn as_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -246,7 +242,7 @@ fn as_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -266,7 +262,7 @@ fn display<'a>(&'a self) -> Display<'a, Self> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -285,7 +281,7 @@ fn filename_display<'a>(&'a self) -> Display<'a, Self> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -302,7 +298,7 @@ fn filename_display<'a>(&'a self) -> Display<'a, Self> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -323,7 +319,7 @@ fn dirname_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -340,7 +336,7 @@ fn dirname_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -361,7 +357,7 @@ fn filename_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -390,7 +386,7 @@ fn filestem<'a>(&'a self) -> Option<&'a [u8]> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -412,7 +408,7 @@ fn filestem_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -441,7 +437,7 @@ fn extension<'a>(&'a self) -> Option<&'a [u8]> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -461,7 +457,7 @@ fn extension_str<'a>(&'a self) -> Option<&'a str> {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -489,7 +485,7 @@ fn set_filename<T: BytesContainer>(&mut self, filename: T) {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -541,7 +537,7 @@ fn set_extension<T: BytesContainer>(&mut self, extension: T) {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -568,7 +564,7 @@ fn with_filename<T: BytesContainer>(&self, filename: T) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -594,7 +590,7 @@ fn with_extension<T: BytesContainer>(&self, extension: T) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -615,7 +611,7 @@ fn dir_path(&self) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -632,7 +628,7 @@ fn dir_path(&self) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -658,7 +654,7 @@ fn push<T: BytesContainer>(&mut self, path: T) {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -689,7 +685,7 @@ fn push_many<T: BytesContainer>(&mut self, paths: &[T]) {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -708,7 +704,7 @@ fn push_many<T: BytesContainer>(&mut self, paths: &[T]) {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -735,7 +731,7 @@ fn join<T: BytesContainer>(&self, path: T) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -759,7 +755,7 @@ fn join_many<T: BytesContainer>(&self, paths: &[T]) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -778,7 +774,7 @@ fn join_many<T: BytesContainer>(&self, paths: &[T]) -> Self {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -798,7 +794,7 @@ fn is_relative(&self) -> bool {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -819,7 +815,7 @@ fn is_relative(&self) -> bool {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
@@ -837,7 +833,7 @@ fn is_relative(&self) -> bool {
     ///
     /// # Examples
     ///
-    /// ```
+    /// ```ignore
     /// # #![feature(old_path)]
     /// use std::old_path::{Path, GenericPath};
     /// # foo();
index 52f5965db809a76c5168a5d8985d006569e1aaf6..cac1540d0ec4c4fee8f7253d20b4ee8dd643e7db 100644 (file)
 use ffi::OsStr;
 use fmt;
 use io::{self, Error, ErrorKind};
-use libc;
 use path;
 use sync::mpsc::{channel, Receiver};
 use sys::pipe2::{self, AnonPipe};
 use sys::process2::Command as CommandImp;
 use sys::process2::Process as ProcessImp;
 use sys::process2::ExitStatus as ExitStatusImp;
+use sys::process2::Stdio as StdioImp2;
 use sys_common::{AsInner, AsInnerMut};
 use thread;
 
@@ -38,8 +38,6 @@
 /// # Examples
 ///
 /// ```should_panic
-/// # #![feature(process)]
-///
 /// use std::process::Command;
 ///
 /// let output = Command::new("/bin/cat").arg("file.txt").output().unwrap_or_else(|e| {
@@ -229,13 +227,13 @@ pub fn stderr(&mut self, cfg: Stdio) -> &mut Command {
 
     fn spawn_inner(&self, default_io: StdioImp) -> io::Result<Child> {
         let (their_stdin, our_stdin) = try!(
-            setup_io(self.stdin.as_ref().unwrap_or(&default_io), 0, true)
+            setup_io(self.stdin.as_ref().unwrap_or(&default_io), true)
         );
         let (their_stdout, our_stdout) = try!(
-            setup_io(self.stdout.as_ref().unwrap_or(&default_io), 1, false)
+            setup_io(self.stdout.as_ref().unwrap_or(&default_io), false)
         );
         let (their_stderr, our_stderr) = try!(
-            setup_io(self.stderr.as_ref().unwrap_or(&default_io), 2, false)
+            setup_io(self.stderr.as_ref().unwrap_or(&default_io), false)
         );
 
         match ProcessImp::spawn(&self.inner, their_stdin, their_stdout, their_stderr) {
@@ -267,10 +265,8 @@ pub fn spawn(&mut self) -> io::Result<Child> {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(process)]
     /// use std::process::Command;
-    ///
-    /// let output = Command::new("cat").arg("foot.txt").output().unwrap_or_else(|e| {
+    /// let output = Command::new("cat").arg("foo.txt").output().unwrap_or_else(|e| {
     ///     panic!("failed to execute process: {}", e)
     /// });
     ///
@@ -291,7 +287,6 @@ pub fn output(&mut self) -> io::Result<Output> {
     /// # Examples
     ///
     /// ```
-    /// # #![feature(process)]
     /// use std::process::Command;
     ///
     /// let status = Command::new("ls").status().unwrap_or_else(|e| {
@@ -328,23 +323,19 @@ impl AsInnerMut<CommandImp> for Command {
     fn as_inner_mut(&mut self) -> &mut CommandImp { &mut self.inner }
 }
 
-fn setup_io(io: &StdioImp, fd: libc::c_int, readable: bool)
-            -> io::Result<(Option<AnonPipe>, Option<AnonPipe>)>
+fn setup_io(io: &StdioImp, readable: bool)
+            -> io::Result<(StdioImp2, Option<AnonPipe>)>
 {
     use self::StdioImp::*;
     Ok(match *io {
-        Null => {
-            (None, None)
-        }
-        Inherit => {
-            (Some(AnonPipe::from_fd(fd)), None)
-        }
+        Null => (StdioImp2::None, None),
+        Inherit => (StdioImp2::Inherit, None),
         Piped => {
-            let (reader, writer) = try!(unsafe { pipe2::anon_pipe() });
+            let (reader, writer) = try!(pipe2::anon_pipe());
             if readable {
-                (Some(reader), Some(writer))
+                (StdioImp2::Piped(reader), Some(writer))
             } else {
-                (Some(writer), Some(reader))
+                (StdioImp2::Piped(writer), Some(reader))
             }
         }
     })
index e5444843516008bcfd66df49d7d19dab513f86cb..93b27b6ce9efdc7f9cc3ad54e00553ee0e559348 100644 (file)
@@ -345,8 +345,8 @@ impl<T> !Sync for SyncSender<T> {}
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct RecvError;
 
-/// This enumeration is the list of the possible reasons that try_recv could not
-/// return data when called.
+/// This enumeration is the list of the possible reasons that `try_recv` could
+/// not return data when called.
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub enum TryRecvError {
index 5ae508e46106a7f35fcbc431d90db5aba18a1e4b..aa4bf821207648a3c4fe7cab02c37115bc2bae81 100644 (file)
           target_os = "dragonfly",
           target_os = "bitrig",
           target_os = "openbsd"))]
-pub const FIONBIO: libc::c_ulong = 0x8004667e;
-#[cfg(any(all(target_os = "linux",
-              any(target_arch = "x86",
-                  target_arch = "x86_64",
-                  target_arch = "arm",
-                  target_arch = "aarch64")),
-          target_os = "android"))]
-pub const FIONBIO: libc::c_ulong = 0x5421;
-#[cfg(all(target_os = "linux",
-          any(target_arch = "mips",
-              target_arch = "mipsel",
-              target_arch = "powerpc")))]
-pub const FIONBIO: libc::c_ulong = 0x667e;
-
-#[cfg(any(target_os = "macos",
-          target_os = "ios",
-          target_os = "freebsd",
-          target_os = "dragonfly",
-          target_os = "bitrig",
-          target_os = "openbsd"))]
-pub const FIOCLEX: libc::c_ulong = 0x20006601;
+mod consts {
+    use libc;
+    pub const FIONBIO: libc::c_ulong = 0x8004667e;
+    pub const FIOCLEX: libc::c_ulong = 0x20006601;
+    pub const FIONCLEX: libc::c_ulong = 0x20006602;
+}
 #[cfg(any(all(target_os = "linux",
               any(target_arch = "x86",
                   target_arch = "x86_64",
                   target_arch = "arm",
                   target_arch = "aarch64")),
           target_os = "android"))]
-pub const FIOCLEX: libc::c_ulong = 0x5451;
+mod consts {
+    use libc;
+    pub const FIONBIO: libc::c_ulong = 0x5421;
+    pub const FIOCLEX: libc::c_ulong = 0x5451;
+    pub const FIONCLEX: libc::c_ulong = 0x5450;
+}
 #[cfg(all(target_os = "linux",
           any(target_arch = "mips",
               target_arch = "mipsel",
               target_arch = "powerpc")))]
-pub const FIOCLEX: libc::c_ulong = 0x6601;
+mod consts {
+    use libc;
+    pub const FIONBIO: libc::c_ulong = 0x667e;
+    pub const FIOCLEX: libc::c_ulong = 0x6601;
+    pub const FIONCLEX: libc::c_ulong = 0x6600;
+}
+pub use self::consts::*;
 
 #[cfg(any(target_os = "macos",
           target_os = "ios",
@@ -163,6 +159,8 @@ pub fn getpwuid_r(uid: libc::uid_t,
     pub fn utimes(filename: *const libc::c_char,
                   times: *const libc::timeval) -> libc::c_int;
     pub fn gai_strerror(errcode: libc::c_int) -> *const libc::c_char;
+    pub fn setgroups(ngroups: libc::c_int,
+                     ptr: *const libc::c_void) -> libc::c_int;
 }
 
 #[cfg(any(target_os = "macos", target_os = "ios"))]
index f7c57c3f5e53747992ef77809b574dc02ae0a1a2..d86c77624e833eb5c559c2654c7a5941343d3bcf 100644 (file)
@@ -13,6 +13,7 @@
 use io;
 use libc::{self, c_int, size_t, c_void};
 use mem;
+use sys::c;
 use sys::cvt;
 use sys_common::AsInner;
 
@@ -51,6 +52,13 @@ pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
         }));
         Ok(ret as usize)
     }
+
+    pub fn set_cloexec(&self) {
+        unsafe {
+            let ret = c::ioctl(self.fd, c::FIOCLEX);
+            debug_assert_eq!(ret, 0);
+        }
+    }
 }
 
 impl AsInner<c_int> for FileDesc {
@@ -59,14 +67,11 @@ fn as_inner(&self) -> &c_int { &self.fd }
 
 impl Drop for FileDesc {
     fn drop(&mut self) {
-        // closing stdio file handles makes no sense, so never do it. Also, note
-        // that errors are ignored when closing a file descriptor. The reason
-        // for this is that if an error occurs we don't actually know if the
-        // file descriptor was closed or not, and if we retried (for something
-        // like EINTR), we might close another valid file descriptor (opened
-        // after we closed ours.
-        if self.fd > libc::STDERR_FILENO {
-            let _ = unsafe { libc::close(self.fd) };
-        }
+        // Note that errors are ignored when closing a file descriptor. The
+        // reason for this is that if an error occurs we don't actually know if
+        // the file descriptor was closed or not, and if we retried (for
+        // something like EINTR), we might close another valid file descriptor
+        // (opened after we closed ours.
+        let _ = unsafe { libc::close(self.fd) };
     }
 }
index c0426af051be372061b45cae94f907247ae57298..ac121f1c82e09ddedade920cbea8f2e6a8300935 100644 (file)
@@ -205,19 +205,27 @@ fn flag(&mut self, bit: c_int, on: bool) {
 
 impl File {
     pub fn open(path: &Path, opts: &OpenOptions) -> io::Result<File> {
+        let path = try!(cstr(path));
+        File::open_c(&path, opts)
+    }
+
+    pub fn open_c(path: &CStr, opts: &OpenOptions) -> io::Result<File> {
         let flags = opts.flags | match (opts.read, opts.write) {
             (true, true) => libc::O_RDWR,
             (false, true) => libc::O_WRONLY,
             (true, false) |
             (false, false) => libc::O_RDONLY,
         };
-        let path = try!(cstr(path));
         let fd = try!(cvt_r(|| unsafe {
             libc::open(path.as_ptr(), flags, opts.mode)
         }));
-        Ok(File(FileDesc::new(fd)))
+        let fd = FileDesc::new(fd);
+        fd.set_cloexec();
+        Ok(File(fd))
     }
 
+    pub fn into_fd(self) -> FileDesc { self.0 }
+
     pub fn file_attr(&self) -> io::Result<FileAttr> {
         let mut stat: libc::stat = unsafe { mem::zeroed() };
         try!(cvt(unsafe { libc::fstat(self.0.raw(), &mut stat) }));
index 908136a42ab00a96723bc902d863def68d5f26ef..2e1cbb2a1e127094269b6dee8d70fe60eab33685 100644 (file)
@@ -47,7 +47,9 @@ pub fn new(addr: &SocketAddr, ty: c_int) -> io::Result<Socket> {
         };
         unsafe {
             let fd = try!(cvt(libc::socket(fam, ty, 0)));
-            Ok(Socket(FileDesc::new(fd)))
+            let fd = FileDesc::new(fd);
+            fd.set_cloexec();
+            Ok(Socket(fd))
         }
     }
 
@@ -56,13 +58,16 @@ pub fn accept(&self, storage: *mut libc::sockaddr,
         let fd = try!(cvt_r(|| unsafe {
             libc::accept(self.0.raw(), storage, len)
         }));
-        Ok(Socket(FileDesc::new(fd)))
+        let fd = FileDesc::new(fd);
+        fd.set_cloexec();
+        Ok(Socket(fd))
     }
 
     pub fn duplicate(&self) -> io::Result<Socket> {
-        cvt(unsafe { libc::dup(self.0.raw()) }).map(|fd| {
-            Socket(FileDesc::new(fd))
-        })
+        let fd = try!(cvt(unsafe { libc::dup(self.0.raw()) }));
+        let fd = FileDesc::new(fd);
+        fd.set_cloexec();
+        Ok(Socket(fd))
     }
 
     pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
index 7af2c0f0b2a8ea883d1d5286d256e9e848cc7e7f..e9d8c69fefb52035cbdb2a341211dcbf76ccab48 100644 (file)
 
 pub struct AnonPipe(FileDesc);
 
-pub unsafe fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
+pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
     let mut fds = [0; 2];
-    if libc::pipe(fds.as_mut_ptr()) == 0 {
-        Ok((AnonPipe::from_fd(fds[0]),
-            AnonPipe::from_fd(fds[1])))
+    if unsafe { libc::pipe(fds.as_mut_ptr()) == 0 } {
+        Ok((AnonPipe::from_fd(fds[0]), AnonPipe::from_fd(fds[1])))
     } else {
         Err(io::Error::last_os_error())
     }
@@ -32,7 +31,9 @@ pub unsafe fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
 
 impl AnonPipe {
     pub fn from_fd(fd: libc::c_int) -> AnonPipe {
-        AnonPipe(FileDesc::new(fd))
+        let fd = FileDesc::new(fd);
+        fd.set_cloexec();
+        AnonPipe(fd)
     }
 
     pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
@@ -43,7 +44,7 @@ pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
         self.0.write(buf)
     }
 
-    pub fn raw(&self) -> libc::c_int {
-        self.0.raw()
+    pub fn into_fd(self) -> FileDesc {
+        self.0
     }
 }
index 60f00c80b4abdbf61b42b7020627a9603f28121a..0b4e871454db044d347fc3b03a421e39c358d254 100644 (file)
 
 use collections::HashMap;
 use env;
-use ffi::{OsString, OsStr, CString};
+use ffi::{OsString, OsStr, CString, CStr};
 use fmt;
 use io::{self, Error, ErrorKind};
 use libc::{self, pid_t, c_void, c_int, gid_t, uid_t};
-use mem;
 use ptr;
 use sys::pipe2::AnonPipe;
 use sys::{self, retry, c, cvt};
+use sys::fs2::{File, OpenOptions};
 
 ////////////////////////////////////////////////////////////////////////////////
 // Command
@@ -119,6 +119,12 @@ pub struct Process {
     pid: pid_t
 }
 
+pub enum Stdio {
+    Inherit,
+    Piped(AnonPipe),
+    None,
+}
+
 const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX";
 
 impl Process {
@@ -128,221 +134,185 @@ pub unsafe fn kill(&self) -> io::Result<()> {
     }
 
     pub fn spawn(cfg: &Command,
-                 in_fd: Option<AnonPipe>, out_fd: Option<AnonPipe>, err_fd: Option<AnonPipe>)
-                 -> io::Result<Process>
-    {
-        use libc::funcs::posix88::unistd::{fork, dup2, close, chdir, execvp};
-
-        mod rustrt {
-            extern {
-                pub fn rust_unset_sigprocmask();
+                 in_fd: Stdio,
+                 out_fd: Stdio,
+                 err_fd: Stdio) -> io::Result<Process> {
+        let dirp = cfg.cwd.as_ref().map(|c| c.as_ptr()).unwrap_or(ptr::null());
+
+        let (envp, _a, _b) = make_envp(cfg.env.as_ref());
+        let (argv, _a) = make_argv(&cfg.program, &cfg.args);
+        let (input, output) = try!(sys::pipe2::anon_pipe());
+
+        let pid = unsafe {
+            match libc::fork() {
+                0 => {
+                    drop(input);
+                    Process::child_after_fork(cfg, output, argv, envp, dirp,
+                                              in_fd, out_fd, err_fd)
+                }
+                n if n < 0 => return Err(Error::last_os_error()),
+                n => n,
+            }
+        };
+
+        let p = Process{ pid: pid };
+        drop(output);
+        let mut bytes = [0; 8];
+
+        // loop to handle EINTR
+        loop {
+            match input.read(&mut bytes) {
+                Ok(0) => return Ok(p),
+                Ok(8) => {
+                    assert!(combine(CLOEXEC_MSG_FOOTER) == combine(&bytes[4.. 8]),
+                            "Validation on the CLOEXEC pipe failed: {:?}", bytes);
+                    let errno = combine(&bytes[0.. 4]);
+                    assert!(p.wait().is_ok(),
+                            "wait() should either return Ok or panic");
+                    return Err(Error::from_raw_os_error(errno))
+                }
+                Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
+                Err(e) => {
+                    assert!(p.wait().is_ok(),
+                            "wait() should either return Ok or panic");
+                    panic!("the CLOEXEC pipe failed: {:?}", e)
+                },
+                Ok(..) => { // pipe I/O up to PIPE_BUF bytes should be atomic
+                    assert!(p.wait().is_ok(),
+                            "wait() should either return Ok or panic");
+                    panic!("short read on the CLOEXEC pipe")
+                }
             }
         }
 
-        unsafe fn set_cloexec(fd: c_int) {
-            let ret = c::ioctl(fd, c::FIOCLEX);
-            assert_eq!(ret, 0);
-        }
+        fn combine(arr: &[u8]) -> i32 {
+            let a = arr[0] as u32;
+            let b = arr[1] as u32;
+            let c = arr[2] as u32;
+            let d = arr[3] as u32;
 
-        #[cfg(all(target_os = "android", target_arch = "aarch64"))]
-        unsafe fn getdtablesize() -> c_int {
-            libc::sysconf(libc::consts::os::sysconf::_SC_OPEN_MAX) as c_int
+            ((a << 24) | (b << 16) | (c << 8) | (d << 0)) as i32
         }
+    }
 
-        #[cfg(not(all(target_os = "android", target_arch = "aarch64")))]
-        unsafe fn getdtablesize() -> c_int {
-            libc::funcs::bsd44::getdtablesize()
+    // And at this point we've reached a special time in the life of the
+    // child. The child must now be considered hamstrung and unable to
+    // do anything other than syscalls really. Consider the following
+    // scenario:
+    //
+    //      1. Thread A of process 1 grabs the malloc() mutex
+    //      2. Thread B of process 1 forks(), creating thread C
+    //      3. Thread C of process 2 then attempts to malloc()
+    //      4. The memory of process 2 is the same as the memory of
+    //         process 1, so the mutex is locked.
+    //
+    // This situation looks a lot like deadlock, right? It turns out
+    // that this is what pthread_atfork() takes care of, which is
+    // presumably implemented across platforms. The first thing that
+    // threads to *before* forking is to do things like grab the malloc
+    // mutex, and then after the fork they unlock it.
+    //
+    // Despite this information, libnative's spawn has been witnessed to
+    // deadlock on both OSX and FreeBSD. I'm not entirely sure why, but
+    // all collected backtraces point at malloc/free traffic in the
+    // child spawned process.
+    //
+    // For this reason, the block of code below should contain 0
+    // invocations of either malloc of free (or their related friends).
+    //
+    // As an example of not having malloc/free traffic, we don't close
+    // this file descriptor by dropping the FileDesc (which contains an
+    // allocation). Instead we just close it manually. This will never
+    // have the drop glue anyway because this code never returns (the
+    // child will either exec() or invoke libc::exit)
+    unsafe fn child_after_fork(cfg: &Command,
+                               mut output: AnonPipe,
+                               argv: *const *const libc::c_char,
+                               envp: *const libc::c_void,
+                               dirp: *const libc::c_char,
+                               in_fd: Stdio,
+                               out_fd: Stdio,
+                               err_fd: Stdio) -> ! {
+        fn fail(output: &mut AnonPipe) -> ! {
+            let errno = sys::os::errno() as u32;
+            let bytes = [
+                (errno >> 24) as u8,
+                (errno >> 16) as u8,
+                (errno >>  8) as u8,
+                (errno >>  0) as u8,
+                CLOEXEC_MSG_FOOTER[0], CLOEXEC_MSG_FOOTER[1],
+                CLOEXEC_MSG_FOOTER[2], CLOEXEC_MSG_FOOTER[3]
+            ];
+            // pipe I/O up to PIPE_BUF bytes should be atomic, and then we want
+            // to be sure we *don't* run at_exit destructors as we're being torn
+            // down regardless
+            assert!(output.write(&bytes).is_ok());
+            unsafe { libc::_exit(1) }
         }
 
-        let dirp = cfg.cwd.as_ref().map(|c| c.as_ptr()).unwrap_or(ptr::null());
-
-        with_envp(cfg.env.as_ref(), |envp: *const c_void| {
-            with_argv(&cfg.program, &cfg.args, |argv: *const *const libc::c_char| unsafe {
-                let (input, mut output) = try!(sys::pipe2::anon_pipe());
-
-                // We may use this in the child, so perform allocations before the
-                // fork
-                let devnull = b"/dev/null\0";
-
-                set_cloexec(output.raw());
-
-                let pid = fork();
-                if pid < 0 {
-                    return Err(Error::last_os_error())
-                } else if pid > 0 {
-                    #[inline]
-                    fn combine(arr: &[u8]) -> i32 {
-                        let a = arr[0] as u32;
-                        let b = arr[1] as u32;
-                        let c = arr[2] as u32;
-                        let d = arr[3] as u32;
-
-                        ((a << 24) | (b << 16) | (c << 8) | (d << 0)) as i32
-                    }
-
-                    let p = Process{ pid: pid };
-                    drop(output);
-                    let mut bytes = [0; 8];
-
-                    // loop to handle EINTER
-                    loop {
-                        match input.read(&mut bytes) {
-                            Ok(8) => {
-                                assert!(combine(CLOEXEC_MSG_FOOTER) == combine(&bytes[4.. 8]),
-                                        "Validation on the CLOEXEC pipe failed: {:?}", bytes);
-                                let errno = combine(&bytes[0.. 4]);
-                                assert!(p.wait().is_ok(),
-                                        "wait() should either return Ok or panic");
-                                return Err(Error::from_raw_os_error(errno))
-                            }
-                            Ok(0) => return Ok(p),
-                            Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
-                            Err(e) => {
-                                assert!(p.wait().is_ok(),
-                                        "wait() should either return Ok or panic");
-                                panic!("the CLOEXEC pipe failed: {:?}", e)
-                            },
-                            Ok(..) => { // pipe I/O up to PIPE_BUF bytes should be atomic
-                                assert!(p.wait().is_ok(),
-                                        "wait() should either return Ok or panic");
-                                panic!("short read on the CLOEXEC pipe")
-                            }
-                        }
+        let setup = |src: Stdio, dst: c_int| {
+            let fd = match src {
+                Stdio::Inherit => return true,
+                Stdio::Piped(pipe) => pipe.into_fd(),
+
+                // If a stdio file descriptor is set to be ignored, we open up
+                // /dev/null into that file descriptor. Otherwise, the first
+                // file descriptor opened up in the child would be numbered as
+                // one of the stdio file descriptors, which is likely to wreak
+                // havoc.
+                Stdio::None => {
+                    let mut opts = OpenOptions::new();
+                    opts.read(dst == libc::STDIN_FILENO);
+                    opts.write(dst != libc::STDIN_FILENO);
+                    let devnull = CStr::from_ptr(b"/dev/null\0".as_ptr()
+                                                    as *const _);
+                    if let Ok(f) = File::open_c(devnull, &opts) {
+                        f.into_fd()
+                    } else {
+                        return false
                     }
                 }
+            };
+            retry(|| libc::dup2(fd.raw(), dst)) != -1
+        };
 
-                // And at this point we've reached a special time in the life of the
-                // child. The child must now be considered hamstrung and unable to
-                // do anything other than syscalls really. Consider the following
-                // scenario:
-                //
-                //      1. Thread A of process 1 grabs the malloc() mutex
-                //      2. Thread B of process 1 forks(), creating thread C
-                //      3. Thread C of process 2 then attempts to malloc()
-                //      4. The memory of process 2 is the same as the memory of
-                //         process 1, so the mutex is locked.
-                //
-                // This situation looks a lot like deadlock, right? It turns out
-                // that this is what pthread_atfork() takes care of, which is
-                // presumably implemented across platforms. The first thing that
-                // threads to *before* forking is to do things like grab the malloc
-                // mutex, and then after the fork they unlock it.
-                //
-                // Despite this information, libnative's spawn has been witnessed to
-                // deadlock on both OSX and FreeBSD. I'm not entirely sure why, but
-                // all collected backtraces point at malloc/free traffic in the
-                // child spawned process.
-                //
-                // For this reason, the block of code below should contain 0
-                // invocations of either malloc of free (or their related friends).
-                //
-                // As an example of not having malloc/free traffic, we don't close
-                // this file descriptor by dropping the FileDesc (which contains an
-                // allocation). Instead we just close it manually. This will never
-                // have the drop glue anyway because this code never returns (the
-                // child will either exec() or invoke libc::exit)
-                let _ = libc::close(input.raw());
-
-                fn fail(output: &mut AnonPipe) -> ! {
-                    let errno = sys::os::errno() as u32;
-                    let bytes = [
-                        (errno >> 24) as u8,
-                        (errno >> 16) as u8,
-                        (errno >>  8) as u8,
-                        (errno >>  0) as u8,
-                        CLOEXEC_MSG_FOOTER[0], CLOEXEC_MSG_FOOTER[1],
-                        CLOEXEC_MSG_FOOTER[2], CLOEXEC_MSG_FOOTER[3]
-                    ];
-                    // pipe I/O up to PIPE_BUF bytes should be atomic
-                    assert!(output.write(&bytes).is_ok());
-                    unsafe { libc::_exit(1) }
-                }
-
-                rustrt::rust_unset_sigprocmask();
-
-                // If a stdio file descriptor is set to be ignored, we don't
-                // actually close it, but rather open up /dev/null into that
-                // file descriptor. Otherwise, the first file descriptor opened
-                // up in the child would be numbered as one of the stdio file
-                // descriptors, which is likely to wreak havoc.
-                let setup = |src: Option<AnonPipe>, dst: c_int| {
-                    let src = match src {
-                        None => {
-                            let flags = if dst == libc::STDIN_FILENO {
-                                libc::O_RDONLY
-                            } else {
-                                libc::O_RDWR
-                            };
-                            libc::open(devnull.as_ptr() as *const _, flags, 0)
-                        }
-                        Some(obj) => {
-                            let fd = obj.raw();
-                            // Leak the memory and the file descriptor. We're in the
-                            // child now an all our resources are going to be
-                            // cleaned up very soon
-                            mem::forget(obj);
-                            fd
-                        }
-                    };
-                    src != -1 && retry(|| dup2(src, dst)) != -1
-                };
-
-                if !setup(in_fd, libc::STDIN_FILENO) { fail(&mut output) }
-                if !setup(out_fd, libc::STDOUT_FILENO) { fail(&mut output) }
-                if !setup(err_fd, libc::STDERR_FILENO) { fail(&mut output) }
-
-                // close all other fds
-                for fd in (3..getdtablesize()).rev() {
-                    if fd != output.raw() {
-                        let _ = close(fd as c_int);
-                    }
-                }
+        if !setup(in_fd, libc::STDIN_FILENO) { fail(&mut output) }
+        if !setup(out_fd, libc::STDOUT_FILENO) { fail(&mut output) }
+        if !setup(err_fd, libc::STDERR_FILENO) { fail(&mut output) }
 
-                match cfg.gid {
-                    Some(u) => {
-                        if libc::setgid(u as libc::gid_t) != 0 {
-                            fail(&mut output);
-                        }
-                    }
-                    None => {}
-                }
-                match cfg.uid {
-                    Some(u) => {
-                        // When dropping privileges from root, the `setgroups` call
-                        // will remove any extraneous groups. If we don't call this,
-                        // then even though our uid has dropped, we may still have
-                        // groups that enable us to do super-user things. This will
-                        // fail if we aren't root, so don't bother checking the
-                        // return value, this is just done as an optimistic
-                        // privilege dropping function.
-                        extern {
-                            fn setgroups(ngroups: libc::c_int,
-                                         ptr: *const libc::c_void) -> libc::c_int;
-                        }
-                        let _ = setgroups(0, ptr::null());
-
-                        if libc::setuid(u as libc::uid_t) != 0 {
-                            fail(&mut output);
-                        }
-                    }
-                    None => {}
-                }
-                if cfg.detach {
-                    // Don't check the error of setsid because it fails if we're the
-                    // process leader already. We just forked so it shouldn't return
-                    // error, but ignore it anyway.
-                    let _ = libc::setsid();
-                }
-                if !dirp.is_null() && chdir(dirp) == -1 {
-                    fail(&mut output);
-                }
-                if !envp.is_null() {
-                    *sys::os::environ() = envp as *const _;
-                }
-                let _ = execvp(*argv, argv as *mut _);
+        if let Some(u) = cfg.gid {
+            if libc::setgid(u as libc::gid_t) != 0 {
                 fail(&mut output);
-            })
-        })
+            }
+        }
+        if let Some(u) = cfg.uid {
+            // When dropping privileges from root, the `setgroups` call
+            // will remove any extraneous groups. If we don't call this,
+            // then even though our uid has dropped, we may still have
+            // groups that enable us to do super-user things. This will
+            // fail if we aren't root, so don't bother checking the
+            // return value, this is just done as an optimistic
+            // privilege dropping function.
+            let _ = c::setgroups(0, ptr::null());
+
+            if libc::setuid(u as libc::uid_t) != 0 {
+                fail(&mut output);
+            }
+        }
+        if cfg.detach {
+            // Don't check the error of setsid because it fails if we're the
+            // process leader already. We just forked so it shouldn't return
+            // error, but ignore it anyway.
+            let _ = libc::setsid();
+        }
+        if !dirp.is_null() && libc::chdir(dirp) == -1 {
+            fail(&mut output);
+        }
+        if !envp.is_null() {
+            *sys::os::environ() = envp as *const _;
+        }
+        let _ = libc::execvp(*argv, argv as *mut _);
+        fail(&mut output)
     }
 
     pub fn wait(&self) -> io::Result<ExitStatus> {
@@ -364,8 +334,8 @@ pub fn try_wait(&self) -> Option<ExitStatus> {
     }
 }
 
-fn with_argv<T,F>(prog: &CString, args: &[CString], cb: F) -> T
-    where F : FnOnce(*const *const libc::c_char) -> T
+fn make_argv(prog: &CString, args: &[CString])
+             -> (*const *const libc::c_char, Vec<*const libc::c_char>)
 {
     let mut ptrs: Vec<*const libc::c_char> = Vec::with_capacity(args.len()+1);
 
@@ -380,40 +350,38 @@ fn with_argv<T,F>(prog: &CString, args: &[CString], cb: F) -> T
     // Add a terminating null pointer (required by libc).
     ptrs.push(ptr::null());
 
-    cb(ptrs.as_ptr())
+    (ptrs.as_ptr(), ptrs)
 }
 
-fn with_envp<T, F>(env: Option<&HashMap<OsString, OsString>>, cb: F) -> T
-    where F : FnOnce(*const c_void) -> T
+fn make_envp(env: Option<&HashMap<OsString, OsString>>)
+             -> (*const c_void, Vec<Vec<u8>>, Vec<*const libc::c_char>)
 {
     // On posixy systems we can pass a char** for envp, which is a
     // null-terminated array of "k=v\0" strings. Since we must create
     // these strings locally, yet expose a raw pointer to them, we
     // create a temporary vector to own the CStrings that outlives the
     // call to cb.
-    match env {
-        Some(env) => {
-            let mut tmps = Vec::with_capacity(env.len());
-
-            for pair in env {
-                let mut kv = Vec::new();
-                kv.push_all(pair.0.as_bytes());
-                kv.push('=' as u8);
-                kv.push_all(pair.1.as_bytes());
-                kv.push(0); // terminating null
-                tmps.push(kv);
-            }
+    if let Some(env) = env {
+        let mut tmps = Vec::with_capacity(env.len());
+
+        for pair in env {
+            let mut kv = Vec::new();
+            kv.push_all(pair.0.as_bytes());
+            kv.push('=' as u8);
+            kv.push_all(pair.1.as_bytes());
+            kv.push(0); // terminating null
+            tmps.push(kv);
+        }
 
-            // As with `with_argv`, this is unsafe, since cb could leak the pointers.
-            let mut ptrs: Vec<*const libc::c_char> =
-                tmps.iter()
-                    .map(|tmp| tmp.as_ptr() as *const libc::c_char)
-                    .collect();
-            ptrs.push(ptr::null());
+        let mut ptrs: Vec<*const libc::c_char> =
+            tmps.iter()
+                .map(|tmp| tmp.as_ptr() as *const libc::c_char)
+                .collect();
+        ptrs.push(ptr::null());
 
-            cb(ptrs.as_ptr() as *const c_void)
-        }
-        _ => cb(ptr::null())
+        (ptrs.as_ptr() as *const _, tmps, ptrs)
+    } else {
+        (0 as *const _, Vec::new(), Vec::new())
     }
 }
 
index 229481e3d57e637c3cc0c24d25f4b9aa186c703b..ed41c95978289f508a481ec922f7ddc6128b5733 100644 (file)
@@ -22,22 +22,24 @@ pub struct AnonPipe {
     fd: c_int
 }
 
-pub unsafe fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
+pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
     // Windows pipes work subtly differently than unix pipes, and their
     // inheritance has to be handled in a different way that I do not
     // fully understand. Here we explicitly make the pipe non-inheritable,
     // which means to pass it to a subprocess they need to be duplicated
     // first, as in std::run.
     let mut fds = [0; 2];
-    match libc::pipe(fds.as_mut_ptr(), 1024 as ::libc::c_uint,
-    (libc::O_BINARY | libc::O_NOINHERIT) as c_int) {
-        0 => {
-            assert!(fds[0] != -1 && fds[0] != 0);
-            assert!(fds[1] != -1 && fds[1] != 0);
+    unsafe {
+        match libc::pipe(fds.as_mut_ptr(), 1024 as ::libc::c_uint,
+                         (libc::O_BINARY | libc::O_NOINHERIT) as c_int) {
+            0 => {
+                assert!(fds[0] != -1 && fds[0] != 0);
+                assert!(fds[1] != -1 && fds[1] != 0);
 
-            Ok((AnonPipe::from_fd(fds[0]), AnonPipe::from_fd(fds[1])))
+                Ok((AnonPipe::from_fd(fds[0]), AnonPipe::from_fd(fds[1])))
+            }
+            _ => Err(io::Error::last_os_error()),
         }
-        _ => Err(io::Error::last_os_error()),
     }
 }
 
index 7e832b6384dee46ce09686ccd483c7c4008928b3..7495392192170ab91914a6bd9196c2954f2737a2 100644 (file)
@@ -105,11 +105,18 @@ pub struct Process {
     handle: Handle,
 }
 
+pub enum Stdio {
+    Inherit,
+    Piped(AnonPipe),
+    None,
+}
+
 impl Process {
     #[allow(deprecated)]
     pub fn spawn(cfg: &Command,
-                 in_fd: Option<AnonPipe>, out_fd: Option<AnonPipe>, err_fd: Option<AnonPipe>)
-                 -> io::Result<Process>
+                 in_fd: Stdio,
+                 out_fd: Stdio,
+                 err_fd: Stdio) -> io::Result<Process>
     {
         use libc::types::os::arch::extra::{DWORD, HANDLE, STARTUPINFO};
         use libc::consts::os::extra::{
@@ -156,13 +163,16 @@ pub fn spawn(cfg: &Command,
 
             let cur_proc = GetCurrentProcess();
 
-            // Similarly to unix, we don't actually leave holes for the stdio file
-            // descriptors, but rather open up /dev/null equivalents. These
-            // equivalents are drawn from libuv's windows process spawning.
-            let set_fd = |fd: &Option<AnonPipe>, slot: &mut HANDLE,
+            let set_fd = |fd: &Stdio, slot: &mut HANDLE,
                           is_stdin: bool| {
                 match *fd {
-                    None => {
+                    Stdio::Inherit => {}
+
+                    // Similarly to unix, we don't actually leave holes for the
+                    // stdio file descriptors, but rather open up /dev/null
+                    // equivalents. These equivalents are drawn from libuv's
+                    // windows process spawning.
+                    Stdio::None => {
                         let access = if is_stdin {
                             libc::FILE_GENERIC_READ
                         } else {
@@ -188,11 +198,8 @@ pub fn spawn(cfg: &Command,
                             return Err(Error::last_os_error())
                         }
                     }
-                    Some(ref pipe) => {
+                    Stdio::Piped(ref pipe) => {
                         let orig = pipe.raw();
-                        if orig == INVALID_HANDLE_VALUE {
-                            return Err(Error::last_os_error())
-                        }
                         if DuplicateHandle(cur_proc, orig, cur_proc, slot,
                                            0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE {
                             return Err(Error::last_os_error())
@@ -235,9 +242,15 @@ pub fn spawn(cfg: &Command,
                 })
             });
 
-            assert!(CloseHandle(si.hStdInput) != 0);
-            assert!(CloseHandle(si.hStdOutput) != 0);
-            assert!(CloseHandle(si.hStdError) != 0);
+            if !in_fd.inherited() {
+                assert!(CloseHandle(si.hStdInput) != 0);
+            }
+            if !out_fd.inherited() {
+                assert!(CloseHandle(si.hStdOutput) != 0);
+            }
+            if !err_fd.inherited() {
+                assert!(CloseHandle(si.hStdError) != 0);
+            }
 
             match create_err {
                 Some(err) => return Err(err),
@@ -296,6 +309,12 @@ pub fn wait(&self) -> io::Result<ExitStatus> {
     }
 }
 
+impl Stdio {
+    fn inherited(&self) -> bool {
+        match *self { Stdio::Inherit => true, _ => false }
+    }
+}
+
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
 pub struct ExitStatus(i32);
 
index acd6970f113731a95dd79b8c7d662bee55e50010..f5a1093be2b1e9ee83f8cfcb3e960c99e310396c 100644 (file)
@@ -95,7 +95,7 @@ macro_rules! thread_local {
     (static $name:ident: $t:ty = $init:expr) => (
         static $name: ::std::thread::LocalKey<$t> = {
             use std::cell::UnsafeCell as __UnsafeCell;
-            use std::thread::__local::__impl::KeyInner as __KeyInner;
+            use std::thread::__local::KeyInner as __KeyInner;
             use std::option::Option as __Option;
             use std::option::Option::None as __None;
 
@@ -112,7 +112,7 @@ fn __getit() -> &'static __KeyInner<__UnsafeCell<__Option<$t>>> {
     (pub static $name:ident: $t:ty = $init:expr) => (
         pub static $name: ::std::thread::LocalKey<$t> = {
             use std::cell::UnsafeCell as __UnsafeCell;
-            use std::thread::__local::__impl::KeyInner as __KeyInner;
+            use std::thread::__local::KeyInner as __KeyInner;
             use std::option::Option as __Option;
             use std::option::Option::None as __None;
 
@@ -156,20 +156,20 @@ macro_rules! __thread_local_inner {
         #[cfg_attr(all(any(target_os = "macos", target_os = "linux"),
                        not(target_arch = "aarch64")),
                    thread_local)]
-        static $name: ::std::thread::__local::__impl::KeyInner<$t> =
+        static $name: ::std::thread::__local::KeyInner<$t> =
             __thread_local_inner!($init, $t);
     );
     (pub static $name:ident: $t:ty = $init:expr) => (
         #[cfg_attr(all(any(target_os = "macos", target_os = "linux"),
                        not(target_arch = "aarch64")),
                    thread_local)]
-        pub static $name: ::std::thread::__local::__impl::KeyInner<$t> =
+        pub static $name: ::std::thread::__local::KeyInner<$t> =
             __thread_local_inner!($init, $t);
     );
     ($init:expr, $t:ty) => ({
         #[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))]
-        const _INIT: ::std::thread::__local::__impl::KeyInner<$t> = {
-            ::std::thread::__local::__impl::KeyInner {
+        const _INIT: ::std::thread::__local::KeyInner<$t> = {
+            ::std::thread::__local::KeyInner {
                 inner: ::std::cell::UnsafeCell { value: $init },
                 dtor_registered: ::std::cell::UnsafeCell { value: false },
                 dtor_running: ::std::cell::UnsafeCell { value: false },
@@ -178,13 +178,13 @@ macro_rules! __thread_local_inner {
 
         #[allow(trivial_casts)]
         #[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))]
-        const _INIT: ::std::thread::__local::__impl::KeyInner<$t> = {
-            ::std::thread::__local::__impl::KeyInner {
+        const _INIT: ::std::thread::__local::KeyInner<$t> = {
+            ::std::thread::__local::KeyInner {
                 inner: ::std::cell::UnsafeCell { value: $init },
-                os: ::std::thread::__local::__impl::OsStaticKey {
-                    inner: ::std::thread::__local::__impl::OS_INIT_INNER,
+                os: ::std::thread::__local::OsStaticKey {
+                    inner: ::std::thread::__local::OS_INIT_INNER,
                     dtor: ::std::option::Option::Some(
-                        ::std::thread::__local::__impl::destroy_value::<$t>
+                        ::std::thread::__local::destroy_value::<$t>
                     ),
                 },
             }
index 5fe6e80d6e93a0c851b2c857e9d220b6f6c14051..10c79671c0c9433dfa39632604fe494c50086007 100644 (file)
@@ -99,6 +99,7 @@
 //! `println!` and `panic!` for the child thread:
 //!
 //! ```rust
+//! # #![allow(unused_must_use)]
 //! use std::thread;
 //!
 //! thread::Builder::new().name("child1".to_string()).spawn(move || {
 
 #![stable(feature = "rust1", since = "1.0.0")]
 
-#[stable(feature = "rust1", since = "1.0.0")]
-pub use self::__local::{LocalKey, LocalKeyState};
-
-#[unstable(feature = "scoped_tls",
-            reason = "scoped TLS has yet to have wide enough use to fully consider \
-                      stabilizing its interface")]
-pub use self::__scoped::ScopedKey;
-
 use prelude::v1::*;
 
 use any::Any;
 // Thread-local storage
 ////////////////////////////////////////////////////////////////////////////////
 
-#[macro_use]
-#[doc(hidden)]
-#[path = "local.rs"] pub mod __local;
+#[macro_use] mod local;
+#[macro_use] mod scoped;
+
+#[stable(feature = "rust1", since = "1.0.0")]
+pub use self::local::{LocalKey, LocalKeyState};
+
+#[unstable(feature = "scoped_tls",
+            reason = "scoped TLS has yet to have wide enough use to fully \
+                      consider stabilizing its interface")]
+pub use self::scoped::ScopedKey;
 
-#[macro_use]
-#[doc(hidden)]
-#[path = "scoped.rs"] pub mod __scoped;
+#[doc(hidden)] pub use self::local::__impl as __local;
+#[doc(hidden)] pub use self::scoped::__impl as __scoped;
 
 ////////////////////////////////////////////////////////////////////////////////
 // Builder
index b384879d7a956751daba630d1061a14a27857117..fa980954c2f8c1ee19a63efdbbfc5dffdd322c91 100644 (file)
@@ -110,7 +110,7 @@ macro_rules! __scoped_thread_local_inner {
                       target_os = "openbsd",
                       target_arch = "aarch64")))]
         const _INIT: __Key<$t> = __Key {
-            inner: ::std::thread::__scoped::__impl::KeyInner {
+            inner: ::std::thread::__scoped::KeyInner {
                 inner: ::std::cell::UnsafeCell { value: 0 as *mut _ },
             }
         };
@@ -121,8 +121,8 @@ macro_rules! __scoped_thread_local_inner {
                   target_os = "openbsd",
                   target_arch = "aarch64"))]
         const _INIT: __Key<$t> = __Key {
-            inner: ::std::thread::__scoped::__impl::KeyInner {
-                inner: ::std::thread::__scoped::__impl::OS_INIT,
+            inner: ::std::thread::__scoped::KeyInner {
+                inner: ::std::thread::__scoped::OS_INIT,
                 marker: ::std::marker::PhantomData::<::std::cell::Cell<$t>>,
             }
         };
index 56af43474a6155d69240411bcd01d1fbf209c704..7635c8eadc26efab0fb7fce588aa10d33c04daba 100644 (file)
@@ -49,7 +49,7 @@ pub trait Pos {
 /// A character offset. Because of multibyte utf8 characters, a byte offset
 /// is not equivalent to a character offset. The CodeMap will convert BytePos
 /// values to CharPos values as necessary.
-#[derive(Copy, Clone, PartialEq, Hash, PartialOrd, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Debug)]
 pub struct CharPos(pub usize);
 
 // FIXME: Lots of boilerplate in these impls, but so far my attempts to fix
@@ -305,9 +305,21 @@ pub fn to_llvm_cookie(self) -> i32 {
 
 pub type FileName = String;
 
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+pub struct LineInfo {
+    /// Index of line, starting from 0.
+    pub line_index: usize,
+
+    /// Column in line where span begins, starting from 0.
+    pub start_col: CharPos,
+
+    /// Column in line where span ends, starting from 0, exclusive.
+    pub end_col: CharPos,
+}
+
 pub struct FileLines {
     pub file: Rc<FileMap>,
-    pub lines: Vec<usize>
+    pub lines: Vec<LineInfo>
 }
 
 /// Identifies an offset of a multi-byte character in a FileMap
@@ -479,9 +491,9 @@ pub fn next_line(&self, pos: BytePos) {
         lines.push(pos);
     }
 
-    /// get a line from the list of pre-computed line-beginnings
-    ///
-    pub fn get_line(&self, line_number: usize) -> Option<String> {
+    /// get a line from the list of pre-computed line-beginnings.
+    /// line-number here is 0-based.
+    pub fn get_line(&self, line_number: usize) -> Option<&str> {
         match self.src {
             Some(ref src) => {
                 let lines = self.lines.borrow();
@@ -492,7 +504,7 @@ pub fn get_line(&self, line_number: usize) -> Option<String> {
                     match slice.find('\n') {
                         Some(e) => &slice[..e],
                         None => slice
-                    }.to_string()
+                    }
                 })
             }
             None => None
@@ -661,10 +673,29 @@ pub fn span_to_filename(&self, sp: Span) -> FileName {
     pub fn span_to_lines(&self, sp: Span) -> FileLines {
         let lo = self.lookup_char_pos(sp.lo);
         let hi = self.lookup_char_pos(sp.hi);
-        let mut lines = Vec::new();
-        for i in lo.line - 1..hi.line {
-            lines.push(i);
-        };
+        let mut lines = Vec::with_capacity(hi.line - lo.line + 1);
+
+        // The span starts partway through the first line,
+        // but after that it starts from offset 0.
+        let mut start_col = lo.col;
+
+        // For every line but the last, it extends from `start_col`
+        // and to the end of the line. Be careful because the line
+        // numbers in Loc are 1-based, so we subtract 1 to get 0-based
+        // lines.
+        for line_index in lo.line-1 .. hi.line-1 {
+            let line_len = lo.file.get_line(line_index).map(|s| s.len()).unwrap_or(0);
+            lines.push(LineInfo { line_index: line_index,
+                                  start_col: start_col,
+                                  end_col: CharPos::from_usize(line_len) });
+            start_col = CharPos::from_usize(0);
+        }
+
+        // For the last line, it extends from `start_col` to `hi.col`:
+        lines.push(LineInfo { line_index: hi.line - 1,
+                              start_col: start_col,
+                              end_col: hi.col });
+
         FileLines {file: lo.file, lines: lines}
     }
 
@@ -919,6 +950,7 @@ pub struct MalformedCodemapPositions {
 #[cfg(test)]
 mod test {
     use super::*;
+    use std::rc::Rc;
 
     #[test]
     fn t1 () {
@@ -926,10 +958,10 @@ fn t1 () {
         let fm = cm.new_filemap("blork.rs".to_string(),
                                 "first line.\nsecond line".to_string());
         fm.next_line(BytePos(0));
-        assert_eq!(fm.get_line(0), Some("first line.".to_string()));
+        assert_eq!(fm.get_line(0), Some("first line."));
         // TESTING BROKEN BEHAVIOR:
         fm.next_line(BytePos(10));
-        assert_eq!(fm.get_line(1), Some(".".to_string()));
+        assert_eq!(fm.get_line(1), Some("."));
     }
 
     #[test]
@@ -1057,7 +1089,54 @@ fn t7() {
 
         assert_eq!(file_lines.file.name, "blork.rs");
         assert_eq!(file_lines.lines.len(), 1);
-        assert_eq!(file_lines.lines[0], 1);
+        assert_eq!(file_lines.lines[0].line_index, 1);
+    }
+
+    /// Given a string like " ^~~~~~~~~~~~ ", produces a span
+    /// coverting that range. The idea is that the string has the same
+    /// length as the input, and we uncover the byte positions.  Note
+    /// that this can span lines and so on.
+    fn span_from_selection(input: &str, selection: &str) -> Span {
+        assert_eq!(input.len(), selection.len());
+        let left_index = selection.find('^').unwrap() as u32;
+        let right_index = selection.rfind('~').unwrap() as u32;
+        Span { lo: BytePos(left_index), hi: BytePos(right_index + 1), expn_id: NO_EXPANSION }
+    }
+
+    fn new_filemap_and_lines(cm: &CodeMap, filename: &str, input: &str) -> Rc<FileMap> {
+        let fm = cm.new_filemap(filename.to_string(), input.to_string());
+        let mut byte_pos: u32 = 0;
+        for line in input.lines() {
+            // register the start of this line
+            fm.next_line(BytePos(byte_pos));
+
+            // update byte_pos to include this line and the \n at the end
+            byte_pos += line.len() as u32 + 1;
+        }
+        fm
+    }
+
+    /// Test span_to_snippet and span_to_lines for a span coverting 3
+    /// lines in the middle of a file.
+    #[test]
+    fn span_to_snippet_and_lines_spanning_multiple_lines() {
+        let cm = CodeMap::new();
+        let inputtext = "aaaaa\nbbbbBB\nCCC\nDDDDDddddd\neee\n";
+        let selection = "     \n    ^~\n~~~\n~~~~~     \n   \n";
+        new_filemap_and_lines(&cm, "blork.rs", inputtext);
+        let span = span_from_selection(inputtext, selection);
+
+        // check that we are extracting the text we thought we were extracting
+        assert_eq!(&cm.span_to_snippet(span).unwrap(), "BB\nCCC\nDDDDD");
+
+        // check that span_to_lines gives us the complete result with the lines/cols we expected
+        let lines = cm.span_to_lines(span);
+        let expected = vec![
+            LineInfo { line_index: 1, start_col: CharPos(4), end_col: CharPos(6) },
+            LineInfo { line_index: 2, start_col: CharPos(0), end_col: CharPos(3) },
+            LineInfo { line_index: 3, start_col: CharPos(0), end_col: CharPos(5) }
+            ];
+        assert_eq!(lines.lines, expected);
     }
 
     #[test]
index 8fe23a3c8e82664bf1c053f46622f2be6fcae962..ed7bdcd898e9357ebcfa60cd65d187623ba3aa0d 100644 (file)
@@ -18,6 +18,7 @@
 use diagnostics;
 
 use std::cell::{RefCell, Cell};
+use std::cmp;
 use std::fmt;
 use std::io::prelude::*;
 use std::io;
 /// maximum number of lines we will print for each error; arbitrary.
 const MAX_LINES: usize = 6;
 
-#[derive(Clone, Copy)]
+#[derive(Clone)]
 pub enum RenderSpan {
     /// A FullSpan renders with both with an initial line for the
     /// message, prefixed by file:linenum, followed by a summary of
     /// the source code covered by the span.
     FullSpan(Span),
 
+    /// Similar to a FullSpan, but the cited position is the end of
+    /// the span, instead of the start. Used, at least, for telling
+    /// compiletest/runtest to look at the last line of the span
+    /// (since `end_highlight_lines` displays an arrow to the end
+    /// of the span).
+    EndSpan(Span),
+
+    /// A suggestion renders with both with an initial line for the
+    /// message, prefixed by file:linenum, followed by a summary
+    /// of hypothetical source code, where the `String` is spliced
+    /// into the lines in place of the code covered by the span.
+    Suggestion(Span, String),
+
     /// A FileLine renders with just a line for the message prefixed
     /// by file:linenum.
     FileLine(Span),
 }
 
 impl RenderSpan {
-    fn span(self) -> Span {
-        match self {
-            FullSpan(s) | FileLine(s) => s
-        }
-    }
-    fn is_full_span(&self) -> bool {
-        match self {
-            &FullSpan(..) => true,
-            &FileLine(..) => false,
+    fn span(&self) -> Span {
+        match *self {
+            FullSpan(s) |
+            Suggestion(s, _) |
+            EndSpan(s) |
+            FileLine(s) =>
+                s
         }
     }
 }
@@ -115,11 +127,17 @@ pub fn span_note(&self, sp: Span, msg: &str) {
         self.handler.emit(Some((&self.cm, sp)), msg, Note);
     }
     pub fn span_end_note(&self, sp: Span, msg: &str) {
-        self.handler.custom_emit(&self.cm, FullSpan(sp), msg, Note);
+        self.handler.custom_emit(&self.cm, EndSpan(sp), msg, Note);
     }
     pub fn span_help(&self, sp: Span, msg: &str) {
         self.handler.emit(Some((&self.cm, sp)), msg, Help);
     }
+    /// Prints out a message with a suggested edit of the code.
+    ///
+    /// See `diagnostic::RenderSpan::Suggestion` for more information.
+    pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
+        self.handler.custom_emit(&self.cm, Suggestion(sp, suggestion), msg, Help);
+    }
     pub fn fileline_note(&self, sp: Span, msg: &str) {
         self.handler.custom_emit(&self.cm, FileLine(sp), msg, Note);
     }
@@ -407,8 +425,8 @@ fn emit(&mut self,
         let error = match cmsp {
             Some((cm, COMMAND_LINE_SP)) => emit(self, cm,
                                                 FileLine(COMMAND_LINE_SP),
-                                                msg, code, lvl, false),
-            Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, code, lvl, false),
+                                                msg, code, lvl),
+            Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, code, lvl),
             None => print_diagnostic(self, "", lvl, msg, code),
         };
 
@@ -420,7 +438,7 @@ fn emit(&mut self,
 
     fn custom_emit(&mut self, cm: &codemap::CodeMap,
                    sp: RenderSpan, msg: &str, lvl: Level) {
-        match emit(self, cm, sp, msg, None, lvl, true) {
+        match emit(self, cm, sp, msg, None, lvl) {
             Ok(()) => {}
             Err(e) => panic!("failed to print diagnostics: {:?}", e),
         }
@@ -428,35 +446,41 @@ fn custom_emit(&mut self, cm: &codemap::CodeMap,
 }
 
 fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
-        msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> io::Result<()> {
+        msg: &str, code: Option<&str>, lvl: Level) -> io::Result<()> {
     let sp = rsp.span();
 
     // We cannot check equality directly with COMMAND_LINE_SP
     // since PartialEq is manually implemented to ignore the ExpnId
     let ss = if sp.expn_id == COMMAND_LINE_EXPN {
         "<command line option>".to_string()
+    } else if let EndSpan(_) = rsp {
+        let span_end = Span { lo: sp.hi, hi: sp.hi, expn_id: sp.expn_id};
+        cm.span_to_string(span_end)
     } else {
         cm.span_to_string(sp)
     };
-    if custom {
-        // we want to tell compiletest/runtest to look at the last line of the
-        // span (since `custom_highlight_lines` displays an arrow to the end of
-        // the span)
-        let span_end = Span { lo: sp.hi, hi: sp.hi, expn_id: sp.expn_id};
-        let ses = cm.span_to_string(span_end);
-        try!(print_diagnostic(dst, &ses[..], lvl, msg, code));
-        if rsp.is_full_span() {
-            try!(custom_highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
-        }
-    } else {
-        try!(print_diagnostic(dst, &ss[..], lvl, msg, code));
-        if rsp.is_full_span() {
+
+    try!(print_diagnostic(dst, &ss[..], lvl, msg, code));
+
+    match rsp {
+        FullSpan(_) => {
             try!(highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
         }
+        EndSpan(_) => {
+            try!(end_highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
+        }
+        Suggestion(_, ref suggestion) => {
+            try!(highlight_suggestion(dst, cm, sp, suggestion));
+        }
+        FileLine(..) => {
+            // no source text in this case!
+        }
     }
+
     if sp != COMMAND_LINE_SP {
         try!(print_macro_backtrace(dst, cm, sp));
     }
+
     match code {
         Some(code) =>
             match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) {
@@ -472,29 +496,90 @@ fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
     Ok(())
 }
 
+fn highlight_suggestion(err: &mut EmitterWriter,
+                        cm: &codemap::CodeMap,
+                        sp: Span,
+                        suggestion: &str)
+                        -> io::Result<()>
+{
+    let lines = cm.span_to_lines(sp);
+    assert!(!lines.lines.is_empty());
+
+    // To build up the result, we want to take the snippet from the first
+    // line that precedes the span, prepend that with the suggestion, and
+    // then append the snippet from the last line that trails the span.
+    let fm = &lines.file;
+
+    let first_line = &lines.lines[0];
+    let prefix = fm.get_line(first_line.line_index)
+                   .map(|l| &l[..first_line.start_col.0])
+                   .unwrap_or("");
+
+    let last_line = lines.lines.last().unwrap();
+    let suffix = fm.get_line(last_line.line_index)
+                   .map(|l| &l[last_line.end_col.0..])
+                   .unwrap_or("");
+
+    let complete = format!("{}{}{}", prefix, suggestion, suffix);
+
+    // print the suggestion without any line numbers, but leave
+    // space for them. This helps with lining up with previous
+    // snippets from the actual error being reported.
+    let fm = &*lines.file;
+    let mut lines = complete.lines();
+    for (line, line_index) in lines.by_ref().take(MAX_LINES).zip(first_line.line_index..) {
+        let elided_line_num = format!("{}", line_index+1);
+        try!(write!(&mut err.dst, "{0}:{1:2$} {3}\n",
+                    fm.name, "", elided_line_num.len(), line));
+    }
+
+    // if we elided some lines, add an ellipsis
+    if lines.next().is_some() {
+        let elided_line_num = format!("{}", first_line.line_index + MAX_LINES + 1);
+        try!(write!(&mut err.dst, "{0:1$} {0:2$} ...\n",
+                    "", fm.name.len(), elided_line_num.len()));
+    }
+
+    Ok(())
+}
+
 fn highlight_lines(err: &mut EmitterWriter,
                    cm: &codemap::CodeMap,
                    sp: Span,
                    lvl: Level,
-                   lines: codemap::FileLines) -> io::Result<()> {
+                   lines: codemap::FileLines)
+                   -> io::Result<()>
+{
     let fm = &*lines.file;
 
-    let mut elided = false;
-    let mut display_lines = &lines.lines[..];
-    if display_lines.len() > MAX_LINES {
-        display_lines = &display_lines[0..MAX_LINES];
-        elided = true;
-    }
+    let line_strings: Option<Vec<&str>> =
+        lines.lines.iter()
+                   .map(|info| fm.get_line(info.line_index))
+                   .collect();
+
+    let line_strings = match line_strings {
+        None => { return Ok(()); }
+        Some(line_strings) => line_strings
+    };
+
+    // Display only the first MAX_LINES lines.
+    let all_lines = lines.lines.len();
+    let display_lines = cmp::min(all_lines, MAX_LINES);
+    let display_line_infos = &lines.lines[..display_lines];
+    let display_line_strings = &line_strings[..display_lines];
+
     // Print the offending lines
-    for &line_number in display_lines {
-        if let Some(line) = fm.get_line(line_number) {
-            try!(write!(&mut err.dst, "{}:{} {}\n", fm.name,
-                        line_number + 1, line));
-        }
+    for (line_info, line) in display_line_infos.iter().zip(display_line_strings.iter()) {
+        try!(write!(&mut err.dst, "{}:{} {}\n",
+                    fm.name,
+                    line_info.line_index + 1,
+                    line));
     }
-    if elided {
-        let last_line = display_lines[display_lines.len() - 1];
-        let s = format!("{}:{} ", fm.name, last_line + 1);
+
+    // If we elided something, put an ellipsis.
+    if display_lines < all_lines {
+        let last_line_index = display_line_infos.last().unwrap().line_index;
+        let s = format!("{}:{} ", fm.name, last_line_index + 1);
         try!(write!(&mut err.dst, "{0:1$}...\n", "", s.len()));
     }
 
@@ -503,7 +588,7 @@ fn highlight_lines(err: &mut EmitterWriter,
     if lines.lines.len() == 1 {
         let lo = cm.lookup_char_pos(sp.lo);
         let mut digits = 0;
-        let mut num = (lines.lines[0] + 1) / 10;
+        let mut num = (lines.lines[0].line_index + 1) / 10;
 
         // how many digits must be indent past?
         while num > 0 { num /= 10; digits += 1; }
@@ -515,7 +600,7 @@ fn highlight_lines(err: &mut EmitterWriter,
         for _ in 0..skip {
             s.push(' ');
         }
-        if let Some(orig) = fm.get_line(lines.lines[0]) {
+        if let Some(orig) = fm.get_line(lines.lines[0].line_index) {
             let mut col = skip;
             let mut lastc = ' ';
             let mut iter = orig.chars().enumerate();
@@ -575,12 +660,12 @@ fn highlight_lines(err: &mut EmitterWriter,
 }
 
 /// Here are the differences between this and the normal `highlight_lines`:
-/// `custom_highlight_lines` will always put arrow on the last byte of the
+/// `end_highlight_lines` will always put arrow on the last byte of the
 /// span (instead of the first byte). Also, when the span is too long (more
-/// than 6 lines), `custom_highlight_lines` will print the first line, then
+/// than 6 lines), `end_highlight_lines` will print the first line, then
 /// dot dot dot, then last line, whereas `highlight_lines` prints the first
 /// six lines.
-fn custom_highlight_lines(w: &mut EmitterWriter,
+fn end_highlight_lines(w: &mut EmitterWriter,
                           cm: &codemap::CodeMap,
                           sp: Span,
                           lvl: Level,
@@ -590,32 +675,32 @@ fn custom_highlight_lines(w: &mut EmitterWriter,
 
     let lines = &lines.lines[..];
     if lines.len() > MAX_LINES {
-        if let Some(line) = fm.get_line(lines[0]) {
+        if let Some(line) = fm.get_line(lines[0].line_index) {
             try!(write!(&mut w.dst, "{}:{} {}\n", fm.name,
-                        lines[0] + 1, line));
+                        lines[0].line_index + 1, line));
         }
         try!(write!(&mut w.dst, "...\n"));
-        let last_line_number = lines[lines.len() - 1];
-        if let Some(last_line) = fm.get_line(last_line_number) {
+        let last_line_index = lines[lines.len() - 1].line_index;
+        if let Some(last_line) = fm.get_line(last_line_index) {
             try!(write!(&mut w.dst, "{}:{} {}\n", fm.name,
-                        last_line_number + 1, last_line));
+                        last_line_index + 1, last_line));
         }
     } else {
-        for &line_number in lines {
-            if let Some(line) = fm.get_line(line_number) {
+        for line_info in lines {
+            if let Some(line) = fm.get_line(line_info.line_index) {
                 try!(write!(&mut w.dst, "{}:{} {}\n", fm.name,
-                            line_number + 1, line));
+                            line_info.line_index + 1, line));
             }
         }
     }
-    let last_line_start = format!("{}:{} ", fm.name, lines[lines.len()-1]+1);
+    let last_line_start = format!("{}:{} ", fm.name, lines[lines.len()-1].line_index + 1);
     let hi = cm.lookup_char_pos(sp.hi);
     let skip = last_line_start.width(false);
     let mut s = String::new();
     for _ in 0..skip {
         s.push(' ');
     }
-    if let Some(orig) = fm.get_line(lines[0]) {
+    if let Some(orig) = fm.get_line(lines[0].line_index) {
         let iter = orig.chars().enumerate();
         for (pos, ch) in iter {
             // Span seems to use half-opened interval, so subtract 1
index 80ee92608a520e965598a6ec62177a9356a5a4b1..346fb3580e134811f699baf7dfbd50a11c97871d 100644 (file)
@@ -208,10 +208,11 @@ fn expand<'cx>(&self,
 }
 
 // Use a macro because forwarding to a simple function has type system issues
-macro_rules! make_stmt_default {
+macro_rules! make_stmts_default {
     ($me:expr) => {
         $me.make_expr().map(|e| {
-            P(codemap::respan(e.span, ast::StmtExpr(e, ast::DUMMY_NODE_ID)))
+            SmallVector::one(P(codemap::respan(
+                e.span, ast::StmtExpr(e, ast::DUMMY_NODE_ID))))
         })
     }
 }
@@ -238,12 +239,12 @@ fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
         None
     }
 
-    /// Create a statement.
+    /// Create zero or more statements.
     ///
     /// By default this attempts to create an expression statement,
     /// returning None if that fails.
-    fn make_stmt(self: Box<Self>) -> Option<P<ast::Stmt>> {
-        make_stmt_default!(self)
+    fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
+        make_stmts_default!(self)
     }
 }
 
@@ -276,7 +277,7 @@ pub fn $fld(v: $t) -> Box<MacResult> {
     pat: P<ast::Pat>,
     items: SmallVector<P<ast::Item>>,
     impl_items: SmallVector<P<ast::ImplItem>>,
-    stmt: P<ast::Stmt>,
+    stmts: SmallVector<P<ast::Stmt>>,
 }
 
 impl MacResult for MacEager {
@@ -292,10 +293,10 @@ fn make_impl_items(self: Box<Self>) -> Option<SmallVector<P<ast::ImplItem>>> {
         self.impl_items
     }
 
-    fn make_stmt(self: Box<Self>) -> Option<P<ast::Stmt>> {
-        match self.stmt {
-            None => make_stmt_default!(self),
-            s => s,
+    fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
+        match self.stmts.as_ref().map_or(0, |s| s.len()) {
+            0 => make_stmts_default!(self),
+            _ => self.stmts,
         }
     }
 
@@ -384,10 +385,11 @@ fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVector<P<ast::ImplItem
             Some(SmallVector::zero())
         }
     }
-    fn make_stmt(self: Box<DummyResult>) -> Option<P<ast::Stmt>> {
-        Some(P(codemap::respan(self.span,
-                               ast::StmtExpr(DummyResult::raw_expr(self.span),
-                                             ast::DUMMY_NODE_ID))))
+    fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
+        Some(SmallVector::one(P(
+            codemap::respan(self.span,
+                            ast::StmtExpr(DummyResult::raw_expr(self.span),
+                                          ast::DUMMY_NODE_ID)))))
     }
 }
 
index 397775fdbfec384870677af77fd4d06d7b40e98e..ac96375095e143a8bfd10635f74ee8bd011133ee 100644 (file)
 use ext::build::AstBuilder;
 use codemap::{self, DUMMY_SP};
 use codemap::Span;
+use diagnostic::SpanHandler;
 use fold::MoveMap;
 use owned_slice::OwnedSlice;
 use parse::token::InternedString;
@@ -391,6 +392,7 @@ pub fn expand<F>(&self,
             ast::ItemEnum(ref enum_def, ref generics) => {
                 self.expand_enum_def(cx,
                                      enum_def,
+                                     &item.attrs[..],
                                      item.ident,
                                      generics)
             }
@@ -653,6 +655,7 @@ fn expand_struct_def(&self,
     fn expand_enum_def(&self,
                        cx: &mut ExtCtxt,
                        enum_def: &EnumDef,
+                       type_attrs: &[ast::Attribute],
                        type_ident: Ident,
                        generics: &Generics) -> P<ast::Item> {
         let mut field_tys = Vec::new();
@@ -687,6 +690,7 @@ fn expand_enum_def(&self,
                 method_def.expand_enum_method_body(cx,
                                                    self,
                                                    enum_def,
+                                                   type_attrs,
                                                    type_ident,
                                                    self_args,
                                                    &nonself_args[..])
@@ -706,13 +710,30 @@ fn expand_enum_def(&self,
     }
 }
 
-fn variant_to_pat(cx: &mut ExtCtxt, sp: Span, enum_ident: ast::Ident, variant: &ast::Variant)
-                  -> P<ast::Pat> {
-    let path = cx.path(sp, vec![enum_ident, variant.node.name]);
-    cx.pat(sp, match variant.node.kind {
-        ast::TupleVariantKind(..) => ast::PatEnum(path, None),
-        ast::StructVariantKind(..) => ast::PatStruct(path, Vec::new(), true),
-    })
+fn find_repr_type_name(diagnostic: &SpanHandler,
+                       type_attrs: &[ast::Attribute]) -> &'static str {
+    let mut repr_type_name = "i32";
+    for a in type_attrs {
+        for r in &attr::find_repr_attrs(diagnostic, a) {
+            repr_type_name = match *r {
+                attr::ReprAny | attr::ReprPacked => continue,
+                attr::ReprExtern => "i32",
+
+                attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize",
+                attr::ReprInt(_, attr::SignedInt(ast::TyI8)) => "i8",
+                attr::ReprInt(_, attr::SignedInt(ast::TyI16)) => "i16",
+                attr::ReprInt(_, attr::SignedInt(ast::TyI32)) => "i32",
+                attr::ReprInt(_, attr::SignedInt(ast::TyI64)) => "i64",
+
+                attr::ReprInt(_, attr::UnsignedInt(ast::TyUs)) => "usize",
+                attr::ReprInt(_, attr::UnsignedInt(ast::TyU8)) => "u8",
+                attr::ReprInt(_, attr::UnsignedInt(ast::TyU16)) => "u16",
+                attr::ReprInt(_, attr::UnsignedInt(ast::TyU32)) => "u32",
+                attr::ReprInt(_, attr::UnsignedInt(ast::TyU64)) => "u64",
+            }
+        }
+    }
+    repr_type_name
 }
 
 impl<'a> MethodDef<'a> {
@@ -983,12 +1004,13 @@ fn expand_enum_method_body(&self,
                                cx: &mut ExtCtxt,
                                trait_: &TraitDef,
                                enum_def: &EnumDef,
+                               type_attrs: &[ast::Attribute],
                                type_ident: Ident,
                                self_args: Vec<P<Expr>>,
                                nonself_args: &[P<Expr>])
                                -> P<Expr> {
         self.build_enum_match_tuple(
-            cx, trait_, enum_def, type_ident, self_args, nonself_args)
+            cx, trait_, enum_def, type_attrs, type_ident, self_args, nonself_args)
     }
 
 
@@ -1022,6 +1044,7 @@ fn build_enum_match_tuple(
         cx: &mut ExtCtxt,
         trait_: &TraitDef,
         enum_def: &EnumDef,
+        type_attrs: &[ast::Attribute],
         type_ident: Ident,
         self_args: Vec<P<Expr>>,
         nonself_args: &[P<Expr>]) -> P<Expr> {
@@ -1044,8 +1067,8 @@ fn build_enum_match_tuple(
             .collect::<Vec<ast::Ident>>();
 
         // The `vi_idents` will be bound, solely in the catch-all, to
-        // a series of let statements mapping each self_arg to a usize
-        // corresponding to its variant index.
+        // a series of let statements mapping each self_arg to an int
+        // value corresponding to its discriminant.
         let vi_idents: Vec<ast::Ident> = self_arg_names.iter()
             .map(|name| { let vi_suffix = format!("{}_vi", &name[..]);
                           cx.ident_of(&vi_suffix[..]) })
@@ -1160,33 +1183,44 @@ fn build_enum_match_tuple(
         //   unreachable-pattern error.
         //
         if variants.len() > 1 && self_args.len() > 1 {
-            let arms: Vec<ast::Arm> = variants.iter().enumerate()
-                .map(|(index, variant)| {
-                    let pat = variant_to_pat(cx, sp, type_ident, &**variant);
-                    let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs));
-                    cx.arm(sp, vec![pat], cx.expr_lit(sp, lit))
-                }).collect();
-
             // Build a series of let statements mapping each self_arg
-            // to a usize corresponding to its variant index.
+            // to its discriminant value. If this is a C-style enum
+            // with a specific repr type, then casts the values to
+            // that type.  Otherwise casts to `i32` (the default repr
+            // type).
+            //
             // i.e. for `enum E<T> { A, B(1), C(T, T) }`, and a deriving
             // with three Self args, builds three statements:
             //
             // ```
-            // let __self0_vi = match   self {
-            //     A => 0, B(..) => 1, C(..) => 2
-            // };
-            // let __self1_vi = match __arg1 {
-            //     A => 0, B(..) => 1, C(..) => 2
-            // };
-            // let __self2_vi = match __arg2 {
-            //     A => 0, B(..) => 1, C(..) => 2
-            // };
+            // let __self0_vi = unsafe {
+            //     std::intrinsics::discriminant_value(&self) } as i32;
+            // let __self1_vi = unsafe {
+            //     std::intrinsics::discriminant_value(&__arg1) } as i32;
+            // let __self2_vi = unsafe {
+            //     std::intrinsics::discriminant_value(&__arg2) } as i32;
             // ```
             let mut index_let_stmts: Vec<P<ast::Stmt>> = Vec::new();
+
+            let target_type_name =
+                find_repr_type_name(&cx.parse_sess.span_diagnostic, type_attrs);
+
             for (&ident, self_arg) in vi_idents.iter().zip(self_args.iter()) {
-                let variant_idx = cx.expr_match(sp, self_arg.clone(), arms.clone());
-                let let_stmt = cx.stmt_let(sp, false, ident, variant_idx);
+                let path = vec![cx.ident_of_std("core"),
+                                cx.ident_of("intrinsics"),
+                                cx.ident_of("discriminant_value")];
+                let call = cx.expr_call_global(
+                    sp, path, vec![cx.expr_addr_of(sp, self_arg.clone())]);
+                let variant_value = cx.expr_block(P(ast::Block {
+                    stmts: vec![],
+                    expr: Some(call),
+                    id: ast::DUMMY_NODE_ID,
+                    rules: ast::UnsafeBlock(ast::CompilerGenerated),
+                    span: sp }));
+
+                let target_ty = cx.ty_ident(sp, cx.ident_of(target_type_name));
+                let variant_disr = cx.expr_cast(sp, variant_value, target_ty);
+                let let_stmt = cx.stmt_let(sp, false, ident, variant_disr);
                 index_let_stmts.push(let_stmt);
             }
 
index dd0c7d716b7979e462145a5dfa5fef7f44d28132..5f4ec01791c88506ec04ec3c6167761cc9a77294 100644 (file)
@@ -720,37 +720,49 @@ pub fn expand_item_mac(it: P<ast::Item>,
 }
 
 /// Expand a stmt
-fn expand_stmt(s: Stmt, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
-    let (mac, style) = match s.node {
+fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
+    let stmt = stmt.and_then(|stmt| stmt);
+    let (mac, style) = match stmt.node {
         StmtMac(mac, style) => (mac, style),
-        _ => return expand_non_macro_stmt(s, fld)
+        _ => return expand_non_macro_stmt(stmt, fld)
     };
-    let expanded_stmt = match expand_mac_invoc(mac.and_then(|m| m), s.span,
-                                                |r| r.make_stmt(),
-                                                mark_stmt, fld) {
-        Some(stmt) => stmt,
-        None => {
-            return SmallVector::zero();
+
+    let maybe_new_items =
+        expand_mac_invoc(mac.and_then(|m| m), stmt.span,
+                         |r| r.make_stmts(),
+                         |stmts, mark| stmts.move_map(|m| mark_stmt(m, mark)),
+                         fld);
+
+    let mut fully_expanded = match maybe_new_items {
+        Some(stmts) => {
+            // Keep going, outside-in.
+            let new_items = stmts.into_iter().flat_map(|s| {
+                fld.fold_stmt(s).into_iter()
+            }).collect();
+            fld.cx.bt_pop();
+            new_items
         }
+        None => SmallVector::zero()
     };
 
-    // Keep going, outside-in.
-    let fully_expanded = fld.fold_stmt(expanded_stmt);
-    fld.cx.bt_pop();
-
+    // If this is a macro invocation with a semicolon, then apply that
+    // semicolon to the final statement produced by expansion.
     if style == MacStmtWithSemicolon {
-        fully_expanded.into_iter().map(|s| s.map(|Spanned {node, span}| {
-            Spanned {
-                node: match node {
-                    StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id),
-                    _ => node /* might already have a semi */
-                },
-                span: span
-            }
-        })).collect()
-    } else {
-        fully_expanded
+        if let Some(stmt) = fully_expanded.pop() {
+            let new_stmt = stmt.map(|Spanned {node, span}| {
+                Spanned {
+                    node: match node {
+                        StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id),
+                        _ => node /* might already have a semi */
+                    },
+                    span: span
+                }
+            });
+            fully_expanded.push(new_stmt);
+        }
     }
+
+    fully_expanded
 }
 
 // expand a non-macro stmt. this is essentially the fallthrough for
@@ -1355,7 +1367,7 @@ fn fold_item_underscore(&mut self, item: ast::Item_) -> ast::Item_ {
     }
 
     fn fold_stmt(&mut self, stmt: P<ast::Stmt>) -> SmallVector<P<ast::Stmt>> {
-        stmt.and_then(|stmt| expand_stmt(stmt, self))
+        expand_stmt(stmt, self)
     }
 
     fn fold_block(&mut self, block: P<Block>) -> P<Block> {
@@ -1502,8 +1514,8 @@ fn mark_pat(pat: P<ast::Pat>, m: Mrk) -> P<ast::Pat> {
 }
 
 // apply a given mark to the given stmt. Used following the expansion of a macro.
-fn mark_stmt(expr: P<ast::Stmt>, m: Mrk) -> P<ast::Stmt> {
-    Marker{mark:m}.fold_stmt(expr)
+fn mark_stmt(stmt: P<ast::Stmt>, m: Mrk) -> P<ast::Stmt> {
+    Marker{mark:m}.fold_stmt(stmt)
         .expect_one("marking a stmt didn't return exactly one stmt")
 }
 
index 009075540fa1e01cbcf9f312ad009859c86420b7..730da6cc59419f3ea71566d1edf2b36fe9ecb711 100644 (file)
@@ -99,10 +99,24 @@ fn make_impl_items(self: Box<ParserAnyMacro<'a>>)
         Some(ret)
     }
 
-    fn make_stmt(self: Box<ParserAnyMacro<'a>>) -> Option<P<ast::Stmt>> {
-        let ret = self.parser.borrow_mut().parse_stmt();
-        self.ensure_complete_parse(true);
-        ret
+    fn make_stmts(self: Box<ParserAnyMacro<'a>>)
+                 -> Option<SmallVector<P<ast::Stmt>>> {
+        let mut ret = SmallVector::zero();
+        loop {
+            let mut parser = self.parser.borrow_mut();
+            match parser.token {
+                token::Eof => break,
+                _ => match parser.parse_stmt_nopanic() {
+                    Ok(maybe_stmt) => match maybe_stmt {
+                        Some(stmt) => ret.push(stmt),
+                        None => (),
+                    },
+                    Err(_) => break,
+                }
+            }
+        }
+        self.ensure_complete_parse(false);
+        Some(ret)
     }
 }
 
index 1649934f4b10e5d4628d20e9ed26370bb9e5a7f6..6b864d5294766fabffa4448c4440f997c32d6d22 100644 (file)
@@ -69,6 +69,20 @@ pub fn as_slice<'a>(&'a self) -> &'a [T] {
         }
     }
 
+    pub fn pop(&mut self) -> Option<T> {
+        match self.repr {
+            Zero => None,
+            One(..) => {
+                let one = mem::replace(&mut self.repr, Zero);
+                match one {
+                    One(v1) => Some(v1),
+                    _ => unreachable!()
+                }
+            }
+            Many(ref mut vs) => vs.pop(),
+        }
+    }
+
     pub fn push(&mut self, v: T) {
         match self.repr {
             Zero => self.repr = One(v),
index f06290b27cb2809583269f159f4b3313de5745ee..f96704ee128325fee864cd4109adfd1b42057619 100644 (file)
@@ -89,7 +89,8 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
         } else {
             src = PathBuf::from(&env::args().nth(2).unwrap());
         }
-        // preprocess the markdown, rerouting markdown references to html references
+        // preprocess the markdown, rerouting markdown references to html
+        // references
         let mut markdown_data = String::new();
         try!(File::open(&src.join(&item.path)).and_then(|mut f| {
             f.read_to_string(&mut markdown_data)
@@ -135,6 +136,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
             format!("-o{}", out_path.display()),
             format!("--html-before-content={}", prelude.display()),
             format!("--html-after-content={}", postlude.display()),
+            format!("--markdown-playground-url=http://play.rust-lang.org"),
             format!("--markdown-css={}", item.path_to_root.join("rust-book.css").display()),
             "--markdown-no-toc".to_string(),
         ];
@@ -148,6 +150,14 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> {
 
     // create index.html from the root README
     try!(fs::copy(&tgt.join("README.html"), &tgt.join("index.html")));
+
+    // Copy some js for playpen
+    let mut jquery = try!(File::create(tgt.join("jquery.js")));
+    let js = include_bytes!("../librustdoc/html/static/jquery-2.1.0.min.js");
+    try!(jquery.write_all(js));
+    let mut playpen = try!(File::create(tgt.join("playpen.js")));
+    let js = include_bytes!("../librustdoc/html/static/playpen.js");
+    try!(playpen.write_all(js));
     Ok(())
 }
 
index 6ee8230e9f8baeab4b1bd35d05c521fcc488caaf..d5483593aa8888f3e487d145f7cd0e01b7b510de 100644 (file)
@@ -71,4 +71,6 @@
 
 });
 </script>
+<script type="text/javascript" src="jquery.js"></script>
+<script type="text/javascript" src="playpen.js"></script>
 "#;
diff --git a/src/test/auxiliary/inline-default-methods.rs b/src/test/auxiliary/inline-default-methods.rs
new file mode 100644 (file)
index 0000000..5f1bd7a
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Foo {
+    fn bar(&self);
+    fn foo(&mut self) {}
+}
diff --git a/src/test/auxiliary/issue-13698.rs b/src/test/auxiliary/issue-13698.rs
new file mode 100644 (file)
index 0000000..0bb2133
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Foo {
+    #[doc(hidden)]
+    fn foo(&self) {}
+}
+
+impl Foo for i32 {}
diff --git a/src/test/auxiliary/issue-15318.rs b/src/test/auxiliary/issue-15318.rs
new file mode 100644 (file)
index 0000000..9e42dbf
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![doc(html_root_url = "http://example.com/")]
+
+/// dox
+#[doc(primitive = "pointer")]
+pub mod ptr {}
diff --git a/src/test/auxiliary/issue-17476.rs b/src/test/auxiliary/issue-17476.rs
new file mode 100644 (file)
index 0000000..d3a8603
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+#![doc(html_root_url = "http://example.com")]
+
+pub trait Foo {
+    fn foo(&self) {}
+}
diff --git a/src/test/auxiliary/issue-20646.rs b/src/test/auxiliary/issue-20646.rs
new file mode 100644 (file)
index 0000000..150d801
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Trait {
+    type Output;
+}
+
+pub fn fun<T>(_: T) where T: Trait<Output=i32> {}
diff --git a/src/test/auxiliary/issue-20727.rs b/src/test/auxiliary/issue-20727.rs
new file mode 100644 (file)
index 0000000..aea8b42
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Deref {
+    type Target: ?Sized;
+
+    fn deref<'a>(&'a self) -> &'a Self::Target;
+}
+
+pub trait Add<RHS = Self> {
+    type Output;
+
+    fn add(self, rhs: RHS) -> Self::Output;
+}
+
+
+pub trait Bar {}
+pub trait Deref2 {
+    type Target: Bar;
+
+    fn deref(&self) -> Self::Target;
+}
+
+pub trait Index<Idx: ?Sized> {
+    type Output: ?Sized;
+    fn index(&self, index: Idx) -> &Self::Output;
+}
+
+pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
+    fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
+}
diff --git a/src/test/auxiliary/issue-21092.rs b/src/test/auxiliary/issue-21092.rs
new file mode 100644 (file)
index 0000000..6d6046c
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Foo {
+    type Bar;
+    fn foo(&self) {}
+}
+
+pub struct Bar;
+
+impl Foo for Bar {
+    type Bar = i32;
+}
diff --git a/src/test/auxiliary/issue-21801.rs b/src/test/auxiliary/issue-21801.rs
new file mode 100644 (file)
index 0000000..ada6c69
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub struct Foo;
+
+impl Foo {
+    pub fn new<F>(f: F) -> Foo where F: FnMut() -> i32 {
+        loop {}
+    }
+}
diff --git a/src/test/auxiliary/issue-22025.rs b/src/test/auxiliary/issue-22025.rs
new file mode 100644 (file)
index 0000000..554b580
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub mod foo {
+
+    pub trait Foo {}
+    pub struct Bar;
+
+    impl Foo for Bar {}
+
+}
diff --git a/src/test/auxiliary/issue-23207-1.rs b/src/test/auxiliary/issue-23207-1.rs
new file mode 100644 (file)
index 0000000..ec9f200
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub mod fmt {
+    pub struct Error;
+}
diff --git a/src/test/auxiliary/issue-23207-2.rs b/src/test/auxiliary/issue-23207-2.rs
new file mode 100644 (file)
index 0000000..5e9c540
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern crate issue_23207_1;
+
+pub mod fmt {
+    pub use issue_23207_1::fmt::Error;
+}
+
diff --git a/src/test/auxiliary/rustdoc-default-impl.rs b/src/test/auxiliary/rustdoc-default-impl.rs
new file mode 100644 (file)
index 0000000..8f11629
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(core)]
+
+pub mod bar {
+    use std::marker;
+
+    pub trait Bar: marker::MarkerTrait + 'static {}
+
+    impl Bar for .. {}
+
+    pub trait Foo {
+        fn foo(&self) {}
+    }
+
+    impl Foo {
+        pub fn test<T: Bar>(&self) {}
+    }
+
+    pub struct TypeId;
+
+    impl TypeId {
+        pub fn of<T: Bar + ?Sized>() -> TypeId {
+            panic!()
+        }
+    }
+}
diff --git a/src/test/auxiliary/rustdoc-extern-default-method.rs b/src/test/auxiliary/rustdoc-extern-default-method.rs
new file mode 100644 (file)
index 0000000..8615627
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+
+pub trait Trait {
+    fn provided(&self) {}
+}
+
+pub struct Struct;
+
+impl Trait for Struct {
+    fn provided(&self) {}
+}
diff --git a/src/test/auxiliary/rustdoc-extern-method.rs b/src/test/auxiliary/rustdoc-extern-method.rs
new file mode 100644 (file)
index 0000000..96a7a83
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+#![feature(unboxed_closures)]
+
+pub trait Foo {
+    extern "rust-call" fn foo(&self, _: ()) -> i32;
+    extern "rust-call" fn foo_(&self, _: ()) -> i32 { 0 }
+}
diff --git a/src/test/auxiliary/rustdoc-ffi.rs b/src/test/auxiliary/rustdoc-ffi.rs
new file mode 100644 (file)
index 0000000..e06dbe7
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+
+extern "C" {
+    // @has lib/fn.foreigner.html //pre 'pub unsafe fn foreigner(cold_as_ice: u32)'
+    pub fn foreigner(cold_as_ice: u32);
+}
diff --git a/src/test/compile-fail/borrowck-escaping-closure-error-1.rs b/src/test/compile-fail/borrowck-escaping-closure-error-1.rs
new file mode 100644 (file)
index 0000000..87e40df
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::thread::spawn;
+
+// Test that we give a custom error (E0373) for the case where a
+// closure is escaping current frame, and offer a suggested code edit.
+// I refrained from including the precise message here, but the
+// original text as of the time of this writing is:
+//
+//    closure may outlive the current function, but it borrows `books`,
+//    which is owned by the current function
+
+fn main() {
+    let mut books = vec![1,2,3];
+    spawn(|| books.push(4));
+    //~^ ERROR E0373
+}
diff --git a/src/test/compile-fail/borrowck-escaping-closure-error-2.rs b/src/test/compile-fail/borrowck-escaping-closure-error-2.rs
new file mode 100644 (file)
index 0000000..67700be
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we give a custom error (E0373) for the case where a
+// closure is escaping current frame, and offer a suggested code edit.
+// I refrained from including the precise message here, but the
+// original text as of the time of this writing is:
+//
+//    closure may outlive the current function, but it borrows `books`,
+//    which is owned by the current function
+
+fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
+    let mut books = vec![1,2,3];
+    Box::new(|| books.push(4))
+    //~^ ERROR E0373
+}
+
+fn main() { }
diff --git a/src/test/compile-fail/coherence-overlap-all-t-and-tuple.rs b/src/test/compile-fail/coherence-overlap-all-t-and-tuple.rs
new file mode 100644 (file)
index 0000000..3fd635b
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Check that we detect an overlap here in the case where:
+//
+//    for some type X:
+//      T = (X,)
+//      T11 = X, U11 = X
+//
+// Seems pretty basic, but then there was issue #24241. :)
+
+trait From<U> {
+}
+
+impl <T> From<T> for T { //~ ERROR E0119
+}
+
+impl <T11, U11> From<(U11,)> for (T11,) {
+}
+
+fn main() { }
index 64334fe4392f8774962a9c301aa109bc50bb0c1e..b4abef0bd280b914aa20d155a0ac18f07740f432 100644 (file)
@@ -18,10 +18,10 @@ trait ListItem<'a> : MarkerTrait {
 
 struct List<'a, T: ListItem<'a>> {
 //~^ ERROR the parameter type `T` may not live long enough
-//~^^ NOTE ...so that the reference type `&'a [T]` does not outlive the data it points at
+//~| HELP consider adding an explicit lifetime bound
+//~| NOTE ...so that the reference type `&'a [T]` does not outlive the data it points at
     slice: &'a [T]
 }
-//~^ HELP consider adding an explicit lifetime bound
 impl<'a, T: ListItem<'a>> Collection for List<'a, T> {
     fn len(&self) -> usize {
         0
index 55a793f7480a42e1db237844f544e8271d6c0a10..0089bff3e8fd89c56d0870bd3edc8648e285068b 100644 (file)
@@ -15,7 +15,7 @@ fn id<T>(t: T) -> T { t }
 fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
     // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
     id(Box::new(|| *v))
-        //~^ ERROR `v` does not live long enough
+        //~^ ERROR E0373
         //~| ERROR cannot move out of borrowed content
 }
 
index b3ce84c7e6f1a2dbfcd46c49e2f9e13910146c0c..32770d9018938b96da18a91a61abc5beeb0e8330 100644 (file)
@@ -17,7 +17,8 @@ fn bar() {}
 }
 
 macro_rules! ignored_expr {
-    () => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
+    () => ( 1,  //~ ERROR unexpected token: `,`
+            2 ) //~ ERROR macro expansion ignores token `2`
 }
 
 macro_rules! ignored_pat {
index bdebadb2832caa0bcfe50e295a1e26769232d30b..948dc8cd219689301a9b30ba2702422a39294451 100644 (file)
@@ -13,7 +13,7 @@ fn ignore<F>(_f: F) where F: for<'z> FnOnce(&'z isize) -> &'z isize {}
 fn nested() {
     let y = 3;
     ignore(
-        |z| { //~ ERROR `y` does not live long enough
+        |z| { //~ ERROR E0373
             if false { &y } else { z }
         });
 }
index 0b1f1291df0665b5bff30d60b600a27fc1c77a28..50c63abc0d4e54432de2c5ee92b45e0ff1b45ef2 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![crate_name="foo"]
-
 /// ```rust
 /// assert_eq!(foo::foo(), 1);
 /// ```
diff --git a/src/test/run-make/rustdoc-assoc-types/Makefile b/src/test/run-make/rustdoc-assoc-types/Makefile
deleted file mode 100644 (file)
index 74fca83..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-
-all: lib.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc lib.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc lib.rs
diff --git a/src/test/run-make/rustdoc-assoc-types/lib.rs b/src/test/run-make/rustdoc-assoc-types/lib.rs
deleted file mode 100644 (file)
index 3e6e0ad..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type="lib"]
-
-// @has lib/trait.Index.html
-pub trait Index<I: ?Sized> {
-    // @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
-    type Output: ?Sized;
-    // @has - '//*[@id="tymethod.index"]//code' \
-    //      "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
-    fn index<'a>(&'a self, index: I) -> &'a Self::Output;
-}
diff --git a/src/test/run-make/rustdoc-default-impl/Makefile b/src/test/run-make/rustdoc-default-impl/Makefile
deleted file mode 100644 (file)
index 338cf9d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-
-all: foo.rs bar.rs
-       $(RUSTC) foo.rs --crate-type lib
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc bar.rs -L $(TMPDIR)
diff --git a/src/test/run-make/rustdoc-default-impl/bar.rs b/src/test/run-make/rustdoc-default-impl/bar.rs
deleted file mode 100644 (file)
index 60a2f72..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-extern crate foo;
-
-pub use foo::bar;
-
-pub fn wut<T: bar::Bar>() {
-}
diff --git a/src/test/run-make/rustdoc-default-impl/foo.rs b/src/test/run-make/rustdoc-default-impl/foo.rs
deleted file mode 100644 (file)
index 8f11629..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(optin_builtin_traits)]
-#![feature(core)]
-
-pub mod bar {
-    use std::marker;
-
-    pub trait Bar: marker::MarkerTrait + 'static {}
-
-    impl Bar for .. {}
-
-    pub trait Foo {
-        fn foo(&self) {}
-    }
-
-    impl Foo {
-        pub fn test<T: Bar>(&self) {}
-    }
-
-    pub struct TypeId;
-
-    impl TypeId {
-        pub fn of<T: Bar + ?Sized>() -> TypeId {
-            panic!()
-        }
-    }
-}
diff --git a/src/test/run-make/rustdoc-extern-default-method/Makefile b/src/test/run-make/rustdoc-extern-default-method/Makefile
deleted file mode 100644 (file)
index ffc4a08..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
--include ../tools.mk
-
-all: lib.rs ext.rs
-       $(HOST_RPATH_ENV) $(RUSTC) ext.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -L $(TMPDIR) -w html -o $(TMPDIR)/doc lib.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc lib.rs
diff --git a/src/test/run-make/rustdoc-extern-default-method/ext.rs b/src/test/run-make/rustdoc-extern-default-method/ext.rs
deleted file mode 100644 (file)
index 8615627..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type="lib"]
-
-pub trait Trait {
-    fn provided(&self) {}
-}
-
-pub struct Struct;
-
-impl Trait for Struct {
-    fn provided(&self) {}
-}
diff --git a/src/test/run-make/rustdoc-extern-default-method/lib.rs b/src/test/run-make/rustdoc-extern-default-method/lib.rs
deleted file mode 100644 (file)
index df92764..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-extern crate ext;
-
-// @count lib/struct.Struct.html '//*[@id="method.provided"]' 1
-pub use ext::Struct;
diff --git a/src/test/run-make/rustdoc-extern-method/Makefile b/src/test/run-make/rustdoc-extern-method/Makefile
deleted file mode 100644 (file)
index 55cbd2d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
--include ../tools.mk
-
-all: foo.rs bar.rs
-       $(HOST_RPATH_ENV) $(RUSTC) foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -L $(TMPDIR) -w html -o $(TMPDIR)/doc bar.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc bar.rs
diff --git a/src/test/run-make/rustdoc-extern-method/bar.rs b/src/test/run-make/rustdoc-extern-method/bar.rs
deleted file mode 100644 (file)
index 26a05f8..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(unboxed_closures)]
-
-extern crate foo;
-
-// @has bar/trait.Foo.html //pre "pub trait Foo"
-// @has - '//*[@id="tymethod.foo"]//code' 'extern "rust-call" fn foo'
-// @has - '//*[@id="tymethod.foo_"]//code' 'extern "rust-call" fn foo_'
-pub use foo::Foo;
-
-// @has bar/trait.Bar.html //pre "pub trait Bar"
-pub trait Bar {
-    // @has - '//*[@id="tymethod.bar"]//code' 'extern "rust-call" fn bar'
-    extern "rust-call" fn bar(&self, _: ());
-    // @has - '//*[@id="method.bar_"]//code' 'extern "rust-call" fn bar_'
-    extern "rust-call" fn bar_(&self, _: ()) { }
-}
diff --git a/src/test/run-make/rustdoc-extern-method/foo.rs b/src/test/run-make/rustdoc-extern-method/foo.rs
deleted file mode 100644 (file)
index 96a7a83..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type="lib"]
-#![feature(unboxed_closures)]
-
-pub trait Foo {
-    extern "rust-call" fn foo(&self, _: ()) -> i32;
-    extern "rust-call" fn foo_(&self, _: ()) -> i32 { 0 }
-}
diff --git a/src/test/run-make/rustdoc-ffi/Makefile b/src/test/run-make/rustdoc-ffi/Makefile
deleted file mode 100644 (file)
index c312efe..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
--include ../tools.mk
-
-all: lib.rs
-       $(HOST_RPATH_ENV) $(RUSTC) lib.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc lib.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -L $(TMPDIR) -w html -o $(TMPDIR)/doc user.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc lib.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc user.rs
diff --git a/src/test/run-make/rustdoc-ffi/lib.rs b/src/test/run-make/rustdoc-ffi/lib.rs
deleted file mode 100644 (file)
index e06dbe7..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type="lib"]
-
-extern "C" {
-    // @has lib/fn.foreigner.html //pre 'pub unsafe fn foreigner(cold_as_ice: u32)'
-    pub fn foreigner(cold_as_ice: u32);
-}
diff --git a/src/test/run-make/rustdoc-ffi/user.rs b/src/test/run-make/rustdoc-ffi/user.rs
deleted file mode 100644 (file)
index 09d7a7c..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type="lib"]
-
-extern crate lib;
-
-// @has user/fn.foreigner.html //pre 'pub unsafe fn foreigner(cold_as_ice: u32)'
-pub use lib::foreigner;
diff --git a/src/test/run-make/rustdoc-hidden-line/Makefile b/src/test/run-make/rustdoc-hidden-line/Makefile
deleted file mode 100644 (file)
index 3ac7b6d..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
--include ../tools.mk
-
-# FIXME ignore windows
-ifndef IS_WINDOWS
-
-all:
-       @echo $(RUSTDOC)
-       $(HOST_RPATH_ENV) $(RUSTDOC) --test foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc foo.rs
-
-else
-all:
-
-endif
diff --git a/src/test/run-make/rustdoc-hidden-line/foo.rs b/src/test/run-make/rustdoc-hidden-line/foo.rs
deleted file mode 100644 (file)
index 3906d9e..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_name="foo"]
-
-/// The '# ' lines should be removed from the output, but the #[derive] should be
-/// retained.
-///
-/// ```rust
-/// mod to_make_deriving_work { // FIXME #4913
-///
-/// # #[derive(PartialEq)] // invisible
-/// # struct Foo; // invisible
-///
-/// #[derive(PartialEq)] // Bar
-/// struct Bar(Foo);
-///
-/// fn test() {
-///     let x = Bar(Foo);
-///     assert!(x == x); // check that the derivings worked
-/// }
-///
-/// }
-/// ```
-pub fn foo() {}
-
-// @!has foo/fn.foo.html invisible
-// @matches - //pre "#\[derive\(PartialEq\)\] // Bar"
diff --git a/src/test/run-make/rustdoc-must-use/Makefile b/src/test/run-make/rustdoc-must-use/Makefile
deleted file mode 100644 (file)
index 74fca83..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-
-all: lib.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc lib.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc lib.rs
diff --git a/src/test/run-make/rustdoc-must-use/lib.rs b/src/test/run-make/rustdoc-must-use/lib.rs
deleted file mode 100644 (file)
index cef79d4..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type="lib"]
-
-// @has lib/struct.Struct.html //pre '#[must_use]'
-#[must_use]
-pub struct Struct {
-    field: i32,
-}
-
-// @has lib/enum.Enum.html //pre '#[must_use = "message"]'
-#[must_use = "message"]
-pub enum Enum {
-    Variant(i32),
-}
diff --git a/src/test/run-make/rustdoc-negative-impl/Makefile b/src/test/run-make/rustdoc-negative-impl/Makefile
deleted file mode 100644 (file)
index c1b1683..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-
-all: foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc foo.rs
diff --git a/src/test/run-make/rustdoc-negative-impl/foo.rs b/src/test/run-make/rustdoc-negative-impl/foo.rs
deleted file mode 100644 (file)
index 6c56bcc..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(optin_builtin_traits)]
-
-// @matches foo/struct.Alpha.html '//pre' "pub struct Alpha"
-pub struct Alpha;
-// @matches foo/struct.Bravo.html '//pre' "pub struct Bravo<B>"
-pub struct Bravo<B>(B);
-
-// @matches foo/struct.Alpha.html '//*[@class="impl"]//code' "impl !Send for Alpha"
-impl !Send for Alpha {}
-
-// @matches foo/struct.Bravo.html '//*[@class="impl"]//code' "impl<B> !Send for Bravo<B>"
-impl<B> !Send for Bravo<B> {}
diff --git a/src/test/run-make/rustdoc-recursion/Makefile b/src/test/run-make/rustdoc-recursion/Makefile
deleted file mode 100644 (file)
index ba97183..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
--include ../tools.mk
-
-# FIXME ignore windows
-ifndef IS_WINDOWS
-all:
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo2.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo3.rs
-else
-all:
-endif
diff --git a/src/test/run-make/rustdoc-recursion/foo.rs b/src/test/run-make/rustdoc-recursion/foo.rs
deleted file mode 100644 (file)
index 7505d20..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type = "lib"]
-#![feature(globs)]
-
-mod m {
-    pub use self::a::Foo;
-
-    mod a {
-        pub struct Foo;
-    }
-
-    mod b {
-        pub use super::*;
-    }
-}
diff --git a/src/test/run-make/rustdoc-recursion/foo2.rs b/src/test/run-make/rustdoc-recursion/foo2.rs
deleted file mode 100644 (file)
index 7505d20..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_type = "lib"]
-#![feature(globs)]
-
-mod m {
-    pub use self::a::Foo;
-
-    mod a {
-        pub struct Foo;
-    }
-
-    mod b {
-        pub use super::*;
-    }
-}
diff --git a/src/test/run-make/rustdoc-recursion/foo3.rs b/src/test/run-make/rustdoc-recursion/foo3.rs
deleted file mode 100644 (file)
index 62a13f7..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(globs)]
-
-pub mod longhands {
-    pub use super::*;
-
-    pub use super::common_types::computed::compute_CSSColor as to_computed_value;
-
-    pub fn computed_as_specified() {}
-}
-
-pub mod common_types {
-    pub mod computed {
-        pub use super::super::longhands::computed_as_specified as compute_CSSColor;
-    }
-}
diff --git a/src/test/run-make/rustdoc-search-index/Makefile b/src/test/run-make/rustdoc-search-index/Makefile
deleted file mode 100644 (file)
index e7e8f0c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
--include ../tools.mk
-
-# FIXME ignore windows
-ifndef IS_WINDOWS
-
-source=index.rs
-
-all:
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc $(source)
-       $(HTMLDOCCK) $(TMPDIR)/doc $(source)
-
-else
-all:
-
-endif
diff --git a/src/test/run-make/rustdoc-search-index/index.rs b/src/test/run-make/rustdoc-search-index/index.rs
deleted file mode 100644 (file)
index 42469a2..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_name = "rustdoc_test"]
-
-// @has search-index.js Foo
-pub use private::Foo;
-
-mod private {
-    pub struct Foo;
-    impl Foo {
-        pub fn test_method() {} // @has - test_method
-        fn priv_method() {} // @!has - priv_method
-    }
-
-    pub trait PrivateTrait {
-        fn trait_method(&self) {} // @!has - priv_method
-    }
-}
diff --git a/src/test/run-make/rustdoc-smoke/Makefile b/src/test/run-make/rustdoc-smoke/Makefile
deleted file mode 100644 (file)
index 7a1ad76..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
--include ../tools.mk
-all:
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc foo.rs
diff --git a/src/test/run-make/rustdoc-smoke/foo.rs b/src/test/run-make/rustdoc-smoke/foo.rs
deleted file mode 100644 (file)
index 494eb03..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// @has foo/index.html
-#![crate_name = "foo"]
-
-//! Very docs
-
-// @has foo/bar/index.html
-pub mod bar {
-
-    /// So correct
-    // @has foo/bar/baz/index.html
-    pub mod baz {
-        /// Much detail
-        // @has foo/bar/baz/fn.baz.html
-        pub fn baz() { }
-    }
-
-    /// *wow*
-    // @has foo/bar/trait.Doge.html
-    pub trait Doge { fn dummy(&self) { } }
-
-    // @has foo/bar/struct.Foo.html
-    pub struct Foo { x: isize, y: usize }
-
-    // @has foo/bar/fn.prawns.html
-    pub fn prawns((a, b): (isize, usize), Foo { x, y }: Foo) { }
-}
diff --git a/src/test/run-make/rustdoc-src-links/Makefile b/src/test/run-make/rustdoc-src-links/Makefile
deleted file mode 100644 (file)
index 419603e..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-all:
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc qux/mod.rs
diff --git a/src/test/run-make/rustdoc-src-links/foo.rs b/src/test/run-make/rustdoc-src-links/foo.rs
deleted file mode 100644 (file)
index 9a964f1..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![crate_name = "foo"]
-
-//! Dox
-// @has src/foo/foo.rs.html
-// @has foo/index.html '//a/@href' '../src/foo/foo.rs.html'
-
-pub mod qux;
-
-// @has foo/bar/index.html '//a/@href' '../../src/foo/foo.rs.html'
-pub mod bar {
-
-    /// Dox
-    // @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/foo.rs.html'
-    pub mod baz {
-        /// Dox
-        // @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/foo.rs.html'
-        pub fn baz() { }
-    }
-
-    /// Dox
-    // @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/foo.rs.html'
-    pub trait Foobar { fn dummy(&self) { } }
-
-    // @has foo/bar/struct.Foo.html '//a/@href' '../../src/foo/foo.rs.html'
-    pub struct Foo { x: i32, y: u32 }
-
-    // @has foo/bar/fn.prawns.html '//a/@href' '../../src/foo/foo.rs.html'
-    pub fn prawns((a, b): (i32, u32), Foo { x, y }: Foo) { }
-}
-
-/// Dox
-// @has foo/fn.modfn.html '//a/@href' '../src/foo/foo.rs.html'
-pub fn modfn() { }
diff --git a/src/test/run-make/rustdoc-src-links/qux/mod.rs b/src/test/run-make/rustdoc-src-links/qux/mod.rs
deleted file mode 100644 (file)
index 9b1563d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Dox
-// @has src/foo/qux/mod.rs.html
-// @has foo/qux/index.html '//a/@href' '../../src/foo/qux/mod.rs.html'
-
-// @has foo/qux/bar/index.html '//a/@href' '../../../src/foo/qux/mod.rs.html'
-pub mod bar {
-
-    /// Dox
-    // @has foo/qux/bar/baz/index.html '//a/@href' '../../../../src/foo/qux/mod.rs.html'
-    pub mod baz {
-        /// Dox
-        // @has foo/qux/bar/baz/fn.baz.html '//a/@href' '../../../../src/foo/qux/mod.rs.html'
-        pub fn baz() { }
-    }
-
-    /// Dox
-    // @has foo/qux/bar/trait.Foobar.html '//a/@href' '../../../src/foo/qux/mod.rs.html'
-    pub trait Foobar { fn dummy(&self) { } }
-
-    // @has foo/qux/bar/struct.Foo.html '//a/@href' '../../../src/foo/qux/mod.rs.html'
-    pub struct Foo { x: i32, y: u32 }
-
-    // @has foo/qux/bar/fn.prawns.html '//a/@href' '../../../src/foo/qux/mod.rs.html'
-    pub fn prawns((a, b): (i32, u32), Foo { x, y }: Foo) { }
-}
-
-/// Dox
-// @has foo/qux/fn.modfn.html '//a/@href' '../../src/foo/qux/mod.rs.html'
-pub fn modfn() { }
diff --git a/src/test/run-make/rustdoc-viewpath-self/Makefile b/src/test/run-make/rustdoc-viewpath-self/Makefile
deleted file mode 100644 (file)
index c1b1683..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-
-all: foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc foo.rs
diff --git a/src/test/run-make/rustdoc-viewpath-self/foo.rs b/src/test/run-make/rustdoc-viewpath-self/foo.rs
deleted file mode 100644 (file)
index 6fd47d8..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2015 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-pub mod io {
-    pub trait Reader { fn dummy(&self) { } }
-}
-
-pub enum Maybe<A> {
-    Just(A),
-    Nothing
-}
-
-// @has foo/prelude/index.html
-pub mod prelude {
-    // @has foo/prelude/index.html '//code' 'pub use io::{self, Reader}'
-    #[doc(no_inline)] pub use io::{self, Reader};
-    // @has foo/prelude/index.html '//code' 'pub use Maybe::{self, Just, Nothing}'
-    #[doc(no_inline)] pub use Maybe::{self, Just, Nothing};
-}
diff --git a/src/test/run-make/rustdoc-where/Makefile b/src/test/run-make/rustdoc-where/Makefile
deleted file mode 100644 (file)
index c1b1683..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--include ../tools.mk
-
-all: foo.rs
-       $(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
-       $(HTMLDOCCK) $(TMPDIR)/doc foo.rs
diff --git a/src/test/run-make/rustdoc-where/foo.rs b/src/test/run-make/rustdoc-where/foo.rs
deleted file mode 100644 (file)
index 91a7e1c..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-pub trait MyTrait { fn dummy(&self) { } }
-
-// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A> where A: MyTrait"
-pub struct Alpha<A>(A) where A: MyTrait;
-// @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B> where B: MyTrait"
-pub trait Bravo<B> where B: MyTrait { fn get(&self, B: B); }
-// @has foo/fn.charlie.html '//pre' "pub fn charlie<C>() where C: MyTrait"
-pub fn charlie<C>() where C: MyTrait {}
-
-pub struct Delta<D>(D);
-
-// @has foo/struct.Delta.html '//*[@class="impl"]//code' \
-//          "impl<D> Delta<D> where D: MyTrait"
-impl<D> Delta<D> where D: MyTrait {
-    pub fn delta() {}
-}
-
-pub struct Echo<E>(E);
-
-// @has foo/struct.Echo.html '//*[@class="impl"]//code' \
-//          "impl<E> MyTrait for Echo<E> where E: MyTrait"
-// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
-//          "impl<E> MyTrait for Echo<E> where E: MyTrait"
-impl<E> MyTrait for Echo<E> where E: MyTrait {}
-
-pub enum Foxtrot<F> { Foxtrot1(F) }
-
-// @has foo/enum.Foxtrot.html '//*[@class="impl"]//code' \
-//          "impl<F> MyTrait for Foxtrot<F> where F: MyTrait"
-// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
-//          "impl<F> MyTrait for Foxtrot<F> where F: MyTrait"
-impl<F> MyTrait for Foxtrot<F> where F: MyTrait {}
diff --git a/src/test/run-pass/discriminant_value.rs b/src/test/run-pass/discriminant_value.rs
new file mode 100644 (file)
index 0000000..217e696
--- /dev/null
@@ -0,0 +1,77 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(core)]
+
+extern crate core;
+use core::intrinsics::discriminant_value;
+
+enum CLike1 {
+    A,
+    B,
+    C,
+    D
+}
+
+enum CLike2 {
+    A = 5,
+    B = 2,
+    C = 19,
+    D
+}
+
+#[repr(i8)]
+enum CLike3 {
+    A = 5,
+    B,
+    C = -1,
+    D
+}
+
+enum ADT {
+    First(u32, u32),
+    Second(u64)
+}
+
+enum NullablePointer {
+    Something(&'static u32),
+    Nothing
+}
+
+static CONST : u32 = 0xBEEF;
+
+pub fn main() {
+    unsafe {
+
+        assert_eq!(discriminant_value(&CLike1::A), 0);
+        assert_eq!(discriminant_value(&CLike1::B), 1);
+        assert_eq!(discriminant_value(&CLike1::C), 2);
+        assert_eq!(discriminant_value(&CLike1::D), 3);
+
+        assert_eq!(discriminant_value(&CLike2::A), 5);
+        assert_eq!(discriminant_value(&CLike2::B), 2);
+        assert_eq!(discriminant_value(&CLike2::C), 19);
+        assert_eq!(discriminant_value(&CLike2::D), 20);
+
+        assert_eq!(discriminant_value(&CLike3::A), 5);
+        assert_eq!(discriminant_value(&CLike3::B), 6);
+        assert_eq!(discriminant_value(&CLike3::C), -1_i8 as u64);
+        assert_eq!(discriminant_value(&CLike3::D), 0);
+
+        assert_eq!(discriminant_value(&ADT::First(0,0)), 0);
+        assert_eq!(discriminant_value(&ADT::Second(5)), 1);
+
+        assert_eq!(discriminant_value(&NullablePointer::Nothing), 1);
+        assert_eq!(discriminant_value(&NullablePointer::Something(&CONST)), 0);
+
+        assert_eq!(discriminant_value(&10), 0);
+        assert_eq!(discriminant_value(&"test"), 0);
+    }
+}
diff --git a/src/test/run-pass/fds-are-cloexec.rs b/src/test/run-pass/fds-are-cloexec.rs
new file mode 100644 (file)
index 0000000..cbf7830
--- /dev/null
@@ -0,0 +1,76 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// ignore-windows
+// ignore-android
+
+#![feature(libc)]
+
+extern crate libc;
+
+use std::env;
+use std::fs::{self, File};
+use std::io;
+use std::net::{TcpListener, TcpStream, UdpSocket};
+use std::os::unix::prelude::*;
+use std::process::Command;
+use std::thread;
+
+fn main() {
+    let args = env::args().collect::<Vec<_>>();
+    if args.len() == 1 {
+        parent()
+    } else {
+        child(&args)
+    }
+}
+
+fn parent() {
+    let file = File::open("Makefile").unwrap();
+    let _dir = fs::read_dir("/").unwrap();
+    let tcp1 = TcpListener::bind("127.0.0.1:0").unwrap();
+    assert_eq!(tcp1.as_raw_fd(), file.as_raw_fd() + 2);
+    let tcp2 = tcp1.try_clone().unwrap();
+    let addr = tcp1.local_addr().unwrap();
+    let t = thread::scoped(|| TcpStream::connect(addr).unwrap());
+    let tcp3 = tcp1.accept().unwrap().0;
+    let tcp4 = t.join();
+    let tcp5 = tcp3.try_clone().unwrap();
+    let tcp6 = tcp4.try_clone().unwrap();
+    let udp1 = UdpSocket::bind("127.0.0.1:0").unwrap();
+    let udp2 = udp1.try_clone().unwrap();
+
+    let status = Command::new(env::args().next().unwrap())
+                        .arg(file.as_raw_fd().to_string())
+                        .arg((file.as_raw_fd() + 1).to_string())
+                        .arg(tcp1.as_raw_fd().to_string())
+                        .arg(tcp2.as_raw_fd().to_string())
+                        .arg(tcp3.as_raw_fd().to_string())
+                        .arg(tcp4.as_raw_fd().to_string())
+                        .arg(tcp5.as_raw_fd().to_string())
+                        .arg(tcp6.as_raw_fd().to_string())
+                        .arg(udp1.as_raw_fd().to_string())
+                        .arg(udp2.as_raw_fd().to_string())
+                        .status()
+                        .unwrap();
+    assert!(status.success());
+}
+
+fn child(args: &[String]) {
+    let mut b = [0u8; 2];
+    for arg in &args[1..] {
+        let fd: libc::c_int = arg.parse().unwrap();
+        unsafe {
+            assert_eq!(libc::read(fd, b.as_mut_ptr() as *mut _, 2), -1);
+            assert_eq!(io::Error::last_os_error().raw_os_error(),
+                       Some(libc::EBADF));
+        }
+    }
+}
index be8ecde67836e5e78776203e6ab6fa910b62bd11..96f31891f2f34bbea5d042a635f3f6abd3a11f08 100644 (file)
@@ -23,6 +23,13 @@ fn main() {
     let _ = format!("{:p}{:p}{:p}",
                     rc, arc, b);
 
+    if cfg!(target_pointer_width = "32") {
+        assert_eq!(format!("{:#p}", p),
+                   "0x00000000");
+    } else {
+        assert_eq!(format!("{:#p}", p),
+                   "0x0000000000000000");
+    }
     assert_eq!(format!("{:p}", p),
                "0x0");
 }
index 41c859214e96b188cdc19f970946831ad3bf30f2..3a7af0976441927fe03799d32ce185bb6bd16b40 100644 (file)
@@ -72,6 +72,13 @@ pub fn main() {
     t!(format!("{:X}", 10_usize), "A");
     t!(format!("{}", "foo"), "foo");
     t!(format!("{}", "foo".to_string()), "foo");
+    if cfg!(target_pointer_width = "32") {
+        t!(format!("{:#p}", 0x1234 as *const isize), "0x00001234");
+        t!(format!("{:#p}", 0x1234 as *mut isize), "0x00001234");
+    } else {
+        t!(format!("{:#p}", 0x1234 as *const isize), "0x0000000000001234");
+        t!(format!("{:#p}", 0x1234 as *mut isize), "0x0000000000001234");
+    }
     t!(format!("{:p}", 0x1234 as *const isize), "0x1234");
     t!(format!("{:p}", 0x1234 as *mut isize), "0x1234");
     t!(format!("{:x}", A), "aloha");
@@ -85,9 +92,8 @@ pub fn main() {
     t!(format!("{}", 5 + 5), "10");
     t!(format!("{:#4}", C), "☃123");
 
-    // FIXME(#20676)
-    // let a: &fmt::Debug = &1;
-    // t!(format!("{:?}", a), "1");
+    let a: &fmt::Debug = &1;
+    t!(format!("{:?}", a), "1");
 
 
     // Formatting strings and their arguments
diff --git a/src/test/run-pass/issue-15523-big.rs b/src/test/run-pass/issue-15523-big.rs
new file mode 100644 (file)
index 0000000..33c81ca
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Issue 15523: derive(PartialOrd) should use the provided
+// discriminant values for the derived ordering.
+//
+// This test is checking corner cases that arise when you have
+// 64-bit values in the variants.
+
+#[derive(PartialEq, PartialOrd)]
+#[repr(u64)]
+enum Eu64 {
+    Pos2 = 2,
+    PosMax = !0,
+    Pos1 = 1,
+}
+
+#[derive(PartialEq, PartialOrd)]
+#[repr(i64)]
+enum Ei64 {
+    Pos2 = 2,
+    Neg1 = -1,
+    NegMin = 1 << 63,
+    PosMax = !(1 << 63),
+    Pos1 = 1,
+}
+
+fn main() {
+    assert!(Eu64::Pos2 > Eu64::Pos1);
+    assert!(Eu64::Pos2 < Eu64::PosMax);
+    assert!(Eu64::Pos1 < Eu64::PosMax);
+
+
+    assert!(Ei64::Pos2 > Ei64::Pos1);
+    assert!(Ei64::Pos2 > Ei64::Neg1);
+    assert!(Ei64::Pos1 > Ei64::Neg1);
+    assert!(Ei64::Pos2 > Ei64::NegMin);
+    assert!(Ei64::Pos1 > Ei64::NegMin);
+    assert!(Ei64::Pos2 < Ei64::PosMax);
+    assert!(Ei64::Pos1 < Ei64::PosMax);
+}
diff --git a/src/test/run-pass/issue-15523.rs b/src/test/run-pass/issue-15523.rs
new file mode 100644 (file)
index 0000000..bb8fa67
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Issue 15523: derive(PartialOrd) should use the provided
+// discriminant values for the derived ordering.
+//
+// This is checking the basic functionality.
+
+#[derive(PartialEq, PartialOrd)]
+enum E1 {
+    Pos2 = 2,
+    Neg1 = -1,
+    Pos1 = 1,
+}
+
+#[derive(PartialEq, PartialOrd)]
+#[repr(u8)]
+enum E2 {
+    Pos2 = 2,
+    PosMax = !0 as u8,
+    Pos1 = 1,
+}
+
+#[derive(PartialEq, PartialOrd)]
+#[repr(i8)]
+enum E3 {
+    Pos2 = 2,
+    Neg1 = -1_i8,
+    Pos1 = 1,
+}
+
+fn main() {
+    assert!(E1::Pos2 > E1::Pos1);
+    assert!(E1::Pos1 > E1::Neg1);
+    assert!(E1::Pos2 > E1::Neg1);
+
+    assert!(E2::Pos2 > E2::Pos1);
+    assert!(E2::Pos1 < E2::PosMax);
+    assert!(E2::Pos2 < E2::PosMax);
+
+    assert!(E3::Pos2 > E3::Pos1);
+    assert!(E3::Pos1 > E3::Neg1);
+    assert!(E3::Pos2 > E3::Neg1);
+}
index a92fcb01f5b302d9a6dd3599901014fdc28c377d..819ec532ed2ce00c8e1092405b91cdf27120947e 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// pretty-expanded FIXME #23616
-
 #[derive(Eq, PartialEq, PartialOrd, Ord)]
 enum Test<'a> {
     Int(&'a isize),
diff --git a/src/test/run-pass/issue-19097.rs b/src/test/run-pass/issue-19097.rs
new file mode 100644 (file)
index 0000000..ca4b72f
--- /dev/null
@@ -0,0 +1,22 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// regression test for #19097
+
+struct Foo<T>(T);
+
+impl<'a, T> Foo<&'a T> {
+    fn foo(&self) {}
+}
+impl<'a, T> Foo<&'a mut T> {
+    fn foo(&self) {}
+}
+
+fn main() {}
diff --git a/src/test/run-pass/issue-21291.rs b/src/test/run-pass/issue-21291.rs
new file mode 100644 (file)
index 0000000..ec095d4
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Regression test for unwrapping the result of `join`, issue #21291
+
+use std::thread;
+
+fn main() {
+    thread::spawn(|| {}).join().unwrap()
+}
diff --git a/src/test/run-pass/issue-21400.rs b/src/test/run-pass/issue-21400.rs
new file mode 100644 (file)
index 0000000..cd55b9f
--- /dev/null
@@ -0,0 +1,66 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Regression test for #21400 which itself was extracted from
+// stackoverflow.com/questions/28031155/is-my-borrow-checker-drunk/28031580
+
+fn main() {
+    let mut t = Test;
+    assert_eq!(t.method1("one"), Ok(1));
+    assert_eq!(t.method2("two"), Ok(2));
+    assert_eq!(t.test(), Ok(2));
+}
+
+struct Test;
+
+impl Test {
+    fn method1(&mut self, _arg: &str) -> Result<usize, &str> {
+        Ok(1)
+    }
+
+    fn method2(self: &mut Test, _arg: &str) -> Result<usize, &str> {
+        Ok(2)
+    }
+
+    fn test(self: &mut Test) -> Result<usize, &str> {
+        let s = format!("abcde");
+        // (Originally, this invocation of method2 was saying that `s`
+        // does not live long enough.)
+        let data = match self.method2(&*s) {
+            Ok(r) => r,
+            Err(e) => return Err(e)
+        };
+        Ok(data)
+    }
+}
+
+// Below is a closer match for the original test that was failing to compile
+
+pub struct GitConnect;
+
+impl GitConnect {
+    fn command(self: &mut GitConnect, _s: &str) -> Result<Vec<Vec<u8>>, &str> {
+        unimplemented!()
+    }
+
+    pub fn git_upload_pack(self: &mut GitConnect) -> Result<String, &str> {
+        let c = format!("git-upload-pack");
+
+        let mut out = String::new();
+        let data = try!(self.command(&c));
+
+        for line in data.iter() {
+            out.push_str(&format!("{:?}", line));
+        }
+
+        Ok(out)
+    }
+}
+
diff --git a/src/test/run-pass/issue-21486.rs b/src/test/run-pass/issue-21486.rs
new file mode 100644 (file)
index 0000000..7f8bd7a
--- /dev/null
@@ -0,0 +1,86 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Issue #21486: Make sure that all structures are dropped, even when
+// created via FRU and control-flow breaks in the middle of
+// construction.
+
+
+use std::sync::atomic::{Ordering, AtomicUsize, ATOMIC_USIZE_INIT};
+
+#[derive(Debug)]
+struct Noisy(u8);
+impl Drop for Noisy {
+    fn drop(&mut self) {
+        // println!("splat #{}", self.0);
+        event(self.0);
+    }
+}
+
+#[allow(dead_code)]
+#[derive(Debug)]
+struct Foo { n0: Noisy, n1: Noisy }
+impl Foo {
+    fn vals(&self) -> (u8, u8) { (self.n0.0, self.n1.0) }
+}
+
+fn leak_1_ret() -> Foo {
+    let _old_foo = Foo { n0: Noisy(1), n1: Noisy(2) };
+    Foo { n0: { return Foo { n0: Noisy(3), n1: Noisy(4) } },
+          .._old_foo
+    };
+}
+
+fn leak_2_ret() -> Foo {
+    let _old_foo = Foo { n0: Noisy(1), n1: Noisy(2) };
+    Foo { n1: { return Foo { n0: Noisy(3), n1: Noisy(4) } },
+          .._old_foo
+    };
+}
+
+// In this case, the control flow break happens *before* we construct
+// `Foo(Noisy(1),Noisy(2))`, so there should be no record of it in the
+// event log.
+fn leak_3_ret() -> Foo {
+    let _old_foo = || Foo { n0: Noisy(1), n1: Noisy(2) };
+    Foo { n1: { return Foo { n0: Noisy(3), n1: Noisy(4) } },
+          .._old_foo()
+    };
+}
+
+pub fn main() {
+    reset_log();
+    assert_eq!(leak_1_ret().vals(), (3,4));
+    assert_eq!(0x01_02_03_04, event_log());
+
+    reset_log();
+    assert_eq!(leak_2_ret().vals(), (3,4));
+    assert_eq!(0x01_02_03_04, event_log());
+
+    reset_log();
+    assert_eq!(leak_3_ret().vals(), (3,4));
+    assert_eq!(0x03_04, event_log());
+}
+
+static LOG: AtomicUsize = ATOMIC_USIZE_INIT;
+
+fn reset_log() {
+    LOG.store(0, Ordering::SeqCst);
+}
+
+fn event_log() -> usize {
+    LOG.load(Ordering::SeqCst)
+}
+
+fn event(tag: u8) {
+    let old_log = LOG.load(Ordering::SeqCst);
+    let new_log = (old_log << 8) + tag as usize;
+    LOG.store(new_log, Ordering::SeqCst);
+}
diff --git a/src/test/run-pass/macro-nested_stmt_macros.rs b/src/test/run-pass/macro-nested_stmt_macros.rs
new file mode 100644 (file)
index 0000000..5997a4f
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+macro_rules! foo {
+    () => {
+        struct Bar;
+        struct Baz;
+    }
+}
+
+macro_rules! grault {
+    () => {
+        foo!();
+        struct Xyzzy;
+    }
+}
+
+fn static_assert_exists<T>() { }
+
+fn main() {
+    grault!();
+    static_assert_exists::<Bar>();
+    static_assert_exists::<Baz>();
+    static_assert_exists::<Xyzzy>();
+}
diff --git a/src/test/run-pass/macro-stmt_macro_in_expr_macro.rs b/src/test/run-pass/macro-stmt_macro_in_expr_macro.rs
new file mode 100644 (file)
index 0000000..c5badd7
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+macro_rules! foo {
+    () => {
+        struct Bar;
+        struct Baz;
+    }
+}
+
+macro_rules! grault {
+    () => {{
+        foo!();
+        struct Xyzzy;
+        0
+    }}
+}
+
+fn main() {
+    let x = grault!();
+    assert_eq!(x, 0);
+}
index 88d5314a96ac59a1cf8e5e7dcff1082c9c31a45a..7ff770327742baaf8c36e0d24126dda278073581 100644 (file)
@@ -8,8 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// pretty-expanded FIXME #23616
-
 #![feature(collections)]
 
 use std::string::String;
diff --git a/src/test/rustdoc/assoc-types.rs b/src/test/rustdoc/assoc-types.rs
new file mode 100644 (file)
index 0000000..20076a7
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+
+// @has assoc_types/trait.Index.html
+pub trait Index<I: ?Sized> {
+    // @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
+    type Output: ?Sized;
+    // @has - '//*[@id="tymethod.index"]//code' \
+    //      "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
+    fn index<'a>(&'a self, index: I) -> &'a Self::Output;
+}
diff --git a/src/test/rustdoc/default-impl.rs b/src/test/rustdoc/default-impl.rs
new file mode 100644 (file)
index 0000000..92b2431
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:rustdoc-default-impl.rs
+// ignore-android
+
+extern crate rustdoc_default_impl as foo;
+
+pub use foo::bar;
+
+pub fn wut<T: bar::Bar>() {
+}
diff --git a/src/test/rustdoc/extern-default-method.rs b/src/test/rustdoc/extern-default-method.rs
new file mode 100644 (file)
index 0000000..9178c1b
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:rustdoc-extern-default-method.rs
+// ignore-android
+
+extern crate rustdoc_extern_default_method as ext;
+
+// @count extern_default_method/struct.Struct.html '//*[@id="method.provided"]' 1
+pub use ext::Struct;
diff --git a/src/test/rustdoc/extern-method.rs b/src/test/rustdoc/extern-method.rs
new file mode 100644 (file)
index 0000000..5e30e6c
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:rustdoc-extern-method.rs
+// ignore-android
+
+#![feature(unboxed_closures)]
+
+extern crate rustdoc_extern_method as foo;
+
+// @has extern_method/trait.Foo.html //pre "pub trait Foo"
+// @has - '//*[@id="tymethod.foo"]//code' 'extern "rust-call" fn foo'
+// @has - '//*[@id="method.foo_"]//code' 'extern "rust-call" fn foo_'
+pub use foo::Foo;
+
+// @has extern_method/trait.Bar.html //pre "pub trait Bar"
+pub trait Bar {
+    // @has - '//*[@id="tymethod.bar"]//code' 'extern "rust-call" fn bar'
+    extern "rust-call" fn bar(&self, _: ());
+    // @has - '//*[@id="method.bar_"]//code' 'extern "rust-call" fn bar_'
+    extern "rust-call" fn bar_(&self, _: ()) { }
+}
diff --git a/src/test/rustdoc/ffi.rs b/src/test/rustdoc/ffi.rs
new file mode 100644 (file)
index 0000000..717c64b
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:rustdoc-ffi.rs
+// ignore-android
+
+extern crate rustdoc_ffi as lib;
+
+// @has ffi/fn.foreigner.html //pre 'pub unsafe extern fn foreigner(cold_as_ice: u32)'
+pub use lib::foreigner;
+
+extern "C" {
+    // @has ffi/fn.another.html //pre 'pub unsafe extern fn another(cold_as_ice: u32)'
+    pub fn another(cold_as_ice: u32);
+}
diff --git a/src/test/rustdoc/hidden-line.rs b/src/test/rustdoc/hidden-line.rs
new file mode 100644 (file)
index 0000000..bb9eec7
--- /dev/null
@@ -0,0 +1,33 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+/// The '# ' lines should be removed from the output, but the #[derive] should be
+/// retained.
+///
+/// ```rust
+/// mod to_make_deriving_work { // FIXME #4913
+///
+/// # #[derive(PartialEq)] // invisible
+/// # struct Foo; // invisible
+///
+/// #[derive(PartialEq)] // Bar
+/// struct Bar(Foo);
+///
+/// fn test() {
+///     let x = Bar(Foo);
+///     assert!(x == x); // check that the derivings worked
+/// }
+///
+/// }
+/// ```
+pub fn foo() {}
+
+// @!has hidden_line/fn.foo.html invisible
+// @matches - //pre "#\[derive\(PartialEq\)\] // Bar"
diff --git a/src/test/rustdoc/inline-default-methods.rs b/src/test/rustdoc/inline-default-methods.rs
new file mode 100644 (file)
index 0000000..a613736
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:inline-default-methods.rs
+// ignore-android
+
+extern crate inline_default_methods;
+
+// @has inline_default_methods/trait.Foo.html
+// @has - '//*[@class="rust trait"]' 'fn bar(&self);'
+// @has - '//*[@class="rust trait"]' 'fn foo(&mut self) { ... }'
+pub use inline_default_methods::Foo;
diff --git a/src/test/rustdoc/issue-13698.rs b/src/test/rustdoc/issue-13698.rs
new file mode 100644 (file)
index 0000000..5c31c29
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-13698.rs
+// ignore-android
+
+extern crate issue_13698;
+
+pub struct Foo;
+// @!has issue_13698/struct.Foo.html '//*[@id="method.foo"]' 'fn foo'
+impl issue_13698::Foo for Foo {}
+
+pub trait Bar {
+    #[doc(hidden)]
+    fn bar(&self) {}
+}
+
+// @!has issue_13698/struct.Foo.html '//*[@id="method.foo"]' 'fn bar'
+impl Bar for Foo {}
diff --git a/src/test/rustdoc/issue-15169.rs b/src/test/rustdoc/issue-15169.rs
new file mode 100644 (file)
index 0000000..6ab848b
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// @has issue_15169/struct.Foo.html '//*[@id="method.eq"]' 'fn eq'
+#[derive(PartialEq)]
+pub struct Foo;
diff --git a/src/test/rustdoc/issue-15318-2.rs b/src/test/rustdoc/issue-15318-2.rs
new file mode 100644 (file)
index 0000000..32898d6
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-15318.rs
+// ignore-android
+
+extern crate issue_15318;
+
+pub use issue_15318::ptr;
+
+// @has issue_15318_2/fn.bar.html \
+//          '//*[@href="primitive.pointer.html"]' \
+//          '*mut T'
+pub fn bar<T>(ptr: *mut T) {}
+
diff --git a/src/test/rustdoc/issue-15318-3.rs b/src/test/rustdoc/issue-15318-3.rs
new file mode 100644 (file)
index 0000000..a548249
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// @has issue_15318_3/primitive.pointer.html
+
+/// dox
+#[doc(primitive = "pointer")]
+pub mod ptr {}
diff --git a/src/test/rustdoc/issue-15318.rs b/src/test/rustdoc/issue-15318.rs
new file mode 100644 (file)
index 0000000..3bcc8f4
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-15318.rs
+// ignore-android
+
+#![feature(no_std)]
+#![no_std]
+
+extern crate issue_15318;
+
+// @has issue_15318/fn.bar.html \
+//      '//*[@href="http://example.com/issue_15318/primitive.pointer.html"]' \
+//      '*mut T'
+pub fn bar<T>(ptr: *mut T) {}
diff --git a/src/test/rustdoc/issue-15347.rs b/src/test/rustdoc/issue-15347.rs
new file mode 100644 (file)
index 0000000..97c37bb
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2105 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:--no-defaults --passes "collapse-docs" --passes "unindent-comments"
+
+// @has issue_15347/fn.foo.html
+#[doc(hidden)]
+pub fn foo() {}
diff --git a/src/test/rustdoc/issue-16019.rs b/src/test/rustdoc/issue-16019.rs
new file mode 100644 (file)
index 0000000..7aae6a0
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+macro_rules! define_struct {
+    ($rounds:expr) => (
+        struct Struct {
+            sk: [u32; $rounds + 1]
+        }
+        )
+}
+
+define_struct!(2);
diff --git a/src/test/rustdoc/issue-16265-1.rs b/src/test/rustdoc/issue-16265-1.rs
new file mode 100644 (file)
index 0000000..c0b99a6
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub struct Foo;
+
+// @has issue_16265_1/traits/index.html '[src]'
+pub mod traits {
+    impl PartialEq for super::Foo {
+        fn eq(&self, _: &super::Foo) -> bool { true }
+    }
+}
diff --git a/src/test/rustdoc/issue-16265-2.rs b/src/test/rustdoc/issue-16265-2.rs
new file mode 100644 (file)
index 0000000..22a8df4
--- /dev/null
@@ -0,0 +1,15 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+// @has issue_16265_2/index.html '[src]'
+
+trait Y {}
+impl Y for Option<u32>{}
diff --git a/src/test/rustdoc/issue-17476.rs b/src/test/rustdoc/issue-17476.rs
new file mode 100644 (file)
index 0000000..8d31a1c
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-17476.rs
+// ignore-android
+
+extern crate issue_17476;
+
+pub struct Foo;
+
+// @has issue_17476/struct.Foo.html \
+//      '//*[@href="http://example.com/issue_17476/trait.Foo.html#method.foo"]' \
+//      'foo'
+impl issue_17476::Foo for Foo {}
diff --git a/src/test/rustdoc/issue-18199.rs b/src/test/rustdoc/issue-18199.rs
new file mode 100644 (file)
index 0000000..46aac87
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:--test
+
+#![doc(test(attr(feature(staged_api))))]
+
+/// ```
+/// #![staged_api]
+/// fn main() {}
+/// ```
+pub fn foo() {}
diff --git a/src/test/rustdoc/issue-19055.rs b/src/test/rustdoc/issue-19055.rs
new file mode 100644 (file)
index 0000000..609ae22
--- /dev/null
@@ -0,0 +1,30 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// @has issue_19055/trait.Any.html
+pub trait Any {}
+
+impl<'any> Any + 'any {
+    // @has - '//*[@id="method.is"]' 'fn is'
+    pub fn is<T: 'static>(&self) -> bool { loop {} }
+
+    // @has - '//*[@id="method.downcast_ref"]' 'fn downcast_ref'
+    pub fn downcast_ref<T: 'static>(&self) -> Option<&T> { loop {} }
+
+    // @has - '//*[@id="method.downcast_mut"]' 'fn downcast_mut'
+    pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> { loop {} }
+}
+
+pub trait Foo {
+    fn foo(&self) {}
+}
+
+// @has - '//*[@id="method.foo"]' 'fn foo'
+impl Foo for Any {}
diff --git a/src/test/rustdoc/issue-20175.rs b/src/test/rustdoc/issue-20175.rs
new file mode 100644 (file)
index 0000000..33ec4b7
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Foo {
+    fn foo(&self) {}
+}
+
+pub struct Bar;
+
+// @has issue_20175/struct.Bar.html \
+//      '//*[@id="method.foo"]' \
+//      'fn foo'
+impl<'a> Foo for &'a Bar {}
diff --git a/src/test/rustdoc/issue-20646.rs b/src/test/rustdoc/issue-20646.rs
new file mode 100644 (file)
index 0000000..77abe35
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-20646.rs
+// ignore-android
+
+#![feature(associated_types)]
+
+extern crate issue_20646;
+
+// @has issue_20646/trait.Trait.html \
+//      '//*[@id="associatedtype.Output"]' \
+//      'type Output'
+pub trait Trait {
+    type Output;
+}
+
+// @has issue_20646/fn.fun.html \
+//      '//*[@class="rust fn"]' 'where T: Trait<Output=i32>'
+pub fn fun<T>(_: T) where T: Trait<Output=i32> {}
+
+pub mod reexport {
+    // @has issue_20646/reexport/trait.Trait.html \
+    //      '//*[@id="associatedtype.Output"]' \
+    //      'type Output'
+    // @has issue_20646/reexport/fn.fun.html \
+    //      '//*[@class="rust fn"]' 'where T: Trait<Output=i32>'
+    pub use issue_20646::{Trait, fun};
+}
diff --git a/src/test/rustdoc/issue-20727-2.rs b/src/test/rustdoc/issue-20727-2.rs
new file mode 100644 (file)
index 0000000..03181be
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-20727.rs
+// ignore-android
+
+extern crate issue_20727;
+
+// @has issue_20727_2/trait.Add.html
+pub trait Add<RHS = Self> {
+    // @has - '//*[@class="rust trait"]' 'trait Add<RHS = Self> {'
+    // @has - '//*[@class="rust trait"]' 'type Output;'
+    type Output;
+
+    // @has - '//*[@class="rust trait"]' 'fn add(self, rhs: RHS) -> Self::Output;'
+    fn add(self, rhs: RHS) -> Self::Output;
+}
+
+// @has issue_20727_2/reexport/trait.Add.html
+pub mod reexport {
+    // @has - '//*[@class="rust trait"]' 'trait Add<RHS = Self> {'
+    // @has - '//*[@class="rust trait"]' 'type Output;'
+    // @has - '//*[@class="rust trait"]' 'fn add(self, rhs: RHS) -> Self::Output;'
+    pub use issue_20727::Add;
+}
+
diff --git a/src/test/rustdoc/issue-20727-3.rs b/src/test/rustdoc/issue-20727-3.rs
new file mode 100644 (file)
index 0000000..9d05ce9
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-20727.rs
+// ignore-android
+
+extern crate issue_20727;
+
+pub trait Bar {}
+
+// @has issue_20727_3/trait.Deref2.html
+pub trait Deref2 {
+    // @has - '//*[@class="rust trait"]' 'trait Deref2 {'
+    // @has - '//*[@class="rust trait"]' 'type Target: Bar;'
+    type Target: Bar;
+
+    // @has - '//*[@class="rust trait"]' 'fn deref(&self) -> Self::Target;'
+    fn deref(&self) -> Self::Target;
+}
+
+// @has issue_20727_3/reexport/trait.Deref2.html
+pub mod reexport {
+    // @has - '//*[@class="rust trait"]' 'trait Deref2 {'
+    // @has - '//*[@class="rust trait"]' 'type Target: Bar;'
+    // @has - '//*[@class="rust trait"]' 'fn deref(&self) -> Self::Target;'
+    pub use issue_20727::Deref2;
+}
diff --git a/src/test/rustdoc/issue-20727-4.rs b/src/test/rustdoc/issue-20727-4.rs
new file mode 100644 (file)
index 0000000..39db387
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-20727.rs
+// ignore-android
+
+extern crate issue_20727;
+
+// @has issue_20727_4/trait.Index.html
+pub trait Index<Idx: ?Sized> {
+    // @has - '//*[@class="rust trait"]' 'trait Index<Idx: ?Sized> {'
+    // @has - '//*[@class="rust trait"]' 'type Output: ?Sized'
+    type Output: ?Sized;
+
+    // @has - '//*[@class="rust trait"]' \
+    //        'fn index(&self, index: Idx) -> &Self::Output'
+    fn index(&self, index: Idx) -> &Self::Output;
+}
+
+// @has issue_20727_4/trait.IndexMut.html
+pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
+    // @has - '//*[@class="rust trait"]' \
+    //        'trait IndexMut<Idx: ?Sized>: Index<Idx> {'
+    // @has - '//*[@class="rust trait"]' \
+    //        'fn index_mut(&mut self, index: Idx) -> &mut Self::Output;'
+    fn index_mut(&mut self, index: Idx) -> &mut Self::Output;
+}
+
+pub mod reexport {
+    // @has issue_20727_4/reexport/trait.Index.html
+    // @has - '//*[@class="rust trait"]' 'trait Index<Idx> where Idx: ?Sized {'
+    // @has - '//*[@class="rust trait"]' 'type Output: ?Sized'
+    // @has - '//*[@class="rust trait"]' \
+    //        'fn index(&self, index: Idx) -> &Self::Output'
+    pub use issue_20727::Index;
+
+    // @has issue_20727_4/reexport/trait.IndexMut.html
+    // @has - '//*[@class="rust trait"]' \
+    //        'trait IndexMut<Idx>: Index<Idx> where Idx: ?Sized {'
+    // @has - '//*[@class="rust trait"]' \
+    //        'fn index_mut(&mut self, index: Idx) -> &mut Self::Output;'
+    pub use issue_20727::IndexMut;
+}
diff --git a/src/test/rustdoc/issue-20727.rs b/src/test/rustdoc/issue-20727.rs
new file mode 100644 (file)
index 0000000..3205f5b
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-20727.rs
+// ignore-android
+
+extern crate issue_20727;
+
+// @has issue_20727/trait.Deref.html
+pub trait Deref {
+    // @has - '//*[@class="rust trait"]' 'trait Deref {'
+    // @has - '//*[@class="rust trait"]' 'type Target: ?Sized;'
+    type Target: ?Sized;
+
+    // @has - '//*[@class="rust trait"]' \
+    //        "fn deref<'a>(&'a self) -> &'a Self::Target;"
+    fn deref<'a>(&'a self) -> &'a Self::Target;
+}
+
+// @has issue_20727/reexport/trait.Deref.html
+pub mod reexport {
+    // @has - '//*[@class="rust trait"]' 'trait Deref {'
+    // @has - '//*[@class="rust trait"]' 'type Target: ?Sized;'
+    // @has - '//*[@class="rust trait"]' \
+    //      "fn deref(&'a self) -> &'a Self::Target;"
+    pub use issue_20727::Deref;
+}
diff --git a/src/test/rustdoc/issue-21092.rs b/src/test/rustdoc/issue-21092.rs
new file mode 100644 (file)
index 0000000..38983ae
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-21092.rs
+// ignore-android
+
+extern crate issue_21092;
+
+// @has issue_21092/struct.Bar.html
+// @has - '//*[@id="assoc_type.Bar"]' 'type Bar = i32'
+pub use issue_21092::{Foo, Bar};
diff --git a/src/test/rustdoc/issue-21474.rs b/src/test/rustdoc/issue-21474.rs
new file mode 100644 (file)
index 0000000..36f160a
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2012-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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub use inner::*;
+
+mod inner {
+    impl super::Blah for super::What { }
+}
+
+pub trait Blah { }
+
+// @count issue_21474/struct.What.html \
+//        '//*[@class="impl"]' 1
+pub struct What;
diff --git a/src/test/rustdoc/issue-21801.rs b/src/test/rustdoc/issue-21801.rs
new file mode 100644 (file)
index 0000000..a4392b8
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-21801.rs
+// ignore-android
+
+extern crate issue_21801;
+
+// @has issue_21801/struct.Foo.html
+// @has - '//*[@id="method.new"]' \
+//        'fn new<F>(f: F) -> Foo where F: FnMut() -> i32'
+pub use issue_21801::Foo;
diff --git a/src/test/rustdoc/issue-22025.rs b/src/test/rustdoc/issue-22025.rs
new file mode 100644 (file)
index 0000000..d2eb4fb
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-22025.rs
+// ignore-android
+
+extern crate issue_22025;
+
+pub use issue_22025::foo::{Foo, Bar};
diff --git a/src/test/rustdoc/issue-22038.rs b/src/test/rustdoc/issue-22038.rs
new file mode 100644 (file)
index 0000000..6f84428
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+extern {
+    // @has issue_22038/fn.foo1.html \
+    //      '//*[@class="rust fn"]' 'pub unsafe extern fn foo1()'
+    pub fn foo1();
+}
+
+extern "system" {
+    // @has issue_22038/fn.foo2.html \
+    //      '//*[@class="rust fn"]' 'pub unsafe extern "system" fn foo2()'
+    pub fn foo2();
+}
+
+// @has issue_22038/fn.bar.html \
+//      '//*[@class="rust fn"]' 'pub extern fn bar()'
+pub extern fn bar() {}
+
+// @has issue_22038/fn.baz.html \
+//      '//*[@class="rust fn"]' 'pub extern "system" fn baz()'
+pub extern "system" fn baz() {}
diff --git a/src/test/rustdoc/issue-23106.rs b/src/test/rustdoc/issue-23106.rs
new file mode 100644 (file)
index 0000000..bfafc6b
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:--test
+
+/// ```
+/// #
+/// ```
+pub fn main() {
+}
diff --git a/src/test/rustdoc/issue-23207.rs b/src/test/rustdoc/issue-23207.rs
new file mode 100644 (file)
index 0000000..7220467
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-23207-1.rs
+// aux-build:issue-23207-2.rs
+// ignore-android
+
+extern crate issue_23207_2;
+
+// @has issue_23207/fmt/index.html
+// @count - '//*[@class="struct"]' 1
+pub use issue_23207_2::fmt;
+
diff --git a/src/test/rustdoc/issue-23511.rs b/src/test/rustdoc/issue-23511.rs
new file mode 100644 (file)
index 0000000..6582ca0
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(no_std, lang_items, core)]
+#![no_std]
+
+extern crate core;
+
+pub mod str {
+    #![doc(primitive = "str")]
+
+    #[lang = "str"]
+    impl str {
+        // @has search-index.js foo
+        pub fn foo(&self) {}
+    }
+}
diff --git a/src/test/rustdoc/issue-23744.rs b/src/test/rustdoc/issue-23744.rs
new file mode 100644 (file)
index 0000000..25374ac
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:--test
+
+/// Example of rustdoc incorrectly parsing <code>```rust,should_panic</code>.
+///
+/// ```should_panic
+/// fn main() { panic!("fee"); }
+/// ```
+///
+/// ```rust,should_panic
+/// fn main() { panic!("fum"); }
+/// ```
+pub fn foo() {}
diff --git a/src/test/rustdoc/must-use.rs b/src/test/rustdoc/must-use.rs
new file mode 100644 (file)
index 0000000..e293675
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// @has must_use/struct.Struct.html //pre '#[must_use]'
+#[must_use]
+pub struct Struct {
+    field: i32,
+}
+
+// @has must_use/enum.Enum.html //pre '#[must_use = "message"]'
+#[must_use = "message"]
+pub enum Enum {
+    Variant(i32),
+}
diff --git a/src/test/rustdoc/negative-impl.rs b/src/test/rustdoc/negative-impl.rs
new file mode 100644 (file)
index 0000000..aadabb1
--- /dev/null
@@ -0,0 +1,22 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+
+// @matches negative_impl/struct.Alpha.html '//pre' "pub struct Alpha"
+pub struct Alpha;
+// @matches negative_impl/struct.Bravo.html '//pre' "pub struct Bravo<B>"
+pub struct Bravo<B>(B);
+
+// @matches negative_impl/struct.Alpha.html '//*[@class="impl"]//code' "impl !Send for Alpha"
+impl !Send for Alpha {}
+
+// @matches negative_impl/struct.Bravo.html '//*[@class="impl"]//code' "impl<B> !Send for Bravo<B>"
+impl<B> !Send for Bravo<B> {}
diff --git a/src/test/rustdoc/recursion1.rs b/src/test/rustdoc/recursion1.rs
new file mode 100644 (file)
index 0000000..7505d20
--- /dev/null
@@ -0,0 +1,24 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "lib"]
+#![feature(globs)]
+
+mod m {
+    pub use self::a::Foo;
+
+    mod a {
+        pub struct Foo;
+    }
+
+    mod b {
+        pub use super::*;
+    }
+}
diff --git a/src/test/rustdoc/recursion2.rs b/src/test/rustdoc/recursion2.rs
new file mode 100644 (file)
index 0000000..7505d20
--- /dev/null
@@ -0,0 +1,24 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "lib"]
+#![feature(globs)]
+
+mod m {
+    pub use self::a::Foo;
+
+    mod a {
+        pub struct Foo;
+    }
+
+    mod b {
+        pub use super::*;
+    }
+}
diff --git a/src/test/rustdoc/recursion3.rs b/src/test/rustdoc/recursion3.rs
new file mode 100644 (file)
index 0000000..62a13f7
--- /dev/null
@@ -0,0 +1,25 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(globs)]
+
+pub mod longhands {
+    pub use super::*;
+
+    pub use super::common_types::computed::compute_CSSColor as to_computed_value;
+
+    pub fn computed_as_specified() {}
+}
+
+pub mod common_types {
+    pub mod computed {
+        pub use super::super::longhands::computed_as_specified as compute_CSSColor;
+    }
+}
diff --git a/src/test/rustdoc/search-index.rs b/src/test/rustdoc/search-index.rs
new file mode 100644 (file)
index 0000000..42469a2
--- /dev/null
@@ -0,0 +1,26 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "rustdoc_test"]
+
+// @has search-index.js Foo
+pub use private::Foo;
+
+mod private {
+    pub struct Foo;
+    impl Foo {
+        pub fn test_method() {} // @has - test_method
+        fn priv_method() {} // @!has - priv_method
+    }
+
+    pub trait PrivateTrait {
+        fn trait_method(&self) {} // @!has - priv_method
+    }
+}
diff --git a/src/test/rustdoc/smoke.rs b/src/test/rustdoc/smoke.rs
new file mode 100644 (file)
index 0000000..6ba7018
--- /dev/null
@@ -0,0 +1,35 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// @has smoke/index.html
+
+//! Very docs
+
+// @has smoke/bar/index.html
+pub mod bar {
+
+    /// So correct
+    // @has smoke/bar/baz/index.html
+    pub mod baz {
+        /// Much detail
+        // @has smoke/bar/baz/fn.baz.html
+        pub fn baz() { }
+    }
+
+    /// *wow*
+    // @has smoke/bar/trait.Doge.html
+    pub trait Doge { fn dummy(&self) { } }
+
+    // @has smoke/bar/struct.Foo.html
+    pub struct Foo { x: isize, y: usize }
+
+    // @has smoke/bar/fn.prawns.html
+    pub fn prawns((a, b): (isize, usize), Foo { x, y }: Foo) { }
+}
diff --git a/src/test/rustdoc/src-links.rs b/src/test/rustdoc/src-links.rs
new file mode 100644 (file)
index 0000000..4d7dad6
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+//! Dox
+// @has src/foo/src-links.rs.html
+// @has foo/index.html '//a/@href' '../src/foo/src-links.rs.html'
+
+#[path = "src-links/mod.rs"]
+pub mod qux;
+
+// @has foo/bar/index.html '//a/@href' '../../src/foo/src-links.rs.html'
+pub mod bar {
+
+    /// Dox
+    // @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/src-links.rs.html'
+    pub mod baz {
+        /// Dox
+        // @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/src-links.rs.html'
+        pub fn baz() { }
+    }
+
+    /// Dox
+    // @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/src-links.rs.html'
+    pub trait Foobar { fn dummy(&self) { } }
+
+    // @has foo/bar/struct.Foo.html '//a/@href' '../../src/foo/src-links.rs.html'
+    pub struct Foo { x: i32, y: u32 }
+
+    // @has foo/bar/fn.prawns.html '//a/@href' '../../src/foo/src-links.rs.html'
+    pub fn prawns((a, b): (i32, u32), Foo { x, y }: Foo) { }
+}
+
+/// Dox
+// @has foo/fn.modfn.html '//a/@href' '../src/foo/src-links.rs.html'
+pub fn modfn() { }
+
+// same hierarchy as above, but just for the submodule
+
+// @has src/foo/src-links/mod.rs.html
+// @has foo/qux/index.html '//a/@href' '../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/bar/index.html '//a/@href' '../../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/bar/baz/index.html '//a/@href' '../../../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/bar/baz/fn.baz.html '//a/@href' '../../../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/bar/trait.Foobar.html '//a/@href' '../../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/bar/struct.Foo.html '//a/@href' '../../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/bar/fn.prawns.html '//a/@href' '../../../src/foo/src-links/mod.rs.html'
+// @has foo/qux/fn.modfn.html '//a/@href' '../../src/foo/src-links/mod.rs.html'
diff --git a/src/test/rustdoc/src-links/mod.rs b/src/test/rustdoc/src-links/mod.rs
new file mode 100644 (file)
index 0000000..eb5e737
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Dox
+pub mod bar {
+
+    /// Dox
+    pub mod baz {
+        /// Dox
+        pub fn baz() { }
+    }
+
+    /// Dox
+    pub trait Foobar { fn dummy(&self) { } }
+
+    pub struct Foo { x: i32, y: u32 }
+
+    pub fn prawns((a, b): (i32, u32), Foo { x, y }: Foo) { }
+}
+
+/// Dox
+pub fn modfn() { }
diff --git a/src/test/rustdoc/viewpath-self.rs b/src/test/rustdoc/viewpath-self.rs
new file mode 100644 (file)
index 0000000..65a9813
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+pub mod io {
+    pub trait Reader { fn dummy(&self) { } }
+}
+
+pub enum Maybe<A> {
+    Just(A),
+    Nothing
+}
+
+// @has foo/prelude/index.html
+pub mod prelude {
+    // @has foo/prelude/index.html '//code' 'pub use io::{self, Reader}'
+    #[doc(no_inline)] pub use io::{self, Reader};
+    // @has foo/prelude/index.html '//code' 'pub use Maybe::{self, Just, Nothing}'
+    #[doc(no_inline)] pub use Maybe::{self, Just, Nothing};
+}
diff --git a/src/test/rustdoc/where.rs b/src/test/rustdoc/where.rs
new file mode 100644 (file)
index 0000000..3ce91d6
--- /dev/null
@@ -0,0 +1,44 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+pub trait MyTrait { fn dummy(&self) { } }
+
+// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A> where A: MyTrait"
+pub struct Alpha<A>(A) where A: MyTrait;
+// @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B> where B: MyTrait"
+pub trait Bravo<B> where B: MyTrait { fn get(&self, B: B); }
+// @has foo/fn.charlie.html '//pre' "pub fn charlie<C>() where C: MyTrait"
+pub fn charlie<C>() where C: MyTrait {}
+
+pub struct Delta<D>(D);
+
+// @has foo/struct.Delta.html '//*[@class="impl"]//code' \
+//          "impl<D> Delta<D> where D: MyTrait"
+impl<D> Delta<D> where D: MyTrait {
+    pub fn delta() {}
+}
+
+pub struct Echo<E>(E);
+
+// @has foo/struct.Echo.html '//*[@class="impl"]//code' \
+//          "impl<E> MyTrait for Echo<E> where E: MyTrait"
+// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
+//          "impl<E> MyTrait for Echo<E> where E: MyTrait"
+impl<E> MyTrait for Echo<E> where E: MyTrait {}
+
+pub enum Foxtrot<F> { Foxtrot1(F) }
+
+// @has foo/enum.Foxtrot.html '//*[@class="impl"]//code' \
+//          "impl<F> MyTrait for Foxtrot<F> where F: MyTrait"
+// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
+//          "impl<F> MyTrait for Foxtrot<F> where F: MyTrait"
+impl<F> MyTrait for Foxtrot<F> where F: MyTrait {}