Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #100947

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7680c8b
Properly forward `ByRefSized::fold` to the inner iterator
scottmcm Aug 7, 2022
8998024
Correct test-args to compiletest on Windows
czzrr Aug 19, 2022
acca4b8
Extra documentation for new formatting feature
IsaacCloos Aug 21, 2022
000dc80
make some methods private
TaKO8Ki Aug 22, 2022
ba74a62
Diagnose missing includes in run-make tests
tmiasko Aug 23, 2022
b0255a1
Suggest alternatives when trying to mutate a `HashMap`/`BTreeMap` via…
ChayimFriedman2 Aug 23, 2022
53565b2
Make use of `[wrapping_]byte_{add,sub}`
WaffleLapkin Aug 19, 2022
8ad36c4
Rewrite error index generator to greatly reduce the size of the pages
GuillaumeGomez Aug 23, 2022
c664a36
Handle error code hash by redirecting to the correct error code page
GuillaumeGomez Aug 23, 2022
4398d92
Fix links to error codes
GuillaumeGomez Aug 23, 2022
3d8c7d2
sugg: take into count the debug formatting
vincenzopalazzo Aug 20, 2022
4eb748b
Use `--userns=keep-id` when "docker" is really podman
cuviper Aug 23, 2022
b1925b8
rustdoc: remove unused CSS rule
notriddle Aug 24, 2022
56f9e29
add a missing test case for impl generic mismatch
TaKO8Ki Aug 24, 2022
d49808f
Rollup merge of #100220 - scottmcm:fix-by-ref-sized, r=joshtriplett
matthiaskrgr Aug 24, 2022
bb4dc44
Rollup merge of #100811 - czzrr:master, r=Mark-Simulacrum
matthiaskrgr Aug 24, 2022
085ba81
Rollup merge of #100819 - WaffleLapkin:use_ptr_byte_methods, r=scottmcm
matthiaskrgr Aug 24, 2022
0d5223d
Rollup merge of #100826 - vincenzopalazzo:macros/wrong_sugg_with_posi…
matthiaskrgr Aug 24, 2022
42d58ae
Rollup merge of #100855 - IsaacCloos:master, r=joshtriplett
matthiaskrgr Aug 24, 2022
b0b4c4f
Rollup merge of #100901 - TaKO8Ki:make-some-methods-private, r=sanxiyn
matthiaskrgr Aug 24, 2022
6623333
Rollup merge of #100906 - ChayimFriedman2:map-index-mut, r=davidtwco
matthiaskrgr Aug 24, 2022
14a5558
Rollup merge of #100912 - tmiasko:make-include, r=TaKO8Ki
matthiaskrgr Aug 24, 2022
2b9d41e
Rollup merge of #100922 - GuillaumeGomez:rewrite-error-index, r=notri…
matthiaskrgr Aug 24, 2022
ccfb168
Rollup merge of #100930 - cuviper:podman-keep-id, r=jyn514
matthiaskrgr Aug 24, 2022
0293780
Rollup merge of #100938 - notriddle:notriddle/fields-table, r=sanxiyn
matthiaskrgr Aug 24, 2022
62ae1fa
Rollup merge of #100945 - TaKO8Ki:add-missing-test-case-for-impl-gene…
matthiaskrgr Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![feature(maybe_uninit_slice)]
#![feature(min_specialization)]
#![feature(decl_macro)]
#![feature(pointer_byte_offsets)]
#![feature(rustc_attrs)]
#![cfg_attr(test, feature(test))]
#![feature(strict_provenance)]
Expand Down Expand Up @@ -211,7 +212,7 @@ impl<T> TypedArena<T> {

unsafe {
if mem::size_of::<T>() == 0 {
self.ptr.set((self.ptr.get() as *mut u8).wrapping_offset(1) as *mut T);
self.ptr.set(self.ptr.get().wrapping_byte_add(1));
let ptr = ptr::NonNull::<T>::dangling().as_ptr();
// Don't drop the object. This `write` is equivalent to `forget`.
ptr::write(ptr, object);
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
_ => {}
}
}
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(

fn add_lifetime_bound_suggestion_to_diagnostic(
&self,
err: &mut Diagnostic,
category: &ConstraintCategory<'tcx>,
Expand Down
19 changes: 17 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_middle::hir::map::Map;
Expand All @@ -12,12 +13,11 @@ use rustc_middle::{
};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::{kw, Symbol};
use rustc_span::{BytePos, Span};
use rustc_span::{sym, BytePos, Span};

use crate::diagnostics::BorrowedContentSource;
use crate::MirBorrowckCtxt;
use rustc_const_eval::util::collect_writes::FindAssignments;
use rustc_errors::{Applicability, Diagnostic};

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum AccessKind {
Expand Down Expand Up @@ -614,6 +614,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
"trait `IndexMut` is required to modify indexed content, \
but it is not implemented for `{ty}`",
));
self.suggest_map_index_mut_alternatives(ty, &mut err);
}
_ => (),
}
Expand All @@ -627,6 +628,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
self.buffer_error(err);
}

fn suggest_map_index_mut_alternatives(
&self,
ty: Ty<'_>,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
) {
let Some(adt) = ty.ty_adt_def() else { return };
let did = adt.did();
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
{
err.help(format!("to modify a `{ty}`, use `.get_mut()`, `.insert()` or the entry API"));
}
}

/// User cannot make signature of a trait mutable without changing the
/// trait. So we find if this error belongs to a trait and if so we move
/// suggestion to the trait or disable it if it is out of scope of this crate
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,14 @@ pub trait LintContext: Sized {

if let Some(positional_arg_to_replace) = position_sp_to_replace {
let name = if is_formatting_arg { named_arg_name + "$" } else { named_arg_name };

let span_to_replace = if let Ok(positional_arg_content) =
self.sess().source_map().span_to_snippet(positional_arg_to_replace) && positional_arg_content.starts_with(":") {
positional_arg_to_replace.shrink_to_lo()
} else {
positional_arg_to_replace
};
db.span_suggestion_verbose(
positional_arg_to_replace,
span_to_replace,
"use the named argument by name to avoid ambiguity",
name,
Applicability::MaybeIncorrect,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
err.emit()
}

pub(crate) fn add_missing_lifetime_specifiers_label(
fn add_missing_lifetime_specifiers_label(
&mut self,
err: &mut Diagnostic,
lifetime_refs: Vec<MissingLifetime>,
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ macro_rules! vec {
/// format!("test");
/// format!("hello {}", "world!");
/// format!("x = {}, y = {y}", 10, y = 30);
/// let (x, y) = (1, 2);
/// format!("{x} + {y} = 3");
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
13 changes: 5 additions & 8 deletions library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::alloc::{Allocator, Global};
use crate::raw_vec::RawVec;
use core::array;
use core::fmt;
use core::intrinsics::arith_offset;
use core::iter::{
FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce,
};
Expand Down Expand Up @@ -154,7 +153,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
self.ptr = unsafe { arith_offset(self.ptr as *const i8, 1) as *mut T };
self.ptr = self.ptr.wrapping_byte_add(1);

// Make up a value of this ZST.
Some(unsafe { mem::zeroed() })
Expand Down Expand Up @@ -184,7 +183,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
// SAFETY: due to unchecked casts of unsigned amounts to signed offsets the wraparound
// effectively results in unsigned pointers representing positions 0..usize::MAX,
// which is valid for ZSTs.
self.ptr = unsafe { arith_offset(self.ptr as *const i8, step_size as isize) as *mut T }
self.ptr = self.ptr.wrapping_byte_add(step_size);
} else {
// SAFETY: the min() above ensures that step_size is in bounds
self.ptr = unsafe { self.ptr.add(step_size) };
Expand Down Expand Up @@ -217,7 +216,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
return Err(unsafe { array::IntoIter::new_unchecked(raw_ary, 0..len) });
}

self.ptr = unsafe { arith_offset(self.ptr as *const i8, N as isize) as *mut T };
self.ptr = self.ptr.wrapping_byte_add(N);
// Safety: ditto
return Ok(unsafe { MaybeUninit::array_assume_init(raw_ary) });
}
Expand Down Expand Up @@ -267,7 +266,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
None
} else if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
self.end = unsafe { arith_offset(self.end as *const i8, -1) as *mut T };
self.end = self.ptr.wrapping_byte_sub(1);

// Make up a value of this ZST.
Some(unsafe { mem::zeroed() })
Expand All @@ -283,9 +282,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
let step_size = self.len().min(n);
if mem::size_of::<T>() == 0 {
// SAFETY: same as for advance_by()
self.end = unsafe {
arith_offset(self.end as *const i8, step_size.wrapping_neg() as isize) as *mut T
}
self.end = self.end.wrapping_byte_sub(step_size);
} else {
// SAFETY: same as for advance_by()
self.end = unsafe { self.end.sub(step_size) };
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use core::cmp::Ordering;
use core::convert::TryFrom;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::intrinsics::{arith_offset, assume};
use core::intrinsics::assume;
use core::iter;
#[cfg(not(no_global_oom_handling))]
use core::iter::FromIterator;
Expand Down Expand Up @@ -2678,7 +2678,7 @@ impl<T, A: Allocator> IntoIterator for Vec<T, A> {
let alloc = ManuallyDrop::new(ptr::read(me.allocator()));
let begin = me.as_mut_ptr();
let end = if mem::size_of::<T>() == 0 {
arith_offset(begin as *const i8, me.len() as isize) as *const T
begin.wrapping_byte_add(me.len())
} else {
begin.add(me.len()) as *const T
};
Expand Down
29 changes: 17 additions & 12 deletions library/core/src/iter/adapters/by_ref_sized.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ops::Try;
use crate::ops::{NeverShortCircuit, Try};

/// Like `Iterator::by_ref`, but requiring `Sized` so it can forward generics.
///
Expand All @@ -8,36 +8,40 @@ use crate::ops::Try;
#[derive(Debug)]
pub struct ByRefSized<'a, I>(pub &'a mut I);

// The following implementations use UFCS-style, rather than trusting autoderef,
// to avoid accidentally calling the `&mut Iterator` implementations.

#[unstable(feature = "std_internals", issue = "none")]
impl<I: Iterator> Iterator for ByRefSized<'_, I> {
type Item = I::Item;

#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
I::next(self.0)
}

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
I::size_hint(self.0)
}

#[inline]
fn advance_by(&mut self, n: usize) -> Result<(), usize> {
self.0.advance_by(n)
I::advance_by(self.0, n)
}

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.0.nth(n)
I::nth(self.0, n)
}

#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
F: FnMut(B, Self::Item) -> B,
{
self.0.fold(init, f)
// `fold` needs ownership, so this can't forward directly.
I::try_fold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0
}

#[inline]
Expand All @@ -46,33 +50,34 @@ impl<I: Iterator> Iterator for ByRefSized<'_, I> {
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
{
self.0.try_fold(init, f)
I::try_fold(self.0, init, f)
}
}

#[unstable(feature = "std_internals", issue = "none")]
impl<I: DoubleEndedIterator> DoubleEndedIterator for ByRefSized<'_, I> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
self.0.next_back()
I::next_back(self.0)
}

#[inline]
fn advance_back_by(&mut self, n: usize) -> Result<(), usize> {
self.0.advance_back_by(n)
I::advance_back_by(self.0, n)
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
self.0.nth_back(n)
I::nth_back(self.0, n)
}

#[inline]
fn rfold<B, F>(self, init: B, f: F) -> B
where
F: FnMut(B, Self::Item) -> B,
{
self.0.rfold(init, f)
// `rfold` needs ownership, so this can't forward directly.
I::try_rfold(self.0, init, NeverShortCircuit::wrap_mut_2(f)).0
}

#[inline]
Expand All @@ -81,6 +86,6 @@ impl<I: DoubleEndedIterator> DoubleEndedIterator for ByRefSized<'_, I> {
F: FnMut(B, Self::Item) -> R,
R: Try<Output = B>,
{
self.0.try_rfold(init, f)
I::try_rfold(self.0, init, f)
}
}
2 changes: 1 addition & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub trait StructuralEq {
/// If you try to implement `Copy` on a struct or enum containing non-`Copy` data, you will get
/// the error [E0204].
///
/// [E0204]: ../../error-index.html#E0204
/// [E0204]: ../../error_codes/E0204.html
///
/// ## When *should* my type be `Copy`?
///
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ops/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub trait Drop {
/// handled by the compiler, but when using unsafe code, can sometimes occur
/// unintentionally, particularly when using [`ptr::drop_in_place`].
///
/// [E0040]: ../../error-index.html#E0040
/// [E0040]: ../../error_codes/E0040.html
/// [`panic!`]: crate::panic!
/// [`mem::drop`]: drop
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<T: ?Sized> *const T {
let offset = dest_addr.wrapping_sub(self_addr);

// This is the canonical desugarring of this operation
self.cast::<u8>().wrapping_offset(offset).cast::<T>()
self.wrapping_byte_offset(offset)
}

/// Creates a new pointer by mapping `self`'s address to a new one.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl<T: ?Sized> *mut T {
let offset = dest_addr.wrapping_sub(self_addr);

// This is the canonical desugarring of this operation
self.cast::<u8>().wrapping_offset(offset).cast::<T>()
self.wrapping_byte_offset(offset)
}

/// Creates a new pointer by mapping `self`'s address to a new one.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/slice/iter/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ macro_rules! iterator {
// backwards by `n`. `n` must not exceed `self.len()`.
macro_rules! zst_shrink {
($self: ident, $n: ident) => {
$self.end = ($self.end as * $raw_mut u8).wrapping_offset(-$n) as * $raw_mut T;
$self.end = $self.end.wrapping_byte_offset(-$n);
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn ptr_add_data() {

assert_eq!(atom.fetch_ptr_sub(1, SeqCst), n.wrapping_add(1));
assert_eq!(atom.load(SeqCst), n);
let bytes_from_n = |b| n.cast::<u8>().wrapping_add(b).cast::<i64>();
let bytes_from_n = |b| n.wrapping_byte_add(b);

assert_eq!(atom.fetch_byte_add(1, SeqCst), n);
assert_eq!(atom.load(SeqCst), bytes_from_n(1));
Expand Down
20 changes: 20 additions & 0 deletions library/core/tests/iter/adapters/by_ref_sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use core::iter::*;

#[test]
fn test_iterator_by_ref_sized() {
let a = ['a', 'b', 'c', 'd'];

let mut s = String::from("Z");
let mut it = a.iter().copied();
ByRefSized(&mut it).take(2).for_each(|x| s.push(x));
assert_eq!(s, "Zab");
ByRefSized(&mut it).fold((), |(), x| s.push(x));
assert_eq!(s, "Zabcd");

let mut s = String::from("Z");
let mut it = a.iter().copied();
ByRefSized(&mut it).rev().take(2).for_each(|x| s.push(x));
assert_eq!(s, "Zdc");
ByRefSized(&mut it).rfold((), |(), x| s.push(x));
assert_eq!(s, "Zdcba");
}
1 change: 1 addition & 0 deletions library/core/tests/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod array_chunks;
mod by_ref_sized;
mod chain;
mod cloned;
mod copied;
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ fn thin_box() {
.unwrap_or_else(|| handle_alloc_error(layout))
.cast::<DynMetadata<T>>();
ptr.as_ptr().write(meta);
ptr.cast::<u8>().as_ptr().add(offset).cast::<Value>().write(value);
ptr.as_ptr().byte_add(offset).cast::<Value>().write(value);
Self { ptr, phantom: PhantomData }
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/io/error/repr_bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ where
}
TAG_SIMPLE_MESSAGE => ErrorData::SimpleMessage(&*ptr.cast::<SimpleMessage>().as_ptr()),
TAG_CUSTOM => {
// It would be correct for us to use `ptr::sub` here (see the
// It would be correct for us to use `ptr::byte_sub` here (see the
// comment above the `wrapping_add` call in `new_custom` for why),
// but it isn't clear that it makes a difference, so we don't.
let custom = ptr.as_ptr().cast::<u8>().wrapping_sub(TAG_CUSTOM).cast::<Custom>();
let custom = ptr.as_ptr().wrapping_byte_sub(TAG_CUSTOM).cast::<Custom>();
ErrorData::Custom(make_custom(custom))
}
_ => {
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
#![feature(panic_can_unwind)]
#![feature(panic_info_message)]
#![feature(panic_internals)]
#![feature(pointer_byte_offsets)]
#![feature(pointer_is_aligned)]
#![feature(portable_simd)]
#![feature(prelude_2024)]
Expand Down
Loading