Skip to content

Commit 019fd0c

Browse files
committed
Update comments and error message to use new syntax instead of old type_const attribute.
1 parent 067ebc0 commit 019fd0c

11 files changed

Lines changed: 24 additions & 23 deletions

File tree

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ where
345345
let uneval = match constant.const_ {
346346
Const::Ty(_, ct) => match ct.kind() {
347347
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
348-
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`).
348+
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`).
349349
ty::ConstKind::Unevaluated(_) => None,
350350
// FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
351351
// strict, and if instead we should be doing some kind of value-based analysis.

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>(
394394
typing_env: ty::TypingEnv<'tcx>,
395395
) -> Result<R, ErrorHandled> {
396396
let def = cid.instance.def.def_id();
397-
// #[type_const] don't have bodys
397+
// `type const` don't have bodys
398398
debug_assert!(!tcx.is_type_const(def), "CTFE tried to evaluate type-const: {:?}", def);
399399

400400
let is_static = tcx.is_static(def);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,14 +2060,14 @@ fn compare_type_const<'tcx>(
20602060
.dcx()
20612061
.struct_span_err(
20622062
tcx.def_span(impl_const_item.def_id),
2063-
"implementation of `#[type_const]` const must be marked with `#[type_const]`",
2063+
"implementation of a `type const` must also be marked as `type const`",
20642064
)
20652065
.with_span_note(
20662066
MultiSpan::from_spans(vec![
20672067
tcx.def_span(trait_const_item.def_id),
20682068
trait_type_const_span,
20692069
]),
2070-
"trait declaration of const is marked with `#[type_const]`",
2070+
"trait declaration of const is marked as `type const`",
20712071
)
20722072
.emit());
20732073
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,17 @@ fn infer_placeholder_type<'tcx>(
420420
kind: &'static str,
421421
) -> Ty<'tcx> {
422422
let tcx = cx.tcx();
423-
// If the type is omitted on a #[type_const] we can't run
423+
// If the type is omitted on a `type const` we can't run
424424
// type check on since that requires the const have a body
425-
// which type_consts don't.
425+
// which `type const`s don't.
426426
let ty = if tcx.is_type_const(def_id.to_def_id()) {
427427
if let Some(trait_item_def_id) = tcx.trait_item_of(def_id.to_def_id()) {
428428
tcx.type_of(trait_item_def_id).instantiate_identity()
429429
} else {
430430
Ty::new_error_with_message(
431431
tcx,
432432
ty_span,
433-
"constant with #[type_const] requires an explicit type",
433+
"constant with `type const` requires an explicit type",
434434
)
435435
}
436436
} else {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
607607
if tcx.features().min_generic_const_args() {
608608
let mut err = self.dcx().struct_span_err(
609609
constraint.span,
610-
"use of trait associated const without `#[type_const]`",
610+
"use of trait associated const not defined as `type const`",
611611
);
612-
err.note("the declaration in the trait must be marked with `#[type_const]`");
612+
err.note("the declaration in the trait must begin with `type const` not just `const` alone");
613613
return Err(err.emit());
614614
} else {
615615
let err = self.dcx().span_delayed_bug(
616616
constraint.span,
617-
"use of trait associated const without `#[type_const]`",
617+
"use of trait associated const defined as `type const`",
618618
);
619619
return Err(err);
620620
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,19 +2844,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
28442844
if tcx.is_type_const(def_id) {
28452845
Ok(())
28462846
} else {
2847-
let mut err = self
2848-
.dcx()
2849-
.struct_span_err(span, "use of `const` in the type system without `#[type_const]`");
2847+
let mut err = self.dcx().struct_span_err(
2848+
span,
2849+
"use of `const` in the type system not defined as `type const`",
2850+
);
28502851
if def_id.is_local() {
28512852
let name = tcx.def_path_str(def_id);
28522853
err.span_suggestion(
28532854
tcx.def_span(def_id).shrink_to_lo(),
2854-
format!("add `#[type_const]` attribute to `{name}`"),
2855-
format!("#[type_const]\n"),
2855+
format!("add `type` before `const` for `{name}`"),
2856+
format!("type const\n"),
28562857
Applicability::MaybeIncorrect,
28572858
);
28582859
} else {
2859-
err.note("only consts marked with `#[type_const]` may be used in types");
2860+
err.note("only consts marked defined as `type const` may be used in types");
28602861
}
28612862
Err(err.emit())
28622863
}

compiler/rustc_middle/src/queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,13 @@ rustc_queries! {
293293
separate_provide_extern
294294
}
295295

296-
/// Returns the const of the RHS of a (free or assoc) const item, if it is a `#[type_const]`.
296+
/// Returns the const of the RHS of a (free or assoc) const item, if it is a `type const`.
297297
///
298298
/// When a const item is used in a type-level expression, like in equality for an assoc const
299299
/// projection, this allows us to retrieve the typesystem-appropriate representation of the
300300
/// const value.
301301
///
302-
/// This query will ICE if given a const that is not marked with `#[type_const]`.
302+
/// This query will ICE if given a const that is not marked with `type const`.
303303
query const_of_item(def_id: DefId) -> ty::EarlyBinder<'tcx, ty::Const<'tcx>> {
304304
desc { |tcx| "computing the type-level value for `{}`", tcx.def_path_str(def_id) }
305305
cache_on_disk_if { def_id.is_local() }

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ impl DynCompatibilityViolation {
845845
format!("it contains generic associated const `{name}`").into()
846846
}
847847
Self::AssocConst(name, AssocConstViolation::NonType, _) => {
848-
format!("it contains associated const `{name}` that's not marked `#[type_const]`")
848+
format!("it contains associated const `{name}` that's not defined as `type const`")
849849
.into()
850850
}
851851
Self::AssocConst(name, AssocConstViolation::TypeReferencesSelf, _) => format!(
@@ -999,7 +999,7 @@ pub enum AssocConstViolation {
999999
/// Has own generic parameters (GAC).
10001000
Generic,
10011001

1002-
/// Isn't marked `#[type_const]`.
1002+
/// Isn't defined as `type const`.
10031003
NonType,
10041004

10051005
/// Its type mentions the `Self` type parameter.

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,7 @@ impl<'tcx> TyCtxt<'tcx> {
29282928
) -> bool {
29292929
let generics = self.generics_of(def_id);
29302930

2931-
// IATs and IACs (inherent associated types/consts with #[type_const]) themselves have a
2931+
// IATs and IACs (inherent associated types/consts with `type const`) themselves have a
29322932
// weird arg setup (self + own args), but nested items *in* IATs (namely: opaques, i.e.
29332933
// ATPITs) do not.
29342934
let is_inherent_assoc_ty = matches!(self.def_kind(def_id), DefKind::AssocTy)

compiler/rustc_passes/src/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'tcx> ReachableContext<'tcx> {
209209
self.visit_nested_body(body);
210210
}
211211
}
212-
// For #[type_const] we want to evaluate the RHS.
212+
// For `type const` we want to evaluate the RHS.
213213
hir::ItemKind::Const(_, _, _, init @ hir::ConstItemRhs::TypeConst(_)) => {
214214
self.visit_const_item_rhs(init);
215215
}

0 commit comments

Comments
 (0)