Skip to content

Commit

Permalink
Format the code base
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Nov 11, 2023
1 parent 8ed9adc commit bdcd36d
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 82 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustflags = [
"-Aclippy::result_unit_err", # ‘Result<_, ()>’ has its uses, in some cases an alt. to ‘Option<_>’
"-Aclippy::return_self_not_must_use", # @Temporary, a churn to fix, not a priority right now
"-Aclippy::similar_names", # too strict
"-Aclippy::struct_field_names", # too many false positives
"-Aclippy::single_match_else", # too opinionated, match exprs look better in many cases
"-Aclippy::struct_excessive_bools", # too many false postives with CLI flag structs
"-Aclippy::too_many_lines", # too opinionated
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion compiler/ast/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ impl Path {
}

pub fn join(mut self, other: Self) -> Result<Self, Hanger> {
if let Some(hanger) = other.hanger && !matches!(hanger.bare, BareHanger::Self_) {
if let Some(hanger) = other.hanger
&& !matches!(hanger.bare, BareHanger::Self_)
{
return Err(hanger);
}
self.segments.extend(other.segments);
Expand Down
4 changes: 3 additions & 1 deletion compiler/codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ pub fn compile_and_link(
module.print_to_stderr();
}

if options.verify_llvm_ir && let Err(message) = module.verify() {
if options.verify_llvm_ir
&& let Err(message) = module.verify()
{
return Err(Diagnostic::bug()
.message("the generated LLVM-IR is invalid")
.note(message.to_string())
Expand Down
2 changes: 1 addition & 1 deletion compiler/diagnostics/src/render.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Diagnostic formatting.
//! The code responsible for rendering diagnostics.
// @Task make absolute paths relative to the current working directory
// @Bug tabs in snippets (and others?) mess up the alignment!
Expand Down
2 changes: 1 addition & 1 deletion compiler/driver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut features = Vec::new();
for (key, _) in std::env::vars_os() {
if let Some(key) = key.to_str()
&& let Some(feature) = key.strip_prefix("CARGO_FEATURE_")
&& let Some(feature) = key.strip_prefix("CARGO_FEATURE_")
{
features.push(feature.to_ascii_lowercase());
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ fn build_units(
})?;
}

if let BuildMode::Document { options } = mode && options.open {
if let BuildMode::Document { options } = mode
&& options.open
{
// @Task smh open in background and immediately disown the child process afterwards
if let Err(error) = open::that(documenter::index_page(context)) {
return Err(Diagnostic::error()
Expand Down Expand Up @@ -244,7 +246,7 @@ fn build_unit(
write!(stdout, " {label} ")?;
stdout.unset()?;

write!(stdout, "{} ({})", unit.name, unit.path.bare.display())
writeln!(stdout, "{} ({})", unit.name, unit.path.bare.display())
},
global_options.color,
)
Expand Down
14 changes: 8 additions & 6 deletions compiler/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,13 @@ pub struct Namespace {

impl fmt::Debug for Namespace {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.binders
let binders = self
.binders
.iter()
.map(|binding| format!("{binding:?}"))
.join_with(' ')
.fmt(f)
.map(|binder| format!("{binder:?}"))
.join_with(' ');

write!(f, "{binders}")
}
}

Expand Down Expand Up @@ -449,8 +451,8 @@ impl From<ExposureReach> for Exposure {
impl fmt::Debug for Exposure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Unrestricted => write!(f, "*"),
Self::Restricted(reach) => write!(f, "{:?}", reach.lock().unwrap()),
Self::Unrestricted => f.pad("*"),
Self::Restricted(reach) => f.pad(&format!("{:?}", reach.lock().unwrap())),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ impl<'a> Lexer<'a> {
// greater or equal to the one of the corresponding opening bracket.
// @Note actually it would be even better if we could emit a nice diagnostic for
// closing brackets that are dedented too far.
if let Some(')' | ']' | '}') = self.peek() && !has_removed_line_break {
if let Some(')' | ']' | '}') = self.peek()
&& !has_removed_line_break
{
// (*) Remove the line break again.
self.tokens.pop();
}
Expand Down
26 changes: 15 additions & 11 deletions compiler/package/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,19 @@ impl BuildQueue {
let manifest_path = CanonicalPathBuf::new(&manifest_path_unchecked).map(ManifestPath::from);

// Deduplicate packages by absolute path and check for circular components.
if let Ok(manifest_path) = manifest_path && let Some(package) = self.packages.get(&manifest_path) {
if let Ok(manifest_path) = manifest_path
&& let Some(package) = self.packages.get(&manifest_path)
{
// @Beacon @Task add a diag note for size-one cycles of the form `{ path: "." }` (etc) and
// recommend the dep-provider `package` (…)

// @Beacon @Note this probably won't scale to our new order-independent component resolver (maybe)
// if so, consider not throwing a cycle error (here / unconditionally)
// @Beacon @Task handle component privacy here
return match package.components.get(&component_endonym.bare) {
Some(&Resolved(component)) if self[component].type_ == ComponentType::Library => Ok(component),
Some(&Resolved(component)) if self[component].type_ == ComponentType::Library => {
Ok(component)
}
// @Bug this does not fire when we want to since the it is apparently unresolved at this stage for some reason
// @Task test this, is this reachable?
Some(&Resolved(component)) => Err(error::non_library_dependency_error(
Expand Down Expand Up @@ -473,7 +477,7 @@ impl BuildQueue {
error::undefined_component_error(component_endonym, package.name)
.report(&self.reporter)
.into(),
)
),
};
}

Expand Down Expand Up @@ -529,13 +533,11 @@ impl BuildQueue {
&& package_name.bare != manifest.profile.name.bare
{
// @Task message, @Task add UI test
return Err(
Diagnostic::error()
.message("declared package name does not match actual one")
.unlabeled_span(package_name)
.report(&self.reporter)
.into()
);
return Err(Diagnostic::error()
.message("declared package name does not match actual one")
.unlabeled_span(package_name)
.report(&self.reporter)
.into());
}

// @Task assert version requirement (if any) is fulfilled
Expand Down Expand Up @@ -645,7 +647,9 @@ impl BuildQueue {
.report(&self.reporter));
}

if provider != DependencyProvider::Filesystem && let Some(path) = &declaration.path {
if provider != DependencyProvider::Filesystem
&& let Some(path) = &declaration.path
{
// @Beacon @Task report an error that those things are incompatible
// @Task add test
// @Task add a 2nd *primary* span that highlights the provider (if available otherwise do sth. else)
Expand Down
16 changes: 12 additions & 4 deletions compiler/parser/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ impl Parser<'_> {
let (binder, kind, argument) = if self.token() == OpeningSquareBracket {
self.advance();

let binder = if let Word(binder) = self.token() && self.look_ahead(1) == Some(Equals) {
let binder = if let Word(binder) = self.token()
&& self.look_ahead(1) == Some(Equals)
{
let span = self.span();
self.advance(); // #Word
self.advance(); // "="
Expand All @@ -431,7 +433,7 @@ impl Parser<'_> {
&& self.look_ahead(2) == Some(Equals)
{
self.advance(); // "("
let binder = Identifier::new_unchecked( self.span(), binder);
let binder = Identifier::new_unchecked(self.span(), binder);
self.advance(); // #Word
self.advance(); // "="

Expand All @@ -448,15 +450,21 @@ impl Parser<'_> {
(None, kind, span.merging(self.parse_lower_item()?))
} else {
self.expected(Expectation::Argument);
self.annotate(Annotation::LabelWhileParsing { span: callee.span, name: T::KIND.name() });
self.annotate(Annotation::LabelWhileParsing {
span: callee.span,
name: T::KIND.name(),
});

if let ItemKind::Pattern = T::KIND
&& let Let = self.token()
&& let Some(Word(binder)) = self.look_ahead(1)
{
let span = self.span().merge(&self.succeeding(1));

self.annotate(Annotation::SuggestBracketsAroundLetBindingPattern { span, binder });
self.annotate(Annotation::SuggestBracketsAroundLetBindingPattern {
span,
binder,
});

return self.error();
} else if let Some(span) = apostrophe {
Expand Down
89 changes: 47 additions & 42 deletions compiler/resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,20 @@ impl<'sess, 'ctx> ResolverMut<'sess, 'ctx> {

let binder = Identifier::new(index.global(self.session), function.binder);

if let Some(intrinsic) = declaration.attributes.get::<{ AttributeName::Intrinsic }>()
&& let Err(error) = self.session.define_special(
special::Kind::Intrinsic,
binder,
match &intrinsic.bare.name {
Some(name) => special::DefinitionStyle::Explicit { name },
None => special::DefinitionStyle::Implicit {
namespace: Some(module),
if let Some(intrinsic) =
declaration.attributes.get::<{ AttributeName::Intrinsic }>()
&& let Err(error) = self.session.define_special(
special::Kind::Intrinsic,
binder,
match &intrinsic.bare.name {
Some(name) => special::DefinitionStyle::Explicit { name },
None => special::DefinitionStyle::Implicit {
namespace: Some(module),
},
},
},
intrinsic.span,
) {
intrinsic.span,
)
{
error.handle(&mut *self);
}
}
Expand All @@ -209,28 +211,31 @@ impl<'sess, 'ctx> ResolverMut<'sess, 'ctx> {

let known = declaration.attributes.get::<{ AttributeName::Known }>();
if let Some(known) = known
&& let Err(error) = self.session.define_special(
special::Kind::Known,
binder,
match &known.bare.name {
Some(name) => special::DefinitionStyle::Explicit { name },
None => special::DefinitionStyle::Implicit { namespace: None },
},
known.span,
) {
&& let Err(error) = self.session.define_special(
special::Kind::Known,
binder,
match &known.bare.name {
Some(name) => special::DefinitionStyle::Explicit { name },
None => special::DefinitionStyle::Implicit { namespace: None },
},
known.span,
)
{
error.handle(&mut *self);
}

if let Some(intrinsic) = declaration.attributes.get::<{ AttributeName::Intrinsic }>()
&& let Err(error) = self.session.define_special(
special::Kind::Intrinsic,
binder,
match &intrinsic.bare.name {
Some(name) => special::DefinitionStyle::Explicit { name },
None => special::DefinitionStyle::Implicit { namespace: None },
},
intrinsic.span,
) {
if let Some(intrinsic) =
declaration.attributes.get::<{ AttributeName::Intrinsic }>()
&& let Err(error) = self.session.define_special(
special::Kind::Intrinsic,
binder,
match &intrinsic.bare.name {
Some(name) => special::DefinitionStyle::Explicit { name },
None => special::DefinitionStyle::Implicit { namespace: None },
},
intrinsic.span,
)
{
error.handle(&mut *self);
}

Expand Down Expand Up @@ -292,14 +297,15 @@ impl<'sess, 'ctx> ResolverMut<'sess, 'ctx> {

// @Task support `@(known name)` on constructors
if let Some(known) = known
&& let Err(error) = self.session.define_special(
special::Kind::Known,
binder,
special::DefinitionStyle::Implicit {
namespace: Some(namespace),
},
known,
) {
&& let Err(error) = self.session.define_special(
special::Kind::Known,
binder,
special::DefinitionStyle::Implicit {
namespace: Some(namespace),
},
known,
)
{
error.handle(&mut *self);
}
}
Expand Down Expand Up @@ -1601,10 +1607,9 @@ impl<'a> Resolver<'a> {
}

if !context.allow_deprecated
&& let Some(deprecated) = self
.session[index]
.attributes
.get::<{ AttributeName::Deprecated }>()
&& let Some(deprecated) = self.session[index]
.attributes
.get::<{ AttributeName::Deprecated }>()
{
let mut message = format!(
"use of deprecated binding ‘{}’",
Expand Down
Loading

0 comments on commit bdcd36d

Please sign in to comment.