Skip to content

Commit d902539

Browse files
committed
Auto merge of #66656 - Centril:rollup-fivygwz, r=Centril
Rollup of 4 pull requests Successful merges: - #65961 (add fn type_name_of_val) - #66574 (Update tidy check for error codes testing) - #66576 (made gdb pretty-printing more robust when printing uninitialized vec) - #66583 (Clarify Step Documentation) Failed merges: r? @ghost
2 parents 6d523ee + 8024e0d commit d902539

File tree

4 files changed

+106
-23
lines changed

4 files changed

+106
-23
lines changed

src/etc/gdb_rust_pretty_printing.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,20 @@ def to_string(self):
284284
("(len: %i, cap: %i)" % (length, cap)))
285285

286286
def children(self):
287+
saw_inaccessible = False
287288
(length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(self.__val)
288289
gdb_ptr = data_ptr.get_wrapped_value()
289290
for index in xrange(0, length):
290-
yield (str(index), (gdb_ptr + index).dereference())
291+
if saw_inaccessible:
292+
return
293+
try:
294+
# rust-lang/rust#64343: passing deref expr to `str` allows
295+
# catching exception on garbage pointer
296+
str((gdb_ptr + index).dereference())
297+
yield (str(index), (gdb_ptr + index).dereference())
298+
except RuntimeError:
299+
saw_inaccessible = True
300+
yield (str(index), "inaccessible")
291301

292302

293303
class RustStdVecDequePrinter(object):

src/libcore/any.rs

+40-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ impl TypeId {
452452
/// The current implementation uses the same infrastructure as compiler
453453
/// diagnostics and debuginfo, but this is not guaranteed.
454454
///
455-
/// # Example
455+
/// # Examples
456456
///
457457
/// ```rust
458458
/// assert_eq!(
@@ -465,3 +465,42 @@ impl TypeId {
465465
pub const fn type_name<T: ?Sized>() -> &'static str {
466466
intrinsics::type_name::<T>()
467467
}
468+
469+
/// Returns the name of the type of the pointed-to value as a string slice.
470+
/// This is the same as `type_name::<T>()`, but can be used where the type of a
471+
/// variable is not easily available.
472+
///
473+
/// # Note
474+
///
475+
/// This is intended for diagnostic use. The exact contents and format of the
476+
/// string are not specified, other than being a best-effort description of the
477+
/// type. For example, `type_name_of::<Option<String>>(None)` could return the
478+
/// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not
479+
/// `"foobar"`. In addition, the output may change between versions of the
480+
/// compiler.
481+
///
482+
/// The type name should not be considered a unique identifier of a type;
483+
/// multiple types may share the same type name.
484+
///
485+
/// The current implementation uses the same infrastructure as compiler
486+
/// diagnostics and debuginfo, but this is not guaranteed.
487+
///
488+
/// # Examples
489+
///
490+
/// Prints the default integer and float types.
491+
///
492+
/// ```rust
493+
/// #![feature(type_name_of_val)]
494+
/// use std::any::type_name_of_val;
495+
///
496+
/// let x = 1;
497+
/// println!("{}", type_name_of_val(&x));
498+
/// let y = 1.0;
499+
/// println!("{}", type_name_of_val(&y));
500+
/// ```
501+
#[unstable(feature = "type_name_of_val", issue = "66359")]
502+
#[rustc_const_unstable(feature = "const_type_name")]
503+
pub const fn type_name_of_val<T: ?Sized>(val: &T) -> &'static str {
504+
let _ = val;
505+
type_name::<T>()
506+
}

src/libcore/iter/range.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ pub trait Step: Clone + PartialOrd + Sized {
2020
/// without overflow.
2121
fn steps_between(start: &Self, end: &Self) -> Option<usize>;
2222

23-
/// Replaces this step with `1`, returning itself.
23+
/// Replaces this step with `1`, returning a clone of itself.
24+
///
25+
/// The output of this method should always be greater than the output of replace_zero.
2426
fn replace_one(&mut self) -> Self;
2527

26-
/// Replaces this step with `0`, returning itself.
28+
/// Replaces this step with `0`, returning a clone of itself.
29+
///
30+
/// The output of this method should always be less than the output of replace_one.
2731
fn replace_zero(&mut self) -> Self;
2832

2933
/// Adds one to this step, returning the result.

src/tools/tidy/src/error_codes_check.rs

+49-19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
44
use std::collections::HashMap;
55
use std::ffi::OsStr;
6+
use std::fs::read_to_string;
7+
use std::io::Read;
68
use std::path::Path;
79

810
// A few of those error codes can't be tested but all the others can and *should* be tested!
@@ -50,41 +52,69 @@ const WHITELIST: &[&str] = &[
5052
"E0729",
5153
];
5254

53-
fn extract_error_codes(f: &str, error_codes: &mut HashMap<String, bool>) {
55+
fn check_error_code_explanation(
56+
f: &str,
57+
error_codes: &mut HashMap<String, bool>,
58+
err_code: String,
59+
) {
60+
for line in f.lines() {
61+
let s = line.trim();
62+
if s.starts_with("```") && s.contains("compile_fail") && s.contains('E') {
63+
error_codes.insert(err_code, true);
64+
return;
65+
} else if s.starts_with("#### Note: this error code is no longer emitted by the compiler") {
66+
error_codes.get_mut(&err_code).map(|x| *x = true);
67+
return;
68+
}
69+
}
70+
}
71+
72+
macro_rules! some_or_continue {
73+
($e:expr) => (
74+
match $e {
75+
Some(e) => e,
76+
None => continue,
77+
}
78+
);
79+
}
80+
81+
fn extract_error_codes(f: &str, error_codes: &mut HashMap<String, bool>, path: &Path) {
5482
let mut reached_no_explanation = false;
55-
let mut last_error_code = None;
5683

5784
for line in f.lines() {
5885
let s = line.trim();
59-
if s.starts_with('E') && s.ends_with(": r##\"") {
86+
if !reached_no_explanation && s.starts_with('E') && s.contains("include_str!(\"") {
6087
if let Some(err_code) = s.splitn(2, ':').next() {
6188
let err_code = err_code.to_owned();
62-
last_error_code = Some(err_code.clone());
6389
if !error_codes.contains_key(&err_code) {
64-
error_codes.insert(err_code, false);
90+
error_codes.insert(err_code.clone(), false);
6591
}
66-
}
67-
} else if s.starts_with("```") && s.contains("compile_fail") && s.contains('E') {
68-
if let Some(err_code) = s.splitn(2, 'E').skip(1).next() {
69-
if let Some(err_code) = err_code.splitn(2, ',').next() {
70-
let nb = error_codes.entry(format!("E{}", err_code)).or_insert(false);
71-
*nb = true;
92+
// Now we extract the tests from the markdown file!
93+
let md = some_or_continue!(s.splitn(2, "include_str!(\"").skip(1).next());
94+
let md_file_name = some_or_continue!(md.splitn(2, "\")").next());
95+
let path = some_or_continue!(path.parent()).join(md_file_name);
96+
match read_to_string(&path) {
97+
Ok(content) => {
98+
check_error_code_explanation(
99+
&content,
100+
error_codes,
101+
err_code,
102+
);
103+
}
104+
Err(e) => {
105+
eprintln!("Couldn't read `{}`: {}", path.display(), e);
106+
}
72107
}
73108
}
74-
} else if s == ";" {
75-
reached_no_explanation = true;
76109
} else if reached_no_explanation && s.starts_with('E') {
77110
if let Some(err_code) = s.splitn(2, ',').next() {
78111
let err_code = err_code.to_owned();
79112
if !error_codes.contains_key(&err_code) { // this check should *never* fail!
80113
error_codes.insert(err_code, false);
81114
}
82115
}
83-
} else if s.starts_with("#### Note: this error code is no longer emitted by the compiler") {
84-
if let Some(last) = last_error_code {
85-
error_codes.get_mut(&last).map(|x| *x = true);
86-
}
87-
last_error_code = None;
116+
} else if s == ";" {
117+
reached_no_explanation = true;
88118
}
89119
}
90120
}
@@ -111,7 +141,7 @@ pub fn check(path: &Path, bad: &mut bool) {
111141
&mut |entry, contents| {
112142
let file_name = entry.file_name();
113143
if file_name == "error_codes.rs" {
114-
extract_error_codes(contents, &mut error_codes);
144+
extract_error_codes(contents, &mut error_codes, entry.path());
115145
} else if entry.path().extension() == Some(OsStr::new("stderr")) {
116146
extract_error_codes_from_tests(contents, &mut error_codes);
117147
}

0 commit comments

Comments
 (0)