Skip to content

Commit 23adc62

Browse files
committed
Fix dependent type generation
1 parent cb86b83 commit 23adc62

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

binding-generator/src/type_ref.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,18 +1513,20 @@ impl<'tu> TypeRef<'tu> {
15131513
// vector<std::string> if not - both.
15141514
let vec_cv_string = self.gen_env.resolve_type("std::vector<cv::String>").expect("Can't resolve std::vector<cv::String>");
15151515
let vec_std_string = self.gen_env.resolve_type("std::vector<std::string>").expect("Can't resolve std::vector<std::string>");
1516-
let vec_type_ref = if vec_cv_string.get_canonical_type() == vec_std_string.get_canonical_type() {
1517-
TypeRef::new(vec_std_string, self.gen_env)
1518-
} else {
1519-
vec.type_ref()
1520-
};
1521-
let const_hint = self.get_const_hint(&vec_type_ref);
1522-
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new_ext(
1523-
vec_type_ref,
1524-
const_hint,
1525-
DefinitionLocation::Module,
1526-
self.gen_env,
1527-
)));
1516+
if let DependentTypeMode::ForReturn(def_location) = mode {
1517+
let vec_type_ref = if vec_cv_string.get_canonical_type() == vec_std_string.get_canonical_type() {
1518+
TypeRef::new(vec_std_string, self.gen_env)
1519+
} else {
1520+
vec.type_ref()
1521+
};
1522+
let const_hint = self.get_const_hint(&vec_type_ref);
1523+
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new_ext(
1524+
vec_type_ref,
1525+
const_hint,
1526+
def_location,
1527+
self.gen_env,
1528+
)));
1529+
}
15281530
// implement workaround for race when type with std::string gets generated first
15291531
// we only want vector<cv::String> because it's more compatible across OpenCV versions
15301532
if str_type == StrType::StdString {
@@ -1537,28 +1539,31 @@ impl<'tu> TypeRef<'tu> {
15371539
out.push(D::from_vector(vec))
15381540
}
15391541
} else {
1540-
let vec_type_ref = vec.type_ref().canonical_clang();
1541-
let const_hint = self.get_const_hint(&vec_type_ref);
1542-
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new_ext(
1543-
vec_type_ref,
1544-
const_hint,
1545-
DefinitionLocation::Module,
1546-
self.gen_env,
1547-
)));
1542+
if let DependentTypeMode::ForReturn(def_location) = mode {
1543+
let vec_type_ref = vec.type_ref().canonical_clang();
1544+
let const_hint = self.get_const_hint(&vec_type_ref);
1545+
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new_ext(
1546+
vec_type_ref,
1547+
const_hint,
1548+
def_location,
1549+
self.gen_env,
1550+
)));
1551+
}
15481552
out.push(D::from_vector(vec));
15491553
}
15501554
},
15511555
Kind::SmartPtr(ptr) => {
15521556
out = ptr.dependent_types();
1553-
out.reserve(2);
1554-
let ptr_type_ref = ptr.type_ref().canonical_clang();
1555-
let const_hint = self.get_const_hint(&ptr_type_ref);
1556-
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new_ext(
1557-
ptr_type_ref,
1558-
const_hint,
1559-
DefinitionLocation::Module,
1560-
self.gen_env,
1561-
)));
1557+
if let DependentTypeMode::ForReturn(def_location) = mode {
1558+
let ptr_type_ref = ptr.type_ref().canonical_clang();
1559+
let const_hint = self.get_const_hint(&ptr_type_ref);
1560+
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new_ext(
1561+
ptr_type_ref,
1562+
const_hint,
1563+
def_location,
1564+
self.gen_env,
1565+
)));
1566+
}
15621567
out.push(D::from_smart_ptr(ptr))
15631568
},
15641569
Kind::Typedef(typedef) => {

binding-generator/src/vector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'tu> Vector<'tu> {
6161
self.gen_env,
6262
)));
6363
} else {
64-
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new(element_type.canonical_clang(), DefinitionLocation::Type, self.gen_env)));
64+
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new(element_type.canonical_clang(), DefinitionLocation::Module, self.gen_env)));
6565
}
6666
if is_data_type {
6767
out.push(D::from_return_type_wrapper(ReturnTypeWrapper::new(

0 commit comments

Comments
 (0)