Skip to content

Commit 00df16e

Browse files
committed
Auto merge of #157149 - JonathanBrouwer:rollup-JIG4HGr, r=<try>
Rollup of 12 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents 6eda741 + cf39dc6 commit 00df16e

101 files changed

Lines changed: 3003 additions & 2017 deletions

File tree

Some content is hidden

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

compiler/rustc_abi/src/layout.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::BTreeSet;
22
use std::fmt::{self, Write};
33
use std::ops::Deref;
4+
use std::range::RangeInclusive;
45
use std::{cmp, iter};
56

67
use rustc_hashes::Hash64;
@@ -631,11 +632,13 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
631632
let all_indices = variants.indices();
632633
let needs_disc =
633634
|index: VariantIdx| index != largest_variant_index && !absent(&variants[index]);
634-
let niche_variants = all_indices.clone().find(|v| needs_disc(*v)).unwrap()
635-
..=all_indices.rev().find(|v| needs_disc(*v)).unwrap();
635+
let niche_variants = RangeInclusive {
636+
start: all_indices.clone().find(|v| needs_disc(*v)).unwrap(),
637+
last: all_indices.rev().find(|v| needs_disc(*v)).unwrap(),
638+
};
636639

637640
let count =
638-
(niche_variants.end().index() as u128 - niche_variants.start().index() as u128) + 1;
641+
(niche_variants.last.index() as u128 - niche_variants.start.index() as u128) + 1;
639642

640643
// Use the largest niche in the largest variant.
641644
let niche = variant_layouts[largest_variant_index].largest_niche?;

compiler/rustc_abi/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ use std::fmt;
4040
#[cfg(feature = "nightly")]
4141
use std::iter::Step;
4242
use std::num::{NonZeroUsize, ParseIntError};
43-
use std::ops::{Add, AddAssign, Deref, Mul, RangeFull, RangeInclusive, Sub};
43+
use std::ops::{Add, AddAssign, Deref, Mul, RangeFull, Sub};
44+
use std::range::RangeInclusive;
4445
use std::str::FromStr;
4546

4647
use bitflags::bitflags;
@@ -1958,7 +1959,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
19581959
}
19591960

19601961
// NOTE: This struct is generic over the VariantIdx for rust-analyzer usage.
1961-
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1962+
#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
19621963
#[cfg_attr(feature = "nightly", derive(StableHash))]
19631964
pub enum TagEncoding<VariantIdx: Idx> {
19641965
/// The tag directly stores the discriminant, but possibly with a smaller layout

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15491549
fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
15501550
let target_id = match destination {
15511551
Some((id, _)) => {
1552-
if let Some(loop_id) = self.resolver.get_label_res(id) {
1552+
if let Some(loop_id) = self.owner.get_label_res(id) {
15531553
let local_id = self.ident_and_label_to_local_id[&loop_id];
15541554
let loop_hir_id = HirId { owner: self.current_hir_id_owner, local_id };
15551555
Ok(loop_hir_id)

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
293293
self.import_res_map.get(&id).copied().unwrap_or_default()
294294
}
295295

296-
/// Obtains resolution for a label with the given `NodeId`.
297-
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
298-
self.label_res_map.get(&id).copied()
299-
}
300-
301-
/// Obtains resolution for a lifetime with the given `NodeId`.
302-
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes> {
303-
self.lifetimes_res_map.get(&id).copied()
304-
}
305-
306296
/// Obtain the list of lifetimes parameters to add to an item.
307297
///
308298
/// Extra lifetime parameters should only be added in places that can appear
@@ -321,10 +311,6 @@ impl<'tcx> ResolverAstLowering<'tcx> {
321311
fn owner_def_id(&self, id: NodeId) -> LocalDefId {
322312
self.owners[&id].def_id
323313
}
324-
325-
fn lifetime_elision_allowed(&self, id: NodeId) -> bool {
326-
self.lifetime_elision_allowed.contains(&id)
327-
}
328314
}
329315

330316
/// How relaxed bounds `?Trait` should be treated.
@@ -1612,7 +1598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16121598

16131599
None => {
16141600
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
1615-
self.resolver.get_lifetime_res(t.id)
1601+
self.owner.get_lifetime_res(t.id)
16161602
{
16171603
assert_eq!(start.plus(1), end);
16181604
start
@@ -1853,7 +1839,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
18531839
_ => hir::ImplicitSelfKind::None,
18541840
}
18551841
}))
1856-
.set_lifetime_elision_allowed(self.resolver.lifetime_elision_allowed(fn_node_id))
1842+
.set_lifetime_elision_allowed(
1843+
self.owner.id == fn_node_id && self.owner.lifetime_elision_allowed,
1844+
)
18571845
.set_c_variadic(c_variadic);
18581846

18591847
self.arena.alloc(hir::FnDecl { inputs, output, fn_decl_kind })
@@ -2019,7 +2007,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20192007
source: LifetimeSource,
20202008
syntax: LifetimeSyntax,
20212009
) -> &'hir hir::Lifetime {
2022-
let res = if let Some(res) = self.resolver.get_lifetime_res(id) {
2010+
let res = if let Some(res) = self.owner.get_lifetime_res(id) {
20232011
match res {
20242012
LifetimeRes::Param { param, .. } => hir::LifetimeKind::Param(param),
20252013
LifetimeRes::Fresh { param, .. } => {
@@ -2105,13 +2093,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
21052093
// AST resolution emitted an error on those parameters, so we lower them using
21062094
// `ParamName::Error`.
21072095
let ident = self.lower_ident(param.ident);
2108-
let param_name = if let Some(LifetimeRes::Error(..)) =
2109-
self.resolver.get_lifetime_res(param.id)
2110-
{
2111-
ParamName::Error(ident)
2112-
} else {
2113-
ParamName::Plain(ident)
2114-
};
2096+
let param_name =
2097+
if let Some(LifetimeRes::Error(..)) = self.owner.get_lifetime_res(param.id) {
2098+
ParamName::Error(ident)
2099+
} else {
2100+
ParamName::Plain(ident)
2101+
};
21152102
let kind =
21162103
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
21172104

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use super::errors::{
1717
};
1818
use super::{
1919
AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, ImplTraitPosition,
20-
LifetimeRes, LoweringContext, ParamMode, ResolverAstLoweringExt,
20+
LifetimeRes, LoweringContext, ParamMode,
2121
};
2222

2323
impl<'hir> LoweringContext<'_, 'hir> {
@@ -422,7 +422,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
422422
segment_ident_span: Span,
423423
generic_args: &mut GenericArgsCtor<'hir>,
424424
) {
425-
let (start, end) = match self.resolver.get_lifetime_res(segment_id) {
425+
let (start, end) = match self.owner.get_lifetime_res(segment_id) {
426426
Some(LifetimeRes::ElidedAnchor { start, end }) => (start, end),
427427
None => return,
428428
Some(res) => {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,63 +4023,60 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
40234023
&& decl.can_be_made_mutable()
40244024
{
40254025
let mut is_for_loop = false;
4026-
let mut is_ref_pattern = false;
4026+
let mut is_immut_ref_pattern = false;
40274027
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
40284028
opt_match_place: Some((_, match_span)),
40294029
..
40304030
})) = *decl.local_info()
40314031
{
40324032
if matches!(match_span.desugaring_kind(), Some(DesugaringKind::ForLoop)) {
40334033
is_for_loop = true;
4034+
}
40344035

4035-
if let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
4036-
struct RefPatternFinder<'tcx> {
4037-
tcx: TyCtxt<'tcx>,
4038-
binding_span: Span,
4039-
is_ref_pattern: bool,
4040-
}
4036+
if let Some(body) = self.infcx.tcx.hir_maybe_body_owned_by(self.mir_def_id()) {
4037+
struct RefPatternFinder<'tcx> {
4038+
tcx: TyCtxt<'tcx>,
4039+
binding_span: Span,
4040+
is_immut_ref_pattern: bool,
4041+
}
40414042

4042-
impl<'tcx> Visitor<'tcx> for RefPatternFinder<'tcx> {
4043-
type NestedFilter = OnlyBodies;
4043+
impl<'tcx> Visitor<'tcx> for RefPatternFinder<'tcx> {
4044+
type NestedFilter = OnlyBodies;
40444045

4045-
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
4046-
self.tcx
4047-
}
4046+
fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
4047+
self.tcx
4048+
}
40484049

4049-
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
4050-
if !self.is_ref_pattern
4051-
&& let hir::PatKind::Binding(_, _, ident, _) = pat.kind
4052-
&& ident.span == self.binding_span
4053-
{
4054-
self.is_ref_pattern =
4055-
self.tcx.hir_parent_iter(pat.hir_id).any(|(_, node)| {
4056-
matches!(
4057-
node,
4058-
hir::Node::Pat(hir::Pat {
4059-
kind: hir::PatKind::Ref(..),
4060-
..
4061-
})
4062-
)
4063-
});
4064-
}
4065-
hir::intravisit::walk_pat(self, pat);
4050+
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
4051+
if !self.is_immut_ref_pattern
4052+
&& let hir::PatKind::Binding(_, _, ident, _) = pat.kind
4053+
&& ident.span == self.binding_span
4054+
&& matches!(
4055+
self.tcx.parent_hir_node(pat.hir_id),
4056+
hir::Node::Pat(hir::Pat {
4057+
kind: hir::PatKind::Ref(_, _, hir::Mutability::Not),
4058+
..
4059+
})
4060+
)
4061+
{
4062+
self.is_immut_ref_pattern = true;
40664063
}
4064+
hir::intravisit::walk_pat(self, pat);
40674065
}
4066+
}
40684067

4069-
let mut finder = RefPatternFinder {
4070-
tcx: self.infcx.tcx,
4071-
binding_span: decl.source_info.span,
4072-
is_ref_pattern: false,
4073-
};
4068+
let mut finder = RefPatternFinder {
4069+
tcx: self.infcx.tcx,
4070+
binding_span: decl.source_info.span,
4071+
is_immut_ref_pattern: false,
4072+
};
40744073

4075-
finder.visit_body(body);
4076-
is_ref_pattern = finder.is_ref_pattern;
4077-
}
4074+
finder.visit_body(body);
4075+
is_immut_ref_pattern = finder.is_immut_ref_pattern;
40784076
}
40794077
}
40804078

4081-
let (span, message) = if is_for_loop
4082-
&& is_ref_pattern
4079+
let (span, message) = if is_immut_ref_pattern
40834080
&& let Ok(binding_name) =
40844081
self.infcx.tcx.sess.source_map().span_to_snippet(decl.source_info.span)
40854082
{

compiler/rustc_codegen_cranelift/src/discriminant.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
5555
if variant_index != untagged_variant {
5656
let niche = place.place_field(fx, tag_field);
5757
let niche_type = fx.clif_type(niche.layout().ty).unwrap();
58-
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
58+
let niche_value = variant_index.as_u32() - niche_variants.start.as_u32();
5959
let niche_value = (niche_value as u128).wrapping_add(niche_start);
6060
let niche_value = match niche_type {
6161
types::I128 => {
@@ -133,7 +133,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
133133
dest.write_cvalue(fx, res);
134134
}
135135
TagEncoding::Niche { untagged_variant, ref niche_variants, niche_start } => {
136-
let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32();
136+
let relative_max = niche_variants.last.as_u32() - niche_variants.start.as_u32();
137137

138138
// We have a subrange `niche_start..=niche_end` inside `range`.
139139
// If the value of the tag is inside this subrange, it's a
@@ -162,7 +162,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
162162
// }
163163
let is_niche = codegen_icmp_imm(fx, IntCC::Equal, tag, niche_start as i128);
164164
let tagged_discr =
165-
fx.bcx.ins().iconst(cast_to, niche_variants.start().as_u32() as i64);
165+
fx.bcx.ins().iconst(cast_to, niche_variants.start.as_u32() as i64);
166166
(is_niche, tagged_discr, 0)
167167
} else {
168168
// The special cases don't apply, so we'll have to go with
@@ -184,7 +184,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
184184
relative_discr,
185185
i128::from(relative_max),
186186
);
187-
(is_niche, cast_tag, niche_variants.start().as_u32() as u128)
187+
(is_niche, cast_tag, niche_variants.start.as_u32() as u128)
188188
};
189189

190190
let tagged_discr = if delta == 0 {

0 commit comments

Comments
 (0)