Skip to content

Commit d290dec

Browse files
committed
Auto merge of #44474 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 13 pull requests - Successful merges: #44262, #44329, #44332, #44347, #44372, #44384, #44387, #44396, #44449, #44451, #44457, #44464, #44467 - Failed merges:
2 parents 23aaeb5 + 8a7d93b commit d290dec

File tree

14 files changed

+158
-105
lines changed

14 files changed

+158
-105
lines changed

src/liballoc/str.rs

+44-7
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,34 @@ impl str {
297297
/// [`str::from_utf8_mut`] function.
298298
///
299299
/// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
300+
///
301+
/// # Examples
302+
///
303+
/// Basic usage:
304+
///
305+
/// ```
306+
/// let mut s = String::from("Hello");
307+
/// let bytes = unsafe { s.as_bytes_mut() };
308+
///
309+
/// assert_eq!(b"Hello", bytes);
310+
/// ```
311+
///
312+
/// Mutability:
313+
///
314+
/// ```
315+
/// let mut s = String::from("🗻∈🌏");
316+
///
317+
/// unsafe {
318+
/// let bytes = s.as_bytes_mut();
319+
///
320+
/// bytes[0] = 0xF0;
321+
/// bytes[1] = 0x9F;
322+
/// bytes[2] = 0x8D;
323+
/// bytes[3] = 0x94;
324+
/// }
325+
///
326+
/// assert_eq!("🍔∈🌏", s);
327+
/// ```
300328
#[stable(feature = "str_mut_extras", since = "1.20.0")]
301329
#[inline(always)]
302330
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
@@ -362,16 +390,25 @@ impl str {
362390
/// # Examples
363391
///
364392
/// ```
365-
/// let mut v = String::from("🗻∈🌏");
366-
///
367-
/// assert_eq!(Some("🗻"), v.get_mut(0..4).map(|v| &*v));
368-
///
369-
/// // indices not on UTF-8 sequence boundaries
370-
/// assert!(v.get_mut(1..).is_none());
371-
/// assert!(v.get_mut(..8).is_none());
393+
/// use std::ascii::AsciiExt;
372394
///
395+
/// let mut v = String::from("hello");
396+
/// // correct length
397+
/// assert!(v.get_mut(0..5).is_some());
373398
/// // out of bounds
374399
/// assert!(v.get_mut(..42).is_none());
400+
/// assert_eq!(Some("he"), v.get_mut(0..2).map(|v| &*v));
401+
///
402+
/// assert_eq!("hello", v);
403+
/// {
404+
/// let s = v.get_mut(0..2);
405+
/// let s = s.map(|s| {
406+
/// s.make_ascii_uppercase();
407+
/// &*s
408+
/// });
409+
/// assert_eq!(Some("HE"), s);
410+
/// }
411+
/// assert_eq!("HEllo", v);
375412
/// ```
376413
#[stable(feature = "str_checked_slicing", since = "1.20.0")]
377414
#[inline]

src/liballoc/string.rs

+10
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,16 @@ impl String {
743743
}
744744

745745
/// Extracts a string slice containing the entire string.
746+
///
747+
/// # Examples
748+
///
749+
/// Basic usage:
750+
///
751+
/// ```
752+
/// let s = String::from("foo");
753+
///
754+
/// assert_eq!("foo", s.as_str());
755+
/// ```
746756
#[inline]
747757
#[stable(feature = "string_as_str", since = "1.7.0")]
748758
pub fn as_str(&self) -> &str {

src/liballoc_system/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ mod platform {
221221
}
222222
}
223223

224-
#[cfg(any(target_os = "android", target_os = "redox"))]
224+
#[cfg(any(target_os = "android", target_os = "redox", target_os = "solaris"))]
225225
#[inline]
226226
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
227227
// On android we currently target API level 9 which unfortunately
@@ -244,7 +244,7 @@ mod platform {
244244
libc::memalign(layout.align(), layout.size()) as *mut u8
245245
}
246246

247-
#[cfg(not(any(target_os = "android", target_os = "redox")))]
247+
#[cfg(not(any(target_os = "android", target_os = "redox", target_os = "solaris")))]
248248
#[inline]
249249
unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
250250
let mut out = ptr::null_mut();

src/librustc_trans/mir/block.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,16 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
383383
};
384384
let msg_str = Symbol::intern(str).as_str();
385385
let msg_str = C_str_slice(bcx.ccx, msg_str);
386-
let msg_file_line = C_struct(bcx.ccx,
387-
&[msg_str, filename, line],
386+
let msg_file_line_col = C_struct(bcx.ccx,
387+
&[msg_str, filename, line, col],
388388
false);
389-
let align = llalign_of_min(bcx.ccx, common::val_ty(msg_file_line));
390-
let msg_file_line = consts::addr_of(bcx.ccx,
391-
msg_file_line,
392-
align,
393-
"panic_loc");
389+
let align = llalign_of_min(bcx.ccx, common::val_ty(msg_file_line_col));
390+
let msg_file_line_col = consts::addr_of(bcx.ccx,
391+
msg_file_line_col,
392+
align,
393+
"panic_loc");
394394
(lang_items::PanicFnLangItem,
395-
vec![msg_file_line],
395+
vec![msg_file_line_col],
396396
None)
397397
}
398398
};

src/librustc_typeck/check/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1554,9 +1554,12 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
15541554

15551555
let repr_type_ty = def.repr.discr_type().to_ty(tcx);
15561556
if repr_type_ty == tcx.types.i128 || repr_type_ty == tcx.types.u128 {
1557-
if !tcx.sess.features.borrow().i128_type {
1557+
if !tcx.sess.features.borrow().repr128 {
15581558
emit_feature_err(&tcx.sess.parse_sess,
1559-
"i128_type", sp, GateIssue::Language, "128-bit type is unstable");
1559+
"repr128",
1560+
sp,
1561+
GateIssue::Language,
1562+
"repr with 128-bit type is unstable");
15601563
}
15611564
}
15621565

src/librustdoc/html/render.rs

+29-83
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,20 @@ pub fn run(mut krate: clean::Crate,
606606
}
607607

608608
// A short, single-line view of `s`.
609-
fn concise_str(s: &str) -> String {
609+
fn concise_str(mut s: &str) -> String {
610610
if s.contains('\n') {
611-
return format!("{}...", s.lines().next().expect("Impossible! We just found a newline"));
611+
s = s.lines().next().expect("Impossible! We just found a newline");
612612
}
613613
if s.len() > 70 {
614-
return format!("{} ... {}", &s[..50], &s[s.len()-20..]);
614+
let mut lo = 50;
615+
let mut hi = s.len() - 20;
616+
while !s.is_char_boundary(lo) {
617+
lo -= 1;
618+
}
619+
while !s.is_char_boundary(hi) {
620+
hi += 1;
621+
}
622+
return format!("{} ... {}", &s[..lo], &s[hi..]);
615623
}
616624
s.to_owned()
617625
}
@@ -660,9 +668,13 @@ fn render_difference(diff: &html_diff::Difference) {
660668
elem.path, elem.element_name, elem_attributes, opposite_elem_attributes);
661669
}
662670
html_diff::Difference::NodeText { ref elem, ref elem_text, ref opposite_elem_text, .. } => {
663-
let (s1, s2) = concise_compared_strs(elem_text, opposite_elem_text);
664-
println!(" {} Text differs:\n expected: `{}`\n found: `{}`",
665-
elem.path, s1, s2);
671+
if elem_text.split("\n")
672+
.zip(opposite_elem_text.split("\n"))
673+
.any(|(a, b)| a.trim() != b.trim()) {
674+
let (s1, s2) = concise_compared_strs(elem_text, opposite_elem_text);
675+
println!(" {} Text differs:\n expected: `{}`\n found: `{}`",
676+
elem.path, s1, s2);
677+
}
666678
}
667679
html_diff::Difference::NotPresent { ref elem, ref opposite_elem } => {
668680
if let Some(ref elem) = *elem {
@@ -1756,18 +1768,18 @@ fn render_markdown(w: &mut fmt::Formatter,
17561768
// We only emit warnings if the user has opted-in to Pulldown rendering.
17571769
let output = if render_type == RenderType::Pulldown {
17581770
let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown));
1759-
let differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
1760-
let differences = differences.into_iter()
1761-
.filter(|s| {
1762-
match *s {
1763-
html_diff::Difference::NodeText { ref elem_text,
1764-
ref opposite_elem_text,
1765-
.. }
1766-
if match_non_whitespace(elem_text, opposite_elem_text) => false,
1767-
_ => true,
1771+
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
1772+
differences.retain(|s| {
1773+
match *s {
1774+
html_diff::Difference::NodeText { ref elem_text,
1775+
ref opposite_elem_text,
1776+
.. }
1777+
if elem_text.split_whitespace().eq(opposite_elem_text.split_whitespace()) => {
1778+
false
17681779
}
1769-
})
1770-
.collect::<Vec<_>>();
1780+
_ => true,
1781+
}
1782+
});
17711783

17721784
if !differences.is_empty() {
17731785
scx.markdown_warnings.borrow_mut().push((span, md_text.to_owned(), differences));
@@ -1781,40 +1793,6 @@ fn render_markdown(w: &mut fmt::Formatter,
17811793
write!(w, "<div class='docblock'>{}{}</div>", prefix, output)
17821794
}
17831795

1784-
// Returns true iff s1 and s2 match, ignoring whitespace.
1785-
fn match_non_whitespace(s1: &str, s2: &str) -> bool {
1786-
let s1 = s1.trim();
1787-
let s2 = s2.trim();
1788-
let mut cs1 = s1.chars();
1789-
let mut cs2 = s2.chars();
1790-
while let Some(c1) = cs1.next() {
1791-
if c1.is_whitespace() {
1792-
continue;
1793-
}
1794-
1795-
loop {
1796-
if let Some(c2) = cs2.next() {
1797-
if !c2.is_whitespace() {
1798-
if c1 != c2 {
1799-
return false;
1800-
}
1801-
break;
1802-
}
1803-
} else {
1804-
return false;
1805-
}
1806-
}
1807-
}
1808-
1809-
while let Some(c2) = cs2.next() {
1810-
if !c2.is_whitespace() {
1811-
return false;
1812-
}
1813-
}
1814-
1815-
true
1816-
}
1817-
18181796
fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink,
18191797
cx: &Context, prefix: &str) -> fmt::Result {
18201798
if let Some(s) = item.doc_value() {
@@ -3791,35 +3769,3 @@ fn test_name_sorting() {
37913769
sorted.sort_by_key(|&s| name_key(s));
37923770
assert_eq!(names, sorted);
37933771
}
3794-
3795-
#[cfg(test)]
3796-
#[test]
3797-
fn test_match_non_whitespace() {
3798-
assert!(match_non_whitespace("", ""));
3799-
assert!(match_non_whitespace(" ", ""));
3800-
assert!(match_non_whitespace("", " "));
3801-
3802-
assert!(match_non_whitespace("a", "a"));
3803-
assert!(match_non_whitespace(" a ", "a"));
3804-
assert!(match_non_whitespace("a", " a"));
3805-
assert!(match_non_whitespace("abc", "abc"));
3806-
assert!(match_non_whitespace("abc", " abc "));
3807-
assert!(match_non_whitespace("abc ", "abc"));
3808-
assert!(match_non_whitespace("abc xyz", "abc xyz"));
3809-
assert!(match_non_whitespace("abc xyz", "abc\nxyz"));
3810-
assert!(match_non_whitespace("abc xyz", "abcxyz"));
3811-
assert!(match_non_whitespace("abcxyz", "abc xyz"));
3812-
assert!(match_non_whitespace("abc xyz ", " abc xyz\n"));
3813-
3814-
assert!(!match_non_whitespace("a", "b"));
3815-
assert!(!match_non_whitespace(" a ", "c"));
3816-
assert!(!match_non_whitespace("a", " aa"));
3817-
assert!(!match_non_whitespace("abc", "ac"));
3818-
assert!(!match_non_whitespace("abc", " adc "));
3819-
assert!(!match_non_whitespace("abc ", "abca"));
3820-
assert!(!match_non_whitespace("abc xyz", "abc xy"));
3821-
assert!(!match_non_whitespace("abc xyz", "bc\nxyz"));
3822-
assert!(!match_non_whitespace("abc xyz", "abc.xyz"));
3823-
assert!(!match_non_whitespace("abcxyz", "abc.xyz"));
3824-
assert!(!match_non_whitespace("abc xyz ", " abc xyz w"));
3825-
}

src/libstd/sys/unix/backtrace/printing/dladdr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ pub fn resolve_symname<F>(frame: Frame,
2222
{
2323
unsafe {
2424
let mut info: Dl_info = intrinsics::init();
25-
let symname = if dladdr(frame.exact_position, &mut info) == 0 {
25+
let symname = if dladdr(frame.exact_position, &mut info) == 0 ||
26+
info.dli_sname.is_null() {
2627
None
2728
} else {
2829
CStr::from_ptr(info.dli_sname).to_str().ok()

src/libstd/thread/local.rs

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ use mem;
3131
/// within a thread, and values that implement [`Drop`] get destructed when a
3232
/// thread exits. Some caveats apply, which are explained below.
3333
///
34+
/// A `LocalKey`'s initializer cannot recursively depend on itself, and using
35+
/// a `LocalKey` in this way will cause the initializer to infinitely recurse
36+
/// on the first call to `with`.
37+
///
3438
/// # Examples
3539
///
3640
/// ```

src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ declare_features! (
312312
// The `i128` type
313313
(active, i128_type, "1.16.0", Some(35118)),
314314

315+
// The `repr(i128)` annotation for enums
316+
(active, repr128, "1.16.0", Some(35118)),
317+
315318
// The `unadjusted` ABI. Perma unstable.
316319
(active, abi_unadjusted, "1.16.0", None),
317320

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4699,7 +4699,7 @@ impl<'a> Parser<'a> {
46994699
SeqSep::trailing_allowed(token::Comma),
47004700
|p| p.parse_fn_block_arg()
47014701
);
4702-
self.bump();
4702+
self.expect(&token::BinOp(token::Or))?;
47034703
args
47044704
}
47054705
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
#[repr(u128)]
12+
enum A { //~ ERROR repr with 128-bit type is unstable
13+
//~| HELP: add #![feature(repr128)]
14+
A(u64)
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 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+
pub fn example(ref s: str) {}
12+
//~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
13+
//~| `str` does not have a constant size known at compile-time
14+
//~| the trait `std::marker::Sized` is not implemented for `str`
15+
16+
fn main() {}

src/test/compile-fail/issue-44021.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
struct MyStruct;
12+
impl MyStruct {
13+
fn f() {|x, y} //~ ERROR expected one of `:`, `@`, or `|`, found `}`
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)