Skip to content

Commit

Permalink
Rollup merge of rust-lang#35264 - GuillaumeGomez:E0132_update, r=jona…
Browse files Browse the repository at this point in the history
…thandturner

E0132 update

Fixes rust-lang#35258.

r? @jonathandturner
  • Loading branch information
steveklabnik committed Aug 4, 2016
2 parents 540451f + 1607d5b commit 1a0a919
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/librustc/hir/mod.rs
Expand Up @@ -36,7 +36,7 @@ use hir::def::Def;
use hir::def_id::DefId;
use util::nodemap::{NodeMap, FnvHashSet};

use syntax_pos::{mk_sp, Span, ExpnId};
use syntax_pos::{BytePos, mk_sp, Span, ExpnId};
use syntax::codemap::{self, respan, Spanned};
use syntax::abi::Abi;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, AsmDialect};
Expand Down Expand Up @@ -326,6 +326,38 @@ impl Generics {
pub fn is_parameterized(&self) -> bool {
self.is_lt_parameterized() || self.is_type_parameterized()
}

// Does return a span which includes lifetimes and type parameters,
// not where clause.
pub fn span(&self) -> Option<Span> {
if !self.is_parameterized() {
None
} else {
let mut span: Option<Span> = None;
for lifetime in self.lifetimes.iter() {
if let Some(ref mut span) = span {
let life_span = lifetime.lifetime.span;
span.hi = if span.hi > life_span.hi { span.hi } else { life_span.hi };
span.lo = if span.lo < life_span.lo { span.lo } else { life_span.lo };
} else {
span = Some(lifetime.lifetime.span.clone());
}
}
for ty_param in self.ty_params.iter() {
if let Some(ref mut span) = span {
span.lo = if span.lo < ty_param.span.lo { span.lo } else { ty_param.span.lo };
span.hi = if span.hi > ty_param.span.hi { span.hi } else { ty_param.span.hi };
} else {
span = Some(ty_param.span.clone());
}
}
if let Some(ref mut span) = span {
span.lo = span.lo - BytePos(1);
span.hi = span.hi + BytePos(1);
}
span
}
}
}

/// A `where` clause in a definition
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_typeck/lib.rs
Expand Up @@ -261,8 +261,11 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
match it.node {
hir::ItemFn(_,_,_,_,ref ps,_)
if ps.is_parameterized() => {
span_err!(tcx.sess, start_span, E0132,
"start function is not allowed to have type parameters");
struct_span_err!(tcx.sess, start_span, E0132,
"start function is not allowed to have type parameters")
.span_label(ps.span().unwrap(),
&format!("start function cannot have type parameters"))
.emit();
return;
}
_ => ()
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/E0132.rs
Expand Up @@ -12,6 +12,7 @@

#[start]
fn f<T>() {} //~ ERROR E0132
//~| NOTE start function cannot have type parameters

fn main() {
}

0 comments on commit 1a0a919

Please sign in to comment.