librustc: Implement simple where clauses.

These `where` clauses are accepted everywhere generics are currently
accepted and desugar during type collection to the type parameter bounds
we have today.

A new keyword, `where`, has been added. Therefore, this is a breaking
change. Change uses of `where` to other identifiers.

[breaking-change]
This commit is contained in:
Patrick Walton 2014-08-11 09:32:26 -07:00
parent a8c8e3f80f
commit 604af3f6c0
25 changed files with 626 additions and 207 deletions

View file

@ -363,7 +363,7 @@ impl Clean<Item> for doctree::Module {
// determine if we should display the inner contents or
// the outer `mod` item for the source code.
let where = {
let whence = {
let ctxt = super::ctxtkey.get().unwrap();
let cm = ctxt.sess().codemap();
let outer = cm.lookup_char_pos(self.where_outer.lo);
@ -380,7 +380,7 @@ impl Clean<Item> for doctree::Module {
Item {
name: Some(name),
attrs: self.attrs.clean(),
source: where.clean(),
source: whence.clean(),
visibility: self.vis.clean(),
stability: self.stab.clean(),
def_id: ast_util::local_def(self.id),
@ -781,7 +781,7 @@ impl Clean<Item> for doctree::Function {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
visibility: self.vis.clean(),
stability: self.stab.clean(),
def_id: ast_util::local_def(self.id),
@ -917,7 +917,7 @@ impl Clean<Item> for doctree::Trait {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
def_id: ast_util::local_def(self.id),
visibility: self.vis.clean(),
stability: self.stab.clean(),
@ -1397,7 +1397,7 @@ impl Clean<Item> for doctree::Struct {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
def_id: ast_util::local_def(self.id),
visibility: self.vis.clean(),
stability: self.stab.clean(),
@ -1443,7 +1443,7 @@ impl Clean<Item> for doctree::Enum {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
def_id: ast_util::local_def(self.id),
visibility: self.vis.clean(),
stability: self.stab.clean(),
@ -1466,7 +1466,7 @@ impl Clean<Item> for doctree::Variant {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
visibility: self.vis.clean(),
stability: self.stab.clean(),
def_id: ast_util::local_def(self.id),
@ -1652,7 +1652,7 @@ impl Clean<Item> for doctree::Typedef {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
def_id: ast_util::local_def(self.id.clone()),
visibility: self.vis.clean(),
stability: self.stab.clean(),
@ -1702,7 +1702,7 @@ impl Clean<Item> for doctree::Static {
Item {
name: Some(self.name.clean()),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
def_id: ast_util::local_def(self.id),
visibility: self.vis.clean(),
stability: self.stab.clean(),
@ -1748,7 +1748,7 @@ impl Clean<Item> for doctree::Impl {
Item {
name: None,
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
def_id: ast_util::local_def(self.id),
visibility: self.vis.clean(),
stability: self.stab.clean(),
@ -2115,12 +2115,12 @@ impl Clean<Item> for doctree::Macro {
Item {
name: Some(format!("{}!", self.name.clean())),
attrs: self.attrs.clean(),
source: self.where.clean(),
source: self.whence.clean(),
visibility: ast::Public.clean(),
stability: self.stab.clean(),
def_id: ast_util::local_def(self.id),
inner: MacroItem(Macro {
source: self.where.to_src(),
source: self.whence.to_src(),
}),
}
}

View file

@ -93,7 +93,7 @@ pub struct Struct {
pub generics: ast::Generics,
pub attrs: Vec<ast::Attribute>,
pub fields: Vec<ast::StructField>,
pub where: Span,
pub whence: Span,
}
pub struct Enum {
@ -103,7 +103,7 @@ pub struct Enum {
pub generics: ast::Generics,
pub attrs: Vec<ast::Attribute>,
pub id: NodeId,
pub where: Span,
pub whence: Span,
pub name: Ident,
}
@ -114,7 +114,7 @@ pub struct Variant {
pub id: ast::NodeId,
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
pub where: Span,
pub whence: Span,
}
pub struct Function {
@ -125,7 +125,7 @@ pub struct Function {
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
pub fn_style: ast::FnStyle,
pub where: Span,
pub whence: Span,
pub generics: ast::Generics,
}
@ -135,7 +135,7 @@ pub struct Typedef {
pub name: Ident,
pub id: ast::NodeId,
pub attrs: Vec<ast::Attribute>,
pub where: Span,
pub whence: Span,
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
}
@ -149,7 +149,7 @@ pub struct Static {
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
pub id: ast::NodeId,
pub where: Span,
pub whence: Span,
}
pub struct Trait {
@ -159,7 +159,7 @@ pub struct Trait {
pub parents: Vec<ast::TraitRef>,
pub attrs: Vec<ast::Attribute>,
pub id: ast::NodeId,
pub where: Span,
pub whence: Span,
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
}
@ -170,7 +170,7 @@ pub struct Impl {
pub for_: ast::P<ast::Ty>,
pub items: Vec<ast::ImplItem>,
pub attrs: Vec<ast::Attribute>,
pub where: Span,
pub whence: Span,
pub vis: ast::Visibility,
pub stab: Option<attr::Stability>,
pub id: ast::NodeId,
@ -180,7 +180,7 @@ pub struct Macro {
pub name: Ident,
pub id: ast::NodeId,
pub attrs: Vec<ast::Attribute>,
pub where: Span,
pub whence: Span,
pub stab: Option<attr::Stability>,
}

View file

@ -91,7 +91,7 @@ impl<'a> RustdocVisitor<'a> {
attrs: item.attrs.iter().map(|x| *x).collect(),
generics: generics.clone(),
fields: sd.fields.iter().map(|x| (*x).clone()).collect(),
where: item.span
whence: item.span
}
}
@ -107,7 +107,7 @@ impl<'a> RustdocVisitor<'a> {
stab: self.stability(x.node.id),
id: x.node.id,
kind: x.node.kind.clone(),
where: x.span,
whence: x.span,
});
}
Enum {
@ -118,7 +118,7 @@ impl<'a> RustdocVisitor<'a> {
generics: params.clone(),
attrs: it.attrs.iter().map(|x| *x).collect(),
id: it.id,
where: it.span,
whence: it.span,
}
}
@ -133,7 +133,7 @@ impl<'a> RustdocVisitor<'a> {
attrs: item.attrs.iter().map(|x| *x).collect(),
decl: fd.clone(),
name: item.ident,
where: item.span,
whence: item.span,
generics: gen.clone(),
fn_style: *fn_style,
}
@ -297,7 +297,7 @@ impl<'a> RustdocVisitor<'a> {
name: item.ident,
id: item.id,
attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span,
whence: item.span,
vis: item.vis,
stab: self.stability(item.id),
};
@ -311,7 +311,7 @@ impl<'a> RustdocVisitor<'a> {
id: item.id,
name: item.ident,
attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span,
whence: item.span,
vis: item.vis,
stab: self.stability(item.id),
};
@ -325,7 +325,7 @@ impl<'a> RustdocVisitor<'a> {
parents: tr.iter().map(|x| (*x).clone()).collect(),
id: item.id,
attrs: item.attrs.iter().map(|x| *x).collect(),
where: item.span,
whence: item.span,
vis: item.vis,
stab: self.stability(item.id),
};
@ -339,7 +339,7 @@ impl<'a> RustdocVisitor<'a> {
items: items.iter().map(|x| *x).collect(),
attrs: item.attrs.iter().map(|x| *x).collect(),
id: item.id,
where: item.span,
whence: item.span,
vis: item.vis,
stab: self.stability(item.id),
};
@ -360,7 +360,7 @@ impl<'a> RustdocVisitor<'a> {
id: item.id,
attrs: item.attrs.iter().map(|x| *x).collect(),
name: item.ident,
where: item.span,
whence: item.span,
stab: self.stability(item.id),
}
}