Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fea7c2a

Browse files
committed
Auto merge of rust-lang#126001 - fmease:rollup-c2h2zao, r=fmease
Rollup of 7 pull requests Successful merges: - rust-lang#122192 (Do not try to reveal hidden types when trying to prove Freeze in the defining scope) - rust-lang#124840 (resolve: mark it undetermined if single import is not has any bindings) - rust-lang#125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply) - rust-lang#125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters) - rust-lang#125893 (Handle all GVN binops in a single place.) - rust-lang#125911 (delete bootstrap build before switching to bumped rustc) - rust-lang#125918 (Revert: create const block bodies in typeck via query feeding) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a330e49 + 21268d9 commit fea7c2a

File tree

87 files changed

+804
-393
lines changed

Some content is hidden

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

87 files changed

+804
-393
lines changed

‎compiler/rustc_ast/src/ast.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ pub enum ExprKind {
13921392
/// An array (e.g, `[a, b, c, d]`).
13931393
Array(ThinVec<P<Expr>>),
13941394
/// Allow anonymous constants from an inline `const` block
1395-
ConstBlock(P<Expr>),
1395+
ConstBlock(AnonConst),
13961396
/// A function call
13971397
///
13981398
/// The first field resolves to the function itself,

‎compiler/rustc_ast/src/mut_visit.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
14111411
match kind {
14121412
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
14131413
ExprKind::ConstBlock(anon_const) => {
1414-
vis.visit_expr(anon_const);
1414+
vis.visit_anon_const(anon_const);
14151415
}
14161416
ExprKind::Repeat(expr, count) => {
14171417
vis.visit_expr(expr);

‎compiler/rustc_ast/src/visit.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V
954954
ExprKind::Array(subexpressions) => {
955955
walk_list!(visitor, visit_expr, subexpressions);
956956
}
957-
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_expr(anon_const)),
957+
ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)),
958958
ExprKind::Repeat(element, count) => {
959959
try_visit!(visitor.visit_expr(element));
960960
try_visit!(visitor.visit_anon_const(count));

‎compiler/rustc_ast_lowering/src/expr.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
7575
let kind = match &e.kind {
7676
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
7777
ExprKind::ConstBlock(c) => {
78-
self.has_inline_consts = true;
79-
hir::ExprKind::ConstBlock(self.lower_expr(c))
78+
let c = self.with_new_scopes(c.value.span, |this| hir::ConstBlock {
79+
def_id: this.local_def_id(c.id),
80+
hir_id: this.lower_node_id(c.id),
81+
body: this.lower_const_body(c.value.span, Some(&c.value)),
82+
});
83+
hir::ExprKind::ConstBlock(c)
8084
}
8185
ExprKind::Repeat(expr, count) => {
8286
let expr = self.lower_expr(expr);

‎compiler/rustc_ast_lowering/src/index.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
236236
});
237237
}
238238

239+
fn visit_inline_const(&mut self, constant: &'hir ConstBlock) {
240+
self.insert(DUMMY_SP, constant.hir_id, Node::ConstBlock(constant));
241+
242+
self.with_parent(constant.hir_id, |this| {
243+
intravisit::walk_inline_const(this, constant);
244+
});
245+
}
246+
239247
fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
240248
self.insert(expr.span, expr.hir_id, Node::Expr(expr));
241249

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ struct LoweringContext<'a, 'hir> {
9696

9797
/// Bodies inside the owner being lowered.
9898
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
99-
/// Whether there were inline consts that typeck will split out into bodies
100-
has_inline_consts: bool,
10199
/// Attributes inside the owner being lowered.
102100
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
103101
/// Collect items that were created by lowering the current owner.
@@ -160,7 +158,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
160158
item_local_id_counter: hir::ItemLocalId::ZERO,
161159
node_id_to_local_id: Default::default(),
162160
trait_map: Default::default(),
163-
has_inline_consts: false,
164161

165162
// Lowering state.
166163
catch_scope: None,
@@ -570,7 +567,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
570567

571568
let current_attrs = std::mem::take(&mut self.attrs);
572569
let current_bodies = std::mem::take(&mut self.bodies);
573-
let current_has_inline_consts = std::mem::take(&mut self.has_inline_consts);
574570
let current_node_ids = std::mem::take(&mut self.node_id_to_local_id);
575571
let current_trait_map = std::mem::take(&mut self.trait_map);
576572
let current_owner =
@@ -597,7 +593,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
597593

598594
self.attrs = current_attrs;
599595
self.bodies = current_bodies;
600-
self.has_inline_consts = current_has_inline_consts;
601596
self.node_id_to_local_id = current_node_ids;
602597
self.trait_map = current_trait_map;
603598
self.current_hir_id_owner = current_owner;
@@ -634,7 +629,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
634629
let attrs = std::mem::take(&mut self.attrs);
635630
let mut bodies = std::mem::take(&mut self.bodies);
636631
let trait_map = std::mem::take(&mut self.trait_map);
637-
let has_inline_consts = std::mem::take(&mut self.has_inline_consts);
638632

639633
#[cfg(debug_assertions)]
640634
for (id, attrs) in attrs.iter() {
@@ -652,7 +646,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
652646
self.tcx.hash_owner_nodes(node, &bodies, &attrs);
653647
let num_nodes = self.item_local_id_counter.as_usize();
654648
let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes);
655-
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies, has_inline_consts };
649+
let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies };
656650
let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash };
657651

658652
self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map })

‎compiler/rustc_ast_pretty/src/pprust/state/expr.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,8 @@ impl<'a> State<'a> {
380380
ast::ExprKind::Array(exprs) => {
381381
self.print_expr_vec(exprs);
382382
}
383-
ast::ExprKind::ConstBlock(expr) => {
384-
self.word_space("const");
385-
self.print_expr(expr, FixupContext::default());
383+
ast::ExprKind::ConstBlock(anon_const) => {
384+
self.print_expr_anon_const(anon_const, attrs);
386385
}
387386
ast::ExprKind::Repeat(element, count) => {
388387
self.print_expr_repeat(element, count);

‎compiler/rustc_const_eval/src/check_consts/qualifs.rs‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,33 @@ impl Qualif for HasMutInterior {
100100
}
101101

102102
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
103-
!ty.is_freeze(cx.tcx, cx.param_env)
103+
// Avoid selecting for simple cases, such as builtin types.
104+
if ty.is_trivially_freeze() {
105+
return false;
106+
}
107+
108+
// We do not use `ty.is_freeze` here, because that requires revealing opaque types, which
109+
// requires borrowck, which in turn will invoke mir_const_qualifs again, causing a cycle error.
110+
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
111+
// that allow the trait solver to just error out instead of cycling.
112+
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span));
113+
114+
let obligation = Obligation::new(
115+
cx.tcx,
116+
ObligationCause::dummy_with_span(cx.body.span),
117+
cx.param_env,
118+
ty::TraitRef::new(cx.tcx, freeze_def_id, [ty::GenericArg::from(ty)]),
119+
);
120+
121+
let infcx = cx
122+
.tcx
123+
.infer_ctxt()
124+
.with_opaque_type_inference(cx.body.source.def_id().expect_local())
125+
.build();
126+
let ocx = ObligationCtxt::new(&infcx);
127+
ocx.register_obligation(obligation);
128+
let errors = ocx.select_all_or_error();
129+
!errors.is_empty()
104130
}
105131

106132
fn in_adt_inherently<'tcx>(

‎compiler/rustc_const_eval/src/const_eval/fn_queries.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
3838
match node {
3939
hir::Node::Ctor(_)
4040
| hir::Node::AnonConst(_)
41+
| hir::Node::ConstBlock(_)
4142
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. }) => {
4243
hir::Constness::Const
4344
}
@@ -56,7 +57,6 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
5657
if is_const { hir::Constness::Const } else { hir::Constness::NotConst }
5758
}
5859
hir::Node::Expr(e) if let hir::ExprKind::Closure(c) = e.kind => c.constness,
59-
hir::Node::Expr(e) if let hir::ExprKind::ConstBlock(_) = e.kind => hir::Constness::Const,
6060
_ => {
6161
if let Some(fn_kind) = node.fn_kind() {
6262
if fn_kind.constness() == hir::Constness::Const {

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,9 +907,6 @@ pub struct OwnerNodes<'tcx> {
907907
pub nodes: IndexVec<ItemLocalId, ParentedNode<'tcx>>,
908908
/// Content of local bodies.
909909
pub bodies: SortedMap<ItemLocalId, &'tcx Body<'tcx>>,
910-
/// Whether the body contains inline constants that are created for the query system during typeck
911-
/// of the body.
912-
pub has_inline_consts: bool,
913910
}
914911

915912
impl<'tcx> OwnerNodes<'tcx> {
@@ -1626,6 +1623,14 @@ pub struct AnonConst {
16261623
pub span: Span,
16271624
}
16281625

1626+
/// An inline constant expression `const { something }`.
1627+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
1628+
pub struct ConstBlock {
1629+
pub hir_id: HirId,
1630+
pub def_id: LocalDefId,
1631+
pub body: BodyId,
1632+
}
1633+
16291634
/// An expression.
16301635
#[derive(Debug, Clone, Copy, HashStable_Generic)]
16311636
pub struct Expr<'hir> {
@@ -1912,7 +1917,7 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
19121917
#[derive(Debug, Clone, Copy, HashStable_Generic)]
19131918
pub enum ExprKind<'hir> {
19141919
/// Allow anonymous constants from an inline `const` block
1915-
ConstBlock(&'hirExpr<'hir>),
1920+
ConstBlock(ConstBlock),
19161921
/// An array (e.g., `[a, b, c, d]`).
19171922
Array(&'hir [Expr<'hir>]),
19181923
/// A function call.
@@ -3644,6 +3649,7 @@ pub enum Node<'hir> {
36443649
Variant(&'hir Variant<'hir>),
36453650
Field(&'hir FieldDef<'hir>),
36463651
AnonConst(&'hir AnonConst),
3652+
ConstBlock(&'hir ConstBlock),
36473653
Expr(&'hir Expr<'hir>),
36483654
ExprField(&'hir ExprField<'hir>),
36493655
Stmt(&'hir Stmt<'hir>),
@@ -3704,6 +3710,7 @@ impl<'hir> Node<'hir> {
37043710
Node::PreciseCapturingNonLifetimeArg(a) => Some(a.ident),
37053711
Node::Param(..)
37063712
| Node::AnonConst(..)
3713+
| Node::ConstBlock(..)
37073714
| Node::Expr(..)
37083715
| Node::Stmt(..)
37093716
| Node::Block(..)
@@ -3801,6 +3808,7 @@ impl<'hir> Node<'hir> {
38013808
}
38023809

38033810
Node::AnonConst(constant) => Some((constant.def_id, constant.body)),
3811+
Node::ConstBlock(constant) => Some((constant.def_id, constant.body)),
38043812

38053813
_ => None,
38063814
}
@@ -3869,6 +3877,7 @@ impl<'hir> Node<'hir> {
38693877
expect_variant, &'hir Variant<'hir>, Node::Variant(n), n;
38703878
expect_field, &'hir FieldDef<'hir>, Node::Field(n), n;
38713879
expect_anon_const, &'hir AnonConst, Node::AnonConst(n), n;
3880+
expect_inline_const, &'hir ConstBlock, Node::ConstBlock(n), n;
38723881
expect_expr, &'hir Expr<'hir>, Node::Expr(n), n;
38733882
expect_expr_field, &'hir ExprField<'hir>, Node::ExprField(n), n;
38743883
expect_stmt, &'hir Stmt<'hir>, Node::Stmt(n), n;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /