Skip to content

Commit

Permalink
Auto merge of #47962 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

- Successful merges: #46156, #47829, #47842, #47898, #47914, #47916, #47919, #47942, #47951, #47973
- Failed merges: #47753
  • Loading branch information
bors committed Feb 3, 2018
2 parents 6c15dff + 3a0a423 commit 8d04b8f
Show file tree
Hide file tree
Showing 19 changed files with 157 additions and 70 deletions.
21 changes: 8 additions & 13 deletions src/doc/unstable-book/src/language-features/lang-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,23 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
p
}
#[lang = "exchange_free"]
unsafe fn deallocate(ptr: *mut u8, _size: usize, _align: usize) {
libc::free(ptr as *mut libc::c_void)
}
#[lang = "box_free"]
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
deallocate(ptr as *mut u8, ::core::mem::size_of_val(&*ptr), ::core::mem::align_of_val(&*ptr));
libc::free(ptr as *mut libc::c_void)
}
#[start]
fn main(argc: isize, argv: *const *const u8) -> isize {
let x = box 1;
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let _x = box 1;
0
}
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } }
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
#[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
#[no_mangle] pub extern fn rust_eh_register_frames () {}
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}
```

Note the use of `abort`: the `exchange_malloc` lang item is assumed to
Expand All @@ -80,7 +75,7 @@ Other features provided by lang items include:

Lang items are loaded lazily by the compiler; e.g. if one never uses
`Box` then there is no need to define functions for `exchange_malloc`
and `exchange_free`. `rustc` will emit an error when an item is needed
and `box_free`. `rustc` will emit an error when an item is needed
but not found in the current crate or any that it depends on.

Most lang items are defined by `libcore`, but if you're trying to build
Expand Down Expand Up @@ -318,4 +313,4 @@ the source code.
- `phantom_data`: `libcore/marker.rs`
- `freeze`: `libcore/marker.rs`
- `debug_trait`: `libcore/fmt/mod.rs`
- `non_zero`: `libcore/nonzero.rs`
- `non_zero`: `libcore/nonzero.rs`
2 changes: 1 addition & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ extern "rust-intrinsic" {
/// ptr::copy_nonoverlapping(y, x, 1);
/// ptr::copy_nonoverlapping(&t, y, 1);
///
/// // y and t now point to the same thing, but we need to completely forget `tmp`
/// // y and t now point to the same thing, but we need to completely forget `t`
/// // because it's no longer relevant.
/// mem::forget(t);
/// }
Expand Down
1 change: 1 addition & 0 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ pub fn forget<T>(t: T) {
/// Type | size_of::\<Type>()
/// ---- | ---------------
/// () | 0
/// bool | 1
/// u8 | 1
/// u16 | 2
/// u32 | 4
Expand Down
4 changes: 3 additions & 1 deletion src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ impl Float for f32 {
/// Converts to degrees, assuming the number is in radians.
#[inline]
fn to_degrees(self) -> f32 {
self * (180.0f32 / consts::PI)
// Use a constant for better precision.
const PIS_IN_180: f32 = 57.2957795130823208767981548141051703_f32;
self * PIS_IN_180
}

/// Converts to radians, assuming the number is in degrees.
Expand Down
3 changes: 3 additions & 0 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ impl Float for f64 {
/// Converts to degrees, assuming the number is in radians.
#[inline]
fn to_degrees(self) -> f64 {
// The division here is correctly rounded with respect to the true
// value of 180/π. (This differs from f32, where a constant must be
// used to ensure a correctly rounded result.)
self * (180.0f64 / consts::PI)
}

Expand Down
24 changes: 0 additions & 24 deletions src/librustc_errors/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,8 @@

// Code for annotating snippets.

use syntax_pos::{Span, FileMap};
use CodeMapper;
use std::rc::Rc;
use Level;

#[derive(Clone)]
pub struct SnippetData {
codemap: Rc<CodeMapper>,
files: Vec<FileInfo>,
}

#[derive(Clone)]
pub struct FileInfo {
file: Rc<FileMap>,

/// The "primary file", if any, gets a `-->` marker instead of
/// `>>>`, and has a line-number/column printed and not just a
/// filename (other files are not guaranteed to have line numbers
/// or columns). It appears first in the listing. It is known to
/// contain at least one primary span, though primary spans (which
/// are designated with `^^^`) may also occur in other files.
primary_span: Option<Span>,

lines: Vec<Line>,
}

#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
pub struct Line {
pub line_index: usize,
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
// Issue #46746: Two-phase borrows handles
// stmts of form `Tmp = &mut Borrow` ...
match lhs {
Place::Local(..) => {} // okay
Place::Static(..) => unreachable!(), // (filtered by is_unsafe_place)
Place::Local(..) | Place::Static(..) => {} // okay
Place::Projection(..) => {
// ... can assign into projections,
// e.g. `box (&mut _)`. Current
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_passes/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
kind.name())
.span_label(e.span,
"can only break with a value inside `loop`")
.span_suggestion(e.span,
&format!("instead, use `break` on its own \
without a value inside this `{}` loop",
kind.name()),
"break".to_string())
.emit();
}
}
Expand Down
30 changes: 22 additions & 8 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,19 @@ nav.sub {
overflow: auto;
}

.sidebar .current {
.sidebar .block > ul > li {
margin-right: -20px;
}

.content, nav { max-width: 960px; }
.content, nav {
max-width: 960px;
}

/* Everything else */

.js-only, .hidden { display: none !important; }
.js-only, .hidden {
display: none !important;
}

.sidebar img {
margin: 20px auto;
Expand Down Expand Up @@ -218,7 +222,9 @@ nav.sub {
border: none;
}

.location a:first-child { font-weight: 500; }
.location a:first-child {
font-weight: 500;
}

.block {
padding: 0;
Expand Down Expand Up @@ -299,7 +305,9 @@ nav.sub {
-ms-user-select: none;
user-select: none;
}
.line-numbers span { cursor: pointer; }
.line-numbers span {
cursor: pointer;
}

.docblock-short p {
display: inline;
Expand All @@ -317,7 +325,9 @@ nav.sub {
text-overflow: ellipsis;
margin: 0;
}
.docblock-short code { white-space: nowrap; }
.docblock-short code {
white-space: nowrap;
}

.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 {
border-bottom: 1px solid;
Expand Down Expand Up @@ -384,7 +394,9 @@ h4 > code, h3 > code, .invisible > code {
display: inline-block;
}

#main { position: relative; }
#main {
position: relative;
}
#main > .since {
top: inherit;
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
Expand Down Expand Up @@ -428,7 +440,9 @@ h4 > code, h3 > code, .invisible > code {
padding: 0;
}

.content .item-list li { margin-bottom: 1em; }
.content .item-list li {
margin-bottom: 1em;
}

.content .multi-column {
-moz-column-count: 5;
Expand Down
1 change: 1 addition & 0 deletions src/libstd/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,7 @@ mod tests {
assert!(nan.to_degrees().is_nan());
assert_eq!(inf.to_degrees(), inf);
assert_eq!(neg_inf.to_degrees(), neg_inf);
assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
}

#[test]
Expand Down
31 changes: 19 additions & 12 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,27 @@ impl<'a> StringReader<'a> {
self.err_span(self.mk_sp(from_pos, to_pos), m)
}

/// Pushes a character to a message string for error reporting
fn push_escaped_char_for_msg(m: &mut String, c: char) {
match c {
'\u{20}'...'\u{7e}' => {
// Don't escape \, ' or " for user-facing messages
m.push(c);
}
_ => {
for c in c.escape_default() {
m.push(c);
}
}
}
}

/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
/// escaped character to the error message
fn fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) -> FatalError {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() {
m.push(c)
}
Self::push_escaped_char_for_msg(&mut m, c);
self.fatal_span_(from_pos, to_pos, &m[..])
}
fn struct_fatal_span_char(&self,
Expand All @@ -264,9 +277,7 @@ impl<'a> StringReader<'a> {
-> DiagnosticBuilder<'a> {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() {
m.push(c)
}
Self::push_escaped_char_for_msg(&mut m, c);
self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), &m[..])
}

Expand All @@ -275,9 +286,7 @@ impl<'a> StringReader<'a> {
fn err_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() {
m.push(c)
}
Self::push_escaped_char_for_msg(&mut m, c);
self.err_span_(from_pos, to_pos, &m[..]);
}
fn struct_err_span_char(&self,
Expand All @@ -288,9 +297,7 @@ impl<'a> StringReader<'a> {
-> DiagnosticBuilder<'a> {
let mut m = m.to_string();
m.push_str(": ");
for c in c.escape_default() {
m.push(c)
}
Self::push_escaped_char_for_msg(&mut m, c);
self.sess.span_diagnostic.struct_span_err(self.mk_sp(from_pos, to_pos), &m[..])
}

Expand Down
23 changes: 17 additions & 6 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,24 @@ impl Span {

/// Return a `Span` that would enclose both `self` and `end`.
pub fn to(self, end: Span) -> Span {
let span = self.data();
let end = end.data();
let span_data = self.data();
let end_data = end.data();
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
// have an incomplete span than a completely nonsensical one.
if span_data.ctxt != end_data.ctxt {
if span_data.ctxt == SyntaxContext::empty() {
return end;
} else if end_data.ctxt == SyntaxContext::empty() {
return self;
}
// both span fall within a macro
// FIXME(estebank) check if it is the *same* macro
}
Span::new(
cmp::min(span.lo, end.lo),
cmp::max(span.hi, end.hi),
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
if span.ctxt == SyntaxContext::empty() { end.ctxt } else { span.ctxt },
cmp::min(span_data.lo, end_data.lo),
cmp::max(span_data.hi, end_data.hi),
if span_data.ctxt == SyntaxContext::empty() { end_data.ctxt } else { span_data.ctxt },
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/parse-fail/bad-char-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
fn main() {
// these literals are just silly.
''';
//~^ ERROR: character constant must be escaped: \'
//~^ ERROR: character constant must be escaped: '

// note that this is a literal "\n" byte
'
Expand Down
13 changes: 13 additions & 0 deletions src/test/parse-fail/lex-stray-backslash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

\ //~ ERROR: unknown start of token: \
20 changes: 20 additions & 0 deletions src/test/run-pass/issue-47789.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.


#![feature(nll)]

static mut x: &'static u32 = &0;

fn foo() {
unsafe { x = &1; }
}

fn main() { }
4 changes: 4 additions & 0 deletions src/test/ui/loop-break-value-no-repeat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ error[E0571]: `break` with value from a `for` loop
|
22 | break 22 //~ ERROR `break` with value from a `for` loop
| ^^^^^^^^ can only break with a value inside `loop`
help: instead, use `break` on its own without a value inside this `for` loop
|
22 | break //~ ERROR `break` with value from a `for` loop
| ^^^^^

error: aborting due to previous error

Loading

0 comments on commit 8d04b8f

Please sign in to comment.