Skip to content

Rollup of 7 pull requests #112512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3983881
take care module name for suggesting surround the struct literal in p…
chenyukang Jun 6, 2023
e3071ea
reword the message to suggest surrounding with parentheses
chenyukang Jun 6, 2023
f531fec
Give more helpful progress messages in `Assemble`
jyn514 Jun 9, 2023
f54e757
remove unwrap
chenyukang Jun 10, 2023
48e410e
Lazy load ntdll functions on UWP
bdbai Jun 10, 2023
08e0c12
Migrate GUI colors test to original CSS color format
GuillaumeGomez Jun 10, 2023
cd523f2
Keep uwp specific code in sync with windows-sys
bdbai Jun 10, 2023
83d7826
abs_sub: fix typo 0[-:][+.]0
icecream17 Jun 10, 2023
e5fccf9
Update links to Rust Reference page on literals in diagnostic
SamZhang3 Jun 10, 2023
6336da9
Use a better link
SamZhang3 Jun 10, 2023
a995255
iat selection: normalize self ty & completely erase bound vars
fmease Jun 10, 2023
e19a509
Rollup merge of #112475 - chenyukang:yukang-fix-112278, r=compiler-er…
matthiaskrgr Jun 10, 2023
dbe31bb
Rollup merge of #112477 - jyn514:assemble-info, r=clubby789
matthiaskrgr Jun 10, 2023
e4f6b3d
Rollup merge of #112484 - bdbai:fix/uwpntdll, r=ChrisDenton
matthiaskrgr Jun 10, 2023
fcf621e
Rollup merge of #112492 - GuillaumeGomez:migrate-gui-test-color-13, r…
matthiaskrgr Jun 10, 2023
e9666d4
Rollup merge of #112493 - fmease:iat-select-complete-bound-var-erasur…
matthiaskrgr Jun 10, 2023
0ff35f2
Rollup merge of #112497 - icecream17:patch-1, r=Mark-Simulacrum
matthiaskrgr Jun 10, 2023
46b64aa
Rollup merge of #112498 - SamZhang3:rust-reference-link-update, r=Nil…
matthiaskrgr Jun 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 57 additions & 19 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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.
//
Expand All @@ -2465,30 +2472,61 @@ 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()
.copied()
.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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/reference/tokens.html#literals>",
);
}
diag.emit();
Expand Down
25 changes: 18 additions & 7 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,24 @@ 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() {}`.
Err(self.sess.create_err(StructLiteralNeedingParens {
span: maybe_struct_name.span.to(expr.span),
sugg: StructLiteralNeedingParensSugg {
before: maybe_struct_name.span.shrink_to_lo(),
after: expr.span.shrink_to_hi(),
},
}))
// 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();
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.shrink_to_lo(),
after: expr.span.shrink_to_hi(),
},
}))
} else {
return None;
}
} else {
self.sess.emit_err(StructLiteralBodyWithoutPath {
span: expr.span,
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,21 @@ 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) {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions library/std/src/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -267,6 +268,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,
Expand Down Expand Up @@ -313,6 +316,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.
Expand Down Expand Up @@ -376,4 +381,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) -> u32 {
Status as u32
}
}
1 change: 1 addition & 0 deletions library/std/src/sys/windows/c/windows_sys.lst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sys/windows/c/windows_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sys/windows/rand.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::ffi::c_void;
use crate::io;
use crate::mem;
use crate::ptr;
use crate::sys::c;
Expand All @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,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;
}

Expand Down Expand Up @@ -1525,11 +1529,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
Expand Down
4 changes: 2 additions & 2 deletions tests/rustdoc-gui/search-reexport.goml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"})
14 changes: 14 additions & 0 deletions tests/ui/associated-inherent-types/issue-111404-0.rs
Original file line number Diff line number Diff line change
@@ -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() {}
13 changes: 13 additions & 0 deletions tests/ui/associated-inherent-types/issue-111404-1.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading