From 8489a67f0b0ca5a973d48b27d609c91cb93cf343 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 14 Sep 2022 19:22:20 +0200 Subject: [PATCH] Implement IntoDiagnosticArg for rustc_ast::Path --- Cargo.lock | 2 ++ compiler/rustc_errors/Cargo.toml | 2 ++ compiler/rustc_errors/src/diagnostic.rs | 8 ++++++++ 3 files changed, 12 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c99a07f40b2e..6432a0426b7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3438,6 +3438,8 @@ version = "0.0.0" dependencies = [ "annotate-snippets", "atty", + "rustc_ast", + "rustc_ast_pretty", "rustc_data_structures", "rustc_error_messages", "rustc_hir", diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index c36ca11fad6f..1eb9dca2a2b9 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -8,6 +8,8 @@ doctest = false [dependencies] tracing = "0.1" +rustc_ast = { path = "../rustc_ast" } +rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_error_messages = { path = "../rustc_error_messages" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 1c440a0a07ef..fb409c578f6d 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -3,6 +3,8 @@ use crate::{ CodeSuggestion, DiagnosticMessage, EmissionGuarantee, Level, LintDiagnosticBuilder, MultiSpan, SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle, }; +use rustc_ast as ast; +use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; use rustc_error_messages::FluentValue; use rustc_hir as hir; @@ -175,6 +177,12 @@ impl IntoDiagnosticArg for hir::ConstContext { } } +impl IntoDiagnosticArg for ast::Path { + fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { + DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self))) + } +} + /// Trait implemented by error types. This should not be implemented manually. Instead, use /// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic]. #[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]