mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 07:10:29 +00:00
Improve span of errors on impls of type with lifetimes
This commit is contained in:
parent
fedc63bfb7
commit
eb55cee41e
@ -1138,7 +1138,7 @@ fn expand_rust_box(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl
|
||||
let local_dealloc = format_ident!("{}dealloc", local_prefix);
|
||||
let local_drop = format_ident!("{}drop", local_prefix);
|
||||
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(explicit_impl, resolve);
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
|
||||
|
||||
let begin_span =
|
||||
explicit_impl.map_or_else(Span::call_site, |explicit| explicit.impl_token.span);
|
||||
@ -1187,7 +1187,7 @@ fn expand_rust_vec(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl
|
||||
let local_reserve_total = format_ident!("{}reserve_total", local_prefix);
|
||||
let local_set_len = format_ident!("{}set_len", local_prefix);
|
||||
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(explicit_impl, resolve);
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
|
||||
|
||||
let begin_span =
|
||||
explicit_impl.map_or_else(Span::call_site, |explicit| explicit.impl_token.span);
|
||||
@ -1251,7 +1251,7 @@ fn expand_unique_ptr(
|
||||
let link_release = format!("{}release", prefix);
|
||||
let link_drop = format!("{}drop", prefix);
|
||||
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(explicit_impl, resolve);
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
|
||||
|
||||
let can_construct_from_value = types.structs.contains_key(ident)
|
||||
|| types.enums.contains_key(ident)
|
||||
@ -1348,7 +1348,7 @@ fn expand_shared_ptr(
|
||||
let link_get = format!("{}get", prefix);
|
||||
let link_drop = format!("{}drop", prefix);
|
||||
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(explicit_impl, resolve);
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
|
||||
|
||||
let can_construct_from_value = types.structs.contains_key(ident)
|
||||
|| types.enums.contains_key(ident)
|
||||
@ -1427,7 +1427,7 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl
|
||||
let link_upgrade = format!("{}upgrade", prefix);
|
||||
let link_drop = format!("{}drop", prefix);
|
||||
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(explicit_impl, resolve);
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
|
||||
|
||||
let begin_span =
|
||||
explicit_impl.map_or_else(Span::call_site, |explicit| explicit.impl_token.span);
|
||||
@ -1505,7 +1505,7 @@ fn expand_cxx_vector(
|
||||
let link_unique_ptr_release = format!("{}release", unique_ptr_prefix);
|
||||
let link_unique_ptr_drop = format!("{}drop", unique_ptr_prefix);
|
||||
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(explicit_impl, resolve);
|
||||
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
|
||||
|
||||
let begin_span =
|
||||
explicit_impl.map_or_else(Span::call_site, |explicit| explicit.impl_token.span);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::syntax::instantiate::NamedImplKey;
|
||||
use crate::syntax::resolve::Resolution;
|
||||
use crate::syntax::Impl;
|
||||
use proc_macro2::TokenStream;
|
||||
@ -9,11 +10,13 @@ pub struct ImplGenerics<'a> {
|
||||
}
|
||||
|
||||
pub struct TyGenerics<'a> {
|
||||
key: NamedImplKey<'a>,
|
||||
explicit_impl: Option<&'a Impl>,
|
||||
resolve: Resolution<'a>,
|
||||
}
|
||||
|
||||
pub fn split_for_impl<'a>(
|
||||
key: NamedImplKey<'a>,
|
||||
explicit_impl: Option<&'a Impl>,
|
||||
resolve: Resolution<'a>,
|
||||
) -> (ImplGenerics<'a>, TyGenerics<'a>) {
|
||||
@ -22,6 +25,7 @@ pub fn split_for_impl<'a>(
|
||||
resolve,
|
||||
};
|
||||
let ty_generics = TyGenerics {
|
||||
key,
|
||||
explicit_impl,
|
||||
resolve,
|
||||
};
|
||||
@ -43,7 +47,9 @@ impl<'a> ToTokens for TyGenerics<'a> {
|
||||
if let Some(imp) = self.explicit_impl {
|
||||
imp.ty_generics.to_tokens(tokens);
|
||||
} else {
|
||||
self.resolve.generics.to_tokens(tokens);
|
||||
self.key.lt_token.to_tokens(tokens);
|
||||
self.resolve.generics.lifetimes.to_tokens(tokens);
|
||||
self.key.gt_token.to_tokens(tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,11 @@ error[E0117]: only traits defined in the current crate can be implemented for ar
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
--> $DIR/nonlocal_rust_type.rs:7:1
|
||||
|
|
||||
7 | #[cxx::bridge]
|
||||
| ^^^^^^^^^^^^^^ impl doesn't use only types from inside the current crate
|
||||
7 | #[cxx::bridge]
|
||||
| ^^^^^^^^^^^^^^ impl doesn't use only types from inside the current crate
|
||||
...
|
||||
10 | type OptBuilder<'a>;
|
||||
| ___________________________-
|
||||
11 | | }
|
||||
12 | |
|
||||
13 | | struct MyBuilder<'a> {
|
||||
14 | | rs: Box<OptBuilder<'a>>,
|
||||
| |__________________________- `Option` is not defined in the current crate
|
||||
14 | rs: Box<OptBuilder<'a>>,
|
||||
| --------------- `Option` is not defined in the current crate
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
Loading…
Reference in New Issue
Block a user