Skip to content

Commit 116e983

Browse files
committed
support default impl for specialization
this commit implements the first step of the `default impl` feature: all items in a `default impl` are (implicitly) `default` and hence specializable. In order to test this feature I've copied all the tests provided for the `default` method implementation (in run-pass/specialization and compile-fail/specialization directories) and moved the `default` keyword from the item to the impl. See referenced issue for further info
1 parent 15ce540 commit 116e983

Some content is hidden

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

50 files changed

+1078
-41
lines changed

rls

Submodule rls updated from 6ecff95 to 016cbc5

src/doc/reference

src/librustc/hir/lowering.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,13 @@ impl<'a> LoweringContext<'a> {
13261326
hir::ItemDefaultImpl(self.lower_unsafety(unsafety),
13271327
trait_ref)
13281328
}
1329-
ItemKind::Impl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => {
1329+
ItemKind::Impl(unsafety,
1330+
polarity,
1331+
defaultness,
1332+
ref generics,
1333+
ref ifce,
1334+
ref ty,
1335+
ref impl_items) => {
13301336
let new_impl_items = impl_items.iter()
13311337
.map(|item| self.lower_impl_item_ref(item))
13321338
.collect();
@@ -1340,6 +1346,7 @@ impl<'a> LoweringContext<'a> {
13401346

13411347
hir::ItemImpl(self.lower_unsafety(unsafety),
13421348
self.lower_impl_polarity(polarity),
1349+
self.lower_defaultness(defaultness),
13431350
self.lower_generics(generics),
13441351
ifce,
13451352
self.lower_ty(ty),

src/librustc/hir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ pub enum Item_ {
17121712
/// An implementation, eg `impl<A> Trait for Foo { .. }`
17131713
ItemImpl(Unsafety,
17141714
ImplPolarity,
1715+
Defaultness,
17151716
Generics,
17161717
Option<TraitRef>, // (optional) trait this impl implements
17171718
P<Ty>, // self

src/librustc/hir/print.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,14 @@ impl<'a> State<'a> {
678678
}
679679
hir::ItemImpl(unsafety,
680680
polarity,
681+
defaultness,
681682
ref generics,
682683
ref opt_trait,
683684
ref ty,
684685
ref impl_items) => {
685686
self.head("")?;
686687
self.print_visibility(&item.vis)?;
688+
self.print_defaultness(defaultness)?;
687689
self.print_unsafety(unsafety)?;
688690
self.word_nbsp("impl")?;
689691

@@ -820,6 +822,13 @@ impl<'a> State<'a> {
820822
}
821823
}
822824

825+
pub fn print_defaultness(&mut self, defaultness: hir::Defaultness) -> io::Result<()> {
826+
if let hir::Defaultness::Default = defaultness {
827+
self.word_nbsp("default")?;
828+
}
829+
Ok(())
830+
}
831+
823832
pub fn print_struct(&mut self,
824833
struct_def: &hir::VariantData,
825834
generics: &hir::Generics,
@@ -931,11 +940,7 @@ impl<'a> State<'a> {
931940
self.hardbreak_if_not_bol()?;
932941
self.maybe_print_comment(ii.span.lo)?;
933942
self.print_outer_attributes(&ii.attrs)?;
934-
935-
match ii.defaultness {
936-
hir::Defaultness::Default { .. } => self.word_nbsp("default")?,
937-
hir::Defaultness::Final => (),
938-
}
943+
self.print_defaultness(ii.defaultness)?;
939944

940945
match ii.node {
941946
hir::ImplItemKind::Const(ref ty, expr) => {

0 commit comments

Comments
 (0)