diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rustdoc-js/substring.js | 22 | ||||
| -rw-r--r-- | tests/rustdoc-js/substring.rs | 2 | ||||
| -rw-r--r-- | tests/ui-fulldeps/stable-mir/check_allocation.rs | 22 |
3 files changed, 39 insertions, 7 deletions
diff --git a/tests/rustdoc-js/substring.js b/tests/rustdoc-js/substring.js index 96efa992bb6..b791ac4bfd1 100644 --- a/tests/rustdoc-js/substring.js +++ b/tests/rustdoc-js/substring.js @@ -1,7 +1,15 @@ -const EXPECTED = { - 'query': 'waker_from', - 'others': [ - { 'path': 'substring::SuperWaker', 'name': 'local_waker_from_nonlocal' }, - { 'path': 'substring::SuperWakerTask', 'name': 'local_waker_from_nonlocal' }, - ], -}; +const EXPECTED = [ + { + 'query': 'waker_from', + 'others': [ + { 'path': 'substring::SuperWaker', 'name': 'local_waker_from_nonlocal' }, + { 'path': 'substring::SuperWakerTask', 'name': 'local_waker_from_nonlocal' }, + ], + }, + { + 'query': 'my', + 'others': [ + { 'path': 'substring', 'name': 'm_y_substringmatching' }, + ], + }, +]; diff --git a/tests/rustdoc-js/substring.rs b/tests/rustdoc-js/substring.rs index e729c722c79..ea88894d03d 100644 --- a/tests/rustdoc-js/substring.rs +++ b/tests/rustdoc-js/substring.rs @@ -19,3 +19,5 @@ impl SuperWakerTask { pub fn waker_non_local() {} pub fn from_non_local() {} } + +pub fn m_y_substringmatching() {} diff --git a/tests/ui-fulldeps/stable-mir/check_allocation.rs b/tests/ui-fulldeps/stable-mir/check_allocation.rs index 88c41537d9f..8554630e9c9 100644 --- a/tests/ui-fulldeps/stable-mir/check_allocation.rs +++ b/tests/ui-fulldeps/stable-mir/check_allocation.rs @@ -33,6 +33,7 @@ use std::ascii::Char; use std::assert_matches::assert_matches; use std::cmp::{max, min}; use std::collections::HashMap; +use std::ffi::CStr; use std::io::Write; use std::ops::ControlFlow; @@ -45,6 +46,7 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> { check_foo(*get_item(&items, (ItemKind::Static, "FOO")).unwrap()); check_bar(*get_item(&items, (ItemKind::Static, "BAR")).unwrap()); check_len(*get_item(&items, (ItemKind::Static, "LEN")).unwrap()); + check_cstr(*get_item(&items, (ItemKind::Static, "C_STR")).unwrap()); check_other_consts(*get_item(&items, (ItemKind::Fn, "other_consts")).unwrap()); check_type_id(*get_item(&items, (ItemKind::Fn, "check_type_id")).unwrap()); ControlFlow::Continue(()) @@ -86,6 +88,24 @@ fn check_bar(item: CrateItem) { assert_eq!(std::str::from_utf8(&allocation.raw_bytes().unwrap()), Ok("Bar")); } +/// Check the allocation data for static `C_STR`. +/// +/// ```no_run +/// static C_STR: &core::ffi::cstr = c"cstr"; +/// ``` +fn check_cstr(item: CrateItem) { + let def = StaticDef::try_from(item).unwrap(); + let alloc = def.eval_initializer().unwrap(); + assert_eq!(alloc.provenance.ptrs.len(), 1); + let deref = item.ty().kind().builtin_deref(true).unwrap(); + assert!(deref.ty.kind().is_cstr(), "Expected CStr, but got: {:?}", item.ty()); + + let alloc_id_0 = alloc.provenance.ptrs[0].1.0; + let GlobalAlloc::Memory(allocation) = GlobalAlloc::from(alloc_id_0) else { unreachable!() }; + assert_eq!(allocation.bytes.len(), 5); + assert_eq!(CStr::from_bytes_until_nul(&allocation.raw_bytes().unwrap()), Ok(c"cstr")); +} + /// Check the allocation data for constants used in `other_consts` function. fn check_other_consts(item: CrateItem) { // Instance body will force constant evaluation. @@ -206,6 +226,7 @@ fn main() { generate_input(&path).unwrap(); let args = vec![ "rustc".to_string(), + "--edition=2021".to_string(), "--crate-name".to_string(), CRATE_NAME.to_string(), path.to_string(), @@ -224,6 +245,7 @@ fn generate_input(path: &str) -> std::io::Result<()> { static LEN: usize = 2; static FOO: [&str; 2] = ["hi", "there"]; static BAR: &str = "Bar"; + static C_STR: &std::ffi::CStr = c"cstr"; const NULL: *const u8 = std::ptr::null(); const TUPLE: (u32, u32) = (10, u32::MAX); |
