Skip to content

Rollup of 9 pull requests #140239

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

Merged
merged 24 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ac34a6f
Stabilize the `cell_update` feature
tgross35 Dec 17, 2024
fe03f76
std: Add performance warnings to HashMap::get_disjoint_mut
xizheyin Apr 3, 2025
35a20de
Implement `SmirInterface`
makai410 Apr 18, 2025
16381b3
Use `currently` for futher improvement
xizheyin Apr 20, 2025
08baec4
add a test for byte string literal pattern mutability mismatches
dianne Apr 22, 2025
6184025
make `str` literal patterns usable in deref patterns
dianne Mar 25, 2025
3250344
make `[u8]` and `[u8;N]` literal patterns usable in deref patterns
dianne Apr 16, 2025
4c7e866
update unstable book to mention string/bytestring typing
dianne Apr 19, 2025
19e44d4
Don't warn about `v128` in wasm ABI transition
alexcrichton Apr 14, 2025
51088fd
Remove `synstructure::Structure::underscore_const` calls.
nnethercote Apr 23, 2025
5b390cd
Make `SmirInterface` pub(crate) and rename `Context` to `SmirContext`
makai410 Apr 23, 2025
780f95d
Impl new API `std::os::unix::fs::mkfifo` under feature `unix_fifo`
NobodyXu Apr 6, 2025
2a5c349
Extend HIR to track the source and syntax of a lifetime
shepmaster Mar 28, 2025
055a27d
Remove some unnecessary clones.
nnethercote Apr 23, 2025
af80477
Refactor `StableMir` to avoid some clones.
nnethercote Apr 23, 2025
fdaa91a
Rollup merge of #134446 - tgross35:stabilize-cell_update, r=jhpratt
matthiaskrgr Apr 24, 2025
cb3c5d7
Rollup merge of #139307 - xizheyin:issue-139296, r=joboet
matthiaskrgr Apr 24, 2025
10732e1
Rollup merge of #139450 - NobodyXu:new-api/make-fifo, r=tgross35
matthiaskrgr Apr 24, 2025
32b2428
Rollup merge of #139809 - alexcrichton:wasm-simd-safe, r=RalfJung
matthiaskrgr Apr 24, 2025
2a07f99
Rollup merge of #139852 - makai410:smir-refactor, r=celinval
matthiaskrgr Apr 24, 2025
2ba3a5c
Rollup merge of #139945 - shepmaster:hir-lifetime-syntax-source, r=nn…
matthiaskrgr Apr 24, 2025
5d52b37
Rollup merge of #140028 - dianne:lit-deref-pats-p1, r=oli-obk
matthiaskrgr Apr 24, 2025
1254559
Rollup merge of #140181 - nnethercote:rm-underscore_const, r=compiler…
matthiaskrgr Apr 24, 2025
986750d
Rollup merge of #140232 - nnethercote:rm-unnecessary-clones, r=Sparro…
matthiaskrgr Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_ast::*;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
use rustc_hir::{self as hir, HirId, IsAnonInPath, PredicateOrigin};
use rustc_hir::{self as hir, HirId, LifetimeSource, PredicateOrigin};
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_span::edit_distance::find_best_match_for_name;
Expand Down Expand Up @@ -1868,7 +1868,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
GenericParamKind::Lifetime => {
let lt_id = self.next_node_id();
let lifetime = self.new_named_lifetime(id, lt_id, ident, IsAnonInPath::No);
let lifetime =
self.new_named_lifetime(id, lt_id, ident, LifetimeSource::Other, ident.into());
hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
lifetime,
bounds,
Expand Down Expand Up @@ -1901,7 +1902,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
}),
WherePredicateKind::RegionPredicate(WhereRegionPredicate { lifetime, bounds }) => {
hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
lifetime: self.lower_lifetime(lifetime),
lifetime: self.lower_lifetime(
lifetime,
LifetimeSource::Other,
lifetime.ident.into(),
),
bounds: self.lower_param_bounds(
bounds,
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
Expand Down
121 changes: 73 additions & 48 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
use rustc_hir::{
self as hir, ConstArg, GenericArg, HirId, IsAnonInPath, ItemLocalMap, LangItem, ParamName,
TraitCandidate,
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem, LifetimeSource,
LifetimeSyntax, ParamName, TraitCandidate,
};
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::extension;
Expand Down Expand Up @@ -1079,7 +1079,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx: ImplTraitContext,
) -> hir::GenericArg<'hir> {
match arg {
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(lt)),
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
lt,
LifetimeSource::Path { with_angle_brackets: true },
lt.ident.into(),
)),
ast::GenericArg::Type(ty) => {
// We cannot just match on `TyKind::Infer` as `(_)` is represented as
// `TyKind::Paren(TyKind::Infer)` and should also be lowered to `GenericArg::Infer`
Expand Down Expand Up @@ -1198,35 +1202,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
TyKind::Slice(ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
TyKind::Ptr(mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
TyKind::Ref(region, mt) => {
let region = region.unwrap_or_else(|| {
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
self.resolver.get_lifetime_res(t.id)
{
debug_assert_eq!(start.plus(1), end);
start
} else {
self.next_node_id()
};
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
});
let lifetime = self.lower_lifetime(&region);
let lifetime = self.lower_ty_direct_lifetime(t, *region);
hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx))
}
TyKind::PinnedRef(region, mt) => {
let region = region.unwrap_or_else(|| {
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
self.resolver.get_lifetime_res(t.id)
{
debug_assert_eq!(start.plus(1), end);
start
} else {
self.next_node_id()
};
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
});
let lifetime = self.lower_lifetime(&region);
let lifetime = self.lower_ty_direct_lifetime(t, *region);
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
let span = self.lower_span(t.span);
let arg = hir::Ty { kind, span, hir_id: self.next_id() };
Expand Down Expand Up @@ -1302,7 +1282,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
GenericBound::Outlives(lifetime) => {
if lifetime_bound.is_none() {
lifetime_bound = Some(this.lower_lifetime(lifetime));
lifetime_bound = Some(this.lower_lifetime(
lifetime,
LifetimeSource::Other,
lifetime.ident.into(),
));
}
None
}
Expand Down Expand Up @@ -1393,6 +1377,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
}

fn lower_ty_direct_lifetime(
&mut self,
t: &Ty,
region: Option<Lifetime>,
) -> &'hir hir::Lifetime {
let (region, syntax) = match region {
Some(region) => (region, region.ident.into()),

None => {
let id = if let Some(LifetimeRes::ElidedAnchor { start, end }) =
self.resolver.get_lifetime_res(t.id)
{
debug_assert_eq!(start.plus(1), end);
start
} else {
self.next_node_id()
};
let span = self.tcx.sess.source_map().start_point(t.span).shrink_to_hi();
let region = Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id };
(region, LifetimeSyntax::Hidden)
}
};
self.lower_lifetime(&region, LifetimeSource::Reference, syntax)
}

/// Lowers a `ReturnPositionOpaqueTy` (`-> impl Trait`) or a `TypeAliasesOpaqueTy` (`type F =
/// impl Trait`): this creates the associated Opaque Type (TAIT) definition and then returns a
/// HIR type that references the TAIT.
Expand Down Expand Up @@ -1474,9 +1483,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
precise_capturing_args: &[PreciseCapturingArg],
) -> &'hir [hir::PreciseCapturingArg<'hir>] {
self.arena.alloc_from_iter(precise_capturing_args.iter().map(|arg| match arg {
PreciseCapturingArg::Lifetime(lt) => {
hir::PreciseCapturingArg::Lifetime(self.lower_lifetime(lt))
}
PreciseCapturingArg::Lifetime(lt) => hir::PreciseCapturingArg::Lifetime(
self.lower_lifetime(lt, LifetimeSource::PreciseCapturing, lt.ident.into()),
),
PreciseCapturingArg::Arg(path, id) => {
let [segment] = path.segments.as_slice() else {
panic!();
Expand Down Expand Up @@ -1739,22 +1748,40 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> hir::GenericBound<'hir> {
match tpb {
GenericBound::Trait(p) => hir::GenericBound::Trait(self.lower_poly_trait_ref(p, itctx)),
GenericBound::Outlives(lifetime) => {
hir::GenericBound::Outlives(self.lower_lifetime(lifetime))
}
GenericBound::Outlives(lifetime) => hir::GenericBound::Outlives(self.lower_lifetime(
lifetime,
LifetimeSource::OutlivesBound,
lifetime.ident.into(),
)),
GenericBound::Use(args, span) => hir::GenericBound::Use(
self.lower_precise_capturing_args(args),
self.lower_span(*span),
),
}
}

fn lower_lifetime(&mut self, l: &Lifetime) -> &'hir hir::Lifetime {
self.new_named_lifetime(l.id, l.id, l.ident, IsAnonInPath::No)
fn lower_lifetime(
&mut self,
l: &Lifetime,
source: LifetimeSource,
syntax: LifetimeSyntax,
) -> &'hir hir::Lifetime {
self.new_named_lifetime(l.id, l.id, l.ident, source, syntax)
}

fn lower_lifetime_anon_in_path(&mut self, id: NodeId, span: Span) -> &'hir hir::Lifetime {
self.new_named_lifetime(id, id, Ident::new(kw::UnderscoreLifetime, span), IsAnonInPath::Yes)
fn lower_lifetime_hidden_in_path(
&mut self,
id: NodeId,
span: Span,
with_angle_brackets: bool,
) -> &'hir hir::Lifetime {
self.new_named_lifetime(
id,
id,
Ident::new(kw::UnderscoreLifetime, span),
LifetimeSource::Path { with_angle_brackets },
LifetimeSyntax::Hidden,
)
}

#[instrument(level = "debug", skip(self))]
Expand All @@ -1763,7 +1790,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
id: NodeId,
new_id: NodeId,
ident: Ident,
is_anon_in_path: IsAnonInPath,
source: LifetimeSource,
syntax: LifetimeSyntax,
) -> &'hir hir::Lifetime {
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
let res = match res {
Expand All @@ -1787,17 +1815,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
};

#[cfg(debug_assertions)]
if is_anon_in_path == IsAnonInPath::Yes {
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
}

debug!(?res);
self.arena.alloc(hir::Lifetime::new(
self.lower_node_id(new_id),
self.lower_ident(ident),
res,
is_anon_in_path,
source,
syntax,
))
}

Expand Down Expand Up @@ -2389,7 +2413,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.next_id(),
Ident::new(kw::UnderscoreLifetime, self.lower_span(span)),
hir::LifetimeKind::ImplicitObjectLifetimeDefault,
IsAnonInPath::No,
LifetimeSource::Other,
LifetimeSyntax::Hidden,
);
debug!("elided_dyn_bound: r={:?}", r);
self.arena.alloc(r)
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::Arc;

use rustc_ast::{self as ast, *};
use rustc_hir as hir;
use rustc_hir::GenericArg;
use rustc_hir::def::{DefKind, PartialRes, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, GenericArg};
use rustc_middle::{span_bug, ty};
use rustc_session::parse::add_feature_diagnostics;
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
Expand Down Expand Up @@ -433,23 +432,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

// Note: these spans are used for diagnostics when they can't be inferred.
// See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label
let elided_lifetime_span = if generic_args.span.is_empty() {
let (elided_lifetime_span, with_angle_brackets) = if generic_args.span.is_empty() {
// If there are no brackets, use the identifier span.
// HACK: we use find_ancestor_inside to properly suggest elided spans in paths
// originating from macros, since the segment's span might be from a macro arg.
segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span)
(segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span), false)
} else if generic_args.is_empty() {
// If there are brackets, but not generic arguments, then use the opening bracket
generic_args.span.with_hi(generic_args.span.lo() + BytePos(1))
(generic_args.span.with_hi(generic_args.span.lo() + BytePos(1)), true)
} else {
// Else use an empty span right after the opening bracket.
generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo()
(generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo(), true)
};

generic_args.args.insert_many(
0,
(start..end).map(|id| {
let l = self.lower_lifetime_anon_in_path(id, elided_lifetime_span);
let l = self.lower_lifetime_hidden_in_path(
id,
elided_lifetime_span,
with_angle_brackets,
);
GenericArg::Lifetime(l)
}),
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
has_bang,
Some(*ident),
macro_def.body.delim,
&macro_def.body.tokens.clone(),
&macro_def.body.tokens,
true,
sp,
);
Expand Down Expand Up @@ -1468,7 +1468,7 @@ impl<'a> State<'a> {
true,
None,
m.args.delim,
&m.args.tokens.clone(),
&m.args.tokens,
true,
m.span(),
);
Expand Down
Loading
Loading