Skip to content

Commit fbd7e0c

Browse files
committed
Fix broken test and nit
1 parent b049221 commit fbd7e0c

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

Diff for: src/librustc/hir/print.rs

+35-32
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,24 @@ impl<'a> State<'a> {
450450
self.s.word(";")
451451
}
452452

453+
fn print_item_type(
454+
&mut self,
455+
item: &hir::Item,
456+
generics: &hir::Generics,
457+
inner: impl Fn(&mut Self),
458+
) {
459+
self.head(visibility_qualified(&item.vis, "type"));
460+
self.print_ident(item.ident);
461+
self.print_generic_params(&generics.params);
462+
self.end(); // end the inner ibox
463+
464+
self.print_where_clause(&generics.where_clause);
465+
self.s.space();
466+
inner(self);
467+
self.s.word(";");
468+
self.end(); // end the outer ibox
469+
}
470+
453471
/// Pretty-print an item
454472
pub fn print_item(&mut self, item: &hir::Item) {
455473
self.hardbreak_if_not_bol();
@@ -553,43 +571,28 @@ impl<'a> State<'a> {
553571
self.end()
554572
}
555573
hir::ItemKind::Ty(ref ty, ref generics) => {
556-
self.head(visibility_qualified(&item.vis, "type"));
557-
self.print_ident(item.ident);
558-
self.print_generic_params(&generics.params);
559-
self.end(); // end the inner ibox
560-
561-
self.print_where_clause(&generics.where_clause);
562-
self.s.space();
563-
self.word_space("=");
564-
self.print_type(&ty);
565-
self.s.word(";");
566-
self.end(); // end the outer ibox
574+
self.print_item_type(item, &generics, |state| {
575+
state.word_space("=");
576+
state.print_type(&ty);
577+
});
567578
}
568579
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
569-
self.head(visibility_qualified(&item.vis, "type"));
570-
self.print_ident(item.ident);
571-
self.print_generic_params(&opaque_ty.generics.params);
572-
let mut real_bounds = Vec::with_capacity(opaque_ty.bounds.len());
573-
for b in opaque_ty.bounds.iter() {
574-
if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
575-
self.s.space();
576-
self.word_space("for ?");
577-
self.print_trait_ref(&ptr.trait_ref);
578-
} else {
579-
real_bounds.push(b);
580+
self.print_item_type(item, &opaque_ty.generics, |state| {
581+
let mut real_bounds = Vec::with_capacity(opaque_ty.bounds.len());
582+
for b in opaque_ty.bounds.iter() {
583+
if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
584+
state.s.space();
585+
state.word_space("for ?");
586+
state.print_trait_ref(&ptr.trait_ref);
587+
} else {
588+
real_bounds.push(b);
589+
}
580590
}
581-
}
582-
self.print_bounds(" = impl", real_bounds);
583-
584-
self.end(); // end the inner ibox
585-
586-
self.print_where_clause(&opaque_ty.generics.where_clause);
587-
self.s.word(";");
588-
self.end(); // end the outer ibox
591+
state.print_bounds("= impl", real_bounds);
592+
});
589593
}
590594
hir::ItemKind::Enum(ref enum_definition, ref params) => {
591-
self.print_enum_def(enum_definition, params, item.ident.name, item.span,
592-
&item.vis);
595+
self.print_enum_def(enum_definition, params, item.ident.name, item.span, &item.vis);
593596
}
594597
hir::ItemKind::Struct(ref struct_def, ref generics) => {
595598
self.head(visibility_qualified(&item.vis, "struct"));

Diff for: src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: at least one trait must be specified
2-
--> $DIR/generic_type_does_not_live_long_enough.rs:9:35
2+
--> $DIR/generic_type_does_not_live_long_enough.rs:9:29
33
|
4-
LL | existential type WrongGeneric<T>: 'static;
5-
| ^^^^^^^
4+
LL | type WrongGeneric<T> = impl 'static;
5+
| ^^^^^^^
66

77
error[E0308]: mismatched types
88
--> $DIR/generic_type_does_not_live_long_enough.rs:6:18

Diff for: src/test/ui/existential_types/issue-58951.rs renamed to src/test/ui/type-alias-impl-trait/issue-58951.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// check-pass
2-
#![feature(existential_type)]
32

4-
existential type A: Iterator;
3+
#![feature(type_alias_impl_trait)]
4+
5+
type A = impl Iterator;
6+
57
fn def_a() -> A { 0..1 }
8+
69
pub fn use_a() {
710
def_a().map(|x| x);
811
}

0 commit comments

Comments
 (0)