Skip to content
Merged
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
10 changes: 5 additions & 5 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ impl Expr {
| ExprKind::UnsafeBinderCast(..)
| ExprKind::While(..)
| ExprKind::Yield(YieldKind::Postfix(..))
| ExprKind::DirectConstArg(..)
| ExprKind::GcaMacro(..)
| ExprKind::Err(_)
| ExprKind::Dummy => prefix_attrs_precedence(&self.attrs),
}
Expand Down Expand Up @@ -1920,8 +1920,8 @@ pub enum ExprKind {

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

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

/// Placeholder for an expression that wasn't syntactically well formed in some way.
Err(ErrorGuaranteed),
Expand Down Expand Up @@ -2579,8 +2579,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>),
/// An mGCA `gca!()` expression.
GcaMacro(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
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/util/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn leading_labeled_expr(mut expr: &ast::Expr) -> bool {
| Yeet(..)
| Yield(..)
| UnsafeBinderCast(..)
| DirectConstArg(..)
| GcaMacro(..)
| Err(..)
| Dummy => return false,
}
Expand Down Expand Up @@ -244,7 +244,7 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<TrailingBrace<'_>> {
| Try(_)
| Yeet(None)
| UnsafeBinderCast(..)
| DirectConstArg(..)
| GcaMacro(..)
| Err(_)
| Dummy => {
break None;
Expand Down Expand Up @@ -307,7 +307,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
| ast::TyKind::Pat(..)
| ast::TyKind::FieldOf(..)
| ast::TyKind::View(..)
| ast::TyKind::DirectConstArg(..)
| ast::TyKind::GcaMacro(..)
| ast::TyKind::Dummy
| ast::TyKind::Err(..) => break None,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ macro_rules! common_visitor_and_walkers {
visit_visitable!(vis, bytes),
ExprKind::UnsafeBinderCast(kind, expr, ty) =>
visit_visitable!(vis, kind, expr, ty),
ExprKind::DirectConstArg(expr) =>
ExprKind::GcaMacro(expr) =>
visit_visitable!(vis, expr),
ExprKind::Err(_guar) => {}
ExprKind::Dummy => {}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ impl<'hir> LoweringContext<'_, 'hir> {

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

ExprKind::DirectConstArg(expr) => {
let e = self.emit_bad_direct_const_arg(e.span, expr, "expression");
ExprKind::GcaMacro(expr) => {
let e = self.emit_bad_gca_macro(e.span, expr, "expression");
hir::ExprKind::Err(e)
}
};
Expand Down
31 changes: 14 additions & 17 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let ct = self.arena.alloc(ct);
return GenericArg::Const(ct.try_as_ambig_ct().unwrap());
}
TyKind::DirectConstArg(expr)
if self.tcx.features().min_generic_const_args() =>
{
TyKind::GcaMacro(expr) if self.tcx.features().min_generic_const_args() => {
let ct = match self.can_lower_expr_to_const_arg_direct(
expr,
DirectConstArgContext::MacrolessMinGenericConstArgs,
Expand Down Expand Up @@ -1797,8 +1795,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let fields = self.arena.alloc_slice(fields);
hir::TyKind::View(ty, fields)
}
TyKind::DirectConstArg(expr) => {
let e = self.emit_bad_direct_const_arg(t.span, expr, "type");
TyKind::GcaMacro(expr) => {
let e = self.emit_bad_gca_macro(t.span, expr, "type");
hir::TyKind::Err(e)
}
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
Expand All @@ -1807,16 +1805,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
}

pub(crate) fn emit_bad_direct_const_arg(
pub(crate) fn emit_bad_gca_macro(
&mut self,
span: Span,
expr: &Expr,
expected: &'static str,
) -> ErrorGuaranteed {
let msg = format!("expected {expected}, found `direct_const_arg!()` constant");
let msg = format!("expected {expected}, found `gca!()` constant");
if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
// FIXME(mgca): make this non-fatal once we have a better way to handle
// nested items in invalid `direct_const_arg!()` arguments.
// nested items in invalid `gca!()` arguments.
self.dcx().span_fatal(span, msg)
} else {
self.dcx().span_err(span, msg)
Expand Down Expand Up @@ -2711,9 +2709,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
.is_ok()
} else {
// do not check can_lower_expr_to_const_arg_direct, but rather just
// ExprKind::DirectConstArg, because we don't want e.g.
// ExprKind::GcaMacro, because we don't want e.g.
// `impl<const N: u8> { const C: u8 = N; }` to be a direct-rhs const
matches!(body, Expr { kind: ExprKind::DirectConstArg(_), .. })
matches!(body, Expr { kind: ExprKind::GcaMacro(_), .. })
}
};
if self.tcx.features().min_generic_const_args()
Expand Down Expand Up @@ -2816,7 +2814,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Ok(())
}
(ExprKind::ConstBlock(_), MacrolessMinGenericConstArgs) => Ok(()),
(ExprKind::DirectConstArg(_), MacrolessMinGenericConstArgs | MinGenericConstArgs) => {
(ExprKind::GcaMacro(_), MacrolessMinGenericConstArgs | MinGenericConstArgs) => {
// Always report this as able to be represented directly. If it turns out not to be,
// `lower_expr_to_const_arg_direct` will report an error.
Ok(())
Expand Down Expand Up @@ -2998,11 +2996,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
}
}
ExprKind::DirectConstArg(expr) => {
ExprKind::GcaMacro(expr) => {
// `can_lower_expr_to_const_arg_direct` always returns success upon encountering a
// ExprKind::DirectConstArg, which effectively forces the expression to be lowered
// as a direct arg. If it actually turns out to not be possible, emit an error
// instead.
// ExprKind::GcaMacro, which effectively forces the expression to be lowered as a
// direct arg. If it actually turns out to not be possible, emit an error instead.
// Always use MacrolessMinGenericConstArgs, even if we're under regular GCA, because
// that's what the macro means: to enter a context that is like macroless GCA.
match self.can_lower_expr_to_const_arg_direct(
Expand Down Expand Up @@ -3354,12 +3351,12 @@ enum DirectConstArgContext {
/// The only allowed direct const arg representation is simple paths that nameres to generic
/// const parameters.
Stable,
/// The allowed representations are what is allowed on stable, plus the `direct_const_arg!` macro.
/// The allowed representations are what is allowed on stable, plus the `gca!` macro.
MinGenericConstArgs,
/// Expressions attempt to be lowered directly, and if that fails, the expression falls back to
/// being represented as an anon const.
///
/// This context is also used under MinGenericConstArgs inside a `direct_const_arg!` macro, for
/// This context is also used under MinGenericConstArgs inside a `gca!` macro, for
/// simplicity, as they allow the same code.
MacrolessMinGenericConstArgs,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,8 @@ impl<'a> State<'a> {
self.print_type(ty);
self.print_view(fields);
}
ast::TyKind::DirectConstArg(expr) => {
self.word_nbsp("core::direct_const_arg!");
ast::TyKind::GcaMacro(expr) => {
self.word_nbsp("core::gca!");
self.popen();
self.print_expr(expr, FixupContext::default());
self.pclose();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ impl<'a> State<'a> {
self.word("/*DUMMY*/");
self.pclose();
}
ast::ExprKind::DirectConstArg(expr) => {
self.word_nbsp("core::direct_const_arg!");
ast::ExprKind::GcaMacro(expr) => {
self.word_nbsp("core::gca!");
self.popen();
self.print_expr(expr, FixupContext::default());
self.pclose()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
| ExprKind::Yeet(_)
| ExprKind::Become(_)
| ExprKind::Yield(_)
| ExprKind::DirectConstArg(_)
| ExprKind::GcaMacro(_)
| ExprKind::UnsafeBinderCast(..) => {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ pub(crate) fn expand<'cx>(
span: Span,
tts: TokenStream,
) -> MacroExpanderResult<'cx> {
let ExpandResult::Ready(expr) = get_single_expr_from_tts(cx, span, tts, "direct_const_arg!")
else {
let ExpandResult::Ready(expr) = get_single_expr_from_tts(cx, span, tts, "gca!") else {
return ExpandResult::Retry(());
};
let expr = match expr {
Expand All @@ -23,12 +22,12 @@ pub(crate) fn expand<'cx>(
ExpandResult::Ready(Box::new(base::MacEager {
expr: Some(Box::new(ast::Expr {
id,
kind: ast::ExprKind::DirectConstArg(expr.clone()),
kind: ast::ExprKind::GcaMacro(expr.clone()),
span,
attrs: Default::default(),
tokens: None,
})),
ty: Some(Box::new(ast::Ty { id, kind: ast::TyKind::DirectConstArg(expr), span })),
ty: Some(Box::new(ast::Ty { id, kind: ast::TyKind::GcaMacro(expr), span })),
..Default::default()
}))
}
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ mod define_opaque;
mod derive;
mod deriving;
mod diagnostics;
mod direct_const_arg;
mod edition_panic;
mod eii;
mod env;
mod format;
mod format_foreign;
mod gca;
mod global_allocator;
mod iter;
mod log_syntax;
Expand Down Expand Up @@ -83,11 +83,11 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
concat_bytes: concat_bytes::expand_concat_bytes,
const_format_args: format::expand_format_args,
core_panic: edition_panic::expand_panic,
direct_const_arg: direct_const_arg::expand,
env: env::expand_env,
file: source_util::expand_file,
format_args: format::expand_format_args,
format_args_nl: format::expand_format_args_nl,
gca: gca::expand,
global_asm: asm::expand_global_asm,
include: source_util::expand_include,
include_bytes: source_util::expand_include_bytes,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ declare_features! (
/// Provides a way to concatenate identifiers using metavariable expressions.
(unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)),
/// Allows directly represented generic_const_args as the rhs of const items without the
/// `direct_const_arg!` macro.
/// `gca!` macro.
(incomplete, macroless_const_item_generic_const_args, "CURRENT_RUSTC_VERSION", Some(162540)),
/// Allows directly represented generic_const_args without the `direct_const_arg!` macro.
/// Allows directly represented generic_const_args without the `gca!` macro.
(incomplete, macroless_generic_const_args, "1.99.0", Some(159006)),
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
(unstable, marker_trait_attr, "1.30.0", Some(29864)),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ pub enum InferArgKind {
/// determined during HIR ty lowering.
TypeOrConst,
/// An infer argument with unambiguous const syntax, e.g. S<{ _ }> or
/// S<direct_const_arg!(_)>. It can only be inferred to a const.
/// S<gca!(_)>. It can only be inferred to a const.
Const,
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ pub(super) fn compare_const_directness<'tcx>(
tcx.dcx()
.struct_span_err(
tcx.def_span(impl_const_item.def_id),
"implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS",
"implementation of a `#[rustc_always_gca]` must have a `gca!` RHS",
)
.with_span_note(
tcx.def_span(trait_const_item.def_id),
Expand All @@ -2182,7 +2182,7 @@ pub(super) fn compare_const_directness<'tcx>(
tcx.dcx()
.struct_span_err(
tcx.def_span(impl_const_item.def_id),
"implementation of a regular const cannot have a `direct_const_arg!` RHS",
"implementation of a regular const cannot have a `gca!` RHS",
)
.with_span_note(
tcx.def_span(trait_const_item.def_id),
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3147,9 +3147,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let body_span = tcx.hir_body(body_id).value.span;

err.multipart_suggestion(
"add direct_const_arg!() to the right-hand side of the constant",
"add gca!() to the right-hand side of the constant",
vec![
(body_span.shrink_to_lo(), String::from("core::direct_const_arg!(")),
(body_span.shrink_to_lo(), String::from("core::gca!(")),
(body_span.shrink_to_hi(), String::from(")")),
],
Applicability::MaybeIncorrect,
Expand All @@ -3165,9 +3165,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
);
}
} else {
err.note(
"only consts with a `direct_const_arg!` right-hand side may be used in types",
);
err.note("only consts with a `gca!` right-hand side may be used in types");
}
Err(err.emit_err())
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ trait UnusedDelimLint {
| Paren(_)
| Become(_) => true,
Call(..) | MethodCall(_) | Let(..) | Field(..) | MacCall(_) | FormatArgs(_) => false,
// `direct_const_arg!()` is invalid in function/method argument position.
DirectConstArg(_) => false,
// `gca!()` is invalid in function/method argument position.
GcaMacro(_) => false,
// don't lint for placeholder/error-recovery
Underscore | Err(_) | Dummy => false,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ rustc_queries! {
}

/// Returns the const of the RHS of a (free or assoc) const item, if it is a `type const`, or if
/// it is a directly represented `const` (i.e. a const with a `direct_const_arg!` RHS, or a
/// const that `feature(macroless_generic_const_args)` has decided is direct).
/// it is a directly represented `const` (i.e. a const with a `gca!` RHS, or a const that
/// `feature(macroless_generic_const_args)` has decided is direct).
///
/// When a const item is used in a type-level expression, like in equality for an assoc const
/// projection, this allows us to retrieve the typesystem-appropriate representation of the
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4358,7 +4358,7 @@ impl MutVisitor for CondChecker<'_> {
| ExprKind::IncludedBytes(_)
| ExprKind::FormatArgs(_)
| ExprKind::Err(_)
| ExprKind::DirectConstArg(_)
| ExprKind::GcaMacro(_)
| ExprKind::Dummy => {
// These would forbid any let expressions they contain already.
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_passes/src/input_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
If, While, ForLoop, Loop, Match, Closure, Block, Await, Move, Use, TryBlock, Assign,
AssignOp, Field, Index, Range, Underscore, Path, AddrOf, Break, Continue, Ret,
InlineAsm, FormatArgs, OffsetOf, MacCall, Struct, Repeat, Paren, Try, Yield, Yeet,
Become, IncludedBytes, Gen, UnsafeBinderCast, Err, Dummy, DirectConstArg
Become, IncludedBytes, Gen, UnsafeBinderCast, GcaMacro, Err, Dummy
]
);
ast_visit::walk_expr(self, e)
Expand Down Expand Up @@ -691,7 +691,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
CVarArgs,
FieldOf,
View,
DirectConstArg,
GcaMacro,
Dummy,
Err
]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc
self.visit_ty(element_ty);
self.resolve_anon_const(length, AnonConstKind::ArrayLength);
}
TyKind::DirectConstArg(expr) => self.resolve_anon_const_manual(
TyKind::GcaMacro(expr) => self.resolve_anon_const_manual(
true,
AnonConstKind::ConstArg(IsRepeatExpr::No),
|this| this.resolve_expr(expr, None),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,6 @@ symbols! {
diagnostic_opaque,
dialect,
direct,
direct_const_arg,
discriminant_kind,
discriminant_type,
discriminant_value,
Expand Down Expand Up @@ -1068,6 +1067,7 @@ symbols! {
future_output,
future_trait,
fxsr,
gca,
gdb_script_file,
ge,
gen_blocks,
Expand Down
Loading
Loading