Skip to content

Commit

Permalink
Auto merge of #61172 - matthewjasper:cleanup-implied-bounds-lint, r=v…
Browse files Browse the repository at this point in the history
…arkor

Improve the explicit_outlives_requirements lint

* Don't use Strings to compare parameters
* Extend the lint to lifetime bounds
* Extend the lint to enums and unions
* Use the correct span for where clauses in tuple structs
* Try to early-out where possible
* Remove unnecessary bounds in rustc crates
  • Loading branch information
bors committed Jun 19, 2019
2 parents 9cb052a + fdeb581 commit e79b2a1
Show file tree
Hide file tree
Showing 20 changed files with 3,429 additions and 548 deletions.
1 change: 0 additions & 1 deletion src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi

pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
walk_list!(visitor, visit_generic_param, &generics.params);
visitor.visit_id(generics.where_clause.hir_id);
walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,8 +1755,8 @@ impl<'a> LoweringContext<'a> {
generics: hir::Generics {
params: lifetime_defs,
where_clause: hir::WhereClause {
hir_id: lctx.next_id(),
predicates: hir_vec![],
span,
},
span,
},
Expand Down Expand Up @@ -2647,8 +2647,8 @@ impl<'a> LoweringContext<'a> {
generics: hir::Generics {
params: generic_params,
where_clause: hir::WhereClause {
hir_id: this.next_id(),
predicates: hir_vec![],
span,
},
span,
},
Expand Down Expand Up @@ -3001,11 +3001,11 @@ impl<'a> LoweringContext<'a> {
AnonymousLifetimeMode::ReportError,
|this| {
hir::WhereClause {
hir_id: this.lower_node_id(wc.id),
predicates: wc.predicates
.iter()
.map(|predicate| this.lower_where_predicate(predicate))
.collect(),
span: wc.span,
}
},
)
Expand Down
17 changes: 8 additions & 9 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ impl Generics {
Generics {
params: HirVec::new(),
where_clause: WhereClause {
hir_id: DUMMY_HIR_ID,
predicates: HirVec::new(),
span: DUMMY_SP,
},
span: DUMMY_SP,
}
Expand Down Expand Up @@ -644,19 +644,18 @@ pub enum SyntheticTyParamKind {
/// A where-clause in a definition.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct WhereClause {
pub hir_id: HirId,
pub predicates: HirVec<WherePredicate>,
// Only valid if predicates isn't empty.
span: Span,
}

impl WhereClause {
pub fn span(&self) -> Option<Span> {
self.predicates.iter().map(|predicate| predicate.span())
.fold(None, |acc, i| match (acc, i) {
(None, i) => Some(i),
(Some(acc), i) => {
Some(acc.to(i))
}
})
if self.predicates.is_empty() {
None
} else {
Some(self.span)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,8 +2202,8 @@ impl<'a> State<'a> {
let generics = hir::Generics {
params: hir::HirVec::new(),
where_clause: hir::WhereClause {
hir_id: hir::DUMMY_HIR_ID,
predicates: hir::HirVec::new(),
span: syntax_pos::DUMMY_SP,
},
span: syntax_pos::DUMMY_SP,
};
Expand Down
Loading

0 comments on commit e79b2a1

Please sign in to comment.