Skip to content

Commit 8e595f5

Browse files
committed
Make generics always have a valid span
1 parent 7840a0b commit 8e595f5

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,6 @@ impl<'hir> Map<'hir> {
628628
})
629629
}
630630

631-
pub fn get_generics_span(&self, id: DefId) -> Option<Span> {
632-
self.get_generics(id).map(|generics| generics.span).filter(|sp| *sp != DUMMY_SP)
633-
}
634-
635631
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
636632
pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
637633
let hir_id = self.node_to_hir_id(id);

src/librustc_typeck/check/compare_method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
385385
// the moment, give a kind of vague error message.
386386
if trait_params != impl_params {
387387
let def_span = tcx.sess.source_map().def_span(span);
388-
let span = tcx.hir().get_generics_span(impl_m.def_id).unwrap_or(def_span);
388+
let span = tcx.hir().get_generics(impl_m.def_id).map(|g| g.span).unwrap_or(def_span);
389389
let mut err = struct_span_err!(
390390
tcx.sess,
391391
span,
@@ -396,7 +396,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
396396
err.span_label(span, "lifetimes do not match method in trait");
397397
if let Some(sp) = tcx.hir().span_if_local(trait_m.def_id) {
398398
let def_sp = tcx.sess.source_map().def_span(sp);
399-
let sp = tcx.hir().get_generics_span(trait_m.def_id).unwrap_or(def_sp);
399+
let sp = tcx.hir().get_generics(trait_m.def_id).map(|g| g.span).unwrap_or(def_sp);
400400
err.span_label(sp, "lifetimes in impl do not match this method in trait");
401401
}
402402
err.emit();

src/libsyntax/parse/parser.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,21 +5050,22 @@ impl<'a> Parser<'a> {
50505050
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
50515051
fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
50525052
let span_lo = self.span;
5053-
if self.eat_lt() {
5053+
let (params, span) = if self.eat_lt() {
50545054
let params = self.parse_generic_params()?;
50555055
self.expect_gt()?;
5056-
Ok(ast::Generics {
5057-
params,
5058-
where_clause: WhereClause {
5059-
id: ast::DUMMY_NODE_ID,
5060-
predicates: Vec::new(),
5061-
span: DUMMY_SP,
5062-
},
5063-
span: span_lo.to(self.prev_span),
5064-
})
5056+
(params, span_lo.to(self.prev_span))
50655057
} else {
5066-
Ok(ast::Generics::default())
5067-
}
5058+
(vec![], self.prev_span.between(self.span))
5059+
};
5060+
Ok(ast::Generics {
5061+
params,
5062+
where_clause: WhereClause {
5063+
id: ast::DUMMY_NODE_ID,
5064+
predicates: Vec::new(),
5065+
span: DUMMY_SP,
5066+
},
5067+
span,
5068+
})
50685069
}
50695070

50705071
/// Parses generic args (within a path segment) with recovery for extra leading angle brackets.

src/test/ui/borrowck/regions-bound-missing-bound-in-impl.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d
3636
| ^^
3737

3838
error[E0195]: lifetime parameters or bounds on method `wrong_bound2` do not match the trait declaration
39-
--> $DIR/regions-bound-missing-bound-in-impl.rs:41:5
39+
--> $DIR/regions-bound-missing-bound-in-impl.rs:41:20
4040
|
4141
LL | fn wrong_bound2<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
4242
| ---------------- lifetimes in impl do not match this method in trait
4343
...
4444
LL | fn wrong_bound2(self, b: Inv, c: Inv, d: Inv) {
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait
45+
| ^ lifetimes do not match method in trait
4646

4747
error[E0276]: impl has stricter requirements than trait
4848
--> $DIR/regions-bound-missing-bound-in-impl.rs:48:5

src/test/ui/issues/type-arg-mismatch-due-to-impl-trait.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0049]: method `foo` has 1 type parameter but its trait declaration has 0 type parameters
2-
--> $DIR/type-arg-mismatch-due-to-impl-trait.rs:10:5
2+
--> $DIR/type-arg-mismatch-due-to-impl-trait.rs:10:11
33
|
44
LL | fn foo(&self, t: Self::T);
55
| -------------------------- expected 0 type parameters
66
...
77
LL | fn foo(&self, t: impl Clone) {}
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found 1 type parameter
8+
| ^ found 1 type parameter
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)