Skip to content

Commit 0b9f7b9

Browse files
committed
Auto merge of #144611 - samueltardieu:rollup-c57gj2t, r=samueltardieu
Rollup of 11 pull requests Successful merges: - #143289 (Remove `[T]::array_chunks(_mut)`) - #143883 (Add `--link-targets-dir` argument to linkchecker) - #144034 (tests: Test line number in debuginfo for diverging function calls) - #144236 (Add `core::mem::DropGuard`) - #144268 (Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt`) - #144303 (Consolidate staging for `rustc_private` tools) - #144539 (constify with_exposed_provenance) - #144569 (rustc-dev-guide subtree update) - #144573 (Raw Pointers are Constant PatKinds too) - #144578 (Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.) - #144582 (fix `Atomic*::as_ptr` wording) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cdccba8 + ca330e1 commit 0b9f7b9

File tree

45 files changed

+1480
-1266
lines changed

Some content is hidden

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

45 files changed

+1480
-1266
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
341341
}
342342
}
343343
} else if let LocalInfo::BlockTailTemp(info) = local_decl.local_info() {
344-
let sp = info.span.find_oldest_ancestor_in_same_ctxt();
344+
let sp = info.span.find_ancestor_not_from_macro().unwrap_or(info.span);
345345
if info.tail_result_is_ignored {
346346
// #85581: If the first mutable borrow's scope contains
347347
// the second borrow, this suggestion isn't helpful.

compiler/rustc_codegen_cranelift/patches/0027-sysroot_tests-128bit-atomic-operations.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ index 1e336bf..35e6f54 100644
1919
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
2020
#![cfg_attr(test, feature(cfg_select))]
2121
#![feature(alloc_layout_extra)]
22-
#![feature(array_chunks)]
22+
#![feature(array_ptr_get)]
2323
diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs
2424
index b735957..ea728b6 100644
2525
--- a/coretests/tests/atomic.rs

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ impl From<Ident> for LifetimeSyntax {
148148
/// `LifetimeSource::OutlivesBound` or `LifetimeSource::PreciseCapturing`
149149
/// — there's no way to "elide" these lifetimes.
150150
#[derive(Debug, Copy, Clone, HashStable_Generic)]
151+
// Raise the aligement to at least 4 bytes - this is relied on in other parts of the compiler(for pointer tagging):
152+
// https://github.com/rust-lang/rust/blob/ce5fdd7d42aba9a2925692e11af2bd39cf37798a/compiler/rustc_data_structures/src/tagged_ptr.rs#L163
153+
// Removing this `repr(4)` will cause the compiler to not build on platforms like `m68k` Linux, where the aligement of u32 and usize is only 2.
154+
// Since `repr(align)` may only raise aligement, this has no effect on platforms where the aligement is already sufficient.
155+
#[repr(align(4))]
151156
pub struct Lifetime {
152157
#[stable_hasher(ignore)]
153158
pub hir_id: HirId,

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13951395
.macro_backtrace()
13961396
.any(|x| matches!(x.kind, ExpnKind::Macro(MacroKind::Attr | MacroKind::Derive, ..)))
13971397
{
1398-
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
1398+
let span = expr
1399+
.span
1400+
.find_ancestor_not_from_extern_macro(&self.tcx.sess.source_map())
1401+
.unwrap_or(expr.span);
13991402

14001403
let mut sugg = if self.precedence(expr) >= ExprPrecedence::Unambiguous {
14011404
vec![(span.shrink_to_hi(), ".into()".to_owned())]
@@ -2062,7 +2065,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20622065
None => sugg.to_string(),
20632066
};
20642067

2065-
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
2068+
let span = expr
2069+
.span
2070+
.find_ancestor_not_from_extern_macro(&self.tcx.sess.source_map())
2071+
.unwrap_or(expr.span);
20662072
err.span_suggestion_verbose(span.shrink_to_hi(), msg, sugg, Applicability::HasPlaceholders);
20672073
true
20682074
}

compiler/rustc_lint/src/unused.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
185185
let mut op_warned = false;
186186

187187
if let Some(must_use_op) = must_use_op {
188-
let span = expr.span.find_oldest_ancestor_in_same_ctxt();
188+
let span = expr.span.find_ancestor_not_from_macro().unwrap_or(expr.span);
189189
cx.emit_span_lint(
190190
UNUSED_MUST_USE,
191191
expr.span,
@@ -511,7 +511,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
511511
);
512512
}
513513
MustUsePath::Def(span, def_id, reason) => {
514-
let span = span.find_oldest_ancestor_in_same_ctxt();
514+
let span = span.find_ancestor_not_from_macro().unwrap_or(*span);
515515
cx.emit_span_lint(
516516
UNUSED_MUST_USE,
517517
span,

compiler/rustc_middle/src/thir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ pub enum PatKind<'tcx> {
838838
/// * integer, bool, char or float (represented as a valtree), which will be handled by
839839
/// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
840840
/// much simpler.
841+
/// * raw pointers derived from integers, other raw pointers will have already resulted in an
842+
// error.
841843
/// * `String`, if `string_deref_patterns` is enabled.
842844
Constant {
843845
value: mir::Const<'tcx>,

compiler/rustc_span/src/lib.rs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,17 @@ impl Span {
716716
(!ctxt.is_root()).then(|| ctxt.outer_expn_data().call_site)
717717
}
718718

719-
/// Walk down the expansion ancestors to find a span that's contained within `outer`.
719+
/// Find the first ancestor span that's contained within `outer`.
720720
///
721-
/// The span returned by this method may have a different [`SyntaxContext`] as `outer`.
721+
/// This method traverses the macro expansion ancestors until it finds the first span
722+
/// that's contained within `outer`.
723+
///
724+
/// The span returned by this method may have a different [`SyntaxContext`] than `outer`.
722725
/// If you need to extend the span, use [`find_ancestor_inside_same_ctxt`] instead,
723726
/// because joining spans with different syntax contexts can create unexpected results.
724727
///
728+
/// This is used to find the span of the macro call when a parent expr span, i.e. `outer`, is known.
729+
///
725730
/// [`find_ancestor_inside_same_ctxt`]: Self::find_ancestor_inside_same_ctxt
726731
pub fn find_ancestor_inside(mut self, outer: Span) -> Option<Span> {
727732
while !outer.contains(self) {
@@ -730,8 +735,10 @@ impl Span {
730735
Some(self)
731736
}
732737

733-
/// Walk down the expansion ancestors to find a span with the same [`SyntaxContext`] as
734-
/// `other`.
738+
/// Find the first ancestor span with the same [`SyntaxContext`] as `other`.
739+
///
740+
/// This method traverses the macro expansion ancestors until it finds a span
741+
/// that has the same [`SyntaxContext`] as `other`.
735742
///
736743
/// Like [`find_ancestor_inside_same_ctxt`], but specifically for when spans might not
737744
/// overlap. Take care when using this, and prefer [`find_ancestor_inside`] or
@@ -747,9 +754,12 @@ impl Span {
747754
Some(self)
748755
}
749756

750-
/// Walk down the expansion ancestors to find a span that's contained within `outer` and
757+
/// Find the first ancestor span that's contained within `outer` and
751758
/// has the same [`SyntaxContext`] as `outer`.
752759
///
760+
/// This method traverses the macro expansion ancestors until it finds a span
761+
/// that is both contained within `outer` and has the same [`SyntaxContext`] as `outer`.
762+
///
753763
/// This method is the combination of [`find_ancestor_inside`] and
754764
/// [`find_ancestor_in_same_ctxt`] and should be preferred when extending the returned span.
755765
/// If you do not need to modify the span, use [`find_ancestor_inside`] instead.
@@ -763,43 +773,43 @@ impl Span {
763773
Some(self)
764774
}
765775

766-
/// Recursively walk down the expansion ancestors to find the oldest ancestor span with the same
767-
/// [`SyntaxContext`] the initial span.
776+
/// Find the first ancestor span that does not come from an external macro.
768777
///
769-
/// This method is suitable for peeling through *local* macro expansions to find the "innermost"
770-
/// span that is still local and shares the same [`SyntaxContext`]. For example, given
778+
/// This method traverses the macro expansion ancestors until it finds a span
779+
/// that is either from user-written code or from a local macro (defined in the current crate).
771780
///
772-
/// ```ignore (illustrative example, contains type error)
773-
/// macro_rules! outer {
774-
/// ($x: expr) => {
775-
/// inner!($x)
776-
/// }
777-
/// }
781+
/// External macros are those defined in dependencies or the standard library.
782+
/// This method is useful for reporting errors in user-controllable code and avoiding
783+
/// diagnostics inside external macros.
778784
///
779-
/// macro_rules! inner {
780-
/// ($x: expr) => {
781-
/// format!("error: {}", $x)
782-
/// //~^ ERROR mismatched types
783-
/// }
784-
/// }
785+
/// # See also
785786
///
786-
/// fn bar(x: &str) -> Result<(), Box<dyn std::error::Error>> {
787-
/// Err(outer!(x))
788-
/// }
789-
/// ```
787+
/// - [`Self::find_ancestor_not_from_macro`]
788+
/// - [`Self::in_external_macro`]
789+
pub fn find_ancestor_not_from_extern_macro(mut self, sm: &SourceMap) -> Option<Span> {
790+
while self.in_external_macro(sm) {
791+
self = self.parent_callsite()?;
792+
}
793+
Some(self)
794+
}
795+
796+
/// Find the first ancestor span that does not come from any macro expansion.
790797
///
791-
/// if provided the initial span of `outer!(x)` inside `bar`, this method will recurse
792-
/// the parent callsites until we reach `format!("error: {}", $x)`, at which point it is the
793-
/// oldest ancestor span that is both still local and shares the same [`SyntaxContext`] as the
794-
/// initial span.
795-
pub fn find_oldest_ancestor_in_same_ctxt(self) -> Span {
796-
let mut cur = self;
797-
while cur.eq_ctxt(self)
798-
&& let Some(parent_callsite) = cur.parent_callsite()
799-
{
800-
cur = parent_callsite;
798+
/// This method traverses the macro expansion ancestors until it finds a span
799+
/// that originates from user-written code rather than any macro-generated code.
800+
///
801+
/// This method is useful for reporting errors at the exact location users wrote code
802+
/// and providing suggestions at directly editable locations.
803+
///
804+
/// # See also
805+
///
806+
/// - [`Self::find_ancestor_not_from_extern_macro`]
807+
/// - [`Span::from_expansion`]
808+
pub fn find_ancestor_not_from_macro(mut self) -> Option<Span> {
809+
while self.from_expansion() {
810+
self = self.parent_callsite()?;
801811
}
802-
cur
812+
Some(self)
803813
}
804814

805815
/// Edition of the crate from which this span came.

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
// tidy-alphabetical-start
9595
#![feature(alloc_layout_extra)]
9696
#![feature(allocator_api)]
97-
#![feature(array_chunks)]
9897
#![feature(array_into_iter_constructors)]
9998
#![feature(array_windows)]
10099
#![feature(ascii_char)]

library/alloc/src/slice.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ use core::cmp::Ordering::{self, Less};
1616
use core::mem::MaybeUninit;
1717
#[cfg(not(no_global_oom_handling))]
1818
use core::ptr;
19-
#[unstable(feature = "array_chunks", issue = "74985")]
20-
pub use core::slice::ArrayChunks;
21-
#[unstable(feature = "array_chunks", issue = "74985")]
22-
pub use core::slice::ArrayChunksMut;
2319
#[unstable(feature = "array_windows", issue = "75027")]
2420
pub use core::slice::ArrayWindows;
2521
#[stable(feature = "inherent_ascii_escape", since = "1.60.0")]

library/alloc/src/string.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,12 @@ impl String {
787787
#[cfg(not(no_global_oom_handling))]
788788
#[unstable(feature = "str_from_utf16_endian", issue = "116258")]
789789
pub fn from_utf16le(v: &[u8]) -> Result<String, FromUtf16Error> {
790-
if v.len() % 2 != 0 {
790+
let (chunks, []) = v.as_chunks::<2>() else {
791791
return Err(FromUtf16Error(()));
792-
}
792+
};
793793
match (cfg!(target_endian = "little"), unsafe { v.align_to::<u16>() }) {
794794
(true, ([], v, [])) => Self::from_utf16(v),
795-
_ => char::decode_utf16(v.array_chunks::<2>().copied().map(u16::from_le_bytes))
795+
_ => char::decode_utf16(chunks.iter().copied().map(u16::from_le_bytes))
796796
.collect::<Result<_, _>>()
797797
.map_err(|_| FromUtf16Error(())),
798798
}
@@ -830,11 +830,11 @@ impl String {
830830
(true, ([], v, [])) => Self::from_utf16_lossy(v),
831831
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
832832
_ => {
833-
let mut iter = v.array_chunks::<2>();
834-
let string = char::decode_utf16(iter.by_ref().copied().map(u16::from_le_bytes))
833+
let (chunks, remainder) = v.as_chunks::<2>();
834+
let string = char::decode_utf16(chunks.iter().copied().map(u16::from_le_bytes))
835835
.map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
836836
.collect();
837-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
837+
if remainder.is_empty() { string } else { string + "\u{FFFD}" }
838838
}
839839
}
840840
}
@@ -862,12 +862,12 @@ impl String {
862862
#[cfg(not(no_global_oom_handling))]
863863
#[unstable(feature = "str_from_utf16_endian", issue = "116258")]
864864
pub fn from_utf16be(v: &[u8]) -> Result<String, FromUtf16Error> {
865-
if v.len() % 2 != 0 {
865+
let (chunks, []) = v.as_chunks::<2>() else {
866866
return Err(FromUtf16Error(()));
867-
}
867+
};
868868
match (cfg!(target_endian = "big"), unsafe { v.align_to::<u16>() }) {
869869
(true, ([], v, [])) => Self::from_utf16(v),
870-
_ => char::decode_utf16(v.array_chunks::<2>().copied().map(u16::from_be_bytes))
870+
_ => char::decode_utf16(chunks.iter().copied().map(u16::from_be_bytes))
871871
.collect::<Result<_, _>>()
872872
.map_err(|_| FromUtf16Error(())),
873873
}
@@ -905,11 +905,11 @@ impl String {
905905
(true, ([], v, [])) => Self::from_utf16_lossy(v),
906906
(true, ([], v, [_remainder])) => Self::from_utf16_lossy(v) + "\u{FFFD}",
907907
_ => {
908-
let mut iter = v.array_chunks::<2>();
909-
let string = char::decode_utf16(iter.by_ref().copied().map(u16::from_be_bytes))
908+
let (chunks, remainder) = v.as_chunks::<2>();
909+
let string = char::decode_utf16(chunks.iter().copied().map(u16::from_be_bytes))
910910
.map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
911911
.collect();
912-
if iter.remainder().is_empty() { string } else { string + "\u{FFFD}" }
912+
if remainder.is_empty() { string } else { string + "\u{FFFD}" }
913913
}
914914
}
915915
}

0 commit comments

Comments
 (0)