Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy erorrs #1015

Merged
merged 3 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boa/src/builtins/bigint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl BigInt {
} else {
10
};
if radix < 2 || radix > 36 {
if !(2..=36).contains(&radix) {
return context
.throw_range_error("radix must be an integer at least 2 and no greater than 36");
}
Expand Down
6 changes: 3 additions & 3 deletions boa/src/builtins/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl Date {
let sec = sec as u32;
let milli = milli as u32;

let year = if 0 <= year && year <= 99 {
let year = if (0..=99).contains(&year) {
1900 + year
} else {
year
Expand Down Expand Up @@ -936,7 +936,7 @@ impl Date {
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setYear
pub fn set_year(&mut self, year: Option<f64>, month: Option<f64>, day: Option<f64>) {
if let Some(mut year) = year {
year += if 0f64 <= year && year < 100f64 {
year += if (0f64..100f64).contains(&year) {
1900f64
} else {
0f64
Expand Down Expand Up @@ -1330,7 +1330,7 @@ impl Date {
let sec = sec as u32;
let milli = milli as u32;

let year = if 0 <= year && year <= 99 {
let year = if (0..=99).contains(&year) {
1900 + year
} else {
year
Expand Down
2 changes: 1 addition & 1 deletion boa/src/builtins/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl Number {
.map_or(10, |radix| radix as u8);

// 4. If radixNumber < 2 or radixNumber > 36, throw a RangeError exception.
if radix < 2 || radix > 36 {
if !(2..=36).contains(&radix) {
return context
.throw_range_error("radix must be an integer at least 2 and no greater than 36");
}
Expand Down
4 changes: 2 additions & 2 deletions boa/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Object {
// TODO: proto should be a &Value here
#[inline]
pub fn create(proto: Value) -> Self {
let mut obj = Self::default();
let mut obj = Self::new();
obj.prototype = proto;
obj
}
Expand Down Expand Up @@ -474,7 +474,7 @@ impl Object {
/// Similar to `Value::new_object`, but you can pass a prototype to create from, plus a kind
#[inline]
pub fn with_prototype(proto: Value, data: ObjectData) -> Object {
let mut object = Object::default();
let mut object = Object::new();
object.data = data;
object.set_prototype_instance(proto);
object
Expand Down
5 changes: 1 addition & 4 deletions boa/src/syntax/lexer/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,7 @@ fn utf8_is_first_byte(byte: u8) -> bool {

#[inline]
fn unwrap_or_0(opt: Option<u8>) -> u8 {
match opt {
Some(byte) => byte,
None => 0,
}
opt.unwrap_or(0)
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion boa/src/syntax/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<R> Lexer<R> {
Span::new(start, self.cursor.pos()),
)),
'.' => {
if self.cursor.peek()?.map(|c| c >= b'0' && c <= b'9') == Some(true) {
if self.cursor.peek()?.map(|c| (b'0'..=b'9').contains(&c)) == Some(true) {
NumberLiteral::new(next_ch as u8).lex(&mut self.cursor, start)
} else {
SpreadLiteral::new().lex(&mut self.cursor, start)
Expand Down
1 change: 1 addition & 0 deletions boa/src/syntax/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ fn illegal_code_point_following_numeric_literal() {
let mut lexer = Lexer::new(&br#"17.4\u{2764}"#[..]);
assert!(
lexer.next().is_err(),
"{}",
r#"IdentifierStart \u{2764} following NumericLiteral not rejected as expected"#
);
}
Expand Down