Skip to content

Commit 7672ce9

Browse files
committed
Touch up PR 1681
1 parent 7b522fe commit 7672ce9

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

macro/src/generics.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::syntax::instantiate::NamedImplKey;
33
use crate::syntax::types::ConditionalImpl;
44
use crate::syntax::{Lifetimes, Type, Types};
55
use proc_macro2::TokenStream;
6-
use quote::{quote_spanned, ToTokens};
6+
use quote::{quote, ToTokens};
77
use syn::{Lifetime, Token};
88

99
pub(crate) struct ResolvedGenericType<'a> {
@@ -62,13 +62,12 @@ impl<'a> ToTokens for ResolvedGenericType<'a> {
6262
}
6363
}
6464
Type::RustBox(ty1) => {
65-
let span = ty1.name.span();
6665
let inner = ResolvedGenericType {
6766
ty: &ty1.inner,
6867
explicit_impl: self.explicit_impl,
6968
types: self.types,
7069
};
71-
tokens.extend(quote_spanned! {span=>
70+
tokens.extend(quote! {
7271
::cxx::alloc::boxed::Box<#inner>
7372
});
7473
}
@@ -77,7 +76,7 @@ impl<'a> ToTokens for ResolvedGenericType<'a> {
7776
}
7877
}
7978

80-
fn get_impl_generics<'a>(ty: &Type, types: &'a Types<'a>) -> &'a Lifetimes {
79+
fn get_impl_generics<'a>(ty: &Type, types: &Types<'a>) -> &'a Lifetimes {
8180
match ty {
8281
Type::Ident(named_type) => types.resolve(named_type).generics,
8382
Type::RustBox(ty1) => get_impl_generics(&ty1.inner, types),
@@ -88,16 +87,14 @@ fn get_impl_generics<'a>(ty: &Type, types: &'a Types<'a>) -> &'a Lifetimes {
8887
pub(crate) fn format_for_prevent_unwind_label(ty: &Type) -> TokenStream {
8988
match ty {
9089
Type::Ident(named_type) => {
91-
let span = named_type.rust.span();
9290
let rust_name = named_type.rust.to_string();
93-
quote_spanned! {span=>
91+
quote! {
9492
::cxx::core::concat!(::cxx::core::module_path!(), "::", #rust_name)
9593
}
9694
}
9795
Type::RustBox(ty1) => {
98-
let span = ty1.name.span();
9996
let inner = format_for_prevent_unwind_label(&ty1.inner);
100-
quote_spanned! {span=>
97+
quote! {
10198
::cxx::core::concat!("Box<", #inner, ">")
10299
}
103100
}

macro/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,14 @@ fn test_vec_of_box() {
168168
}
169169
}
170170
});
171+
171172
assert!(rs.contains("unsafe impl ::cxx::private::ImplBox for R {}"));
172173
assert!(rs.contains("export_name = \"cxxbridge1$box$R$drop\""));
173174

174-
assert!(rs.contains("unsafe impl ::cxx::private::ImplVec for ::cxx::alloc::boxed::Box<R> {}"),);
175+
assert!(rs.contains("unsafe impl ::cxx::private::ImplVec for ::cxx::alloc::boxed::Box<R> {}"));
175176
assert!(rs.contains("export_name = \"cxxbridge1$rust_vec$box$R$set_len\""));
176177

177-
// Covering these lines, because an early WIP incorrectly said
178-
// `RustVec<*mut R>` instead of `RustVec<Box<R>>` in *some* of these lines.
178+
// Not supposed to be `RustVec<*mut R>` (which happened in an early draft).
179179
assert!(rs.contains("__return: *mut ::cxx::private::RustVec<::cxx::alloc::boxed::Box<R>>"));
180180
assert!(rs.contains("fn __foo() -> ::cxx::alloc::vec::Vec<::cxx::alloc::boxed::Box<R>>"));
181181
}

syntax/types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ impl<'a> Types<'a> {
338338
|| self.aliases.contains_key(ident)
339339
}
340340
Type::CxxVector(_) => false,
341-
// Note: `Type::RustBox(_)` cannot be used as an inner type of
342-
// `CxxVector`, `UniquePtr`, nor `SharedPtr`.
341+
// No other type can appear as the inner type of CxxVector,
342+
// UniquePtr, or SharedPtr.
343343
_ => unreachable!("syntax/check.rs should reject other types"),
344344
}
345345
}
@@ -374,9 +374,9 @@ impl<'a> Types<'a> {
374374
Atom::from(&ident.rust).is_none() && !self.aliases.contains_key(&ident.rust)
375375
}
376376
Type::RustBox(ty1) => {
377-
// From Rust reference [1]: "Any time a type T is considered local [...]
378-
// Box<T> [... is] also considered local."
379-
// [1] https://doc.rust-lang.org/reference/glossary.html#fundamental-type-constructors
377+
// https://doc.rust-lang.org/reference/glossary.html#fundamental-type-constructors
378+
// "Any time a type T is considered local [...] Box<T> [... is]
379+
// also considered local."
380380
self.is_local(&ty1.inner)
381381
}
382382
Type::Array(_)

0 commit comments

Comments
 (0)