Skip to content

Commit 8489a67

Browse files
committed
Implement IntoDiagnosticArg for rustc_ast::Path
1 parent 495e271 commit 8489a67

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,8 @@ version = "0.0.0"
34383438
dependencies = [
34393439
"annotate-snippets",
34403440
"atty",
3441+
"rustc_ast",
3442+
"rustc_ast_pretty",
34413443
"rustc_data_structures",
34423444
"rustc_error_messages",
34433445
"rustc_hir",

compiler/rustc_errors/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ doctest = false
88

99
[dependencies]
1010
tracing = "0.1"
11+
rustc_ast = { path = "../rustc_ast" }
12+
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1113
rustc_error_messages = { path = "../rustc_error_messages" }
1214
rustc_serialize = { path = "../rustc_serialize" }
1315
rustc_span = { path = "../rustc_span" }

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use crate::{
33
CodeSuggestion, DiagnosticMessage, EmissionGuarantee, Level, LintDiagnosticBuilder, MultiSpan,
44
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
55
};
6+
use rustc_ast as ast;
7+
use rustc_ast_pretty::pprust;
68
use rustc_data_structures::fx::FxHashMap;
79
use rustc_error_messages::FluentValue;
810
use rustc_hir as hir;
@@ -175,6 +177,12 @@ impl IntoDiagnosticArg for hir::ConstContext {
175177
}
176178
}
177179

180+
impl IntoDiagnosticArg for ast::Path {
181+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
182+
DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(&self)))
183+
}
184+
}
185+
178186
/// Trait implemented by error types. This should not be implemented manually. Instead, use
179187
/// `#[derive(Subdiagnostic)]` -- see [rustc_macros::Subdiagnostic].
180188
#[cfg_attr(bootstrap, rustc_diagnostic_item = "AddSubdiagnostic")]

0 commit comments

Comments
 (0)