Skip to content

Commit 76ee6fc

Browse files
committed
Auto merge of rust-lang#122312 - matthiaskrgr:rollup-0p8y7gg, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#122275 (disable OOM test in Miri) - rust-lang#122276 (io::Read trait: make it more clear when we are adressing implementations vs callers) - rust-lang#122277 (BorrowedCursor docs clarification) - rust-lang#122286 (use Instance::expect_resolve() instead of unwraping Instance::resolve()) - rust-lang#122290 (MIR printing: print the path of uneval'd const) - rust-lang#122293 (diagnostics: Do not suggest using `#[unix_sigpipe]` without a value) - rust-lang#122297 (bootstrap: document what the triples in 'Build' mean) - rust-lang#122302 (docs: Correct ptr/ref verbiage in SliceIndex docs.) - rust-lang#122304 (fix metadata for dyn-star in new solver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3b1717c + 16ffeb2 commit 76ee6fc

File tree

99 files changed

+204
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+204
-169
lines changed

compiler/rustc_codegen_cranelift/src/main_shim.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,12 @@ pub(crate) fn maybe_create_entry_wrapper(
115115
termination_trait,
116116
)
117117
.unwrap();
118-
let report = Instance::resolve(
118+
let report = Instance::expect_resolve(
119119
tcx,
120120
ParamEnv::reveal_all(),
121121
report.def_id,
122122
tcx.mk_args(&[GenericArg::from(main_ret_ty)]),
123123
)
124-
.unwrap()
125-
.unwrap()
126124
.polymorphize(tcx);
127125

128126
let report_name = tcx.symbol_name(report).name;
@@ -142,14 +140,12 @@ pub(crate) fn maybe_create_entry_wrapper(
142140
}
143141
} else if is_main_fn {
144142
let start_def_id = tcx.require_lang_item(LangItem::Start, None);
145-
let start_instance = Instance::resolve(
143+
let start_instance = Instance::expect_resolve(
146144
tcx,
147145
ParamEnv::reveal_all(),
148146
start_def_id,
149147
tcx.mk_args(&[main_ret_ty.into()]),
150148
)
151-
.unwrap()
152-
.unwrap()
153149
.polymorphize(tcx);
154150
let start_func_id = import_function(tcx, m, start_instance);
155151

compiler/rustc_codegen_gcc/src/context.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -473,14 +473,12 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
473473
let tcx = self.tcx;
474474
let func = match tcx.lang_items().eh_personality() {
475475
Some(def_id) if !wants_msvc_seh(self.sess()) => {
476-
let instance = ty::Instance::resolve(
476+
let instance = ty::Instance::expect_resolve(
477477
tcx,
478478
ty::ParamEnv::reveal_all(),
479479
def_id,
480480
ty::List::empty(),
481-
)
482-
.unwrap()
483-
.unwrap();
481+
);
484482

485483
let symbol_name = tcx.symbol_name(instance).name;
486484
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());

compiler/rustc_codegen_llvm/src/context.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,12 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
558558

559559
let tcx = self.tcx;
560560
let llfn = match tcx.lang_items().eh_personality() {
561-
Some(def_id) if name.is_none() => self.get_fn_addr(
562-
ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, ty::List::empty())
563-
.unwrap()
564-
.unwrap(),
565-
),
561+
Some(def_id) if name.is_none() => self.get_fn_addr(ty::Instance::expect_resolve(
562+
tcx,
563+
ty::ParamEnv::reveal_all(),
564+
def_id,
565+
ty::List::empty(),
566+
)),
566567
_ => {
567568
let name = name.unwrap_or("rust_eh_personality");
568569
if let Some(llfn) = self.get_declared_value(name) {

compiler/rustc_codegen_ssa/src/base.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,12 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
467467

468468
let (start_fn, start_ty, args) = if let EntryFnType::Main { sigpipe } = entry_type {
469469
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None);
470-
let start_fn = cx.get_fn_addr(
471-
ty::Instance::resolve(
472-
cx.tcx(),
473-
ty::ParamEnv::reveal_all(),
474-
start_def_id,
475-
cx.tcx().mk_args(&[main_ret_ty.into()]),
476-
)
477-
.unwrap()
478-
.unwrap(),
479-
);
470+
let start_fn = cx.get_fn_addr(ty::Instance::expect_resolve(
471+
cx.tcx(),
472+
ty::ParamEnv::reveal_all(),
473+
start_def_id,
474+
cx.tcx().mk_args(&[main_ret_ty.into()]),
475+
));
480476

481477
let i8_ty = cx.type_i8();
482478
let arg_sigpipe = bx.const_u8(sigpipe);

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
6767
trace!(
6868
"eval_body_using_ecx: pushing stack frame for global: {}{}",
6969
with_no_trimmed_paths!(ecx.tcx.def_path_str(cid.instance.def_id())),
70-
cid.promoted.map_or_else(String::new, |p| format!("::promoted[{p:?}]"))
70+
cid.promoted.map_or_else(String::new, |p| format!("::{p:?}"))
7171
);
7272

7373
ecx.push_stack_frame(

compiler/rustc_const_eval/src/const_eval/machine.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,12 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
243243
} else if Some(def_id) == self.tcx.lang_items().panic_fmt() {
244244
// For panic_fmt, call const_panic_fmt instead.
245245
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None);
246-
let new_instance = ty::Instance::resolve(
246+
let new_instance = ty::Instance::expect_resolve(
247247
*self.tcx,
248248
ty::ParamEnv::reveal_all(),
249249
const_def_id,
250250
instance.args,
251-
)
252-
.unwrap()
253-
.unwrap();
251+
);
254252

255253
return Ok(Some(new_instance));
256254
} else if Some(def_id) == self.tcx.lang_items().align_offset_fn() {

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
389389
),
390390

391391
// Entry point:
392-
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
392+
gated!(unix_sigpipe, Normal, template!(NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
393393
ungated!(start, Normal, template!(Word), WarnFollowing, @only_local: true),
394394
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing, @only_local: true),
395395
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, @only_local: true),

compiler/rustc_middle/src/mir/consts.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_target::abi::{HasDataLayout, Size};
77

88
use crate::mir::interpret::{alloc_range, AllocId, ConstAllocation, ErrorHandled, Scalar};
99
use crate::mir::{pretty_print_const_value, Promoted};
10+
use crate::ty::print::with_no_trimmed_paths;
1011
use crate::ty::GenericArgsRef;
1112
use crate::ty::ScalarInt;
1213
use crate::ty::{self, print::pretty_print_const, Ty, TyCtxt};
@@ -489,9 +490,18 @@ impl<'tcx> Display for Const<'tcx> {
489490
Const::Ty(c) => pretty_print_const(c, fmt, true),
490491
Const::Val(val, ty) => pretty_print_const_value(val, ty, fmt),
491492
// FIXME(valtrees): Correctly print mir constants.
492-
Const::Unevaluated(..) => {
493-
fmt.write_str("_")?;
494-
Ok(())
493+
Const::Unevaluated(c, _ty) => {
494+
ty::tls::with(move |tcx| {
495+
let c = tcx.lift(c).unwrap();
496+
// Matches `GlobalId` printing.
497+
let instance =
498+
with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args));
499+
write!(fmt, "{instance}")?;
500+
if let Some(promoted) = c.promoted {
501+
write!(fmt, "::{promoted:?}")?;
502+
}
503+
Ok(())
504+
})
495505
}
496506
}
497507
}

compiler/rustc_middle/src/mir/pretty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
496496
_ => tcx.is_closure_like(def_id),
497497
};
498498
match (kind, body.source.promoted) {
499-
(_, Some(i)) => write!(w, "{i:?} in ")?,
499+
(_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts
500500
(DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?,
501501
(DefKind::Static(hir::Mutability::Not), _) => write!(w, "static ")?,
502502
(DefKind::Static(hir::Mutability::Mut), _) => write!(w, "static mut ")?,
@@ -509,6 +509,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
509509
// see notes on #41697 elsewhere
510510
write!(w, "{}", tcx.def_path_str(def_id))?
511511
}
512+
if let Some(p) = body.source.promoted {
513+
write!(w, "::{p:?}")?;
514+
}
512515

513516
if body.source.promoted.is_none() && is_function {
514517
write!(w, "(")?;

compiler/rustc_monomorphize/src/collector.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1339,14 +1339,12 @@ impl<'v> RootCollector<'_, 'v> {
13391339
main_ret_ty.no_bound_vars().unwrap(),
13401340
);
13411341

1342-
let start_instance = Instance::resolve(
1342+
let start_instance = Instance::expect_resolve(
13431343
self.tcx,
13441344
ty::ParamEnv::reveal_all(),
13451345
start_def_id,
13461346
self.tcx.mk_args(&[main_ret_ty.into()]),
1347-
)
1348-
.unwrap()
1349-
.unwrap();
1347+
);
13501348

13511349
self.output.push(create_fn_mono_item(self.tcx, start_instance, DUMMY_SP));
13521350
}

compiler/rustc_passes/src/entry.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ fn sigpipe(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
156156
(Some(sym::inherit), None) => sigpipe::INHERIT,
157157
(Some(sym::sig_ign), None) => sigpipe::SIG_IGN,
158158
(Some(sym::sig_dfl), None) => sigpipe::SIG_DFL,
159-
(_, Some(_)) => {
160-
// Keep going so that `fn emit_malformed_attribute()` can print
161-
// an excellent error message
159+
(Some(_), None) => {
160+
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
162161
sigpipe::DEFAULT
163162
}
164163
_ => {
165-
tcx.dcx().emit_err(UnixSigpipeValues { span: attr.span });
164+
// Keep going so that `fn emit_malformed_attribute()` can print
165+
// an excellent error message
166166
sigpipe::DEFAULT
167167
}
168168
}

compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -542,13 +542,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
542542
| ty::Coroutine(..)
543543
| ty::CoroutineWitness(..)
544544
| ty::Never
545-
| ty::Foreign(..) => tcx.types.unit,
545+
| ty::Foreign(..)
546+
| ty::Dynamic(_, _, ty::DynStar) => tcx.types.unit,
546547

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

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

551-
ty::Dynamic(_, _, _) => {
552+
ty::Dynamic(_, _, ty::Dyn) => {
552553
let dyn_metadata = tcx.require_lang_item(LangItem::DynMetadata, None);
553554
tcx.type_of(dyn_metadata)
554555
.instantiate(tcx, &[ty::GenericArg::from(goal.predicate.self_ty())])

library/core/src/io/borrowed_buf.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ impl<'data> BorrowedBuf<'data> {
139139
}
140140
}
141141

142-
/// A writeable view of the unfilled portion of a [`BorrowedBuf`](BorrowedBuf).
142+
/// A writeable view of the unfilled portion of a [`BorrowedBuf`].
143+
///
144+
/// The unfilled portion consists of an initialized and an uninitialized part; see [`BorrowedBuf`]
145+
/// for details.
143146
///
144-
/// Provides access to the initialized and uninitialized parts of the underlying `BorrowedBuf`.
145147
/// Data can be written directly to the cursor by using [`append`](BorrowedCursor::append) or
146148
/// indirectly by getting a slice of part or all of the cursor and writing into the slice. In the
147149
/// indirect case, the caller must call [`advance`](BorrowedCursor::advance) after writing to inform

library/core/src/slice/index.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,19 @@ pub unsafe trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
180180
#[unstable(feature = "slice_index_methods", issue = "none")]
181181
fn get_mut(self, slice: &mut T) -> Option<&mut Self::Output>;
182182

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

192-
/// Returns a mutable reference to the output at this location, without
192+
/// Returns a mutable pointer to the output at this location, without
193193
/// performing any bounds checking.
194194
/// Calling this method with an out-of-bounds index or a dangling `slice` pointer
195-
/// is *[undefined behavior]* even if the resulting reference is not used.
195+
/// is *[undefined behavior]* even if the resulting pointer is not used.
196196
///
197197
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
198198
#[unstable(feature = "slice_index_methods", issue = "none")]

library/std/src/io/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,9 @@ pub trait Read {
692692
/// Callers have to ensure that no unchecked out-of-bounds accesses are possible even if
693693
/// `n > buf.len()`.
694694
///
695-
/// No guarantees are provided about the contents of `buf` when this
696-
/// function is called, so implementations cannot rely on any property of the
697-
/// contents of `buf` being true. It is recommended that *implementations*
698-
/// only write data to `buf` instead of reading its contents.
695+
/// *Implementations* of this method can make no assumptions about the contents of `buf` when
696+
/// this function is called. It is recommended that implementations only write data to `buf`
697+
/// instead of reading its contents.
699698
///
700699
/// Correspondingly, however, *callers* of this method in unsafe code must not assume
701700
/// any guarantees about how the implementation uses `buf`. The trait is safe to implement,
@@ -901,12 +900,10 @@ pub trait Read {
901900
/// This function reads as many bytes as necessary to completely fill the
902901
/// specified buffer `buf`.
903902
///
904-
/// No guarantees are provided about the contents of `buf` when this
905-
/// function is called, so implementations cannot rely on any property of the
906-
/// contents of `buf` being true. It is recommended that implementations
907-
/// only write data to `buf` instead of reading its contents. The
908-
/// documentation on [`read`] has a more detailed explanation on this
909-
/// subject.
903+
/// *Implementations* of this method can make no assumptions about the contents of `buf` when
904+
/// this function is called. It is recommended that implementations only write data to `buf`
905+
/// instead of reading its contents. The documentation on [`read`] has a more detailed
906+
/// explanation of this subject.
910907
///
911908
/// # Errors
912909
///

library/std/src/io/tests.rs

+2
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ fn read_buf_full_read() {
694694
}
695695

696696
#[test]
697+
// Miri does not support signalling OOM
698+
#[cfg_attr(miri, ignore)]
697699
// 64-bit only to be sure the allocator will fail fast on an impossible to satsify size
698700
#[cfg(target_pointer_width = "64")]
699701
fn try_oom_error() {

src/bootstrap/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,11 @@ pub struct Build {
171171
doc_tests: DocTests,
172172
verbosity: usize,
173173

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

179181
initial_rustc: PathBuf,

tests/mir-opt/building/custom/consts.consts.built.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ fn consts() -> () {
1010

1111
bb0: {
1212
_1 = const 5_u8;
13-
_2 = const _;
13+
_2 = const consts::<C>::{constant#0};
1414
_3 = const C;
15-
_4 = const _;
15+
_4 = const D;
1616
_5 = consts::<10>;
1717
return;
1818
}

tests/mir-opt/const_promotion_extern_static.BAR-promoted[0].SimplifyCfg-elaborate-drops.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `BAR::promoted[0]` after SimplifyCfg-elaborate-drops
22

3-
promoted[0] in BAR: &[&i32; 1] = {
3+
const BAR::promoted[0]: &[&i32; 1] = {
44
let mut _0: &[&i32; 1];
55
let mut _1: [&i32; 1];
66
let mut _2: &i32;

tests/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- _4 = &(*_5);
2121
- _3 = [move _4];
2222
- _2 = &_3;
23-
+ _6 = const _;
23+
+ _6 = const BAR::promoted[0];
2424
+ _2 = &(*_6);
2525
_1 = move _2 as &[&i32] (PointerCoercion(Unsize));
2626
- StorageDead(_4);

tests/mir-opt/const_promotion_extern_static.FOO-promoted[0].SimplifyCfg-elaborate-drops.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// MIR for `FOO::promoted[0]` after SimplifyCfg-elaborate-drops
22

3-
promoted[0] in FOO: &[&i32; 1] = {
3+
const FOO::promoted[0]: &[&i32; 1] = {
44
let mut _0: &[&i32; 1];
55
let mut _1: [&i32; 1];
66
let mut _2: &i32;

tests/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- _4 = &(*_5);
2323
- _3 = [move _4];
2424
- _2 = &_3;
25-
+ _6 = const _;
25+
+ _6 = const FOO::promoted[0];
2626
+ _2 = &(*_6);
2727
_1 = move _2 as &[&i32] (PointerCoercion(Unsize));
2828
- StorageDead(_4);

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.32bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-abort.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.GVN.64bit.panic-unwind.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
StorageLive(_1);
2626
StorageLive(_2);
2727
StorageLive(_3);
28-
_9 = const _;
28+
_9 = const main::promoted[0];
2929
_3 = &(*_9);
3030
_2 = &raw const (*_3);
3131
_1 = move _2 as *const [i32] (PointerCoercion(Unsize));

0 commit comments

Comments
 (0)