Skip to content

Commit c262920

Browse files
committed
Remove #[const_trait]
1 parent 8aedbf1 commit c262920

File tree

198 files changed

+920
-1048
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+920
-1048
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ ast_passes_trait_fn_const =
290290
*[false] {""}
291291
}
292292
.make_impl_const_sugg = ... and declare the impl to be const instead
293-
.make_trait_const_sugg = ... and declare the trait to be a `#[const_trait]` instead
293+
.make_trait_const_sugg = ... and declare the trait to be const instead
294294
295295
ast_passes_trait_object_single_bound = only a single explicit lifetime bound is permitted
296296

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum SelfSemantic {
4848
}
4949

5050
enum TraitOrTraitImpl {
51-
Trait { span: Span, constness: Const },
51+
Trait { vis: Span, constness: Const },
5252
TraitImpl { constness: Const, polarity: ImplPolarity, trait_ref_span: Span },
5353
}
5454

@@ -109,10 +109,10 @@ impl<'a> AstValidator<'a> {
109109
self.outer_trait_or_trait_impl = old;
110110
}
111111

112-
fn with_in_trait(&mut self, span: Span, constness: Const, f: impl FnOnce(&mut Self)) {
112+
fn with_in_trait(&mut self, vis: Span, constness: Const, f: impl FnOnce(&mut Self)) {
113113
let old = mem::replace(
114114
&mut self.outer_trait_or_trait_impl,
115-
Some(TraitOrTraitImpl::Trait { span, constness }),
115+
Some(TraitOrTraitImpl::Trait { vis, constness }),
116116
);
117117
f(self);
118118
self.outer_trait_or_trait_impl = old;
@@ -265,10 +265,12 @@ impl<'a> AstValidator<'a> {
265265
None
266266
};
267267

268+
let map = self.sess.source_map();
269+
268270
let make_trait_const_sugg = if const_trait_impl
269-
&& let TraitOrTraitImpl::Trait { span, constness: ast::Const::No } = parent
271+
&& let &TraitOrTraitImpl::Trait { vis, constness: ast::Const::No } = parent
270272
{
271-
Some(span.shrink_to_lo())
273+
Some(map.span_extend_while_whitespace(vis).shrink_to_hi())
272274
} else {
273275
None
274276
};
@@ -279,7 +281,7 @@ impl<'a> AstValidator<'a> {
279281
in_impl: matches!(parent, TraitOrTraitImpl::TraitImpl { .. }),
280282
const_context_label: parent_constness,
281283
remove_const_sugg: (
282-
self.sess.source_map().span_extend_while_whitespace(span),
284+
map.span_extend_while_whitespace(span),
283285
match parent_constness {
284286
Some(_) => rustc_errors::Applicability::MachineApplicable,
285287
None => rustc_errors::Applicability::MaybeIncorrect,
@@ -1165,13 +1167,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11651167
..
11661168
}) => {
11671169
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1168-
// FIXME(const_trait_impl) remove this
1169-
let alt_const_trait_span =
1170-
attr::find_by_name(&item.attrs, sym::const_trait).map(|attr| attr.span);
1171-
let constness = match (*constness, alt_const_trait_span) {
1172-
(Const::Yes(span), _) | (Const::No, Some(span)) => Const::Yes(span),
1173-
(Const::No, None) => Const::No,
1174-
};
11751170
if *is_auto == IsAuto::Yes {
11761171
// Auto traits cannot have generics, super traits nor contain items.
11771172
self.deny_generic_params(generics, ident.span);
@@ -1188,7 +1183,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11881183
this.visit_generics(generics);
11891184
walk_list!(this, visit_param_bound, bounds, BoundKind::SuperTraits)
11901185
});
1191-
self.with_in_trait(item.span, constness, |this| {
1186+
self.with_in_trait(item.vis.span, *constness, |this| {
11921187
walk_list!(this, visit_assoc_item, items, AssocCtxt::Trait);
11931188
});
11941189
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(crate) struct TraitFnConst {
5656
pub make_impl_const_sugg: Option<Span>,
5757
#[suggestion(
5858
ast_passes_make_trait_const_sugg,
59-
code = "#[const_trait]\n",
59+
code = "const ",
6060
applicability = "maybe-incorrect"
6161
)]
6262
pub make_trait_const_sugg: Option<Span>,

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for DoNotImplementViaObjectParser {
101101
const CREATE: fn(Span) -> AttributeKind = AttributeKind::DoNotImplementViaObject;
102102
}
103103

104-
// FIXME(const_trait_impl): remove this
105-
// Const traits
106-
107-
pub(crate) struct ConstTraitParser;
108-
impl<S: Stage> NoArgsAttributeParser<S> for ConstTraitParser {
109-
const PATH: &[Symbol] = &[sym::const_trait];
110-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
111-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Trait)]);
112-
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ConstTrait;
113-
}
114-
115104
// Specialization
116105

117106
pub(crate) struct SpecializationTraitParser;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use crate::attributes::stability::{
6464
};
6565
use crate::attributes::test_attrs::{IgnoreParser, ShouldPanicParser};
6666
use crate::attributes::traits::{
67-
AllowIncoherentImplParser, CoinductiveParser, ConstTraitParser, DenyExplicitImplParser,
67+
AllowIncoherentImplParser, CoinductiveParser, DenyExplicitImplParser,
6868
DoNotImplementViaObjectParser, FundamentalParser, MarkerParser, ParenSugarParser,
6969
PointeeParser, SkipDuringMethodDispatchParser, SpecializationTraitParser, TypeConstParser,
7070
UnsafeSpecializationMarkerParser,
@@ -218,7 +218,6 @@ attribute_parsers!(
218218
Single<WithoutArgs<ColdParser>>,
219219
Single<WithoutArgs<ConstContinueParser>>,
220220
Single<WithoutArgs<ConstStabilityIndirectParser>>,
221-
Single<WithoutArgs<ConstTraitParser>>,
222221
Single<WithoutArgs<CoroutineParser>>,
223222
Single<WithoutArgs<DenyExplicitImplParser>>,
224223
Single<WithoutArgs<DoNotImplementViaObjectParser>>,

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,23 +381,21 @@ fn build_error_for_const_call<'tcx>(
381381
`{trait_name}` is not const",
382382
),
383383
);
384-
if parent.is_local() && ccx.tcx.sess.is_nightly_build() {
384+
if let Some(parent) = parent.as_local()
385+
&& ccx.tcx.sess.is_nightly_build()
386+
{
385387
if !ccx.tcx.features().const_trait_impl() {
386388
err.help(
387389
"add `#![feature(const_trait_impl)]` to the crate attributes to \
388-
enable `#[const_trait]`",
390+
enable const traits",
389391
);
390392
}
391-
let indentation = ccx
392-
.tcx
393-
.sess
394-
.source_map()
395-
.indentation_before(trait_span)
396-
.unwrap_or_default();
393+
let span = ccx.tcx.hir_expect_item(parent).vis_span;
394+
let span = ccx.tcx.sess.source_map().span_extend_while_whitespace(span);
397395
err.span_suggestion_verbose(
398-
trait_span.shrink_to_lo(),
396+
span.shrink_to_hi(),
399397
format!("consider making trait `{trait_name}` const"),
400-
format!("#[const_trait]\n{indentation}"),
398+
"const ".to_owned(),
401399
Applicability::MaybeIncorrect,
402400
);
403401
} else if !ccx.tcx.sess.is_nightly_build() {

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
846846
EncodeCrossCrate::No, experimental!(register_tool),
847847
),
848848

849-
// RFC 2632
850-
// FIXME(const_trait_impl) remove this
851-
gated!(
852-
const_trait, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, const_trait_impl,
853-
"`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
854-
`impls` and all default bodies as `const`, which may be removed or renamed in the \
855-
future."
856-
),
857849
// lang-team MCP 147
858850
gated!(
859851
deprecated_safe, Normal, template!(List: &[r#"since = "version", note = "...""#]), ErrorFollowing,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,6 @@ pub enum AttributeKind {
489489
/// Represents `#[rustc_const_stable_indirect]`.
490490
ConstStabilityIndirect,
491491

492-
/// Represents `#[const_trait]`.
493-
ConstTrait(Span),
494-
495492
/// Represents `#[coroutine]`.
496493
Coroutine(Span),
497494

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ impl AttributeKind {
3232
ConstContinue(..) => No,
3333
ConstStability { .. } => Yes,
3434
ConstStabilityIndirect => No,
35-
ConstTrait(..) => No,
3635
Coroutine(..) => No,
3736
Coverage(..) => No,
3837
CrateName { .. } => No,

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -890,15 +890,6 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
890890
};
891891

892892
let attrs = tcx.get_all_attrs(def_id);
893-
// Only regular traits can be const.
894-
// FIXME(const_trait_impl): remove this
895-
let constness = if constness == hir::Constness::Const
896-
|| !is_alias && find_attr!(attrs, AttributeKind::ConstTrait(_))
897-
{
898-
hir::Constness::Const
899-
} else {
900-
hir::Constness::NotConst
901-
};
902893

903894
let paren_sugar = find_attr!(attrs, AttributeKind::ParenSugar(_));
904895
if paren_sugar && !tcx.features().unboxed_closures() {
@@ -1366,22 +1357,27 @@ fn check_impl_constness(
13661357
}
13671358

13681359
let trait_name = tcx.item_name(trait_def_id).to_string();
1369-
let (local_trait_span, suggestion_pre) =
1370-
match (trait_def_id.is_local(), tcx.sess.is_nightly_build()) {
1371-
(true, true) => (
1372-
Some(tcx.def_span(trait_def_id).shrink_to_lo()),
1360+
let (suggestion, suggestion_pre) = match (trait_def_id.as_local(), tcx.sess.is_nightly_build())
1361+
{
1362+
(Some(trait_def_id), true) => {
1363+
let span = tcx.hir_expect_item(trait_def_id).vis_span;
1364+
let span = tcx.sess.source_map().span_extend_while_whitespace(span);
1365+
1366+
(
1367+
Some(span.shrink_to_hi()),
13731368
if tcx.features().const_trait_impl() {
13741369
""
13751370
} else {
13761371
"enable `#![feature(const_trait_impl)]` in your crate and "
13771372
},
1378-
),
1379-
(false, _) | (_, false) => (None, ""),
1380-
};
1373+
)
1374+
}
1375+
(None, _) | (_, false) => (None, ""),
1376+
};
13811377
tcx.dcx().emit_err(errors::ConstImplForNonConstTrait {
13821378
trait_ref_span: hir_trait_ref.path.span,
13831379
trait_name,
1384-
local_trait_span,
1380+
suggestion,
13851381
suggestion_pre,
13861382
marking: (),
13871383
adding: (),

0 commit comments

Comments
 (0)