mirror of
https://github.com/servo/servo.git
synced 2025-06-13 19:04:30 +00:00
Replace inheritance_integrity by trait shenanigans
For each derived DomObject impl, we also generate a dummy trait ShouldNotImplDomObject that is implemented for all T: DomObject. We then try to implement it for each field type except the first one. If compilation succeed, this means that field type doesn't implement DomObject itself otherwise it would break coherence rules. error[E0119]: conflicting implementations of trait `dom::xmlhttprequest::_IMPL_DOMOBJECT_FOR_XMLHttpRequest::ShouldNotImplDomObject` for type `((), SomeFieldTypeThatShouldNotImplementDomObject)`: --> /Users/nox/src/servo/components/script/dom/xmlhttprequest.rs:120:1 | 120 | #[dom_struct] | ^^^^^^^^^^^^^ | | | first implementation here | conflicting implementation for `((), SomeFieldTypeThatShouldNotImplementDomObject)`
This commit is contained in:
parent
37dab8f9f2
commit
a6d59d8714
7 changed files with 56 additions and 139 deletions
|
@ -2,18 +2,13 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use rustc::hir::{self, def};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::lint::{LateContext, LintContext};
|
||||
use syntax::ast;
|
||||
use syntax::attr::mark_used;
|
||||
use syntax::codemap::{ExpnFormat, Span};
|
||||
use syntax::ptr::P;
|
||||
|
||||
|
||||
/// Matches a type with a provided string, and returns its type parameters if successful
|
||||
///
|
||||
/// Try not to use this for types defined in crates you own, use match_lang_ty instead (for lint passes)
|
||||
pub fn match_ty_unwrap<'a>(ty: &'a ast::Ty, segments: &[&str]) -> Option<&'a [P<ast::Ty>]> {
|
||||
match ty.node {
|
||||
ast::TyKind::Path(_, ast::Path { segments: ref seg, .. }) => {
|
||||
|
@ -42,31 +37,6 @@ pub fn match_ty_unwrap<'a>(ty: &'a ast::Ty, segments: &[&str]) -> Option<&'a [P<
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks if a type has a #[servo_lang = "str"] attribute
|
||||
pub fn match_lang_ty(cx: &LateContext, ty: &hir::Ty, value: &str) -> bool {
|
||||
let def = match ty.node {
|
||||
hir::TyPath(hir::QPath::Resolved(_, ref path)) => path.def,
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
if let def::Def::PrimTy(_) = def {
|
||||
return false;
|
||||
}
|
||||
|
||||
match_lang_did(cx, def.def_id(), value)
|
||||
}
|
||||
|
||||
pub fn match_lang_did(cx: &LateContext, did: DefId, value: &str) -> bool {
|
||||
cx.tcx.get_attrs(did).iter().any(|attr| {
|
||||
if attr.check_name("servo_lang") && attr.value_str().map_or(false, |v| v == value) {
|
||||
mark_used(attr);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// check if a DefId's path matches the given absolute type path
|
||||
/// usage e.g. with
|
||||
/// `match_def_path(cx, id, &["core", "option", "Option"])`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue