mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
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)`
24 lines
1 KiB
Rust
24 lines
1 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* 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 syntax::ast::MetaItem;
|
|
use syntax::codemap::Span;
|
|
use syntax::ext::base::{Annotatable, ExtCtxt};
|
|
use syntax::ptr::P;
|
|
|
|
pub fn expand_dom_struct(cx: &mut ExtCtxt, sp: Span, _: &MetaItem, anno: Annotatable) -> Annotatable {
|
|
if let Annotatable::Item(item) = anno {
|
|
let mut item2 = (*item).clone();
|
|
item2.attrs.push(quote_attr!(cx, #[must_root]));
|
|
item2.attrs.push(quote_attr!(cx, #[repr(C)]));
|
|
item2.attrs.push(quote_attr!(cx, #[derive(JSTraceable)]));
|
|
item2.attrs.push(quote_attr!(cx, #[derive(HeapSizeOf)]));
|
|
item2.attrs.push(quote_attr!(cx, #[derive(DenyPublicFields)]));
|
|
item2.attrs.push(quote_attr!(cx, #[derive(DomObject)]));
|
|
Annotatable::Item(P(item2))
|
|
} else {
|
|
cx.span_err(sp, "#[dom_struct] applied to something other than a struct");
|
|
anno
|
|
}
|
|
}
|