Skip to content

Commit

Permalink
Use the Spanned trait everywhere (FuelLabs#1881)
Browse files Browse the repository at this point in the history
* Use Spanned everywhere.

* clippy
  • Loading branch information
emilyaherbert authored Jun 7, 2022
1 parent f38bd95 commit 3afc08d
Show file tree
Hide file tree
Showing 57 changed files with 355 additions and 361 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions forc-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ annotate-snippets = { version = "0.9", features = ["color"] }
anyhow = "1"
dirs = "3.0.2"
sway-core = { version = "0.15.1", path = "../sway-core" }
sway-types = { version = "0.15.1", path = "../sway-types" }
sway-utils = { version = "0.15.1", path = "../sway-utils" }
termcolor = "1.1"
tracing = "0.1"
Expand Down
1 change: 1 addition & 0 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::str;
use sway_core::{error::LineCol, CompileError, CompileWarning, TreeType};
use sway_types::Spanned;
use sway_utils::constants;
use termcolor::{self, Color as TermColor, ColorChoice, ColorSpec, StandardStream, WriteColor};
use tracing_subscriber::filter::EnvFilter;
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
};

use sway_ir::*;
use sway_types::span::Span;
use sway_types::{span::Span, Spanned};

use either::Either;

Expand Down Expand Up @@ -636,7 +636,7 @@ impl<'ir> AsmBuilder<'ir> {
.map(|reg_name| -> Result<_, CompileError> {
realize_register(reg_name.as_str()).ok_or_else(|| {
CompileError::UnknownRegister {
span: reg_name.span().clone(),
span: reg_name.span(),
initialized_registers: inline_reg_map
.iter()
.map(|(name, _)| *name)
Expand Down Expand Up @@ -710,7 +710,7 @@ impl<'ir> AsmBuilder<'ir> {
.map(|(name, _)| name.to_string())
.collect::<Vec<_>>()
.join("\n"),
span: ret_reg_name.span().clone(),
span: ret_reg_name.span(),
});
return err(warnings, errors);
}
Expand Down
38 changes: 12 additions & 26 deletions sway-core/src/asm_lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) use virtual_register::*;

use crate::{asm_generation::DataId, error::*, parse_tree::AsmRegister, Ident};

use sway_types::span::Span;
use sway_types::{span::Span, Spanned};

use either::Either;
use std::{
Expand Down Expand Up @@ -1007,7 +1007,7 @@ impl Op {
_ => {
errors.push(CompileError::UnrecognizedOp {
op_name: name.clone(),
span: name.span().clone(),
span: name.span(),
});
return err(warnings, errors);
}
Expand Down Expand Up @@ -1047,9 +1047,7 @@ fn single_reg(
match immediate {
None => (),
Some(i) => {
errors.push(CompileError::UnnecessaryImmediate {
span: i.span().clone(),
});
errors.push(CompileError::UnnecessaryImmediate { span: i.span() });
}
};

Expand Down Expand Up @@ -1084,9 +1082,7 @@ fn two_regs(
};
match immediate {
None => (),
Some(i) => errors.push(CompileError::UnnecessaryImmediate {
span: i.span().clone(),
}),
Some(i) => errors.push(CompileError::UnnecessaryImmediate { span: i.span() }),
};

ok((reg.clone(), reg2.clone()), warnings, errors)
Expand Down Expand Up @@ -1126,9 +1122,7 @@ fn four_regs(
match immediate {
None => (),
Some(i) => {
errors.push(CompileError::MissingImmediate {
span: i.span().clone(),
});
errors.push(CompileError::MissingImmediate { span: i.span() });
}
};

Expand Down Expand Up @@ -1197,9 +1191,7 @@ fn three_regs(
match immediate {
None => (),
Some(i) => {
errors.push(CompileError::UnnecessaryImmediate {
span: i.span().clone(),
});
errors.push(CompileError::UnnecessaryImmediate { span: i.span() });
}
};

Expand Down Expand Up @@ -1227,11 +1219,9 @@ fn single_imm_24(
return err(warnings, errors);
}
Some(i) => match i.as_str()[1..].parse() {
Ok(o) => (o, i.span().clone()),
Ok(o) => (o, i.span()),
Err(_) => {
errors.push(CompileError::InvalidImmediateValue {
span: i.span().clone(),
});
errors.push(CompileError::InvalidImmediateValue { span: i.span() });
return err(warnings, errors);
}
},
Expand Down Expand Up @@ -1280,11 +1270,9 @@ fn single_reg_imm_18(
return err(warnings, errors);
}
Some(i) => match i.as_str()[1..].parse() {
Ok(o) => (o, i.span().clone()),
Ok(o) => (o, i.span()),
Err(_) => {
errors.push(CompileError::InvalidImmediateValue {
span: i.span().clone(),
});
errors.push(CompileError::InvalidImmediateValue { span: i.span() });
return err(warnings, errors);
}
},
Expand Down Expand Up @@ -1333,11 +1321,9 @@ fn two_regs_imm_12(
return err(warnings, errors);
}
Some(i) => match i.as_str()[1..].parse() {
Ok(o) => (o, i.span().clone()),
Ok(o) => (o, i.span()),
Err(_) => {
errors.push(CompileError::InvalidImmediateValue {
span: i.span().clone(),
});
errors.push(CompileError::InvalidImmediateValue { span: i.span() });
return err(warnings, errors);
}
},
Expand Down
10 changes: 5 additions & 5 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
type_engine::{resolve_type, TypeInfo},
CompileError, CompileWarning, Ident, TreeType, Warning,
};
use sway_types::span::Span;
use sway_types::{span::Span, Spanned};

use crate::semantic_analysis::TypedStorageDeclaration;

Expand Down Expand Up @@ -45,7 +45,7 @@ impl ControlFlowGraph {
variant_name,
is_public,
} if !is_public => Some(CompileWarning {
span: variant_name.span().clone(),
span: variant_name.span(),
warning_content: Warning::DeadEnumVariant {
variant_name: variant_name.clone(),
},
Expand All @@ -64,7 +64,7 @@ impl ControlFlowGraph {
variant_name,
is_public,
} if !is_public => Some(CompileWarning {
span: variant_name.span().clone(),
span: variant_name.span(),
warning_content: Warning::DeadEnumVariant {
variant_name: variant_name.clone(),
},
Expand All @@ -79,7 +79,7 @@ impl ControlFlowGraph {
warning_content: Warning::StructFieldNeverRead,
}),
ControlFlowGraphNode::StorageField { field_name, .. } => Some(CompileWarning {
span: field_name.span().clone(),
span: field_name.span(),
warning_content: Warning::DeadStorageDeclaration,
}),
ControlFlowGraphNode::OrganizationalDominator(..) => None,
Expand Down Expand Up @@ -1163,7 +1163,7 @@ fn construct_dead_code_warning_from_node(node: &TypedAstNode) -> Option<CompileW
)),
..
} => CompileWarning {
span: name.span().clone(),
span: name.span(),
warning_content: Warning::DeadTrait,
},
TypedAstNode {
Expand Down
10 changes: 5 additions & 5 deletions sway-core/src/convert_parse_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ pub enum ConvertParseTreeError {
RecursiveType { span: Span },
}

impl ConvertParseTreeError {
pub fn span(&self) -> Span {
impl Spanned for ConvertParseTreeError {
fn span(&self) -> Span {
match self {
ConvertParseTreeError::PubUseNotSupported { span } => span.clone(),
ConvertParseTreeError::ReturnOutsideOfBlock { span } => span.clone(),
Expand Down Expand Up @@ -587,7 +587,7 @@ fn get_attributed_purity(
_otherwise => {
return Err(ec.error(ConvertParseTreeError::InvalidAttributeArgument {
attribute: "storage".to_owned(),
span: arg.span().clone(),
span: arg.span(),
}));
}
}
Expand Down Expand Up @@ -1354,7 +1354,7 @@ fn expr_to_expression(ec: &mut ErrorContext, expr: Expr) -> Result<Expression, E
};
match method_type_opt {
Some(type_name) => {
let type_name_span = type_name.span().clone();
let type_name_span = type_name.span();
let type_name = match type_name_to_type_info_opt(&type_name) {
Some(type_info) => type_info,
None => TypeInfo::Custom {
Expand Down Expand Up @@ -2418,7 +2418,7 @@ fn asm_block_to_asm_expression(
let asm_register = AsmRegister {
name: asm_final_expr.register.as_str().to_owned(),
};
let returns = Some((asm_register, asm_final_expr.register.span().clone()));
let returns = Some((asm_register, asm_final_expr.register.span()));
let return_type = match asm_final_expr.ty_opt {
Some((_colon_token, ty)) => ty_to_type_info(ec, ty)?,
None => TypeInfo::UnsignedInteger(IntegerBits::SixtyFour),
Expand Down
Loading

0 comments on commit 3afc08d

Please sign in to comment.