Path: blob/master/rust/pin-init/internal/src/diagnostics.rs
121834 views
// SPDX-License-Identifier: Apache-2.0 OR MIT12use std::fmt::Display;34use proc_macro2::TokenStream;5use syn::{spanned::Spanned, Error};67pub(crate) struct DiagCtxt(TokenStream);8pub(crate) struct ErrorGuaranteed(());910impl DiagCtxt {11pub(crate) fn error(&mut self, span: impl Spanned, msg: impl Display) -> ErrorGuaranteed {12let error = Error::new(span.span(), msg);13self.0.extend(error.into_compile_error());14ErrorGuaranteed(())15}1617pub(crate) fn with(18fun: impl FnOnce(&mut DiagCtxt) -> Result<TokenStream, ErrorGuaranteed>,19) -> TokenStream {20let mut dcx = Self(TokenStream::new());21match fun(&mut dcx) {22Ok(mut stream) => {23stream.extend(dcx.0);24stream25}26Err(ErrorGuaranteed(())) => dcx.0,27}28}29}303132