Skip to content

Commit e12f911

Browse files
authored
Merge pull request #4336 from rust-lang/rustup-2025-05-21
Automatic Rustup
2 parents 49482ca + b5688fb commit e12f911

File tree

247 files changed

+4142
-2091
lines changed

Some content is hidden

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

247 files changed

+4142
-2091
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,32 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
7070
}
7171
}
7272

73-
pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> {
73+
pub(super) fn lower_node(&mut self, def_id: LocalDefId) {
7474
let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom);
7575
if let hir::MaybeOwner::Phantom = owner {
7676
let node = self.ast_index[def_id];
7777
match node {
7878
AstOwner::NonOwner => {}
79-
AstOwner::Crate(c) => self.lower_crate(c),
80-
AstOwner::Item(item) => self.lower_item(item),
81-
AstOwner::AssocItem(item, ctxt) => self.lower_assoc_item(item, ctxt),
82-
AstOwner::ForeignItem(item) => self.lower_foreign_item(item),
79+
AstOwner::Crate(c) => {
80+
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
81+
self.with_lctx(CRATE_NODE_ID, |lctx| {
82+
let module = lctx.lower_mod(&c.items, &c.spans);
83+
// FIXME(jdonszelman): is dummy span ever a problem here?
84+
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP);
85+
hir::OwnerNode::Crate(module)
86+
})
87+
}
88+
AstOwner::Item(item) => {
89+
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
90+
}
91+
AstOwner::AssocItem(item, ctxt) => {
92+
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt))
93+
}
94+
AstOwner::ForeignItem(item) => self.with_lctx(item.id, |lctx| {
95+
hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))
96+
}),
8397
}
8498
}
85-
86-
self.owners[def_id]
87-
}
88-
89-
#[instrument(level = "debug", skip(self, c))]
90-
fn lower_crate(&mut self, c: &Crate) {
91-
debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID);
92-
self.with_lctx(CRATE_NODE_ID, |lctx| {
93-
let module = lctx.lower_mod(&c.items, &c.spans);
94-
// FIXME(jdonszelman): is dummy span ever a problem here?
95-
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP);
96-
hir::OwnerNode::Crate(module)
97-
})
98-
}
99-
100-
#[instrument(level = "debug", skip(self))]
101-
fn lower_item(&mut self, item: &Item) {
102-
self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item)))
103-
}
104-
105-
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
106-
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt))
107-
}
108-
109-
fn lower_foreign_item(&mut self, item: &ForeignItem) {
110-
self.with_lctx(item.id, |lctx| hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item)))
11199
}
112100
}
113101

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,14 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> {
444444
tcx.definitions_untracked().def_index_count(),
445445
);
446446

447+
let mut lowerer = item::ItemLowerer {
448+
tcx,
449+
resolver: &mut resolver,
450+
ast_index: &ast_index,
451+
owners: &mut owners,
452+
};
447453
for def_id in ast_index.indices() {
448-
item::ItemLowerer {
449-
tcx,
450-
resolver: &mut resolver,
451-
ast_index: &ast_index,
452-
owners: &mut owners,
453-
}
454-
.lower_node(def_id);
454+
lowerer.lower_node(def_id);
455455
}
456456

457457
drop(ast_index);

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ pub trait Machine<'tcx>: Sized {
147147
/// already been checked before.
148148
const ALL_CONSTS_ARE_PRECHECKED: bool = true;
149149

150+
/// Determines whether rustc_const_eval functions that make use of the [Machine] should make
151+
/// tracing calls (to the `tracing` library). By default this is `false`, meaning the tracing
152+
/// calls will supposedly be optimized out. This flag is set to `true` inside Miri, to allow
153+
/// tracing the interpretation steps, among other things.
154+
const TRACING_ENABLED: bool = false;
155+
150156
/// Whether memory accesses should be alignment-checked.
151157
fn enforce_alignment(ecx: &InterpCx<'tcx, Self>) -> bool;
152158

compiler/rustc_const_eval/src/interpret/util.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,22 @@ pub(crate) fn create_static_alloc<'tcx>(
4545
assert!(ecx.memory.alloc_map.insert(alloc_id, (MemoryKind::Stack, alloc)).is_none());
4646
interp_ok(ecx.ptr_to_mplace(Pointer::from(alloc_id).into(), layout))
4747
}
48+
49+
/// This struct is needed to enforce `#[must_use]` on [tracing::span::EnteredSpan]
50+
/// while wrapping them in an `Option`.
51+
#[must_use]
52+
pub enum MaybeEnteredSpan {
53+
Some(tracing::span::EnteredSpan),
54+
None,
55+
}
56+
57+
#[macro_export]
58+
macro_rules! enter_trace_span {
59+
($machine:ident, $($tt:tt)*) => {
60+
if $machine::TRACING_ENABLED {
61+
$crate::interpret::tracing_utils::MaybeEnteredSpan::Some(tracing::info_span!($($tt)*).entered())
62+
} else {
63+
$crate::interpret::tracing_utils::MaybeEnteredSpan::None
64+
}
65+
}
66+
}

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8484

8585
self.annotate_expected_due_to_let_ty(err, expr, error);
8686
self.annotate_loop_expected_due_to_inference(err, expr, error);
87-
if self.annotate_mut_binding_to_immutable_binding(err, expr, error) {
87+
if self.annotate_mut_binding_to_immutable_binding(err, expr, expr_ty, expected, error) {
8888
return;
8989
}
9090

@@ -799,17 +799,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
799799
/// Detect the following case
800800
///
801801
/// ```text
802-
/// fn change_object(mut a: &Ty) {
802+
/// fn change_object(mut b: &Ty) {
803803
/// let a = Ty::new();
804804
/// b = a;
805805
/// }
806806
/// ```
807807
///
808-
/// where the user likely meant to modify the value behind there reference, use `a` as an out
808+
/// where the user likely meant to modify the value behind there reference, use `b` as an out
809809
/// parameter, instead of mutating the local binding. When encountering this we suggest:
810810
///
811811
/// ```text
812-
/// fn change_object(a: &'_ mut Ty) {
812+
/// fn change_object(b: &'_ mut Ty) {
813813
/// let a = Ty::new();
814814
/// *b = a;
815815
/// }
@@ -818,13 +818,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
818818
&self,
819819
err: &mut Diag<'_>,
820820
expr: &hir::Expr<'_>,
821+
expr_ty: Ty<'tcx>,
822+
expected: Ty<'tcx>,
821823
error: Option<TypeError<'tcx>>,
822824
) -> bool {
823-
if let Some(TypeError::Sorts(ExpectedFound { expected, found })) = error
825+
if let Some(TypeError::Sorts(ExpectedFound { .. })) = error
824826
&& let ty::Ref(_, inner, hir::Mutability::Not) = expected.kind()
825827

826828
// The difference between the expected and found values is one level of borrowing.
827-
&& self.can_eq(self.param_env, *inner, found)
829+
&& self.can_eq(self.param_env, *inner, expr_ty)
828830

829831
// We have an `ident = expr;` assignment.
830832
&& let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Assign(lhs, rhs, _), .. }) =

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
//! which creates a new `TypeckResults` which doesn't contain any inference variables.
1010
1111
use std::mem;
12+
use std::ops::ControlFlow;
1213

14+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1315
use rustc_data_structures::unord::ExtendUnord;
14-
use rustc_errors::ErrorGuaranteed;
16+
use rustc_errors::{E0720, ErrorGuaranteed};
17+
use rustc_hir::def_id::LocalDefId;
1518
use rustc_hir::intravisit::{self, InferKind, Visitor};
1619
use rustc_hir::{self as hir, AmbigArg, HirId};
1720
use rustc_infer::traits::solve::Goal;
1821
use rustc_middle::traits::ObligationCause;
1922
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
2023
use rustc_middle::ty::{
21-
self, DefiningScopeKind, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
22-
TypeVisitableExt, fold_regions,
24+
self, DefiningScopeKind, OpaqueHiddenType, Ty, TyCtxt, TypeFoldable, TypeFolder,
25+
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
26+
fold_regions,
2327
};
2428
use rustc_span::{Span, sym};
2529
use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
@@ -595,6 +599,35 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
595599
entry.span = prev.span.substitute_dummy(hidden_type.span);
596600
}
597601
}
602+
603+
let recursive_opaques: Vec<_> = self
604+
.typeck_results
605+
.concrete_opaque_types
606+
.iter()
607+
.filter(|&(&def_id, hidden_ty)| {
608+
hidden_ty
609+
.ty
610+
.visit_with(&mut HasRecursiveOpaque {
611+
def_id,
612+
seen: Default::default(),
613+
opaques: &self.typeck_results.concrete_opaque_types,
614+
tcx,
615+
})
616+
.is_break()
617+
})
618+
.map(|(def_id, hidden_ty)| (*def_id, hidden_ty.span))
619+
.collect();
620+
for (def_id, span) in recursive_opaques {
621+
let guar = self
622+
.fcx
623+
.dcx()
624+
.struct_span_err(span, "cannot resolve opaque type")
625+
.with_code(E0720)
626+
.emit();
627+
self.typeck_results
628+
.concrete_opaque_types
629+
.insert(def_id, OpaqueHiddenType { span, ty: Ty::new_error(tcx, guar) });
630+
}
598631
}
599632

600633
fn visit_field_id(&mut self, hir_id: HirId) {
@@ -959,3 +992,34 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerlyNormalizeConsts<'tcx> {
959992
self.tcx.try_normalize_erasing_regions(self.typing_env, ct).unwrap_or(ct)
960993
}
961994
}
995+
996+
struct HasRecursiveOpaque<'a, 'tcx> {
997+
def_id: LocalDefId,
998+
seen: FxHashSet<LocalDefId>,
999+
opaques: &'a FxIndexMap<LocalDefId, ty::OpaqueHiddenType<'tcx>>,
1000+
tcx: TyCtxt<'tcx>,
1001+
}
1002+
1003+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> {
1004+
type Result = ControlFlow<()>;
1005+
1006+
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1007+
if let ty::Alias(ty::Opaque, alias_ty) = *t.kind()
1008+
&& let Some(def_id) = alias_ty.def_id.as_local()
1009+
{
1010+
if self.def_id == def_id {
1011+
return ControlFlow::Break(());
1012+
}
1013+
1014+
if self.seen.insert(def_id)
1015+
&& let Some(hidden_ty) = self.opaques.get(&def_id)
1016+
{
1017+
ty::EarlyBinder::bind(hidden_ty.ty)
1018+
.instantiate(self.tcx, alias_ty.args)
1019+
.visit_with(self)?;
1020+
}
1021+
}
1022+
1023+
t.super_visit_with(self)
1024+
}
1025+
}

compiler/rustc_metadata/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ metadata_as_needed_compatibility =
22
linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds
33
44
metadata_async_drop_types_in_dependency =
5-
found async drop types in dependecy `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`
5+
found async drop types in dependency `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}`
66
.help = if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
77
88
metadata_bad_panic_strategy =

compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt;
22
use std::iter::once;
3-
use std::ops::ControlFlow;
43

54
use rustc_abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx};
65
use rustc_arena::DroplessArena;
@@ -12,8 +11,7 @@ use rustc_middle::mir::{self, Const};
1211
use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary};
1312
use rustc_middle::ty::layout::IntegerExt;
1413
use rustc_middle::ty::{
15-
self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
16-
TypeVisitableExt, TypeVisitor, VariantDef,
14+
self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeVisitableExt, VariantDef,
1715
};
1816
use rustc_middle::{bug, span_bug};
1917
use rustc_session::lint;
@@ -137,22 +135,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
137135
/// Returns the hidden type corresponding to this key if the body under analysis is allowed to
138136
/// know it.
139137
fn reveal_opaque_key(&self, key: OpaqueTypeKey<'tcx>) -> Option<Ty<'tcx>> {
140-
if let Some(hidden_ty) = self.typeck_results.concrete_opaque_types.get(&key.def_id) {
141-
let ty = ty::EarlyBinder::bind(hidden_ty.ty).instantiate(self.tcx, key.args);
142-
if ty.visit_with(&mut RecursiveOpaque { def_id: key.def_id.into() }).is_continue() {
143-
Some(ty)
144-
} else {
145-
// HACK: We skip revealing opaque types which recursively expand
146-
// to themselves. This is because we may infer hidden types like
147-
// `Opaque<T> = Opaque<Opaque<T>>` or `Opaque<T> = Opaque<(T,)>`
148-
// in hir typeck.
149-
None
150-
}
151-
} else {
152-
None
153-
}
138+
self.typeck_results
139+
.concrete_opaque_types
140+
.get(&key.def_id)
141+
.map(|x| ty::EarlyBinder::bind(x.ty).instantiate(self.tcx, key.args))
154142
}
155-
156143
// This can take a non-revealed `Ty` because it reveals opaques itself.
157144
pub fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
158145
!ty.inhabited_predicate(self.tcx).apply_revealing_opaque(
@@ -1177,20 +1164,3 @@ fn detect_mixed_deref_pat_ctors<'p, 'tcx>(
11771164
}
11781165
Ok(())
11791166
}
1180-
1181-
struct RecursiveOpaque {
1182-
def_id: DefId,
1183-
}
1184-
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for RecursiveOpaque {
1185-
type Result = ControlFlow<()>;
1186-
1187-
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
1188-
if let ty::Alias(ty::Opaque, alias_ty) = t.kind() {
1189-
if alias_ty.def_id == self.def_id {
1190-
return ControlFlow::Break(());
1191-
}
1192-
}
1193-
1194-
if t.has_opaque_types() { t.super_visit_with(self) } else { ControlFlow::Continue(()) }
1195-
}
1196-
}

compiler/rustc_type_ir/src/region_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<I: Interner> fmt::Debug for RegionKind<I> {
193193

194194
ReVar(vid) => write!(f, "{vid:?}"),
195195

196-
RePlaceholder(placeholder) => write!(f, "{placeholder:?}"),
196+
RePlaceholder(placeholder) => write!(f, "'{placeholder:?}"),
197197

198198
// Use `'{erased}` as the output instead of `'erased` so that its more obviously distinct from
199199
// a `ReEarlyParam` named `'erased`. Technically that would print as `'erased/#IDX` so this is

library/alloc/src/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl str {
234234
#[stable(feature = "str_box_extras", since = "1.20.0")]
235235
#[must_use = "`self` will be dropped if the result is not used"]
236236
#[inline]
237-
pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> {
237+
pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]> {
238238
self.into()
239239
}
240240

@@ -501,7 +501,7 @@ impl str {
501501
#[rustc_allow_incoherent_impl]
502502
#[must_use = "`self` will be dropped if the result is not used"]
503503
#[inline]
504-
pub fn into_string(self: Box<str>) -> String {
504+
pub fn into_string(self: Box<Self>) -> String {
505505
let slice = Box::<[u8]>::from(self);
506506
unsafe { String::from_utf8_unchecked(slice.into_vec()) }
507507
}

0 commit comments

Comments
 (0)