Skip to content

Commit 506d628

Browse files
committed
Auto merge of rust-lang#123143 - matthiaskrgr:rollup-w6e5gnl, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#121943 (Clarify atomic bit validity) - rust-lang#123089 (Add invariant to VecDeque::pop_* that len < cap if pop successful) - rust-lang#123101 (Delegation: fix ICE on wrong `Self` instantiation) - rust-lang#123130 (Load missing type of impl associated constant from trait definition) - rust-lang#123133 (chore: fix some comments) - rust-lang#123136 (Some wording improvement) - rust-lang#123139 (`num::NonZero::get` can be 1 transmute instead of 2) - rust-lang#123142 (Let nils know about changes to target docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c9f8f34 + 98fa10e commit 506d628

Some content is hidden

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

41 files changed

+482
-271
lines changed

INSTALL.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ toolchain.
151151
directory and uncomment the line `MSYS2_PATH_TYPE=inherit`.
152152

153153
You could install and use MSYS2's version of git instead with `pacman`,
154-
however this is not recommended as it's excrutiatingly slow, and not frequently
155-
tested for compatability.
154+
however this is not recommended as it's excruciatingly slow, and not frequently
155+
tested for compatibility.
156156

157157
3. Start a MINGW64 or MINGW32 shell (depending on whether you want 32-bit
158158
or 64-bit Rust) either from your start menu, or by running `mingw64.exe`

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub(crate) struct FixupContext {
7575
}
7676

7777
/// The default amount of fixing is minimal fixing. Fixups should be turned on
78-
/// in a targetted fashion where needed.
78+
/// in a targeted fashion where needed.
7979
impl Default for FixupContext {
8080
fn default() -> Self {
8181
FixupContext {

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
592592
}
593593
self.cx.borrowck_context.constraints.outlives_constraints.push(constraint)
594594
}
595-
// If the region is live at at least one location in the promoted MIR,
595+
// If the region is live at least one location in the promoted MIR,
596596
// then add a liveness constraint to the main MIR for this region
597597
// at the location provided as an argument to this method
598598
//

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn const_validate_mplace<'mir, 'tcx>(
409409
}
410410
};
411411
ecx.const_validate_operand(&mplace.into(), path, &mut ref_tracking, mode)
412-
// Instead of just reporting the `InterpError` via the usual machinery, we give a more targetted
412+
// Instead of just reporting the `InterpError` via the usual machinery, we give a more targeted
413413
// error about the validation failure.
414414
.map_err(|error| report_validation_error(&ecx, error, alloc_id))?;
415415
inner = true;

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::HirTyLowerer;
1111
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
1212
/// Prohibit or lint against *bare* trait object types depending on the edition.
1313
///
14-
/// *Bare* trait object types are ones that aren't preceeded by the keyword `dyn`.
14+
/// *Bare* trait object types are ones that aren't preceded by the keyword `dyn`.
1515
/// In edition 2021 and onward we emit a hard error for them.
1616
pub(super) fn prohibit_or_lint_bare_trait_object_ty(
1717
&self,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2212,6 +2212,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22122212
try_emit("delegation with early bound generics");
22132213
}
22142214

2215+
// There is no way to instantiate `Self` param for caller if
2216+
// 1. callee is a trait method
2217+
// 2. delegation item isn't an associative item
2218+
if let DefKind::AssocFn = self.tcx().def_kind(sig_id)
2219+
&& let DefKind::Fn = self.tcx().def_kind(self.item_def_id())
2220+
&& self.tcx().associated_item(sig_id).container
2221+
== ty::AssocItemContainer::TraitContainer
2222+
{
2223+
try_emit("delegation to a trait method from a free function");
2224+
}
2225+
22152226
if self.tcx().asyncness(sig_id) == ty::Asyncness::Yes {
22162227
try_emit("delegation to async functions");
22172228
}

compiler/rustc_hir_typeck/src/lib.rs

+57-53
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,6 @@ macro_rules! type_error_struct {
8383
})
8484
}
8585

86-
/// If this `DefId` is a "primary tables entry", returns
87-
/// `Some((body_id, body_ty, fn_sig))`. Otherwise, returns `None`.
88-
///
89-
/// If this function returns `Some`, then `typeck_results(def_id)` will
90-
/// succeed; if it returns `None`, then `typeck_results(def_id)` may or
91-
/// may not succeed. In some cases where this function returns `None`
92-
/// (notably closures), `typeck_results(def_id)` would wind up
93-
/// redirecting to the owning function.
94-
fn primary_body_of(
95-
node: Node<'_>,
96-
) -> Option<(hir::BodyId, Option<&hir::Ty<'_>>, Option<&hir::FnSig<'_>>)> {
97-
Some((node.body_id()?, node.ty(), node.fn_sig()))
98-
}
99-
10086
fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
10187
// Closures' typeck results come from their outermost function,
10288
// as they are part of the same "inference environment".
@@ -106,7 +92,7 @@ fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
10692
}
10793

10894
if let Some(def_id) = def_id.as_local() {
109-
primary_body_of(tcx.hir_node_by_def_id(def_id)).is_some()
95+
tcx.hir_node_by_def_id(def_id).body_id().is_some()
11096
} else {
11197
false
11298
}
@@ -163,7 +149,7 @@ fn typeck_with_fallback<'tcx>(
163149
let span = tcx.hir().span(id);
164150

165151
// Figure out what primary body this item has.
166-
let (body_id, body_ty, fn_sig) = primary_body_of(node).unwrap_or_else(|| {
152+
let body_id = node.body_id().unwrap_or_else(|| {
167153
span_bug!(span, "can't type-check body of {:?}", def_id);
168154
});
169155
let body = tcx.hir().body(body_id);
@@ -176,7 +162,7 @@ fn typeck_with_fallback<'tcx>(
176162
}
177163
let mut fcx = FnCtxt::new(&root_ctxt, param_env, def_id);
178164

179-
if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
165+
if let Some(hir::FnSig { header, decl, .. }) = node.fn_sig() {
180166
let fn_sig = if decl.output.get_infer_ret_ty().is_some() {
181167
fcx.lowerer().lower_fn_ty(id, header.unsafety, header.abi, decl, None, None)
182168
} else {
@@ -191,42 +177,7 @@ fn typeck_with_fallback<'tcx>(
191177

192178
check_fn(&mut fcx, fn_sig, None, decl, def_id, body, tcx.features().unsized_fn_params);
193179
} else {
194-
let expected_type = if let Some(&hir::Ty { kind: hir::TyKind::Infer, span, .. }) = body_ty {
195-
Some(fcx.next_ty_var(TypeVariableOrigin {
196-
kind: TypeVariableOriginKind::TypeInference,
197-
span,
198-
}))
199-
} else if let Node::AnonConst(_) = node {
200-
match tcx.parent_hir_node(id) {
201-
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), .. })
202-
if anon_const.hir_id == id =>
203-
{
204-
Some(fcx.next_ty_var(TypeVariableOrigin {
205-
kind: TypeVariableOriginKind::TypeInference,
206-
span,
207-
}))
208-
}
209-
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), .. })
210-
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), .. }) => {
211-
asm.operands.iter().find_map(|(op, _op_sp)| match op {
212-
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == id => {
213-
// Inline assembly constants must be integers.
214-
Some(fcx.next_int_var())
215-
}
216-
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == id => {
217-
Some(fcx.next_ty_var(TypeVariableOrigin {
218-
kind: TypeVariableOriginKind::MiscVariable,
219-
span,
220-
}))
221-
}
222-
_ => None,
223-
})
224-
}
225-
_ => None,
226-
}
227-
} else {
228-
None
229-
};
180+
let expected_type = infer_type_if_missing(&fcx, node);
230181
let expected_type = expected_type.unwrap_or_else(fallback);
231182

232183
let expected_type = fcx.normalize(body.value.span, expected_type);
@@ -296,6 +247,59 @@ fn typeck_with_fallback<'tcx>(
296247
typeck_results
297248
}
298249

250+
fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Option<Ty<'tcx>> {
251+
let tcx = fcx.tcx;
252+
let def_id = fcx.body_id;
253+
let expected_type = if let Some(&hir::Ty { kind: hir::TyKind::Infer, span, .. }) = node.ty() {
254+
if let Some(item) = tcx.opt_associated_item(def_id.into())
255+
&& let ty::AssocKind::Const = item.kind
256+
&& let ty::ImplContainer = item.container
257+
&& let Some(trait_item) = item.trait_item_def_id
258+
{
259+
let args =
260+
tcx.impl_trait_ref(item.container_id(tcx)).unwrap().instantiate_identity().args;
261+
Some(tcx.type_of(trait_item).instantiate(tcx, args))
262+
} else {
263+
Some(fcx.next_ty_var(TypeVariableOrigin {
264+
kind: TypeVariableOriginKind::TypeInference,
265+
span,
266+
}))
267+
}
268+
} else if let Node::AnonConst(_) = node {
269+
let id = tcx.local_def_id_to_hir_id(def_id);
270+
match tcx.parent_hir_node(id) {
271+
Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(ref anon_const), span, .. })
272+
if anon_const.hir_id == id =>
273+
{
274+
Some(fcx.next_ty_var(TypeVariableOrigin {
275+
kind: TypeVariableOriginKind::TypeInference,
276+
span,
277+
}))
278+
}
279+
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. })
280+
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), span, .. }) => {
281+
asm.operands.iter().find_map(|(op, _op_sp)| match op {
282+
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == id => {
283+
// Inline assembly constants must be integers.
284+
Some(fcx.next_int_var())
285+
}
286+
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == id => {
287+
Some(fcx.next_ty_var(TypeVariableOrigin {
288+
kind: TypeVariableOriginKind::MiscVariable,
289+
span,
290+
}))
291+
}
292+
_ => None,
293+
})
294+
}
295+
_ => None,
296+
}
297+
} else {
298+
None
299+
};
300+
expected_type
301+
}
302+
299303
/// When `check_fn` is invoked on a coroutine (i.e., a body that
300304
/// includes yield), it returns back some information about the yield
301305
/// points.

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ impl<'a> Parser<'a> {
27682768
};
27692769
return if self.token.kind == token::CloseDelim(Delimiter::Parenthesis) {
27702770
// We know for sure we have seen `for ($SOMETHING in $EXPR)`, so we recover the
2771-
// parser state and emit a targetted suggestion.
2771+
// parser state and emit a targeted suggestion.
27722772
let span = vec![start_span, self.token.span];
27732773
let right = self.prev_token.span.between(self.look_ahead(1, |t| t.span));
27742774
self.bump(); // )

library/alloc/src/collections/vec_deque/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
16141614
let old_head = self.head;
16151615
self.head = self.to_physical_idx(1);
16161616
self.len -= 1;
1617-
Some(unsafe { self.buffer_read(old_head) })
1617+
unsafe {
1618+
core::hint::assert_unchecked(self.len < self.capacity());
1619+
Some(self.buffer_read(old_head))
1620+
}
16181621
}
16191622
}
16201623

@@ -1638,7 +1641,10 @@ impl<T, A: Allocator> VecDeque<T, A> {
16381641
None
16391642
} else {
16401643
self.len -= 1;
1641-
Some(unsafe { self.buffer_read(self.to_physical_idx(self.len)) })
1644+
unsafe {
1645+
core::hint::assert_unchecked(self.len < self.capacity());
1646+
Some(self.buffer_read(self.to_physical_idx(self.len)))
1647+
}
16421648
}
16431649
}
16441650

library/core/src/num/nonzero.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ use super::{IntErrorKind, ParseIntError};
2020
///
2121
/// # Safety
2222
///
23-
/// Types implementing this trait must be primitves that are valid when zeroed.
23+
/// Types implementing this trait must be primitives that are valid when zeroed.
24+
///
25+
/// The associated `Self::NonZeroInner` type must have the same size+align as `Self`,
26+
/// but with a niche and bit validity making it so the following `transmutes` are sound:
27+
///
28+
/// - `Self::NonZeroInner` to `Option<Self::NonZeroInner>`
29+
/// - `Option<Self::NonZeroInner>` to `Self`
30+
///
31+
/// (And, consequently, `Self::NonZeroInner` to `Self`.)
2432
#[unstable(
2533
feature = "nonzero_internals",
2634
reason = "implementation detail which may disappear or be replaced at any time",
@@ -434,17 +442,11 @@ where
434442
// of some not-inlined function, LLVM don't have range metadata
435443
// to understand that the value cannot be zero.
436444
//
437-
// SAFETY: `Self` is guaranteed to have the same layout as `Option<Self>`.
438-
match unsafe { intrinsics::transmute_unchecked(self) } {
439-
None => {
440-
// SAFETY: `NonZero` is guaranteed to only contain non-zero values, so this is unreachable.
441-
unsafe { intrinsics::unreachable() }
442-
}
443-
Some(Self(inner)) => {
444-
// SAFETY: `T::NonZeroInner` is guaranteed to have the same layout as `T`.
445-
unsafe { intrinsics::transmute_unchecked(inner) }
446-
}
447-
}
445+
// For now, using the transmute `assume`s the range at runtime.
446+
//
447+
// SAFETY: `ZeroablePrimitive` guarantees that the size and bit validity
448+
// of `.0` is such that this transmute is sound.
449+
unsafe { intrinsics::transmute_unchecked(self) }
448450
}
449451
}
450452

library/core/src/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@
806806
//!
807807
//! As a consequence, the struct *must not* be [`#[repr(packed)]`][packed].
808808
//!
809-
//! 3. *Structural Notice of Destruction.* You must uphold the the
809+
//! 3. *Structural Notice of Destruction.* You must uphold the
810810
//! [`Drop` guarantee][drop-guarantee]: once your struct is pinned, the struct's storage cannot
811811
//! be re-used without calling the structurally-pinned fields' destructors, as well.
812812
//!

library/core/src/sync/atomic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const EMULATE_ATOMIC_BOOL: bool =
243243

244244
/// A boolean type which can be safely shared between threads.
245245
///
246-
/// This type has the same in-memory representation as a [`bool`].
246+
/// This type has the same size, alignment, and bit validity as a [`bool`].
247247
///
248248
/// **Note**: This type is only available on platforms that support atomic
249249
/// loads and stores of `u8`.
@@ -272,7 +272,7 @@ unsafe impl Sync for AtomicBool {}
272272

273273
/// A raw pointer type which can be safely shared between threads.
274274
///
275-
/// This type has the same in-memory representation as a `*mut T`.
275+
/// This type has the same size and bit validity as a `*mut T`.
276276
///
277277
/// **Note**: This type is only available on platforms that support atomic
278278
/// loads and stores of pointers. Its size depends on the target pointer's size.
@@ -2121,7 +2121,7 @@ macro_rules! atomic_int {
21212121
$int_type:ident $atomic_type:ident) => {
21222122
/// An integer type which can be safely shared between threads.
21232123
///
2124-
/// This type has the same in-memory representation as the underlying
2124+
/// This type has the same size and bit validity as the underlying
21252125
/// integer type, [`
21262126
#[doc = $s_int_type]
21272127
/// `].

library/std/src/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl File {
385385
/// See the [`OpenOptions::open`] function for more details.
386386
///
387387
/// See also [`std::fs::write()`][self::write] for a simple function to
388-
/// create a file with a given data.
388+
/// create a file with some given data.
389389
///
390390
/// # Examples
391391
///
@@ -1036,7 +1036,7 @@ impl OpenOptions {
10361036
/// [`OpenOptions::append`] access must be used.
10371037
///
10381038
/// See also [`std::fs::write()`][self::write] for a simple function to
1039-
/// create a file with a given data.
1039+
/// create a file with some given data.
10401040
///
10411041
/// # Examples
10421042
///

0 commit comments

Comments
 (0)