From 75ec606f5307d13d5226442c1706b4c5fa34f502 Mon Sep 17 00:00:00 2001 From: Chance Date: Sat, 25 Jan 2025 12:17:58 -0500 Subject: [PATCH] still broken.. i dont think related is the way to go --- Cargo.lock | 104 +++++++++------------------------------------- Cargo.toml | 2 +- src/assign.rs | 3 +- src/diagnostic.rs | 90 +++++++++++++++++++++++++++++++++------ src/pointer.rs | 47 +++++++++++---------- 5 files changed, 126 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 614e52f..f22b580 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,7 +38,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets 0.52.6", + "windows-targets", ] [[package]] @@ -172,9 +172,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miette" -version = "7.2.0" +version = "7.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4edc8853320c2a0dab800fbda86253c8938f6ea88510dc92c5f1ed20e794afc1" +checksum = "317f146e2eb7021892722af37cf1b971f0a70c8406f487e24952667616192c64" dependencies = [ "backtrace", "backtrace-ext", @@ -192,9 +192,9 @@ dependencies = [ [[package]] name = "miette-derive" -version = "7.2.0" +version = "7.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" +checksum = "23c9b935fbe1d6cbd1dac857b54a688145e2d93f48db36010514d0f612d0ad67" dependencies = [ "proc-macro2", "quote", @@ -378,12 +378,6 @@ dependencies = [ "serde", ] -[[package]] -name = "smawk" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c" - [[package]] name = "supports-color" version = "3.0.1" @@ -429,12 +423,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "5352447f921fda68cf61b4101566c0bdb5104eff6804d0678e5227580ab6a4e9" dependencies = [ "rustix", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -443,7 +437,6 @@ version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" dependencies = [ - "smawk", "unicode-linebreak", "unicode-width", ] @@ -526,37 +519,22 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", + "windows-targets", ] [[package]] -name = "windows-targets" -version = "0.48.5" +name = "windows-sys" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -565,46 +543,28 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -617,48 +577,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index f658d1d..b137ae6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rust-version = "1.79.0" version = "0.6.3" [dependencies] -miette = { version = "7.2.0", optional = true, features = ["fancy"] } +miette = { version = "7.4.0", optional = true, features = ["fancy"] } serde = { version = "1.0.203", optional = true, features = ["alloc"] } serde_json = { version = "1.0.119", optional = true, features = ["alloc"] } toml = { version = "0.8", optional = true } diff --git a/src/assign.rs b/src/assign.rs index 7f627e1..ed43e5c 100644 --- a/src/assign.rs +++ b/src/assign.rs @@ -43,6 +43,7 @@ use crate::{ }; use alloc::borrow::Cow; use core::{ + convert::Infallible, fmt::{self, Debug}, iter::once, }; @@ -230,7 +231,7 @@ impl fmt::Display for Error { impl Diagnostic for Error { type Subject = PointerBuf; - type Related = (); + type Related = Infallible; fn url() -> &'static str { impl_diagnostic_url!(enum assign::Error) diff --git a/src/diagnostic.rs b/src/diagnostic.rs index b73e45d..9fc31b0 100644 --- a/src/diagnostic.rs +++ b/src/diagnostic.rs @@ -1,25 +1,24 @@ //! Error reporting data structures and miette integration. -use core::{fmt, ops::Deref}; +use core::{convert::Infallible, fmt, ops::Deref}; +use std::sync::OnceLock; /// Implemented by errors which can be converted into a [`Report`]. pub trait Diagnostic: Sized { /// The value which caused the error. type Subject: Deref; - // TODO: this is here to handle multiple errors, if we choose to support it. remove if not needed. /// Optional type of related errors for miette reporting. /// /// This is required as this trait is not object safe. Implementations which - /// do not have related errors should use `()`. + /// do not have related errors should use + /// [`Infallible`](core::convert::Infallible) and simply not implement + /// `related`. type Related; /// Combine the error with its subject to generate a [`Report`]. fn into_report(self, subject: impl Into) -> Report { - Report { - source: self, - subject: subject.into(), - } + Report::new(self, subject.into()) } /// The docs.rs URL for this error @@ -28,14 +27,40 @@ pub trait Diagnostic: Sized { /// Returns the label for the given [`Subject`] if applicable. fn labels(&self, subject: &Self::Subject) -> Option>>; - // TODO: this is here to handle multiple errors, if we choose to support it. remove if not needed. - // The idea is that we will need - fn related(&self) -> Option>> { + /// Returns the related errors if applicable. + fn related(&self, subject: &Self::Subject) -> Vec { + _ = subject; + vec![] + } +} +impl Diagnostic for () { + type Subject = String; + type Related = (); + + fn url() -> &'static str { + "" + } + + fn labels(&self, _: &Self::Subject) -> Option>> { + None + } +} + +impl Diagnostic for Infallible { + type Subject = String; + type Related = (); + + fn url() -> &'static str { + "https://doc.rust-lang.org/std/convert/enum.Infallible.html" + } + + fn labels(&self, _: &Self::Subject) -> Option>> { None } } /// A label for a span within a json pointer or malformed string. +/// #[derive(Debug, PartialEq, Eq, Clone)] pub struct Label { text: String, @@ -58,13 +83,22 @@ impl From