Skip to content

Commit 93fa2d7

Browse files
committed
Auto merge of #56155 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 11 pull requests Successful merges: - #55367 (lint if a private item has doctests) - #55485 (Return &T / &mut T in ManuallyDrop Deref(Mut) impl) - #55784 (Clarifying documentation for collections::hash_map::Entry::or_insert) - #55961 (Fix VecDeque pretty-printer) - #55980 (Suggest on closure args count mismatching with pipe span) - #56002 (fix #55972: Erroneous self arguments on bare functions emit subpar compilation error) - #56063 (Update any.rs documentation using keyword dyn) - #56067 (Add SGX target to rustc) - #56078 (Fix error message for `-C panic=xxx`.) - #56106 (Remove some incorrect doc comments) - #56126 (core/benches/num: Add `from_str/from_str_radix()` benchmarks) Failed merges: r? @ghost
2 parents f3adec6 + 61d7b3e commit 93fa2d7

33 files changed

+507
-97
lines changed

Diff for: src/etc/gdb_rust_pretty_printing.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,23 @@ def display_hint():
293293
def to_string(self):
294294
(tail, head, data_ptr, cap) = \
295295
rustpp.extract_tail_head_ptr_and_cap_from_std_vecdeque(self.__val)
296+
if head >= tail:
297+
size = head - tail
298+
else:
299+
size = cap + head - tail
296300
return (self.__val.type.get_unqualified_type_name() +
297-
("(len: %i, cap: %i)" % (head - tail, cap)))
301+
("(len: %i, cap: %i)" % (size, cap)))
298302

299303
def children(self):
300304
(tail, head, data_ptr, cap) = \
301305
rustpp.extract_tail_head_ptr_and_cap_from_std_vecdeque(self.__val)
302306
gdb_ptr = data_ptr.get_wrapped_value()
303-
for index in xrange(tail, head):
304-
yield (str(index), (gdb_ptr + index).dereference())
307+
if head >= tail:
308+
size = head - tail
309+
else:
310+
size = cap + head - tail
311+
for index in xrange(0, size):
312+
yield (str(index), (gdb_ptr + ((tail + index) % cap)).dereference())
305313

306314

307315
class RustStdBTreeSetPrinter(object):

Diff for: src/libcore/any.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//!
4040
//! // Logger function for any type that implements Debug.
4141
//! fn log<T: Any + Debug>(value: &T) {
42-
//! let value_any = value as &Any;
42+
//! let value_any = value as &dyn Any;
4343
//!
4444
//! // try to convert our value to a String. If successful, we want to
4545
//! // output the String's length as well as its value. If not, it's a
@@ -95,7 +95,7 @@ pub trait Any: 'static {
9595
///
9696
/// use std::any::{Any, TypeId};
9797
///
98-
/// fn is_string(s: &Any) -> bool {
98+
/// fn is_string(s: &dyn Any) -> bool {
9999
/// TypeId::of::<String>() == s.get_type_id()
100100
/// }
101101
///
@@ -151,7 +151,7 @@ impl dyn Any {
151151
/// ```
152152
/// use std::any::Any;
153153
///
154-
/// fn is_string(s: &Any) {
154+
/// fn is_string(s: &dyn Any) {
155155
/// if s.is::<String>() {
156156
/// println!("It's a string!");
157157
/// } else {
@@ -185,7 +185,7 @@ impl dyn Any {
185185
/// ```
186186
/// use std::any::Any;
187187
///
188-
/// fn print_if_string(s: &Any) {
188+
/// fn print_if_string(s: &dyn Any) {
189189
/// if let Some(string) = s.downcast_ref::<String>() {
190190
/// println!("It's a string({}): '{}'", string.len(), string);
191191
/// } else {
@@ -218,7 +218,7 @@ impl dyn Any {
218218
/// ```
219219
/// use std::any::Any;
220220
///
221-
/// fn modify_if_u32(s: &mut Any) {
221+
/// fn modify_if_u32(s: &mut dyn Any) {
222222
/// if let Some(num) = s.downcast_mut::<u32>() {
223223
/// *num = 42;
224224
/// }
@@ -256,7 +256,7 @@ impl dyn Any+Send {
256256
/// ```
257257
/// use std::any::Any;
258258
///
259-
/// fn is_string(s: &(Any + Send)) {
259+
/// fn is_string(s: &(dyn Any + Send)) {
260260
/// if s.is::<String>() {
261261
/// println!("It's a string!");
262262
/// } else {
@@ -282,7 +282,7 @@ impl dyn Any+Send {
282282
/// ```
283283
/// use std::any::Any;
284284
///
285-
/// fn print_if_string(s: &(Any + Send)) {
285+
/// fn print_if_string(s: &(dyn Any + Send)) {
286286
/// if let Some(string) = s.downcast_ref::<String>() {
287287
/// println!("It's a string({}): '{}'", string.len(), string);
288288
/// } else {
@@ -308,7 +308,7 @@ impl dyn Any+Send {
308308
/// ```
309309
/// use std::any::Any;
310310
///
311-
/// fn modify_if_u32(s: &mut (Any + Send)) {
311+
/// fn modify_if_u32(s: &mut (dyn Any + Send)) {
312312
/// if let Some(num) = s.downcast_mut::<u32>() {
313313
/// *num = 42;
314314
/// }
@@ -340,7 +340,7 @@ impl dyn Any+Send+Sync {
340340
/// ```
341341
/// use std::any::Any;
342342
///
343-
/// fn is_string(s: &(Any + Send + Sync)) {
343+
/// fn is_string(s: &(dyn Any + Send + Sync)) {
344344
/// if s.is::<String>() {
345345
/// println!("It's a string!");
346346
/// } else {
@@ -366,7 +366,7 @@ impl dyn Any+Send+Sync {
366366
/// ```
367367
/// use std::any::Any;
368368
///
369-
/// fn print_if_string(s: &(Any + Send + Sync)) {
369+
/// fn print_if_string(s: &(dyn Any + Send + Sync)) {
370370
/// if let Some(string) = s.downcast_ref::<String>() {
371371
/// println!("It's a string({}): '{}'", string.len(), string);
372372
/// } else {
@@ -392,7 +392,7 @@ impl dyn Any+Send+Sync {
392392
/// ```
393393
/// use std::any::Any;
394394
///
395-
/// fn modify_if_u32(s: &mut (Any + Send + Sync)) {
395+
/// fn modify_if_u32(s: &mut (dyn Any + Send + Sync)) {
396396
/// if let Some(num) = s.downcast_mut::<u32>() {
397397
/// *num = 42;
398398
/// }

Diff for: src/libcore/benches/num/mod.rs

+105
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,108 @@
1010

1111
mod flt2dec;
1212
mod dec2flt;
13+
14+
use test::Bencher;
15+
use std::str::FromStr;
16+
17+
const ASCII_NUMBERS: [&str; 19] = [
18+
"0",
19+
"1",
20+
"2",
21+
"43",
22+
"765",
23+
"76567",
24+
"987245987",
25+
"-4aa32",
26+
"1786235",
27+
"8723095",
28+
"f##5s",
29+
"83638730",
30+
"-2345",
31+
"562aa43",
32+
"-1",
33+
"-0",
34+
"abc",
35+
"xyz",
36+
"c0ffee",
37+
];
38+
39+
macro_rules! from_str_bench {
40+
($mac:ident, $t:ty) => (
41+
#[bench]
42+
fn $mac(b: &mut Bencher) {
43+
b.iter(|| {
44+
ASCII_NUMBERS
45+
.iter()
46+
.cycle()
47+
.take(5_000)
48+
.filter_map(|s| <($t)>::from_str(s).ok())
49+
.max()
50+
})
51+
}
52+
)
53+
}
54+
55+
macro_rules! from_str_radix_bench {
56+
($mac:ident, $t:ty, $radix:expr) => (
57+
#[bench]
58+
fn $mac(b: &mut Bencher) {
59+
b.iter(|| {
60+
ASCII_NUMBERS
61+
.iter()
62+
.cycle()
63+
.take(5_000)
64+
.filter_map(|s| <($t)>::from_str_radix(s, $radix).ok())
65+
.max()
66+
})
67+
}
68+
)
69+
}
70+
71+
from_str_bench!(bench_u8_from_str, u8);
72+
from_str_radix_bench!(bench_u8_from_str_radix_2, u8, 2);
73+
from_str_radix_bench!(bench_u8_from_str_radix_10, u8, 10);
74+
from_str_radix_bench!(bench_u8_from_str_radix_16, u8, 16);
75+
from_str_radix_bench!(bench_u8_from_str_radix_36, u8, 36);
76+
77+
from_str_bench!(bench_u16_from_str, u16);
78+
from_str_radix_bench!(bench_u16_from_str_radix_2, u16, 2);
79+
from_str_radix_bench!(bench_u16_from_str_radix_10, u16, 10);
80+
from_str_radix_bench!(bench_u16_from_str_radix_16, u16, 16);
81+
from_str_radix_bench!(bench_u16_from_str_radix_36, u16, 36);
82+
83+
from_str_bench!(bench_u32_from_str, u32);
84+
from_str_radix_bench!(bench_u32_from_str_radix_2, u32, 2);
85+
from_str_radix_bench!(bench_u32_from_str_radix_10, u32, 10);
86+
from_str_radix_bench!(bench_u32_from_str_radix_16, u32, 16);
87+
from_str_radix_bench!(bench_u32_from_str_radix_36, u32, 36);
88+
89+
from_str_bench!(bench_u64_from_str, u64);
90+
from_str_radix_bench!(bench_u64_from_str_radix_2, u64, 2);
91+
from_str_radix_bench!(bench_u64_from_str_radix_10, u64, 10);
92+
from_str_radix_bench!(bench_u64_from_str_radix_16, u64, 16);
93+
from_str_radix_bench!(bench_u64_from_str_radix_36, u64, 36);
94+
95+
from_str_bench!(bench_i8_from_str, i8);
96+
from_str_radix_bench!(bench_i8_from_str_radix_2, i8, 2);
97+
from_str_radix_bench!(bench_i8_from_str_radix_10, i8, 10);
98+
from_str_radix_bench!(bench_i8_from_str_radix_16, i8, 16);
99+
from_str_radix_bench!(bench_i8_from_str_radix_36, i8, 36);
100+
101+
from_str_bench!(bench_i16_from_str, i16);
102+
from_str_radix_bench!(bench_i16_from_str_radix_2, i16, 2);
103+
from_str_radix_bench!(bench_i16_from_str_radix_10, i16, 10);
104+
from_str_radix_bench!(bench_i16_from_str_radix_16, i16, 16);
105+
from_str_radix_bench!(bench_i16_from_str_radix_36, i16, 36);
106+
107+
from_str_bench!(bench_i32_from_str, i32);
108+
from_str_radix_bench!(bench_i32_from_str_radix_2, i32, 2);
109+
from_str_radix_bench!(bench_i32_from_str_radix_10, i32, 10);
110+
from_str_radix_bench!(bench_i32_from_str_radix_16, i32, 16);
111+
from_str_radix_bench!(bench_i32_from_str_radix_36, i32, 36);
112+
113+
from_str_bench!(bench_i64_from_str, i64);
114+
from_str_radix_bench!(bench_i64_from_str_radix_2, i64, 2);
115+
from_str_radix_bench!(bench_i64_from_str_radix_10, i64, 10);
116+
from_str_radix_bench!(bench_i64_from_str_radix_16, i64, 16);
117+
from_str_radix_bench!(bench_i64_from_str_radix_36, i64, 36);

Diff for: src/libcore/mem.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1016,15 +1016,15 @@ impl<T: ?Sized> ManuallyDrop<T> {
10161016
impl<T: ?Sized> Deref for ManuallyDrop<T> {
10171017
type Target = T;
10181018
#[inline]
1019-
fn deref(&self) -> &Self::Target {
1019+
fn deref(&self) -> &T {
10201020
&self.value
10211021
}
10221022
}
10231023

10241024
#[stable(feature = "manually_drop", since = "1.20.0")]
10251025
impl<T: ?Sized> DerefMut for ManuallyDrop<T> {
10261026
#[inline]
1027-
fn deref_mut(&mut self) -> &mut Self::Target {
1027+
fn deref_mut(&mut self) -> &mut T {
10281028
&mut self.value
10291029
}
10301030
}

Diff for: src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ declare_lint! {
318318
"warn about missing code example in an item's documentation"
319319
}
320320

321+
declare_lint! {
322+
pub PRIVATE_DOC_TESTS,
323+
Allow,
324+
"warn about doc test in private item"
325+
}
326+
321327
declare_lint! {
322328
pub WHERE_CLAUSES_OBJECT_SAFETY,
323329
Warn,
@@ -415,6 +421,7 @@ impl LintPass for HardwiredLints {
415421
DUPLICATE_MACRO_EXPORTS,
416422
INTRA_DOC_LINK_RESOLUTION_FAILURE,
417423
MISSING_DOC_CODE_EXAMPLES,
424+
PRIVATE_DOC_TESTS,
418425
WHERE_CLAUSES_OBJECT_SAFETY,
419426
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
420427
MACRO_USE_EXTERN_CRATE,

Diff for: src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ macro_rules! options {
802802
pub const parse_opt_uint: Option<&'static str> =
803803
Some("a number");
804804
pub const parse_panic_strategy: Option<&'static str> =
805-
Some("either `panic` or `abort`");
805+
Some("either `unwind` or `abort`");
806806
pub const parse_relro_level: Option<&'static str> =
807807
Some("one of: `full`, `partial`, or `off`");
808808
pub const parse_sanitizer: Option<&'static str> =

Diff for: src/librustc/traits/error_reporting.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1092,13 +1092,27 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10921092
if let Some(found_span) = found_span {
10931093
err.span_label(found_span, format!("takes {}", found_str));
10941094

1095+
// move |_| { ... }
1096+
// ^^^^^^^^-- def_span
1097+
//
1098+
// move |_| { ... }
1099+
// ^^^^^-- prefix
1100+
let prefix_span = self.tcx.sess.source_map().span_until_non_whitespace(found_span);
1101+
// move |_| { ... }
1102+
// ^^^-- pipe_span
1103+
let pipe_span = if let Some(span) = found_span.trim_start(prefix_span) {
1104+
span
1105+
} else {
1106+
found_span
1107+
};
1108+
10951109
// Suggest to take and ignore the arguments with expected_args_length `_`s if
10961110
// found arguments is empty (assume the user just wants to ignore args in this case).
10971111
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
10981112
if found_args.is_empty() && is_closure {
10991113
let underscores = vec!["_"; expected_args.len()].join(", ");
11001114
err.span_suggestion_with_applicability(
1101-
found_span,
1115+
pipe_span,
11021116
&format!(
11031117
"consider changing the closure to take and ignore the expected argument{}",
11041118
if expected_args.len() < 2 {

Diff for: src/librustc_codegen_ssa/back/linker.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,10 @@ impl<'a> Linker for WasmLd<'a> {
10501050
}
10511051

10521052
fn exported_symbols(tcx: TyCtxt, crate_type: CrateType) -> Vec<String> {
1053+
if let Some(ref exports) = tcx.sess.target.target.options.override_export_symbols {
1054+
return exports.clone()
1055+
}
1056+
10531057
let mut symbols = Vec::new();
10541058

10551059
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);

Diff for: src/librustc_codegen_ssa/mono_item.rs

-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Walks the crate looking for items/impl-items/trait-items that have
12-
//! either a `rustc_symbol_name` or `rustc_item_path` attribute and
13-
//! generates an error giving, respectively, the symbol name or
14-
//! item-path. This is used for unit testing the code that generates
15-
//! paths etc in all kinds of annoying scenarios.
16-
1711
use base;
1812
use rustc::hir;
1913
use rustc::hir::def::Def;

Diff for: src/librustc_mir/monomorphize/item.rs

-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Walks the crate looking for items/impl-items/trait-items that have
12-
//! either a `rustc_symbol_name` or `rustc_item_path` attribute and
13-
//! generates an error giving, respectively, the symbol name or
14-
//! item-path. This is used for unit testing the code that generates
15-
//! paths etc in all kinds of annoying scenarios.
16-
1711
use monomorphize::Instance;
1812
use rustc::hir;
1913
use rustc::hir::def_id::DefId;

0 commit comments

Comments
 (0)