Skip to content

Commit bc91d53

Browse files
committed
up
1 parent 13ff467 commit bc91d53

File tree

23 files changed

+113
-113
lines changed

23 files changed

+113
-113
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
100100
ParamMode::Optional,
101101
ParenthesizedGenericArgs::Err,
102102
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
103-
None
103+
None,
104104
));
105105
let receiver = self.lower_expr(receiver);
106106
let args =
@@ -309,7 +309,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
309309
&se.path,
310310
ParamMode::Optional,
311311
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
312-
None
312+
None,
313313
)),
314314
self.arena
315315
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
@@ -1202,7 +1202,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12021202
path,
12031203
ParamMode::Optional,
12041204
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
1205-
None
1205+
None,
12061206
);
12071207
// Destructure like a unit struct.
12081208
let unit_struct_pat = hir::PatKind::Path(qpath);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13681368
modifier @ (TraitBoundModifier::None
13691369
| TraitBoundModifier::MaybeConst
13701370
| TraitBoundModifier::Negative),
1371-
) => Some(this.lower_poly_trait_ref(ty, itctx, modifier.to_constness())),
1371+
) => {
1372+
Some(this.lower_poly_trait_ref(ty, itctx, modifier.to_constness()))
1373+
}
13721374
// `~const ?Bound` will cause an error during AST validation
13731375
// anyways, so treat it like `?Bound` as compilation proceeds.
13741376
GenericBound::Trait(
@@ -2336,8 +2338,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23362338
}
23372339
}
23382340

2339-
fn lower_trait_ref(&mut self, constness: ast::Const, p: &TraitRef, itctx: &ImplTraitContext) -> hir::TraitRef<'hir> {
2340-
let path = match self.lower_qpath(p.ref_id, &None, &p.path, ParamMode::Explicit, itctx, Some(constness)) {
2341+
fn lower_trait_ref(
2342+
&mut self,
2343+
constness: ast::Const,
2344+
p: &TraitRef,
2345+
itctx: &ImplTraitContext,
2346+
) -> hir::TraitRef<'hir> {
2347+
let path = match self.lower_qpath(
2348+
p.ref_id,
2349+
&None,
2350+
&p.path,
2351+
ParamMode::Explicit,
2352+
itctx,
2353+
Some(constness),
2354+
) {
23412355
hir::QPath::Resolved(None, path) => path,
23422356
qpath => panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
23432357
};
@@ -2353,7 +2367,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23532367
) -> hir::PolyTraitRef<'hir> {
23542368
let bound_generic_params =
23552369
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
2356-
let trait_ref = self.lower_trait_ref(constness, &p.trait_ref, itctx,);
2370+
let trait_ref = self.lower_trait_ref(constness, &p.trait_ref, itctx);
23572371
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
23582372
}
23592373

@@ -2708,23 +2722,31 @@ struct GenericArgsCtor<'hir> {
27082722

27092723
impl<'hir> GenericArgsCtor<'hir> {
27102724
fn push_constness(&mut self, lcx: &mut LoweringContext<'_, 'hir>, constness: ast::Const) {
2711-
let span = if let ast::Const::Yes(sp) = constness {
2712-
sp
2713-
} else {
2714-
DUMMY_SP
2715-
};
2725+
let span = if let ast::Const::Yes(sp) = constness { sp } else { DUMMY_SP };
27162726
let id = lcx.next_node_id();
2717-
lcx.lower_body(|lcx| {
2718-
(&[], match constness {
2719-
ast::Const::Yes(_) => lcx.expr_ident_mut(span, Ident { name: sym::host, span }, binding),
2720-
ast::Const::No => lcx.expr(span, hir::ExprKind::Lit(lcx.arena.alloc(hir::Lit { span, node: ast::LitKind::Bool(true) }))),
2721-
})
2727+
let hir_id = lcx.next_id();
2728+
let body = lcx.lower_body(|lcx| {
2729+
(
2730+
&[],
2731+
match constness {
2732+
ast::Const::Yes(_) => lcx.expr_ident_mut(
2733+
span,
2734+
Ident { name: sym::host, span },
2735+
lcx.host_param_id.unwrap(),
2736+
),
2737+
ast::Const::No => lcx.expr(
2738+
span,
2739+
hir::ExprKind::Lit(
2740+
lcx.arena.alloc(hir::Lit { span, node: ast::LitKind::Bool(true) }),
2741+
),
2742+
),
2743+
},
2744+
)
27222745
});
2723-
let def = lcx.create_def(lcx.current_hir_id_owner.def_id, id, DefPathData::AnonConst, span);
2746+
let def_id =
2747+
lcx.create_def(lcx.current_hir_id_owner.def_id, id, DefPathData::AnonConst, span);
27242748
self.args.push(hir::GenericArg::Const(hir::ConstArg {
2725-
value: hir::AnonConst {
2726-
def_id,
2727-
},
2749+
value: hir::AnonConst { def_id, hir_id, body },
27282750
span,
27292751
}))
27302752
}

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7676
parenthesized_generic_args,
7777
itctx,
7878
// if this is the last segment, add constness to the trait path
79-
if i == proj_start - 1 {
80-
constness
81-
} else {
82-
None
83-
}
79+
if i == proj_start - 1 { constness } else { None },
8480
)
8581
},
8682
)),

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9090
) {
9191
self.prove_predicate(
9292
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Trait(
93-
ty::TraitPredicate {
94-
trait_ref,
95-
polarity: ty::ImplPolarity::Positive,
96-
},
93+
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive },
9794
))),
9895
locations,
9996
category,

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
3737

3838
match node {
3939
hir::Node::Ctor(_) => hir::Constness::Const,
40-
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.constness,
40+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }) => tcx.generics_of(def_id).host_effect_index.map_or(hir::Constness::NotConst, |_| hir::Constness::Const),
4141
hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) => {
4242
// Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other
4343
// foreign items cannot be evaluated at compile-time.

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,9 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
127127
let hir_id = tcx.local_def_id_to_hir_id(local_def_id);
128128

129129
let Some(parent) = tcx.hir().opt_parent_id(hir_id) else { return false };
130-
let parent_def = tcx.hir().get(parent);
131-
132-
if !matches!(
133-
parent_def,
134-
hir::Node::Item(hir::Item {
135-
kind: hir::ItemKind::Impl(hir::Impl { constness: hir::Constness::Const, .. }),
136-
..
137-
})
138-
) {
130+
131+
// TODO sus
132+
if tcx.generics_of(parent.owner).host_effect_index.is_none() {
139133
return false;
140134
}
141135

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,7 @@ impl Qualif for NeedsNonConstDrop {
170170

171171
trace!(?impl_src);
172172

173-
if !matches!(
174-
impl_src,
175-
ImplSource::Builtin(_) | ImplSource::Param(_)
176-
) {
173+
if !matches!(impl_src, ImplSource::Builtin(_) | ImplSource::Param(_)) {
177174
// If our const destruct candidate is not ConstDestruct or implied by the param env,
178175
// then it's bad
179176
return true;

compiler/rustc_hir_analysis/src/astconv/object_safety.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
6262
match bound_pred.skip_binder() {
6363
ty::ClauseKind::Trait(trait_pred) => {
6464
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
65-
trait_bounds.push((
66-
bound_pred.rebind(trait_pred.trait_ref),
67-
span,
68-
));
65+
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), span));
6966
}
7067
ty::ClauseKind::Projection(proj) => {
7168
projection_bounds.push((bound_pred.rebind(proj), span));

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,10 +1194,8 @@ fn check_impl<'tcx>(
11941194
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
11951195
trait_ref,
11961196
);
1197-
let trait_pred = ty::TraitPredicate {
1198-
trait_ref,
1199-
polarity: ty::ImplPolarity::Positive,
1200-
};
1197+
let trait_pred =
1198+
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive };
12011199
let mut obligations = traits::wf::trait_obligations(
12021200
wfcx.infcx,
12031201
wfcx.param_env,

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,7 @@ pub(super) fn type_param_predicates(
769769
if param_id == item_hir_id {
770770
let identity_trait_ref =
771771
ty::TraitRef::identity(tcx, item_def_id.to_def_id());
772-
extend =
773-
Some((identity_trait_ref.to_predicate(tcx), item.span));
772+
extend = Some((identity_trait_ref.to_predicate(tcx), item.span));
774773
}
775774
generics
776775
}

0 commit comments

Comments
 (0)