From 3983881d4e00c2b12d1b5b0319b4c61d72926917 Mon Sep 17 00:00:00 2001 From: yukang <moorekang@gmail.com> Date: Tue, 6 Jun 2023 23:51:09 +0800 Subject: [PATCH 01/11] take care module name for suggesting surround the struct literal in parentheses --- .../rustc_parse/src/parser/diagnostics.rs | 10 +++- compiler/rustc_span/src/source_map.rs | 12 +++++ tests/ui/parser/issues/issue-111692.rs | 32 +++++++++++++ tests/ui/parser/issues/issue-111692.stderr | 46 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 tests/ui/parser/issues/issue-111692.rs create mode 100644 tests/ui/parser/issues/issue-111692.stderr diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index c1454039685..2abd485b1be 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -751,10 +751,18 @@ impl<'a> Parser<'a> { tail.could_be_bare_literal = true; if maybe_struct_name.is_ident() && can_be_struct_literal { // Account for `if Example { a: one(), }.is_pos() {}`. + // expand `before` so that we take care of module path such as: + // `foo::Bar { ... } ` + // we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })` + let sm = self.sess.source_map(); + let before = maybe_struct_name.span.shrink_to_lo(); + let extend_before = sm.span_extend_prev_while(before, |t| { + t.is_alphanumeric() || t == ':' || t == '_' + }); Err(self.sess.create_err(StructLiteralNeedingParens { span: maybe_struct_name.span.to(expr.span), sugg: StructLiteralNeedingParensSugg { - before: maybe_struct_name.span.shrink_to_lo(), + before: extend_before.unwrap().shrink_to_lo(), after: expr.span.shrink_to_hi(), }, })) diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 1824510a974..f354751112f 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -744,6 +744,18 @@ impl SourceMap { }) } + /// Extends the given `Span` to previous character while the previous character matches the predicate + pub fn span_extend_prev_while( + &self, + span: Span, + f: impl Fn(char) -> bool, + ) -> Result<Span, SpanSnippetError> { + self.span_to_source(span, |s, start, _end| { + let n = s[..start].char_indices().rfind(|&(_, c)| !f(c)).map_or(start, |(i, _)| start - i - 1); + Ok(span.with_lo(span.lo() - BytePos(n as u32))) + }) + } + /// Extends the given `Span` to just before the next occurrence of `c`. pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span { if let Ok(next_source) = self.span_to_next_source(sp) { diff --git a/tests/ui/parser/issues/issue-111692.rs b/tests/ui/parser/issues/issue-111692.rs new file mode 100644 index 00000000000..56096f706a8 --- /dev/null +++ b/tests/ui/parser/issues/issue-111692.rs @@ -0,0 +1,32 @@ +mod module { + #[derive(Eq, PartialEq)] + pub struct Type { + pub x: u8, + pub y: u8, + } + + pub const C: u8 = 32u8; +} + +fn test(x: module::Type) { + if x == module::Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal + } +} + +fn test2(x: module::Type) { + if x ==module::Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal + } +} + + +fn test3(x: module::Type) { + if x == Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal + } +} + +fn test4(x: module::Type) { + if x == demo_module::Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal + } +} + +fn main() { } diff --git a/tests/ui/parser/issues/issue-111692.stderr b/tests/ui/parser/issues/issue-111692.stderr new file mode 100644 index 00000000000..7b09d47301d --- /dev/null +++ b/tests/ui/parser/issues/issue-111692.stderr @@ -0,0 +1,46 @@ +error: invalid struct literal + --> $DIR/issue-111692.rs:12:21 + | +LL | if x == module::Type { x: module::C, y: 1 } { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you might need to surround the struct literal in parentheses + | +LL | if x == (module::Type { x: module::C, y: 1 }) { + | + + + +error: invalid struct literal + --> $DIR/issue-111692.rs:17:20 + | +LL | if x ==module::Type { x: module::C, y: 1 } { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you might need to surround the struct literal in parentheses + | +LL | if x ==(module::Type { x: module::C, y: 1 }) { + | + + + +error: invalid struct literal + --> $DIR/issue-111692.rs:23:13 + | +LL | if x == Type { x: module::C, y: 1 } { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you might need to surround the struct literal in parentheses + | +LL | if x == (Type { x: module::C, y: 1 }) { + | + + + +error: invalid struct literal + --> $DIR/issue-111692.rs:28:26 + | +LL | if x == demo_module::Type { x: module::C, y: 1 } { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: you might need to surround the struct literal in parentheses + | +LL | if x == (demo_module::Type { x: module::C, y: 1 }) { + | + + + +error: aborting due to 4 previous errors + From e3071eaa608301bd4106c304e3c2f433d6507500 Mon Sep 17 00:00:00 2001 From: yukang <moorekang@gmail.com> Date: Tue, 6 Jun 2023 23:56:46 +0800 Subject: [PATCH 02/11] reword the message to suggest surrounding with parentheses --- compiler/rustc_parse/messages.ftl | 2 +- compiler/rustc_span/src/source_map.rs | 5 ++++- tests/ui/parser/issues/issue-111692.stderr | 8 ++++---- .../method-call-on-struct-literal-in-if-condition.stderr | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 9263394508e..35eec2c8e1b 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -695,7 +695,7 @@ parse_struct_literal_body_without_path = parse_struct_literal_needing_parens = invalid struct literal - .suggestion = you might need to surround the struct literal in parentheses + .suggestion = you might need to surround the struct literal with parentheses parse_struct_literal_not_allowed_here = struct literals are not allowed here .suggestion = surround the struct literal with parentheses diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index f354751112f..c53fe084c4d 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -751,7 +751,10 @@ impl SourceMap { f: impl Fn(char) -> bool, ) -> Result<Span, SpanSnippetError> { self.span_to_source(span, |s, start, _end| { - let n = s[..start].char_indices().rfind(|&(_, c)| !f(c)).map_or(start, |(i, _)| start - i - 1); + let n = s[..start] + .char_indices() + .rfind(|&(_, c)| !f(c)) + .map_or(start, |(i, _)| start - i - 1); Ok(span.with_lo(span.lo() - BytePos(n as u32))) }) } diff --git a/tests/ui/parser/issues/issue-111692.stderr b/tests/ui/parser/issues/issue-111692.stderr index 7b09d47301d..068b0483b0f 100644 --- a/tests/ui/parser/issues/issue-111692.stderr +++ b/tests/ui/parser/issues/issue-111692.stderr @@ -4,7 +4,7 @@ error: invalid struct literal LL | if x == module::Type { x: module::C, y: 1 } { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: you might need to surround the struct literal in parentheses +help: you might need to surround the struct literal with parentheses | LL | if x == (module::Type { x: module::C, y: 1 }) { | + + @@ -15,7 +15,7 @@ error: invalid struct literal LL | if x ==module::Type { x: module::C, y: 1 } { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: you might need to surround the struct literal in parentheses +help: you might need to surround the struct literal with parentheses | LL | if x ==(module::Type { x: module::C, y: 1 }) { | + + @@ -26,7 +26,7 @@ error: invalid struct literal LL | if x == Type { x: module::C, y: 1 } { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: you might need to surround the struct literal in parentheses +help: you might need to surround the struct literal with parentheses | LL | if x == (Type { x: module::C, y: 1 }) { | + + @@ -37,7 +37,7 @@ error: invalid struct literal LL | if x == demo_module::Type { x: module::C, y: 1 } { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | -help: you might need to surround the struct literal in parentheses +help: you might need to surround the struct literal with parentheses | LL | if x == (demo_module::Type { x: module::C, y: 1 }) { | + + diff --git a/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr b/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr index 7fd7ffc94a5..dedbad90945 100644 --- a/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr +++ b/tests/ui/parser/method-call-on-struct-literal-in-if-condition.stderr @@ -4,7 +4,7 @@ error: invalid struct literal LL | if Example { a: one(), }.is_pos() { | ^^^^^^^^^^^^^^^^^^^^^ | -help: you might need to surround the struct literal in parentheses +help: you might need to surround the struct literal with parentheses | LL | if (Example { a: one(), }).is_pos() { | + + From f531fec41116afef6c814f7c3201519a54083ae8 Mon Sep 17 00:00:00 2001 From: jyn <github@jyn.dev> Date: Fri, 9 Jun 2023 17:52:22 -0500 Subject: [PATCH 03/11] Give more helpful progress messages in `Assemble` Before (download-rustc): ``` # no output ``` After (download-rustc): ``` Creating a sysroot for stage2 compiler (use `rustup toolchain link 'name' build/host/stage2`) ``` Before (compiling from source): ``` Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu) Assembling stage1 compiler Build stage1 library artifacts (x86_64-unknown-linux-gnu -> i686-unknown-linux-gnu) Building compiler artifacts (stage0:x86_64-unknown-linux-gnu -> stage1:i686-unknown-linux-gnu) Assembling stage1 compiler (i686-unknown-linux-gnu) ``` After (compiling from source): ``` Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu) Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`) Build stage1 library artifacts (x86_64-unknown-linux-gnu) Building compiler artifacts (stage0:x86_64-unknown-linux-gnu -> stage1:i686-unknown-linux-gnu) Creating a sysroot for stage1 compiler (i686-unknown-linux-gnu) (use `rustup toolchain link 'name' build/i686-unknown-linux-gnu/stage1`) ``` --- src/bootstrap/compile.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index a7ebd018a87..b5870dd2093 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1415,6 +1415,10 @@ impl Step for Assemble { // Ensure that `libLLVM.so` ends up in the newly created target directory, // so that tools using `rustc_private` can use it. dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot); + // Lower stages use `ci-rustc-sysroot`, not stageN + if target_compiler.stage == builder.top_stage { + builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage)); + } return target_compiler; } @@ -1452,11 +1456,18 @@ impl Step for Assemble { let stage = target_compiler.stage; let host = target_compiler.host; - let msg = if build_compiler.host == host { - format!("Assembling stage{} compiler", stage) + let (host_info, dir_name) = if build_compiler.host == host { + ("".into(), "host".into()) } else { - format!("Assembling stage{} compiler ({})", stage, host) + (format!(" ({host})"), host.to_string()) }; + // NOTE: "Creating a sysroot" is somewhat inconsistent with our internal terminology, since + // sysroots can temporarily be empty until we put the compiler inside. However, + // `ensure(Sysroot)` isn't really something that's user facing, so there shouldn't be any + // ambiguity. + let msg = format!( + "Creating a sysroot for stage{stage} compiler{host_info} (use `rustup toolchain link 'name' build/{dir_name}/stage{stage}`)" + ); builder.info(&msg); // Link in all dylibs to the libdir From f54e75730bb33d08281c91a9b77332606ec69942 Mon Sep 17 00:00:00 2001 From: yukang <moorekang@gmail.com> Date: Sat, 10 Jun 2023 10:34:19 +0800 Subject: [PATCH 04/11] remove unwrap --- .../rustc_parse/src/parser/diagnostics.rs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 2abd485b1be..228eff1269f 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -756,16 +756,19 @@ impl<'a> Parser<'a> { // we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })` let sm = self.sess.source_map(); let before = maybe_struct_name.span.shrink_to_lo(); - let extend_before = sm.span_extend_prev_while(before, |t| { + if let Ok(extend_before) = sm.span_extend_prev_while(before, |t| { t.is_alphanumeric() || t == ':' || t == '_' - }); - Err(self.sess.create_err(StructLiteralNeedingParens { - span: maybe_struct_name.span.to(expr.span), - sugg: StructLiteralNeedingParensSugg { - before: extend_before.unwrap().shrink_to_lo(), - after: expr.span.shrink_to_hi(), - }, - })) + }) { + Err(self.sess.create_err(StructLiteralNeedingParens { + span: maybe_struct_name.span.to(expr.span), + sugg: StructLiteralNeedingParensSugg { + before: extend_before.shrink_to_lo(), + after: expr.span.shrink_to_hi(), + }, + })) + } else { + return None; + } } else { self.sess.emit_err(StructLiteralBodyWithoutPath { span: expr.span, From 48e410e317c16bb4b844245a32e29844b0d933b7 Mon Sep 17 00:00:00 2001 From: bdbai <bdbaiapp@163.com> Date: Sat, 10 Jun 2023 16:30:26 +0800 Subject: [PATCH 05/11] Lazy load ntdll functions on UWP --- library/std/src/sys/windows/c.rs | 58 +++++++++++++++++++++++++++++ library/std/src/sys/windows/rand.rs | 5 ++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 07b0610d463..929aaf5a266 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -19,6 +19,7 @@ pub use windows_sys::*; pub type DWORD = c_ulong; pub type NonZeroDWORD = NonZero_c_ulong; pub type LARGE_INTEGER = c_longlong; +#[cfg_attr(target_vendor = "uwp", allow(unused))] pub type LONG = c_long; pub type UINT = c_uint; pub type WCHAR = u16; @@ -50,6 +51,9 @@ pub type CONDITION_VARIABLE = RTL_CONDITION_VARIABLE; pub type SRWLOCK = RTL_SRWLOCK; pub type INIT_ONCE = RTL_RUN_ONCE; +#[cfg(target_vendor = "uwp")] +pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _; + pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { Ptr: ptr::null_mut() }; pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { Ptr: ptr::null_mut() }; pub const INIT_ONCE_STATIC_INIT: INIT_ONCE = INIT_ONCE { Ptr: ptr::null_mut() }; @@ -267,6 +271,8 @@ pub unsafe fn getaddrinfo( windows_sys::getaddrinfo(node.cast::<u8>(), service.cast::<u8>(), hints, res) } +cfg_if::cfg_if! { +if #[cfg(not(target_vendor = "uwp"))] { pub unsafe fn NtReadFile( filehandle: BorrowedHandle<'_>, event: HANDLE, @@ -313,6 +319,8 @@ pub unsafe fn NtWriteFile( key.map(|k| k as *const u32).unwrap_or(ptr::null()), ) } +} +} // Functions that aren't available on every version of Windows that we support, // but we still use them and just provide some form of a fallback implementation. @@ -376,4 +384,54 @@ compat_fn_with_fallback! { ) -> NTSTATUS { panic!("keyed events not available") } + + // These functions are available on UWP when lazily loaded. They will fail WACK if loaded statically. + #[cfg(target_vendor = "uwp")] + pub fn NtCreateFile( + filehandle: *mut HANDLE, + desiredaccess: FILE_ACCESS_RIGHTS, + objectattributes: *const OBJECT_ATTRIBUTES, + iostatusblock: *mut IO_STATUS_BLOCK, + allocationsize: *const i64, + fileattributes: FILE_FLAGS_AND_ATTRIBUTES, + shareaccess: FILE_SHARE_MODE, + createdisposition: NTCREATEFILE_CREATE_DISPOSITION, + createoptions: NTCREATEFILE_CREATE_OPTIONS, + eabuffer: *const ::core::ffi::c_void, + ealength: u32 + ) -> NTSTATUS { + STATUS_NOT_IMPLEMENTED + } + #[cfg(target_vendor = "uwp")] + pub fn NtReadFile( + filehandle: BorrowedHandle<'_>, + event: HANDLE, + apcroutine: PIO_APC_ROUTINE, + apccontext: *mut c_void, + iostatusblock: &mut IO_STATUS_BLOCK, + buffer: *mut crate::mem::MaybeUninit<u8>, + length: ULONG, + byteoffset: Option<&LARGE_INTEGER>, + key: Option<&ULONG> + ) -> NTSTATUS { + STATUS_NOT_IMPLEMENTED + } + #[cfg(target_vendor = "uwp")] + pub fn NtWriteFile( + filehandle: BorrowedHandle<'_>, + event: HANDLE, + apcroutine: PIO_APC_ROUTINE, + apccontext: *mut c_void, + iostatusblock: &mut IO_STATUS_BLOCK, + buffer: *const u8, + length: ULONG, + byteoffset: Option<&LARGE_INTEGER>, + key: Option<&ULONG> + ) -> NTSTATUS { + STATUS_NOT_IMPLEMENTED + } + #[cfg(target_vendor = "uwp")] + pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> ULONG { + Status as ULONG + } } diff --git a/library/std/src/sys/windows/rand.rs b/library/std/src/sys/windows/rand.rs index bca4e38d9f6..5d8fd13785a 100644 --- a/library/std/src/sys/windows/rand.rs +++ b/library/std/src/sys/windows/rand.rs @@ -1,5 +1,3 @@ -use crate::ffi::c_void; -use crate::io; use crate::mem; use crate::ptr; use crate::sys::c; @@ -25,6 +23,9 @@ pub fn hashmap_random_keys() -> (u64, u64) { #[cfg(not(target_vendor = "uwp"))] #[inline(never)] fn fallback_rng() -> (u64, u64) { + use crate::ffi::c_void; + use crate::io; + let mut v = (0, 0); let ret = unsafe { c::RtlGenRandom(&mut v as *mut _ as *mut c_void, mem::size_of_val(&v) as c::ULONG) From 08e0c12c0719cec6edc66cff178507632e467adf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez <guillaume.gomez@huawei.com> Date: Sat, 10 Jun 2023 14:38:08 +0200 Subject: [PATCH 06/11] Migrate GUI colors test to original CSS color format --- tests/rustdoc-gui/search-reexport.goml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rustdoc-gui/search-reexport.goml b/tests/rustdoc-gui/search-reexport.goml index fd817b58990..c5c386ce750 100644 --- a/tests/rustdoc-gui/search-reexport.goml +++ b/tests/rustdoc-gui/search-reexport.goml @@ -17,7 +17,7 @@ assert-attribute: ( assert-text: ("//a[@class='result-import']", "test_docs::TheStdReexport") click: "//a[@class='result-import']" // We check that it has the background modified thanks to the focus. -wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgb(73, 74, 61)"}) +wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "#494a3d"}) // We now check that the alias is working as well on the reexport. // To be SURE that the search will be run. @@ -30,4 +30,4 @@ assert-text: ( ) // Same thing again, we click on it to ensure the background is once again set as expected. click: "//a[@class='result-import']" -wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgb(73, 74, 61)"}) +wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "#494a3d"}) From cd523f2f184b4325b860e7705b939f7ec1cfb4f0 Mon Sep 17 00:00:00 2001 From: bdbai <bdbaiapp@163.com> Date: Sat, 10 Jun 2023 20:47:10 +0800 Subject: [PATCH 07/11] Keep uwp specific code in sync with windows-sys --- library/std/src/sys/windows/c.rs | 7 ++----- library/std/src/sys/windows/c/windows_sys.lst | 1 + library/std/src/sys/windows/c/windows_sys.rs | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 929aaf5a266..5fc6136ba1f 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -51,9 +51,6 @@ pub type CONDITION_VARIABLE = RTL_CONDITION_VARIABLE; pub type SRWLOCK = RTL_SRWLOCK; pub type INIT_ONCE = RTL_RUN_ONCE; -#[cfg(target_vendor = "uwp")] -pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = 0xC0000002_u32 as _; - pub const CONDITION_VARIABLE_INIT: CONDITION_VARIABLE = CONDITION_VARIABLE { Ptr: ptr::null_mut() }; pub const SRWLOCK_INIT: SRWLOCK = SRWLOCK { Ptr: ptr::null_mut() }; pub const INIT_ONCE_STATIC_INIT: INIT_ONCE = INIT_ONCE { Ptr: ptr::null_mut() }; @@ -431,7 +428,7 @@ compat_fn_with_fallback! { STATUS_NOT_IMPLEMENTED } #[cfg(target_vendor = "uwp")] - pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> ULONG { - Status as ULONG + pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> u32 { + Status as u32 } } diff --git a/library/std/src/sys/windows/c/windows_sys.lst b/library/std/src/sys/windows/c/windows_sys.lst index 3e454199f13..2cf1ade99ce 100644 --- a/library/std/src/sys/windows/c/windows_sys.lst +++ b/library/std/src/sys/windows/c/windows_sys.lst @@ -1930,6 +1930,7 @@ Windows.Win32.Foundation.SetLastError Windows.Win32.Foundation.STATUS_DELETE_PENDING Windows.Win32.Foundation.STATUS_END_OF_FILE Windows.Win32.Foundation.STATUS_INVALID_PARAMETER +Windows.Win32.Foundation.STATUS_NOT_IMPLEMENTED Windows.Win32.Foundation.STATUS_PENDING Windows.Win32.Foundation.STATUS_SUCCESS Windows.Win32.Foundation.TRUE diff --git a/library/std/src/sys/windows/c/windows_sys.rs b/library/std/src/sys/windows/c/windows_sys.rs index 36a30f6ba56..8c8b006a1d3 100644 --- a/library/std/src/sys/windows/c/windows_sys.rs +++ b/library/std/src/sys/windows/c/windows_sys.rs @@ -3888,6 +3888,7 @@ pub type STARTUPINFOW_FLAGS = u32; pub const STATUS_DELETE_PENDING: NTSTATUS = -1073741738i32; pub const STATUS_END_OF_FILE: NTSTATUS = -1073741807i32; pub const STATUS_INVALID_PARAMETER: NTSTATUS = -1073741811i32; +pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = -1073741822i32; pub const STATUS_PENDING: NTSTATUS = 259i32; pub const STATUS_SUCCESS: NTSTATUS = 0i32; pub const STD_ERROR_HANDLE: STD_HANDLE = 4294967284u32; From 83d7826753251848f92427a8b713b5c59c48c3ef Mon Sep 17 00:00:00 2001 From: icecream17 <nguyeste008@students.garlandisd.net> Date: Sat, 10 Jun 2023 10:45:50 -0500 Subject: [PATCH 08/11] abs_sub: fix typo 0[-:][+.]0 --- library/std/src/f32.rs | 2 +- library/std/src/f64.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 408244b2ce9..bed90418be1 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -528,7 +528,7 @@ impl f32 { /// The positive difference of two numbers. /// - /// * If `self <= other`: `0:0` + /// * If `self <= other`: `0.0` /// * Else: `self - other` /// /// # Examples diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs index 6782b861f11..e72de05ca41 100644 --- a/library/std/src/f64.rs +++ b/library/std/src/f64.rs @@ -530,7 +530,7 @@ impl f64 { /// The positive difference of two numbers. /// - /// * If `self <= other`: `0:0` + /// * If `self <= other`: `0.0` /// * Else: `self - other` /// /// # Examples From e5fccf927d5a9574ba3eca1d8ea063d50e4fc8fa Mon Sep 17 00:00:00 2001 From: Hankai Zhang <hsamzhang@gmail.com> Date: Sat, 10 Jun 2023 12:34:16 -0400 Subject: [PATCH 09/11] Update links to Rust Reference page on literals in diagnostic Instead of linking to the old Rust Reference site on static.rust-lang.org, link to the current website doc.rust-lang.org/stable/reference instead in diagnostic about incorrect literals. --- compiler/rustc_parse/src/lexer/unescape_error_reporting.rs | 2 +- tests/ui/lexer/lex-bad-char-literals-1.stderr | 4 ++-- tests/ui/parser/bad-escape-suggest-raw-string.rs | 2 +- tests/ui/parser/bad-escape-suggest-raw-string.stderr | 2 +- tests/ui/parser/byte-literals.stderr | 4 ++-- tests/ui/parser/byte-string-literals.stderr | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs index eb9625f923a..4bbd640cd59 100644 --- a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs +++ b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs @@ -158,7 +158,7 @@ pub(crate) fn emit_unescape_error( diag.help( "for more information, visit \ - <https://static.rust-lang.org/doc/master/reference.html#literals>", + <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html>", ); } diag.emit(); diff --git a/tests/ui/lexer/lex-bad-char-literals-1.stderr b/tests/ui/lexer/lex-bad-char-literals-1.stderr index e6ff1f662bd..44e8700bf8d 100644 --- a/tests/ui/lexer/lex-bad-char-literals-1.stderr +++ b/tests/ui/lexer/lex-bad-char-literals-1.stderr @@ -16,7 +16,7 @@ error: unknown character escape: `\u{25cf}` LL | '\●' | ^ unknown character escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | LL | r"\●" @@ -28,7 +28,7 @@ error: unknown character escape: `\u{25cf}` LL | "\●" | ^ unknown character escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | LL | r"\●" diff --git a/tests/ui/parser/bad-escape-suggest-raw-string.rs b/tests/ui/parser/bad-escape-suggest-raw-string.rs index 978b92cbcd2..6725a11c223 100644 --- a/tests/ui/parser/bad-escape-suggest-raw-string.rs +++ b/tests/ui/parser/bad-escape-suggest-raw-string.rs @@ -2,6 +2,6 @@ fn main() { let ok = r"ab\[c"; let bad = "ab\[c"; //~^ ERROR unknown character escape: `[` - //~| HELP for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + //~| HELP for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> //~| HELP if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal } diff --git a/tests/ui/parser/bad-escape-suggest-raw-string.stderr b/tests/ui/parser/bad-escape-suggest-raw-string.stderr index fc34bd3281a..f54761d1bd1 100644 --- a/tests/ui/parser/bad-escape-suggest-raw-string.stderr +++ b/tests/ui/parser/bad-escape-suggest-raw-string.stderr @@ -4,7 +4,7 @@ error: unknown character escape: `[` LL | let bad = "ab\[c"; | ^ unknown character escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | LL | let bad = r"ab\[c"; diff --git a/tests/ui/parser/byte-literals.stderr b/tests/ui/parser/byte-literals.stderr index efa55ae05bd..7406905f932 100644 --- a/tests/ui/parser/byte-literals.stderr +++ b/tests/ui/parser/byte-literals.stderr @@ -4,7 +4,7 @@ error: unknown byte escape: `f` LL | static FOO: u8 = b'\f'; | ^ unknown byte escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> error: unknown byte escape: `f` --> $DIR/byte-literals.rs:6:8 @@ -12,7 +12,7 @@ error: unknown byte escape: `f` LL | b'\f'; | ^ unknown byte escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> error: invalid character in numeric character escape: `Z` --> $DIR/byte-literals.rs:7:10 diff --git a/tests/ui/parser/byte-string-literals.stderr b/tests/ui/parser/byte-string-literals.stderr index 5b96cc3d18a..fbc719c5b67 100644 --- a/tests/ui/parser/byte-string-literals.stderr +++ b/tests/ui/parser/byte-string-literals.stderr @@ -4,7 +4,7 @@ error: unknown byte escape: `f` LL | static FOO: &'static [u8] = b"\f"; | ^ unknown byte escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> error: unknown byte escape: `f` --> $DIR/byte-string-literals.rs:4:8 @@ -12,7 +12,7 @@ error: unknown byte escape: `f` LL | b"\f"; | ^ unknown byte escape | - = help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> + = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> error: invalid character in numeric character escape: `Z` --> $DIR/byte-string-literals.rs:5:10 From 6336da9a75633a074bf169fe62dfb0728e7055a7 Mon Sep 17 00:00:00 2001 From: Hankai Zhang <hsamzhang@gmail.com> Date: Sat, 10 Jun 2023 14:46:11 -0400 Subject: [PATCH 10/11] Use a better link --- compiler/rustc_parse/src/lexer/unescape_error_reporting.rs | 2 +- tests/ui/lexer/lex-bad-char-literals-1.stderr | 4 ++-- tests/ui/parser/bad-escape-suggest-raw-string.rs | 2 +- tests/ui/parser/bad-escape-suggest-raw-string.stderr | 2 +- tests/ui/parser/byte-literals.stderr | 4 ++-- tests/ui/parser/byte-string-literals.stderr | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs index 4bbd640cd59..461a34b67db 100644 --- a/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs +++ b/compiler/rustc_parse/src/lexer/unescape_error_reporting.rs @@ -158,7 +158,7 @@ pub(crate) fn emit_unescape_error( diag.help( "for more information, visit \ - <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html>", + <https://doc.rust-lang.org/reference/tokens.html#literals>", ); } diag.emit(); diff --git a/tests/ui/lexer/lex-bad-char-literals-1.stderr b/tests/ui/lexer/lex-bad-char-literals-1.stderr index 44e8700bf8d..9dc0a338063 100644 --- a/tests/ui/lexer/lex-bad-char-literals-1.stderr +++ b/tests/ui/lexer/lex-bad-char-literals-1.stderr @@ -16,7 +16,7 @@ error: unknown character escape: `\u{25cf}` LL | '\●' | ^ unknown character escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | LL | r"\●" @@ -28,7 +28,7 @@ error: unknown character escape: `\u{25cf}` LL | "\●" | ^ unknown character escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | LL | r"\●" diff --git a/tests/ui/parser/bad-escape-suggest-raw-string.rs b/tests/ui/parser/bad-escape-suggest-raw-string.rs index 6725a11c223..06df82d288b 100644 --- a/tests/ui/parser/bad-escape-suggest-raw-string.rs +++ b/tests/ui/parser/bad-escape-suggest-raw-string.rs @@ -2,6 +2,6 @@ fn main() { let ok = r"ab\[c"; let bad = "ab\[c"; //~^ ERROR unknown character escape: `[` - //~| HELP for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + //~| HELP for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> //~| HELP if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal } diff --git a/tests/ui/parser/bad-escape-suggest-raw-string.stderr b/tests/ui/parser/bad-escape-suggest-raw-string.stderr index f54761d1bd1..45d24bc0fb3 100644 --- a/tests/ui/parser/bad-escape-suggest-raw-string.stderr +++ b/tests/ui/parser/bad-escape-suggest-raw-string.stderr @@ -4,7 +4,7 @@ error: unknown character escape: `[` LL | let bad = "ab\[c"; | ^ unknown character escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | LL | let bad = r"ab\[c"; diff --git a/tests/ui/parser/byte-literals.stderr b/tests/ui/parser/byte-literals.stderr index 7406905f932..5b414c8927e 100644 --- a/tests/ui/parser/byte-literals.stderr +++ b/tests/ui/parser/byte-literals.stderr @@ -4,7 +4,7 @@ error: unknown byte escape: `f` LL | static FOO: u8 = b'\f'; | ^ unknown byte escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> error: unknown byte escape: `f` --> $DIR/byte-literals.rs:6:8 @@ -12,7 +12,7 @@ error: unknown byte escape: `f` LL | b'\f'; | ^ unknown byte escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> error: invalid character in numeric character escape: `Z` --> $DIR/byte-literals.rs:7:10 diff --git a/tests/ui/parser/byte-string-literals.stderr b/tests/ui/parser/byte-string-literals.stderr index fbc719c5b67..655b6998e85 100644 --- a/tests/ui/parser/byte-string-literals.stderr +++ b/tests/ui/parser/byte-string-literals.stderr @@ -4,7 +4,7 @@ error: unknown byte escape: `f` LL | static FOO: &'static [u8] = b"\f"; | ^ unknown byte escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> error: unknown byte escape: `f` --> $DIR/byte-string-literals.rs:4:8 @@ -12,7 +12,7 @@ error: unknown byte escape: `f` LL | b"\f"; | ^ unknown byte escape | - = help: for more information, visit <https://doc.rust-lang.org/stable/reference/expressions/literal-expr.html> + = help: for more information, visit <https://doc.rust-lang.org/reference/tokens.html#literals> error: invalid character in numeric character escape: `Z` --> $DIR/byte-string-literals.rs:5:10 From a995255cf5dfd053584198c10e86d7763e5dbc87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= <me@fmease.dev> Date: Sat, 10 Jun 2023 14:56:08 +0200 Subject: [PATCH 11/11] iat selection: normalize self ty & completely erase bound vars --- .../rustc_hir_analysis/src/astconv/mod.rs | 76 ++++++++++++++----- .../issue-111404-0.rs | 14 ++++ .../issue-111404-1.rs | 13 ++++ .../issue-111404-1.stderr | 8 ++ 4 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 tests/ui/associated-inherent-types/issue-111404-0.rs create mode 100644 tests/ui/associated-inherent-types/issue-111404-1.rs create mode 100644 tests/ui/associated-inherent-types/issue-111404-1.stderr diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index a9e8afe434e..1037a49acdf 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -26,10 +26,9 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_generics, Visitor as _}; use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin}; -use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; +use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use rustc_infer::traits::ObligationCause; use rustc_middle::middle::stability::AllowUnstable; -use rustc_middle::ty::fold::FnMutDelegate; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef}; use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; @@ -43,7 +42,10 @@ use rustc_trait_selection::traits::error_reporting::{ report_object_safety_error, suggestions::NextTypeParamName, }; use rustc_trait_selection::traits::wf::object_region_bounds; -use rustc_trait_selection::traits::{self, astconv_object_safety_violations, ObligationCtxt}; +use rustc_trait_selection::traits::{ + self, astconv_object_safety_violations, NormalizeExt, ObligationCtxt, +}; +use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use smallvec::{smallvec, SmallVec}; use std::collections::BTreeSet; @@ -2442,6 +2444,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { return Ok(None); } + if !tcx.features().inherent_associated_types { + tcx.sess + .delay_span_bug(span, "found inherent assoc type without the feature being gated"); + } + // // Select applicable inherent associated type candidates modulo regions. // @@ -2465,23 +2472,53 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let mut fulfillment_errors = Vec::new(); let mut applicable_candidates: Vec<_> = infcx.probe(|_| { - let universe = infcx.create_next_universe(); - // Regions are not considered during selection. - // FIXME(non_lifetime_binders): Here we are "truncating" or "flattening" the universes - // of type and const binders. Is that correct in the selection phase? See also #109505. - let self_ty = tcx.replace_escaping_bound_vars_uncached( - self_ty, - FnMutDelegate { - regions: &mut |_| tcx.lifetimes.re_erased, - types: &mut |bv| { - tcx.mk_placeholder(ty::PlaceholderType { universe, bound: bv }) - }, - consts: &mut |bv, ty| { - tcx.mk_const(ty::PlaceholderConst { universe, bound: bv }, ty) - }, - }, - ); + let self_ty = self_ty + .fold_with(&mut BoundVarEraser { tcx, universe: infcx.create_next_universe() }); + + struct BoundVarEraser<'tcx> { + tcx: TyCtxt<'tcx>, + universe: ty::UniverseIndex, + } + + // FIXME(non_lifetime_binders): Don't assign the same universe to each placeholder. + impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarEraser<'tcx> { + fn interner(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { + if r.is_late_bound() { self.tcx.lifetimes.re_erased } else { r } + } + + fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { + match *ty.kind() { + ty::Bound(_, bv) => self.tcx.mk_placeholder(ty::PlaceholderType { + universe: self.universe, + bound: bv, + }), + _ => ty.super_fold_with(self), + } + } + + fn fold_const( + &mut self, + ct: ty::Const<'tcx>, + ) -> <TyCtxt<'tcx> as rustc_type_ir::Interner>::Const { + assert!(!ct.ty().has_escaping_bound_vars()); + + match ct.kind() { + ty::ConstKind::Bound(_, bv) => self.tcx.mk_const( + ty::PlaceholderConst { universe: self.universe, bound: bv }, + ct.ty(), + ), + _ => ct.super_fold_with(self), + } + } + } + + let InferOk { value: self_ty, obligations } = + infcx.at(&cause, param_env).normalize(self_ty); candidates .iter() @@ -2489,6 +2526,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .filter(|&(impl_, _)| { infcx.probe(|_| { let ocx = ObligationCtxt::new_in_snapshot(&infcx); + ocx.register_obligations(obligations.clone()); let impl_substs = infcx.fresh_substs_for_item(span, impl_); let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs); diff --git a/tests/ui/associated-inherent-types/issue-111404-0.rs b/tests/ui/associated-inherent-types/issue-111404-0.rs new file mode 100644 index 00000000000..1180577bd54 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-111404-0.rs @@ -0,0 +1,14 @@ +// check-pass + +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +struct Foo<T>(T); + +impl<'a> Foo<fn(&'a ())> { + type Assoc = &'a (); +} + +fn bar(_: for<'a> fn(Foo<fn(Foo<fn(&'a ())>::Assoc)>::Assoc)) {} + +fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-111404-1.rs b/tests/ui/associated-inherent-types/issue-111404-1.rs new file mode 100644 index 00000000000..f4ad5d7ff6c --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-111404-1.rs @@ -0,0 +1,13 @@ +#![feature(inherent_associated_types)] +#![allow(incomplete_features)] + +struct Foo<T>(T); + +impl<'a> Foo<fn(&'a ())> { + type Assoc = &'a (); +} + +fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {} +//~^ ERROR higher-ranked subtype error + +fn main() {} diff --git a/tests/ui/associated-inherent-types/issue-111404-1.stderr b/tests/ui/associated-inherent-types/issue-111404-1.stderr new file mode 100644 index 00000000000..c55f1432389 --- /dev/null +++ b/tests/ui/associated-inherent-types/issue-111404-1.stderr @@ -0,0 +1,8 @@ +error: higher-ranked subtype error + --> $DIR/issue-111404-1.rs:10:1 + | +LL | fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error +