Skip to content

Commit

Permalink
Re-enable ConstArgKind::Path lowering by default
Browse files Browse the repository at this point in the history
...and remove the `const_arg_path` feature gate as a result. It was only
a stopgap measure to fix the regression that the new lowering introduced
(which should now be fixed by this PR).
  • Loading branch information
camelid committed Sep 8, 2024
1 parent 6834dfe commit 7fa114c
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 21 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let parent_def_id = self.current_def_id_parent;
let node_id = self.next_node_id();
// HACK(min_generic_const_args): see lower_anon_const
if !self.tcx.features().const_arg_path
|| !expr.is_potential_trivial_const_arg()
{
if !expr.is_potential_trivial_const_arg() {
self.create_def(
parent_def_id,
node_id,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let node_id = self.next_node_id();

// HACK(min_generic_const_args): see lower_anon_const
if !self.tcx.features().const_arg_path || !arg.is_potential_trivial_const_arg() {
if !arg.is_potential_trivial_const_arg() {
// Add a definition for the in-band const def.
self.create_def(parent_def_id, node_id, kw::Empty, DefKind::AnonConst, f.span);
}
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2335,7 +2335,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span,
) -> &'hir hir::ConstArg<'hir> {
let ct_kind = match res {
Res::Def(DefKind::ConstParam, _) if self.tcx.features().const_arg_path => {
Res::Def(DefKind::ConstParam, _) => {
let qpath = self.lower_qpath(
ty_id,
&None,
Expand Down Expand Up @@ -2410,8 +2410,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
debug!("res={:?}", maybe_res);
// FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
if self.tcx.features().const_arg_path
&& let Some(res) = maybe_res
if let Some(res) = maybe_res
&& let Res::Def(DefKind::ConstParam, _) = res
&& let ExprKind::Path(qself, path) = &expr.kind
{
Expand Down Expand Up @@ -2442,7 +2441,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// See [`hir::ConstArg`] for when to use this function vs
/// [`Self::lower_anon_const_to_const_arg`].
fn lower_anon_const_to_anon_const(&mut self, c: &AnonConst) -> &'hir hir::AnonConst {
if self.tcx.features().const_arg_path && c.value.is_potential_trivial_const_arg() {
if c.value.is_potential_trivial_const_arg() {
// HACK(min_generic_const_args): see DefCollector::visit_anon_const
// Over there, we guess if this is a bare param and only create a def if
// we think it's not. However we may can guess wrong (see there for example)
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ declare_features! (
(unstable, anonymous_lifetime_in_impl_trait, "1.63.0", None),
/// Allows identifying the `compiler_builtins` crate.
(internal, compiler_builtins, "1.13.0", None),
/// Gating for a new desugaring of const arguments of usages of const parameters
(internal, const_arg_path, "1.81.0", None),
/// Allows writing custom MIR
(internal, custom_mir, "1.65.0", None),
/// Outputs useful `assert!` messages
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,7 @@ impl<'tcx> Const<'tcx> {
),
) = expr.kind
{
if tcx.features().const_arg_path {
span_bug!(
expr.span,
"try_from_lit: received const param which shouldn't be possible"
);
}
return Some(Const::from_param(tcx, qpath, expr.hir_id));
span_bug!(expr.span, "try_from_lit: received const param which shouldn't be possible");
};

let lit_input = match expr.kind {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
}

fn visit_anon_const(&mut self, constant: &'a AnonConst) {
if self.resolver.tcx.features().const_arg_path
&& constant.value.is_potential_trivial_const_arg()
{
if constant.value.is_potential_trivial_const_arg() {
// HACK(min_generic_const_args): don't create defs for anon consts if we think they will
// later be turned into ConstArgKind::Path's. because this is before resolve is done, we
// may accidentally identify a construction of a unit struct as a param and not create a
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,6 @@ symbols! {
conservative_impl_trait,
console,
const_allocate,
const_arg_path,
const_async_blocks,
const_closures,
const_compare_raw_pointers,
Expand Down

0 comments on commit 7fa114c

Please sign in to comment.