Skip to content

Commit

Permalink
Auto merge of #122312 - matthiaskrgr:rollup-0p8y7gg, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #122275 (disable OOM test in Miri)
 - #122276 (io::Read trait: make it more clear when we are adressing implementations vs callers)
 - #122277 (BorrowedCursor docs clarification)
 - #122286 (use Instance::expect_resolve() instead of unwraping Instance::resolve())
 - #122290 (MIR printing: print the path of uneval'd const)
 - #122293 (diagnostics: Do not suggest using `#[unix_sigpipe]` without a value)
 - #122297 (bootstrap: document what the triples in 'Build' mean)
 - #122302 (docs: Correct ptr/ref verbiage in SliceIndex docs.)
 - #122304 (fix metadata for dyn-star in new solver)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 10, 2024
2 parents 3b1717c + 16ffeb2 commit 76ee6fc
Show file tree
Hide file tree
Showing 99 changed files with 204 additions and 169 deletions.
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

0 comments on commit 76ee6fc

Please sign in to comment.