Skip to content
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

Rollup of 9 pull requests #122312

Merged
merged 18 commits into from
Mar 11, 2024
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
1dd47e0
disable OOM test in Miri
RalfJung Mar 10, 2024
93049be
io::Read trait: make it more clear when we are adressing implementati…
RalfJung Mar 10, 2024
c06f801
BorrowedCursor docs clarification
RalfJung Mar 10, 2024
aa9145e
use Instance::expect_resolve() instead of unwraping Instance::resolve()
RalfJung Mar 10, 2024
7d99e80
MIR printing: print the path of uneval'd const; refer to promoteds in…
RalfJung Mar 10, 2024
ee428c5
diagnostics: Do not suggest using `#[unix_sigpipe]` without a value
Enselic Mar 10, 2024
89ed992
bootstrap: document what the triples in 'Build' mean
RalfJung Mar 10, 2024
dd2cda7
docs: Correct ptr/ref verbiage in SliceIndex docs.
ratmice Mar 10, 2024
e4bafa2
fix metadata for dyn-star in new solver
Mar 10, 2024
217d004
Rollup merge of #122275 - RalfJung:std-oom, r=workingjubilee
matthiaskrgr Mar 10, 2024
0c73b2d
Rollup merge of #122276 - RalfJung:io-read, r=Nilstrieb
matthiaskrgr Mar 10, 2024
ff09d32
Rollup merge of #122277 - RalfJung:BorrowedCursor, r=cuviper
matthiaskrgr Mar 10, 2024
b02f2a0
Rollup merge of #122286 - RalfJung:resolve, r=compiler-errors
matthiaskrgr Mar 10, 2024
9ccbbda
Rollup merge of #122290 - RalfJung:mir-printing, r=compiler-errors
matthiaskrgr Mar 10, 2024
c4b159c
Rollup merge of #122293 - Enselic:no-bare-unix_sigpipe, r=fmease
matthiaskrgr Mar 10, 2024
2a3a8db
Rollup merge of #122297 - RalfJung:bootstrap-build, r=onur-ozkan
matthiaskrgr Mar 10, 2024
97f3b33
Rollup merge of #122302 - ratmice:issue122234, r=cuviper
matthiaskrgr Mar 10, 2024
16ffeb2
Rollup merge of #122304 - lukas-code:dyn-star-meta, r=compiler-errors
matthiaskrgr Mar 10, 2024
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
8 changes: 2 additions & 6 deletions compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ pub(crate) fn maybe_create_entry_wrapper(
termination_trait,
)
.unwrap();
let report = Instance::resolve(
let report = Instance::expect_resolve(
tcx,
ParamEnv::reveal_all(),
report.def_id,
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
)
.unwrap()
.unwrap()
.polymorphize(tcx);

let report_name = tcx.symbol_name(report).name;
Expand All @@ -142,14 +140,12 @@ pub(crate) fn maybe_create_entry_wrapper(
}
} else if is_main_fn {
let start_def_id = tcx.require_lang_item(LangItem::Start, None);
let start_instance = Instance::resolve(
let start_instance = Instance::expect_resolve(
tcx,
ParamEnv::reveal_all(),
start_def_id,
tcx.mk_args(&[main_ret_ty.into()]),
)
.unwrap()
.unwrap()
.polymorphize(tcx);
let start_func_id = import_function(tcx, m, start_instance);

Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,12 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let tcx = self.tcx;
let func = match tcx.lang_items().eh_personality() {
Some(def_id) if !wants_msvc_seh(self.sess()) => {
let instance = ty::Instance::resolve(
let instance = ty::Instance::expect_resolve(
tcx,
ty::ParamEnv::reveal_all(),
def_id,
ty::List::empty(),
)
.unwrap()
.unwrap();
);

let symbol_name = tcx.symbol_name(instance).name;
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,12 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {

let tcx = self.tcx;
let llfn = match tcx.lang_items().eh_personality() {
Some(def_id) if name.is_none() => self.get_fn_addr(
ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, ty::List::empty())
.unwrap()
.unwrap(),
),
Some(def_id) if name.is_none() => self.get_fn_addr(ty::Instance::expect_resolve(
tcx,
ty::ParamEnv::reveal_all(),
def_id,
ty::List::empty(),
)),
_ => {
let name = name.unwrap_or("rust_eh_personality");
if let Some(llfn) = self.get_declared_value(name) {
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,12 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

let (start_fn, start_ty, args) = if let EntryFnType::Main { sigpipe } = entry_type {
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None);
let start_fn = cx.get_fn_addr(
ty::Instance::resolve(
cx.tcx(),
ty::ParamEnv::reveal_all(),
start_def_id,
cx.tcx().mk_args(&[main_ret_ty.into()]),
)
.unwrap()
.unwrap(),
);
let start_fn = cx.get_fn_addr(ty::Instance::expect_resolve(
cx.tcx(),
ty::ParamEnv::reveal_all(),
start_def_id,
cx.tcx().mk_args(&[main_ret_ty.into()]),
));

let i8_ty = cx.type_i8();
let arg_sigpipe = bx.const_u8(sigpipe);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
trace!(
"eval_body_using_ecx: pushing stack frame for global: {}{}",
with_no_trimmed_paths!(ecx.tcx.def_path_str(cid.instance.def_id())),
cid.promoted.map_or_else(String::new, |p| format!("::promoted[{p:?}]"))
cid.promoted.map_or_else(String::new, |p| format!("::{p:?}"))
);

ecx.push_stack_frame(
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,12 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
} else if Some(def_id) == self.tcx.lang_items().panic_fmt() {
// For panic_fmt, call const_panic_fmt instead.
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
let new_instance = ty::Instance::resolve(
let new_instance = ty::Instance::expect_resolve(
*self.tcx,
ty::ParamEnv::reveal_all(),
const_def_id,
instance.args,
)
.unwrap()
.unwrap();
);

return Ok(Some(new_instance));
} else if Some(def_id) == self.tcx.lang_items().align_offset_fn() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

// Entry point:
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
gated!(unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
Expand Down
16 changes: 13 additions & 3 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_target::abi::{HasDataLayout, Size};

use crate::mir::interpret::{alloc_range, AllocId, ConstAllocation, ErrorHandled, Scalar};
use crate::mir::{pretty_print_const_value, Promoted};
use crate::ty::print::with_no_trimmed_paths;
use crate::ty::GenericArgsRef;
use crate::ty::ScalarInt;
use crate::ty::{self, print::pretty_print_const, Ty, TyCtxt};
Expand Down Expand Up @@ -489,9 +490,18 @@ impl<'tcx> Display for Const<'tcx> {
Const::Ty(c) => pretty_print_const(c, fmt, true),
Const::Val(val, ty) => pretty_print_const_value(val, ty, fmt),
// FIXME(valtrees): Correctly print mir constants.
Const::Unevaluated(..) => {
fmt.write_str("_")?;
Ok(())
Const::Unevaluated(c, _ty) => {
ty::tls::with(move |tcx| {
let c = tcx.lift(c).unwrap();
// Matches `GlobalId` printing.
let instance =
with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args));
write!(fmt, "{instance}")?;
if let Some(promoted) = c.promoted {
write!(fmt, "::{promoted:?}")?;
}
Ok(())
})
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
_ => tcx.is_closure_like(def_id),
};
match (kind, body.source.promoted) {
(_, Some(i)) => write!(w, "{i:?} in ")?,
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
(DefKind::Static(hir::Mutability::Not), _) => write!(w, "static ")?,
(DefKind::Static(hir::Mutability::Mut), _) => write!(w, "static mut ")?,
Expand All @@ -509,6 +509,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
// see notes on #41697 elsewhere
write!(w, "{}", tcx.def_path_str(def_id))?
}
if let Some(p) = body.source.promoted {
write!(w, "::{p:?}")?;
}

if body.source.promoted.is_none() && is_function {
write!(w, "(")?;
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,14 +1339,12 @@ impl<'v> RootCollector<'_, 'v> {
main_ret_ty.no_bound_vars().unwrap(),
);

let start_instance = Instance::resolve(
let start_instance = Instance::expect_resolve(
self.tcx,
ty::ParamEnv::reveal_all(),
start_def_id,
self.tcx.mk_args(&[main_ret_ty.into()]),
)
.unwrap()
.unwrap();
);

self.output.push(create_fn_mono_item(self.tcx, start_instance, DUMMY_SP));
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_passes/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
(Some(sym::inherit), None) => sigpipe::INHERIT,
(Some(sym::sig_ign), None) => sigpipe::SIG_IGN,
(Some(sym::sig_dfl), None) => sigpipe::SIG_DFL,
(_, Some(_)) => {
// Keep going so that `fn emit_malformed_attribute()` can print
// an excellent error message
(Some(_), None) => {
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
sigpipe::DEFAULT
}
_ => {
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
// Keep going so that `fn emit_malformed_attribute()` can print
// an excellent error message
sigpipe::DEFAULT
}
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
| ty::Coroutine(..)
| ty::CoroutineWitness(..)
| ty::Never
| ty::Foreign(..) => tcx.types.unit,
| ty::Foreign(..)
| ty::Dynamic(_, _, ty::DynStar) => tcx.types.unit,

ty::Error(e) => Ty::new_error(tcx, *e),

ty::Str | ty::Slice(_) => tcx.types.usize,

ty::Dynamic(_, _, _) => {
ty::Dynamic(_, _, ty::Dyn) => {
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
tcx.type_of(dyn_metadata)
.instantiate(tcx, &[ty::GenericArg::from(goal.predicate.self_ty())])
Expand Down
6 changes: 4 additions & 2 deletions library/core/src/io/borrowed_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ impl<'data> BorrowedBuf<'data> {
}
}

/// A writeable view of the unfilled portion of a [`BorrowedBuf`](BorrowedBuf).
/// A writeable view of the unfilled portion of a [`BorrowedBuf`].
///
/// The unfilled portion consists of an initialized and an uninitialized part; see [`BorrowedBuf`]
/// for details.
///
/// Provides access to the initialized and uninitialized parts of the underlying `BorrowedBuf`.
/// Data can be written directly to the cursor by using [`append`](BorrowedCursor::append) or
/// indirectly by getting a slice of part or all of the cursor and writing into the slice. In the
/// indirect case, the caller must call [`advance`](BorrowedCursor::advance) after writing to inform
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
#[unstable(feature = "slice_index_methods", issue = "none")]
fn get_mut(self, slice: &mut T) -> Option<&mut Self::Output>;

/// Returns a shared reference to the output at this location, without
/// Returns a pointer to the output at this location, without
/// performing any bounds checking.
/// Calling this method with an out-of-bounds index or a dangling `slice` pointer
/// is *[undefined behavior]* even if the resulting reference is not used.
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
#[unstable(feature = "slice_index_methods", issue = "none")]
unsafe fn get_unchecked(self, slice: *const T) -> *const Self::Output;

/// Returns a mutable reference to the output at this location, without
/// Returns a mutable pointer to the output at this location, without
/// performing any bounds checking.
/// Calling this method with an out-of-bounds index or a dangling `slice` pointer
/// is *[undefined behavior]* even if the resulting reference is not used.
/// is *[undefined behavior]* even if the resulting pointer is not used.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
#[unstable(feature = "slice_index_methods", issue = "none")]
Expand Down
17 changes: 7 additions & 10 deletions library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,9 @@ pub trait Read {
/// Callers have to ensure that no unchecked out-of-bounds accesses are possible even if
/// `n > buf.len()`.
///
/// No guarantees are provided about the contents of `buf` when this
/// function is called, so implementations cannot rely on any property of the
/// contents of `buf` being true. It is recommended that *implementations*
/// only write data to `buf` instead of reading its contents.
/// *Implementations* of this method can make no assumptions about the contents of `buf` when
/// this function is called. It is recommended that implementations only write data to `buf`
/// instead of reading its contents.
///
/// Correspondingly, however, *callers* of this method in unsafe code must not assume
/// any guarantees about how the implementation uses `buf`. The trait is safe to implement,
Expand Down Expand Up @@ -901,12 +900,10 @@ pub trait Read {
/// This function reads as many bytes as necessary to completely fill the
/// specified buffer `buf`.
///
/// No guarantees are provided about the contents of `buf` when this
/// function is called, so implementations cannot rely on any property of the
/// contents of `buf` being true. It is recommended that implementations
/// only write data to `buf` instead of reading its contents. The
/// documentation on [`read`] has a more detailed explanation on this
/// subject.
/// *Implementations* of this method can make no assumptions about the contents of `buf` when
/// this function is called. It is recommended that implementations only write data to `buf`
/// instead of reading its contents. The documentation on [`read`] has a more detailed
/// explanation of this subject.
///
/// # Errors
///
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/io/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ fn read_buf_full_read() {
}

#[test]
// Miri does not support signalling OOM
#[cfg_attr(miri, ignore)]
// 64-bit only to be sure the allocator will fail fast on an impossible to satsify size
#[cfg(target_pointer_width = "64")]
fn try_oom_error() {
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ pub struct Build {
doc_tests: DocTests,
verbosity: usize,

// Targets for which to build
/// Build triple for the pre-compiled snapshot compiler.
build: TargetSelection,
/// Which triples to produce a compiler toolchain for.
hosts: Vec<TargetSelection>,
/// Which triples to build libraries (core/alloc/std/test/proc_macro) for.
targets: Vec<TargetSelection>,

initial_rustc: PathBuf,
Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/building/custom/consts.consts.built.after.mir
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fn consts() -> () {

bb0: {
_1 = const 5_u8;
_2 = const _;
_2 = const consts::<C>::{constant#0};
_3 = const C;
_4 = const _;
_4 = const D;
_5 = consts::<10>;
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIR for `BAR::promoted[0]` after SimplifyCfg-elaborate-drops

promoted[0] in BAR: &[&i32; 1] = {
const BAR::promoted[0]: &[&i32; 1] = {
let mut _0: &[&i32; 1];
let mut _1: [&i32; 1];
let mut _2: &i32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- _4 = &(*_5);
- _3 = [move _4];
- _2 = &_3;
+ _6 = const _;
+ _6 = const BAR::promoted[0];
+ _2 = &(*_6);
_1 = move _2 as &[&i32] (PointerCoercion(Unsize));
- StorageDead(_4);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIR for `FOO::promoted[0]` after SimplifyCfg-elaborate-drops

promoted[0] in FOO: &[&i32; 1] = {
const FOO::promoted[0]: &[&i32; 1] = {
let mut _0: &[&i32; 1];
let mut _1: [&i32; 1];
let mut _2: &i32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- _4 = &(*_5);
- _3 = [move _4];
- _2 = &_3;
+ _6 = const _;
+ _6 = const FOO::promoted[0];
+ _2 = &(*_6);
_1 = move _2 as &[&i32] (PointerCoercion(Unsize));
- StorageDead(_4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
_9 = const _;
_9 = const main::promoted[0];
_3 = &(*_9);
_2 = &raw const (*_3);
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
_9 = const _;
_9 = const main::promoted[0];
_3 = &(*_9);
_2 = &raw const (*_3);
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
_9 = const _;
_9 = const main::promoted[0];
_3 = &(*_9);
_2 = &raw const (*_3);
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
StorageLive(_1);
StorageLive(_2);
StorageLive(_3);
_9 = const _;
_9 = const main::promoted[0];
_3 = &(*_9);
_2 = &raw const (*_3);
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));
Expand Down
Loading
Loading