Skip to content

Commit 970058e

Browse files
committed
Auto merge of rust-lang#112512 - matthiaskrgr:rollup-o2jh1jx, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#112475 (Fix issue for module name when surround the struct literal with parentheses) - rust-lang#112477 (Give more helpful progress messages in `Assemble`) - rust-lang#112484 (Fix ntdll linkage issues on Windows UWP platforms) - rust-lang#112492 (Migrate GUI colors test to original CSS color format) - rust-lang#112493 (iat selection: normalize self ty & completely erase bound vars) - rust-lang#112497 (abs_sub: fix typo 0[-:][+.]0) - rust-lang#112498 (Update links to Rust Reference in diagnostic) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b8a5001 + 46b64aa commit 970058e

24 files changed

+292
-46
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+57-19
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ use rustc_hir::def::{CtorOf, DefKind, Namespace, Res};
2626
use rustc_hir::def_id::{DefId, LocalDefId};
2727
use rustc_hir::intravisit::{walk_generics, Visitor as _};
2828
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
29-
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
29+
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
3030
use rustc_infer::traits::ObligationCause;
3131
use rustc_middle::middle::stability::AllowUnstable;
32-
use rustc_middle::ty::fold::FnMutDelegate;
3332
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
3433
use rustc_middle::ty::GenericParamDefKind;
3534
use rustc_middle::ty::{self, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
@@ -43,7 +42,10 @@ use rustc_trait_selection::traits::error_reporting::{
4342
report_object_safety_error, suggestions::NextTypeParamName,
4443
};
4544
use rustc_trait_selection::traits::wf::object_region_bounds;
46-
use rustc_trait_selection::traits::{self, astconv_object_safety_violations, ObligationCtxt};
45+
use rustc_trait_selection::traits::{
46+
self, astconv_object_safety_violations, NormalizeExt, ObligationCtxt,
47+
};
48+
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
4749

4850
use smallvec::{smallvec, SmallVec};
4951
use std::collections::BTreeSet;
@@ -2442,6 +2444,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24422444
return Ok(None);
24432445
}
24442446

2447+
if !tcx.features().inherent_associated_types {
2448+
tcx.sess
2449+
.delay_span_bug(span, "found inherent assoc type without the feature being gated");
2450+
}
2451+
24452452
//
24462453
// Select applicable inherent associated type candidates modulo regions.
24472454
//
@@ -2465,30 +2472,61 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24652472

24662473
let mut fulfillment_errors = Vec::new();
24672474
let mut applicable_candidates: Vec<_> = infcx.probe(|_| {
2468-
let universe = infcx.create_next_universe();
2469-
24702475
// Regions are not considered during selection.
2471-
// FIXME(non_lifetime_binders): Here we are "truncating" or "flattening" the universes
2472-
// of type and const binders. Is that correct in the selection phase? See also #109505.
2473-
let self_ty = tcx.replace_escaping_bound_vars_uncached(
2474-
self_ty,
2475-
FnMutDelegate {
2476-
regions: &mut |_| tcx.lifetimes.re_erased,
2477-
types: &mut |bv| {
2478-
tcx.mk_placeholder(ty::PlaceholderType { universe, bound: bv })
2479-
},
2480-
consts: &mut |bv, ty| {
2481-
tcx.mk_const(ty::PlaceholderConst { universe, bound: bv }, ty)
2482-
},
2483-
},
2484-
);
2476+
let self_ty = self_ty
2477+
.fold_with(&mut BoundVarEraser { tcx, universe: infcx.create_next_universe() });
2478+
2479+
struct BoundVarEraser<'tcx> {
2480+
tcx: TyCtxt<'tcx>,
2481+
universe: ty::UniverseIndex,
2482+
}
2483+
2484+
// FIXME(non_lifetime_binders): Don't assign the same universe to each placeholder.
2485+
impl<'tcx> TypeFolder<TyCtxt<'tcx>> for BoundVarEraser<'tcx> {
2486+
fn interner(&self) -> TyCtxt<'tcx> {
2487+
self.tcx
2488+
}
2489+
2490+
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
2491+
if r.is_late_bound() { self.tcx.lifetimes.re_erased } else { r }
2492+
}
2493+
2494+
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
2495+
match *ty.kind() {
2496+
ty::Bound(_, bv) => self.tcx.mk_placeholder(ty::PlaceholderType {
2497+
universe: self.universe,
2498+
bound: bv,
2499+
}),
2500+
_ => ty.super_fold_with(self),
2501+
}
2502+
}
2503+
2504+
fn fold_const(
2505+
&mut self,
2506+
ct: ty::Const<'tcx>,
2507+
) -> <TyCtxt<'tcx> as rustc_type_ir::Interner>::Const {
2508+
assert!(!ct.ty().has_escaping_bound_vars());
2509+
2510+
match ct.kind() {
2511+
ty::ConstKind::Bound(_, bv) => self.tcx.mk_const(
2512+
ty::PlaceholderConst { universe: self.universe, bound: bv },
2513+
ct.ty(),
2514+
),
2515+
_ => ct.super_fold_with(self),
2516+
}
2517+
}
2518+
}
2519+
2520+
let InferOk { value: self_ty, obligations } =
2521+
infcx.at(&cause, param_env).normalize(self_ty);
24852522

24862523
candidates
24872524
.iter()
24882525
.copied()
24892526
.filter(|&(impl_, _)| {
24902527
infcx.probe(|_| {
24912528
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
2529+
ocx.register_obligations(obligations.clone());
24922530

24932531
let impl_substs = infcx.fresh_substs_for_item(span, impl_);
24942532
let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs);

compiler/rustc_parse/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ parse_struct_literal_body_without_path =
695695
696696
parse_struct_literal_needing_parens =
697697
invalid struct literal
698-
.suggestion = you might need to surround the struct literal in parentheses
698+
.suggestion = you might need to surround the struct literal with parentheses
699699
700700
parse_struct_literal_not_allowed_here = struct literals are not allowed here
701701
.suggestion = surround the struct literal with parentheses

compiler/rustc_parse/src/lexer/unescape_error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub(crate) fn emit_unescape_error(
158158

159159
diag.help(
160160
"for more information, visit \
161-
<https://static.rust-lang.org/doc/master/reference.html#literals>",
161+
<https://doc.rust-lang.org/reference/tokens.html#literals>",
162162
);
163163
}
164164
diag.emit();

compiler/rustc_parse/src/parser/diagnostics.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,24 @@ impl<'a> Parser<'a> {
751751
tail.could_be_bare_literal = true;
752752
if maybe_struct_name.is_ident() && can_be_struct_literal {
753753
// Account for `if Example { a: one(), }.is_pos() {}`.
754-
Err(self.sess.create_err(StructLiteralNeedingParens {
755-
span: maybe_struct_name.span.to(expr.span),
756-
sugg: StructLiteralNeedingParensSugg {
757-
before: maybe_struct_name.span.shrink_to_lo(),
758-
after: expr.span.shrink_to_hi(),
759-
},
760-
}))
754+
// expand `before` so that we take care of module path such as:
755+
// `foo::Bar { ... } `
756+
// we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })`
757+
let sm = self.sess.source_map();
758+
let before = maybe_struct_name.span.shrink_to_lo();
759+
if let Ok(extend_before) = sm.span_extend_prev_while(before, |t| {
760+
t.is_alphanumeric() || t == ':' || t == '_'
761+
}) {
762+
Err(self.sess.create_err(StructLiteralNeedingParens {
763+
span: maybe_struct_name.span.to(expr.span),
764+
sugg: StructLiteralNeedingParensSugg {
765+
before: extend_before.shrink_to_lo(),
766+
after: expr.span.shrink_to_hi(),
767+
},
768+
}))
769+
} else {
770+
return None;
771+
}
761772
} else {
762773
self.sess.emit_err(StructLiteralBodyWithoutPath {
763774
span: expr.span,

compiler/rustc_span/src/source_map.rs

+15
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,21 @@ impl SourceMap {
744744
})
745745
}
746746

747+
/// Extends the given `Span` to previous character while the previous character matches the predicate
748+
pub fn span_extend_prev_while(
749+
&self,
750+
span: Span,
751+
f: impl Fn(char) -> bool,
752+
) -> Result<Span, SpanSnippetError> {
753+
self.span_to_source(span, |s, start, _end| {
754+
let n = s[..start]
755+
.char_indices()
756+
.rfind(|&(_, c)| !f(c))
757+
.map_or(start, |(i, _)| start - i - 1);
758+
Ok(span.with_lo(span.lo() - BytePos(n as u32)))
759+
})
760+
}
761+
747762
/// Extends the given `Span` to just before the next occurrence of `c`.
748763
pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
749764
if let Ok(next_source) = self.span_to_next_source(sp) {

library/std/src/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl f32 {
528528

529529
/// The positive difference of two numbers.
530530
///
531-
/// * If `self <= other`: `0:0`
531+
/// * If `self <= other`: `0.0`
532532
/// * Else: `self - other`
533533
///
534534
/// # Examples

library/std/src/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl f64 {
530530

531531
/// The positive difference of two numbers.
532532
///
533-
/// * If `self <= other`: `0:0`
533+
/// * If `self <= other`: `0.0`
534534
/// * Else: `self - other`
535535
///
536536
/// # Examples

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

+55
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub use windows_sys::*;
1919
pub type DWORD = c_ulong;
2020
pub type NonZeroDWORD = NonZero_c_ulong;
2121
pub type LARGE_INTEGER = c_longlong;
22+
#[cfg_attr(target_vendor = "uwp", allow(unused))]
2223
pub type LONG = c_long;
2324
pub type UINT = c_uint;
2425
pub type WCHAR = u16;
@@ -267,6 +268,8 @@ pub unsafe fn getaddrinfo(
267268
windows_sys::getaddrinfo(node.cast::<u8>(), service.cast::<u8>(), hints, res)
268269
}
269270

271+
cfg_if::cfg_if! {
272+
if #[cfg(not(target_vendor = "uwp"))] {
270273
pub unsafe fn NtReadFile(
271274
filehandle: BorrowedHandle<'_>,
272275
event: HANDLE,
@@ -313,6 +316,8 @@ pub unsafe fn NtWriteFile(
313316
key.map(|k| k as *const u32).unwrap_or(ptr::null()),
314317
)
315318
}
319+
}
320+
}
316321

317322
// Functions that aren't available on every version of Windows that we support,
318323
// but we still use them and just provide some form of a fallback implementation.
@@ -376,4 +381,54 @@ compat_fn_with_fallback! {
376381
) -> NTSTATUS {
377382
panic!("keyed events not available")
378383
}
384+
385+
// These functions are available on UWP when lazily loaded. They will fail WACK if loaded statically.
386+
#[cfg(target_vendor = "uwp")]
387+
pub fn NtCreateFile(
388+
filehandle: *mut HANDLE,
389+
desiredaccess: FILE_ACCESS_RIGHTS,
390+
objectattributes: *const OBJECT_ATTRIBUTES,
391+
iostatusblock: *mut IO_STATUS_BLOCK,
392+
allocationsize: *const i64,
393+
fileattributes: FILE_FLAGS_AND_ATTRIBUTES,
394+
shareaccess: FILE_SHARE_MODE,
395+
createdisposition: NTCREATEFILE_CREATE_DISPOSITION,
396+
createoptions: NTCREATEFILE_CREATE_OPTIONS,
397+
eabuffer: *const ::core::ffi::c_void,
398+
ealength: u32
399+
) -> NTSTATUS {
400+
STATUS_NOT_IMPLEMENTED
401+
}
402+
#[cfg(target_vendor = "uwp")]
403+
pub fn NtReadFile(
404+
filehandle: BorrowedHandle<'_>,
405+
event: HANDLE,
406+
apcroutine: PIO_APC_ROUTINE,
407+
apccontext: *mut c_void,
408+
iostatusblock: &mut IO_STATUS_BLOCK,
409+
buffer: *mut crate::mem::MaybeUninit<u8>,
410+
length: ULONG,
411+
byteoffset: Option<&LARGE_INTEGER>,
412+
key: Option<&ULONG>
413+
) -> NTSTATUS {
414+
STATUS_NOT_IMPLEMENTED
415+
}
416+
#[cfg(target_vendor = "uwp")]
417+
pub fn NtWriteFile(
418+
filehandle: BorrowedHandle<'_>,
419+
event: HANDLE,
420+
apcroutine: PIO_APC_ROUTINE,
421+
apccontext: *mut c_void,
422+
iostatusblock: &mut IO_STATUS_BLOCK,
423+
buffer: *const u8,
424+
length: ULONG,
425+
byteoffset: Option<&LARGE_INTEGER>,
426+
key: Option<&ULONG>
427+
) -> NTSTATUS {
428+
STATUS_NOT_IMPLEMENTED
429+
}
430+
#[cfg(target_vendor = "uwp")]
431+
pub fn RtlNtStatusToDosError(Status: NTSTATUS) -> u32 {
432+
Status as u32
433+
}
379434
}

library/std/src/sys/windows/c/windows_sys.lst

+1
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,7 @@ Windows.Win32.Foundation.SetLastError
19301930
Windows.Win32.Foundation.STATUS_DELETE_PENDING
19311931
Windows.Win32.Foundation.STATUS_END_OF_FILE
19321932
Windows.Win32.Foundation.STATUS_INVALID_PARAMETER
1933+
Windows.Win32.Foundation.STATUS_NOT_IMPLEMENTED
19331934
Windows.Win32.Foundation.STATUS_PENDING
19341935
Windows.Win32.Foundation.STATUS_SUCCESS
19351936
Windows.Win32.Foundation.TRUE

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

+1
Original file line numberDiff line numberDiff line change
@@ -3888,6 +3888,7 @@ pub type STARTUPINFOW_FLAGS = u32;
38883888
pub const STATUS_DELETE_PENDING: NTSTATUS = -1073741738i32;
38893889
pub const STATUS_END_OF_FILE: NTSTATUS = -1073741807i32;
38903890
pub const STATUS_INVALID_PARAMETER: NTSTATUS = -1073741811i32;
3891+
pub const STATUS_NOT_IMPLEMENTED: NTSTATUS = -1073741822i32;
38913892
pub const STATUS_PENDING: NTSTATUS = 259i32;
38923893
pub const STATUS_SUCCESS: NTSTATUS = 0i32;
38933894
pub const STD_ERROR_HANDLE: STD_HANDLE = 4294967284u32;

library/std/src/sys/windows/rand.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::ffi::c_void;
2-
use crate::io;
31
use crate::mem;
42
use crate::ptr;
53
use crate::sys::c;
@@ -25,6 +23,9 @@ pub fn hashmap_random_keys() -> (u64, u64) {
2523
#[cfg(not(target_vendor = "uwp"))]
2624
#[inline(never)]
2725
fn fallback_rng() -> (u64, u64) {
26+
use crate::ffi::c_void;
27+
use crate::io;
28+
2829
let mut v = (0, 0);
2930
let ret = unsafe {
3031
c::RtlGenRandom(&mut v as *mut _ as *mut c_void, mem::size_of_val(&v) as c::ULONG)

src/bootstrap/compile.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,10 @@ impl Step for Assemble {
14881488
// Ensure that `libLLVM.so` ends up in the newly created target directory,
14891489
// so that tools using `rustc_private` can use it.
14901490
dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot);
1491+
// Lower stages use `ci-rustc-sysroot`, not stageN
1492+
if target_compiler.stage == builder.top_stage {
1493+
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage));
1494+
}
14911495
return target_compiler;
14921496
}
14931497

@@ -1525,11 +1529,18 @@ impl Step for Assemble {
15251529

15261530
let stage = target_compiler.stage;
15271531
let host = target_compiler.host;
1528-
let msg = if build_compiler.host == host {
1529-
format!("Assembling stage{} compiler", stage)
1532+
let (host_info, dir_name) = if build_compiler.host == host {
1533+
("".into(), "host".into())
15301534
} else {
1531-
format!("Assembling stage{} compiler ({})", stage, host)
1535+
(format!(" ({host})"), host.to_string())
15321536
};
1537+
// NOTE: "Creating a sysroot" is somewhat inconsistent with our internal terminology, since
1538+
// sysroots can temporarily be empty until we put the compiler inside. However,
1539+
// `ensure(Sysroot)` isn't really something that's user facing, so there shouldn't be any
1540+
// ambiguity.
1541+
let msg = format!(
1542+
"Creating a sysroot for stage{stage} compiler{host_info} (use `rustup toolchain link 'name' build/{dir_name}/stage{stage}`)"
1543+
);
15331544
builder.info(&msg);
15341545

15351546
// Link in all dylibs to the libdir

tests/rustdoc-gui/search-reexport.goml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ assert-attribute: (
1717
assert-text: ("//a[@class='result-import']", "test_docs::TheStdReexport")
1818
click: "//a[@class='result-import']"
1919
// We check that it has the background modified thanks to the focus.
20-
wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgb(73, 74, 61)"})
20+
wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "#494a3d"})
2121

2222
// We now check that the alias is working as well on the reexport.
2323
// To be SURE that the search will be run.
@@ -30,4 +30,4 @@ assert-text: (
3030
)
3131
// Same thing again, we click on it to ensure the background is once again set as expected.
3232
click: "//a[@class='result-import']"
33-
wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgb(73, 74, 61)"})
33+
wait-for-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "#494a3d"})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// check-pass
2+
3+
#![feature(inherent_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
struct Foo<T>(T);
7+
8+
impl<'a> Foo<fn(&'a ())> {
9+
type Assoc = &'a ();
10+
}
11+
12+
fn bar(_: for<'a> fn(Foo<fn(Foo<fn(&'a ())>::Assoc)>::Assoc)) {}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features)]
3+
4+
struct Foo<T>(T);
5+
6+
impl<'a> Foo<fn(&'a ())> {
7+
type Assoc = &'a ();
8+
}
9+
10+
fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
11+
//~^ ERROR higher-ranked subtype error
12+
13+
fn main() {}

0 commit comments

Comments
 (0)