Skip to content

Commit

Permalink
Deny returning owned slices (rust-diplomat#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Jul 19, 2024
1 parent f922f89 commit bd491cb
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 141 deletions.
21 changes: 14 additions & 7 deletions core/src/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,14 @@ impl<'ast> LoweringContext<'ast> {
));
Err(())
}
ast::TypeName::StrReference(lifetime, encoding) => Ok(OutType::Slice(Slice::Str(
lifetime.as_ref().map(|l| ltl.lower_lifetime(l)),
ast::TypeName::PrimitiveSlice(None, _) | ast::TypeName::StrReference(None, _) => {
self.errors.push(LoweringError::Other(
"Owned slices cannot be returned".into(),
));
Err(())
}
ast::TypeName::StrReference(Some(l), encoding) => Ok(OutType::Slice(Slice::Str(
Some(ltl.lower_lifetime(l)),
*encoding,
))),
ast::TypeName::StrSlice(..) => {
Expand All @@ -934,11 +940,12 @@ impl<'ast> LoweringContext<'ast> {
));
Err(())
}
ast::TypeName::PrimitiveSlice(lm, prim) => Ok(OutType::Slice(Slice::Primitive(
lm.as_ref()
.map(|(lt, m)| Borrow::new(ltl.lower_lifetime(lt), *m)),
PrimitiveType::from_ast(*prim),
))),
ast::TypeName::PrimitiveSlice(Some((lt, m)), prim) => {
Ok(OutType::Slice(Slice::Primitive(
Some(Borrow::new(ltl.lower_lifetime(lt), *m)),
PrimitiveType::from_ast(*prim),
)))
}
ast::TypeName::Unit => {
self.errors.push(LoweringError::Other("Unit types can only appear as the return value of a method, or as the Ok/Err variants of a returned result".into()));
Err(())
Expand Down
2 changes: 0 additions & 2 deletions feature_tests/c/include/Float64Vec.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/c/include/MyString.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions feature_tests/c/include/Utf16Wrap.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions feature_tests/cpp/include/Float64Vec.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions feature_tests/cpp/include/Float64Vec.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/cpp/include/MyString.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions feature_tests/cpp/include/MyString.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions feature_tests/cpp/include/Utf16Wrap.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions feature_tests/cpp/include/Utf16Wrap.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions feature_tests/dart/lib/src/Float64Vec.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions feature_tests/dart/lib/src/MyString.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions feature_tests/dart/lib/src/Utf16Wrap.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions feature_tests/js/api/Float64Vec.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions feature_tests/js/api/Float64Vec.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion feature_tests/js/api/MyString.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions feature_tests/js/api/MyString.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions feature_tests/js/api/Utf16Wrap.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions feature_tests/js/api/Utf16Wrap.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bd491cb

Please sign in to comment.