Skip to content

Commit

Permalink
format_code_in_doc_comments=true
Browse files Browse the repository at this point in the history
Summary:
Want to make another attempt to enable

```
format_code_in_doc_comments=true
```

Reformatting parts of the repository for now.

These changes are easier than previous reformats because when option is removed after reformat, reformat back is not needed.

[Poll](https://fb.workplace.com/groups/rust.language/posts/24184800024475285)

Reviewed By: zertosh

Differential Revision: D52631887

fbshipit-source-id: d7030044049000a99afd07e351f2b3cf685ff0e9
  • Loading branch information
stepancheg authored and facebook-github-bot committed Jan 9, 2024
1 parent 57fa014 commit 7b148dd
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 111 deletions.
6 changes: 3 additions & 3 deletions starlark/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ unsafe impl<'a, T: ProvidesStaticType<'a> + 'a + ?Sized> AnyLifetime<'a> for T {
/// struct Baz<T: Display>(T);
/// # // TODO: `#[derive(ProvidesStaticType)]` should learn to handle this case too.
/// unsafe impl<'a, T> ProvidesStaticType<'a> for Baz<T>
/// where
/// T: ProvidesStaticType<'a> + Display,
/// T::StaticType: Display + Sized,
/// where
/// T: ProvidesStaticType<'a> + Display,
/// T::StaticType: Display + Sized,
/// {
/// type StaticType = Baz<T::StaticType>;
/// }
Expand Down
12 changes: 8 additions & 4 deletions starlark/src/assert/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,12 @@ impl<'a> Assert<'a> {
///
/// ```
/// # use starlark::assert::Assert;
/// Assert::new().is_true(r#"
/// Assert::new().is_true(
/// r#"
/// x = 1 + 1
/// x == 2
/// "#);
/// "#,
/// );
/// ```
pub fn is_true(&self, program: &str) {
self.with_gc(|gc| {
Expand All @@ -544,11 +546,13 @@ impl<'a> Assert<'a> {
///
/// ```
/// # use starlark::assert::Assert;
/// Assert::new().all_true(r#"
/// Assert::new().all_true(
/// r#"
/// 1 == 1
///
/// 2 == 1 + 1
/// "#);
/// "#,
/// );
/// ```
pub fn all_true(&self, program: &str) {
self.with_gc(|gc| {
Expand Down
16 changes: 6 additions & 10 deletions starlark/src/coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,23 @@ use starlark_map::small_map::SmallMap;
/// One use of `Coerce` is around newtype wrappers:
///
/// ```
/// use starlark::coerce::{Coerce, coerce};
/// use starlark::coerce::coerce;
/// use starlark::coerce::Coerce;
/// #[repr(transparent)]
/// #[derive(Debug, Coerce)]
/// struct Wrapper(String);
///
/// let value = vec![Wrapper("hello".to_owned()), Wrapper("world".to_owned())];
/// assert_eq!(
/// coerce::<_, &Vec<String>>(&value).join(" "),
/// "hello world"
/// );
/// assert_eq!(coerce::<_, &Vec<String>>(&value).join(" "), "hello world");
/// let mut value = coerce::<_, Vec<String>>(value);
/// assert_eq!(value.pop(), Some("world".to_owned()));
/// ```
///
/// Another involves containers:
///
/// ```
/// use starlark::coerce::{Coerce, coerce};
/// use starlark::coerce::coerce;
/// use starlark::coerce::Coerce;
/// # #[derive(Coerce)]
/// # #[repr(transparent)]
/// # struct Wrapper(String);
Expand All @@ -68,10 +67,7 @@ use starlark_map::small_map::SmallMap;
/// struct Container<T>(i32, T);
///
/// let value = Container(20, Wrapper("twenty".to_owned()));
/// assert_eq!(
/// coerce::<_, &Container<String>>(&value).1,
/// "twenty"
/// );
/// assert_eq!(coerce::<_, &Container<String>>(&value).1, "twenty");
/// ```
///
/// If you only need [`coerce`] on newtype references,
Expand Down
139 changes: 90 additions & 49 deletions starlark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
//!
//! ```
//! # fn run() -> starlark::Result<()> {
//! use starlark::environment::Globals;
//! use starlark::environment::Module;
//! use starlark::eval::Evaluator;
//! use starlark::environment::{Module, Globals};
//! use starlark::syntax::AstModule;
//! use starlark::syntax::Dialect;
//! use starlark::values::Value;
//! use starlark::syntax::{AstModule, Dialect};
//!
//! let content = r#"
//! def hello():
Expand All @@ -36,7 +38,8 @@
//!
//! // We first parse the content, giving a filename and the Starlark
//! // `Dialect` we'd like to use (we pick standard).
//! let ast: AstModule = AstModule::parse("hello_world.star", content.to_owned(), &Dialect::Standard)?;
//! let ast: AstModule =
//! AstModule::parse("hello_world.star", content.to_owned(), &Dialect::Standard)?;
//!
//! // We create a `Globals`, defining the standard library functions available.
//! // The `standard` function uses those defined in the Starlark specification.
Expand Down Expand Up @@ -108,13 +111,18 @@
//! #[macro_use]
//! extern crate starlark;
//! # fn run() -> starlark::Result<()> {
//! use starlark::environment::{GlobalsBuilder, Module};
//! use starlark::eval::Evaluator;
//! use starlark::syntax::{AstModule, Dialect};
//! use starlark::values::{none::NoneType, Value, ValueLike};
//! use starlark::any::ProvidesStaticType;
//! use std::cell::RefCell;
//!
//! use starlark::any::ProvidesStaticType;
//! use starlark::environment::GlobalsBuilder;
//! use starlark::environment::Module;
//! use starlark::eval::Evaluator;
//! use starlark::syntax::AstModule;
//! use starlark::syntax::Dialect;
//! use starlark::values::none::NoneType;
//! use starlark::values::Value;
//! use starlark::values::ValueLike;
//!
//! let content = r#"
//! emit(1)
//! emit(["test"])
Expand All @@ -127,7 +135,7 @@
//!
//! impl Store {
//! fn add(&self, x: String) {
//! self.0.borrow_mut().push(x)
//! self.0.borrow_mut().push(x)
//! }
//! }
//!
Expand Down Expand Up @@ -169,9 +177,12 @@
//!
//! ```
//! # fn run() -> starlark::Result<()> {
//! use starlark::environment::{Globals, Module};
//! use starlark::environment::Globals;
//! use starlark::environment::Module;
//! use starlark::eval::Evaluator;
//! use starlark::syntax::{AstModule, Dialect, DialectTypes};
//! use starlark::syntax::AstModule;
//! use starlark::syntax::Dialect;
//! use starlark::syntax::DialectTypes;
//!
//! let content = r#"
//! def takes_int(x: int):
Expand All @@ -180,15 +191,22 @@
//! "#;
//!
//! // Make the dialect enable types
//! let dialect = Dialect {enable_types: DialectTypes::Enable, ..Dialect::Standard};
//! let dialect = Dialect {
//! enable_types: DialectTypes::Enable,
//! ..Dialect::Standard
//! };
//! // We could equally have done `dialect = Dialect::Extended`.
//! let ast = AstModule::parse("json.star", content.to_owned(), &dialect)?;
//! let globals = Globals::standard();
//! let module = Module::new();
//! let mut eval = Evaluator::new(&module);
//! let res = eval.eval_module(ast, &globals);
//! // We expect this to fail, since it is a type violation
//! assert!(res.unwrap_err().to_string().contains("Value `test` of type `string` does not match the type annotation `int`"));
//! assert!(
//! res.unwrap_err()
//! .to_string()
//! .contains("Value `test` of type `string` does not match the type annotation `int`")
//! );
//! # Ok(())
//! # }
//! # fn main(){ run().unwrap(); }
Expand All @@ -202,16 +220,21 @@
//!
//! ```
//! # fn run() -> starlark::Result<()> {
//! use starlark::environment::{FrozenModule, Globals, Module};
//! use starlark::eval::{Evaluator, ReturnFileLoader};
//! use starlark::syntax::{AstModule, Dialect};
//! use starlark::environment::FrozenModule;
//! use starlark::environment::Globals;
//! use starlark::environment::Module;
//! use starlark::eval::Evaluator;
//! use starlark::eval::ReturnFileLoader;
//! use starlark::syntax::AstModule;
//! use starlark::syntax::Dialect;
//!
//! // Get the file contents (for the demo), in reality use `AstModule::parse_file`.
//! fn get_source(file: &str) -> &str {
//! match file {
//! "a.star" => "a = 7",
//! "b.star" => "b = 6",
//! _ => { r#"
//! _ => {
//! r#"
//! load('a.star', 'a')
//! load('b.star', 'b')
//! ab = a * b
Expand All @@ -221,27 +244,27 @@
//! }
//!
//! fn get_module(file: &str) -> starlark::Result<FrozenModule> {
//! let ast = AstModule::parse(file, get_source(file).to_owned(), &Dialect::Standard)?;
//!
//! // We can get the loaded modules from `ast.loads`.
//! // And ultimately produce a `loader` capable of giving those modules to Starlark.
//! let mut loads = Vec::new();
//! for load in ast.loads() {
//! loads.push((load.module_id.to_owned(), get_module(load.module_id)?));
//! }
//! let modules = loads.iter().map(|(a, b)| (a.as_str(), b)).collect();
//! let mut loader = ReturnFileLoader { modules: &modules };
//!
//! let globals = Globals::standard();
//! let module = Module::new();
//! {
//! let mut eval = Evaluator::new(&module);
//! eval.set_loader(&mut loader);
//! eval.eval_module(ast, &globals)?;
//! }
//! // After creating a module we freeze it, preventing further mutation.
//! // It can now be used as the input for other Starlark modules.
//! Ok(module.freeze()?)
//! let ast = AstModule::parse(file, get_source(file).to_owned(), &Dialect::Standard)?;
//!
//! // We can get the loaded modules from `ast.loads`.
//! // And ultimately produce a `loader` capable of giving those modules to Starlark.
//! let mut loads = Vec::new();
//! for load in ast.loads() {
//! loads.push((load.module_id.to_owned(), get_module(load.module_id)?));
//! }
//! let modules = loads.iter().map(|(a, b)| (a.as_str(), b)).collect();
//! let mut loader = ReturnFileLoader { modules: &modules };
//!
//! let globals = Globals::standard();
//! let module = Module::new();
//! {
//! let mut eval = Evaluator::new(&module);
//! eval.set_loader(&mut loader);
//! eval.eval_module(ast, &globals)?;
//! }
//! // After creating a module we freeze it, preventing further mutation.
//! // It can now be used as the input for other Starlark modules.
//! Ok(module.freeze()?)
//! }
//!
//! let ab = get_module("ab.star")?;
Expand All @@ -257,9 +280,11 @@
//!
//! ```
//! # fn run() -> starlark::Result<()> {
//! use starlark::environment::{Globals, Module};
//! use starlark::environment::Globals;
//! use starlark::environment::Module;
//! use starlark::eval::Evaluator;
//! use starlark::syntax::{AstModule, Dialect};
//! use starlark::syntax::AstModule;
//! use starlark::syntax::Dialect;
//! use starlark::values::Value;
//!
//! let content = r#"
Expand Down Expand Up @@ -292,13 +317,24 @@
//!
//! ```
//! # fn run() -> starlark::Result<()> {
//! use starlark::environment::{Globals, Module};
//! use std::fmt::Display;
//! use std::fmt::Write;
//! use std::fmt::{self};
//!
//! use allocative::Allocative;
//! use starlark::environment::Globals;
//! use starlark::environment::Module;
//! use starlark::eval::Evaluator;
//! use starlark::syntax::{AstModule, Dialect};
//! use starlark::values::{Heap, StarlarkValue, Value, ValueError, ValueLike, ProvidesStaticType, NoSerialize};
//! use starlark::starlark_simple_value;
//! use std::fmt::{self, Display, Write};
//! use allocative::Allocative;
//! use starlark::syntax::AstModule;
//! use starlark::syntax::Dialect;
//! use starlark::values::Heap;
//! use starlark::values::NoSerialize;
//! use starlark::values::ProvidesStaticType;
//! use starlark::values::StarlarkValue;
//! use starlark::values::Value;
//! use starlark::values::ValueError;
//! use starlark::values::ValueLike;
//! use starlark_derive::starlark_value;
//!
//! // Define complex numbers
Expand All @@ -318,8 +354,7 @@
//! #[starlark_value(type = "complex")]
//! impl<'v> StarlarkValue<'v> for Complex {
//! // How we add them
//! fn add(&self, rhs: Value<'v>, heap: &'v Heap)
//! -> Option<starlark::Result<Value<'v>>> {
//! fn add(&self, rhs: Value<'v>, heap: &'v Heap) -> Option<starlark::Result<Value<'v>>> {
//! if let Some(rhs) = rhs.downcast_ref::<Self>() {
//! Some(Ok(heap.alloc(Complex {
//! real: self.real + rhs.real,
Expand All @@ -337,9 +372,15 @@
//! let globals = Globals::standard();
//! let module = Module::new();
//! // We inject some complex numbers into the module before we start.
//! let a = module.heap().alloc(Complex {real: 1, imaginary: 8});
//! let a = module.heap().alloc(Complex {
//! real: 1,
//! imaginary: 8,
//! });
//! module.set("a", a);
//! let b = module.heap().alloc(Complex {real: 4, imaginary: 2});
//! let b = module.heap().alloc(Complex {
//! real: 4,
//! imaginary: 2,
//! });
//! module.set("b", b);
//! let mut eval = Evaluator::new(&module);
//! let res = eval.eval_module(ast, &globals)?;
Expand Down
10 changes: 7 additions & 3 deletions starlark/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ macro_rules! starlark_complex_values {
/// Let's define a simple object, where `+x` makes the string uppercase:
///
/// ```
/// use starlark::values::{Heap, StarlarkValue, Value, ProvidesStaticType, NoSerialize};
/// use starlark::{starlark_simple_value};
/// use derive_more::Display;
/// use allocative::Allocative;
/// use derive_more::Display;
/// use starlark::starlark_simple_value;
/// use starlark::values::Heap;
/// use starlark::values::NoSerialize;
/// use starlark::values::ProvidesStaticType;
/// use starlark::values::StarlarkValue;
/// use starlark::values::Value;
/// use starlark_derive::starlark_value;
///
/// #[derive(Debug, Display, ProvidesStaticType, NoSerialize, Allocative)]
Expand Down
3 changes: 1 addition & 2 deletions starlark/src/stdlib/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ pub(crate) fn string_methods(builder: &mut MethodsBuilder) {
///
/// ```
/// # starlark::assert::is_true(r#"
/// list("Hello, 世界".elems()) == [
/// "H", "e", "l", "l", "o", ",", " ", "世", "界"]
/// list("Hello, 世界".elems()) == ["H", "e", "l", "l", "o", ",", " ", "世", "界"]
/// # "#);
/// ```
fn elems<'v>(
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/values/layout/typed/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ use crate::values::ValueTyped;
///
/// ```
/// use starlark::const_frozen_string;
/// use starlark::values::{FrozenStringValue, FrozenValue};
/// use starlark::values::FrozenStringValue;
/// use starlark::values::FrozenValue;
///
/// let fv: FrozenStringValue = const_frozen_string!("magic");
/// assert_eq!("magic", fv.as_str());
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/values/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ impl OwnedFrozenValue {
/// `owner`, typically because the value was created on the heap.
///
/// ```
/// use starlark::values::{FrozenHeap, OwnedFrozenValue};
/// use starlark::values::FrozenHeap;
/// use starlark::values::OwnedFrozenValue;
/// let heap = FrozenHeap::new();
/// let value = heap.alloc("test");
/// unsafe { OwnedFrozenValue::new(heap.into_ref(), value) };
Expand Down
2 changes: 1 addition & 1 deletion starlark/src/values/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::values::Value;
///
/// #[derive(Trace)]
/// struct MySet<'v> {
/// keys: Vec<Value<'v>>
/// keys: Vec<Value<'v>>,
/// }
/// ```
pub unsafe trait Trace<'v> {
Expand Down
Loading

0 comments on commit 7b148dd

Please sign in to comment.