Skip to content

Commit

Permalink
Fix clippy and tests (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Oct 19, 2023
1 parent 2a52612 commit 5091e17
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 36 deletions.
10 changes: 6 additions & 4 deletions core/src/ast/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,10 @@ impl BorrowedParams<'_> {
/// param will be called if present.
pub fn return_names<'a>(&'a self, self_name: &'a Ident) -> impl Iterator<Item = &'a Ident> {
self.0.iter().map(move |_| self_name).chain(
self.1.iter().filter_map(|&(param, ltk)| {
(ltk == LifetimeKind::ReturnValue).then(|| &param.name)
}),
self.1
.iter()
.filter(|(_, ltk)| (*ltk == LifetimeKind::ReturnValue))
.map(|(param, _)| &param.name),
)
}

Expand All @@ -342,7 +343,8 @@ impl BorrowedParams<'_> {
pub fn static_names(&self) -> impl Iterator<Item = &'_ Ident> {
self.1
.iter()
.filter_map(|&(param, ltk)| (ltk == LifetimeKind::Static).then(|| &param.name))
.filter(|(_, ltk)| (*ltk == LifetimeKind::Static))
.map(|(param, _)| &param.name)
}

/// Returns `true` if a provided param name is included in the borrowed params,
Expand Down
4 changes: 2 additions & 2 deletions example/js/lib/test/fixed-decimal-ts.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormat, ICU4XFixedDecimalFormatOptions } from "../api/index.js";
import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter, ICU4XFixedDecimalFormatterOptions } from "../api/index.js";
test("multiply a fixed decimal by 1.1", t => {
const my_decimal = ICU4XFixedDecimal.new(123);
my_decimal.multiply_pow10(-1);
Expand All @@ -12,7 +12,7 @@ test("format a fixed decimal", t => {
let locale = ICU4XLocale.new_from_bytes(bytes);
locale = ICU4XLocale.new("bn");
const data_provider = ICU4XDataProvider.new_static();
const fdf = ICU4XFixedDecimalFormat.try_new(locale, data_provider, ICU4XFixedDecimalFormatOptions.default());
const fdf = ICU4XFixedDecimalFormatter.try_new(locale, data_provider, ICU4XFixedDecimalFormatterOptions.default());
if (!fdf.success) {
throw "Failed to format fixed decimal";
}
Expand Down
4 changes: 2 additions & 2 deletions example/js/lib/test/fixed-decimal-ts.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';

import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormat, ICU4XFixedDecimalFormatOptions } from "../api/index.js"
import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter, ICU4XFixedDecimalFormatterOptions } from "../api/index.js";

test("multiply a fixed decimal by 1.1", t => {
const my_decimal = ICU4XFixedDecimal.new(123);
Expand All @@ -21,7 +21,7 @@ test("format a fixed decimal", t => {

const data_provider = ICU4XDataProvider.new_static();

const fdf = ICU4XFixedDecimalFormat.try_new(locale, data_provider, ICU4XFixedDecimalFormatOptions.default());
const fdf = ICU4XFixedDecimalFormatter.try_new(locale, data_provider, ICU4XFixedDecimalFormatterOptions.default());
if (!fdf.success) {
throw "Failed to format fixed decimal";
}
Expand Down
4 changes: 2 additions & 2 deletions example/js/lib/test/fixed-decimal.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';

import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormat, ICU4XFixedDecimalFormatOptions } from "../api/index.js"
import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter, ICU4XFixedDecimalFormatterOptions } from "../api/index.js"

test("multiply a fixed decimal by 0.1", t => {
const my_decimal = ICU4XFixedDecimal.new(123);
Expand All @@ -21,7 +21,7 @@ test("format a fixed decimal", t => {

const data_provider = ICU4XDataProvider.new_static();

const fdf = ICU4XFixedDecimalFormat.try_new(locale, data_provider, ICU4XFixedDecimalFormatOptions.default());
const fdf = ICU4XFixedDecimalFormatter.try_new(locale, data_provider, ICU4XFixedDecimalFormatterOptions.default());
if (!fdf.success) {
throw "Failed to format fixed decimal";
}
Expand Down
12 changes: 3 additions & 9 deletions tool/src/c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use results::*;
pub static RUNTIME_H: &str = include_str!("runtime.h");

pub fn gen_bindings(env: &Env, outs: &mut HashMap<String, String>) -> fmt::Result {
let diplomat_runtime_out = outs
.entry("diplomat_runtime.h".to_string())
.or_insert_with(String::new);
let diplomat_runtime_out = outs.entry("diplomat_runtime.h".to_string()).or_default();
write!(diplomat_runtime_out, "{RUNTIME_H}")?;

let all_types = util::get_all_custom_types(env);
Expand Down Expand Up @@ -60,9 +58,7 @@ fn gen_struct_header<'a>(
outs: &mut HashMap<String, String>,
env: &Env,
) -> Result<(), fmt::Error> {
let out = outs
.entry(format!("{}.h", typ.name()))
.or_insert_with(String::new);
let out = outs.entry(format!("{}.h", typ.name())).or_default();

writeln!(out, "#ifndef {}_H", typ.name())?;
writeln!(out, "#define {}_H", typ.name())?;
Expand Down Expand Up @@ -193,9 +189,7 @@ fn gen_result_header(
env: &Env,
) -> fmt::Result {
if let ast::TypeName::Result(ok, err, _) = typ {
let out = outs
.entry(format!("{}.h", name_for_type(typ)))
.or_insert_with(String::new);
let out = outs.entry(format!("{}.h", name_for_type(typ))).or_default();

writeln!(out, "#ifndef {}_H", name_for_type(typ))?;
writeln!(out, "#define {}_H", name_for_type(typ))?;
Expand Down
6 changes: 2 additions & 4 deletions tool/src/cpp/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ pub fn gen_docs(
}
}

let index_out = outs
.entry("index.rst".to_string())
.or_insert_with(String::new);
let index_out = outs.entry("index.rst".to_string()).or_default();
writeln!(index_out, "Documentation")?;
writeln!(index_out, "=============")?;
writeln!(index_out)?;
Expand Down Expand Up @@ -71,7 +69,7 @@ pub fn gen_docs(
{
let out = outs
.entry(format!("{}.rst", in_path.elements.join("_")))
.or_insert_with(String::new);
.or_default();

let title = format!("``{}``", in_path.elements.join("::"));
writeln!(out, "{title}")?;
Expand Down
8 changes: 2 additions & 6 deletions tool/src/cpp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,13 @@ pub fn gen_bindings(
}
}

let diplomat_runtime_out = outs
.entry("diplomat_runtime.hpp".to_string())
.or_insert_with(String::new);
let diplomat_runtime_out = outs.entry("diplomat_runtime.hpp".to_string()).or_default();
write!(diplomat_runtime_out, "{RUNTIME_HPP}")?;

let all_types = crate::util::get_all_custom_types(env);

for (in_path, typ) in &all_types {
let out = outs
.entry(format!("{}.hpp", typ.name()))
.or_insert_with(String::new);
let out = outs.entry(format!("{}.hpp", typ.name())).or_default();

let rendered = render_header(typ.name(), &library_config.headers);
writeln!(out, "{rendered}").expect("Failed to write string.");
Expand Down
4 changes: 1 addition & 3 deletions tool/src/dotnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub fn gen_bindings(
}
}

let diplomat_runtime_out = outs
.entry("DiplomatRuntime.cs".to_owned())
.or_insert_with(String::new);
let diplomat_runtime_out = outs.entry("DiplomatRuntime.cs".to_owned()).or_default();
write!(
diplomat_runtime_out,
"{}",
Expand Down
6 changes: 2 additions & 4 deletions tool/src/js/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub fn gen_docs(
outs: &mut HashMap<String, String>,
docs_url_gen: &ast::DocsUrlGenerator,
) -> fmt::Result {
let index_out = outs
.entry("index.rst".to_string())
.or_insert_with(String::new);
let index_out = outs.entry("index.rst".to_string()).or_default();
writeln!(index_out, "Documentation")?;
writeln!(index_out, "=============")?;
writeln!(index_out)?;
Expand Down Expand Up @@ -46,7 +44,7 @@ pub fn gen_docs(
{
let out = outs
.entry(format!("{}.rst", in_path.elements.join("_")))
.or_insert_with(String::new);
.or_default();

let title = format!("``{}``", in_path.elements.join("::"));
writeln!(out, "{title}")?;
Expand Down

0 comments on commit 5091e17

Please sign in to comment.