Skip to content

Commit 95f1866

Browse files
committed
Make GenericBound explicit
1 parent c5f16e0 commit 95f1866

File tree

13 files changed

+53
-56
lines changed

13 files changed

+53
-56
lines changed

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,11 +1109,11 @@ impl<'a> LoweringContext<'a> {
11091109
let bounds = bounds
11101110
.iter()
11111111
.filter_map(|bound| match *bound {
1112-
Trait(ref ty, TraitBoundModifier::None) => {
1112+
GenericBound::Trait(ref ty, TraitBoundModifier::None) => {
11131113
Some(self.lower_poly_trait_ref(ty, itctx))
11141114
}
1115-
Trait(_, TraitBoundModifier::Maybe) => None,
1116-
Outlives(ref lifetime) => {
1115+
GenericBound::Trait(_, TraitBoundModifier::Maybe) => None,
1116+
GenericBound::Outlives(ref lifetime) => {
11171117
if lifetime_bound.is_none() {
11181118
lifetime_bound = Some(self.lower_lifetime(lifetime));
11191119
}

src/librustc_passes/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a> AstValidator<'a> {
101101

102102
fn no_questions_in_bounds(&self, bounds: &GenericBounds, where_: &str, is_trait: bool) {
103103
for bound in bounds {
104-
if let Trait(ref poly, TraitBoundModifier::Maybe) = *bound {
104+
if let GenericBound::Trait(ref poly, TraitBoundModifier::Maybe) = *bound {
105105
let mut err = self.err_handler().struct_span_err(poly.span,
106106
&format!("`?Trait` is not permitted in {}", where_));
107107
if is_trait {
@@ -190,7 +190,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
190190
TyKind::TraitObject(ref bounds, ..) => {
191191
let mut any_lifetime_bounds = false;
192192
for bound in bounds {
193-
if let Outlives(ref lifetime) = *bound {
193+
if let GenericBound::Outlives(ref lifetime) = *bound {
194194
if any_lifetime_bounds {
195195
span_err!(self.session, lifetime.ident.span, E0226,
196196
"only a single explicit lifetime bound is permitted");
@@ -203,7 +203,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
203203
}
204204
TyKind::ImplTrait(ref bounds) => {
205205
if !bounds.iter()
206-
.any(|b| if let Trait(..) = *b { true } else { false }) {
206+
.any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) {
207207
self.err_handler().span_err(ty.span, "at least one trait must be specified");
208208
}
209209
}

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
761761
// super-traits
762762
for super_bound in trait_refs.iter() {
763763
let trait_ref = match *super_bound {
764-
ast::Trait(ref trait_ref, _) => trait_ref,
765-
ast::Outlives(..) => {
766-
continue;
767-
}
764+
ast::GenericBound::Trait(ref trait_ref, _) => trait_ref,
765+
ast::GenericBound::Outlives(..) => continue,
768766
};
769767

770768
let trait_ref = &trait_ref.trait_ref;
@@ -1489,7 +1487,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14891487
ast::GenericParamKind::Lifetime { .. } => {}
14901488
ast::GenericParamKind::Type { ref default, .. } => {
14911489
for bound in &param.bounds {
1492-
if let ast::Trait(ref trait_ref, _) = *bound {
1490+
if let ast::GenericBound::Trait(ref trait_ref, _) = *bound {
14931491
self.process_path(trait_ref.trait_ref.ref_id, &trait_ref.trait_ref.path)
14941492
}
14951493
}

src/librustdoc/clean/inline.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
374374
let polarity = tcx.impl_polarity(did);
375375
let trait_ = associated_trait.clean(cx).map(|bound| {
376376
match bound {
377-
clean::TraitBound(polyt, _) => polyt.trait_,
378-
clean::Outlives(..) => unreachable!(),
377+
clean::GenericBound::TraitBound(polyt, _) => polyt.trait_,
378+
clean::GenericBound::Outlives(..) => unreachable!(),
379379
}
380380
});
381381
if trait_.def_id() == tcx.lang_items().deref_trait() {
@@ -387,9 +387,9 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
387387

388388
let provided = trait_.def_id().map(|did| {
389389
tcx.provided_trait_methods(did)
390-
.into_iter()
391-
.map(|meth| meth.name.to_string())
392-
.collect()
390+
.into_iter()
391+
.map(|meth| meth.name.to_string())
392+
.collect()
393393
}).unwrap_or(FxHashSet());
394394

395395
ret.push(clean::Item {

src/librustdoc/clean/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
pub use self::Type::*;
1515
pub use self::Mutability::*;
1616
pub use self::ItemEnum::*;
17-
pub use self::GenericBound::*;
1817
pub use self::SelfTy::*;
1918
pub use self::FunctionRetTy::*;
2019
pub use self::Visibility::{Public, Inherited};
@@ -1470,7 +1469,7 @@ impl GenericBound {
14701469
let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
14711470
Some(did), false, vec![], empty);
14721471
inline::record_extern_fqn(cx, did, TypeKind::Trait);
1473-
TraitBound(PolyTrait {
1472+
GenericBound::TraitBound(PolyTrait {
14741473
trait_: ResolvedPath {
14751474
path,
14761475
typarams: None,
@@ -1510,8 +1509,10 @@ impl GenericBound {
15101509
impl Clean<GenericBound> for hir::GenericBound {
15111510
fn clean(&self, cx: &DocContext) -> GenericBound {
15121511
match *self {
1513-
hir::GenericBound::Outlives(lt) => Outlives(lt.clean(cx)),
1514-
hir::GenericBound::Trait(ref t, modifier) => TraitBound(t.clean(cx), modifier),
1512+
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)),
1513+
hir::GenericBound::Trait(ref t, modifier) => {
1514+
GenericBound::TraitBound(t.clean(cx), modifier)
1515+
}
15151516
}
15161517
}
15171518
}
@@ -1599,7 +1600,7 @@ impl<'a, 'tcx> Clean<GenericBound> for (&'a ty::TraitRef<'tcx>, Vec<TypeBinding>
15991600
}
16001601
}
16011602

1602-
TraitBound(
1603+
GenericBound::TraitBound(
16031604
PolyTrait {
16041605
trait_: ResolvedPath {
16051606
path,
@@ -1623,9 +1624,8 @@ impl<'tcx> Clean<GenericBound> for ty::TraitRef<'tcx> {
16231624
impl<'tcx> Clean<Option<Vec<GenericBound>>> for Substs<'tcx> {
16241625
fn clean(&self, cx: &DocContext) -> Option<Vec<GenericBound>> {
16251626
let mut v = Vec::new();
1626-
v.extend(self.regions().filter_map(|r| r.clean(cx))
1627-
.map(GenericBound::Outlives));
1628-
v.extend(self.types().map(|t| TraitBound(PolyTrait {
1627+
v.extend(self.regions().filter_map(|r| r.clean(cx)).map(GenericBound::Outlives));
1628+
v.extend(self.types().map(|t| GenericBound::TraitBound(PolyTrait {
16291629
trait_: t.clean(cx),
16301630
generic_params: Vec::new(),
16311631
}, hir::TraitBoundModifier::None)));
@@ -2978,10 +2978,11 @@ impl Clean<Type> for hir::Ty {
29782978
match bounds[0].clean(cx).trait_ {
29792979
ResolvedPath { path, typarams: None, did, is_generic } => {
29802980
let mut bounds: Vec<self::GenericBound> = bounds[1..].iter().map(|bound| {
2981-
TraitBound(bound.clean(cx), hir::TraitBoundModifier::None)
2981+
self::GenericBound::TraitBound(bound.clean(cx),
2982+
hir::TraitBoundModifier::None)
29822983
}).collect();
29832984
if !lifetime.is_elided() {
2984-
bounds.push(self::Outlives(lifetime.clean(cx)));
2985+
bounds.push(self::GenericBound::Outlives(lifetime.clean(cx)));
29852986
}
29862987
ResolvedPath { path, typarams: Some(bounds), did, is_generic, }
29872988
}
@@ -3086,7 +3087,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
30863087
let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
30873088
Some(did), false, vec![], empty);
30883089
inline::record_extern_fqn(cx, did, TypeKind::Trait);
3089-
let bound = TraitBound(PolyTrait {
3090+
let bound = GenericBound::TraitBound(PolyTrait {
30903091
trait_: ResolvedPath {
30913092
path,
30923093
typarams: None,

src/librustdoc/clean/simplify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ pub fn where_clauses(cx: &DocContext, clauses: Vec<WP>) -> Vec<WP> {
8383
};
8484
!bounds.iter_mut().any(|b| {
8585
let trait_ref = match *b {
86-
clean::TraitBound(ref mut tr, _) => tr,
87-
clean::Outlives(..) => return false,
86+
clean::GenericBound::TraitBound(ref mut tr, _) => tr,
87+
clean::GenericBound::Outlives(..) => return false,
8888
};
8989
let (did, path) = match trait_ref.trait_ {
9090
clean::ResolvedPath { did, ref mut path, ..} => (did, path),

src/librustdoc/html/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ impl fmt::Display for clean::PolyTrait {
270270
impl fmt::Display for clean::GenericBound {
271271
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
272272
match *self {
273-
clean::Outlives(ref lt) => {
273+
clean::GenericBound::Outlives(ref lt) => {
274274
write!(f, "{}", *lt)
275275
}
276-
clean::TraitBound(ref ty, modifier) => {
276+
clean::GenericBound::TraitBound(ref ty, modifier) => {
277277
let modifier_str = match modifier {
278278
hir::TraitBoundModifier::None => "",
279279
hir::TraitBoundModifier::Maybe => "?",

src/libsyntax/ast.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// The Rust abstract syntax tree.
1212

13-
pub use self::GenericBound::*;
1413
pub use self::UnsafeSource::*;
1514
pub use self::GenericArgs::*;
1615
pub use symbol::{Ident, Symbol as Name};
@@ -290,8 +289,8 @@ pub enum GenericBound {
290289
impl GenericBound {
291290
pub fn span(&self) -> Span {
292291
match self {
293-
&Trait(ref t, ..) => t.span,
294-
&Outlives(ref l) => l.ident.span,
292+
&GenericBound::Trait(ref t, ..) => t.span,
293+
&GenericBound::Outlives(ref l) => l.ident.span,
295294
}
296295
}
297296
}
@@ -930,8 +929,8 @@ impl Expr {
930929
fn to_bound(&self) -> Option<GenericBound> {
931930
match &self.node {
932931
ExprKind::Path(None, path) =>
933-
Some(Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span),
934-
TraitBoundModifier::None)),
932+
Some(GenericBound::Trait(PolyTraitRef::new(Vec::new(), path.clone(), self.span),
933+
TraitBoundModifier::None)),
935934
_ => None,
936935
}
937936
}

src/libsyntax/ext/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
465465
}
466466

467467
fn ty_param_bound(&self, path: ast::Path) -> ast::GenericBound {
468-
ast::Trait(self.poly_trait_ref(path.span, path), ast::TraitBoundModifier::None)
468+
ast::GenericBound::Trait(self.poly_trait_ref(path.span, path),
469+
ast::TraitBoundModifier::None)
469470
}
470471

471472
fn lifetime(&self, span: Span, ident: ast::Ident) -> ast::Lifetime {

src/libsyntax/fold.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,12 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
678678

679679
pub fn noop_fold_param_bound<T>(pb: GenericBound, fld: &mut T) -> GenericBound where T: Folder {
680680
match pb {
681-
Trait(ty, modifier) => {
682-
Trait(fld.fold_poly_trait_ref(ty), modifier)
681+
GenericBound::Trait(ty, modifier) => {
682+
GenericBound::Trait(fld.fold_poly_trait_ref(ty), modifier)
683+
}
684+
GenericBound::Outlives(lifetime) => {
685+
GenericBound::Outlives(noop_fold_lifetime(lifetime, fld))
683686
}
684-
Outlives(lifetime) => Outlives(noop_fold_lifetime(lifetime, fld)),
685687
}
686688
}
687689

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc_target::spec::abi::{self, Abi};
1212
use ast::{AngleBracketedArgs, ParenthesizedArgData, AttrStyle, BareFnTy};
13-
use ast::{Outlives, Trait, TraitBoundModifier};
13+
use ast::{GenericBound, TraitBoundModifier};
1414
use ast::Unsafety;
1515
use ast::{Mod, AnonConst, Arg, Arm, Attribute, BindingMode, TraitItemKind};
1616
use ast::Block;
@@ -1444,7 +1444,7 @@ impl<'a> Parser<'a> {
14441444
TyKind::TraitObject(ref bounds, TraitObjectSyntax::None)
14451445
if maybe_bounds && bounds.len() == 1 && !trailing_plus => {
14461446
let path = match bounds[0] {
1447-
Trait(ref pt, ..) => pt.trait_ref.path.clone(),
1447+
GenericBound::Trait(ref pt, ..) => pt.trait_ref.path.clone(),
14481448
_ => self.bug("unexpected lifetime bound"),
14491449
};
14501450
self.parse_remaining_bounds(Vec::new(), path, lo, true)?
@@ -1566,7 +1566,7 @@ impl<'a> Parser<'a> {
15661566
fn parse_remaining_bounds(&mut self, generic_params: Vec<GenericParam>, path: ast::Path,
15671567
lo: Span, parse_plus: bool) -> PResult<'a, TyKind> {
15681568
let poly_trait_ref = PolyTraitRef::new(generic_params, path, lo.to(self.prev_span));
1569-
let mut bounds = vec![Trait(poly_trait_ref, TraitBoundModifier::None)];
1569+
let mut bounds = vec![GenericBound::Trait(poly_trait_ref, TraitBoundModifier::None)];
15701570
if parse_plus {
15711571
self.eat_plus(); // `+`, or `+=` gets split and `+` is discarded
15721572
bounds.append(&mut self.parse_ty_param_bounds()?);
@@ -4752,7 +4752,7 @@ impl<'a> Parser<'a> {
47524752
self.span_err(question_span,
47534753
"`?` may only modify trait bounds, not lifetime bounds");
47544754
}
4755-
bounds.push(Outlives(self.expect_lifetime()));
4755+
bounds.push(GenericBound::Outlives(self.expect_lifetime()));
47564756
if has_parens {
47574757
self.expect(&token::CloseDelim(token::Paren))?;
47584758
self.span_err(self.prev_span,
@@ -4770,7 +4770,7 @@ impl<'a> Parser<'a> {
47704770
} else {
47714771
TraitBoundModifier::None
47724772
};
4773-
bounds.push(Trait(poly_trait, modifier));
4773+
bounds.push(GenericBound::Trait(poly_trait, modifier));
47744774
}
47754775
} else {
47764776
break

src/libsyntax/print/pprust.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use self::AnnNode::*;
1212

1313
use rustc_target::spec::abi::{self, Abi};
1414
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
15-
use ast::{SelfKind, Outlives, Trait, TraitBoundModifier};
15+
use ast::{SelfKind, GenericBound, TraitBoundModifier};
1616
use ast::{Attribute, MacDelimiter, GenericArg};
1717
use util::parser::{self, AssocOp, Fixity};
1818
use attr;
@@ -1364,7 +1364,7 @@ impl<'a> State<'a> {
13641364
self.print_generic_params(&generics.params)?;
13651365
let mut real_bounds = Vec::with_capacity(bounds.len());
13661366
for b in bounds.iter() {
1367-
if let Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
1367+
if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
13681368
self.s.space()?;
13691369
self.word_space("for ?")?;
13701370
self.print_trait_ref(&ptr.trait_ref)?;
@@ -1390,7 +1390,7 @@ impl<'a> State<'a> {
13901390
let mut real_bounds = Vec::with_capacity(bounds.len());
13911391
// FIXME(durka) this seems to be some quite outdated syntax
13921392
for b in bounds.iter() {
1393-
if let Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
1393+
if let GenericBound::Trait(ref ptr, ast::TraitBoundModifier::Maybe) = *b {
13941394
self.s.space()?;
13951395
self.word_space("for ?")?;
13961396
self.print_trait_ref(&ptr.trait_ref)?;
@@ -2826,13 +2826,13 @@ impl<'a> State<'a> {
28262826
}
28272827

28282828
match bound {
2829-
Trait(tref, modifier) => {
2829+
GenericBound::Trait(tref, modifier) => {
28302830
if modifier == &TraitBoundModifier::Maybe {
28312831
self.s.word("?")?;
28322832
}
28332833
self.print_poly_trait_ref(tref)?;
28342834
}
2835-
Outlives(lt) => self.print_lifetime(*lt)?,
2835+
GenericBound::Outlives(lt) => self.print_lifetime(*lt)?,
28362836
}
28372837
}
28382838
}

src/libsyntax/visit.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,8 @@ pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) {
481481

482482
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
483483
match *bound {
484-
Trait(ref typ, ref modifier) => {
485-
visitor.visit_poly_trait_ref(typ, modifier);
486-
}
487-
Outlives(ref lifetime) => {
488-
visitor.visit_lifetime(lifetime);
489-
}
484+
GenericBound::Trait(ref typ, ref modifier) => visitor.visit_poly_trait_ref(typ, modifier),
485+
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
490486
}
491487
}
492488

0 commit comments

Comments
 (0)