Skip to content

Commit

Permalink
Auto merge of rust-lang#79596 - m-ou-se:rollup-hujx3c7, r=m-ou-se
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - rust-lang#79038 (Change ui test that are run-pass and that do not test the compiler to library tests)
 - rust-lang#79184 (Stop adding '*' at the end of slice and str typenames for MSVC case)
 - rust-lang#79227 (Remove const_fn_feature_flags test)
 - rust-lang#79444 (Move const ip in ui test to unit test)
 - rust-lang#79522 (Validate lint docs separately.)
 - rust-lang#79525 (Add -Z normalize-docs and enable it for compiler docs)
 - rust-lang#79527 (Move intra-doc link tests into a subdirectory)
 - rust-lang#79548 (Show since when a function is const in stdlib)
 - rust-lang#79568 (update Miri)
 - rust-lang#79573 (Update with status for various NetBSD ports.)
 - rust-lang#79583 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 1, 2020
2 parents 0fa9d31 + c06a00e commit b2dd829
Show file tree
Hide file tree
Showing 159 changed files with 1,878 additions and 1,740 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,7 @@ dependencies = [
"rustc-workspace-hack",
"rustc_version",
"shell-escape",
"smallvec 1.4.2",
]

[[package]]
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ pub fn push_debuginfo_type_name<'tcx>(
push_debuginfo_type_name(tcx, inner_type, true, output, visited);

if cpp_like_names {
output.push('*');
// Slices and `&str` are treated like C++ pointers when computing debug
// info for MSVC debugger. However, adding '*' at the end of these types' names
// causes the .natvis engine for WinDbg to fail to display their data, so we opt these
// types out to aid debugging in MSVC.
match *inner_type.kind() {
ty::Slice(_) | ty::Str => {}
_ => output.push('*'),
}
}
}
ty::Array(inner_type, len) => {
Expand Down
24 changes: 19 additions & 5 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,25 @@ impl LintBuffer {
/// ```
///
/// The `{{produces}}` tag will be automatically replaced with the output from
/// the example by the build system. You can build and view the rustc book
/// with `x.py doc --stage=1 src/doc/rustc --open`. If the lint example is too
/// complex to run as a simple example (for example, it needs an extern
/// crate), mark it with `ignore` and manually paste the expected output below
/// the example.
/// the example by the build system. If the lint example is too complex to run
/// as a simple example (for example, it needs an extern crate), mark the code
/// block with `ignore` and manually replace the `{{produces}}` line with the
/// expected output in a `text` code block.
///
/// If this is a rustdoc-only lint, then only include a brief introduction
/// with a link with the text `[rustdoc book]` so that the validator knows
/// that this is for rustdoc only (see BROKEN_INTRA_DOC_LINKS as an example).
///
/// Commands to view and test the documentation:
///
/// * `./x.py doc --stage=1 src/doc/rustc --open`: Builds the rustc book and opens it.
/// * `./x.py test src/tools/lint-docs`: Validates that the lint docs have the
/// correct style, and that the code example actually emits the expected
/// lint.
///
/// If you have already built the compiler, and you want to make changes to
/// just the doc comments, then use the `--keep-stage=0` flag with the above
/// commands to avoid rebuilding the compiler.
#[macro_export]
macro_rules! declare_lint {
($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
"prevent automatic injection of the profiler_builtins crate"),
normalize_docs: bool = (false, parse_bool, [TRACKED],
"normalize associated items in rustdoc when generating documentation"),
osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
"pass `-install_name @rpath/...` to the macOS linker (default: no)"),
panic_abort_tests: bool = (false, parse_bool, [TRACKED],
Expand Down
96 changes: 95 additions & 1 deletion library/alloc/tests/str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::cmp::Ordering::{Equal, Greater, Less};
use std::str::from_utf8;
use std::str::{from_utf8, from_utf8_unchecked};

#[test]
fn test_le() {
Expand Down Expand Up @@ -1971,3 +1971,97 @@ fn test_str_escapes() {
";
assert_eq!(x, r"\\"); // extraneous whitespace stripped
}

#[test]
fn const_str_ptr() {
const A: [u8; 2] = ['h' as u8, 'i' as u8];
const B: &'static [u8; 2] = &A;
const C: *const u8 = B as *const u8;

unsafe {
let foo = &A as *const u8;
assert_eq!(foo, C);
assert_eq!(from_utf8_unchecked(&A), "hi");
assert_eq!(*C, A[0]);
assert_eq!(*(&B[0] as *const u8), A[0]);
}
}

#[test]
fn utf8() {
let yen: char = '¥'; // 0xa5
let c_cedilla: char = 'ç'; // 0xe7
let thorn: char = 'þ'; // 0xfe
let y_diaeresis: char = 'ÿ'; // 0xff
let pi: char = 'Π'; // 0x3a0

assert_eq!(yen as isize, 0xa5);
assert_eq!(c_cedilla as isize, 0xe7);
assert_eq!(thorn as isize, 0xfe);
assert_eq!(y_diaeresis as isize, 0xff);
assert_eq!(pi as isize, 0x3a0);

assert_eq!(pi as isize, '\u{3a0}' as isize);
assert_eq!('\x0a' as isize, '\n' as isize);

let bhutan: String = "འབྲུག་ཡུལ།".to_string();
let japan: String = "日本".to_string();
let uzbekistan: String = "Ўзбекистон".to_string();
let austria: String = "Österreich".to_string();

let bhutan_e: String =
"\u{f60}\u{f56}\u{fb2}\u{f74}\u{f42}\u{f0b}\u{f61}\u{f74}\u{f63}\u{f0d}".to_string();
let japan_e: String = "\u{65e5}\u{672c}".to_string();
let uzbekistan_e: String =
"\u{40e}\u{437}\u{431}\u{435}\u{43a}\u{438}\u{441}\u{442}\u{43e}\u{43d}".to_string();
let austria_e: String = "\u{d6}sterreich".to_string();

let oo: char = 'Ö';
assert_eq!(oo as isize, 0xd6);

fn check_str_eq(a: String, b: String) {
let mut i: isize = 0;
for ab in a.bytes() {
println!("{}", i);
println!("{}", ab);
let bb: u8 = b.as_bytes()[i as usize];
println!("{}", bb);
assert_eq!(ab, bb);
i += 1;
}
}

check_str_eq(bhutan, bhutan_e);
check_str_eq(japan, japan_e);
check_str_eq(uzbekistan, uzbekistan_e);
check_str_eq(austria, austria_e);
}

#[test]
fn utf8_chars() {
// Chars of 1, 2, 3, and 4 bytes
let chs: Vec<char> = vec!['e', 'é', '€', '\u{10000}'];
let s: String = chs.iter().cloned().collect();
let schs: Vec<char> = s.chars().collect();

assert_eq!(s.len(), 10);
assert_eq!(s.chars().count(), 4);
assert_eq!(schs.len(), 4);
assert_eq!(schs.iter().cloned().collect::<String>(), s);

assert!((from_utf8(s.as_bytes()).is_ok()));
// invalid prefix
assert!((!from_utf8(&[0x80]).is_ok()));
// invalid 2 byte prefix
assert!((!from_utf8(&[0xc0]).is_ok()));
assert!((!from_utf8(&[0xc0, 0x10]).is_ok()));
// invalid 3 byte prefix
assert!((!from_utf8(&[0xe0]).is_ok()));
assert!((!from_utf8(&[0xe0, 0x10]).is_ok()));
assert!((!from_utf8(&[0xe0, 0xff, 0x10]).is_ok()));
// invalid 4 byte prefix
assert!((!from_utf8(&[0xf0]).is_ok()));
assert!((!from_utf8(&[0xf0, 0x10]).is_ok()));
assert!((!from_utf8(&[0xf0, 0xff, 0x10]).is_ok()));
assert!((!from_utf8(&[0xf0, 0xff, 0xff, 0x10]).is_ok()));
}
53 changes: 53 additions & 0 deletions library/core/tests/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,56 @@ fn ascii_const() {
const BYTE_IS_ASCII: bool = 97u8.is_ascii();
assert!(BYTE_IS_ASCII);
}

#[test]
fn ascii_ctype_const() {
macro_rules! suite {
( $( $fn:ident => [$a:ident, $A:ident, $nine:ident, $dot:ident, $space:ident]; )* ) => {
$(
mod $fn {
const CHAR_A_LOWER: bool = 'a'.$fn();
const CHAR_A_UPPER: bool = 'A'.$fn();
const CHAR_NINE: bool = '9'.$fn();
const CHAR_DOT: bool = '.'.$fn();
const CHAR_SPACE: bool = ' '.$fn();

const U8_A_LOWER: bool = b'a'.$fn();
const U8_A_UPPER: bool = b'A'.$fn();
const U8_NINE: bool = b'9'.$fn();
const U8_DOT: bool = b'.'.$fn();
const U8_SPACE: bool = b' '.$fn();

pub fn run() {
assert_eq!(CHAR_A_LOWER, $a);
assert_eq!(CHAR_A_UPPER, $A);
assert_eq!(CHAR_NINE, $nine);
assert_eq!(CHAR_DOT, $dot);
assert_eq!(CHAR_SPACE, $space);

assert_eq!(U8_A_LOWER, $a);
assert_eq!(U8_A_UPPER, $A);
assert_eq!(U8_NINE, $nine);
assert_eq!(U8_DOT, $dot);
assert_eq!(U8_SPACE, $space);
}
}
)*

$( $fn::run(); )*
}
}

suite! {
// 'a' 'A' '9' '.' ' '
is_ascii_alphabetic => [true, true, false, false, false];
is_ascii_uppercase => [false, true, false, false, false];
is_ascii_lowercase => [true, false, false, false, false];
is_ascii_alphanumeric => [true, true, true, false, false];
is_ascii_digit => [false, false, true, false, false];
is_ascii_hexdigit => [true, true, true, false, false];
is_ascii_punctuation => [false, false, false, true, false];
is_ascii_graphic => [true, true, true, true, false];
is_ascii_whitespace => [false, false, false, false, true];
is_ascii_control => [false, false, false, false, false];
}
}
79 changes: 79 additions & 0 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,82 @@ fn static_init() {
assert!(S_INT.fetch_add(1, SeqCst) == 0);
assert!(S_UINT.fetch_add(1, SeqCst) == 0);
}

#[test]
fn atomic_access_bool() {
static mut ATOMIC: AtomicBool = AtomicBool::new(false);

unsafe {
assert_eq!(*ATOMIC.get_mut(), false);
ATOMIC.store(true, SeqCst);
assert_eq!(*ATOMIC.get_mut(), true);
ATOMIC.fetch_or(false, SeqCst);
assert_eq!(*ATOMIC.get_mut(), true);
ATOMIC.fetch_and(false, SeqCst);
assert_eq!(*ATOMIC.get_mut(), false);
ATOMIC.fetch_nand(true, SeqCst);
assert_eq!(*ATOMIC.get_mut(), true);
ATOMIC.fetch_xor(true, SeqCst);
assert_eq!(*ATOMIC.get_mut(), false);
}
}

#[test]
fn atomic_alignment() {
use std::mem::{align_of, size_of};

#[cfg(target_has_atomic = "8")]
assert_eq!(align_of::<AtomicBool>(), size_of::<AtomicBool>());
#[cfg(target_has_atomic = "ptr")]
assert_eq!(align_of::<AtomicPtr<u8>>(), size_of::<AtomicPtr<u8>>());
#[cfg(target_has_atomic = "8")]
assert_eq!(align_of::<AtomicU8>(), size_of::<AtomicU8>());
#[cfg(target_has_atomic = "8")]
assert_eq!(align_of::<AtomicI8>(), size_of::<AtomicI8>());
#[cfg(target_has_atomic = "16")]
assert_eq!(align_of::<AtomicU16>(), size_of::<AtomicU16>());
#[cfg(target_has_atomic = "16")]
assert_eq!(align_of::<AtomicI16>(), size_of::<AtomicI16>());
#[cfg(target_has_atomic = "32")]
assert_eq!(align_of::<AtomicU32>(), size_of::<AtomicU32>());
#[cfg(target_has_atomic = "32")]
assert_eq!(align_of::<AtomicI32>(), size_of::<AtomicI32>());
#[cfg(target_has_atomic = "64")]
assert_eq!(align_of::<AtomicU64>(), size_of::<AtomicU64>());
#[cfg(target_has_atomic = "64")]
assert_eq!(align_of::<AtomicI64>(), size_of::<AtomicI64>());
#[cfg(target_has_atomic = "128")]
assert_eq!(align_of::<AtomicU128>(), size_of::<AtomicU128>());
#[cfg(target_has_atomic = "128")]
assert_eq!(align_of::<AtomicI128>(), size_of::<AtomicI128>());
#[cfg(target_has_atomic = "ptr")]
assert_eq!(align_of::<AtomicUsize>(), size_of::<AtomicUsize>());
#[cfg(target_has_atomic = "ptr")]
assert_eq!(align_of::<AtomicIsize>(), size_of::<AtomicIsize>());
}

#[test]
fn atomic_compare_exchange() {
use Ordering::*;

static ATOMIC: AtomicIsize = AtomicIsize::new(0);

ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok();
ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok();
ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok();
ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok();
ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok();
ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok();
ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok();
ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok();
}
84 changes: 84 additions & 0 deletions library/core/tests/bool.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
use core::cmp::Ordering::{Equal, Greater, Less};
use core::ops::{BitAnd, BitOr, BitXor};

#[test]
fn test_bool() {
assert_eq!(false.eq(&true), false);
assert_eq!(false == false, true);
assert_eq!(false != true, true);
assert_eq!(false.ne(&false), false);

assert_eq!(false.bitand(false), false);
assert_eq!(true.bitand(false), false);
assert_eq!(false.bitand(true), false);
assert_eq!(true.bitand(true), true);

assert_eq!(false & false, false);
assert_eq!(true & false, false);
assert_eq!(false & true, false);
assert_eq!(true & true, true);

assert_eq!(false.bitor(false), false);
assert_eq!(true.bitor(false), true);
assert_eq!(false.bitor(true), true);
assert_eq!(true.bitor(true), true);

assert_eq!(false | false, false);
assert_eq!(true | false, true);
assert_eq!(false | true, true);
assert_eq!(true | true, true);

assert_eq!(false.bitxor(false), false);
assert_eq!(true.bitxor(false), true);
assert_eq!(false.bitxor(true), true);
assert_eq!(true.bitxor(true), false);

assert_eq!(false ^ false, false);
assert_eq!(true ^ false, true);
assert_eq!(false ^ true, true);
assert_eq!(true ^ true, false);

assert_eq!(!true, false);
assert_eq!(!false, true);

let s = false.to_string();
assert_eq!(s, "false");
let s = true.to_string();
assert_eq!(s, "true");

assert!(true > false);
assert!(!(false > true));

assert!(false < true);
assert!(!(true < false));

assert!(false <= false);
assert!(false >= false);
assert!(true <= true);
assert!(true >= true);

assert!(false <= true);
assert!(!(false >= true));
assert!(true >= false);
assert!(!(true <= false));

assert_eq!(true.cmp(&true), Equal);
assert_eq!(false.cmp(&false), Equal);
assert_eq!(true.cmp(&false), Greater);
assert_eq!(false.cmp(&true), Less);
}

#[test]
pub fn test_bool_not() {
if !false {
assert!((true));
} else {
assert!((false));
}
if !true {
assert!((false));
} else {
assert!((true));
}
}

#[test]
fn test_bool_to_option() {
assert_eq!(false.then_some(0), None);
Expand Down
Loading

0 comments on commit b2dd829

Please sign in to comment.