WIP-9999999-cssparserfix-25318.patch 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. # HG changeset patch
  2. # User Frank-Rainer Grahl <frgrahl@gmx.net>
  3. # Date 1643851534 -3600
  4. # Parent c920992f4fe36435f52aed1f1b4eb86c2886b0ce
  5. Bug 9999999 - Fix cssparser for later rust versions. r=me a=me.
  6. diff --git a/Cargo.lock b/Cargo.lock
  7. --- a/Cargo.lock
  8. +++ b/Cargo.lock
  9. @@ -344,17 +344,16 @@ checksum = "2760899e32a1d58d5abb31129f8f
  10. dependencies = [
  11. "cfg-if 0.1.10",
  12. ]
  13. [[package]]
  14. name = "cssparser"
  15. version = "0.23.9"
  16. source = "registry+https://github.com/rust-lang/crates.io-index"
  17. -checksum = "205647ffe2b63a9726a4c3bb6f31c7325e8ceff10e2f1b75a6fb7609e20419ea"
  18. dependencies = [
  19. "cssparser-macros",
  20. "dtoa-short",
  21. "itoa 0.4.1",
  22. "matches",
  23. "phf",
  24. "proc-macro2 0.3.6",
  25. "procedural-masquerade",
  26. diff --git a/Cargo.toml b/Cargo.toml
  27. --- a/Cargo.toml
  28. +++ b/Cargo.toml
  29. @@ -49,8 +49,9 @@ rpath = false
  30. debug-assertions = false
  31. panic = "abort"
  32. codegen-units = 1
  33. [patch.crates-io]
  34. libudev-sys = { path = "dom/webauthn/libudev-sys" }
  35. serde_derive = { git = "https://github.com/servo/serde", branch = "deserialize_from_enums6" }
  36. packed_simd = { package = "packed_simd_2", git = "https://github.com/hsivonen/packed_simd", rev="412f9a0aa556611de021bde89dee8fefe6e0fbbd" }
  37. +cssparser = { path = "third_party/myrust/cssparser" }
  38. diff --git a/servo/components/selectors/lib.rs b/servo/components/selectors/lib.rs
  39. --- a/servo/components/selectors/lib.rs
  40. +++ b/servo/components/selectors/lib.rs
  41. @@ -1,14 +1,15 @@
  42. /* This Source Code Form is subject to the terms of the Mozilla Public
  43. * License, v. 2.0. If a copy of the MPL was not distributed with this
  44. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  45. // Make |cargo bench| work.
  46. #![cfg_attr(feature = "bench", feature(test))]
  47. +#![warn(proc_macro_back_compat)]
  48. #[macro_use] extern crate bitflags;
  49. #[macro_use] extern crate cssparser;
  50. #[macro_use] extern crate log;
  51. #[macro_use] extern crate matches;
  52. extern crate fnv;
  53. extern crate phf;
  54. extern crate precomputed_hash;
  55. diff --git a/servo/components/style_traits/lib.rs b/servo/components/style_traits/lib.rs
  56. --- a/servo/components/style_traits/lib.rs
  57. +++ b/servo/components/style_traits/lib.rs
  58. @@ -5,16 +5,17 @@
  59. //! This module contains shared types and messages for use by devtools/script.
  60. //! The traits are here instead of in script so that the devtools crate can be
  61. //! modified independently of the rest of Servo.
  62. #![crate_name = "style_traits"]
  63. #![crate_type = "rlib"]
  64. #![deny(unsafe_code, missing_docs)]
  65. +#![warn(proc_macro_back_compat)]
  66. extern crate app_units;
  67. #[macro_use] extern crate bitflags;
  68. #[macro_use] extern crate cssparser;
  69. extern crate euclid;
  70. extern crate malloc_size_of;
  71. #[macro_use] extern crate malloc_size_of_derive;
  72. extern crate selectors;
  73. diff --git a/servo/components/style_traits/values.rs b/servo/components/style_traits/values.rs
  74. --- a/servo/components/style_traits/values.rs
  75. +++ b/servo/components/style_traits/values.rs
  76. @@ -131,16 +131,17 @@ where
  77. self.inner.write_str(prefix)?;
  78. }
  79. }
  80. self.inner.write_char(c)
  81. }
  82. }
  83. #[macro_export]
  84. +/// Make rust happy
  85. macro_rules! serialize_function {
  86. ($dest: expr, $name: ident($( $arg: expr, )+)) => {
  87. serialize_function!($dest, $name($($arg),+))
  88. };
  89. ($dest: expr, $name: ident($first_arg: expr $( , $arg: expr )*)) => {
  90. {
  91. $dest.write_str(concat!(stringify!($name), "("))?;
  92. $first_arg.to_css($dest)?;
  93. diff --git a/third_party/rust/cssparser/.cargo-checksum.json b/third_party/myrust/cssparser/.cargo-checksum.json
  94. rename from third_party/rust/cssparser/.cargo-checksum.json
  95. rename to third_party/myrust/cssparser/.cargo-checksum.json
  96. diff --git a/third_party/rust/cssparser/Cargo.toml b/third_party/myrust/cssparser/Cargo.toml
  97. rename from third_party/rust/cssparser/Cargo.toml
  98. rename to third_party/myrust/cssparser/Cargo.toml
  99. diff --git a/third_party/rust/cssparser/LICENSE b/third_party/myrust/cssparser/LICENSE
  100. rename from third_party/rust/cssparser/LICENSE
  101. rename to third_party/myrust/cssparser/LICENSE
  102. diff --git a/third_party/rust/cssparser/README.md b/third_party/myrust/cssparser/README.md
  103. rename from third_party/rust/cssparser/README.md
  104. rename to third_party/myrust/cssparser/README.md
  105. diff --git a/third_party/rust/cssparser/build.rs b/third_party/myrust/cssparser/build.rs
  106. rename from third_party/rust/cssparser/build.rs
  107. rename to third_party/myrust/cssparser/build.rs
  108. diff --git a/third_party/rust/cssparser/build/match_byte.rs b/third_party/myrust/cssparser/build/match_byte.rs
  109. rename from third_party/rust/cssparser/build/match_byte.rs
  110. rename to third_party/myrust/cssparser/build/match_byte.rs
  111. diff --git a/third_party/rust/cssparser/docs/404.html b/third_party/myrust/cssparser/docs/404.html
  112. rename from third_party/rust/cssparser/docs/404.html
  113. rename to third_party/myrust/cssparser/docs/404.html
  114. diff --git a/third_party/rust/cssparser/docs/index.html b/third_party/myrust/cssparser/docs/index.html
  115. rename from third_party/rust/cssparser/docs/index.html
  116. rename to third_party/myrust/cssparser/docs/index.html
  117. diff --git a/third_party/rust/cssparser/src/color.rs b/third_party/myrust/cssparser/src/color.rs
  118. rename from third_party/rust/cssparser/src/color.rs
  119. rename to third_party/myrust/cssparser/src/color.rs
  120. --- a/third_party/rust/cssparser/src/color.rs
  121. +++ b/third_party/myrust/cssparser/src/color.rs
  122. @@ -514,19 +514,19 @@ pub fn parse_color_keyword(ident: &str)
  123. }
  124. keyword(ident).cloned().ok_or(())
  125. }
  126. #[inline]
  127. fn from_hex(c: u8) -> Result<u8, ()> {
  128. match c {
  129. - b'0' ... b'9' => Ok(c - b'0'),
  130. - b'a' ... b'f' => Ok(c - b'a' + 10),
  131. - b'A' ... b'F' => Ok(c - b'A' + 10),
  132. + b'0' ..= b'9' => Ok(c - b'0'),
  133. + b'a' ..= b'f' => Ok(c - b'a' + 10),
  134. + b'A' ..= b'F' => Ok(c - b'A' + 10),
  135. _ => Err(())
  136. }
  137. }
  138. fn clamp_unit_f32(val: f32) -> u8 {
  139. // Whilst scaling by 256 and flooring would provide
  140. // an equal distribution of integers to percentage inputs,
  141. // this is not what Gecko does so we instead multiply by 255
  142. diff --git a/third_party/rust/cssparser/src/cow_rc_str.rs b/third_party/myrust/cssparser/src/cow_rc_str.rs
  143. rename from third_party/rust/cssparser/src/cow_rc_str.rs
  144. rename to third_party/myrust/cssparser/src/cow_rc_str.rs
  145. diff --git a/third_party/rust/cssparser/src/from_bytes.rs b/third_party/myrust/cssparser/src/from_bytes.rs
  146. rename from third_party/rust/cssparser/src/from_bytes.rs
  147. rename to third_party/myrust/cssparser/src/from_bytes.rs
  148. diff --git a/third_party/rust/cssparser/src/lib.rs b/third_party/myrust/cssparser/src/lib.rs
  149. rename from third_party/rust/cssparser/src/lib.rs
  150. rename to third_party/myrust/cssparser/src/lib.rs
  151. --- a/third_party/rust/cssparser/src/lib.rs
  152. +++ b/third_party/myrust/cssparser/src/lib.rs
  153. @@ -2,17 +2,17 @@
  154. * License, v. 2.0. If a copy of the MPL was not distributed with this
  155. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  156. #![crate_name = "cssparser"]
  157. #![crate_type = "rlib"]
  158. #![cfg_attr(feature = "bench", feature(test))]
  159. #![deny(missing_docs)]
  160. -
  161. +#![warn(proc_macro_back_compat)]
  162. /*!
  163. Implementation of [CSS Syntax Module Level 3](https://drafts.csswg.org/css-syntax/) for Rust.
  164. # Input
  165. Everything is based on `Parser` objects, which borrow a `&str` input.
  166. If you have bytes (from a file, the network, or something)
  167. diff --git a/third_party/rust/cssparser/src/macros.rs b/third_party/myrust/cssparser/src/macros.rs
  168. rename from third_party/rust/cssparser/src/macros.rs
  169. rename to third_party/myrust/cssparser/src/macros.rs
  170. --- a/third_party/rust/cssparser/src/macros.rs
  171. +++ b/third_party/myrust/cssparser/src/macros.rs
  172. @@ -127,17 +127,17 @@ macro_rules! cssparser_internal__to_lowe
  173. /// **This function is not part of the public API. It can change or be removed between any verisons.**
  174. ///
  175. /// If `input` is larger than buffer, return `None`.
  176. /// Otherwise, return `input` ASCII-lowercased, using `buffer` as temporary space if necessary.
  177. #[doc(hidden)]
  178. #[allow(non_snake_case)]
  179. pub fn _internal__to_lowercase<'a>(buffer: &'a mut [u8], input: &'a str) -> Option<&'a str> {
  180. if let Some(buffer) = buffer.get_mut(..input.len()) {
  181. - if let Some(first_uppercase) = input.bytes().position(|byte| matches!(byte, b'A'...b'Z')) {
  182. + if let Some(first_uppercase) = input.bytes().position(|byte| matches!(byte, b'A'..=b'Z')) {
  183. buffer.copy_from_slice(input.as_bytes());
  184. ::std::ascii::AsciiExt::make_ascii_lowercase(&mut buffer[first_uppercase..]);
  185. // `buffer` was initialized to a copy of `input` (which is &str so well-formed UTF-8)
  186. // then lowercased (which preserves UTF-8 well-formedness)
  187. unsafe {
  188. Some(::std::str::from_utf8_unchecked(buffer))
  189. }
  190. } else {
  191. diff --git a/third_party/rust/cssparser/src/nth.rs b/third_party/myrust/cssparser/src/nth.rs
  192. rename from third_party/rust/cssparser/src/nth.rs
  193. rename to third_party/myrust/cssparser/src/nth.rs
  194. --- a/third_party/rust/cssparser/src/nth.rs
  195. +++ b/third_party/myrust/cssparser/src/nth.rs
  196. @@ -88,17 +88,17 @@ fn parse_signless_b<'i, 't>(input: &mut
  197. token => Err(input.new_basic_unexpected_token_error(token))
  198. }
  199. }
  200. fn parse_n_dash_digits(string: &str) -> Result<i32, ()> {
  201. let bytes = string.as_bytes();
  202. if bytes.len() >= 3
  203. && bytes[..2].eq_ignore_ascii_case(b"n-")
  204. - && bytes[2..].iter().all(|&c| matches!(c, b'0'...b'9'))
  205. + && bytes[2..].iter().all(|&c| matches!(c, b'0'..=b'9'))
  206. {
  207. Ok(parse_number_saturate(&string[1..]).unwrap()) // Include the minus sign
  208. } else {
  209. Err(())
  210. }
  211. }
  212. fn parse_number_saturate(string: &str) -> Result<i32, ()> {
  213. diff --git a/third_party/rust/cssparser/src/parser.rs b/third_party/myrust/cssparser/src/parser.rs
  214. rename from third_party/rust/cssparser/src/parser.rs
  215. rename to third_party/myrust/cssparser/src/parser.rs
  216. --- a/third_party/rust/cssparser/src/parser.rs
  217. +++ b/third_party/myrust/cssparser/src/parser.rs
  218. @@ -550,38 +550,44 @@ impl<'i: 't, 't> Parser<'i, 't> {
  219. }
  220. let byte = self.input.tokenizer.next_byte();
  221. if self.stop_before.contains(Delimiters::from_byte(byte)) {
  222. return Err(self.new_basic_error(BasicParseErrorKind::EndOfInput))
  223. }
  224. let token_start_position = self.input.tokenizer.position();
  225. - let token;
  226. - match self.input.cached_token {
  227. - Some(ref cached_token)
  228. - if cached_token.start_position == token_start_position => {
  229. - self.input.tokenizer.reset(&cached_token.end_state);
  230. - match cached_token.token {
  231. - Token::Function(ref name) => self.input.tokenizer.see_function(name),
  232. - _ => {}
  233. - }
  234. - token = &cached_token.token
  235. + let using_cached_token = self
  236. + .input
  237. + .cached_token
  238. + .as_ref()
  239. + .map_or(false, |cached_token| {
  240. + cached_token.start_position == token_start_position
  241. + });
  242. + let token = if using_cached_token {
  243. + let cached_token = self.input.cached_token.as_ref().unwrap();
  244. + self.input.tokenizer.reset(&cached_token.end_state);
  245. + match cached_token.token {
  246. + Token::Function(ref name) => self.input.tokenizer.see_function(name),
  247. + _ => {}
  248. }
  249. - _ => {
  250. - let new_token = self.input.tokenizer.next()
  251. - .map_err(|()| self.new_basic_error(BasicParseErrorKind::EndOfInput))?;
  252. - self.input.cached_token = Some(CachedToken {
  253. - token: new_token,
  254. - start_position: token_start_position,
  255. - end_state: self.input.tokenizer.state(),
  256. - });
  257. - token = self.input.cached_token_ref()
  258. - }
  259. - }
  260. + &cached_token.token
  261. + } else {
  262. + let new_token = self
  263. + .input
  264. + .tokenizer
  265. + .next()
  266. + .map_err(|()| self.new_basic_error(BasicParseErrorKind::EndOfInput))?;
  267. + self.input.cached_token = Some(CachedToken {
  268. + token: new_token,
  269. + start_position: token_start_position,
  270. + end_state: self.input.tokenizer.state(),
  271. + });
  272. + self.input.cached_token_ref()
  273. + };
  274. if let Some(block_type) = BlockType::opening(token) {
  275. self.at_start_of = Some(block_type);
  276. }
  277. Ok(token)
  278. }
  279. /// Have the given closure parse something, then check the the input is exhausted.
  280. diff --git a/third_party/rust/cssparser/src/rules_and_declarations.rs b/third_party/myrust/cssparser/src/rules_and_declarations.rs
  281. rename from third_party/rust/cssparser/src/rules_and_declarations.rs
  282. rename to third_party/myrust/cssparser/src/rules_and_declarations.rs
  283. diff --git a/third_party/rust/cssparser/src/serializer.rs b/third_party/myrust/cssparser/src/serializer.rs
  284. rename from third_party/rust/cssparser/src/serializer.rs
  285. rename to third_party/myrust/cssparser/src/serializer.rs
  286. --- a/third_party/rust/cssparser/src/serializer.rs
  287. +++ b/third_party/myrust/cssparser/src/serializer.rs
  288. @@ -175,33 +175,33 @@ pub fn serialize_identifier<W>(mut value
  289. serialize_name(&value[2..], dest)
  290. } else if value == "-" {
  291. dest.write_str("\\-")
  292. } else {
  293. if value.as_bytes()[0] == b'-' {
  294. dest.write_str("-")?;
  295. value = &value[1..];
  296. }
  297. - if let digit @ b'0'...b'9' = value.as_bytes()[0] {
  298. + if let digit @ b'0'..=b'9' = value.as_bytes()[0] {
  299. hex_escape(digit, dest)?;
  300. value = &value[1..];
  301. }
  302. serialize_name(value, dest)
  303. }
  304. }
  305. /// Write a CSS name, like a custom property name.
  306. ///
  307. /// You should only use this when you know what you're doing, when in doubt,
  308. /// consider using `serialize_identifier`.
  309. pub fn serialize_name<W>(value: &str, dest: &mut W) -> fmt::Result where W:fmt::Write {
  310. let mut chunk_start = 0;
  311. for (i, b) in value.bytes().enumerate() {
  312. let escaped = match b {
  313. - b'0'...b'9' | b'A'...b'Z' | b'a'...b'z' | b'_' | b'-' => continue,
  314. + b'0'..=b'9' | b'A'..=b'Z' | b'a'..=b'z' | b'_' | b'-' => continue,
  315. _ if !b.is_ascii() => continue,
  316. b'\0' => Some("\u{FFFD}"),
  317. _ => None,
  318. };
  319. dest.write_str(&value[chunk_start..i])?;
  320. if let Some(escaped) = escaped {
  321. dest.write_str(escaped)?;
  322. } else if (b >= b'\x01' && b <= b'\x1F') || b == b'\x7F' {
  323. @@ -214,17 +214,17 @@ pub fn serialize_name<W>(value: &str, de
  324. dest.write_str(&value[chunk_start..])
  325. }
  326. fn serialize_unquoted_url<W>(value: &str, dest: &mut W) -> fmt::Result where W:fmt::Write {
  327. let mut chunk_start = 0;
  328. for (i, b) in value.bytes().enumerate() {
  329. let hex = match b {
  330. - b'\0' ... b' ' | b'\x7F' => true,
  331. + b'\0' ..= b' ' | b'\x7F' => true,
  332. b'(' | b')' | b'"' | b'\'' | b'\\' => false,
  333. _ => continue
  334. };
  335. dest.write_str(&value[chunk_start..i])?;
  336. if hex {
  337. hex_escape(b, dest)?;
  338. } else {
  339. char_escape(b, dest)?;
  340. @@ -274,17 +274,17 @@ impl<'a, W> CssStringWriter<'a, W> where
  341. impl<'a, W> fmt::Write for CssStringWriter<'a, W> where W: fmt::Write {
  342. fn write_str(&mut self, s: &str) -> fmt::Result {
  343. let mut chunk_start = 0;
  344. for (i, b) in s.bytes().enumerate() {
  345. let escaped = match b {
  346. b'"' => Some("\\\""),
  347. b'\\' => Some("\\\\"),
  348. b'\0' => Some("\u{FFFD}"),
  349. - b'\x01'...b'\x1F' | b'\x7F' => None,
  350. + b'\x01'..=b'\x1F' | b'\x7F' => None,
  351. _ => continue,
  352. };
  353. self.inner.write_str(&s[chunk_start..i])?;
  354. match escaped {
  355. Some(x) => self.inner.write_str(x)?,
  356. None => hex_escape(b, self.inner)?,
  357. };
  358. chunk_start = i + 1;
  359. diff --git a/third_party/rust/cssparser/src/size_of_tests.rs b/third_party/myrust/cssparser/src/size_of_tests.rs
  360. rename from third_party/rust/cssparser/src/size_of_tests.rs
  361. rename to third_party/myrust/cssparser/src/size_of_tests.rs
  362. diff --git a/third_party/rust/cssparser/src/tests.rs b/third_party/myrust/cssparser/src/tests.rs
  363. rename from third_party/rust/cssparser/src/tests.rs
  364. rename to third_party/myrust/cssparser/src/tests.rs
  365. diff --git a/third_party/rust/cssparser/src/tokenizer.rs b/third_party/myrust/cssparser/src/tokenizer.rs
  366. rename from third_party/rust/cssparser/src/tokenizer.rs
  367. rename to third_party/myrust/cssparser/src/tokenizer.rs
  368. diff --git a/third_party/rust/cssparser/src/unicode_range.rs b/third_party/myrust/cssparser/src/unicode_range.rs
  369. rename from third_party/rust/cssparser/src/unicode_range.rs
  370. rename to third_party/myrust/cssparser/src/unicode_range.rs