Skip to content

Commit d4c940f

Browse files
committed
Auto merge of #75244 - Manishearth:rollup-dzfyjva, r=Manishearth
Rollup of 4 pull requests Successful merges: - #74774 (adds [*mut|*const] ptr::set_ptr_value) - #75079 (Disallow linking to items with a mismatched disambiguator) - #75203 (Make `IntoIterator` lifetime bounds of `&BTreeMap` match with `&HashMap` ) - #75227 (Fix ICE when using asm! on an unsupported architecture) Failed merges: r? @ghost
2 parents 9892279 + 9ab750d commit d4c940f

File tree

15 files changed

+447
-54
lines changed

15 files changed

+447
-54
lines changed

library/alloc/src/collections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
12941294
}
12951295

12961296
#[stable(feature = "rust1", since = "1.0.0")]
1297-
impl<'a, K: 'a, V: 'a> IntoIterator for &'a BTreeMap<K, V> {
1297+
impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
12981298
type Item = (&'a K, &'a V);
12991299
type IntoIter = Iter<'a, K, V>;
13001300

@@ -1363,7 +1363,7 @@ impl<K, V> Clone for Iter<'_, K, V> {
13631363
}
13641364

13651365
#[stable(feature = "rust1", since = "1.0.0")]
1366-
impl<'a, K: 'a, V: 'a> IntoIterator for &'a mut BTreeMap<K, V> {
1366+
impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> {
13671367
type Item = (&'a K, &'a mut V);
13681368
type IntoIter = IterMut<'a, K, V>;
13691369

library/core/src/ptr/const_ptr.rs

+32
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,38 @@ impl<T: ?Sized> *const T {
656656
self.wrapping_offset((count as isize).wrapping_neg())
657657
}
658658

659+
/// Sets the pointer value to `ptr`.
660+
///
661+
/// In case `self` is a (fat) pointer to an unsized type, this operation
662+
/// will only affect the pointer part, whereas for (thin) pointers to
663+
/// sized types, this has the same effect as a simple assignment.
664+
///
665+
/// # Examples
666+
///
667+
/// This function is primarily useful for allowing byte-wise pointer
668+
/// arithmetic on potentially fat pointers:
669+
///
670+
/// ```
671+
/// #![feature(set_ptr_value)]
672+
/// # use core::fmt::Debug;
673+
/// let arr: [i32; 3] = [1, 2, 3];
674+
/// let mut ptr = &arr[0] as *const dyn Debug;
675+
/// let thin = ptr as *const u8;
676+
/// ptr = ptr.set_ptr_value(unsafe { thin.add(8).cast() });
677+
/// assert_eq!(unsafe { *(ptr as *const i32) }, 3);
678+
/// ```
679+
#[unstable(feature = "set_ptr_value", issue = "75091")]
680+
#[inline]
681+
pub fn set_ptr_value(mut self, val: *const ()) -> Self {
682+
let thin = &mut self as *mut *const T as *mut *const ();
683+
// SAFETY: In case of a thin pointer, this operations is identical
684+
// to a simple assignment. In case of a fat pointer, with the current
685+
// fat pointer layout implementation, the first field of such a
686+
// pointer is always the data pointer, which is likewise assigned.
687+
unsafe { *thin = val };
688+
self
689+
}
690+
659691
/// Reads the value from `self` without moving it. This leaves the
660692
/// memory in `self` unchanged.
661693
///

library/core/src/ptr/mut_ptr.rs

+32
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,38 @@ impl<T: ?Sized> *mut T {
712712
self.wrapping_offset((count as isize).wrapping_neg())
713713
}
714714

715+
/// Sets the pointer value to `ptr`.
716+
///
717+
/// In case `self` is a (fat) pointer to an unsized type, this operation
718+
/// will only affect the pointer part, whereas for (thin) pointers to
719+
/// sized types, this has the same effect as a simple assignment.
720+
///
721+
/// # Examples
722+
///
723+
/// This function is primarily useful for allowing byte-wise pointer
724+
/// arithmetic on potentially fat pointers:
725+
///
726+
/// ```
727+
/// #![feature(set_ptr_value)]
728+
/// # use core::fmt::Debug;
729+
/// let mut arr: [i32; 3] = [1, 2, 3];
730+
/// let mut ptr = &mut arr[0] as *mut dyn Debug;
731+
/// let thin = ptr as *mut u8;
732+
/// ptr = ptr.set_ptr_value(unsafe { thin.add(8).cast() });
733+
/// assert_eq!(unsafe { *(ptr as *mut i32) }, 3);
734+
/// ```
735+
#[unstable(feature = "set_ptr_value", issue = "75091")]
736+
#[inline]
737+
pub fn set_ptr_value(mut self, val: *mut ()) -> Self {
738+
let thin = &mut self as *mut *mut T as *mut *mut ();
739+
// SAFETY: In case of a thin pointer, this operations is identical
740+
// to a simple assignment. In case of a fat pointer, with the current
741+
// fat pointer layout implementation, the first field of such a
742+
// pointer is always the data pointer, which is likewise assigned.
743+
unsafe { *thin = val };
744+
self
745+
}
746+
715747
/// Reads the value from `self` without moving it. This leaves the
716748
/// memory in `self` unchanged.
717749
///

src/librustc_ast_lowering/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10671067
.collect();
10681068

10691069
// Stop if there were any errors when lowering the register classes
1070-
if operands.len() != asm.operands.len() {
1070+
if operands.len() != asm.operands.len() || sess.asm_arch.is_none() {
10711071
return hir::ExprKind::Err;
10721072
}
10731073

src/librustc_hir/def.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl DefKind {
150150
}
151151
}
152152

153-
pub fn matches_ns(&self, ns: Namespace) -> bool {
153+
pub fn ns(&self) -> Option<Namespace> {
154154
match self {
155155
DefKind::Mod
156156
| DefKind::Struct
@@ -163,17 +163,17 @@ impl DefKind {
163163
| DefKind::ForeignTy
164164
| DefKind::TraitAlias
165165
| DefKind::AssocTy
166-
| DefKind::TyParam => ns == Namespace::TypeNS,
166+
| DefKind::TyParam => Some(Namespace::TypeNS),
167167

168168
DefKind::Fn
169169
| DefKind::Const
170170
| DefKind::ConstParam
171171
| DefKind::Static
172172
| DefKind::Ctor(..)
173173
| DefKind::AssocFn
174-
| DefKind::AssocConst => ns == Namespace::ValueNS,
174+
| DefKind::AssocConst => Some(Namespace::ValueNS),
175175

176-
DefKind::Macro(..) => ns == Namespace::MacroNS,
176+
DefKind::Macro(..) => Some(Namespace::MacroNS),
177177

178178
// Not namespaced.
179179
DefKind::AnonConst
@@ -185,7 +185,7 @@ impl DefKind {
185185
| DefKind::Use
186186
| DefKind::ForeignMod
187187
| DefKind::GlobalAsm
188-
| DefKind::Impl => false,
188+
| DefKind::Impl => None,
189189
}
190190
}
191191
}
@@ -453,7 +453,7 @@ impl<Id> Res<Id> {
453453

454454
pub fn matches_ns(&self, ns: Namespace) -> bool {
455455
match self {
456-
Res::Def(kind, ..) => kind.matches_ns(ns),
456+
Res::Def(kind, ..) => kind.ns() == Some(ns),
457457
Res::PrimTy(..) | Res::SelfTy(..) | Res::ToolMod => ns == Namespace::TypeNS,
458458
Res::SelfCtor(..) | Res::Local(..) => ns == Namespace::ValueNS,
459459
Res::NonMacroAttr(..) => ns == Namespace::MacroNS,

src/librustdoc/clean/utils.rs

+3
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ pub fn register_res(cx: &DocContext<'_>, res: Res) -> DefId {
607607
Res::Def(DefKind::TyAlias, i) => (i, TypeKind::Typedef),
608608
Res::Def(DefKind::Enum, i) => (i, TypeKind::Enum),
609609
Res::Def(DefKind::Trait, i) => (i, TypeKind::Trait),
610+
Res::Def(DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst, i) => {
611+
(cx.tcx.parent(i).unwrap(), TypeKind::Trait)
612+
}
610613
Res::Def(DefKind::Struct, i) => (i, TypeKind::Struct),
611614
Res::Def(DefKind::Union, i) => (i, TypeKind::Union),
612615
Res::Def(DefKind::Mod, i) => (i, TypeKind::Module),

0 commit comments

Comments
 (0)