From bdd51adbbc32c3ff8fc0d7b1dbc98fffc923fce8 Mon Sep 17 00:00:00 2001 From: Ariel Davis Date: Thu, 30 Nov 2023 01:00:56 -0800 Subject: [PATCH] Use one line more often --- crates/sml-statics-types/src/display.rs | 21 ++++++++------------- crates/sml-statics/src/error.rs | 22 +++++++++++----------- docs/CHANGELOG.md | 4 ++++ 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/crates/sml-statics-types/src/display.rs b/crates/sml-statics-types/src/display.rs index 3b42c8c7b..cf53aa902 100644 --- a/crates/sml-statics-types/src/display.rs +++ b/crates/sml-statics-types/src/display.rs @@ -366,19 +366,14 @@ impl fmt::Display for RecordMetaVarDisplay<'_> { impl Incompatible { /// Returns a value that displays this. #[must_use] - pub fn display<'a>( - &'a self, - st: &'a St, - lines: config::DiagnosticLines, - ) -> impl fmt::Display + 'a { - IncompatibleDisplay { flavor: self, st, lines } + pub fn display<'a>(&'a self, st: &'a St) -> impl fmt::Display + 'a { + IncompatibleDisplay { flavor: self, st } } } struct IncompatibleDisplay<'a> { flavor: &'a Incompatible, st: &'a St, - lines: config::DiagnosticLines, } impl fmt::Display for IncompatibleDisplay<'_> { @@ -400,8 +395,8 @@ impl fmt::Display for IncompatibleDisplay<'_> { write!(f, "`{a}` and `{b}` are different type constructors") } Incompatible::HeadMismatch(a, b) => { - let a_display = a.display(self.st, self.lines); - let b_display = b.display(self.st, self.lines); + let a_display = a.display(self.st, config::DiagnosticLines::One); + let b_display = b.display(self.st, config::DiagnosticLines::One); let a_desc = a.desc(); let b_desc = b.desc(); write!(f, "`{a_display}` is {a_desc}, but `{b_display}` is {b_desc}") @@ -417,7 +412,7 @@ impl fmt::Display for IncompatibleDisplay<'_> { write!(f, "record types are not compatible with the `{ov}` overload") } Incompatible::OverloadHeadMismatch(ov, ty) => { - let ty_display = ty.display(self.st, self.lines); + let ty_display = ty.display(self.st, config::DiagnosticLines::One); let ty_desc = ty.desc(); write!(f, "`{ov}` is an overloaded type, but `{ty_display}` is {ty_desc}") } @@ -425,13 +420,13 @@ impl fmt::Display for IncompatibleDisplay<'_> { write!(f, "unresolved record type is missing field: `{lab}`") } Incompatible::UnresolvedRecordHeadMismatch(rows, ty) => { - let ty_display = ty.display(self.st, self.lines); + let ty_display = ty.display(self.st, config::DiagnosticLines::One); let ty_desc = ty.desc(); - let rows = record_meta_var(self.st, rows, self.lines); + let rows = record_meta_var(self.st, rows, config::DiagnosticLines::One); write!(f, "`{rows}` is an unresolved record type, but `{ty_display}` is {ty_desc}") } Incompatible::NotEqTy(ty, not_eq) => { - let ty = ty.display(self.st, self.lines); + let ty = ty.display(self.st, config::DiagnosticLines::One); write!(f, "not an equality type because it contains {not_eq}: `{ty}`") } } diff --git a/crates/sml-statics/src/error.rs b/crates/sml-statics/src/error.rs index 9676abc73..b527982a2 100644 --- a/crates/sml-statics/src/error.rs +++ b/crates/sml-statics/src/error.rs @@ -81,15 +81,15 @@ impl fmt::Display for ErrorKindDisplay<'_> { ErrorKind::Missing(item, name) => write!(f, "missing {item} required by signature: `{name}`"), ErrorKind::Extra(item, name) => write!(f, "extra {item} not present in signature: `{name}`"), ErrorKind::Circularity(circ) => { - let mv = circ.meta_var.display(self.st, self.lines); - let ty = circ.ty.display(self.st, self.lines); + let mv = circ.meta_var.display(self.st, config::DiagnosticLines::One); + let ty = circ.ty.display(self.st, config::DiagnosticLines::One); write!(f, "circular type: `{mv}` occurs in `{ty}`") } ErrorKind::IncompatibleTys(reason, want, got) => { - let reason = reason.display(self.st, self.lines); + let reason = reason.display(self.st); write!(f, "incompatible types: {reason}")?; - let want = want.display(self.st, self.lines); - let got = got.display(self.st, self.lines); + let want = want.display(self.st, config::DiagnosticLines::One); + let got = got.display(self.st, config::DiagnosticLines::One); match self.lines { config::DiagnosticLines::One => { write!(f, ": expected `{want}`, found `{got}`") @@ -112,7 +112,7 @@ impl fmt::Display for ErrorKindDisplay<'_> { ErrorKind::ConPatMustHaveArg => f.write_str("missing argument for constructor pattern"), ErrorKind::InvalidAsPatName(name) => write!(f, "invalid `as` pat name: `{name}`"), ErrorKind::TyEscape(ty) => { - let ty = ty.display(self.st, self.lines); + let ty = ty.display(self.st, config::DiagnosticLines::One); write!(f, "type escapes its scope: `{ty}`") } ErrorKind::ValRecExpNotFn => f.write_str("the expression for a `val rec` was not a `fn`"), @@ -124,7 +124,7 @@ impl fmt::Display for ErrorKindDisplay<'_> { ErrorKind::InvalidRebindName(name) => write!(f, "cannot re-bind name: `{name}`"), ErrorKind::WrongIdStatus(name) => write!(f, "incompatible identifier statuses: `{name}`"), ErrorKind::UnresolvedRecordTy(rows) => { - let ty = record_meta_var(self.st, rows, self.lines); + let ty = record_meta_var(self.st, rows, config::DiagnosticLines::One); write!(f, "cannot resolve `...` in record type: `{ty}`") } ErrorKind::OrPatNotSameBindings(name) => { @@ -132,7 +132,7 @@ impl fmt::Display for ErrorKindDisplay<'_> { } ErrorKind::DecNotAllowedHere => f.write_str("`signature` or `functor` not allowed here"), ErrorKind::ExpHole(ty) => { - let ty = ty.display(self.st, self.lines); + let ty = ty.display(self.st, config::DiagnosticLines::One); write!(f, "expression hole with type `{ty}`") } ErrorKind::TyHole => f.write_str("type hole"), @@ -146,11 +146,11 @@ impl fmt::Display for ErrorKindDisplay<'_> { f.write_str("type variable bound at `val` or `fun` not allowed here") } ErrorKind::CannotShareTy(path, ts) => { - let ts = ts.display(self.st, self.lines); + let ts = ts.display(self.st, config::DiagnosticLines::One); write!(f, "cannot share type `{path}` as `{ts}`") } ErrorKind::CannotRealizeTy(path, ts) => { - let ts = ts.display(self.st, self.lines); + let ts = ts.display(self.st, config::DiagnosticLines::One); write!(f, "cannot realize type `{path}` as `{ts}`") } ErrorKind::InvalidEq(name) => write!(f, "calling `=` or `<>` on `{name}`"), @@ -176,7 +176,7 @@ impl fmt::Display for ErrorKindDisplay<'_> { write!(f, "`fn {name} => f {name}`, can be simplified to `f`") } ErrorKind::ShadowInCaseWithSameTy(name, ty_scheme) => { - let ty_scheme = ty_scheme.display(self.st, self.lines); + let ty_scheme = ty_scheme.display(self.st, config::DiagnosticLines::One); write!(f, "this pattern, which binds `{name}` with type `{ty_scheme}`, ")?; write!(f, "does not check any part of the matched expression for equality with the ")?; write!(f, "existing `{name}`, which has the same type, and which was already in scope") diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9a3a60d15..cf0ab7b0c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,10 @@ The versioning system is basically the following: - If there's a really "big" change. - As mentioned, the "major" version is 0. +## main + +- Use multi-line types less often in error messages. + ## v0.14.0 - Warn when a `.sig` file doesn't contain 1 `signature`.