Skip to content

Commit b2dd829

Browse files
committed
Auto merge of #79596 - m-ou-se:rollup-hujx3c7, r=m-ou-se
Rollup of 11 pull requests Successful merges: - #79038 (Change ui test that are run-pass and that do not test the compiler to library tests) - #79184 (Stop adding '*' at the end of slice and str typenames for MSVC case) - #79227 (Remove const_fn_feature_flags test) - #79444 (Move const ip in ui test to unit test) - #79522 (Validate lint docs separately.) - #79525 (Add -Z normalize-docs and enable it for compiler docs) - #79527 (Move intra-doc link tests into a subdirectory) - #79548 (Show since when a function is const in stdlib) - #79568 (update Miri) - #79573 (Update with status for various NetBSD ports.) - #79583 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0fa9d31 + c06a00e commit b2dd829

File tree

159 files changed

+1878
-1740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+1878
-1740
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,7 @@ dependencies = [
21312131
"rustc-workspace-hack",
21322132
"rustc_version",
21332133
"shell-escape",
2134+
"smallvec 1.4.2",
21342135
]
21352136

21362137
[[package]]

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ pub fn push_debuginfo_type_name<'tcx>(
9494
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
9595

9696
if cpp_like_names {
97-
output.push('*');
97+
// Slices and `&str` are treated like C++ pointers when computing debug
98+
// info for MSVC debugger. However, adding '*' at the end of these types' names
99+
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these
100+
// types out to aid debugging in MSVC.
101+
match *inner_type.kind() {
102+
ty::Slice(_) | ty::Str => {}
103+
_ => output.push('*'),
104+
}
98105
}
99106
}
100107
ty::Array(inner_type, len) => {

compiler/rustc_lint_defs/src/lib.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,25 @@ impl LintBuffer {
366366
/// ```
367367
///
368368
/// The `{{produces}}` tag will be automatically replaced with the output from
369-
/// the example by the build system. You can build and view the rustc book
370-
/// with `x.py doc --stage=1 src/doc/rustc --open`. If the lint example is too
371-
/// complex to run as a simple example (for example, it needs an extern
372-
/// crate), mark it with `ignore` and manually paste the expected output below
373-
/// the example.
369+
/// the example by the build system. If the lint example is too complex to run
370+
/// as a simple example (for example, it needs an extern crate), mark the code
371+
/// block with `ignore` and manually replace the `{{produces}}` line with the
372+
/// expected output in a `text` code block.
373+
///
374+
/// If this is a rustdoc-only lint, then only include a brief introduction
375+
/// with a link with the text `[rustdoc book]` so that the validator knows
376+
/// that this is for rustdoc only (see BROKEN_INTRA_DOC_LINKS as an example).
377+
///
378+
/// Commands to view and test the documentation:
379+
///
380+
/// * `./x.py doc --stage=1 src/doc/rustc --open`: Builds the rustc book and opens it.
381+
/// * `./x.py test src/tools/lint-docs`: Validates that the lint docs have the
382+
/// correct style, and that the code example actually emits the expected
383+
/// lint.
384+
///
385+
/// If you have already built the compiler, and you want to make changes to
386+
/// just the doc comments, then use the `--keep-stage=0` flag with the above
387+
/// commands to avoid rebuilding the compiler.
374388
#[macro_export]
375389
macro_rules! declare_lint {
376390
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr) => (

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
996996
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
997997
no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
998998
"prevent automatic injection of the profiler_builtins crate"),
999+
normalize_docs: bool = (false, parse_bool, [TRACKED],
1000+
"normalize associated items in rustdoc when generating documentation"),
9991001
osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
10001002
"pass `-install_name @rpath/...` to the macOS linker (default: no)"),
10011003
panic_abort_tests: bool = (false, parse_bool, [TRACKED],

library/alloc/tests/str.rs

+95-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::borrow::Cow;
22
use std::cmp::Ordering::{Equal, Greater, Less};
3-
use std::str::from_utf8;
3+
use std::str::{from_utf8, from_utf8_unchecked};
44

55
#[test]
66
fn test_le() {
@@ -1971,3 +1971,97 @@ fn test_str_escapes() {
19711971
";
19721972
assert_eq!(x, r"\\"); // extraneous whitespace stripped
19731973
}
1974+
1975+
#[test]
1976+
fn const_str_ptr() {
1977+
const A: [u8; 2] = ['h' as u8, 'i' as u8];
1978+
const B: &'static [u8; 2] = &A;
1979+
const C: *const u8 = B as *const u8;
1980+
1981+
unsafe {
1982+
let foo = &A as *const u8;
1983+
assert_eq!(foo, C);
1984+
assert_eq!(from_utf8_unchecked(&A), "hi");
1985+
assert_eq!(*C, A[0]);
1986+
assert_eq!(*(&B[0] as *const u8), A[0]);
1987+
}
1988+
}
1989+
1990+
#[test]
1991+
fn utf8() {
1992+
let yen: char = '¥'; // 0xa5
1993+
let c_cedilla: char = 'ç'; // 0xe7
1994+
let thorn: char = 'þ'; // 0xfe
1995+
let y_diaeresis: char = 'ÿ'; // 0xff
1996+
let pi: char = 'Π'; // 0x3a0
1997+
1998+
assert_eq!(yen as isize, 0xa5);
1999+
assert_eq!(c_cedilla as isize, 0xe7);
2000+
assert_eq!(thorn as isize, 0xfe);
2001+
assert_eq!(y_diaeresis as isize, 0xff);
2002+
assert_eq!(pi as isize, 0x3a0);
2003+
2004+
assert_eq!(pi as isize, '\u{3a0}' as isize);
2005+
assert_eq!('\x0a' as isize, '\n' as isize);
2006+
2007+
let bhutan: String = "འབྲུག་ཡུལ།".to_string();
2008+
let japan: String = "日本".to_string();
2009+
let uzbekistan: String = "Ўзбекистон".to_string();
2010+
let austria: String = "Österreich".to_string();
2011+
2012+
let bhutan_e: String =
2013+
"\u{f60}\u{f56}\u{fb2}\u{f74}\u{f42}\u{f0b}\u{f61}\u{f74}\u{f63}\u{f0d}".to_string();
2014+
let japan_e: String = "\u{65e5}\u{672c}".to_string();
2015+
let uzbekistan_e: String =
2016+
"\u{40e}\u{437}\u{431}\u{435}\u{43a}\u{438}\u{441}\u{442}\u{43e}\u{43d}".to_string();
2017+
let austria_e: String = "\u{d6}sterreich".to_string();
2018+
2019+
let oo: char = 'Ö';
2020+
assert_eq!(oo as isize, 0xd6);
2021+
2022+
fn check_str_eq(a: String, b: String) {
2023+
let mut i: isize = 0;
2024+
for ab in a.bytes() {
2025+
println!("{}", i);
2026+
println!("{}", ab);
2027+
let bb: u8 = b.as_bytes()[i as usize];
2028+
println!("{}", bb);
2029+
assert_eq!(ab, bb);
2030+
i += 1;
2031+
}
2032+
}
2033+
2034+
check_str_eq(bhutan, bhutan_e);
2035+
check_str_eq(japan, japan_e);
2036+
check_str_eq(uzbekistan, uzbekistan_e);
2037+
check_str_eq(austria, austria_e);
2038+
}
2039+
2040+
#[test]
2041+
fn utf8_chars() {
2042+
// Chars of 1, 2, 3, and 4 bytes
2043+
let chs: Vec<char> = vec!['e', 'é', '€', '\u{10000}'];
2044+
let s: String = chs.iter().cloned().collect();
2045+
let schs: Vec<char> = s.chars().collect();
2046+
2047+
assert_eq!(s.len(), 10);
2048+
assert_eq!(s.chars().count(), 4);
2049+
assert_eq!(schs.len(), 4);
2050+
assert_eq!(schs.iter().cloned().collect::<String>(), s);
2051+
2052+
assert!((from_utf8(s.as_bytes()).is_ok()));
2053+
// invalid prefix
2054+
assert!((!from_utf8(&[0x80]).is_ok()));
2055+
// invalid 2 byte prefix
2056+
assert!((!from_utf8(&[0xc0]).is_ok()));
2057+
assert!((!from_utf8(&[0xc0, 0x10]).is_ok()));
2058+
// invalid 3 byte prefix
2059+
assert!((!from_utf8(&[0xe0]).is_ok()));
2060+
assert!((!from_utf8(&[0xe0, 0x10]).is_ok()));
2061+
assert!((!from_utf8(&[0xe0, 0xff, 0x10]).is_ok()));
2062+
// invalid 4 byte prefix
2063+
assert!((!from_utf8(&[0xf0]).is_ok()));
2064+
assert!((!from_utf8(&[0xf0, 0x10]).is_ok()));
2065+
assert!((!from_utf8(&[0xf0, 0xff, 0x10]).is_ok()));
2066+
assert!((!from_utf8(&[0xf0, 0xff, 0xff, 0x10]).is_ok()));
2067+
}

library/core/tests/ascii.rs

+53
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,56 @@ fn ascii_const() {
408408
const BYTE_IS_ASCII: bool = 97u8.is_ascii();
409409
assert!(BYTE_IS_ASCII);
410410
}
411+
412+
#[test]
413+
fn ascii_ctype_const() {
414+
macro_rules! suite {
415+
( $( $fn:ident => [$a:ident, $A:ident, $nine:ident, $dot:ident, $space:ident]; )* ) => {
416+
$(
417+
mod $fn {
418+
const CHAR_A_LOWER: bool = 'a'.$fn();
419+
const CHAR_A_UPPER: bool = 'A'.$fn();
420+
const CHAR_NINE: bool = '9'.$fn();
421+
const CHAR_DOT: bool = '.'.$fn();
422+
const CHAR_SPACE: bool = ' '.$fn();
423+
424+
const U8_A_LOWER: bool = b'a'.$fn();
425+
const U8_A_UPPER: bool = b'A'.$fn();
426+
const U8_NINE: bool = b'9'.$fn();
427+
const U8_DOT: bool = b'.'.$fn();
428+
const U8_SPACE: bool = b' '.$fn();
429+
430+
pub fn run() {
431+
assert_eq!(CHAR_A_LOWER, $a);
432+
assert_eq!(CHAR_A_UPPER, $A);
433+
assert_eq!(CHAR_NINE, $nine);
434+
assert_eq!(CHAR_DOT, $dot);
435+
assert_eq!(CHAR_SPACE, $space);
436+
437+
assert_eq!(U8_A_LOWER, $a);
438+
assert_eq!(U8_A_UPPER, $A);
439+
assert_eq!(U8_NINE, $nine);
440+
assert_eq!(U8_DOT, $dot);
441+
assert_eq!(U8_SPACE, $space);
442+
}
443+
}
444+
)*
445+
446+
$( $fn::run(); )*
447+
}
448+
}
449+
450+
suite! {
451+
// 'a' 'A' '9' '.' ' '
452+
is_ascii_alphabetic => [true, true, false, false, false];
453+
is_ascii_uppercase => [false, true, false, false, false];
454+
is_ascii_lowercase => [true, false, false, false, false];
455+
is_ascii_alphanumeric => [true, true, true, false, false];
456+
is_ascii_digit => [false, false, true, false, false];
457+
is_ascii_hexdigit => [true, true, true, false, false];
458+
is_ascii_punctuation => [false, false, false, true, false];
459+
is_ascii_graphic => [true, true, true, true, false];
460+
is_ascii_whitespace => [false, false, false, false, true];
461+
is_ascii_control => [false, false, false, false, false];
462+
}
463+
}

library/core/tests/atomic.rs

+79
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,82 @@ fn static_init() {
101101
assert!(S_INT.fetch_add(1, SeqCst) == 0);
102102
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
103103
}
104+
105+
#[test]
106+
fn atomic_access_bool() {
107+
static mut ATOMIC: AtomicBool = AtomicBool::new(false);
108+
109+
unsafe {
110+
assert_eq!(*ATOMIC.get_mut(), false);
111+
ATOMIC.store(true, SeqCst);
112+
assert_eq!(*ATOMIC.get_mut(), true);
113+
ATOMIC.fetch_or(false, SeqCst);
114+
assert_eq!(*ATOMIC.get_mut(), true);
115+
ATOMIC.fetch_and(false, SeqCst);
116+
assert_eq!(*ATOMIC.get_mut(), false);
117+
ATOMIC.fetch_nand(true, SeqCst);
118+
assert_eq!(*ATOMIC.get_mut(), true);
119+
ATOMIC.fetch_xor(true, SeqCst);
120+
assert_eq!(*ATOMIC.get_mut(), false);
121+
}
122+
}
123+
124+
#[test]
125+
fn atomic_alignment() {
126+
use std::mem::{align_of, size_of};
127+
128+
#[cfg(target_has_atomic = "8")]
129+
assert_eq!(align_of::<AtomicBool>(), size_of::<AtomicBool>());
130+
#[cfg(target_has_atomic = "ptr")]
131+
assert_eq!(align_of::<AtomicPtr<u8>>(), size_of::<AtomicPtr<u8>>());
132+
#[cfg(target_has_atomic = "8")]
133+
assert_eq!(align_of::<AtomicU8>(), size_of::<AtomicU8>());
134+
#[cfg(target_has_atomic = "8")]
135+
assert_eq!(align_of::<AtomicI8>(), size_of::<AtomicI8>());
136+
#[cfg(target_has_atomic = "16")]
137+
assert_eq!(align_of::<AtomicU16>(), size_of::<AtomicU16>());
138+
#[cfg(target_has_atomic = "16")]
139+
assert_eq!(align_of::<AtomicI16>(), size_of::<AtomicI16>());
140+
#[cfg(target_has_atomic = "32")]
141+
assert_eq!(align_of::<AtomicU32>(), size_of::<AtomicU32>());
142+
#[cfg(target_has_atomic = "32")]
143+
assert_eq!(align_of::<AtomicI32>(), size_of::<AtomicI32>());
144+
#[cfg(target_has_atomic = "64")]
145+
assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>());
146+
#[cfg(target_has_atomic = "64")]
147+
assert_eq!(align_of::<AtomicI64>(), size_of::<AtomicI64>());
148+
#[cfg(target_has_atomic = "128")]
149+
assert_eq!(align_of::<AtomicU128>(), size_of::<AtomicU128>());
150+
#[cfg(target_has_atomic = "128")]
151+
assert_eq!(align_of::<AtomicI128>(), size_of::<AtomicI128>());
152+
#[cfg(target_has_atomic = "ptr")]
153+
assert_eq!(align_of::<AtomicUsize>(), size_of::<AtomicUsize>());
154+
#[cfg(target_has_atomic = "ptr")]
155+
assert_eq!(align_of::<AtomicIsize>(), size_of::<AtomicIsize>());
156+
}
157+
158+
#[test]
159+
fn atomic_compare_exchange() {
160+
use Ordering::*;
161+
162+
static ATOMIC: AtomicIsize = AtomicIsize::new(0);
163+
164+
ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok();
165+
ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok();
166+
ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok();
167+
ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok();
168+
ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok();
169+
ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok();
170+
ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok();
171+
ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok();
172+
ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok();
173+
ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
174+
ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
175+
ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok();
176+
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
177+
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
178+
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
179+
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
180+
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
181+
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
182+
}

library/core/tests/bool.rs

+84
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,87 @@
1+
use core::cmp::Ordering::{Equal, Greater, Less};
2+
use core::ops::{BitAnd, BitOr, BitXor};
3+
4+
#[test]
5+
fn test_bool() {
6+
assert_eq!(false.eq(&true), false);
7+
assert_eq!(false == false, true);
8+
assert_eq!(false != true, true);
9+
assert_eq!(false.ne(&false), false);
10+
11+
assert_eq!(false.bitand(false), false);
12+
assert_eq!(true.bitand(false), false);
13+
assert_eq!(false.bitand(true), false);
14+
assert_eq!(true.bitand(true), true);
15+
16+
assert_eq!(false & false, false);
17+
assert_eq!(true & false, false);
18+
assert_eq!(false & true, false);
19+
assert_eq!(true & true, true);
20+
21+
assert_eq!(false.bitor(false), false);
22+
assert_eq!(true.bitor(false), true);
23+
assert_eq!(false.bitor(true), true);
24+
assert_eq!(true.bitor(true), true);
25+
26+
assert_eq!(false | false, false);
27+
assert_eq!(true | false, true);
28+
assert_eq!(false | true, true);
29+
assert_eq!(true | true, true);
30+
31+
assert_eq!(false.bitxor(false), false);
32+
assert_eq!(true.bitxor(false), true);
33+
assert_eq!(false.bitxor(true), true);
34+
assert_eq!(true.bitxor(true), false);
35+
36+
assert_eq!(false ^ false, false);
37+
assert_eq!(true ^ false, true);
38+
assert_eq!(false ^ true, true);
39+
assert_eq!(true ^ true, false);
40+
41+
assert_eq!(!true, false);
42+
assert_eq!(!false, true);
43+
44+
let s = false.to_string();
45+
assert_eq!(s, "false");
46+
let s = true.to_string();
47+
assert_eq!(s, "true");
48+
49+
assert!(true > false);
50+
assert!(!(false > true));
51+
52+
assert!(false < true);
53+
assert!(!(true < false));
54+
55+
assert!(false <= false);
56+
assert!(false >= false);
57+
assert!(true <= true);
58+
assert!(true >= true);
59+
60+
assert!(false <= true);
61+
assert!(!(false >= true));
62+
assert!(true >= false);
63+
assert!(!(true <= false));
64+
65+
assert_eq!(true.cmp(&true), Equal);
66+
assert_eq!(false.cmp(&false), Equal);
67+
assert_eq!(true.cmp(&false), Greater);
68+
assert_eq!(false.cmp(&true), Less);
69+
}
70+
71+
#[test]
72+
pub fn test_bool_not() {
73+
if !false {
74+
assert!((true));
75+
} else {
76+
assert!((false));
77+
}
78+
if !true {
79+
assert!((false));
80+
} else {
81+
assert!((true));
82+
}
83+
}
84+
185
#[test]
286
fn test_bool_to_option() {
387
assert_eq!(false.then_some(0), None);

0 commit comments

Comments
 (0)