Skip to content

Commit 01cbe50

Browse files
Add constness field to ast::ItemKind::Impl
1 parent 29b854f commit 01cbe50

File tree

10 files changed

+25
-3
lines changed

10 files changed

+25
-3
lines changed

src/librustc_ast_lowering/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
6767
if let Some(hir_id) = item_hir_id {
6868
self.lctx.with_parent_item_lifetime_defs(hir_id, |this| {
6969
let this = &mut ItemLowerer { lctx: this };
70-
if let ItemKind::Impl { ref of_trait, .. } = item.kind {
71-
if of_trait.as_ref().map(|tr| tr.constness.is_some()).unwrap_or(false) {
72-
this.with_trait_impl_ref(of_trait, |this| visit::walk_item(this, item));
70+
if let ItemKind::Impl { constness, ref of_trait, .. } = item.kind {
71+
if constness == Constness::Const {
7372
this.lctx
7473
.diagnostic()
7574
.span_err(item.span, "const trait impls are not yet implemented");
@@ -366,6 +365,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
366365
unsafety,
367366
polarity,
368367
defaultness,
368+
constness: _, // TODO
369369
generics: ref ast_generics,
370370
of_trait: ref trait_ref,
371371
self_ty: ref ty,

src/librustc_ast_passes/ast_validation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
616616
unsafety,
617617
polarity,
618618
defaultness: _,
619+
constness: _, // TODO
619620
generics: _,
620621
of_trait: Some(_),
621622
ref self_ty,
@@ -649,6 +650,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
649650
unsafety,
650651
polarity,
651652
defaultness,
653+
constness: _, // TODO
652654
generics: _,
653655
of_trait: None,
654656
self_ty: _,

src/librustc_builtin_macros/deriving/generic/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ impl<'a> TraitDef<'a> {
709709
unsafety,
710710
polarity: ast::ImplPolarity::Positive,
711711
defaultness: ast::Defaultness::Final,
712+
constness: ast::Constness::NotConst,
712713
generics: trait_generics,
713714
of_trait: opt_trait_ref,
714715
self_ty: self_type,

src/librustc_builtin_macros/deriving/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn inject_impl_of_structural_trait(
160160
unsafety: ast::Unsafety::Normal,
161161
polarity: ast::ImplPolarity::Positive,
162162
defaultness: ast::Defaultness::Final,
163+
constness: ast::Constness::NotConst,
163164
generics,
164165
of_trait: Some(trait_ref),
165166
self_ty: self_type,

src/librustc_parse/parser/item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ impl<'a> Parser<'a> {
638638
unsafety,
639639
polarity,
640640
defaultness,
641+
constness,
641642
generics,
642643
of_trait: Some(trait_ref),
643644
self_ty: ty_second,
@@ -657,6 +658,7 @@ impl<'a> Parser<'a> {
657658
unsafety,
658659
polarity,
659660
defaultness,
661+
constness,
660662
generics,
661663
of_trait: None,
662664
self_ty: ty_first,

src/librustc_save_analysis/sig.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ impl Sig for ast::Item {
486486
unsafety,
487487
polarity,
488488
defaultness,
489+
constness,
489490
ref generics,
490491
ref of_trait,
491492
ref self_ty,
@@ -499,6 +500,9 @@ impl Sig for ast::Item {
499500
text.push_str("unsafe ");
500501
}
501502
text.push_str("impl");
503+
if constness == ast::Constness::Const {
504+
text.push_str(" const");
505+
}
502506

503507
let generics_sig = generics.make(offset + text.len(), id, scx)?;
504508
text.push_str(&generics_sig.text);

src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,7 @@ pub enum ItemKind {
26182618
unsafety: Unsafety,
26192619
polarity: ImplPolarity,
26202620
defaultness: Defaultness,
2621+
constness: Constness,
26212622
generics: Generics,
26222623

26232624
/// The trait being implemented, if any.

src/libsyntax/mut_visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
922922
unsafety: _,
923923
polarity: _,
924924
defaultness: _,
925+
constness: _,
925926
generics,
926927
of_trait,
927928
self_ty,

src/libsyntax/print/pprust.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ impl<'a> State<'a> {
12301230
unsafety,
12311231
polarity,
12321232
defaultness,
1233+
constness,
12331234
ref generics,
12341235
ref of_trait,
12351236
ref self_ty,
@@ -1240,6 +1241,7 @@ impl<'a> State<'a> {
12401241
self.print_defaultness(defaultness);
12411242
self.print_unsafety(unsafety);
12421243
self.word_nbsp("impl");
1244+
self.print_constness(constness);
12431245

12441246
if !generics.params.is_empty() {
12451247
self.print_generic_params(&generics.params);
@@ -2773,6 +2775,13 @@ impl<'a> State<'a> {
27732775
}
27742776
}
27752777

2778+
crate fn print_constness(&mut self, s: ast::Constness) {
2779+
match s {
2780+
ast::Constness::Const => self.word_nbsp("const"),
2781+
ast::Constness::NotConst => {}
2782+
}
2783+
}
2784+
27762785
crate fn print_is_auto(&mut self, s: ast::IsAuto) {
27772786
match s {
27782787
ast::IsAuto::Yes => self.word_nbsp("auto"),

src/libsyntax/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
312312
unsafety: _,
313313
polarity: _,
314314
defaultness: _,
315+
constness: _,
315316
ref generics,
316317
ref of_trait,
317318
ref self_ty,

0 commit comments

Comments
 (0)