Reduce max line length from 150 to 120 characters

Part of https://github.com/servo/servo/issues/6041
This commit is contained in:
Corey Farwell 2015-05-23 19:49:53 -04:00
parent 7561f7b83f
commit 8e3f4bba85
141 changed files with 1161 additions and 497 deletions

View file

@ -8,7 +8,8 @@ use syntax::ptr::P;
use syntax::ast::{MetaItem, Expr};
use syntax::ast;
use syntax::ext::build::AstBuilder;
use syntax::ext::deriving::generic::{combine_substructure, EnumMatching, FieldInfo, MethodDef, Struct, Substructure, TraitDef, ty};
use syntax::ext::deriving::generic::{combine_substructure, EnumMatching, FieldInfo, MethodDef, Struct,
Substructure, TraitDef, ty};
pub fn expand_dom_struct(cx: &mut ExtCtxt, sp: Span, _: &MetaItem, anno: Annotatable) -> Annotatable {
if let Annotatable::Item(item) = anno {
@ -31,8 +32,10 @@ pub fn expand_dom_struct(cx: &mut ExtCtxt, sp: Span, _: &MetaItem, anno: Annotat
/// Provides the hook to expand `#[jstraceable]` into an implementation of `JSTraceable`
///
/// The expansion basically calls `trace()` on all of the fields of the struct/enum, erroring if they do not implement the method.
pub fn expand_jstraceable(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: Annotatable, push: &mut FnMut(Annotatable)) {
/// The expansion basically calls `trace()` on all of the fields of the struct/enum, erroring if they do not
/// implement the method.
pub fn expand_jstraceable(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item: Annotatable,
push: &mut FnMut(Annotatable)) {
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
@ -44,7 +47,8 @@ pub fn expand_jstraceable(cx: &mut ExtCtxt, span: Span, mitem: &MetaItem, item:
name: "trace",
generics: ty::LifetimeBounds::empty(),
explicit_self: ty::borrowed_explicit_self(),
args: vec!(ty::Ptr(box ty::Literal(ty::Path::new(vec!("js","jsapi","JSTracer"))), ty::Raw(ast::MutMutable))),
args: vec!(ty::Ptr(box ty::Literal(ty::Path::new(vec!("js","jsapi","JSTracer"))),
ty::Raw(ast::MutMutable))),
ret_ty: ty::nil_ty(),
attributes: vec![quote_attr!(cx, #[inline(always)])],
is_unsafe: false,

View file

@ -8,7 +8,8 @@
//!
//! - `#[privatize]` : Forces all fields in a struct/enum to be private
//! - `#[jstraceable]` : Auto-derives an implementation of `JSTraceable` for a struct in the script crate
//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. See the lints module for more details
//! - `#[must_root]` : Prevents data of the marked type from being used on the stack. See the lints module for more
//! details
//! - `#[dom_struct]` : Implies `#[privatize]`,`#[jstraceable]`, and `#[must_root]`.
//! Use this for structs that correspond to a DOM type

View file

@ -22,7 +22,8 @@ impl LintPass for InheritancePass {
lint_array!(INHERITANCE_INTEGRITY)
}
fn check_struct_def(&mut self, cx: &Context, def: &ast::StructDef, _i: ast::Ident, _gen: &ast::Generics, id: ast::NodeId) {
fn check_struct_def(&mut self, cx: &Context, def: &ast::StructDef, _i: ast::Ident,
_gen: &ast::Generics, id: ast::NodeId) {
// Lints are run post expansion, so it's fine to use
// #[_dom_struct_marker] here without also checking for #[dom_struct]
if ty::has_attr(cx.tcx, ast_util::local_def(id), "_dom_struct_marker") {
@ -32,7 +33,8 @@ impl LintPass for InheritancePass {
if match_lang_ty(cx, &*f.node.ty, "reflector") {
if ctr > 0 {
cx.span_lint(INHERITANCE_INTEGRITY, f.span,
"The Reflector should be the first field of the DOM struct");
"The Reflector should be the first field of the DOM \
struct");
}
return true;
}

View file

@ -13,7 +13,8 @@ declare_lint!(PRIVATIZE, Deny,
/// Lint for keeping DOM fields private
///
/// This lint (disable with `-A privatize`/`#[allow(privatize)]`) ensures all types marked with `#[privatize]` have no private fields
/// This lint (disable with `-A privatize`/`#[allow(privatize)]`) ensures all types marked with `#[privatize]`
/// have no private fields
pub struct PrivatizePass;
impl LintPass for PrivatizePass {
@ -21,13 +22,19 @@ impl LintPass for PrivatizePass {
lint_array!(PRIVATIZE)
}
fn check_struct_def(&mut self, cx: &Context, def: &ast::StructDef, _i: ast::Ident, _gen: &ast::Generics, id: ast::NodeId) {
fn check_struct_def(&mut self,
cx: &Context,
def: &ast::StructDef,
_i: ast::Ident,
_gen: &ast::Generics,
id: ast::NodeId) {
if ty::has_attr(cx.tcx, ast_util::local_def(id), "privatize") {
for field in def.fields.iter() {
match field.node {
ast::StructField_ { kind: ast::NamedField(ident, visibility), .. } if visibility == Public => {
cx.span_lint(PRIVATIZE, field.span,
&format!("Field {} is public where only private fields are allowed", ident.name));
&format!("Field {} is public where only private fields are allowed",
ident.name));
}
_ => {}
}

View file

@ -15,14 +15,17 @@ declare_lint!(UNROOTED_MUST_ROOT, Deny,
/// 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.
/// 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, assignment, `for` loop, or `match` 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.
/// 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;
// Checks if a type has the #[must_root] annotation.
@ -31,7 +34,8 @@ pub struct UnrootedPass;
fn lint_unrooted_ty(cx: &Context, ty: &ast::Ty, warning: &str) {
match ty.node {
ast::TyVec(ref t) | ast::TyFixedLengthVec(ref t, _) |
ast::TyPtr(ast::MutTy { ty: ref t, ..}) | ast::TyRptr(_, ast::MutTy { ty: ref t, ..}) => lint_unrooted_ty(cx, &**t, warning),
ast::TyPtr(ast::MutTy { ty: ref t, ..}) | ast::TyRptr(_, ast::MutTy { ty: ref t, ..}) =>
lint_unrooted_ty(cx, &**t, warning),
ast::TyPath(..) => {
match cx.tcx.def_map.borrow()[&ty.id] {
def::PathResolution{ base_def: def::DefTy(def_id, _), .. } => {
@ -51,7 +55,12 @@ impl LintPass for UnrootedPass {
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) {
fn check_struct_def(&mut self,
cx: &Context,
def: &ast::StructDef,
_i: ast::Ident,
_gen: &ast::Generics,
id: ast::NodeId) {
let item = match cx.tcx.map.get(id) {
ast_map::Node::NodeItem(item) => item,
_ => cx.tcx.map.expect_item(cx.tcx.map.get_parent(id)),

View file

@ -9,12 +9,14 @@ use syntax::ast;
use utils::match_ty_unwrap;
pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: Annotatable, push: &mut FnMut(Annotatable)) {
pub fn expand_reflector(cx: &mut ExtCtxt, span: Span, _: &MetaItem, annotatable: Annotatable,
push: &mut FnMut(Annotatable)) {
if let Annotatable::Item(item) = annotatable {
if let ast::ItemStruct(ref def, _) = item.node {
let struct_name = item.ident;
// This path has to be hardcoded, unfortunately, since we can't resolve paths at expansion time
match def.fields.iter().find(|f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) {
match def.fields.iter().find(
|f| match_ty_unwrap(&*f.node.ty, &["dom", "bindings", "utils", "Reflector"]).is_some()) {
// If it has a field that is a Reflector, use that
Some(f) => {
let field_name = f.node.ident();

View file

@ -83,6 +83,7 @@ pub fn unsafe_context(map: &ast_map::Map, id: ast::NodeId) -> bool {
_ => false,
}
}
_ => false // There are probably a couple of other unsafe cases we don't care to lint, those will need to be added.
_ => false // There are probably a couple of other unsafe cases we don't care to lint, those will need
// to be added.
}
}