Skip to content

Commit 8a1f803

Browse files
committed
Auto merge of #134550 - jhpratt:rollup-wsfmo59, r=jhpratt
Rollup of 6 pull requests Successful merges: - #126118 (docs: Mention `spare_capacity_mut()` in `Vec::set_len`) - #132830 (Rename `elem_offset` to `element_offset`) - #133103 (Pass FnAbi to find_mir_or_eval_fn) - #134321 (Hide `= _` as associated constant value inside impl blocks) - #134518 (fix typos in the example code in the doc comments of `Ipv4Addr::from_bits()`, `Ipv6Addr::from_bits()` & `Ipv6Addr::to_bits()`) - #134521 (Arbitrary self types v2: roll loop.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5dfe648 + e6aea1a commit 8a1f803

Some content is hidden

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

51 files changed

+712
-583
lines changed

compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use rustc_middle::mir::interpret::{AllocId, ConstAllocation, InterpResult};
22
use rustc_middle::mir::*;
33
use rustc_middle::query::TyCtxtAt;
4+
use rustc_middle::ty::Ty;
45
use rustc_middle::ty::layout::TyAndLayout;
56
use rustc_middle::{bug, span_bug, ty};
67
use rustc_span::def_id::DefId;
8+
use rustc_target::callconv::FnAbi;
79

810
use crate::interpret::{
911
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, interp_ok,
@@ -86,7 +88,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
8688
fn find_mir_or_eval_fn(
8789
_ecx: &mut InterpCx<'tcx, Self>,
8890
_instance: ty::Instance<'tcx>,
89-
_abi: rustc_abi::ExternAbi,
91+
_abi: &FnAbi<'tcx, Ty<'tcx>>,
9092
_args: &[interpret::FnArg<'tcx, Self::Provenance>],
9193
_destination: &interpret::MPlaceTy<'tcx, Self::Provenance>,
9294
_target: Option<BasicBlock>,

compiler/rustc_const_eval/src/const_eval/machine.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::{Borrow, Cow};
22
use std::fmt;
33
use std::hash::Hash;
44

5-
use rustc_abi::{Align, ExternAbi, Size};
5+
use rustc_abi::{Align, Size};
66
use rustc_ast::Mutability;
77
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
88
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -14,6 +14,7 @@ use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout};
1414
use rustc_middle::ty::{self, Ty, TyCtxt};
1515
use rustc_middle::{bug, mir};
1616
use rustc_span::{Span, Symbol, sym};
17+
use rustc_target::callconv::FnAbi;
1718
use tracing::debug;
1819

1920
use super::error::*;
@@ -339,7 +340,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
339340
fn find_mir_or_eval_fn(
340341
ecx: &mut InterpCx<'tcx, Self>,
341342
orig_instance: ty::Instance<'tcx>,
342-
_abi: ExternAbi,
343+
_abi: &FnAbi<'tcx, Ty<'tcx>>,
343344
args: &[FnArg<'tcx>],
344345
dest: &MPlaceTy<'tcx>,
345346
ret: Option<mir::BasicBlock>,

compiler/rustc_const_eval/src/interpret/call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
519519
return M::call_extra_fn(
520520
self,
521521
extra,
522-
caller_abi,
522+
caller_fn_abi,
523523
args,
524524
destination,
525525
target,
@@ -570,7 +570,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
570570
let Some((body, instance)) = M::find_mir_or_eval_fn(
571571
self,
572572
instance,
573-
caller_abi,
573+
caller_fn_abi,
574574
args,
575575
destination,
576576
target,

compiler/rustc_const_eval/src/interpret/machine.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::borrow::{Borrow, Cow};
66
use std::fmt::Debug;
77
use std::hash::Hash;
88

9-
use rustc_abi::{Align, ExternAbi, Size};
9+
use rustc_abi::{Align, Size};
1010
use rustc_apfloat::{Float, FloatConvert};
1111
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1212
use rustc_middle::query::TyCtxtAt;
@@ -15,6 +15,7 @@ use rustc_middle::ty::layout::TyAndLayout;
1515
use rustc_middle::{mir, ty};
1616
use rustc_span::Span;
1717
use rustc_span::def_id::DefId;
18+
use rustc_target::callconv::FnAbi;
1819

1920
use super::{
2021
AllocBytes, AllocId, AllocKind, AllocRange, Allocation, CTFE_ALLOC_SALT, ConstAllocation,
@@ -201,7 +202,7 @@ pub trait Machine<'tcx>: Sized {
201202
fn find_mir_or_eval_fn(
202203
ecx: &mut InterpCx<'tcx, Self>,
203204
instance: ty::Instance<'tcx>,
204-
abi: ExternAbi,
205+
abi: &FnAbi<'tcx, Ty<'tcx>>,
205206
args: &[FnArg<'tcx, Self::Provenance>],
206207
destination: &MPlaceTy<'tcx, Self::Provenance>,
207208
target: Option<mir::BasicBlock>,
@@ -213,7 +214,7 @@ pub trait Machine<'tcx>: Sized {
213214
fn call_extra_fn(
214215
ecx: &mut InterpCx<'tcx, Self>,
215216
fn_val: Self::ExtraFnVal,
216-
abi: ExternAbi,
217+
abi: &FnAbi<'tcx, Ty<'tcx>>,
217218
args: &[FnArg<'tcx, Self::Provenance>],
218219
destination: &MPlaceTy<'tcx, Self::Provenance>,
219220
target: Option<mir::BasicBlock>,
@@ -656,7 +657,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
656657
fn call_extra_fn(
657658
_ecx: &mut InterpCx<$tcx, Self>,
658659
fn_val: !,
659-
_abi: ExternAbi,
660+
_abi: &FnAbi<$tcx, Ty<$tcx>>,
660661
_args: &[FnArg<$tcx>],
661662
_destination: &MPlaceTy<$tcx, Self::Provenance>,
662663
_target: Option<mir::BasicBlock>,

compiler/rustc_hir_typeck/src/method/probe.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -1229,23 +1229,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12291229
if let Some(by_value_pick) = by_value_pick {
12301230
if let Ok(by_value_pick) = by_value_pick.as_ref() {
12311231
if by_value_pick.kind == PickKind::InherentImplPick {
1232-
if let Err(e) = self.check_for_shadowed_autorefd_method(
1233-
by_value_pick,
1234-
step,
1235-
self_ty,
1236-
hir::Mutability::Not,
1237-
track_unstable_candidates,
1238-
) {
1239-
return Some(Err(e));
1240-
}
1241-
if let Err(e) = self.check_for_shadowed_autorefd_method(
1242-
by_value_pick,
1243-
step,
1244-
self_ty,
1245-
hir::Mutability::Mut,
1246-
track_unstable_candidates,
1247-
) {
1248-
return Some(Err(e));
1232+
for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1233+
if let Err(e) = self.check_for_shadowed_autorefd_method(
1234+
by_value_pick,
1235+
step,
1236+
self_ty,
1237+
mutbl,
1238+
track_unstable_candidates,
1239+
) {
1240+
return Some(Err(e));
1241+
}
12491242
}
12501243
}
12511244
}

library/alloc/src/vec/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,10 @@ impl<T, A: Allocator> Vec<T, A> {
18241824
///
18251825
/// # Examples
18261826
///
1827-
/// This method can be useful for situations in which the vector
1827+
/// See [`spare_capacity_mut()`] for an example with safe
1828+
/// initialization of capacity elements and use of this method.
1829+
///
1830+
/// `set_len()` can be useful for situations in which the vector
18281831
/// is serving as a buffer for other code, particularly over FFI:
18291832
///
18301833
/// ```no_run
@@ -1884,6 +1887,8 @@ impl<T, A: Allocator> Vec<T, A> {
18841887
///
18851888
/// Normally, here, one would use [`clear`] instead to correctly drop
18861889
/// the contents and thus not leak memory.
1890+
///
1891+
/// [`spare_capacity_mut()`]: Vec::spare_capacity_mut
18871892
#[inline]
18881893
#[stable(feature = "rust1", since = "1.0.0")]
18891894
pub unsafe fn set_len(&mut self, new_len: usize) {

library/core/src/net/ip_addr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl Ipv4Addr {
527527
/// ```
528528
/// use std::net::Ipv4Addr;
529529
///
530-
/// let addr = Ipv4Addr::from(0x12345678);
530+
/// let addr = Ipv4Addr::from_bits(0x12345678);
531531
/// assert_eq!(Ipv4Addr::new(0x12, 0x34, 0x56, 0x78), addr);
532532
/// ```
533533
#[rustc_const_stable(feature = "ip_bits", since = "1.80.0")]
@@ -1294,7 +1294,7 @@ impl Ipv6Addr {
12941294
/// 0x1020, 0x3040, 0x5060, 0x7080,
12951295
/// 0x90A0, 0xB0C0, 0xD0E0, 0xF00D,
12961296
/// );
1297-
/// assert_eq!(0x102030405060708090A0B0C0D0E0F00D_u128, u128::from(addr));
1297+
/// assert_eq!(0x102030405060708090A0B0C0D0E0F00D_u128, addr.to_bits());
12981298
/// ```
12991299
///
13001300
/// ```
@@ -1330,7 +1330,7 @@ impl Ipv6Addr {
13301330
/// ```
13311331
/// use std::net::Ipv6Addr;
13321332
///
1333-
/// let addr = Ipv6Addr::from(0x102030405060708090A0B0C0D0E0F00D_u128);
1333+
/// let addr = Ipv6Addr::from_bits(0x102030405060708090A0B0C0D0E0F00D_u128);
13341334
/// assert_eq!(
13351335
/// Ipv6Addr::new(
13361336
/// 0x1020, 0x3040, 0x5060, 0x7080,

library/core/src/slice/mod.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -4641,7 +4641,7 @@ impl<T> [T] {
46414641

46424642
/// Returns the index that an element reference points to.
46434643
///
4644-
/// Returns `None` if `element` does not point within the slice or if it points between elements.
4644+
/// Returns `None` if `element` does not point to the start of an element within the slice.
46454645
///
46464646
/// This method is useful for extending slice iterators like [`slice::split`].
46474647
///
@@ -4661,9 +4661,9 @@ impl<T> [T] {
46614661
/// let num = &nums[2];
46624662
///
46634663
/// assert_eq!(num, &1);
4664-
/// assert_eq!(nums.elem_offset(num), Some(2));
4664+
/// assert_eq!(nums.element_offset(num), Some(2));
46654665
/// ```
4666-
/// Returning `None` with an in-between element:
4666+
/// Returning `None` with an unaligned element:
46674667
/// ```
46684668
/// #![feature(substr_range)]
46694669
///
@@ -4676,12 +4676,12 @@ impl<T> [T] {
46764676
/// assert_eq!(ok_elm, &[0, 1]);
46774677
/// assert_eq!(weird_elm, &[1, 2]);
46784678
///
4679-
/// assert_eq!(arr.elem_offset(ok_elm), Some(0)); // Points to element 0
4680-
/// assert_eq!(arr.elem_offset(weird_elm), None); // Points between element 0 and 1
4679+
/// assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0
4680+
/// assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1
46814681
/// ```
46824682
#[must_use]
46834683
#[unstable(feature = "substr_range", issue = "126769")]
4684-
pub fn elem_offset(&self, element: &T) -> Option<usize> {
4684+
pub fn element_offset(&self, element: &T) -> Option<usize> {
46854685
if T::IS_ZST {
46864686
panic!("elements are zero-sized");
46874687
}
@@ -4702,7 +4702,8 @@ impl<T> [T] {
47024702

47034703
/// Returns the range of indices that a subslice points to.
47044704
///
4705-
/// Returns `None` if `subslice` does not point within the slice or if it points between elements.
4705+
/// Returns `None` if `subslice` does not point within the slice or if it is not aligned with the
4706+
/// elements in the slice.
47064707
///
47074708
/// This method **does not compare elements**. Instead, this method finds the location in the slice that
47084709
/// `subslice` was obtained from. To find the index of a subslice via comparison, instead use

src/librustdoc/clean/mod.rs

+27-20
Original file line numberDiff line numberDiff line change
@@ -1222,22 +1222,24 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12221222
let local_did = trait_item.owner_id.to_def_id();
12231223
cx.with_param_env(local_did, |cx| {
12241224
let inner = match trait_item.kind {
1225-
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(Box::new(Constant {
1226-
generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)),
1227-
kind: ConstantKind::Local { def_id: local_did, body: default },
1228-
type_: clean_ty(ty, cx),
1229-
})),
1225+
hir::TraitItemKind::Const(ty, Some(default)) => {
1226+
ProvidedAssocConstItem(Box::new(Constant {
1227+
generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)),
1228+
kind: ConstantKind::Local { def_id: local_did, body: default },
1229+
type_: clean_ty(ty, cx),
1230+
}))
1231+
}
12301232
hir::TraitItemKind::Const(ty, None) => {
12311233
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
1232-
TyAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
1234+
RequiredAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
12331235
}
12341236
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
12351237
let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Body(body));
12361238
MethodItem(m, None)
12371239
}
12381240
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
12391241
let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Names(names));
1240-
TyMethodItem(m)
1242+
RequiredMethodItem(m)
12411243
}
12421244
hir::TraitItemKind::Type(bounds, Some(default)) => {
12431245
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
@@ -1257,7 +1259,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12571259
hir::TraitItemKind::Type(bounds, None) => {
12581260
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
12591261
let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
1260-
TyAssocTypeItem(generics, bounds)
1262+
RequiredAssocTypeItem(generics, bounds)
12611263
}
12621264
};
12631265
Item::from_def_id_and_parts(local_did, Some(trait_item.ident.name), inner, cx)
@@ -1271,7 +1273,7 @@ pub(crate) fn clean_impl_item<'tcx>(
12711273
let local_did = impl_.owner_id.to_def_id();
12721274
cx.with_param_env(local_did, |cx| {
12731275
let inner = match impl_.kind {
1274-
hir::ImplItemKind::Const(ty, expr) => AssocConstItem(Box::new(Constant {
1276+
hir::ImplItemKind::Const(ty, expr) => ImplAssocConstItem(Box::new(Constant {
12751277
generics: clean_generics(impl_.generics, cx),
12761278
kind: ConstantKind::Local { def_id: local_did, body: expr },
12771279
type_: clean_ty(ty, cx),
@@ -1320,18 +1322,23 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
13201322
);
13211323
simplify::move_bounds_to_generic_parameters(&mut generics);
13221324

1323-
let provided = match assoc_item.container {
1324-
ty::AssocItemContainer::Impl => true,
1325-
ty::AssocItemContainer::Trait => tcx.defaultness(assoc_item.def_id).has_value(),
1326-
};
1327-
if provided {
1328-
AssocConstItem(Box::new(Constant {
1325+
match assoc_item.container {
1326+
ty::AssocItemContainer::Impl => ImplAssocConstItem(Box::new(Constant {
13291327
generics,
13301328
kind: ConstantKind::Extern { def_id: assoc_item.def_id },
13311329
type_: ty,
1332-
}))
1333-
} else {
1334-
TyAssocConstItem(generics, Box::new(ty))
1330+
})),
1331+
ty::AssocItemContainer::Trait => {
1332+
if tcx.defaultness(assoc_item.def_id).has_value() {
1333+
ProvidedAssocConstItem(Box::new(Constant {
1334+
generics,
1335+
kind: ConstantKind::Extern { def_id: assoc_item.def_id },
1336+
type_: ty,
1337+
}))
1338+
} else {
1339+
RequiredAssocConstItem(generics, Box::new(ty))
1340+
}
1341+
}
13351342
}
13361343
}
13371344
ty::AssocKind::Fn => {
@@ -1369,7 +1376,7 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
13691376
};
13701377
MethodItem(item, defaultness)
13711378
} else {
1372-
TyMethodItem(item)
1379+
RequiredMethodItem(item)
13731380
}
13741381
}
13751382
ty::AssocKind::Type => {
@@ -1486,7 +1493,7 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14861493
bounds,
14871494
)
14881495
} else {
1489-
TyAssocTypeItem(generics, bounds)
1496+
RequiredAssocTypeItem(generics, bounds)
14901497
}
14911498
} else {
14921499
AssocTypeItem(

0 commit comments

Comments
 (0)