codegen::{CompileError -> CodegenError} · RustPython/RustPython@58f5122 · GitHub
Skip to content

Commit 58f5122

Browse files
committed
codegen::{CompileError -> CodegenError}
1 parent 1606c26 commit 58f5122

8 files changed

Lines changed: 81 additions & 82 deletions

File tree

compiler/codegen/src/compile.rs

Lines changed: 33 additions & 33 deletions

compiler/codegen/src/error.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use rustpython_ast::Location;
33
use std::{error::Error, fmt};
44

55
#[derive(Debug)]
6-
pub struct CompileError {
7-
pub error: CompileErrorType,
6+
pub struct CodegenError {
7+
pub error: CodegenErrorType,
88
pub location: Location,
99
pub source_path: String,
1010
}
1111

1212
#[derive(Debug)]
1313
#[non_exhaustive]
14-
pub enum CompileErrorType {
14+
pub enum CodegenErrorType {
1515
/// Invalid assignment, cannot store value in target.
1616
Assign(&'static str),
1717
/// Invalid delete
@@ -40,61 +40,62 @@ pub enum CompileErrorType {
4040
NotImplementedYet, // RustPython marker for unimplemented features
4141
}
4242

43-
impl fmt::Display for CompileErrorType {
43+
impl fmt::Display for CodegenErrorType {
4444
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45+
use CodegenErrorType::*;
4546
match self {
46-
CompileErrorType::Assign(target) => write!(f, "cannot assign to {}", target),
47-
CompileErrorType::Delete(target) => write!(f, "cannot delete {}", target),
48-
CompileErrorType::SyntaxError(err) => write!(f, "{}", err.as_str()),
49-
CompileErrorType::MultipleStarArgs => {
47+
Assign(target) => write!(f, "cannot assign to {}", target),
48+
Delete(target) => write!(f, "cannot delete {}", target),
49+
SyntaxError(err) => write!(f, "{}", err.as_str()),
50+
MultipleStarArgs => {
5051
write!(f, "two starred expressions in assignment")
5152
}
52-
CompileErrorType::InvalidStarExpr => write!(f, "cannot use starred expression here"),
53-
CompileErrorType::InvalidBreak => write!(f, "'break' outside loop"),
54-
CompileErrorType::InvalidContinue => write!(f, "'continue' outside loop"),
55-
CompileErrorType::InvalidReturn => write!(f, "'return' outside function"),
56-
CompileErrorType::InvalidYield => write!(f, "'yield' outside function"),
57-
CompileErrorType::InvalidYieldFrom => write!(f, "'yield from' outside function"),
58-
CompileErrorType::InvalidAwait => write!(f, "'await' outside async function"),
59-
CompileErrorType::AsyncYieldFrom => write!(f, "'yield from' inside async function"),
60-
CompileErrorType::AsyncReturnValue => {
53+
InvalidStarExpr => write!(f, "cannot use starred expression here"),
54+
InvalidBreak => write!(f, "'break' outside loop"),
55+
InvalidContinue => write!(f, "'continue' outside loop"),
56+
InvalidReturn => write!(f, "'return' outside function"),
57+
InvalidYield => write!(f, "'yield' outside function"),
58+
InvalidYieldFrom => write!(f, "'yield from' outside function"),
59+
InvalidAwait => write!(f, "'await' outside async function"),
60+
AsyncYieldFrom => write!(f, "'yield from' inside async function"),
61+
AsyncReturnValue => {
6162
write!(f, "'return' with value inside async generator")
6263
}
63-
CompileErrorType::InvalidFuturePlacement => write!(
64+
InvalidFuturePlacement => write!(
6465
f,
6566
"from __future__ imports must occur at the beginning of the file"
6667
),
67-
CompileErrorType::InvalidFutureFeature(feat) => {
68+
InvalidFutureFeature(feat) => {
6869
write!(f, "future feature {} is not defined", feat)
6970
}
70-
CompileErrorType::FunctionImportStar => {
71+
FunctionImportStar => {
7172
write!(f, "import * only allowed at module level")
7273
}
73-
CompileErrorType::TooManyStarUnpack => {
74+
TooManyStarUnpack => {
7475
write!(f, "too many expressions in star-unpacking assignment")
7576
}
76-
CompileErrorType::EmptyWithItems => {
77+
EmptyWithItems => {
7778
write!(f, "empty items on With")
7879
}
79-
CompileErrorType::EmptyWithBody => {
80+
EmptyWithBody => {
8081
write!(f, "empty body on With")
8182
}
82-
CompileErrorType::NotImplementedYet => {
83+
NotImplementedYet => {
8384
write!(f, "RustPython does not implement this feature yet")
8485
}
8586
}
8687
}
8788
}
8889

89-
impl Error for CompileErrorType {}
90+
impl Error for CodegenErrorType {}
9091

91-
impl fmt::Display for CompileError {
92+
impl fmt::Display for CodegenError {
9293
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9394
write!(f, "{} at {}", self.error, self.location)
9495
}
9596
}
9697

97-
impl Error for CompileError {
98+
impl Error for CodegenError {
9899
fn source(&self) -> Option<&(dyn Error + 'static)> {
99100
None
100101
}

compiler/codegen/src/symboltable.rs

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)