From 292688a840db2367052127d762e1628310bcc0da Mon Sep 17 00:00:00 2001 From: sofia Date: Thu, 17 Jul 2025 20:26:01 +0300 Subject: [PATCH] Fix some warnings --- reid/src/ast/parse.rs | 2 +- reid/src/error_raporting.rs | 7 ------- reid/src/lexer.rs | 5 +---- reid/src/lib.rs | 3 +-- reid/src/mir/impl.rs | 6 +----- reid/src/mir/linker.rs | 2 +- reid/src/mir/mod.rs | 5 +---- reid/src/token_stream.rs | 13 ++----------- 8 files changed, 8 insertions(+), 35 deletions(-) diff --git a/reid/src/ast/parse.rs b/reid/src/ast/parse.rs index e1f95c6..8f1263c 100644 --- a/reid/src/ast/parse.rs +++ b/reid/src/ast/parse.rs @@ -392,7 +392,7 @@ impl Parse for Block { // if semicolon is missing. if !matches!(e, Expression(ExpressionKind::IfExpr(_), _)) { // In theory could ignore the missing semicolon.. - return Err(stream.expected_err("expected semicolon to complete statement")?); + return Err(stream.expected_err("semicolon to complete statement")?); } statements.push(BlockLevelStatement::Expression(e)); diff --git a/reid/src/error_raporting.rs b/reid/src/error_raporting.rs index 2b915a8..673b8b1 100644 --- a/reid/src/error_raporting.rs +++ b/reid/src/error_raporting.rs @@ -4,18 +4,11 @@ use std::{ }; use crate::{ - ast, lexer::{self, Cursor, FullToken, Position}, mir::{self, pass, Metadata, SourceModuleId}, token_stream::{self, TokenRange}, }; -impl pass::Error { - fn fmt_simple(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(&self.kind, f) - } -} - fn label(text: &str) -> &str { #[cfg(debug_assertions)] { diff --git a/reid/src/lexer.rs b/reid/src/lexer.rs index 220ae28..51fc49c 100644 --- a/reid/src/lexer.rs +++ b/reid/src/lexer.rs @@ -1,7 +1,4 @@ -use std::{ - fmt::{Debug, Write}, - str::Chars, -}; +use std::{fmt::Debug, str::Chars}; static DECIMAL_NUMERICS: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']; diff --git a/reid/src/lib.rs b/reid/src/lib.rs index bc16550..2a98ec5 100644 --- a/reid/src/lib.rs +++ b/reid/src/lib.rs @@ -41,13 +41,12 @@ //! - Debug Symbols //! ``` -use std::{convert::Infallible, path::PathBuf}; +use std::path::PathBuf; use error_raporting::{ErrorKind as ErrorRapKind, ModuleMap, ReidError}; use lexer::FullToken; use mir::{ linker::LinkerPass, typecheck::TypeCheck, typeinference::TypeInference, typerefs::TypeRefs, - SourceModuleId, }; use reid_lib::{compile::CompileOutput, Context}; diff --git a/reid/src/mir/impl.rs b/reid/src/mir/impl.rs index 2624bac..585da65 100644 --- a/reid/src/mir/impl.rs +++ b/reid/src/mir/impl.rs @@ -1,8 +1,4 @@ -use super::{ - typecheck::ErrorKind, - typerefs::{ScopeTypeRefs, TypeRef, TypeRefs}, - VagueType as Vague, *, -}; +use super::{typecheck::ErrorKind, typerefs::TypeRefs, VagueType as Vague, *}; #[derive(Debug, Clone)] pub enum ReturnTypeOther { diff --git a/reid/src/mir/linker.rs b/reid/src/mir/linker.rs index 1a04ffc..83d7b51 100644 --- a/reid/src/mir/linker.rs +++ b/reid/src/mir/linker.rs @@ -12,7 +12,7 @@ use crate::{compile_module, error_raporting::ModuleMap, lexer::FullToken, parse_ use super::{ pass::{Pass, PassState}, r#impl::EqualsIssue, - Context, FunctionDefinition, Import, Metadata, Module, SourceModuleId, + Context, FunctionDefinition, Import, Metadata, Module, }; pub static STD_SOURCE: &str = include_str!("../../lib/std.reid"); diff --git a/reid/src/mir/mod.rs b/reid/src/mir/mod.rs index 49a73e1..7294a1b 100644 --- a/reid/src/mir/mod.rs +++ b/reid/src/mir/mod.rs @@ -4,10 +4,7 @@ use std::{collections::HashMap, path::PathBuf}; -use crate::{ - lexer::{FullToken, Position}, - token_stream::TokenRange, -}; +use crate::{lexer::Position, token_stream::TokenRange}; mod display; pub mod r#impl; diff --git a/reid/src/token_stream.rs b/reid/src/token_stream.rs index 57158dc..5d86319 100644 --- a/reid/src/token_stream.rs +++ b/reid/src/token_stream.rs @@ -3,7 +3,7 @@ use crate::{ ast::parse::Parse, - lexer::{FullToken, Position, Token}, + lexer::{FullToken, Token}, }; /// Utility struct that is able to parse [`FullToken`]s while being @@ -175,15 +175,6 @@ impl<'a, 'b> TokenStream<'a, 'b> { } } - fn get_position(&self, offset: usize) -> Result { - if self.tokens.is_empty() { - Err(Error::FileEmpty) - } else { - let token_idx = (self.position - 1).min(self.tokens.len() - 1); - Ok(self.tokens[token_idx].position) - } - } - pub fn get_range(&self) -> Option { self.ref_position.as_ref().map(|ref_pos| TokenRange { start: **ref_pos, @@ -237,7 +228,7 @@ impl std::iter::Sum for TokenRange { #[derive(thiserror::Error, Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub enum Error { - #[error("Expected {} got {:?}", .0, .1)] + #[error("Expected {} got \"{}\"", .0, .1.to_string())] Expected(String, Token, TokenRange), #[error("Source file contains no tokens")] FileEmpty,