From 2cbbf8d77c12986fe3b9e018d41686ac45b06a76 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 30 Mar 2018 15:16:38 +0200 Subject: [PATCH 01/11] Fix anchor position on fields --- src/librustdoc/html/static/rustdoc.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 31a501d24e7db..f4918033c8e88 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -533,6 +533,9 @@ a { left: -5px; } .small-section-header > .anchor { + left: -20px; +} +.small-section-header > .anchor:not(.field) { left: -28px; } .anchor:before { From 238583a50f0edc6991091dc3e9e6cae835a856ae Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 Apr 2018 16:16:53 +0200 Subject: [PATCH 02/11] Fix anchors issue when everything is collapsed --- src/librustdoc/html/static/main.js | 30 +++++++++++++++++++-------- src/librustdoc/html/static/storage.js | 3 ++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 3c115e2b8bacf..3a3fa833c238b 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -56,6 +56,14 @@ }; } + function getPageId() { + var id = document.location.href.split('#')[1]; + if (id) { + return id.split('?')[0].split('&')[0]; + } + return null; + } + function hasClass(elem, className) { if (elem && className && elem.className) { var elemClass = elem.className; @@ -1643,7 +1651,7 @@ } } - function toggleAllDocs() { + function toggleAllDocs(pageId) { var toggle = document.getElementById("toggle-all-docs"); if (hasClass(toggle, "will-expand")) { updateLocalStorage("rustdoc-collapse", "false"); @@ -1664,12 +1672,12 @@ toggle.title = "expand all docs"; onEach(document.getElementsByClassName("collapse-toggle"), function(e) { - collapseDocs(e, "hide"); + collapseDocs(e, "hide", pageId); }); } } - function collapseDocs(toggle, mode) { + function collapseDocs(toggle, mode, pageId) { if (!toggle || !toggle.parentNode) { return; } @@ -1745,14 +1753,18 @@ } } - var relatedDoc = toggle.parentNode; + var parentElem = toggle.parentNode; + var relatedDoc = parentElem; var docblock = relatedDoc.nextElementSibling; while (!hasClass(relatedDoc, "impl-items")) { relatedDoc = relatedDoc.nextElementSibling; } - if (!relatedDoc && !hasClass(docblock, "docblock")) { + if ((!relatedDoc && !hasClass(docblock, "docblock")) || + (pageId && onEach(relatedDoc.childNodes, function(e) { + return e.id === pageId; + }) === true)) { return; } @@ -1782,7 +1794,7 @@ } } - function autoCollapseAllImpls() { + function autoCollapseAllImpls(pageId) { // Automatically minimize all non-inherent impls onEach(document.getElementsByClassName('impl'), function(n) { // inherent impl ids are like 'impl' or impl-' @@ -1790,7 +1802,7 @@ if (!inherent) { onEach(n.childNodes, function(m) { if (hasClass(m, "collapse-toggle")) { - collapseDocs(m, "hide"); + collapseDocs(m, "hide", pageId); } }); } @@ -1900,7 +1912,7 @@ } }) - autoCollapseAllImpls(); + autoCollapseAllImpls(getPageId()); function createToggleWrapper() { var span = document.createElement('span'); @@ -2030,7 +2042,7 @@ }; if (getCurrentValue("rustdoc-collapse") === "true") { - toggleAllDocs(); + toggleAllDocs(getPageId()); } }()); diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js index 2f4e203ebc5c2..4ef8349fa9ce9 100644 --- a/src/librustdoc/html/static/storage.js +++ b/src/librustdoc/html/static/storage.js @@ -19,10 +19,11 @@ function onEach(arr, func) { if (arr && arr.length > 0 && func) { for (var i = 0; i < arr.length; i++) { if (func(arr[i]) === true) { - break; + return true; } } } + return false; } function updateLocalStorage(name, value) { From 323f8087910b0d63815003970bb8a45e3ccfdb17 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 5 Apr 2018 11:07:19 -0700 Subject: [PATCH 03/11] std: Inline some Termination-related methods These were showing up in tests and in binaries but are trivially optimize-able away, so add `#[inline]` attributes so LLVM has an opportunity to optimize them out. --- src/libstd/process.rs | 2 ++ src/libstd/sys/unix/process/process_common.rs | 1 + src/libstd/sys/windows/process.rs | 1 + 3 files changed, 4 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 40bc84f4bc104..92f0406c09bb5 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1452,6 +1452,7 @@ pub trait Termination { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for () { + #[inline] fn report(self) -> i32 { ExitCode::SUCCESS.report() } } @@ -1481,6 +1482,7 @@ impl Termination for Result { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for ExitCode { + #[inline] fn report(self) -> i32 { self.0.as_i32() } diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs index b7f30600b8a4c..6396bb3a49e28 100644 --- a/src/libstd/sys/unix/process/process_common.rs +++ b/src/libstd/sys/unix/process/process_common.rs @@ -404,6 +404,7 @@ impl ExitCode { pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _); pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _); + #[inline] pub fn as_i32(&self) -> i32 { self.0 as i32 } diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index afa8e3e136935..bd5507e8f8967 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -414,6 +414,7 @@ impl ExitCode { pub const SUCCESS: ExitCode = ExitCode(EXIT_SUCCESS as _); pub const FAILURE: ExitCode = ExitCode(EXIT_FAILURE as _); + #[inline] pub fn as_i32(&self) -> i32 { self.0 as i32 } From 4c51d47269a2610db6fde2660aac9aad3e10b4e2 Mon Sep 17 00:00:00 2001 From: Tatsuyuki Ishi Date: Fri, 6 Apr 2018 16:23:53 +0900 Subject: [PATCH 04/11] bootstrap: Remove the fast path This is rarely noticed, but when you have old submodules, not updating them will cause you run into https://github.com/rust-lang/cargo/issues/4678. --- src/bootstrap/bootstrap.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index cf54591f25cd5..487440becf630 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -770,10 +770,7 @@ def bootstrap(help_triggered): if 'dev' in data: build.set_dev_environment() - # No help text depends on submodules. This check saves ~1 minute of git commands, even if - # all the submodules are present and downloaded! - if not help_triggered: - build.update_submodules() + build.update_submodules() # Fetch/build the bootstrap build.build = args.build or build.build_triple() From ea08bdf30cdeed72973235b17715b552d322da5e Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 6 Apr 2018 15:40:43 +0200 Subject: [PATCH 05/11] add emit_debug_gdb_scripts target option and .. set it to false for no-std targets like ARM Cortex-M and MSP430. For the rationale of this change see the comment in thumb_base.rs --- src/librustc_back/target/mod.rs | 6 ++++++ src/librustc_back/target/msp430_none_elf.rs | 3 +++ src/librustc_back/target/thumb_base.rs | 7 +++++++ src/librustc_trans/debuginfo/gdb.rs | 3 ++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 507243a58a5f9..592b27ac641b5 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -478,6 +478,9 @@ pub struct TargetOptions { /// Whether or not bitcode is embedded in object files pub embed_bitcode: bool, + + /// Whether a .debug_gdb_scripts section will be added to the output object file + pub emit_debug_gdb_scripts: bool, } impl Default for TargetOptions { @@ -550,6 +553,7 @@ impl Default for TargetOptions { codegen_backend: "llvm".to_string(), default_hidden_visibility: false, embed_bitcode: false, + emit_debug_gdb_scripts: true, } } } @@ -799,6 +803,7 @@ impl Target { key!(codegen_backend); key!(default_hidden_visibility, bool); key!(embed_bitcode, bool); + key!(emit_debug_gdb_scripts, bool); if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) { for name in array.iter().filter_map(|abi| abi.as_string()) { @@ -1002,6 +1007,7 @@ impl ToJson for Target { target_option_val!(codegen_backend); target_option_val!(default_hidden_visibility); target_option_val!(embed_bitcode); + target_option_val!(emit_debug_gdb_scripts); if default.abi_blacklist != self.options.abi_blacklist { d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter() diff --git a/src/librustc_back/target/msp430_none_elf.rs b/src/librustc_back/target/msp430_none_elf.rs index d0f512ae47cd9..31df9be0bc3f8 100644 --- a/src/librustc_back/target/msp430_none_elf.rs +++ b/src/librustc_back/target/msp430_none_elf.rs @@ -59,6 +59,9 @@ pub fn target() -> TargetResult { // too much overhead for such small target. trap_unreachable: false, + // See the thumb_base.rs file for an explanation of this value + emit_debug_gdb_scripts: false, + .. Default::default( ) } }) diff --git a/src/librustc_back/target/thumb_base.rs b/src/librustc_back/target/thumb_base.rs index 6a8f52f509310..bb1fbfad2618f 100644 --- a/src/librustc_back/target/thumb_base.rs +++ b/src/librustc_back/target/thumb_base.rs @@ -53,6 +53,13 @@ pub fn opts() -> TargetOptions { // costs it involves. relocation_model: "static".to_string(), abi_blacklist: super::arm_base::abi_blacklist(), + // When this section is added a volatile load to its start address is also generated. This + // volatile load is a footgun as it can end up loading an invalid memory address, depending + // on how the user set up their linker scripts. This section adds pretty printer for stuff + // like std::Vec, which is not that used in no-std context, so it's best to left it out + // until we figure a way to add the pretty printers without requiring a volatile load cf. + // rust-lang/rust#44993. + emit_debug_gdb_scripts: false, .. Default::default() } } diff --git a/src/librustc_trans/debuginfo/gdb.rs b/src/librustc_trans/debuginfo/gdb.rs index 03e7c63dbca36..036e0589e85f5 100644 --- a/src/librustc_trans/debuginfo/gdb.rs +++ b/src/librustc_trans/debuginfo/gdb.rs @@ -85,5 +85,6 @@ pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx) -> bool { !omit_gdb_pretty_printer_section && !cx.sess().target.target.options.is_like_osx && !cx.sess().target.target.options.is_like_windows && - cx.sess().opts.debuginfo != NoDebugInfo + cx.sess().opts.debuginfo != NoDebugInfo && + cx.sess().target.target.options.emit_debug_gdb_scripts } From 1eed662fc4f066ac97eb12bb88008c7eae957d6a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 6 Apr 2018 15:44:08 +0200 Subject: [PATCH 06/11] refactor: simplify `needs_gdb_debug_scripts_section` --- src/librustc_back/target/apple_base.rs | 1 + src/librustc_back/target/windows_base.rs | 1 + src/librustc_back/target/windows_msvc_base.rs | 1 + src/librustc_trans/debuginfo/gdb.rs | 2 -- 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_back/target/apple_base.rs b/src/librustc_back/target/apple_base.rs index 72173b62594e9..480de9ff486e5 100644 --- a/src/librustc_back/target/apple_base.rs +++ b/src/librustc_back/target/apple_base.rs @@ -47,6 +47,7 @@ pub fn opts() -> TargetOptions { exe_allocation_crate: super::maybe_jemalloc(), has_elf_tls: version >= (10, 7), abi_return_struct_as_int: true, + emit_debug_gdb_scripts: false, .. Default::default() } } diff --git a/src/librustc_back/target/windows_base.rs b/src/librustc_back/target/windows_base.rs index 05b6247c9518f..971b21e062f69 100644 --- a/src/librustc_back/target/windows_base.rs +++ b/src/librustc_back/target/windows_base.rs @@ -102,6 +102,7 @@ pub fn opts() -> TargetOptions { ], custom_unwind_resume: true, abi_return_struct_as_int: true, + emit_debug_gdb_scripts: false, .. Default::default() } diff --git a/src/librustc_back/target/windows_msvc_base.rs b/src/librustc_back/target/windows_msvc_base.rs index 34aa17267f8be..06e879bec3492 100644 --- a/src/librustc_back/target/windows_msvc_base.rs +++ b/src/librustc_back/target/windows_msvc_base.rs @@ -34,6 +34,7 @@ pub fn opts() -> TargetOptions { crt_static_allows_dylibs: true, crt_static_respected: true, abi_return_struct_as_int: true, + emit_debug_gdb_scripts: false, .. Default::default() } diff --git a/src/librustc_trans/debuginfo/gdb.rs b/src/librustc_trans/debuginfo/gdb.rs index 036e0589e85f5..0b4858c7ab051 100644 --- a/src/librustc_trans/debuginfo/gdb.rs +++ b/src/librustc_trans/debuginfo/gdb.rs @@ -83,8 +83,6 @@ pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx) -> bool { "omit_gdb_pretty_printer_section"); !omit_gdb_pretty_printer_section && - !cx.sess().target.target.options.is_like_osx && - !cx.sess().target.target.options.is_like_windows && cx.sess().opts.debuginfo != NoDebugInfo && cx.sess().target.target.options.emit_debug_gdb_scripts } From f9bfd8117ab4cad0fe6183cc6fb04f3493bc7654 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Fri, 6 Apr 2018 16:35:03 +0200 Subject: [PATCH 07/11] add THUMB targets to rustup manifest --- src/tools/build-manifest/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 0f482c95e05a2..9f2389292158b 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -90,6 +90,10 @@ static TARGETS: &'static [&'static str] = &[ "sparc-unknown-linux-gnu", "sparc64-unknown-linux-gnu", "sparcv9-sun-solaris", + "thumbv6m-none-eabi", + "thumbv7em-none-eabi", + "thumbv7em-none-eabihf", + "thumbv7m-none-eabi", "wasm32-unknown-emscripten", "wasm32-unknown-unknown", "x86_64-apple-darwin", From ee880b96ae14c3a3f572c1b3ff2ec487e59a914c Mon Sep 17 00:00:00 2001 From: Pulkit Goyal <7895pulkit@gmail.com> Date: Sat, 7 Apr 2018 00:42:47 +0530 Subject: [PATCH 08/11] Using X headings instead of 0.X #49739 --- src/doc/index.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/doc/index.md b/src/doc/index.md index 2e36831d7e86f..2ea889da1fde2 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -13,65 +13,65 @@ unofficial documentation resources as well! Many of these resources take the form of "books"; we collectively call these "The Rust Bookshelf." Some are large, some are small. -## Learn Rust +# Learn Rust If you'd like to learn Rust, this is the spot for you! All of these resources assume that you have programmed before, but not in any specific language: -### The Rust Programming Language +## The Rust Programming Language Affectionately nicknamed "the book," [The Rust Programming Language](book/index.html) will give you an overview of the language from first principles. You'll build a few projects along the way, and by the end, you'll have a solid grasp of the language. -### Rust By Example +## Rust By Example If reading multiple hundreds of pages about a language isn't your style, then [Rust By Example](rust-by-example/index.html) has you covered. While the book talks about code with a lot of words, RBE shows off a bunch of code, and keeps the talking to a minimum. It also includes exercises! -## Use Rust +# Use Rust Once you've gotten familliar with the language, these resources can help you when you're actually using it day-to-day. -### The Standard Library +## The Standard Library Rust's standard library has [extensive API documentation](std/index.html), with explanations of how to use various things, as well as example code for accomplishing various tasks. -### The Cargo Book +## The Cargo Book [The Cargo Book](cargo/index.html) is a guide to Cargo, Rust's build tool and dependency manager. -### The Rustdoc Book +## The Rustdoc Book [The Rustdoc Book](rustdoc/index.html) describes our documentation tool, `rustdoc`. -### Extended Error Listing +## Extended Error Listing Many of Rust's errors come with error codes, and you can request extended diagnostics from the compiler on those errors. You can also [read them here](error-index.html), if you prefer to read them that way. -## Master Rust +# Master Rust Once you're quite familiar with the language, you may find these advanced resources useful. -### The Reference +## The Reference [The Reference](reference/index.html) is not a formal spec, but is more detailed and comprehensive than the book. -### The Rustonomicon +## The Rustonomicon [The Rustonomicon](nomicon/index.html) is your guidebook to the dark arts of unsafe Rust. It's also sometimes called "the 'nomicon." -### The Unstable Book +## The Unstable Book [The Unstable Book](unstable-book/index.html) has documentation for unstable features. From 6c08bb8b0841ecfbcf6ee22e0690d2e256e84850 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Apr 2018 15:20:57 -0700 Subject: [PATCH 09/11] proc_macro: Improve Debug representations This commit improves the `fmt::Debug` output of `proc_macro` data structures by primarily focusing on the representation exposed by `proc_macro` rather than the compiler's own internal representation. This cuts down quite a bit on assorted wrapper types and ensure a relatively clean output. Closes #49720 --- src/libproc_macro/lib.rs | 83 ++++++++++++++++++++++++++------------ src/libproc_macro/quote.rs | 15 +++---- 2 files changed, 63 insertions(+), 35 deletions(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 32697e46a08ac..257a8a72b1c7c 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -127,7 +127,8 @@ impl fmt::Display for TokenStream { #[stable(feature = "proc_macro_lib", since = "1.15.0")] impl fmt::Debug for TokenStream { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) + f.write_str("TokenStream ")?; + f.debug_list().entries(self.clone()).finish() } } @@ -222,7 +223,7 @@ pub fn quote_span(span: Span) -> TokenStream { /// A region of source code, along with macro expansion information. #[unstable(feature = "proc_macro", issue = "38356")] -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone)] pub struct Span(syntax_pos::Span); macro_rules! diagnostic_method { @@ -334,6 +335,16 @@ impl Span { diagnostic_method!(help, Level::Help); } +#[unstable(feature = "proc_macro", issue = "38356")] +impl fmt::Debug for Span { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?} bytes({}...{})", + self.0.ctxt(), + self.0.lo().0, + self.0.hi().0) + } +} + /// A line-column pair representing the start or end of a `Span`. #[unstable(feature = "proc_macro", issue = "38356")] #[derive(Copy, Clone, Debug, PartialEq, Eq)] @@ -422,7 +433,7 @@ impl PartialEq for SourceFile { /// A single token or a delimited sequence of token trees (e.g. `[1, (), ..]`). #[unstable(feature = "proc_macro", issue = "38356")] -#[derive(Clone, Debug)] +#[derive(Clone)] pub enum TokenTree { /// A delimited tokenstream Group(Group), @@ -463,6 +474,20 @@ impl TokenTree { } } +#[unstable(feature = "proc_macro", issue = "38356")] +impl fmt::Debug for TokenTree { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + // Each of these has the name in the struct type in the derived debug, + // so don't bother with an extra layer of indirection + match *self { + TokenTree::Group(ref tt) => tt.fmt(f), + TokenTree::Term(ref tt) => tt.fmt(f), + TokenTree::Op(ref tt) => tt.fmt(f), + TokenTree::Literal(ref tt) => tt.fmt(f), + } + } +} + #[unstable(feature = "proc_macro", issue = "38356")] impl From for TokenTree { fn from(g: Group) -> TokenTree { @@ -717,7 +742,8 @@ impl fmt::Display for Term { #[derive(Clone, Debug)] #[unstable(feature = "proc_macro", issue = "38356")] pub struct Literal { - token: token::Token, + lit: token::Lit, + suffix: Option, span: Span, } @@ -734,10 +760,9 @@ macro_rules! suffixed_int_literals { /// below. #[unstable(feature = "proc_macro", issue = "38356")] pub fn $name(n: $kind) -> Literal { - let lit = token::Lit::Integer(Symbol::intern(&n.to_string())); - let ty = Some(Symbol::intern(stringify!($kind))); Literal { - token: token::Literal(lit, ty), + lit: token::Lit::Integer(Symbol::intern(&n.to_string())), + suffix: Some(Symbol::intern(stringify!($kind))), span: Span::call_site(), } } @@ -759,9 +784,9 @@ macro_rules! unsuffixed_int_literals { /// below. #[unstable(feature = "proc_macro", issue = "38356")] pub fn $name(n: $kind) -> Literal { - let lit = token::Lit::Integer(Symbol::intern(&n.to_string())); Literal { - token: token::Literal(lit, None), + lit: token::Lit::Integer(Symbol::intern(&n.to_string())), + suffix: None, span: Span::call_site(), } } @@ -814,9 +839,9 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {}", n); } - let lit = token::Lit::Float(Symbol::intern(&n.to_string())); Literal { - token: token::Literal(lit, None), + lit: token::Lit::Float(Symbol::intern(&n.to_string())), + suffix: None, span: Span::call_site(), } } @@ -837,9 +862,9 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {}", n); } - let lit = token::Lit::Float(Symbol::intern(&n.to_string())); Literal { - token: token::Literal(lit, Some(Symbol::intern("f32"))), + lit: token::Lit::Float(Symbol::intern(&n.to_string())), + suffix: Some(Symbol::intern("f32")), span: Span::call_site(), } } @@ -859,9 +884,9 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {}", n); } - let lit = token::Lit::Float(Symbol::intern(&n.to_string())); Literal { - token: token::Literal(lit, None), + lit: token::Lit::Float(Symbol::intern(&n.to_string())), + suffix: None, span: Span::call_site(), } } @@ -882,9 +907,9 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {}", n); } - let lit = token::Lit::Float(Symbol::intern(&n.to_string())); Literal { - token: token::Literal(lit, Some(Symbol::intern("f64"))), + lit: token::Lit::Float(Symbol::intern(&n.to_string())), + suffix: Some(Symbol::intern("f64")), span: Span::call_site(), } } @@ -897,7 +922,8 @@ impl Literal { escaped.extend(ch.escape_debug()); } Literal { - token: token::Literal(token::Lit::Str_(Symbol::intern(&escaped)), None), + lit: token::Lit::Str_(Symbol::intern(&escaped)), + suffix: None, span: Span::call_site(), } } @@ -908,7 +934,8 @@ impl Literal { let mut escaped = String::new(); escaped.extend(ch.escape_unicode()); Literal { - token: token::Literal(token::Lit::Char(Symbol::intern(&escaped)), None), + lit: token::Lit::Char(Symbol::intern(&escaped)), + suffix: None, span: Span::call_site(), } } @@ -919,7 +946,8 @@ impl Literal { let string = bytes.iter().cloned().flat_map(ascii::escape_default) .map(Into::::into).collect::(); Literal { - token: token::Literal(token::Lit::ByteStr(Symbol::intern(&string)), None), + lit: token::Lit::ByteStr(Symbol::intern(&string)), + suffix: None, span: Span::call_site(), } } @@ -1055,7 +1083,7 @@ impl TokenTree { Ident(ident, true) => { tt!(Term::new(&format!("r#{}", ident), Span(span))) } - Literal(..) => tt!(self::Literal { token, span: Span(span) }), + Literal(lit, suffix) => tt!(self::Literal { lit, suffix, span: Span(span) }), DocComment(c) => { let style = comments::doc_comment_style(&c.as_str()); let stripped = comments::strip_doc_comment_decoration(&c.as_str()); @@ -1111,33 +1139,36 @@ impl TokenTree { return TokenTree::Token(tt.span.0, token).into(); } self::TokenTree::Literal(self::Literal { - token: Literal(Lit::Integer(ref a), b), + lit: Lit::Integer(ref a), + suffix, span, }) if a.as_str().starts_with("-") => { let minus = BinOp(BinOpToken::Minus); let integer = Symbol::intern(&a.as_str()[1..]); - let integer = Literal(Lit::Integer(integer), b); + let integer = Literal(Lit::Integer(integer), suffix); let a = TokenTree::Token(span.0, minus); let b = TokenTree::Token(span.0, integer); return vec![a, b].into_iter().collect() } self::TokenTree::Literal(self::Literal { - token: Literal(Lit::Float(ref a), b), + lit: Lit::Float(ref a), + suffix, span, }) if a.as_str().starts_with("-") => { let minus = BinOp(BinOpToken::Minus); let float = Symbol::intern(&a.as_str()[1..]); - let float = Literal(Lit::Float(float), b); + let float = Literal(Lit::Float(float), suffix); let a = TokenTree::Token(span.0, minus); let b = TokenTree::Token(span.0, float); return vec![a, b].into_iter().collect() } self::TokenTree::Literal(tt) => { - return TokenTree::Token(tt.span.0, tt.token).into() + let token = Literal(tt.lit, tt.suffix); + return TokenTree::Token(tt.span.0, token).into() } }; diff --git a/src/libproc_macro/quote.rs b/src/libproc_macro/quote.rs index cc8575b88be97..a0ec692809499 100644 --- a/src/libproc_macro/quote.rs +++ b/src/libproc_macro/quote.rs @@ -208,13 +208,15 @@ macro_rules! literals { match self { $(LiteralKind::$i => { Literal { - token: token::Literal(token::Lit::$i(sym), suffix), + lit: token::Lit::$i(sym), + suffix, span: contents.span, } })* $(LiteralKind::$raw(n) => { Literal { - token: token::Literal(token::Lit::$raw(sym, n), suffix), + lit: token::Lit::$raw(sym, n), + suffix, span: contents.span, } })* @@ -224,16 +226,11 @@ macro_rules! literals { impl Literal { fn kind_contents_and_suffix(self) -> (LiteralKind, Term, Option) { - let (lit, suffix) = match self.token { - token::Literal(lit, suffix) => (lit, suffix), - _ => panic!("unsupported literal {:?}", self.token), - }; - - let (kind, contents) = match lit { + let (kind, contents) = match self.lit { $(token::Lit::$i(contents) => (LiteralKind::$i, contents),)* $(token::Lit::$raw(contents, n) => (LiteralKind::$raw(n), contents),)* }; - let suffix = suffix.map(|sym| Term::new(&sym.as_str(), self.span())); + let suffix = self.suffix.map(|sym| Term::new(&sym.as_str(), self.span())); (kind, Term::new(&contents.as_str(), self.span()), suffix) } } From 52766b57477002583b0a72c917a172c082cb4a36 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 6 Apr 2018 22:57:10 -0700 Subject: [PATCH 10/11] Print proc_macro spans as a half-open range A span covering a single byte, such as for an operator `+` token, should print as e.g. `80..81` rather than `80...81`. The lo end of the range is inclusive and the hi end is exclusive. --- src/libproc_macro/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index 257a8a72b1c7c..449b8fcfb2d40 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -338,7 +338,7 @@ impl Span { #[unstable(feature = "proc_macro", issue = "38356")] impl fmt::Debug for Span { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?} bytes({}...{})", + write!(f, "{:?} bytes({}..{})", self.0.ctxt(), self.0.lo().0, self.0.hi().0) From 679657b863c2a53a3052d8af9defbce48e12db10 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 30 Mar 2018 13:06:34 +0200 Subject: [PATCH 11/11] Inject the `compiler_builtins` crate whenever the `core` crate is injected --- src/Cargo.lock | 14 ++++++++++ src/liballoc/Cargo.toml | 1 + src/liballoc_jemalloc/Cargo.toml | 1 + src/liballoc_system/Cargo.toml | 1 + src/libpanic_abort/Cargo.toml | 1 + src/libpanic_unwind/Cargo.toml | 1 + src/libprofiler_builtins/Cargo.toml | 1 + src/librustc_asan/Cargo.toml | 1 + src/librustc_lsan/Cargo.toml | 1 + src/librustc_msan/Cargo.toml | 1 + src/librustc_tsan/Cargo.toml | 1 + src/libstd/lib.rs | 1 + src/libstd_unicode/Cargo.toml | 1 + src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/std_inject.rs | 41 ++++++++++++++++++----------- src/libunwind/Cargo.toml | 1 + src/rustc/dlmalloc_shim/Cargo.toml | 1 + src/rustc/libc_shim/Cargo.toml | 2 ++ 18 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index f70fc81829f58..004d1c0ffc933 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -10,6 +10,7 @@ dependencies = [ name = "alloc" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "std_unicode 0.0.0", @@ -23,6 +24,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", ] @@ -32,6 +34,7 @@ name = "alloc_system" version = "0.0.0" dependencies = [ "alloc 0.0.0", + "compiler_builtins 0.0.0", "core 0.0.0", "dlmalloc 0.0.0", "libc 0.0.0", @@ -541,6 +544,7 @@ name = "dlmalloc" version = "0.0.0" dependencies = [ "alloc 0.0.0", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -976,6 +980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "libc" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1254,6 +1259,7 @@ dependencies = [ name = "panic_abort" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", ] @@ -1263,6 +1269,7 @@ name = "panic_unwind" version = "0.0.0" dependencies = [ "alloc 0.0.0", + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", "unwind 0.0.0", @@ -1401,6 +1408,7 @@ name = "profiler_builtins" version = "0.0.0" dependencies = [ "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1797,6 +1805,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1942,6 +1951,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -1991,6 +2001,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -2130,6 +2141,7 @@ dependencies = [ "alloc_system 0.0.0", "build_helper 0.1.0", "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -2343,6 +2355,7 @@ dependencies = [ name = "std_unicode" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", ] @@ -2725,6 +2738,7 @@ dependencies = [ name = "unwind" version = "0.0.0" dependencies = [ + "compiler_builtins 0.0.0", "core 0.0.0", "libc 0.0.0", ] diff --git a/src/liballoc/Cargo.toml b/src/liballoc/Cargo.toml index 3bf919b0c0016..2eb8ea1260446 100644 --- a/src/liballoc/Cargo.toml +++ b/src/liballoc/Cargo.toml @@ -10,6 +10,7 @@ path = "lib.rs" [dependencies] core = { path = "../libcore" } std_unicode = { path = "../libstd_unicode" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } [dev-dependencies] rand = "0.4" diff --git a/src/liballoc_jemalloc/Cargo.toml b/src/liballoc_jemalloc/Cargo.toml index 6d7d83dd99388..fd4a45530463d 100644 --- a/src/liballoc_jemalloc/Cargo.toml +++ b/src/liballoc_jemalloc/Cargo.toml @@ -16,6 +16,7 @@ alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } [build-dependencies] build_helper = { path = "../build_helper" } diff --git a/src/liballoc_system/Cargo.toml b/src/liballoc_system/Cargo.toml index f9a57f7d97a74..936e20a32e10e 100644 --- a/src/liballoc_system/Cargo.toml +++ b/src/liballoc_system/Cargo.toml @@ -13,6 +13,7 @@ doc = false alloc = { path = "../liballoc" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } # See comments in the source for what this dependency is [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml index e0eac41f49ec9..633d273b3b93c 100644 --- a/src/libpanic_abort/Cargo.toml +++ b/src/libpanic_abort/Cargo.toml @@ -12,3 +12,4 @@ doc = false [dependencies] core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libpanic_unwind/Cargo.toml b/src/libpanic_unwind/Cargo.toml index a978ea16e9e74..74aaa4d5ae3db 100644 --- a/src/libpanic_unwind/Cargo.toml +++ b/src/libpanic_unwind/Cargo.toml @@ -14,3 +14,4 @@ alloc = { path = "../liballoc" } core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } unwind = { path = "../libunwind" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml index 04f456917b957..79192fbb6819c 100644 --- a/src/libprofiler_builtins/Cargo.toml +++ b/src/libprofiler_builtins/Cargo.toml @@ -13,6 +13,7 @@ doc = false [dependencies] core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } [build-dependencies] cc = "1.0.1" diff --git a/src/librustc_asan/Cargo.toml b/src/librustc_asan/Cargo.toml index 8f8ef1cc4a011..34d8b75a5bfb3 100644 --- a/src/librustc_asan/Cargo.toml +++ b/src/librustc_asan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/librustc_lsan/Cargo.toml b/src/librustc_lsan/Cargo.toml index 087c316211943..9c19b53742654 100644 --- a/src/librustc_lsan/Cargo.toml +++ b/src/librustc_lsan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/librustc_msan/Cargo.toml b/src/librustc_msan/Cargo.toml index 8d7279b29eb55..17ec2b96438ad 100644 --- a/src/librustc_msan/Cargo.toml +++ b/src/librustc_msan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/librustc_tsan/Cargo.toml b/src/librustc_tsan/Cargo.toml index 7b83985ba6731..8bb67c0bbac5f 100644 --- a/src/librustc_tsan/Cargo.toml +++ b/src/librustc_tsan/Cargo.toml @@ -17,3 +17,4 @@ cmake = "0.1.18" alloc = { path = "../liballoc" } alloc_system = { path = "../liballoc_system" } core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6f6abfdd31e57..f9041ac8546b9 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -373,6 +373,7 @@ extern crate unwind; // compiler-rt intrinsics #[doc(masked)] +#[cfg(stage0)] extern crate compiler_builtins; // During testing, this crate is not actually the "real" std library, but rather diff --git a/src/libstd_unicode/Cargo.toml b/src/libstd_unicode/Cargo.toml index b3346dbe2fb12..283070a0e2cf7 100644 --- a/src/libstd_unicode/Cargo.toml +++ b/src/libstd_unicode/Cargo.toml @@ -15,3 +15,4 @@ path = "tests/lib.rs" [dependencies] core = { path = "../libcore" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8d42206c5ccff..8168db1905876 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -94,7 +94,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap, is_expanded: bool) -> io::Result<()> { let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded); - if is_expanded && !std_inject::injected_crate_name().is_none() { + if is_expanded && std_inject::injected_crate_name().is_some() { // We need to print `#![no_std]` (and its feature gate) so that // compiling pretty-printed source won't inject libstd again. // However we don't want these attributes in the AST because diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 63d7b3336a861..bba7a2d737736 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -44,27 +44,38 @@ thread_local! { } pub fn maybe_inject_crates_ref(mut krate: ast::Crate, alt_std_name: Option<&str>) -> ast::Crate { - let name = if attr::contains_name(&krate.attrs, "no_core") { + // the first name in this list is the crate name of the crate with the prelude + let names: &[&str] = if attr::contains_name(&krate.attrs, "no_core") { return krate; } else if attr::contains_name(&krate.attrs, "no_std") { - "core" + if attr::contains_name(&krate.attrs, "compiler_builtins") { + &["core"] + } else { + &["core", "compiler_builtins"] + } } else { - "std" + &["std"] }; - INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name))); + for name in names { + krate.module.items.insert(0, P(ast::Item { + attrs: vec![attr::mk_attr_outer(DUMMY_SP, + attr::mk_attr_id(), + attr::mk_word_item(ast::Ident::from_str("macro_use")))], + vis: dummy_spanned(ast::VisibilityKind::Inherited), + node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)), + ident: ast::Ident::from_str(name), + id: ast::DUMMY_NODE_ID, + span: DUMMY_SP, + tokens: None, + })); + } - krate.module.items.insert(0, P(ast::Item { - attrs: vec![attr::mk_attr_outer(DUMMY_SP, - attr::mk_attr_id(), - attr::mk_word_item(ast::Ident::from_str("macro_use")))], - vis: dummy_spanned(ast::VisibilityKind::Inherited), - node: ast::ItemKind::ExternCrate(alt_std_name.map(Symbol::intern)), - ident: ast::Ident::from_str(name), - id: ast::DUMMY_NODE_ID, - span: DUMMY_SP, - tokens: None, - })); + // the crates have been injected, the assumption is that the first one is the one with + // the prelude. + let name = names[0]; + + INJECTED_CRATE_NAME.with(|opt_name| opt_name.set(Some(name))); let span = ignored_span(DUMMY_SP); krate.module.items.insert(0, P(ast::Item { diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml index fbd9789d2f52d..4760461df64e3 100644 --- a/src/libunwind/Cargo.toml +++ b/src/libunwind/Cargo.toml @@ -14,3 +14,4 @@ doc = false [dependencies] core = { path = "../libcore" } libc = { path = "../rustc/libc_shim" } +compiler_builtins = { path = "../rustc/compiler_builtins_shim" } diff --git a/src/rustc/dlmalloc_shim/Cargo.toml b/src/rustc/dlmalloc_shim/Cargo.toml index cf8440c40da1a..d2fe159d80673 100644 --- a/src/rustc/dlmalloc_shim/Cargo.toml +++ b/src/rustc/dlmalloc_shim/Cargo.toml @@ -11,4 +11,5 @@ doc = false [dependencies] core = { path = "../../libcore" } +compiler_builtins = { path = "../../rustc/compiler_builtins_shim" } alloc = { path = "../../liballoc" } diff --git a/src/rustc/libc_shim/Cargo.toml b/src/rustc/libc_shim/Cargo.toml index 0c04402124a2d..e77897d643313 100644 --- a/src/rustc/libc_shim/Cargo.toml +++ b/src/rustc/libc_shim/Cargo.toml @@ -29,6 +29,8 @@ doc = false # # See https://github.com/rust-lang/rfcs/pull/1133. core = { path = "../../libcore" } +compiler_builtins = { path = "../compiler_builtins_shim" } + [features] # Certain parts of libc are conditionally compiled differently than when used