|
| 1 | +From bd43c2d63ed843668fe8cbc1b7cf4c3f67f4a9da Mon Sep 17 00:00:00 2001 |
| 2 | +From: Martin Jansa < [email protected]> |
| 3 | +Date: Wed, 16 Aug 2023 19:56:58 +0200 |
| 4 | +Subject: [PATCH] Backport D83816 to fix build with newer rust |
| 5 | + |
| 6 | +Upstream-Status: Backport [https://hg.mozilla.org/mozilla-central/rev/da77d5528a08] |
| 7 | +--- |
| 8 | + servo/components/derive_common/cg.rs | 22 +++++++++---------- |
| 9 | + .../style_derive/to_computed_value.rs | 4 +++- |
| 10 | + 2 files changed, 14 insertions(+), 12 deletions(-) |
| 11 | + |
| 12 | +diff --git a/servo/components/derive_common/cg.rs b/servo/components/derive_common/cg.rs |
| 13 | +index 7a8fbc2440..f66b7cde19 100644 |
| 14 | +--- a/servo/components/derive_common/cg.rs |
| 15 | ++++ b/servo/components/derive_common/cg.rs |
| 16 | +@@ -131,19 +131,19 @@ pub fn fmap_trait_output(input: &DeriveInput, trait_path: &Path, trait_output: & |
| 17 | + segment.into() |
| 18 | + } |
| 19 | + |
| 20 | +-pub fn map_type_params<F>(ty: &Type, params: &[&TypeParam], f: &mut F) -> Type |
| 21 | ++pub fn map_type_params<F>(ty: &Type, params: &[&TypeParam], self_type: &Path, f: &mut F) -> Type |
| 22 | + where |
| 23 | + F: FnMut(&Ident) -> Type, |
| 24 | + { |
| 25 | + match *ty { |
| 26 | + Type::Slice(ref inner) => Type::from(TypeSlice { |
| 27 | +- elem: Box::new(map_type_params(&inner.elem, params, f)), |
| 28 | ++ elem: Box::new(map_type_params(&inner.elem, params, self_type, f)), |
| 29 | + ..inner.clone() |
| 30 | + }), |
| 31 | + Type::Array(ref inner) => { |
| 32 | + //ref ty, ref expr) => { |
| 33 | + Type::from(TypeArray { |
| 34 | +- elem: Box::new(map_type_params(&inner.elem, params, f)), |
| 35 | ++ elem: Box::new(map_type_params(&inner.elem, params, self_type, f)), |
| 36 | + ..inner.clone() |
| 37 | + }) |
| 38 | + }, |
| 39 | +@@ -152,7 +152,7 @@ where |
| 40 | + elems: inner |
| 41 | + .elems |
| 42 | + .iter() |
| 43 | +- .map(|ty| map_type_params(&ty, params, f)) |
| 44 | ++ .map(|ty| map_type_params(&ty, params, self_type, f)) |
| 45 | + .collect(), |
| 46 | + ..inner.clone() |
| 47 | + }), |
| 48 | +@@ -167,7 +167,7 @@ where |
| 49 | + } |
| 50 | + Type::from(TypePath { |
| 51 | + qself: None, |
| 52 | +- path: map_type_params_in_path(path, params, f), |
| 53 | ++ path: map_type_params_in_path(path, params, self_type, f), |
| 54 | + }) |
| 55 | + }, |
| 56 | + Type::Path(TypePath { |
| 57 | +@@ -175,21 +175,21 @@ where |
| 58 | + ref path, |
| 59 | + }) => Type::from(TypePath { |
| 60 | + qself: qself.as_ref().map(|qself| QSelf { |
| 61 | +- ty: Box::new(map_type_params(&qself.ty, params, f)), |
| 62 | ++ ty: Box::new(map_type_params(&qself.ty, params, self_type, f)), |
| 63 | + position: qself.position, |
| 64 | + ..qself.clone() |
| 65 | + }), |
| 66 | +- path: map_type_params_in_path(path, params, f), |
| 67 | ++ path: map_type_params_in_path(path, params, self_type, f), |
| 68 | + }), |
| 69 | + Type::Paren(ref inner) => Type::from(TypeParen { |
| 70 | +- elem: Box::new(map_type_params(&inner.elem, params, f)), |
| 71 | ++ elem: Box::new(map_type_params(&inner.elem, params, self_type, f)), |
| 72 | + ..inner.clone() |
| 73 | + }), |
| 74 | + ref ty => panic!("type {:?} cannot be mapped yet", ty), |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +-fn map_type_params_in_path<F>(path: &Path, params: &[&TypeParam], f: &mut F) -> Path |
| 79 | ++fn map_type_params_in_path<F>(path: &Path, params: &[&TypeParam], self_type: &Path, f: &mut F) -> Path |
| 80 | + where |
| 81 | + F: FnMut(&Ident) -> Type, |
| 82 | + { |
| 83 | +@@ -209,11 +209,11 @@ where |
| 84 | + .map(|arg| match arg { |
| 85 | + ty @ &GenericArgument::Lifetime(_) => ty.clone(), |
| 86 | + &GenericArgument::Type(ref data) => { |
| 87 | +- GenericArgument::Type(map_type_params(data, params, f)) |
| 88 | ++ GenericArgument::Type(map_type_params(data, params, self_type, f)) |
| 89 | + }, |
| 90 | + &GenericArgument::Binding(ref data) => { |
| 91 | + GenericArgument::Binding(Binding { |
| 92 | +- ty: map_type_params(&data.ty, params, f), |
| 93 | ++ ty: map_type_params(&data.ty, params, self_type, f), |
| 94 | + ..data.clone() |
| 95 | + }) |
| 96 | + }, |
| 97 | +diff --git a/servo/components/style_derive/to_computed_value.rs b/servo/components/style_derive/to_computed_value.rs |
| 98 | +index ed6e07a2f5..c9b3b70051 100644 |
| 99 | +--- a/servo/components/style_derive/to_computed_value.rs |
| 100 | ++++ b/servo/components/style_derive/to_computed_value.rs |
| 101 | +@@ -58,6 +58,8 @@ pub fn derive_to_value( |
| 102 | + cg::add_predicate(&mut where_clause, parse_quote!(#param: #trait_path)); |
| 103 | + } |
| 104 | + |
| 105 | ++ let computed_value_type = cg::fmap_trait_output(&input, &trait_path, &output_type_name); |
| 106 | ++ |
| 107 | + let to_body = cg::fmap_match(&input, bind_style, |binding| { |
| 108 | + if field_bound(&binding) { |
| 109 | + let ty = &binding.ast().ty; |
| 110 | +@@ -65,6 +67,7 @@ pub fn derive_to_value( |
| 111 | + let output_type = cg::map_type_params( |
| 112 | + ty, |
| 113 | + ¶ms, |
| 114 | ++ &computed_value_type, |
| 115 | + &mut |ident| parse_quote!(<#ident as #trait_path>::#output_type_name), |
| 116 | + ); |
| 117 | + |
| 118 | +@@ -84,7 +87,6 @@ pub fn derive_to_value( |
| 119 | + |
| 120 | + input.generics.where_clause = where_clause; |
| 121 | + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); |
| 122 | +- let computed_value_type = cg::fmap_trait_output(&input, &trait_path, &output_type_name); |
| 123 | + |
| 124 | + let impl_ = trait_impl(from_body, to_body); |
| 125 | + |
0 commit comments