From 360f2f036d14889f4de37a8b4b6aad0d09772aad Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 31 Mar 2018 23:19:02 +0200 Subject: [PATCH 01/12] Inline most of the code paths for conversions with boxed slices This helps with the specific problem described in #49541, obviously without making any large change to how inlining works in the general case. Everything involved in the conversions is made `#[inline]`, except for the `>::into_boxed_slice` entry point which is made `#[inline(always)]` after checking that duplicating the function mentioned in the issue prevented its inlining if I only annotate it with `#[inline]`. For the record, that function was: ```rust pub fn foo() -> Box<[u8]> { vec![0].into_boxed_slice() } ``` To help the inliner's job, we also hoist a `self.capacity() != self.len` check in `>::shrink_to_fit` and mark it as `#[inline]` too. --- src/liballoc/boxed.rs | 2 ++ src/liballoc/str.rs | 3 +++ src/liballoc/string.rs | 1 + src/liballoc/vec.rs | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index fdc3ef4efb866..2fc60a799f3bb 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -577,6 +577,7 @@ impl<'a, T: Copy> From<&'a [T]> for Box<[T]> { #[stable(feature = "box_from_slice", since = "1.17.0")] impl<'a> From<&'a str> for Box { + #[inline] fn from(s: &'a str) -> Box { unsafe { from_boxed_utf8_unchecked(Box::from(s.as_bytes())) } } @@ -584,6 +585,7 @@ impl<'a> From<&'a str> for Box { #[stable(feature = "boxed_str_conv", since = "1.19.0")] impl From> for Box<[u8]> { + #[inline] fn from(s: Box) -> Self { unsafe { Box::from_raw(Box::into_raw(s) as *mut [u8]) } } diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index d5ef41df0d850..6f05c52eb5799 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -1811,6 +1811,7 @@ impl str { /// assert_eq!(*boxed_bytes, *s.as_bytes()); /// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] + #[inline] pub fn into_boxed_bytes(self: Box) -> Box<[u8]> { self.into() } @@ -2049,6 +2050,7 @@ impl str { /// assert_eq!(boxed_str.into_string(), string); /// ``` #[stable(feature = "box_str", since = "1.4.0")] + #[inline] pub fn into_string(self: Box) -> String { let slice = Box::<[u8]>::from(self); unsafe { String::from_utf8_unchecked(slice.into_vec()) } @@ -2307,6 +2309,7 @@ impl str { /// assert_eq!("☺", &*smile); /// ``` #[stable(feature = "str_box_extras", since = "1.20.0")] +#[inline] pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box { Box::from_raw(Box::into_raw(v) as *mut str) } diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index aa202e2362892..95d5b30b67daa 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1587,6 +1587,7 @@ impl String { /// let b = s.into_boxed_str(); /// ``` #[stable(feature = "box_str", since = "1.4.0")] + #[inline] pub fn into_boxed_str(self) -> Box { let slice = self.vec.into_boxed_slice(); unsafe { from_boxed_utf8_unchecked(slice) } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 2eedb964f88ba..e3c036e6aacaf 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -582,8 +582,11 @@ impl Vec { /// assert!(vec.capacity() >= 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline] pub fn shrink_to_fit(&mut self) { - self.buf.shrink_to_fit(self.len); + if self.capacity() != self.len { + self.buf.shrink_to_fit(self.len); + } } /// Shrinks the capacity of the vector with a lower bound. @@ -636,6 +639,7 @@ impl Vec { /// assert_eq!(slice.into_vec().capacity(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[inline(always)] pub fn into_boxed_slice(mut self) -> Box<[T]> { unsafe { self.shrink_to_fit(); From 4577da75f4badd66a337eb15da76ca836ab1ad6e Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Wed, 4 Apr 2018 19:30:46 +0900 Subject: [PATCH 02/12] Use box syntax instead of Box::new in Mutex::remutex on Windows The Box::new(mem::uninitialized()) pattern actually actively copies uninitialized bytes from the stack into the box, which is a waste of time. Using the box syntax instead avoids the useless copy. --- src/libstd/sys/windows/mutex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 8556036859059..9bf9f749d4df2 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -117,7 +117,7 @@ impl Mutex { 0 => {} n => return n as *mut _, } - let mut re = Box::new(ReentrantMutex::uninitialized()); + let mut re = box ReentrantMutex::uninitialized(); re.init(); let re = Box::into_raw(re); match self.lock.compare_and_swap(0, re as usize, Ordering::SeqCst) { From d4dff03e7c6decd6b545dcb290d2c592969b3d81 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 8 Apr 2018 09:03:33 +0200 Subject: [PATCH 03/12] Remove inline on Vec::shrink_to_fit as asked by Alex --- src/liballoc/vec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index e3c036e6aacaf..3fff28469fed5 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -582,7 +582,6 @@ impl Vec { /// assert!(vec.capacity() >= 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[inline] pub fn shrink_to_fit(&mut self) { if self.capacity() != self.len { self.buf.shrink_to_fit(self.len); From 7ab31f6556c2cce433695b113f53d6275edd724d Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 10 Apr 2018 23:55:41 +0100 Subject: [PATCH 04/12] Prevent EPIPE causing ICEs in rustc and rustdoc --- src/librustc_driver/lib.rs | 12 ++++++++++++ src/librustdoc/lib.rs | 1 + src/libstd/sys/unix/mod.rs | 4 ++-- src/rustc/rustc.rs | 5 ++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 6f88b0aecb6b6..4f23c62ab0663 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -548,6 +548,18 @@ fn run_compiler_impl<'a>(args: &[String], (result, Some(sess)) } +#[cfg(unix)] +pub fn set_sigpipe_handler() { + unsafe { + // Set the SIGPIPE signal handler, so that an EPIPE + // will cause rustc to terminate, as expected. + assert!(libc::signal(libc::SIGPIPE, libc::SIG_DFL) != libc::SIG_ERR); + } +} + +#[cfg(windows)] +pub fn set_sigpipe_handler() {} + // Extract output directory and file from matches. fn make_output(matches: &getopts::Matches) -> (Option, Option) { let odir = matches.opt_str("out-dir").map(|o| PathBuf::from(&o)); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 42e87f88fd40d..1e51f45f149a0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -101,6 +101,7 @@ struct Output { pub fn main() { const STACK_SIZE: usize = 32_000_000; // 32MB + rustc_driver::set_sigpipe_handler(); env_logger::init(); let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || { syntax::with_globals(move || { diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 9bdea945ea42e..c1298e5040dbe 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -80,11 +80,11 @@ pub fn init() { reset_sigpipe(); } - #[cfg(not(any(target_os = "emscripten", target_os="fuchsia")))] + #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))] unsafe fn reset_sigpipe() { assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR); } - #[cfg(any(target_os = "emscripten", target_os="fuchsia"))] + #[cfg(any(target_os = "emscripten", target_os = "fuchsia"))] unsafe fn reset_sigpipe() {} } diff --git a/src/rustc/rustc.rs b/src/rustc/rustc.rs index 9fa33f911a168..c07fb41d13b5c 100644 --- a/src/rustc/rustc.rs +++ b/src/rustc/rustc.rs @@ -22,4 +22,7 @@ extern {} extern crate rustc_driver; -fn main() { rustc_driver::main() } +fn main() { + rustc_driver::set_sigpipe_handler(); + rustc_driver::main() +} From cc2906cb26304301709557a88ac4a3334b88616b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 13 Apr 2018 16:52:54 -0700 Subject: [PATCH 05/12] rustbuild: allow building tools with debuginfo Debugging information for the extended tools is currently disabled for concerns about the size. This patch adds `--enable-debuginfo-tools` to let one opt into having that debuginfo. This is useful for debugging the tools in distro packages. We always strip debuginfo into separate packages anyway, so the extra size is not a concern in regular use. --- CONTRIBUTING.md | 1 + config.toml.example | 4 ++++ src/bootstrap/builder.rs | 12 ++++++++---- src/bootstrap/config.rs | 5 +++++ src/bootstrap/configure.py | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a62405f05967..73d4188d69549 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -121,6 +121,7 @@ configuration used in the build process. Some options to note: #### `[rust]`: - `debuginfo = true` - Build a compiler with debuginfo. Makes building rustc slower, but then you can use a debugger to debug `rustc`. - `debuginfo-lines = true` - An alternative to `debuginfo = true` that doesn't let you use a debugger, but doesn't make building rustc slower and still gives you line numbers in backtraces. +- `debuginfo-tools = true` - Build the extended tools with debuginfo. - `debug-assertions = true` - Makes the log output of `debug!` work. - `optimize = false` - Disable optimizations to speed up compilation of stage1 rust, but makes the stage1 compiler x100 slower. diff --git a/config.toml.example b/config.toml.example index 68bc7dfe720fe..bd18a604a9c86 100644 --- a/config.toml.example +++ b/config.toml.example @@ -262,6 +262,10 @@ # standard library. #debuginfo-only-std = false +# Enable debuginfo for the extended tools: cargo, rls, rustfmt +# Adding debuginfo increases their sizes by a factor of 3-4. +#debuginfo-tools = false + # Whether or not jemalloc is built and enabled #use-jemalloc = true diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 7ff64af919671..ae19c66d60708 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -622,10 +622,14 @@ impl<'a> Builder<'a> { cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(self.compiler(2, self.build.build))); } - if mode != Mode::Tool { - // Tools don't get debuginfo right now, e.g. cargo and rls don't - // get compiled with debuginfo. - // Adding debuginfo increases their sizes by a factor of 3-4. + if mode == Mode::Tool { + // Tools like cargo and rls don't get debuginfo by default right now, but this can be + // enabled in the config. Adding debuginfo increases their sizes by a factor of 3-4. + if self.config.rust_debuginfo_tools { + cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()); + cargo.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string()); + } + } else { cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()); cargo.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string()); cargo.env("RUSTC_FORCE_UNSTABLE", "1"); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 239316d45c49c..95d138b9fab2a 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -94,6 +94,7 @@ pub struct Config { pub rust_debuginfo: bool, pub rust_debuginfo_lines: bool, pub rust_debuginfo_only_std: bool, + pub rust_debuginfo_tools: bool, pub rust_rpath: bool, pub rustc_parallel_queries: bool, pub rustc_default_linker: Option, @@ -282,6 +283,7 @@ struct Rust { debuginfo: Option, debuginfo_lines: Option, debuginfo_only_std: Option, + debuginfo_tools: Option, experimental_parallel_queries: Option, debug_jemalloc: Option, use_jemalloc: Option, @@ -462,6 +464,7 @@ impl Config { let mut llvm_assertions = None; let mut debuginfo_lines = None; let mut debuginfo_only_std = None; + let mut debuginfo_tools = None; let mut debug = None; let mut debug_jemalloc = None; let mut debuginfo = None; @@ -499,6 +502,7 @@ impl Config { debuginfo = rust.debuginfo; debuginfo_lines = rust.debuginfo_lines; debuginfo_only_std = rust.debuginfo_only_std; + debuginfo_tools = rust.debuginfo_tools; optimize = rust.optimize; ignore_git = rust.ignore_git; debug_jemalloc = rust.debug_jemalloc; @@ -582,6 +586,7 @@ impl Config { }; config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default); config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default); + config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(default); let default = debug == Some(true); config.debug_jemalloc = debug_jemalloc.unwrap_or(default); diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index b06968d313ba2..a0123da6d8ff9 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -79,6 +79,7 @@ def v(*args): o("debuginfo", "rust.debuginfo", "build with debugger metadata") o("debuginfo-lines", "rust.debuginfo-lines", "build with line number debugger metadata") o("debuginfo-only-std", "rust.debuginfo-only-std", "build only libstd with debugging information") +o("debuginfo-tools", "rust.debuginfo-tools", "build extended tools with debugging information") o("debug-jemalloc", "rust.debug-jemalloc", "build jemalloc with --enable-debug --enable-fill") v("save-toolstates", "rust.save-toolstates", "save build and test status of external tools into this file") From 6f5a16bf1e23d885fd898d430be3cc07eb572163 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Fri, 13 Apr 2018 21:58:42 +0800 Subject: [PATCH 06/12] fix error span --- src/librustc_mir/borrow_check/mod.rs | 22 ++++++++++++++++++---- src/test/ui/nll/issue-47388.stderr | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 62acdf7654624..87379651c232f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1639,10 +1639,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { } else { self.get_default_err_msg(place) }; + let sp = self.mir.source_info(locations[0]).span; + let mut to_suggest_span = String::new(); + if let Ok(src) = + self.tcx.sess.codemap().span_to_snippet(sp) { + to_suggest_span = src[1..].to_string(); + }; err_info = Some(( - self.mir.source_info(locations[0]).span, + sp, "consider changing this to be a \ - mutable reference: `&mut`", item_msg, + mutable reference", + to_suggest_span, + item_msg, self.get_primary_err_msg(base))); } }, @@ -1652,9 +1660,15 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { _ => {}, } - if let Some((err_help_span, err_help_stmt, item_msg, sec_span)) = err_info { + if let Some((err_help_span, + err_help_stmt, + to_suggest_span, + item_msg, + sec_span)) = err_info { let mut err = self.tcx.cannot_assign(span, &item_msg, Origin::Mir); - err.span_suggestion(err_help_span, err_help_stmt, format!("")); + err.span_suggestion(err_help_span, + err_help_stmt, + format!("&mut {}", to_suggest_span)); if place != place_err { err.span_label(span, sec_span); } diff --git a/src/test/ui/nll/issue-47388.stderr b/src/test/ui/nll/issue-47388.stderr index 272cb6510aa3d..f3952c49a2a36 100644 --- a/src/test/ui/nll/issue-47388.stderr +++ b/src/test/ui/nll/issue-47388.stderr @@ -2,7 +2,7 @@ error[E0594]: cannot assign to data in a `&` reference --> $DIR/issue-47388.rs:18:5 | LL | let fancy_ref = &(&mut fancy); - | ------------- help: consider changing this to be a mutable reference: `&mut` + | ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)` LL | fancy_ref.num = 6; //~ ERROR E0594 | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written From bc7403d067b3e2a154df1ef088377cb2a75f429c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 13 Apr 2018 21:57:53 -0700 Subject: [PATCH 07/12] Avoid specific claims about debuginfo size --- config.toml.example | 2 +- src/bootstrap/builder.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.toml.example b/config.toml.example index bd18a604a9c86..effe00843810d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -263,7 +263,7 @@ #debuginfo-only-std = false # Enable debuginfo for the extended tools: cargo, rls, rustfmt -# Adding debuginfo increases their sizes by a factor of 3-4. +# Adding debuginfo makes them several times larger. #debuginfo-tools = false # Whether or not jemalloc is built and enabled diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index ae19c66d60708..6874efa5a4c73 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -624,7 +624,7 @@ impl<'a> Builder<'a> { if mode == Mode::Tool { // Tools like cargo and rls don't get debuginfo by default right now, but this can be - // enabled in the config. Adding debuginfo increases their sizes by a factor of 3-4. + // enabled in the config. Adding debuginfo makes them several times larger. if self.config.rust_debuginfo_tools { cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()); cargo.env("RUSTC_DEBUGINFO_LINES", self.config.rust_debuginfo_lines.to_string()); From 93734e9c46e30acc9a51f19c56511ce8516b6855 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 13 Apr 2018 21:58:21 -0700 Subject: [PATCH 08/12] Make debuginfo-tools always default false --- src/bootstrap/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 95d138b9fab2a..1b4b2c5fb2a54 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -586,7 +586,7 @@ impl Config { }; config.rust_debuginfo_lines = debuginfo_lines.unwrap_or(default); config.rust_debuginfo_only_std = debuginfo_only_std.unwrap_or(default); - config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(default); + config.rust_debuginfo_tools = debuginfo_tools.unwrap_or(false); let default = debug == Some(true); config.debug_jemalloc = debug_jemalloc.unwrap_or(default); From cbabb1be329b80f012223b230384cba8134820f6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 14 Apr 2018 16:21:46 +0200 Subject: [PATCH 09/12] Remove warning about f64->f32 cast being potential UB As discussed in #15536, the LLVM documentation incorrect described overflowing f64->f32 casts as being undefined behavior. LLVM never treated them as such, and the documentation has been adjusted in https://reviews.llvm.org/rL329065. As such, this warning can now be removed. Closes #49622. --- src/librustc_typeck/check/demand.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index ecfe141605029..c0d6993c7d4dd 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -502,10 +502,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { &format!("{}, producing the closest possible value", msg), cast_suggestion); - err.warn("casting here will cause undefined behavior if the value is \ - finite but larger or smaller than the largest or smallest \ - finite value representable by `f32` (this is a bug and will be \ - fixed)"); } true } From b59fa0d9e81fe36c5d298f8f828aaf0755e96f89 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 15 Apr 2018 10:34:57 +0200 Subject: [PATCH 10/12] Remove #[inline(always)] on Vec::into_boxed_slice --- src/liballoc/vec.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 3fff28469fed5..a6498b8861e14 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -638,7 +638,6 @@ impl Vec { /// assert_eq!(slice.into_vec().capacity(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[inline(always)] pub fn into_boxed_slice(mut self) -> Box<[T]> { unsafe { self.shrink_to_fit(); From afa22d63d700d6b3b5f2f00b3b209928d38e017c Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 16 Apr 2018 16:25:57 +0900 Subject: [PATCH 11/12] Remove unnecessary indentation in rustdoc book codeblock. --- src/doc/rustdoc/src/documentation-tests.md | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index fea8685a605d6..3098587a8a4cc 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -138,31 +138,31 @@ To keep each code block testable, we want the whole program in each block, but we don't want the reader to see every line every time. Here's what we put in our source code: -```text - First, we set `x` to five: +``````markdown +First, we set `x` to five: - ``` - let x = 5; - # let y = 6; - # println!("{}", x + y); - ``` +``` +let x = 5; +# let y = 6; +# println!("{}", x + y); +``` - Next, we set `y` to six: +Next, we set `y` to six: - ``` - # let x = 5; - let y = 6; - # println!("{}", x + y); - ``` +``` +# let x = 5; +let y = 6; +# println!("{}", x + y); +``` - Finally, we print the sum of `x` and `y`: +Finally, we print the sum of `x` and `y`: - ``` - # let x = 5; - # let y = 6; - println!("{}", x + y); - ``` ``` +# let x = 5; +# let y = 6; +println!("{}", x + y); +``` +`````` By repeating all parts of the example, you can ensure that your example still compiles, while only showing the parts that are relevant to that part of your From 6c3e1d75553a4b2dbafb8d62a565d10a09c61fc2 Mon Sep 17 00:00:00 2001 From: kennytm Date: Wed, 4 Apr 2018 18:43:00 +0800 Subject: [PATCH 12/12] Remove `underscore_lifetimes` and `match_default_bindings` from active feature list These are already stabilized in 1.26. --- src/librustc_trans/lib.rs | 1 - src/librustc_typeck/lib.rs | 1 - src/libsyntax/feature_gate.rs | 6 ------ 3 files changed, 8 deletions(-) diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index a38d51e754670..49d0f638f2061 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -29,7 +29,6 @@ #![feature(slice_sort_by_cached_key)] #![feature(optin_builtin_traits)] #![feature(inclusive_range_fields)] -#![feature(underscore_lifetimes)] use rustc::dep_graph::WorkProduct; use syntax_pos::symbol::Symbol; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index a4477e80b988a..4b66939963ed0 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -82,7 +82,6 @@ This API is completely unstable and subject to change. #![feature(slice_patterns)] #![feature(slice_sort_by_cached_key)] #![feature(dyn_trait)] -#![feature(underscore_lifetimes)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 73ebfc20876d0..eaa2050f608f3 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -378,12 +378,6 @@ declare_features! ( // Future-proofing enums/structs with #[non_exhaustive] attribute (RFC 2008) (active, non_exhaustive, "1.22.0", Some(44109), None), - // allow `'_` placeholder lifetimes - (active, underscore_lifetimes, "1.22.0", Some(44524), None), - - // Default match binding modes (RFC 2005) - (active, match_default_bindings, "1.22.0", Some(42640), None), - // Trait object syntax with `dyn` prefix (active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)),