Skip to content

Commit 821c33f

Browse files
authored
Merge pull request rust-lang#4196 from rust-lang/rustup-2025-02-17
Automatic Rustup
2 parents 69e5ec7 + 9743852 commit 821c33f

File tree

64 files changed

+1009
-244
lines changed

Some content is hidden

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

64 files changed

+1009
-244
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
1414
use rustc_middle::bug;
1515
use rustc_middle::hir::place::PlaceBase;
1616
use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint};
17-
use rustc_middle::ty::{self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeVisitor};
17+
use rustc_middle::ty::fold::fold_regions;
18+
use rustc_middle::ty::{
19+
self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor,
20+
};
1821
use rustc_span::{Ident, Span, kw};
1922
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2023
use rustc_trait_selection::error_reporting::infer::nice_region_error::{
@@ -183,6 +186,17 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
183186
}
184187
}
185188

189+
/// Map the regions in the type to named regions, where possible.
190+
fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
191+
where
192+
T: TypeFoldable<TyCtxt<'tcx>>,
193+
{
194+
fold_regions(tcx, ty, |region, _| match *region {
195+
ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region),
196+
_ => region,
197+
})
198+
}
199+
186200
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
187201
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
188202
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
@@ -314,7 +328,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
314328
let type_test_span = type_test.span;
315329

316330
if let Some(lower_bound_region) = lower_bound_region {
317-
let generic_ty = self.regioncx.name_regions(
331+
let generic_ty = self.name_regions(
318332
self.infcx.tcx,
319333
type_test.generic_kind.to_ty(self.infcx.tcx),
320334
);
@@ -323,7 +337,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
323337
self.body.source.def_id().expect_local(),
324338
type_test_span,
325339
Some(origin),
326-
self.regioncx.name_regions(self.infcx.tcx, type_test.generic_kind),
340+
self.name_regions(self.infcx.tcx, type_test.generic_kind),
327341
lower_bound_region,
328342
));
329343
} else {
@@ -354,9 +368,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
354368
}
355369

356370
RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, key, member_region } => {
357-
let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
358-
let named_key = self.regioncx.name_regions(self.infcx.tcx, key);
359-
let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
371+
let named_ty =
372+
self.regioncx.name_regions_for_member_constraint(self.infcx.tcx, hidden_ty);
373+
let named_key =
374+
self.regioncx.name_regions_for_member_constraint(self.infcx.tcx, key);
375+
let named_region = self
376+
.regioncx
377+
.name_regions_for_member_constraint(self.infcx.tcx, member_region);
360378
let diag = unexpected_hidden_region_diagnostic(
361379
self.infcx,
362380
self.mir_def_id(),

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
204204
/// that the regions produced are in fact equal to the named region they are
205205
/// replaced with. This is fine because this function is only to improve the
206206
/// region names in error messages.
207-
pub(crate) fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
207+
///
208+
/// This differs from `MirBorrowckCtxt::name_regions` since it is particularly
209+
/// lax with mapping region vids that are *shorter* than a universal region to
210+
/// that universal region. This is useful for member region constraints since
211+
/// we want to suggest a universal region name to capture even if it's technically
212+
/// not equal to the error region.
213+
pub(crate) fn name_regions_for_member_constraint<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> T
208214
where
209215
T: TypeFoldable<TyCtxt<'tcx>>,
210216
{

compiler/rustc_hir_typeck/src/pat.rs

+18-16
Original file line numberDiff line numberDiff line change
@@ -2806,31 +2806,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28062806
&& !self.tcx.features().ref_pat_eat_one_layer_2024_structural(),
28072807
});
28082808

2809+
let pat_kind = if let PatKind::Binding(user_bind_annot, _, _, _) = subpat.kind {
2810+
info.bad_modifiers = true;
2811+
// If the user-provided binding modifier doesn't match the default binding mode, we'll
2812+
// need to suggest reference patterns, which can affect other bindings.
2813+
// For simplicity, we opt to suggest making the pattern fully explicit.
2814+
info.suggest_eliding_modes &=
2815+
user_bind_annot == BindingMode(ByRef::Yes(def_br_mutbl), Mutability::Not);
2816+
"binding modifier"
2817+
} else {
2818+
info.bad_ref_pats = true;
2819+
// For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
2820+
// suggest adding them instead, which can affect the types assigned to bindings.
2821+
// As such, we opt to suggest making the pattern fully explicit.
2822+
info.suggest_eliding_modes = false;
2823+
"reference pattern"
2824+
};
28092825
// Only provide a detailed label if the problematic subpattern isn't from an expansion.
28102826
// In the case that it's from a macro, we'll add a more detailed note in the emitter.
28112827
let from_expansion = subpat.span.from_expansion();
28122828
let primary_label = if from_expansion {
2829+
// We can't suggest eliding modifiers within expansions.
2830+
info.suggest_eliding_modes = false;
28132831
// NB: This wording assumes the only expansions that can produce problematic reference
28142832
// patterns and bindings are macros. If a desugaring or AST pass is added that can do
28152833
// so, we may want to inspect the span's source callee or macro backtrace.
28162834
"occurs within macro expansion".to_owned()
28172835
} else {
2818-
let pat_kind = if let PatKind::Binding(user_bind_annot, _, _, _) = subpat.kind {
2819-
info.bad_modifiers |= true;
2820-
// If the user-provided binding modifier doesn't match the default binding mode, we'll
2821-
// need to suggest reference patterns, which can affect other bindings.
2822-
// For simplicity, we opt to suggest making the pattern fully explicit.
2823-
info.suggest_eliding_modes &=
2824-
user_bind_annot == BindingMode(ByRef::Yes(def_br_mutbl), Mutability::Not);
2825-
"binding modifier"
2826-
} else {
2827-
info.bad_ref_pats |= true;
2828-
// For simplicity, we don't try to suggest eliding reference patterns. Thus, we'll
2829-
// suggest adding them instead, which can affect the types assigned to bindings.
2830-
// As such, we opt to suggest making the pattern fully explicit.
2831-
info.suggest_eliding_modes = false;
2832-
"reference pattern"
2833-
};
28342836
let dbm_str = match def_br_mutbl {
28352837
Mutability::Not => "ref",
28362838
Mutability::Mut => "ref mut",

compiler/rustc_middle/src/mir/tcx.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ impl<'tcx> PlaceTy<'tcx> {
8686
}
8787
}
8888

89+
pub fn multi_projection_ty(
90+
self,
91+
tcx: TyCtxt<'tcx>,
92+
elems: &[PlaceElem<'tcx>],
93+
) -> PlaceTy<'tcx> {
94+
elems.iter().fold(self, |place_ty, &elem| place_ty.projection_ty(tcx, elem))
95+
}
96+
8997
/// Convenience wrapper around `projection_ty_core` for
9098
/// `PlaceElem`, where we can just use the `Ty` that is already
9199
/// stored inline on field projection elems.
@@ -167,11 +175,7 @@ impl<'tcx> Place<'tcx> {
167175
where
168176
D: HasLocalDecls<'tcx>,
169177
{
170-
projection
171-
.iter()
172-
.fold(PlaceTy::from_ty(local_decls.local_decls()[local].ty), |place_ty, &elem| {
173-
place_ty.projection_ty(tcx, elem)
174-
})
178+
PlaceTy::from_ty(local_decls.local_decls()[local].ty).multi_projection_ty(tcx, projection)
175179
}
176180

177181
pub fn ty<D: ?Sized>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> PlaceTy<'tcx>

compiler/rustc_mir_transform/src/elaborate_drop.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub(crate) trait DropElaborator<'a, 'tcx>: fmt::Debug {
8989

9090
// Accessors
9191

92+
fn patch_ref(&self) -> &MirPatch<'tcx>;
9293
fn patch(&mut self) -> &mut MirPatch<'tcx>;
9394
fn body(&self) -> &'a Body<'tcx>;
9495
fn tcx(&self) -> TyCtxt<'tcx>;
@@ -180,7 +181,14 @@ where
180181
{
181182
#[instrument(level = "trace", skip(self), ret)]
182183
fn place_ty(&self, place: Place<'tcx>) -> Ty<'tcx> {
183-
place.ty(self.elaborator.body(), self.tcx()).ty
184+
if place.local < self.elaborator.body().local_decls.next_index() {
185+
place.ty(self.elaborator.body(), self.tcx()).ty
186+
} else {
187+
// We don't have a slice with all the locals, since some are in the patch.
188+
tcx::PlaceTy::from_ty(self.elaborator.patch_ref().local_ty(place.local))
189+
.multi_projection_ty(self.elaborator.tcx(), place.projection)
190+
.ty
191+
}
184192
}
185193

186194
fn tcx(&self) -> TyCtxt<'tcx> {
@@ -410,12 +418,26 @@ where
410418

411419
let unique_place = self.tcx().mk_place_field(self.place, FieldIdx::ZERO, unique_ty);
412420
let nonnull_place = self.tcx().mk_place_field(unique_place, FieldIdx::ZERO, nonnull_ty);
413-
let ptr_place = self.tcx().mk_place_field(nonnull_place, FieldIdx::ZERO, ptr_ty);
414-
let interior = self.tcx().mk_place_deref(ptr_place);
415421

422+
let ptr_local = self.new_temp(ptr_ty);
423+
424+
let interior = self.tcx().mk_place_deref(Place::from(ptr_local));
416425
let interior_path = self.elaborator.deref_subpath(self.path);
417426

418-
self.drop_subpath(interior, interior_path, succ, unwind)
427+
let do_drop_bb = self.drop_subpath(interior, interior_path, succ, unwind);
428+
429+
let setup_bbd = BasicBlockData {
430+
statements: vec![self.assign(
431+
Place::from(ptr_local),
432+
Rvalue::Cast(CastKind::Transmute, Operand::Copy(nonnull_place), ptr_ty),
433+
)],
434+
terminator: Some(Terminator {
435+
kind: TerminatorKind::Goto { target: do_drop_bb },
436+
source_info: self.source_info,
437+
}),
438+
is_cleanup: unwind.is_cleanup(),
439+
};
440+
self.elaborator.patch().new_block(setup_bbd)
419441
}
420442

421443
#[instrument(level = "debug", ret)]

compiler/rustc_mir_transform/src/elaborate_drops.rs

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ impl InitializationData<'_, '_> {
138138
impl<'a, 'tcx> DropElaborator<'a, 'tcx> for ElaborateDropsCtxt<'a, 'tcx> {
139139
type Path = MovePathIndex;
140140

141+
fn patch_ref(&self) -> &MirPatch<'tcx> {
142+
&self.patch
143+
}
144+
141145
fn patch(&mut self) -> &mut MirPatch<'tcx> {
142146
&mut self.patch
143147
}

compiler/rustc_mir_transform/src/patch.rs

+8
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ impl<'tcx> MirPatch<'tcx> {
166166
Local::new(index)
167167
}
168168

169+
/// Returns the type of a local that's newly-added in the patch.
170+
pub(crate) fn local_ty(&self, local: Local) -> Ty<'tcx> {
171+
let local = local.as_usize();
172+
assert!(local < self.next_local);
173+
let new_local_idx = self.new_locals.len() - (self.next_local - local);
174+
self.new_locals[new_local_idx].ty
175+
}
176+
169177
pub(crate) fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
170178
let block = BasicBlock::new(self.patch_map.len());
171179
debug!("MirPatch: new_block: {:?}: {:?}", block, data);

compiler/rustc_mir_transform/src/shim.rs

+3
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ impl fmt::Debug for DropShimElaborator<'_, '_> {
350350
impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> {
351351
type Path = ();
352352

353+
fn patch_ref(&self) -> &MirPatch<'tcx> {
354+
&self.patch
355+
}
353356
fn patch(&mut self) -> &mut MirPatch<'tcx> {
354357
&mut self.patch
355358
}

compiler/rustc_resolve/src/rustdoc.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use pulldown_cmark::{
77
use rustc_ast as ast;
88
use rustc_ast::attr::AttributeExt;
99
use rustc_ast::util::comments::beautify_doc_string;
10-
use rustc_data_structures::fx::FxIndexMap;
10+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1111
use rustc_middle::ty::TyCtxt;
1212
use rustc_span::def_id::DefId;
1313
use rustc_span::{DUMMY_SP, InnerSpan, Span, Symbol, kw, sym};
@@ -422,9 +422,11 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
422422
);
423423
let mut links = Vec::new();
424424

425+
let mut refids = FxHashSet::default();
426+
425427
while let Some(event) = event_iter.next() {
426428
match event {
427-
Event::Start(Tag::Link { link_type, dest_url, title: _, id: _ })
429+
Event::Start(Tag::Link { link_type, dest_url, title: _, id })
428430
if may_be_doc_link(link_type) =>
429431
{
430432
if matches!(
@@ -439,13 +441,25 @@ fn parse_links<'md>(doc: &'md str) -> Vec<Box<str>> {
439441
links.push(display_text);
440442
}
441443
}
444+
if matches!(
445+
link_type,
446+
LinkType::Reference | LinkType::Shortcut | LinkType::Collapsed
447+
) {
448+
refids.insert(id);
449+
}
442450

443451
links.push(preprocess_link(&dest_url));
444452
}
445453
_ => {}
446454
}
447455
}
448456

457+
for (label, refdef) in event_iter.reference_definitions().iter() {
458+
if !refids.contains(label) {
459+
links.push(preprocess_link(&refdef.dest));
460+
}
461+
}
462+
449463
links
450464
}
451465

compiler/rustc_session/src/config/cfg.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
2929
use rustc_lint_defs::BuiltinLintDiag;
3030
use rustc_lint_defs::builtin::EXPLICIT_BUILTIN_CFGS_IN_FLAGS;
3131
use rustc_span::{Symbol, sym};
32-
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, TARGETS, Target, TargetTuple};
32+
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, Target};
3333

3434
use crate::Session;
3535
use crate::config::{CrateType, FmtDebug};
@@ -432,11 +432,7 @@ impl CheckCfg {
432432
panic!("unable to get all the check-cfg values buckets");
433433
};
434434

435-
for target in TARGETS
436-
.iter()
437-
.map(|target| Target::expect_builtin(&TargetTuple::from_tuple(target)))
438-
.chain(iter::once(current_target.clone()))
439-
{
435+
for target in Target::builtins().chain(iter::once(current_target.clone())) {
440436
values_target_abi.insert(Symbol::intern(&target.options.abi));
441437
values_target_arch.insert(Symbol::intern(&target.arch));
442438
values_target_endian.insert(Symbol::intern(target.options.endian.as_str()));

compiler/rustc_target/src/spec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,14 @@ macro_rules! supported_targets {
16581658
Some(t)
16591659
}
16601660

1661+
fn load_all_builtins() -> impl Iterator<Item = Target> {
1662+
[
1663+
$( targets::$module::target, )+
1664+
]
1665+
.into_iter()
1666+
.map(|f| f())
1667+
}
1668+
16611669
#[cfg(test)]
16621670
mod tests {
16631671
// Cannot put this into a separate file without duplication, make an exception.
@@ -3360,6 +3368,11 @@ impl Target {
33603368
}
33613369
}
33623370

3371+
/// Load all built-in targets
3372+
pub fn builtins() -> impl Iterator<Item = Target> {
3373+
load_all_builtins()
3374+
}
3375+
33633376
/// Search for a JSON file specifying the given target tuple.
33643377
///
33653378
/// If none is found in `$RUST_TARGET_PATH`, look for a file called `target.json` inside the

library/alloc/src/boxed.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,6 @@ impl<T: ?Sized> Box<T> {
10531053
/// ```
10541054
///
10551055
/// [memory layout]: self#memory-layout
1056-
/// [`Layout`]: crate::Layout
10571056
#[stable(feature = "box_raw", since = "1.4.0")]
10581057
#[inline]
10591058
#[must_use = "call `drop(Box::from_raw(ptr))` if you intend to drop the `Box`"]
@@ -1108,7 +1107,6 @@ impl<T: ?Sized> Box<T> {
11081107
/// ```
11091108
///
11101109
/// [memory layout]: self#memory-layout
1111-
/// [`Layout`]: crate::Layout
11121110
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
11131111
#[inline]
11141112
#[must_use = "call `drop(Box::from_non_null(ptr))` if you intend to drop the `Box`"]
@@ -1165,7 +1163,6 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11651163
/// ```
11661164
///
11671165
/// [memory layout]: self#memory-layout
1168-
/// [`Layout`]: crate::Layout
11691166
#[unstable(feature = "allocator_api", issue = "32838")]
11701167
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
11711168
#[inline]
@@ -1219,7 +1216,6 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12191216
/// ```
12201217
///
12211218
/// [memory layout]: self#memory-layout
1222-
/// [`Layout`]: crate::Layout
12231219
#[unstable(feature = "allocator_api", issue = "32838")]
12241220
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
12251221
#[rustc_const_unstable(feature = "const_box", issue = "92521")]

library/core/src/alloc/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use crate::{cmp, ptr};
7070
/// {
7171
/// return null_mut();
7272
/// };
73-
/// self.arena.get().cast::<u8>().add(allocated)
73+
/// unsafe { self.arena.get().cast::<u8>().add(allocated) }
7474
/// }
7575
/// unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
7676
/// }

0 commit comments

Comments
 (0)