Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #47962

Merged
merged 20 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
219ba51
Document the size of bool
SimonSapin Nov 21, 2017
b7437c5
Suggest removing value from `break` when invalid
estebank Jan 28, 2018
bc8e11b
Fix ICE when assigning references to a static mut with NLL
Aaron1011 Jan 31, 2018
b9441f2
Improve char escaping in lexer messages
etaoins Jan 31, 2018
cf78ff3
Fix lang items box example code
vmx Jan 31, 2018
e34c31b
Use constant for 180/π in to_degrees
varkor Feb 1, 2018
aaec608
Minimize weird spans involving macro context
estebank Feb 1, 2018
8b8d044
Fix ugly hover in sidebar
GuillaumeGomez Feb 1, 2018
c785013
Remove dead code
Manishearth Jan 29, 2018
3600bfb
Rollup merge of #46156 - SimonSapin:patch-14, r=withoutboats
kennytm Feb 2, 2018
0f36b2c
Rollup merge of #47829 - estebank:break-in-for, r=cramertj Suggest re…
kennytm Feb 2, 2018
a671944
Rollup merge of #47842 - Manishearth:dead-code, r=nagisa Remove dead …
kennytm Feb 2, 2018
2e3a8f5
Rollup merge of #47898 - Aaron1011:static-ref-nll, r=nikomatsakis Fix…
kennytm Feb 2, 2018
b4b73a1
Rollup merge of #47914 - etaoins:improve-char-escape-in-lexer-msg, r=…
kennytm Feb 2, 2018
5edeff3
Rollup merge of #47916 - vmx:patch-2, r=kennytm Fix lang items box ex…
kennytm Feb 2, 2018
7c6380c
Rollup merge of #47919 - varkor:to_degrees-precision, r=rkruppe Use c…
kennytm Feb 2, 2018
9d995d2
Rollup merge of #47942 - estebank:macro-spans, r=nikomatsakis Minimiz…
kennytm Feb 2, 2018
8d1586d
Rollup merge of #47951 - GuillaumeGomez:sidebar-hover, r=QuietMisdrea…
kennytm Feb 2, 2018
321e429
copy_nonoverlapping example: Fixed typo
perlun Feb 2, 2018
3a0a423
Rollup merge of #47973 - perlun:patch-1, r=dtolnay
kennytm Feb 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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