Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,15 +1378,6 @@ pub enum UnsafeSource {
UserProvided,
}

/// Track whether under `feature(min_generic_const_args)` this anon const
/// was explicitly disambiguated as an anon const or not through the use of
/// `const { ... }` syntax.
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy, Walkable)]
pub enum MgcaDisambiguation {
AnonConst,
Direct,
}

/// A constant (expression) that's not an item or associated item,
/// but needs its own `DefId` for type-checking, const-eval, etc.
/// These are usually found nested inside types (e.g., array lengths)
Expand All @@ -1396,7 +1387,6 @@ pub enum MgcaDisambiguation {
pub struct AnonConst {
pub id: NodeId,
pub value: Box<Expr>,
pub mgca_disambiguation: MgcaDisambiguation,
}

/// An expression.
Expand Down Expand Up @@ -1627,6 +1617,7 @@ impl Expr {
| ExprKind::UnsafeBinderCast(..)
| ExprKind::While(..)
| ExprKind::Yield(YieldKind::Postfix(..))
| ExprKind::DirectConstArg(..)
| ExprKind::Err(_)
| ExprKind::Dummy => prefix_attrs_precedence(&self.attrs),
}
Expand Down Expand Up @@ -1920,6 +1911,9 @@ pub enum ExprKind {

UnsafeBinderCast(UnsafeBinderCastKind, Box<Expr>, Option<Box<Ty>>),

/// An mGCA `direct_const_arg!()` expression.
DirectConstArg(Box<Expr>),

/// Placeholder for an expression that wasn't syntactically well formed in some way.
Err(ErrorGuaranteed),

Expand Down Expand Up @@ -2566,6 +2560,8 @@ pub enum TyKind {
FieldOf(Box<Ty>, Option<Ident>, Ident),
/// A view of a type. `T.{ field_1, field_2 }`.
View(Box<Ty>, #[visitable(ignore)] ThinVec<Ident>),
/// An mGCA `direct_const_arg!()` expression.
DirectConstArg(Box<Expr>),
/// Sometimes we need a dummy value when no error has occurred.
Dummy,
/// Placeholder for a kind that has failed to be defined.
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_ast/src/util/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool {
| Yeet(..)
| Yield(..)
| UnsafeBinderCast(..)
| DirectConstArg(..)
| Err(..)
| Dummy => return false,
}
Expand Down Expand Up @@ -240,6 +241,7 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<TrailingBrace<'_>> {
| Try(_)
| Yeet(None)
| UnsafeBinderCast(..)
| DirectConstArg(..)
| Err(_)
| Dummy => {
break None;
Expand Down Expand Up @@ -301,9 +303,10 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
| ast::TyKind::CVarArgs
| ast::TyKind::Pat(..)
| ast::TyKind::FieldOf(..)
| ast::TyKind::View(..)
| ast::TyKind::DirectConstArg(..)
| ast::TyKind::Dummy
| ast::TyKind::Err(..)
| ast::TyKind::View(..) => break None,
| ast::TyKind::Err(..) => break None,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ macro_rules! common_visitor_and_walkers {
UnsafeBinderCastKind,
BinOpKind,
BlockCheckMode,
MgcaDisambiguation,
BorrowKind,
BoundAsyncness,
BoundConstness,
Expand Down Expand Up @@ -1074,6 +1073,8 @@ macro_rules! common_visitor_and_walkers {
visit_visitable!($($mut)? vis, bytes),
ExprKind::UnsafeBinderCast(kind, expr, ty) =>
visit_visitable!($($mut)? vis, kind, expr, ty),
ExprKind::DirectConstArg(expr) =>
visit_visitable!($($mut)? vis, expr),
ExprKind::Err(_guar) => {}
ExprKind::Dummy => {}
}
Expand Down
18 changes: 13 additions & 5 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

ExprKind::MacCall(_) => panic!("{:?} shouldn't exist here", e.span),

ExprKind::DirectConstArg(_) => {
let e = self
.tcx
.dcx()
.struct_span_err(
e.span,
"expected expression, found `direct_const_arg!()` constant",
)
.emit();
hir::ExprKind::Err(e)
}
};

hir::Expr { hir_id: expr_hir_id, kind, span }
Expand Down Expand Up @@ -599,11 +611,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
arg
};

let anon_const = AnonConst {
id: node_id,
value: const_value,
mgca_disambiguation: MgcaDisambiguation::AnonConst,
};
let anon_const = AnonConst { id: node_id, value: const_value };
generic_args.push(AngleBracketedArg::Arg(GenericArg::Const(anon_const)));
} else {
real_args.push(arg);
Expand Down
Loading
Loading