Skip to content

Commit

Permalink
auto_fix_errors.py: make compatible with python < 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Dec 3, 2024
1 parent 2a24483 commit ba9bad9
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions c2rust-analyze/scripts/auto_fix_errors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse
from dataclasses import dataclass
from collections import namedtuple
import json
import re
import sys
Expand All @@ -13,36 +13,43 @@ def parse_args() -> argparse.Namespace:
help='output of `rustc --error-format json`')
return parser.parse_args()

@dataclass(frozen=True)
class Fix:
file_path: str
line_number: int
start_byte: int
end_byte: int
new_text: str
message: str
Fix = namedtuple('Fix', (
# Path to the file to modify.
'file_path',
# Line number where the fix will be applied. This is used for debug output
# only.
'line_number',
# Start of the byte range to replace.
'start_byte',
# End (exclusive) of the byte range to replace.
'end_byte',
# Replacement text (as a `str`, not `bytes`).
'new_text',
# The original error message. This is used for debug output only.
'message',
))

@dataclass(frozen=True)
class LifetimeBound:
file_path: str
line_number: int
LifetimeBound = namedtuple('LifetimeBound', (
'file_path',
'line_number',
# Byte offset of the start of the lifetime parameter declaration.
start_byte: int
'start_byte',
# Byte offset of the end of the lifetime parameter declaration.
end_byte: int
'end_byte',
# The lifetime to use in the new bound. If `'a: 'b` is the suggested
# bound, then `start/end_byte` points to the declaration of `'a`, and
# `bound_lifetime` is the string `"'b"`.
bound_lifetime: str
'bound_lifetime',
))

@dataclass(frozen=True)
class RemoveDeriveCopy:
file_path: str
line_number: int
RemoveDeriveCopy = namedtuple('RemoveDeriveCopy', (
'file_path',
'line_number',
# Byte offset of the start of the token `Copy`.
start_byte: int
'start_byte',
# Byte offset of the end of the token `Copy`.
end_byte: int
'end_byte',
))

MSG_LIFETIME_BOUND = 'lifetime may not live long enough'
MSG_DERIVE_COPY = 'the trait `Copy` may not be implemented for this type'
Expand Down

0 comments on commit ba9bad9

Please sign in to comment.