Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2fdbf07

Browse files
committedJul 25, 2022
Auto merge of #99707 - JohnTitor:rollup-74rb8vq, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #95040 (protect `std::io::Take::limit` from overflow in `read`) - #95916 (kmc-solid: Use `libc::abort` to abort a program) - #99494 (Use non-relocatable code in nofile-limit.rs test) - #99581 (Improve error messages involving `derive` and `packed`.) - #99643 (Add `sign-ext` target feature to the WASM target) - #99659 (Use `VecMap::get` in `ConstraintLocator::check`) - #99690 (add miri-track-caller to more intrinsic-exposing methods) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2f320a2 + d1e4342 commit 2fdbf07

File tree

19 files changed

+140
-111
lines changed

19 files changed

+140
-111
lines changed
 

‎compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ const WASM_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
249249
("bulk-memory", Some(sym::wasm_target_feature)),
250250
("mutable-globals", Some(sym::wasm_target_feature)),
251251
("reference-types", Some(sym::wasm_target_feature)),
252+
("sign-ext", Some(sym::wasm_target_feature)),
252253
];
253254

254255
const BPF_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[("alu32", Some(sym::bpf_target_feature))];

‎compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
3636
tcx.struct_span_lint_hir(UNALIGNED_REFERENCES, lint_hir_id, tcx.def_span(def_id), |lint| {
3737
// FIXME: when we make this a hard error, this should have its
3838
// own error code.
39-
let message = if tcx.generics_of(def_id).own_requires_monomorphization() {
40-
"`#[derive]` can't be used on a `#[repr(packed)]` struct with \
41-
type or const parameters (error E0133)"
39+
let extra = if tcx.generics_of(def_id).own_requires_monomorphization() {
40+
"with type or const parameters"
4241
} else {
43-
"`#[derive]` can't be used on a `#[repr(packed)]` struct that \
44-
does not derive Copy (error E0133)"
42+
"that does not derive `Copy`"
4543
};
44+
let message = format!(
45+
"`{}` can't be derived on this `#[repr(packed)]` struct {} (error E0133)",
46+
tcx.item_name(tcx.trait_id_of_impl(def_id.to_def_id()).expect("derived trait name")),
47+
extra
48+
);
4649
lint.build(message).emit();
4750
});
4851
}

‎compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
538538

539539
impl ConstraintLocator<'_> {
540540
#[instrument(skip(self), level = "debug")]
541-
fn check(&mut self, def_id: LocalDefId) {
541+
fn check(&mut self, item_def_id: LocalDefId) {
542542
// Don't try to check items that cannot possibly constrain the type.
543-
if !self.tcx.has_typeck_results(def_id) {
543+
if !self.tcx.has_typeck_results(item_def_id) {
544544
debug!("no constraint: no typeck results");
545545
return;
546546
}
@@ -555,26 +555,20 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
555555
// // because we again need to reveal `Foo` so we can check whether the
556556
// // constant does not contain interior mutability.
557557
// ```
558-
let tables = self.tcx.typeck(def_id);
558+
let tables = self.tcx.typeck(item_def_id);
559559
if let Some(_) = tables.tainted_by_errors {
560560
self.found = Some(ty::OpaqueHiddenType { span: DUMMY_SP, ty: self.tcx.ty_error() });
561561
return;
562562
}
563-
if tables.concrete_opaque_types.get(&self.def_id).is_none() {
563+
if !tables.concrete_opaque_types.contains_key(&self.def_id) {
564564
debug!("no constraints in typeck results");
565565
return;
566566
}
567567
// Use borrowck to get the type with unerased regions.
568-
let concrete_opaque_types = &self.tcx.mir_borrowck(def_id).concrete_opaque_types;
568+
let concrete_opaque_types = &self.tcx.mir_borrowck(item_def_id).concrete_opaque_types;
569569
debug!(?concrete_opaque_types);
570-
for &(def_id, concrete_type) in concrete_opaque_types {
571-
if def_id != self.def_id {
572-
// Ignore constraints for other opaque types.
573-
continue;
574-
}
575-
570+
if let Some(&concrete_type) = concrete_opaque_types.get(&self.def_id) {
576571
debug!(?concrete_type, "found constraint");
577-
578572
if let Some(prev) = self.found {
579573
if concrete_type.ty != prev.ty && !(concrete_type, prev).references_error() {
580574
prev.report_mismatch(&concrete_type, self.tcx);

‎library/core/src/hint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ use crate::intrinsics;
9696
#[inline]
9797
#[stable(feature = "unreachable", since = "1.27.0")]
9898
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
99+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
99100
pub const unsafe fn unreachable_unchecked() -> ! {
100101
// SAFETY: the safety contract for `intrinsics::unreachable` must
101102
// be upheld by the caller.

‎library/core/src/intrinsics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,7 @@ pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -
24492449
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
24502450
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
24512451
#[inline]
2452+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
24522453
pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
24532454
extern "rust-intrinsic" {
24542455
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
@@ -2535,6 +2536,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
25352536
#[cfg_attr(not(bootstrap), rustc_allowed_through_unstable_modules)]
25362537
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
25372538
#[inline]
2539+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
25382540
pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
25392541
extern "rust-intrinsic" {
25402542
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]

‎library/core/src/mem/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,7 @@ impl<T> fmt::Debug for Discriminant<T> {
11241124
#[stable(feature = "discriminant_value", since = "1.21.0")]
11251125
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
11261126
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")]
1127+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11271128
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
11281129
Discriminant(intrinsics::discriminant_value(v))
11291130
}

‎library/core/src/num/int_macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ macro_rules! int_impl {
449449
without modifying the original"]
450450
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
451451
#[inline(always)]
452+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
452453
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
453454
// SAFETY: the caller must uphold the safety contract for
454455
// `unchecked_add`.
@@ -517,6 +518,7 @@ macro_rules! int_impl {
517518
without modifying the original"]
518519
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
519520
#[inline(always)]
521+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
520522
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
521523
// SAFETY: the caller must uphold the safety contract for
522524
// `unchecked_sub`.
@@ -585,6 +587,7 @@ macro_rules! int_impl {
585587
without modifying the original"]
586588
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
587589
#[inline(always)]
590+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
588591
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
589592
// SAFETY: the caller must uphold the safety contract for
590593
// `unchecked_mul`.
@@ -757,6 +760,7 @@ macro_rules! int_impl {
757760
without modifying the original"]
758761
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
759762
#[inline(always)]
763+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
760764
pub const unsafe fn unchecked_shl(self, rhs: Self) -> Self {
761765
// SAFETY: the caller must uphold the safety contract for
762766
// `unchecked_shl`.
@@ -803,6 +807,7 @@ macro_rules! int_impl {
803807
without modifying the original"]
804808
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
805809
#[inline(always)]
810+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
806811
pub const unsafe fn unchecked_shr(self, rhs: Self) -> Self {
807812
// SAFETY: the caller must uphold the safety contract for
808813
// `unchecked_shr`.

‎library/core/src/num/uint_macros.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ macro_rules! uint_impl {
459459
without modifying the original"]
460460
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
461461
#[inline(always)]
462+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
462463
pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
463464
// SAFETY: the caller must uphold the safety contract for
464465
// `unchecked_add`.
@@ -528,6 +529,7 @@ macro_rules! uint_impl {
528529
without modifying the original"]
529530
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
530531
#[inline(always)]
532+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
531533
pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
532534
// SAFETY: the caller must uphold the safety contract for
533535
// `unchecked_sub`.
@@ -574,6 +576,7 @@ macro_rules! uint_impl {
574576
without modifying the original"]
575577
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
576578
#[inline(always)]
579+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
577580
pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
578581
// SAFETY: the caller must uphold the safety contract for
579582
// `unchecked_mul`.
@@ -933,6 +936,7 @@ macro_rules! uint_impl {
933936
without modifying the original"]
934937
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
935938
#[inline(always)]
939+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
936940
pub const unsafe fn unchecked_shl(self, rhs: Self) -> Self {
937941
// SAFETY: the caller must uphold the safety contract for
938942
// `unchecked_shl`.
@@ -979,6 +983,7 @@ macro_rules! uint_impl {
979983
without modifying the original"]
980984
#[rustc_const_unstable(feature = "const_inherent_unchecked_arith", issue = "85122")]
981985
#[inline(always)]
986+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
982987
pub const unsafe fn unchecked_shr(self, rhs: Self) -> Self {
983988
// SAFETY: the caller must uphold the safety contract for
984989
// `unchecked_shr`.

‎library/core/src/ptr/const_ptr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ impl<T: ?Sized> *const T {
449449
#[must_use = "returns a new pointer rather than modifying its argument"]
450450
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
451451
#[inline(always)]
452+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
452453
pub const unsafe fn offset(self, count: isize) -> *const T
453454
where
454455
T: Sized,
@@ -471,6 +472,7 @@ impl<T: ?Sized> *const T {
471472
#[inline(always)]
472473
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
473474
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
475+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
474476
pub const unsafe fn byte_offset(self, count: isize) -> Self {
475477
// SAFETY: the caller must uphold the safety contract for `offset`.
476478
let this = unsafe { self.cast::<u8>().offset(count).cast::<()>() };
@@ -641,6 +643,7 @@ impl<T: ?Sized> *const T {
641643
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
642644
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
643645
#[inline]
646+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
644647
pub const unsafe fn offset_from(self, origin: *const T) -> isize
645648
where
646649
T: Sized,
@@ -663,6 +666,7 @@ impl<T: ?Sized> *const T {
663666
#[inline(always)]
664667
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
665668
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
669+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
666670
pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize {
667671
// SAFETY: the caller must uphold the safety contract for `offset_from`.
668672
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
@@ -731,6 +735,7 @@ impl<T: ?Sized> *const T {
731735
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
732736
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
733737
#[inline]
738+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
734739
pub const unsafe fn sub_ptr(self, origin: *const T) -> usize
735740
where
736741
T: Sized,
@@ -862,6 +867,7 @@ impl<T: ?Sized> *const T {
862867
#[must_use = "returns a new pointer rather than modifying its argument"]
863868
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
864869
#[inline(always)]
870+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
865871
pub const unsafe fn add(self, count: usize) -> Self
866872
where
867873
T: Sized,
@@ -884,6 +890,7 @@ impl<T: ?Sized> *const T {
884890
#[inline(always)]
885891
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
886892
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
893+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
887894
pub const unsafe fn byte_add(self, count: usize) -> Self {
888895
// SAFETY: the caller must uphold the safety contract for `add`.
889896
let this = unsafe { self.cast::<u8>().add(count).cast::<()>() };
@@ -946,6 +953,7 @@ impl<T: ?Sized> *const T {
946953
#[must_use = "returns a new pointer rather than modifying its argument"]
947954
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
948955
#[inline]
956+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
949957
pub const unsafe fn sub(self, count: usize) -> Self
950958
where
951959
T: Sized,
@@ -969,6 +977,7 @@ impl<T: ?Sized> *const T {
969977
#[inline(always)]
970978
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
971979
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
980+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
972981
pub const unsafe fn byte_sub(self, count: usize) -> Self {
973982
// SAFETY: the caller must uphold the safety contract for `sub`.
974983
let this = unsafe { self.cast::<u8>().sub(count).cast::<()>() };
@@ -1205,6 +1214,7 @@ impl<T: ?Sized> *const T {
12051214
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
12061215
#[stable(feature = "pointer_methods", since = "1.26.0")]
12071216
#[inline]
1217+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12081218
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
12091219
where
12101220
T: Sized,
@@ -1224,6 +1234,7 @@ impl<T: ?Sized> *const T {
12241234
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
12251235
#[stable(feature = "pointer_methods", since = "1.26.0")]
12261236
#[inline]
1237+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12271238
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
12281239
where
12291240
T: Sized,

‎library/core/src/ptr/mut_ptr.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ impl<T: ?Sized> *mut T {
461461
#[must_use = "returns a new pointer rather than modifying its argument"]
462462
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
463463
#[inline(always)]
464+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
464465
pub const unsafe fn offset(self, count: isize) -> *mut T
465466
where
466467
T: Sized,
@@ -485,6 +486,7 @@ impl<T: ?Sized> *mut T {
485486
#[inline(always)]
486487
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
487488
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
489+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
488490
pub const unsafe fn byte_offset(self, count: isize) -> Self {
489491
// SAFETY: the caller must uphold the safety contract for `offset`.
490492
let this = unsafe { self.cast::<u8>().offset(count).cast::<()>() };
@@ -824,6 +826,7 @@ impl<T: ?Sized> *mut T {
824826
#[stable(feature = "ptr_offset_from", since = "1.47.0")]
825827
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "92980")]
826828
#[inline(always)]
829+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
827830
pub const unsafe fn offset_from(self, origin: *const T) -> isize
828831
where
829832
T: Sized,
@@ -844,6 +847,7 @@ impl<T: ?Sized> *mut T {
844847
#[inline(always)]
845848
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
846849
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
850+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
847851
pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize {
848852
// SAFETY: the caller must uphold the safety contract for `offset_from`.
849853
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
@@ -913,6 +917,7 @@ impl<T: ?Sized> *mut T {
913917
#[unstable(feature = "ptr_sub_ptr", issue = "95892")]
914918
#[rustc_const_unstable(feature = "const_ptr_sub_ptr", issue = "95892")]
915919
#[inline]
920+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
916921
pub const unsafe fn sub_ptr(self, origin: *const T) -> usize
917922
where
918923
T: Sized,
@@ -976,6 +981,7 @@ impl<T: ?Sized> *mut T {
976981
#[must_use = "returns a new pointer rather than modifying its argument"]
977982
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
978983
#[inline(always)]
984+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
979985
pub const unsafe fn add(self, count: usize) -> Self
980986
where
981987
T: Sized,
@@ -998,6 +1004,7 @@ impl<T: ?Sized> *mut T {
9981004
#[inline(always)]
9991005
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
10001006
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1007+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10011008
pub const unsafe fn byte_add(self, count: usize) -> Self {
10021009
// SAFETY: the caller must uphold the safety contract for `add`.
10031010
let this = unsafe { self.cast::<u8>().add(count).cast::<()>() };
@@ -1060,6 +1067,7 @@ impl<T: ?Sized> *mut T {
10601067
#[must_use = "returns a new pointer rather than modifying its argument"]
10611068
#[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")]
10621069
#[inline]
1070+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10631071
pub const unsafe fn sub(self, count: usize) -> Self
10641072
where
10651073
T: Sized,
@@ -1083,6 +1091,7 @@ impl<T: ?Sized> *mut T {
10831091
#[inline(always)]
10841092
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
10851093
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
1094+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
10861095
pub const unsafe fn byte_sub(self, count: usize) -> Self {
10871096
// SAFETY: the caller must uphold the safety contract for `sub`.
10881097
let this = unsafe { self.cast::<u8>().sub(count).cast::<()>() };
@@ -1319,6 +1328,7 @@ impl<T: ?Sized> *mut T {
13191328
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13201329
#[stable(feature = "pointer_methods", since = "1.26.0")]
13211330
#[inline(always)]
1331+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13221332
pub const unsafe fn copy_to(self, dest: *mut T, count: usize)
13231333
where
13241334
T: Sized,
@@ -1338,6 +1348,7 @@ impl<T: ?Sized> *mut T {
13381348
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13391349
#[stable(feature = "pointer_methods", since = "1.26.0")]
13401350
#[inline(always)]
1351+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13411352
pub const unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize)
13421353
where
13431354
T: Sized,
@@ -1357,6 +1368,7 @@ impl<T: ?Sized> *mut T {
13571368
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13581369
#[stable(feature = "pointer_methods", since = "1.26.0")]
13591370
#[inline(always)]
1371+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13601372
pub const unsafe fn copy_from(self, src: *const T, count: usize)
13611373
where
13621374
T: Sized,
@@ -1376,6 +1388,7 @@ impl<T: ?Sized> *mut T {
13761388
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
13771389
#[stable(feature = "pointer_methods", since = "1.26.0")]
13781390
#[inline(always)]
1391+
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13791392
pub const unsafe fn copy_from_nonoverlapping(self, src: *const T, count: usize)
13801393
where
13811394
T: Sized,

‎library/panic_abort/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ pub unsafe fn __rust_start_panic(_payload: *mut &mut dyn BoxMeUp) -> u32 {
3737
abort();
3838

3939
cfg_if::cfg_if! {
40-
if #[cfg(unix)] {
40+
if #[cfg(any(unix, target_os = "solid_asp3"))] {
4141
unsafe fn abort() -> ! {
4242
libc::abort();
4343
}
4444
} else if #[cfg(any(target_os = "hermit",
45-
target_os = "solid_asp3",
4645
all(target_vendor = "fortanix", target_env = "sgx")
4746
))] {
4847
unsafe fn abort() -> ! {

‎library/std/src/io/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@ impl<T: Read> Read for Take<T> {
25772577

25782578
let max = cmp::min(buf.len() as u64, self.limit) as usize;
25792579
let n = self.inner.read(&mut buf[..max])?;
2580+
assert!(n as u64 <= self.limit, "number of read bytes exceeds limit");
25802581
self.limit -= n as u64;
25812582
Ok(n)
25822583
}

‎library/std/src/io/tests.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,25 @@ fn test_write_all_vectored() {
583583
}
584584
}
585585

586+
// Issue 94981
587+
#[test]
588+
#[should_panic = "number of read bytes exceeds limit"]
589+
fn test_take_wrong_length() {
590+
struct LieAboutSize(bool);
591+
592+
impl Read for LieAboutSize {
593+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
594+
// Lie about the read size at first time of read.
595+
if core::mem::take(&mut self.0) { Ok(buf.len() + 1) } else { Ok(buf.len()) }
596+
}
597+
}
598+
599+
let mut buffer = vec![0; 4];
600+
let mut reader = LieAboutSize(true).take(4);
601+
// Primed the `Limit` by lying about the read size.
602+
let _ = reader.read(&mut buffer[..]);
603+
}
604+
586605
#[bench]
587606
fn bench_take_read(b: &mut test::Bencher) {
588607
b.iter(|| {

‎library/std/src/sys/solid/abi/mod.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,6 @@ mod fs;
44
pub mod sockets;
55
pub use self::fs::*;
66

7-
#[inline(always)]
8-
pub fn breakpoint_program_exited(tid: usize) {
9-
unsafe {
10-
match () {
11-
// SOLID_BP_PROGRAM_EXITED = 15
12-
#[cfg(target_arch = "arm")]
13-
() => core::arch::asm!("bkpt #15", in("r0") tid),
14-
#[cfg(target_arch = "aarch64")]
15-
() => core::arch::asm!("hlt #15", in("x0") tid),
16-
}
17-
}
18-
}
19-
20-
#[inline(always)]
21-
pub fn breakpoint_abort() {
22-
unsafe {
23-
match () {
24-
// SOLID_BP_CSABORT = 16
25-
#[cfg(target_arch = "arm")]
26-
() => core::arch::asm!("bkpt #16"),
27-
#[cfg(target_arch = "aarch64")]
28-
() => core::arch::asm!("hlt #16"),
29-
}
30-
}
31-
}
32-
337
// `solid_types.h`
348
pub use super::itron::abi::{ER, ER_ID, E_TMOUT, ID};
359

‎library/std/src/sys/solid/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,9 @@ pub fn decode_error_kind(code: i32) -> crate::io::ErrorKind {
7676
error::decode_error_kind(code)
7777
}
7878

79-
#[inline(always)]
79+
#[inline]
8080
pub fn abort_internal() -> ! {
81-
loop {
82-
abi::breakpoint_abort();
83-
}
84-
}
85-
86-
// This function is needed by the panic runtime. The symbol is named in
87-
// pre-link args for the target specification, so keep that in sync.
88-
#[cfg(not(test))]
89-
#[no_mangle]
90-
// NB. used by both libunwind and libpanic_abort
91-
pub extern "C" fn __rust_abort() {
92-
abort_internal();
81+
unsafe { libc::abort() }
9382
}
9483

9584
pub fn hashmap_random_keys() -> (u64, u64) {

‎library/std/src/sys/solid/os.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::path::{self, PathBuf};
1111
use crate::sys_common::rwlock::StaticRwLock;
1212
use crate::vec;
1313

14-
use super::{abi, error, itron, memchr};
14+
use super::{error, itron, memchr};
1515

1616
// `solid` directly maps `errno`s to μITRON error codes.
1717
impl itron::error::ItronError {
@@ -184,11 +184,8 @@ pub fn home_dir() -> Option<PathBuf> {
184184
None
185185
}
186186

187-
pub fn exit(_code: i32) -> ! {
188-
let tid = itron::task::try_current_task_id().unwrap_or(0);
189-
loop {
190-
abi::breakpoint_program_exited(tid as usize);
191-
}
187+
pub fn exit(code: i32) -> ! {
188+
rtabort!("exit({}) called", code);
192189
}
193190

194191
pub fn getpid() -> u32 {

‎src/test/ui/derives/deriving-with-repr-packed.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
#![deny(unaligned_references)]
22

3-
// check that derive on a packed struct with non-Copy fields
4-
// correctly. This can't be made to work perfectly because
5-
// we can't just use the field from the struct as it might
6-
// not be aligned.
3+
// Check that deriving certain builtin traits on certain packed structs cause
4+
// errors. This happens when the derived trait would need to use a potentially
5+
// misaligned reference. But there are two cases that are allowed:
6+
// - If all the fields within the struct meet the required alignment: 1 for
7+
// `repr(packed)`, or `N` for `repr(packed(N))`.
8+
// - If `Default` is the only trait derived, because it doesn't involve any
9+
// references.
710

8-
#[derive(Copy, Clone, PartialEq, Eq)]
9-
//~^ ERROR `#[derive]` can't be used
11+
#[derive(Copy, Clone, Default, PartialEq, Eq)]
12+
//~^ ERROR `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters
1013
//~| hard error
11-
//~^^^ ERROR `#[derive]` can't be used
14+
//~^^^ ERROR `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
1215
//~| hard error
1316
#[repr(packed)]
1417
pub struct Foo<T>(T, T, T);
1518

16-
#[derive(PartialEq, Eq)]
17-
//~^ ERROR `#[derive]` can't be used
19+
#[derive(Default, Hash)]
20+
//~^ ERROR `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
1821
//~| hard error
1922
#[repr(packed)]
2023
pub struct Bar(u32, u32, u32);
2124

22-
#[derive(PartialEq)]
25+
// This one is fine because the field alignment is 1.
26+
#[derive(Default, Hash)]
27+
#[repr(packed)]
28+
pub struct Bar2(u8, i8, bool);
29+
30+
// This one is fine because the field alignment is 2, matching `packed(2)`.
31+
#[derive(Default, Hash)]
32+
#[repr(packed(2))]
33+
pub struct Bar3(u16, i16, bool);
34+
35+
// This one is fine because it's not packed.
36+
#[derive(Debug, Default)]
2337
struct Y(usize);
2438

25-
#[derive(PartialEq)]
26-
//~^ ERROR `#[derive]` can't be used
39+
#[derive(Debug, Default)]
40+
//~^ ERROR `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
2741
//~| hard error
2842
#[repr(packed)]
2943
struct X(Y);
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
2-
--> $DIR/deriving-with-repr-packed.rs:8:16
1+
error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133)
2+
--> $DIR/deriving-with-repr-packed.rs:11:16
33
|
4-
LL | #[derive(Copy, Clone, PartialEq, Eq)]
4+
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
55
| ^^^^^
66
|
77
note: the lint level is defined here
@@ -13,43 +13,43 @@ LL | #![deny(unaligned_references)]
1313
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
1414
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
1515

16-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
17-
--> $DIR/deriving-with-repr-packed.rs:8:23
16+
error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133)
17+
--> $DIR/deriving-with-repr-packed.rs:11:32
1818
|
19-
LL | #[derive(Copy, Clone, PartialEq, Eq)]
20-
| ^^^^^^^^^
19+
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
20+
| ^^^^^^^^^
2121
|
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
2424
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

26-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
27-
--> $DIR/deriving-with-repr-packed.rs:16:10
26+
error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133)
27+
--> $DIR/deriving-with-repr-packed.rs:19:19
2828
|
29-
LL | #[derive(PartialEq, Eq)]
30-
| ^^^^^^^^^
29+
LL | #[derive(Default, Hash)]
30+
| ^^^^
3131
|
3232
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3333
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
34-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
34+
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
3535

36-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
37-
--> $DIR/deriving-with-repr-packed.rs:25:10
36+
error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133)
37+
--> $DIR/deriving-with-repr-packed.rs:39:10
3838
|
39-
LL | #[derive(PartialEq)]
40-
| ^^^^^^^^^
39+
LL | #[derive(Debug, Default)]
40+
| ^^^^^
4141
|
4242
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4343
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
44-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
44+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
4545

4646
error: aborting due to 4 previous errors
4747

4848
Future incompatibility report: Future breakage diagnostic:
49-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
50-
--> $DIR/deriving-with-repr-packed.rs:8:16
49+
error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133)
50+
--> $DIR/deriving-with-repr-packed.rs:11:16
5151
|
52-
LL | #[derive(Copy, Clone, PartialEq, Eq)]
52+
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
5353
| ^^^^^
5454
|
5555
note: the lint level is defined here
@@ -62,11 +62,11 @@ LL | #![deny(unaligned_references)]
6262
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
6363

6464
Future breakage diagnostic:
65-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
66-
--> $DIR/deriving-with-repr-packed.rs:8:23
65+
error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133)
66+
--> $DIR/deriving-with-repr-packed.rs:11:32
6767
|
68-
LL | #[derive(Copy, Clone, PartialEq, Eq)]
69-
| ^^^^^^^^^
68+
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
69+
| ^^^^^^^^^
7070
|
7171
note: the lint level is defined here
7272
--> $DIR/deriving-with-repr-packed.rs:1:9
@@ -78,11 +78,11 @@ LL | #![deny(unaligned_references)]
7878
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
7979

8080
Future breakage diagnostic:
81-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
82-
--> $DIR/deriving-with-repr-packed.rs:16:10
81+
error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133)
82+
--> $DIR/deriving-with-repr-packed.rs:19:19
8383
|
84-
LL | #[derive(PartialEq, Eq)]
85-
| ^^^^^^^^^
84+
LL | #[derive(Default, Hash)]
85+
| ^^^^
8686
|
8787
note: the lint level is defined here
8888
--> $DIR/deriving-with-repr-packed.rs:1:9
@@ -91,14 +91,14 @@ LL | #![deny(unaligned_references)]
9191
| ^^^^^^^^^^^^^^^^^^^^
9292
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9393
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
94-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
94+
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
9595

9696
Future breakage diagnostic:
97-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
98-
--> $DIR/deriving-with-repr-packed.rs:25:10
97+
error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133)
98+
--> $DIR/deriving-with-repr-packed.rs:39:10
9999
|
100-
LL | #[derive(PartialEq)]
101-
| ^^^^^^^^^
100+
LL | #[derive(Debug, Default)]
101+
| ^^^^^
102102
|
103103
note: the lint level is defined here
104104
--> $DIR/deriving-with-repr-packed.rs:1:9
@@ -107,5 +107,5 @@ LL | #![deny(unaligned_references)]
107107
| ^^^^^^^^^^^^^^^^^^^^
108108
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
109109
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
110-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
110+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
111111

‎src/test/ui/process/nofile-limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// dont-check-compiler-stderr
77
// only-linux
88
// no-prefer-dynamic
9-
// compile-flags: -Ctarget-feature=+crt-static -Crpath=no
9+
// compile-flags: -Ctarget-feature=+crt-static -Crpath=no -Crelocation-model=static
1010
#![feature(exit_status_error)]
1111
#![feature(rustc_private)]
1212
extern crate libc;

0 commit comments

Comments
 (0)
Please sign in to comment.