Add documentation to plugins crate

This commit is contained in:
Manish Goregaokar 2014-11-06 00:46:12 +05:30
parent 026b5e34ea
commit 6c9ee378f5
4 changed files with 44 additions and 8 deletions

View file

@ -18,8 +18,27 @@ declare_lint!(UNROOTED_MUST_ROOT, Deny,
declare_lint!(PRIVATIZE, Deny,
"Allows to enforce private fields for struct definitions")
/// Lint for auditing transmutes
///
/// This lint (off by default, enable with `-W transmute-type-lint`) warns about all the transmutes
/// being used, along with the types they transmute to/from.
pub struct TransmutePass;
/// Lint for ensuring safe usage of unrooted pointers
///
/// This lint (disable with `-A unrooted-must-root`/`#[allow(unrooted_must_root)]`) ensures that `#[must_root]` values are used correctly.
/// "Incorrect" usage includes:
///
/// - Not being used in a struct/enum field which is not `#[must_root]` itself
/// - Not being used as an argument to a function (Except onces named `new` and `new_inherited`)
/// - Not being bound locally in a `let` statement.
///
/// This helps catch most situations where pointers like `JS<T>` are used in a way that they can be invalidated by a GC pass.
pub struct UnrootedPass;
/// Lint for keeping DOM fields private
///
/// This lint (disable with `-A privatize`/`#[allow(privatize)]`) ensures all types marked with `#[privatize]` have no private fields
pub struct PrivatizePass;
impl LintPass for TransmutePass {
@ -51,6 +70,9 @@ impl LintPass for TransmutePass {
}
}
// Checks if a type has the #[must_root] annotation.
// Unwraps pointers as well
// TODO (#3874, sort of): unwrap other types like Vec/Option/HashMap/etc
fn lint_unrooted_ty(cx: &Context, ty: &ast::Ty, warning: &str) {
match ty.node {
ast::TyBox(ref t) | ast::TyUniq(ref t) |
@ -74,7 +96,7 @@ impl LintPass for UnrootedPass {
fn get_lints(&self) -> LintArray {
lint_array!(UNROOTED_MUST_ROOT)
}
/// All structs containing #[must_root] types must be #[must_root] themselves
fn check_struct_def(&mut self, cx: &Context, def: &ast::StructDef, _i: ast::Ident, _gen: &ast::Generics, id: ast::NodeId) {
if cx.tcx.map.expect_item(id).attrs.iter().all(|a| !a.check_name("must_root")) {
for ref field in def.fields.iter() {
@ -83,7 +105,7 @@ impl LintPass for UnrootedPass {
}
}
}
/// All enums containing #[must_root] types must be #[must_root] themselves
fn check_variant(&mut self, cx: &Context, var: &ast::Variant, _gen: &ast::Generics) {
let ref map = cx.tcx.map;
if map.expect_item(map.get_parent(var.node.id)).attrs.iter().all(|a| !a.check_name("must_root")) {
@ -98,7 +120,7 @@ impl LintPass for UnrootedPass {
}
}
}
/// Function arguments that are #[must_root] types are not allowed
fn check_fn(&mut self, cx: &Context, kind: visit::FnKind, decl: &ast::FnDecl,
block: &ast::Block, _span: codemap::Span, _id: ast::NodeId) {
match kind {