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

+3-3
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

+40-18
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

+1-5
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

+1-4
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

+1-1
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

+3-9
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

+1-4
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

+1-4
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

+2-4
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

+1-2
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
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13521352
// TODO: check if this is always good to be infer var
13531353
let is_host = param.name == sym::host;
13541354
if !infer_args && has_default && !is_host {
1355-
tcx.const_param_default(param.def_id).instantiate(tcx, args.unwrap()).into()
1355+
tcx.const_param_default(param.def_id)
1356+
.instantiate(tcx, args.unwrap())
1357+
.into()
13561358
} else {
13571359
self.fcx.var_for_def(self.span, param)
13581360
}
@@ -1466,7 +1468,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14661468
// N.B. We are remapping all predicates to non-const since we don't know if we just
14671469
// want them as function pointers or we are calling them from a const-context. The
14681470
// actual checking will occur in `rustc_const_eval::transform::check_consts`.
1469-
// TODO: HMM?
14701471
self.register_predicate(obligation);
14711472
}
14721473
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1867,21 +1867,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18671867
if self.adjust_fulfillment_error_for_expr_obligation(error)
18681868
|| before_span != error.obligation.cause.span
18691869
{
1870-
// Store both the predicate and the predicate *without constness*
1871-
// since sometimes we instantiate and check both of these in a
1872-
// method call, for example.
18731870
remap_cause.insert((
18741871
before_span,
18751872
error.obligation.predicate,
18761873
error.obligation.cause.clone(),
18771874
));
1878-
// TODO: UM WHAT?
1879-
1880-
/* remap_cause.insert((
1881-
before_span,
1882-
error.obligation.predicate.without_const(self.tcx),
1883-
error.obligation.cause.clone(),
1884-
)); */
18851875
} else {
18861876
// If it failed to be adjusted once around, it may be adjusted
18871877
// via the "remap cause" mapping the second time...

compiler/rustc_hir_typeck/src/method/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
341341

342342
// Construct an obligation
343343
let poly_trait_ref = ty::Binder::dummy(trait_ref);
344-
(
345-
traits::Obligation::new(
346-
self.tcx,
347-
cause,
348-
self.param_env,
349-
poly_trait_ref,
350-
),
351-
args,
352-
)
344+
(traits::Obligation::new(self.tcx, cause, self.param_env, poly_trait_ref), args)
353345
}
354346

355347
/// `lookup_method_in_trait` is used for overloaded operators.

compiler/rustc_hir_typeck/src/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1599,8 +1599,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15991599
}
16001600
}
16011601
}
1602-
let predicate =
1603-
ty::Binder::dummy(trait_ref).to_predicate(self.tcx);
1602+
let predicate = ty::Binder::dummy(trait_ref).to_predicate(self.tcx);
16041603
parent_pred = Some(predicate);
16051604
let obligation =
16061605
traits::Obligation::new(self.tcx, cause.clone(), self.param_env, predicate);

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use rustc_middle::traits::util::supertraits;
3030
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
3131
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
3232
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
33-
use rustc_middle::ty::{IsSuggestable, ToPredicate};
3433
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeVisitableExt};
34+
use rustc_middle::ty::{IsSuggestable, ToPredicate};
3535
use rustc_span::def_id::DefIdSet;
3636
use rustc_span::symbol::{kw, sym, Ident};
3737
use rustc_span::Symbol;

compiler/rustc_middle/src/ty/context.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1985,17 +1985,9 @@ impl<'tcx> TyCtxt<'tcx> {
19851985
pub fn is_const_trait_impl_raw(self, def_id: DefId) -> bool {
19861986
let Some(local_def_id) = def_id.as_local() else { return false };
19871987
let hir_id = self.local_def_id_to_hir_id(local_def_id);
1988-
let node = self.hir().get(hir_id);
1988+
let node = self.hir().attrs(hir_id);
19891989

1990-
// TODO
1991-
false
1992-
/*matches!(
1993-
node,
1994-
hir::Node::Item(hir::Item {
1995-
kind: hir::ItemKind::Impl(hir::Impl { constness: hir::Constness::Const, .. }),
1996-
..
1997-
})
1998-
)*/
1990+
node.iter().any(|attr: &Attribute| {})
19991991
}
20001992

20011993
pub fn local_def_id_to_hir_id(self, local_def_id: LocalDefId) -> HirId {

compiler/rustc_middle/src/ty/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1243,10 +1243,7 @@ impl<'tcx> ToPredicate<'tcx> for TraitRef<'tcx> {
12431243
impl<'tcx> ToPredicate<'tcx, TraitPredicate<'tcx>> for TraitRef<'tcx> {
12441244
#[inline(always)]
12451245
fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> TraitPredicate<'tcx> {
1246-
TraitPredicate {
1247-
trait_ref: self,
1248-
polarity: ImplPolarity::Positive,
1249-
}
1246+
TraitPredicate { trait_ref: self, polarity: ImplPolarity::Positive }
12501247
}
12511248
}
12521249

compiler/rustc_middle/src/ty/print/pretty.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir::LangItem;
1717
use rustc_session::config::TrimmedDefPaths;
1818
use rustc_session::cstore::{ExternCrate, ExternCrateSource};
1919
use rustc_session::Limit;
20-
use rustc_span::symbol::{sym, kw, Ident, Symbol};
20+
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2121
use rustc_span::FileNameDisplayPreference;
2222
use rustc_target::abi::Size;
2323
use rustc_target::spec::abi::Abi;
@@ -2020,12 +2020,22 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
20202020
let tcx = self.tcx;
20212021

20222022
// skip host param as those are printed as `~const`
2023-
let mut args = args.iter().copied().filter(|arg| {
2024-
match arg.unpack() {
2025-
GenericArgKind::Const(c) if tcx.features().effects && matches!(c.kind(), ty::ConstKind::Param(ty::ParamConst { name: sym::host, .. })) => tcx.sess.verbose(),
2026-
_ => true
2027-
}
2028-
}).peekable();
2023+
let mut args = args
2024+
.iter()
2025+
.copied()
2026+
.filter(|arg| match arg.unpack() {
2027+
GenericArgKind::Const(c)
2028+
if tcx.features().effects
2029+
&& matches!(
2030+
c.kind(),
2031+
ty::ConstKind::Param(ty::ParamConst { name: sym::host, .. })
2032+
) =>
2033+
{
2034+
tcx.sess.verbose()
2035+
}
2036+
_ => true,
2037+
})
2038+
.peekable();
20292039

20302040
if args.peek().is_some() {
20312041
if self.in_value {

0 commit comments

Comments
 (0)