Skip to content

Commit 6d3db55

Browse files
committed
Auto merge of #134822 - jieyouxu:rollup-5xuaq82, r=jieyouxu
Rollup of 8 pull requests Successful merges: - #134606 (ptr::copy: fix docs for the overlapping case) - #134622 (Windows: Use WriteFile to write to a UTF-8 console) - #134759 (compiletest: Remove the `-test` suffix from normalize directives) - #134787 (Spruce up the docs of several queries related to the type/trait system and const eval) - #134806 (rustdoc: use shorter paths as preferred canonical paths) - #134815 (Sort triples by name in platform_support.md) - #134816 (tools: fix build failure caused by PR #134420) - #134819 (Fix mistake in windows file open) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 42591a4 + 5544091 commit 6d3db55

File tree

263 files changed

+897
-691
lines changed

Some content is hidden

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

263 files changed

+897
-691
lines changed

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@ fn parent_impl_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness
1515
}
1616
}
1717

18-
/// Checks whether an item is considered to be `const`. If it is a constructor, it is const.
19-
/// If it is an assoc method or function,
20-
/// return if it has a `const` modifier. If it is an intrinsic, report whether said intrinsic
21-
/// has a `rustc_const_{un,}stable` attribute. Otherwise, panic.
18+
/// Checks whether a function-like definition is considered to be `const`.
2219
fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
2320
let node = tcx.hir_node_by_def_id(def_id);
2421

2522
match node {
26-
hir::Node::Ctor(hir::VariantData::Tuple(..))
27-
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. }) => {
28-
hir::Constness::Const
29-
}
30-
hir::Node::ForeignItem(_) => {
31-
// Foreign items cannot be evaluated at compile-time.
23+
hir::Node::Ctor(hir::VariantData::Tuple(..)) => hir::Constness::Const,
24+
hir::Node::ForeignItem(item) if let hir::ForeignItemKind::Fn(..) = item.kind => {
25+
// Foreign functions cannot be evaluated at compile-time.
3226
hir::Constness::NotConst
3327
}
3428
hir::Node::Expr(e) if let hir::ExprKind::Closure(c) = e.kind => c.constness,

compiler/rustc_const_eval/src/interpret/memory.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
13591359
let src_alloc = self.get_alloc_raw(src_alloc_id)?;
13601360
let src_range = alloc_range(src_offset, size);
13611361
assert!(!self.memory.validation_in_progress, "we can't be copying during validation");
1362+
// For the overlapping case, it is crucial that we trigger the read hook
1363+
// before the write hook -- the aliasing model cares about the order.
13621364
M::before_memory_read(
13631365
tcx,
13641366
&self.machine,

compiler/rustc_middle/src/query/mod.rs

+217-94
Large diffs are not rendered by default.

library/core/src/intrinsics/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4364,13 +4364,11 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
43644364
///
43654365
/// Behavior is undefined if any of the following conditions are violated:
43664366
///
4367-
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes, and must remain valid even
4368-
/// when `dst` is written for `count * size_of::<T>()` bytes. (This means if the memory ranges
4369-
/// overlap, the two pointers must not be subject to aliasing restrictions relative to each
4370-
/// other.)
4367+
/// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
43714368
///
43724369
/// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes, and must remain valid even
4373-
/// when `src` is read for `count * size_of::<T>()` bytes.
4370+
/// when `src` is read for `count * size_of::<T>()` bytes. (This means if the memory ranges
4371+
/// overlap, the `dst` pointer must not be invalidated by `src` reads.)
43744372
///
43754373
/// * Both `src` and `dst` must be properly aligned.
43764374
///

library/std/src/sys/pal/windows/c/bindings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2426,6 +2426,7 @@ Windows.Win32.System.Console.ENABLE_VIRTUAL_TERMINAL_PROCESSING
24262426
Windows.Win32.System.Console.ENABLE_WINDOW_INPUT
24272427
Windows.Win32.System.Console.ENABLE_WRAP_AT_EOL_OUTPUT
24282428
Windows.Win32.System.Console.GetConsoleMode
2429+
Windows.Win32.System.Console.GetConsoleOutputCP
24292430
Windows.Win32.System.Console.GetStdHandle
24302431
Windows.Win32.System.Console.ReadConsoleW
24312432
Windows.Win32.System.Console.STD_ERROR_HANDLE

library/std/src/sys/pal/windows/c/windows_sys.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ windows_targets::link!("kernel32.dll" "system" fn FreeEnvironmentStringsW(penv :
3434
windows_targets::link!("kernel32.dll" "system" fn GetActiveProcessorCount(groupnumber : u16) -> u32);
3535
windows_targets::link!("kernel32.dll" "system" fn GetCommandLineW() -> PCWSTR);
3636
windows_targets::link!("kernel32.dll" "system" fn GetConsoleMode(hconsolehandle : HANDLE, lpmode : *mut CONSOLE_MODE) -> BOOL);
37+
windows_targets::link!("kernel32.dll" "system" fn GetConsoleOutputCP() -> u32);
3738
windows_targets::link!("kernel32.dll" "system" fn GetCurrentDirectoryW(nbufferlength : u32, lpbuffer : PWSTR) -> u32);
3839
windows_targets::link!("kernel32.dll" "system" fn GetCurrentProcess() -> HANDLE);
3940
windows_targets::link!("kernel32.dll" "system" fn GetCurrentProcessId() -> u32);
@@ -3333,6 +3334,7 @@ pub struct XSAVE_FORMAT {
33333334
pub XmmRegisters: [M128A; 8],
33343335
pub Reserved4: [u8; 224],
33353336
}
3337+
33363338
#[cfg(target_arch = "arm")]
33373339
#[repr(C)]
33383340
pub struct WSADATA {

library/std/src/sys/pal/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl File {
323323
let alloc = c::FILE_ALLOCATION_INFO { AllocationSize: 0 };
324324
let result = c::SetFileInformationByHandle(
325325
handle.as_raw_handle(),
326-
c::FileEndOfFileInfo,
326+
c::FileAllocationInfo,
327327
(&raw const alloc).cast::<c_void>(),
328328
mem::size_of::<c::FILE_ALLOCATION_INFO>() as u32,
329329
);

library/std/src/sys/pal/windows/stdio.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,43 @@ fn is_console(handle: c::HANDLE) -> bool {
8484
unsafe { c::GetConsoleMode(handle, &mut mode) != 0 }
8585
}
8686

87+
/// Returns true if the attached console's code page is currently UTF-8.
88+
#[cfg(not(target_vendor = "win7"))]
89+
fn is_utf8_console() -> bool {
90+
unsafe { c::GetConsoleOutputCP() == c::CP_UTF8 }
91+
}
92+
93+
#[cfg(target_vendor = "win7")]
94+
fn is_utf8_console() -> bool {
95+
// Windows 7 has a fun "feature" where WriteFile on a console handle will return
96+
// the number of UTF-16 code units written and not the number of bytes from the input string.
97+
// So we always claim the console isn't UTF-8 to trigger the WriteConsole fallback code.
98+
false
99+
}
100+
87101
fn write(handle_id: u32, data: &[u8], incomplete_utf8: &mut IncompleteUtf8) -> io::Result<usize> {
88102
if data.is_empty() {
89103
return Ok(0);
90104
}
91105

92106
let handle = get_handle(handle_id)?;
93-
if !is_console(handle) {
107+
if !is_console(handle) || is_utf8_console() {
94108
unsafe {
95109
let handle = Handle::from_raw_handle(handle);
96110
let ret = handle.write(data);
97111
let _ = handle.into_raw_handle(); // Don't close the handle
98112
return ret;
99113
}
114+
} else {
115+
write_console_utf16(data, incomplete_utf8, handle)
100116
}
117+
}
101118

119+
fn write_console_utf16(
120+
data: &[u8],
121+
incomplete_utf8: &mut IncompleteUtf8,
122+
handle: c::HANDLE,
123+
) -> io::Result<usize> {
102124
if incomplete_utf8.len > 0 {
103125
assert!(
104126
incomplete_utf8.len < 4,

0 commit comments

Comments
 (0)