servo: Merge #18340 - Use the better TokenStream API in dom_struct (from servo:dom-struct-errors); r=SimonSapin
authorAnthony Ramine <n.oxyde@gmail.com>
Sat, 02 Sep 2017 00:48:29 -0500
changeset 427929 230d2e70112d007d0f00711030c66ed7c295c314
parent 427928 820cb0437789ef1d3c2aa054e803fa0203b45090
child 427930 7c4c81a8b6996831b41b7a4865a7d7d04188887a
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersSimonSapin
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #18340 - Use the better TokenStream API in dom_struct (from servo:dom-struct-errors); r=SimonSapin Before: ```rust error[E0412]: cannot find type `SourceBuffer` in this scope --> /Users/nox/src/servo/components/script/dom/mediasource.rs:25:1 | 25 | #[dom_struct] | ^^^^^^^^^^^^^ did you mean `SourceBufferList`? ``` After: ```rust error[E0412]: cannot find type `SourceBuffer` in this scope --> /Users/nox/src/servo/components/script/dom/mediasource.rs:28:39 | 28 | source_buffers: DOMRefCell<Vec<JS<SourceBuffer>>>, | ^^^^^^^^^^^^ did you mean `SourceBufferList`? ``` Source-Repo: https://github.com/servo/servo Source-Revision: 32b04b3f517cebcba34a23e6930860bbedb1431b
servo/Cargo.lock
servo/components/dom_struct/Cargo.toml
servo/components/dom_struct/lib.rs
--- a/servo/Cargo.lock
+++ b/servo/Cargo.lock
@@ -738,19 +738,16 @@ dependencies = [
  "serde 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "servo_url 0.0.1",
  "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "dom_struct"
 version = "0.0.1"
-dependencies = [
- "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
-]
 
 [[package]]
 name = "domobject_derive"
 version = "0.0.1"
 dependencies = [
  "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
--- a/servo/components/dom_struct/Cargo.toml
+++ b/servo/components/dom_struct/Cargo.toml
@@ -3,11 +3,8 @@ name = "dom_struct"
 version = "0.0.1"
 authors = ["The Servo Project Developers"]
 license = "MPL-2.0"
 publish = false
 
 [lib]
 path = "lib.rs"
 proc-macro = true
-
-[dependencies]
-quote = "0.3.15"
--- a/servo/components/dom_struct/lib.rs
+++ b/servo/components/dom_struct/lib.rs
@@ -1,28 +1,23 @@
 /* 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/. */
 
 #![feature(proc_macro)]
 
 extern crate proc_macro;
-#[macro_use] extern crate quote;
 
-use proc_macro::TokenStream;
+use proc_macro::{TokenStream, quote};
+use std::iter;
 
 #[proc_macro_attribute]
 pub fn dom_struct(args: TokenStream, input: TokenStream) -> TokenStream {
-    if !args.to_string().is_empty() {
+    if !args.is_empty() {
         panic!("#[dom_struct] takes no arguments");
     }
-    expand_string(&input.to_string()).parse().unwrap()
-}
-
-fn expand_string(input: &str) -> String {
-    let mut tokens = quote! {
+    let attributes = quote! {
         #[derive(DenyPublicFields, DomObject, HeapSizeOf, JSTraceable)]
         #[must_root]
         #[repr(C)]
     };
-    tokens.append(input);
-    tokens.to_string()
+    iter::once(attributes).chain(iter::once(input)).collect()
 }