Skip to content

Commit ba427c8

Browse files
authored
Merge pull request RustPython#4422 from harupy/impl-Default-for-Location
Implement `Default` for `Location`
2 parents f1ca359 + 3602d26 commit ba427c8

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

compiler/core/src/location.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
use serde::{Deserialize, Serialize};
22

33
/// Sourcecode location.
4-
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
4+
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
55
pub struct Location {
66
pub(super) row: u32,
77
pub(super) column: u32,
88
}
99

10+
impl Default for Location {
11+
fn default() -> Self {
12+
Self { row: 1, column: 0 }
13+
}
14+
}
15+
1016
impl Location {
1117
pub fn fmt_with(
1218
&self,

compiler/parser/src/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub type LexResult = Result<Spanned, LexicalError>;
153153

154154
#[inline]
155155
pub fn make_tokenizer(source: &str) -> impl Iterator<Item = LexResult> + '_ {
156-
make_tokenizer_located(source, Location::new(1, 0))
156+
make_tokenizer_located(source, Location::default())
157157
}
158158

159159
pub fn make_tokenizer_located(

compiler/parser/src/string_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ mod tests {
541541
source,
542542
StringKind::FString,
543543
false,
544-
Location::new(1, 0),
545-
Location::new(1, source.len() + 3), // 3 for prefix and quotes
544+
Location::default(),
545+
Location::default().with_col_offset(source.len() + 3), // 3 for prefix and quotes
546546
)
547547
.parse()
548548
}

0 commit comments

Comments
 (0)