From 49ee9f3f08ba4583bc722a663e43551067ace271 Mon Sep 17 00:00:00 2001 From: lukaramu Date: Thu, 24 Aug 2017 17:33:36 +0200 Subject: [PATCH 01/15] Fix inconsistent doc headings This fixes headings reading "Unsafety" and "Example", they should be "Safety" and "Examples" according to RFC 1574. --- src/liballoc/allocator.rs | 24 ++++++++++++------------ src/liballoc/boxed.rs | 2 +- src/liballoc/slice.rs | 18 +++++++++--------- src/liballoc/str.rs | 2 +- src/libcore/cell.rs | 4 ++-- src/libcore/fmt/builders.rs | 10 +++++----- src/libcore/mem.rs | 2 +- src/libstd/io/mod.rs | 4 ++-- src/libstd/memchr.rs | 4 ++-- src/libstd/sys/redox/ext/mod.rs | 2 +- src/libstd/sys/unix/ext/mod.rs | 2 +- src/libstd/thread/mod.rs | 2 +- 12 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/liballoc/allocator.rs b/src/liballoc/allocator.rs index fc6585a9f951d..f14f27023249e 100644 --- a/src/liballoc/allocator.rs +++ b/src/liballoc/allocator.rs @@ -110,7 +110,7 @@ impl Layout { /// Creates a layout, bypassing all checks. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe as it does not verify that `align` is /// a power-of-two that is also less than or equal to 2^31, nor @@ -485,7 +485,7 @@ pub unsafe trait Alloc { /// behavior, e.g. to ensure initialization to particular sets of /// bit patterns.) /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure that `layout` has non-zero size. @@ -513,7 +513,7 @@ pub unsafe trait Alloc { /// Deallocate the memory referenced by `ptr`. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure all of the following: @@ -617,7 +617,7 @@ pub unsafe trait Alloc { /// behavior is well-defined (though underspecified) when this /// constraint is violated; further discussion below. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure all of the following: @@ -688,7 +688,7 @@ pub unsafe trait Alloc { /// Behaves like `alloc`, but also ensures that the contents /// are set to zero before being returned. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe for the same reasons that `alloc` is. /// @@ -714,7 +714,7 @@ pub unsafe trait Alloc { /// the returned block. For some `layout` inputs, like arrays, this /// may include extra storage usable for additional data. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe for the same reasons that `alloc` is. /// @@ -736,7 +736,7 @@ pub unsafe trait Alloc { /// the returned block. For some `layout` inputs, like arrays, this /// may include extra storage usable for additional data. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe for the same reasons that `realloc` is. /// @@ -770,7 +770,7 @@ pub unsafe trait Alloc { /// memory block referenced by `ptr` has not been transferred, and /// the contents of the memory block are unaltered. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure all of the following: @@ -827,7 +827,7 @@ pub unsafe trait Alloc { /// the memory block has not been transferred, and the contents of /// the memory block are unaltered. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure all of the following: @@ -920,7 +920,7 @@ pub unsafe trait Alloc { /// /// Captures a common usage pattern for allocators. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure both: @@ -993,7 +993,7 @@ pub unsafe trait Alloc { /// The returned block is suitable for passing to the /// `alloc`/`realloc` methods of this allocator. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure all of the following: @@ -1037,7 +1037,7 @@ pub unsafe trait Alloc { /// /// Captures a common usage pattern for allocators. /// - /// # Unsafety + /// # Safety /// /// This function is unsafe because undefined behavior can result /// if the caller does not ensure both: diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index c0d43d9c52755..82aac4dbf6334 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -633,7 +633,7 @@ impl FusedIterator for Box {} /// that `FnBox` may be deprecated in the future if `Box` /// closures become directly usable.) /// -/// ### Example +/// # Examples /// /// Here is a snippet of code which creates a hashmap full of boxed /// once closures and then removes them one by one, calling each diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 356ca7a5f5e0c..fd60e8aaded48 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -171,7 +171,7 @@ mod hack { impl [T] { /// Returns the number of elements in the slice. /// - /// # Example + /// # Examples /// /// ``` /// let a = [1, 2, 3]; @@ -185,7 +185,7 @@ impl [T] { /// Returns `true` if the slice has a length of 0. /// - /// # Example + /// # Examples /// /// ``` /// let a = [1, 2, 3]; @@ -523,7 +523,7 @@ impl [T] { /// Reverses the order of elements in the slice, in place. /// - /// # Example + /// # Examples /// /// ``` /// let mut v = [1, 2, 3]; @@ -580,7 +580,7 @@ impl [T] { /// /// Panics if `size` is 0. /// - /// # Example + /// # Examples /// /// ``` /// let slice = ['r', 'u', 's', 't']; @@ -613,7 +613,7 @@ impl [T] { /// /// Panics if `size` is 0. /// - /// # Example + /// # Examples /// /// ``` /// let slice = ['l', 'o', 'r', 'e', 'm']; @@ -1040,7 +1040,7 @@ impl [T] { /// `Err` is returned, containing the index where a matching /// element could be inserted while maintaining sorted order. /// - /// # Example + /// # Examples /// /// Looks up a series of four elements. The first is found, with a /// uniquely determined position; the second and third are not @@ -1074,7 +1074,7 @@ impl [T] { /// `Err` is returned, containing the index where a matching /// element could be inserted while maintaining sorted order. /// - /// # Example + /// # Examples /// /// Looks up a series of four elements. The first is found, with a /// uniquely determined position; the second and third are not @@ -1419,7 +1419,7 @@ impl [T] { /// /// This function will panic if the two slices have different lengths. /// - /// # Example + /// # Examples /// /// ``` /// let mut dst = [0, 0, 0]; @@ -1445,7 +1445,7 @@ impl [T] { /// /// This function will panic if the two slices have different lengths. /// - /// # Example + /// # Examples /// /// ``` /// let mut dst = [0, 0, 0]; diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 80317cd763b5c..79b2bbce2af7c 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -1714,7 +1714,7 @@ impl str { /// /// [`Err`]: str/trait.FromStr.html#associatedtype.Err /// - /// # Example + /// # Examples /// /// Basic usage /// diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index dc0905e297251..e0a3b8d52f40e 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -998,7 +998,7 @@ impl<'b, T: ?Sized> Ref<'b, T> { /// A method would interfere with methods of the same name on the contents /// of a `RefCell` used through `Deref`. /// - /// # Example + /// # Examples /// /// ``` /// use std::cell::{RefCell, Ref}; @@ -1040,7 +1040,7 @@ impl<'b, T: ?Sized> RefMut<'b, T> { /// `RefMut::map(...)`. A method would interfere with methods of the same /// name on the contents of a `RefCell` used through `Deref`. /// - /// # Example + /// # Examples /// /// ``` /// use std::cell::{RefCell, RefMut}; diff --git a/src/libcore/fmt/builders.rs b/src/libcore/fmt/builders.rs index 8125097d7d105..b594c886b64f5 100644 --- a/src/libcore/fmt/builders.rs +++ b/src/libcore/fmt/builders.rs @@ -58,7 +58,7 @@ impl<'a, 'b: 'a> fmt::Write for PadAdapter<'a, 'b> { /// [`Formatter::debug_struct`](struct.Formatter.html#method.debug_struct) /// method. /// -/// # Example +/// # Examples /// /// ``` /// use std::fmt; @@ -153,7 +153,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> { /// [`Formatter::debug_tuple`](struct.Formatter.html#method.debug_tuple) /// method. /// -/// # Example +/// # Examples /// /// ``` /// use std::fmt; @@ -290,7 +290,7 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> { /// [`Formatter::debug_set`](struct.Formatter.html#method.debug_set) /// method. /// -/// # Example +/// # Examples /// /// ``` /// use std::fmt; @@ -361,7 +361,7 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> { /// [`Formatter::debug_list`](struct.Formatter.html#method.debug_list) /// method. /// -/// # Example +/// # Examples /// /// ``` /// use std::fmt; @@ -432,7 +432,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> { /// [`Formatter::debug_map`](struct.Formatter.html#method.debug_map) /// method. /// -/// # Example +/// # Examples /// /// ``` /// use std::fmt; diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 6f7adbe1e7a0e..4b866cab1eae2 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -901,7 +901,7 @@ impl ManuallyDrop { /// Manually drops the contained value. /// - /// # Unsafety + /// # Safety /// /// This function runs the destructor of the contained value and thus the wrapped value /// now represents uninitialized data. It is up to the user of this method to ensure the diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 0fff833e7d83e..074ab3ebd8fdc 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -522,7 +522,7 @@ pub trait Read { /// `Read`er - the method only takes `&self` so that it can be used through /// trait objects. /// - /// # Unsafety + /// # Safety /// /// This method is unsafe because a `Read`er could otherwise return a /// non-zeroing `Initializer` from another `Read` type without an `unsafe` @@ -903,7 +903,7 @@ impl Initializer { /// Returns a new `Initializer` which will not zero out buffers. /// - /// # Unsafety + /// # Safety /// /// This may only be called by `Read`ers which guarantee that they will not /// read from buffers passed to `Read` methods, and that the return value of diff --git a/src/libstd/memchr.rs b/src/libstd/memchr.rs index 98642f86f4dc2..240e82069ff4d 100644 --- a/src/libstd/memchr.rs +++ b/src/libstd/memchr.rs @@ -20,7 +20,7 @@ /// magnitude faster than `haystack.iter().position(|&b| b == needle)`. /// (See benchmarks.) /// -/// # Example +/// # Examples /// /// This shows how to find the first position of a byte in a byte string. /// @@ -40,7 +40,7 @@ pub fn memchr(needle: u8, haystack: &[u8]) -> Option { /// Returns the index corresponding to the last occurrence of `needle` in /// `haystack`, or `None` if one is not found. /// -/// # Example +/// # Examples /// /// This shows how to find the last position of a byte in a byte string. /// diff --git a/src/libstd/sys/redox/ext/mod.rs b/src/libstd/sys/redox/ext/mod.rs index 259cda5bcb3eb..9fd8d6c91869c 100644 --- a/src/libstd/sys/redox/ext/mod.rs +++ b/src/libstd/sys/redox/ext/mod.rs @@ -13,7 +13,7 @@ //! For now, this module is limited to extracting file descriptors, //! but its functionality will grow over time. //! -//! # Example +//! # Examples //! //! ```no_run //! use std::fs::File; diff --git a/src/libstd/sys/unix/ext/mod.rs b/src/libstd/sys/unix/ext/mod.rs index 67fe46cc9c7a2..98bc90dd4e132 100644 --- a/src/libstd/sys/unix/ext/mod.rs +++ b/src/libstd/sys/unix/ext/mod.rs @@ -13,7 +13,7 @@ //! For now, this module is limited to extracting file descriptors, //! but its functionality will grow over time. //! -//! # Example +//! # Examples //! //! ```no_run //! use std::fs::File; diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index ee103c803f542..6354e746af26a 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -807,7 +807,7 @@ pub fn park_timeout_ms(ms: u32) { /// Platforms which do not support nanosecond precision for sleeping will have /// `dur` rounded up to the nearest granularity of time they can sleep for. /// -/// # Example +/// # Examples /// /// Waiting for the complete expiration of the timeout: /// From 8cd4cacbc797cf3ab5024bc819c228cd264aa82e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 24 Aug 2017 23:25:35 +0200 Subject: [PATCH 02/15] include Cargo.{toml,lock} in rust-src tarball --- src/bootstrap/dist.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index bfcfb5f9a37f8..8d3fc0669822e 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -724,6 +724,10 @@ impl Step for Src { let dst_src = dst.join("rust"); t!(fs::create_dir_all(&dst_src)); + let src_files = [ + "src/Cargo.toml", + "src/Cargo.lock", + ]; // This is the reduced set of paths which will become the rust-src component // (essentially libstd and all of its path dependencies) let std_src_dirs = [ @@ -759,6 +763,9 @@ impl Step for Src { ]; copy_src_dirs(build, &std_src_dirs[..], &std_src_dirs_exclude[..], &dst_src); + for file in src_files.iter() { + copy(&build.src.join(file), &dst_src.join(file)); + } // Create source tarball in rust-installer format let mut cmd = rust_installer(builder); From b8d8dc3c23a8d364672bfd25330e17885273b1bc Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 25 Aug 2017 16:08:03 +0200 Subject: [PATCH 03/15] Fix #43457 (and avoid some unneeded lookups to boot, woo). --- src/librustc_mir/hair/cx/block.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 0324552cd56fd..61d128fc84782 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -22,10 +22,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { // We have to eagerly translate the "spine" of the statements // in order to get the lexical scoping correctly. let stmts = mirror_stmts(cx, self.id, &*self.stmts); - let opt_def_id = cx.tcx.hir.opt_local_def_id(self.id); - let opt_destruction_extent = opt_def_id.and_then(|def_id| { - cx.tcx.region_maps(def_id).opt_destruction_extent(self.id) - }); + let opt_destruction_extent = cx.region_maps.opt_destruction_extent(self.id); Block { targeted_by_break: self.targeted_by_break, extent: CodeExtent::Misc(self.id), @@ -42,11 +39,8 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, stmts: &'tcx [hir::Stmt]) -> Vec> { let mut result = vec![]; - let opt_def_id = cx.tcx.hir.opt_local_def_id(block_id); for (index, stmt) in stmts.iter().enumerate() { - let opt_dxn_ext = opt_def_id.and_then(|def_id| { - cx.tcx.region_maps(def_id).opt_destruction_extent(stmt.node.id()) - }); + let opt_dxn_ext = cx.region_maps.opt_destruction_extent(stmt.node.id()); match stmt.node { hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) => { From d1a15cdfb119b42e5333a56f0345d657d7cbd60d Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 25 Aug 2017 16:35:42 +0200 Subject: [PATCH 04/15] Regression test. --- src/test/mir-opt/issue-43457.rs | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/test/mir-opt/issue-43457.rs diff --git a/src/test/mir-opt/issue-43457.rs b/src/test/mir-opt/issue-43457.rs new file mode 100644 index 0000000000000..708784df317a6 --- /dev/null +++ b/src/test/mir-opt/issue-43457.rs @@ -0,0 +1,55 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z identify_regions -Z span_free_formats +// ignore-tidy-linelength + +// Regression test for #43457: an `EndRegion` was missing from output +// because compiler was using a faulty means for region map lookup. + +use std::cell::RefCell; + +fn rc_refcell_test(r: RefCell) { + r.borrow_mut(); +} + +fn main() { } + +// END RUST SOURCE +// START rustc.node5.SimplifyCfg-qualify-consts.after.mir +// +// fn rc_refcell_test(_1: std::cell::RefCell) -> () { +// let mut _0: (); +// scope 1 { +// let _2: std::cell::RefCell; +// } +// let mut _3: std::cell::RefMut<'17dce, i32>; +// let mut _4: &'17dce std::cell::RefCell; +// +// bb0: { +// StorageLive(_2); +// _2 = _1; +// StorageLive(_4); +// _4 = &'17dce _2; +// _3 = const >::borrow_mut(_4) -> bb1; +// } +// +// bb1: { +// drop(_3) -> bb2; +// } +// +// bb2: { +// StorageDead(_4); +// EndRegion('17dce); +// _0 = (); +// StorageDead(_2); +// return; +// } +// } From e13f02eb2e188a3d8c2a5f7ba20823a85ab14307 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 25 Aug 2017 10:10:27 -0700 Subject: [PATCH 05/15] rustbuild: Automatically enable Ninja on MSVC Discovered in #43767 it turns out the default MSBuild generator in CMake for whatever reason isn't supporting many of the configuration options we give to LLVM. To improve the contributor experience automatically enable Ninja if we find it to ensure that "flavorful" configurations of LLVM work by default in more situations. Closes #43767 --- src/bootstrap/sanity.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index a64a6130929cb..54208d8bb57a6 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -93,10 +93,27 @@ pub fn check(build: &mut Build) { } // Ninja is currently only used for LLVM itself. - // Some Linux distros rename `ninja` to `ninja-build`. - // CMake can work with either binary name. - if building_llvm && build.config.ninja && cmd_finder.maybe_have("ninja-build").is_none() { - cmd_finder.must_have("ninja"); + if building_llvm { + if build.config.ninja { + // Some Linux distros rename `ninja` to `ninja-build`. + // CMake can work with either binary name. + if cmd_finder.maybe_have("ninja-build").is_none() { + cmd_finder.must_have("ninja"); + } + } + + // If ninja isn't enabled but we're building for MSVC then we try + // doubly hard to enable it. It was realized in #43767 that the msbuild + // CMake generator for MSVC doesn't respect configuration options like + // disabling LLVM assertions, which can often be quite important! + // + // In these cases we automatically enable Ninja if we find it in the + // environment. + if !build.config.ninja && build.config.build.contains("msvc") { + if cmd_finder.maybe_have("ninja").is_some() { + build.config.ninja = true; + } + } } build.config.python = build.config.python.take().map(|p| cmd_finder.must_have(p)) From 6a721317ff0621a97690dc573ced88274d860e84 Mon Sep 17 00:00:00 2001 From: kennytm Date: Fri, 25 Aug 2017 23:27:42 +0800 Subject: [PATCH 06/15] Allow htmldocck to run using Python 3. --- src/etc/htmldocck.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index a5449b748dd5e..7e8fde2034640 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -29,7 +29,7 @@ In order to avoid one-off dependencies for this task, this script uses a reasonably working HTML parser and the existing XPath implementation -from Python 2's standard library. Hopefully we won't render +from Python's standard library. Hopefully we won't render non-well-formed HTML. # Commands @@ -110,11 +110,17 @@ import re import shlex from collections import namedtuple -from HTMLParser import HTMLParser +try: + from html.parser import HTMLParser +except ImportError: + from HTMLParser import HTMLParser from xml.etree import cElementTree as ET # ⇤/⇥ are not in HTML 4 but are in HTML 5 -from htmlentitydefs import entitydefs +try: + from html.entities import entitydefs +except ImportError: + from htmlentitydefs import entitydefs entitydefs['larrb'] = u'\u21e4' entitydefs['rarrb'] = u'\u21e5' entitydefs['nbsp'] = ' ' @@ -123,6 +129,11 @@ VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr']) +# Python 2 -> 3 compatibility +try: + unichr +except NameError: + unichr = chr class CustomHTMLParser(HTMLParser): """simplified HTML parser. @@ -184,12 +195,8 @@ def concat_multi_lines(f): # strip the common prefix from the current line if needed if lastline is not None: - maxprefix = 0 - for i in xrange(min(len(line), len(lastline))): - if line[i] != lastline[i]: - break - maxprefix += 1 - line = line[maxprefix:].lstrip() + common_prefix = os.path.commonprefix([line, lastline]) + line = line[len(common_prefix):].lstrip() firstlineno = firstlineno or lineno if line.endswith('\\'): @@ -213,7 +220,7 @@ def concat_multi_lines(f): def get_commands(template): - with open(template, 'rUb') as f: + with open(template, 'rU') as f: for lineno, line in concat_multi_lines(f): m = LINE_PATTERN.search(line) if not m: @@ -372,7 +379,7 @@ def check_command(c, cache): cache.get_file(c.args[0]) ret = True except FailedCheck as err: - cerr = err.message + cerr = str(err) ret = False elif len(c.args) == 2: # @has/matches = string test cerr = "`PATTERN` did not match" @@ -413,9 +420,9 @@ def check_command(c, cache): except FailedCheck as err: message = '@{}{} check failed'.format('!' if c.negated else '', c.cmd) - print_err(c.lineno, c.context, err.message, message) + print_err(c.lineno, c.context, str(err), message) except InvalidCheck as err: - print_err(c.lineno, c.context, err.message) + print_err(c.lineno, c.context, str(err)) def check(target, commands): cache = CachedFiles(target) From 5a71e1235137fdcdef124b3af914ef06a24d65c4 Mon Sep 17 00:00:00 2001 From: est31 Date: Fri, 25 Aug 2017 12:25:22 +0200 Subject: [PATCH 07/15] Fix a byte/char confusion issue in the error emitter Fixes #44078. Fixes #44023. The start_col member is given in chars, while the code previously assumed it was given in bytes. The more basic issue #44080 doesn't get fixed. --- src/librustc_errors/emitter.rs | 4 +++- src/test/ui/issue-44023.rs | 16 ++++++++++++++++ src/test/ui/issue-44023.stderr | 13 +++++++++++++ src/test/ui/issue-44078.rs | 13 +++++++++++++ src/test/ui/issue-44078.stderr | 10 ++++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issue-44023.rs create mode 100644 src/test/ui/issue-44023.stderr create mode 100644 src/test/ui/issue-44078.rs create mode 100644 src/test/ui/issue-44078.stderr diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 3b1414ef83a69..53d90531cc946 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -311,7 +311,9 @@ impl EmitterWriter { if line.annotations.len() == 1 { if let Some(ref ann) = line.annotations.get(0) { if let AnnotationType::MultilineStart(depth) = ann.annotation_type { - if source_string[0..ann.start_col].trim() == "" { + if source_string.chars() + .take(ann.start_col) + .all(|c| c.is_whitespace()) { let style = if ann.is_primary { Style::UnderlinePrimary } else { diff --git a/src/test/ui/issue-44023.rs b/src/test/ui/issue-44023.rs new file mode 100644 index 0000000000000..295d480828930 --- /dev/null +++ b/src/test/ui/issue-44023.rs @@ -0,0 +1,16 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(non_ascii_idents)] + +pub fn main () {} + +fn საჭმელად_გემრიელი_სადილი ( ) -> isize { +} diff --git a/src/test/ui/issue-44023.stderr b/src/test/ui/issue-44023.stderr new file mode 100644 index 0000000000000..a17512ba4abc4 --- /dev/null +++ b/src/test/ui/issue-44023.stderr @@ -0,0 +1,13 @@ +error[E0308]: mismatched types + --> $DIR/issue-44023.rs:15:42 + | +15 | fn საჭმელად_გემრიელი_სადილი ( ) -> isize { + | __________________________________________^ +16 | | } + | |_^ expected isize, found () + | + = note: expected type `isize` + found type `()` + +error: aborting due to previous error + diff --git a/src/test/ui/issue-44078.rs b/src/test/ui/issue-44078.rs new file mode 100644 index 0000000000000..ef47214f2b393 --- /dev/null +++ b/src/test/ui/issue-44078.rs @@ -0,0 +1,13 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + "😊""; +} diff --git a/src/test/ui/issue-44078.stderr b/src/test/ui/issue-44078.stderr new file mode 100644 index 0000000000000..389f3b2479aa4 --- /dev/null +++ b/src/test/ui/issue-44078.stderr @@ -0,0 +1,10 @@ +error: unterminated double quote string + --> $DIR/issue-44078.rs:12:8 + | +12 | "😊""; + | ________^ +13 | | } + | |__^ + +error: aborting due to previous error + From 0a6c724ddedf10e60b6fff76a9347cabf1807c04 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 25 Aug 2017 23:09:00 +0200 Subject: [PATCH 08/15] Add missing link in string doc --- src/liballoc/string.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 96bd6273c9484..b1919c7c968c9 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -82,7 +82,7 @@ use boxed::Box; /// /// # Examples /// -/// You can create a `String` from a literal string with `String::from`: +/// You can create a `String` from a literal string with [`String::from`]: /// /// ``` /// let hello = String::from("Hello, world!"); @@ -98,6 +98,7 @@ use boxed::Box; /// hello.push_str("orld!"); /// ``` /// +/// [`String::from`]: #method.from /// [`char`]: ../../std/primitive.char.html /// [`push`]: #method.push /// [`push_str`]: #method.push_str From 6ca124bc9e6756d0f7ea2c7790251aaf531f75e4 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Fri, 25 Aug 2017 17:12:20 -0500 Subject: [PATCH 09/15] haiku/librustc_back: Remove incorrect no_integrated_as * Makes rust bootstrap incorrectly search for xxx.s vs xxx.0.s * Not needed or incorrect fix for another issue. --- src/librustc_back/target/haiku_base.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustc_back/target/haiku_base.rs b/src/librustc_back/target/haiku_base.rs index 21410dcd41264..112f424f7a8bb 100644 --- a/src/librustc_back/target/haiku_base.rs +++ b/src/librustc_back/target/haiku_base.rs @@ -20,7 +20,6 @@ pub fn opts() -> TargetOptions { target_family: Some("unix".to_string()), relro_level: RelroLevel::Full, linker_is_gnu: true, - no_integrated_as: true, .. Default::default() } } From 898be21a5a0b5b6b20fe2ed55fd297a907d8b6cc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Aug 2017 12:52:22 -0700 Subject: [PATCH 10/15] rustc_errors: Add the ability to delay as bugs This adds a function to `DiagnosticBuilder` to delay the entire diagnostic as a bug to be emitted at a later time. This'll end up getting used in the compiler in the subsequent commits... --- src/librustc_errors/diagnostic_builder.rs | 22 ++++++++++++++++++++-- src/librustc_errors/lib.rs | 16 ++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index 0a8119893509c..2c8d8b4691f0a 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -110,6 +110,22 @@ impl<'a> DiagnosticBuilder<'a> { // } } + /// Delay emission of this diagnostic as a bug. + /// + /// This can be useful in contexts where an error indicates a bug but + /// typically this only happens when other compilation errors have already + /// happened. In those cases this can be used to defer emission of this + /// diagnostic as a bug in the compiler only if no other errors have been + /// emitted. + /// + /// In the meantime, though, callsites are required to deal with the "bug" + /// locally in whichever way makes the most sense. + pub fn delay_as_bug(&mut self) { + self.level = Level::Bug; + *self.handler.delayed_span_bug.borrow_mut() = Some(self.diagnostic.clone()); + self.cancel(); + } + /// Add a span/label to be included in the resulting snippet. /// This is pushed onto the `MultiSpan` that was created when the /// diagnostic was first built. If you don't call this function at @@ -182,8 +198,10 @@ impl<'a> DiagnosticBuilder<'a> { DiagnosticBuilder::new_diagnostic(handler, diagnostic) } - /// Creates a new `DiagnosticBuilder` with an already constructed diagnostic. - pub fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) -> DiagnosticBuilder<'a> { + /// Creates a new `DiagnosticBuilder` with an already constructed + /// diagnostic. + pub fn new_diagnostic(handler: &'a Handler, diagnostic: Diagnostic) + -> DiagnosticBuilder<'a> { DiagnosticBuilder { handler, diagnostic } } } diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index 02cb1ede2b115..2f5aac65b923d 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -272,7 +272,7 @@ pub struct Handler { pub can_emit_warnings: bool, treat_err_as_bug: bool, continue_after_error: Cell, - delayed_span_bug: RefCell>, + delayed_span_bug: RefCell>, tracked_diagnostics: RefCell>>, } @@ -439,8 +439,9 @@ impl Handler { if self.treat_err_as_bug { self.span_bug(sp, msg); } - let mut delayed = self.delayed_span_bug.borrow_mut(); - *delayed = Some((sp.into(), msg.to_string())); + let mut diagnostic = Diagnostic::new(Level::Bug, msg); + diagnostic.set_span(sp.into()); + *self.delayed_span_bug.borrow_mut() = Some(diagnostic); } pub fn span_bug_no_panic>(&self, sp: S, msg: &str) { self.emit(&sp.into(), msg, Bug); @@ -507,14 +508,9 @@ impl Handler { let s; match self.err_count.get() { 0 => { - let delayed_bug = self.delayed_span_bug.borrow(); - match *delayed_bug { - Some((ref span, ref errmsg)) => { - self.span_bug(span.clone(), errmsg); - } - _ => {} + if let Some(bug) = self.delayed_span_bug.borrow_mut().take() { + DiagnosticBuilder::new_diagnostic(self, bug).emit(); } - return; } 1 => s = "aborting due to previous error".to_string(), From 05051fb6ae2f632bd1e17dcf3c83884dfe0a57a7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Aug 2017 12:53:29 -0700 Subject: [PATCH 11/15] rustc: Change the return of a query's `try_get` This alters the return value of the `try_get` function so the error contains a diagnostic rather than a `CycleError`. This way consumers are forced to take *some* action (else they get a bug to an un-emitted diagnostic). This action could be to emit the error itself, or in some cases delay the diagnostic as a bug and continue. --- src/librustc/ty/maps.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index f1c624a94e307..18202c96cf52b 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use errors::DiagnosticBuilder; use dep_graph::{DepConstructor, DepNode, DepNodeIndex}; use errors::{Diagnostic, DiagnosticBuilder}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; @@ -218,7 +219,9 @@ pub struct CycleError<'a, 'tcx: 'a> { } impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { - pub fn report_cycle(self, CycleError { span, cycle }: CycleError) { + pub fn report_cycle(self, CycleError { span, cycle }: CycleError) + -> DiagnosticBuilder<'a> + { // Subtle: release the refcell lock before invoking `describe()` // below by dropping `cycle`. let stack = cycle.to_vec(); @@ -247,8 +250,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { err.note(&format!("...which then again requires {}, completing the cycle.", stack[0].1.describe(self))); - err.emit(); - }); + return err + }) } fn cycle_check(self, span: Span, query: Query<'gcx>, compute: F) @@ -704,8 +707,11 @@ macro_rules! define_maps { } pub fn try_get(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) - -> Result<$V, CycleError<'a, $tcx>> { - Self::try_get_with(tcx, span, key, Clone::clone) + -> Result<$V, DiagnosticBuilder<'a>> { + match Self::try_get_with(tcx, span, key, Clone::clone) { + Ok(e) => Ok(e), + Err(e) => Err(tcx.report_cycle(e)), + } } pub fn force(tcx: TyCtxt<'a, $tcx, 'lcx>, span: Span, key: $K) { @@ -714,7 +720,7 @@ macro_rules! define_maps { match Self::try_get_with(tcx, span, key, |_| ()) { Ok(()) => {} - Err(e) => tcx.report_cycle(e) + Err(e) => tcx.report_cycle(e).emit(), } } })* @@ -751,8 +757,8 @@ macro_rules! define_maps { impl<'a, $tcx, 'lcx> TyCtxtAt<'a, $tcx, 'lcx> { $($(#[$attr])* pub fn $name(self, key: $K) -> $V { - queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|e| { - self.report_cycle(e); + queries::$name::try_get(self.tcx, self.span, key).unwrap_or_else(|mut e| { + e.emit(); Value::from_cycle_error(self.global_tcx()) }) })* From 9ab94466a2443edeb8bc8c0946d278f87b186c86 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 23 Aug 2017 12:54:36 -0700 Subject: [PATCH 12/15] rustc: Fix two instances of `try_get` The `sized_constraint` and `needs_drop_raw` queries both use `try_get` to detect cycles, but in both of these cases the cycle indicates an error has happened elsewhere in compilation. In these cases we can just delay the diagnostic to get emitted as a bug later if we ended up forgetting to emit the error diagnostic. --- src/librustc/ty/mod.rs | 7 +++++-- src/librustc/ty/util.rs | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index f9bbcc1bbe086..852bd48a5eeed 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1684,12 +1684,15 @@ impl<'a, 'gcx, 'tcx> AdtDef { pub fn sized_constraint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> &'tcx [Ty<'tcx>] { match queries::adt_sized_constraint::try_get(tcx, DUMMY_SP, self.did) { Ok(tys) => tys, - Err(_) => { + Err(mut bug) => { debug!("adt_sized_constraint: {:?} is recursive", self); // This should be reported as an error by `check_representable`. // // Consider the type as Sized in the meanwhile to avoid - // further errors. + // further errors. Delay our `bug` diagnostic here to get + // emitted later as well in case we accidentally otherwise don't + // emit an error. + bug.delay_as_bug(); tcx.intern_type_list(&[tcx.types.err]) } } diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 9cd6aa2111873..bbbb8611f98a5 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -1069,11 +1069,15 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let needs_drop = |ty: Ty<'tcx>| -> bool { match ty::queries::needs_drop_raw::try_get(tcx, DUMMY_SP, param_env.and(ty)) { Ok(v) => v, - Err(_) => { + Err(mut bug) => { // Cycles should be reported as an error by `check_representable`. // - // Consider the type as not needing drop in the meanwhile to avoid - // further errors. + // Consider the type as not needing drop in the meanwhile to + // avoid further errors. + // + // In case we forgot to emit a bug elsewhere, delay our + // diagnostic to get emitted as a compiler bug. + bug.delay_as_bug(); false } } From 1cc87fded8e86400c39d39e939f49bfa33853998 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 24 Aug 2017 07:00:44 -0700 Subject: [PATCH 13/15] rustc: Add a FIXME for `try_get` in MIR inlining It sounds like this is being handled elsewhere, so for now just preserve the existing behavior of ignoring th error. --- src/librustc_mir/transform/inline.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 28aedc8d67497..53b46dd2683fc 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -115,8 +115,13 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { Ok(ref callee_mir) if self.should_inline(callsite, callee_mir) => { callee_mir.subst(self.tcx, callsite.substs) } + Ok(_) => continue, - _ => continue, + Err(mut bug) => { + // FIXME(#43542) shouldn't have to cancel an error + bug.cancel(); + continue + } }; let start = caller_mir.basic_blocks().len(); From b43afc7ad153ad489d8051b19059ba4e62b96add Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 24 Aug 2017 07:37:09 -0700 Subject: [PATCH 14/15] rustc: Skip cyclic checks in `item_path` This seems like it may be likely to cause bugs with `RUST_LOG` and other "interesting" scenarios, but it removes the usage of `try_get` for now! --- src/librustc/ty/item_path.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 76a20ed8f3023..5caf513981280 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -13,7 +13,6 @@ use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use ty::{self, Ty, TyCtxt}; use syntax::ast; use syntax::symbol::Symbol; -use syntax_pos::DUMMY_SP; use std::cell::Cell; @@ -222,11 +221,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let use_types = !self.is_default_impl(impl_def_id) && (!impl_def_id.is_local() || { // Otherwise, use filename/line-number if forced. let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get()); - !force_no_types && { - // Otherwise, use types if we can query them without inducing a cycle. - ty::queries::impl_trait_ref::try_get(self, DUMMY_SP, impl_def_id).is_ok() && - ty::queries::type_of::try_get(self, DUMMY_SP, impl_def_id).is_ok() - } + !force_no_types }); if !use_types { From 1f43ed43045e4929f50f69c68164434abdbdc532 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 24 Aug 2017 15:13:55 -0700 Subject: [PATCH 15/15] rustc: Make `report_cycle` and `CycleError` private --- src/librustc/ty/maps.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 18202c96cf52b..042ec49b0bda1 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use errors::DiagnosticBuilder; use dep_graph::{DepConstructor, DepNode, DepNodeIndex}; use errors::{Diagnostic, DiagnosticBuilder}; use hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; @@ -213,13 +212,13 @@ impl QueryMap { } } -pub struct CycleError<'a, 'tcx: 'a> { +struct CycleError<'a, 'tcx: 'a> { span: Span, cycle: RefMut<'a, [(Span, Query<'tcx>)]>, } impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { - pub fn report_cycle(self, CycleError { span, cycle }: CycleError) + fn report_cycle(self, CycleError { span, cycle }: CycleError) -> DiagnosticBuilder<'a> { // Subtle: release the refcell lock before invoking `describe()`