Skip to content

Commit 8d04b8f

Browse files
committed
Auto merge of #47962 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests - Successful merges: #46156, #47829, #47842, #47898, #47914, #47916, #47919, #47942, #47951, #47973 - Failed merges: #47753
2 parents 6c15dff + 3a0a423 commit 8d04b8f

File tree

19 files changed

+157
-70
lines changed

19 files changed

+157
-70
lines changed

src/doc/unstable-book/src/language-features/lang-items.md

+8-13
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,23 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
3737
p
3838
}
3939
40-
#[lang = "exchange_free"]
41-
unsafe fn deallocate(ptr: *mut u8, _size: usize, _align: usize) {
42-
libc::free(ptr as *mut libc::c_void)
43-
}
44-
4540
#[lang = "box_free"]
4641
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
47-
deallocate(ptr as *mut u8, ::core::mem::size_of_val(&*ptr), ::core::mem::align_of_val(&*ptr));
42+
libc::free(ptr as *mut libc::c_void)
4843
}
4944
5045
#[start]
51-
fn main(argc: isize, argv: *const *const u8) -> isize {
52-
let x = box 1;
46+
fn main(_argc: isize, _argv: *const *const u8) -> isize {
47+
let _x = box 1;
5348
5449
0
5550
}
5651
5752
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
5853
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } }
59-
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
60-
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
61-
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
54+
#[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
55+
#[no_mangle] pub extern fn rust_eh_register_frames () {}
56+
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}
6257
```
6358

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

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

8681
Most lang items are defined by `libcore`, but if you're trying to build
@@ -318,4 +313,4 @@ the source code.
318313
- `phantom_data`: `libcore/marker.rs`
319314
- `freeze`: `libcore/marker.rs`
320315
- `debug_trait`: `libcore/fmt/mod.rs`
321-
- `non_zero`: `libcore/nonzero.rs`
316+
- `non_zero`: `libcore/nonzero.rs`

src/libcore/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ extern "rust-intrinsic" {
992992
/// ptr::copy_nonoverlapping(y, x, 1);
993993
/// ptr::copy_nonoverlapping(&t, y, 1);
994994
///
995-
/// // y and t now point to the same thing, but we need to completely forget `tmp`
995+
/// // y and t now point to the same thing, but we need to completely forget `t`
996996
/// // because it's no longer relevant.
997997
/// mem::forget(t);
998998
/// }

src/libcore/mem.rs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub fn forget<T>(t: T) {
189189
/// Type | size_of::\<Type>()
190190
/// ---- | ---------------
191191
/// () | 0
192+
/// bool | 1
192193
/// u8 | 1
193194
/// u16 | 2
194195
/// u32 | 4

src/libcore/num/f32.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ impl Float for f32 {
239239
/// Converts to degrees, assuming the number is in radians.
240240
#[inline]
241241
fn to_degrees(self) -> f32 {
242-
self * (180.0f32 / consts::PI)
242+
// Use a constant for better precision.
243+
const PIS_IN_180: f32 = 57.2957795130823208767981548141051703_f32;
244+
self * PIS_IN_180
243245
}
244246

245247
/// Converts to radians, assuming the number is in degrees.

src/libcore/num/f64.rs

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ impl Float for f64 {
237237
/// Converts to degrees, assuming the number is in radians.
238238
#[inline]
239239
fn to_degrees(self) -> f64 {
240+
// The division here is correctly rounded with respect to the true
241+
// value of 180/π. (This differs from f32, where a constant must be
242+
// used to ensure a correctly rounded result.)
240243
self * (180.0f64 / consts::PI)
241244
}
242245

src/librustc_errors/snippet.rs

-24
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,8 @@
1010

1111
// Code for annotating snippets.
1212

13-
use syntax_pos::{Span, FileMap};
14-
use CodeMapper;
15-
use std::rc::Rc;
1613
use Level;
1714

18-
#[derive(Clone)]
19-
pub struct SnippetData {
20-
codemap: Rc<CodeMapper>,
21-
files: Vec<FileInfo>,
22-
}
23-
24-
#[derive(Clone)]
25-
pub struct FileInfo {
26-
file: Rc<FileMap>,
27-
28-
/// The "primary file", if any, gets a `-->` marker instead of
29-
/// `>>>`, and has a line-number/column printed and not just a
30-
/// filename (other files are not guaranteed to have line numbers
31-
/// or columns). It appears first in the listing. It is known to
32-
/// contain at least one primary span, though primary spans (which
33-
/// are designated with `^^^`) may also occur in other files.
34-
primary_span: Option<Span>,
35-
36-
lines: Vec<Line>,
37-
}
38-
3915
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
4016
pub struct Line {
4117
pub line_index: usize,

src/librustc_mir/dataflow/impls/borrows.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
396396
// Issue #46746: Two-phase borrows handles
397397
// stmts of form `Tmp = &mut Borrow` ...
398398
match lhs {
399-
Place::Local(..) => {} // okay
400-
Place::Static(..) => unreachable!(), // (filtered by is_unsafe_place)
399+
Place::Local(..) | Place::Static(..) => {} // okay
401400
Place::Projection(..) => {
402401
// ... can assign into projections,
403402
// e.g. `box (&mut _)`. Current

src/librustc_passes/loops.rs

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
119119
kind.name())
120120
.span_label(e.span,
121121
"can only break with a value inside `loop`")
122+
.span_suggestion(e.span,
123+
&format!("instead, use `break` on its own \
124+
without a value inside this `{}` loop",
125+
kind.name()),
126+
"break".to_string())
122127
.emit();
123128
}
124129
}

src/librustdoc/html/static/rustdoc.css

+22-8
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,19 @@ nav.sub {
181181
overflow: auto;
182182
}
183183

184-
.sidebar .current {
184+
.sidebar .block > ul > li {
185185
margin-right: -20px;
186186
}
187187

188-
.content, nav { max-width: 960px; }
188+
.content, nav {
189+
max-width: 960px;
190+
}
189191

190192
/* Everything else */
191193

192-
.js-only, .hidden { display: none !important; }
194+
.js-only, .hidden {
195+
display: none !important;
196+
}
193197

194198
.sidebar img {
195199
margin: 20px auto;
@@ -218,7 +222,9 @@ nav.sub {
218222
border: none;
219223
}
220224

221-
.location a:first-child { font-weight: 500; }
225+
.location a:first-child {
226+
font-weight: 500;
227+
}
222228

223229
.block {
224230
padding: 0;
@@ -299,7 +305,9 @@ nav.sub {
299305
-ms-user-select: none;
300306
user-select: none;
301307
}
302-
.line-numbers span { cursor: pointer; }
308+
.line-numbers span {
309+
cursor: pointer;
310+
}
303311

304312
.docblock-short p {
305313
display: inline;
@@ -317,7 +325,9 @@ nav.sub {
317325
text-overflow: ellipsis;
318326
margin: 0;
319327
}
320-
.docblock-short code { white-space: nowrap; }
328+
.docblock-short code {
329+
white-space: nowrap;
330+
}
321331

322332
.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 {
323333
border-bottom: 1px solid;
@@ -384,7 +394,9 @@ h4 > code, h3 > code, .invisible > code {
384394
display: inline-block;
385395
}
386396

387-
#main { position: relative; }
397+
#main {
398+
position: relative;
399+
}
388400
#main > .since {
389401
top: inherit;
390402
font-family: "Fira Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
@@ -428,7 +440,9 @@ h4 > code, h3 > code, .invisible > code {
428440
padding: 0;
429441
}
430442

431-
.content .item-list li { margin-bottom: 1em; }
443+
.content .item-list li {
444+
margin-bottom: 1em;
445+
}
432446

433447
.content .multi-column {
434448
-moz-column-count: 5;

src/libstd/f32.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,7 @@ mod tests {
15311531
assert!(nan.to_degrees().is_nan());
15321532
assert_eq!(inf.to_degrees(), inf);
15331533
assert_eq!(neg_inf.to_degrees(), neg_inf);
1534+
assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703);
15341535
}
15351536

15361537
#[test]

src/libsyntax/parse/lexer/mod.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,27 @@ impl<'a> StringReader<'a> {
246246
self.err_span(self.mk_sp(from_pos, to_pos), m)
247247
}
248248

249+
/// Pushes a character to a message string for error reporting
250+
fn push_escaped_char_for_msg(m: &mut String, c: char) {
251+
match c {
252+
'\u{20}'...'\u{7e}' => {
253+
// Don't escape \, ' or " for user-facing messages
254+
m.push(c);
255+
}
256+
_ => {
257+
for c in c.escape_default() {
258+
m.push(c);
259+
}
260+
}
261+
}
262+
}
263+
249264
/// Report a lexical error spanning [`from_pos`, `to_pos`), appending an
250265
/// escaped character to the error message
251266
fn fatal_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) -> FatalError {
252267
let mut m = m.to_string();
253268
m.push_str(": ");
254-
for c in c.escape_default() {
255-
m.push(c)
256-
}
269+
Self::push_escaped_char_for_msg(&mut m, c);
257270
self.fatal_span_(from_pos, to_pos, &m[..])
258271
}
259272
fn struct_fatal_span_char(&self,
@@ -264,9 +277,7 @@ impl<'a> StringReader<'a> {
264277
-> DiagnosticBuilder<'a> {
265278
let mut m = m.to_string();
266279
m.push_str(": ");
267-
for c in c.escape_default() {
268-
m.push(c)
269-
}
280+
Self::push_escaped_char_for_msg(&mut m, c);
270281
self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), &m[..])
271282
}
272283

@@ -275,9 +286,7 @@ impl<'a> StringReader<'a> {
275286
fn err_span_char(&self, from_pos: BytePos, to_pos: BytePos, m: &str, c: char) {
276287
let mut m = m.to_string();
277288
m.push_str(": ");
278-
for c in c.escape_default() {
279-
m.push(c)
280-
}
289+
Self::push_escaped_char_for_msg(&mut m, c);
281290
self.err_span_(from_pos, to_pos, &m[..]);
282291
}
283292
fn struct_err_span_char(&self,
@@ -288,9 +297,7 @@ impl<'a> StringReader<'a> {
288297
-> DiagnosticBuilder<'a> {
289298
let mut m = m.to_string();
290299
m.push_str(": ");
291-
for c in c.escape_default() {
292-
m.push(c)
293-
}
300+
Self::push_escaped_char_for_msg(&mut m, c);
294301
self.sess.span_diagnostic.struct_span_err(self.mk_sp(from_pos, to_pos), &m[..])
295302
}
296303

src/libsyntax_pos/lib.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,24 @@ impl Span {
347347

348348
/// Return a `Span` that would enclose both `self` and `end`.
349349
pub fn to(self, end: Span) -> Span {
350-
let span = self.data();
351-
let end = end.data();
350+
let span_data = self.data();
351+
let end_data = end.data();
352+
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
353+
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
354+
// have an incomplete span than a completely nonsensical one.
355+
if span_data.ctxt != end_data.ctxt {
356+
if span_data.ctxt == SyntaxContext::empty() {
357+
return end;
358+
} else if end_data.ctxt == SyntaxContext::empty() {
359+
return self;
360+
}
361+
// both span fall within a macro
362+
// FIXME(estebank) check if it is the *same* macro
363+
}
352364
Span::new(
353-
cmp::min(span.lo, end.lo),
354-
cmp::max(span.hi, end.hi),
355-
// FIXME(jseyfried): self.ctxt should always equal end.ctxt here (c.f. issue #23480)
356-
if span.ctxt == SyntaxContext::empty() { end.ctxt } else { span.ctxt },
365+
cmp::min(span_data.lo, end_data.lo),
366+
cmp::max(span_data.hi, end_data.hi),
367+
if span_data.ctxt == SyntaxContext::empty() { end_data.ctxt } else { span_data.ctxt },
357368
)
358369
}
359370

src/test/parse-fail/bad-char-literals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
fn main() {
1616
// these literals are just silly.
1717
''';
18-
//~^ ERROR: character constant must be escaped: \'
18+
//~^ ERROR: character constant must be escaped: '
1919

2020
// note that this is a literal "\n" byte
2121
'
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z parse-only
12+
13+
\ //~ ERROR: unknown start of token: \

src/test/run-pass/issue-47789.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
#![feature(nll)]
13+
14+
static mut x: &'static u32 = &0;
15+
16+
fn foo() {
17+
unsafe { x = &1; }
18+
}
19+
20+
fn main() { }

src/test/ui/loop-break-value-no-repeat.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ error[E0571]: `break` with value from a `for` loop
33
|
44
22 | break 22 //~ ERROR `break` with value from a `for` loop
55
| ^^^^^^^^ can only break with a value inside `loop`
6+
help: instead, use `break` on its own without a value inside this `for` loop
7+
|
8+
22 | break //~ ERROR `break` with value from a `for` loop
9+
| ^^^^^
610

711
error: aborting due to previous error
812

0 commit comments

Comments
 (0)