diff options
| author | Yuki Okushi <yuki.okushi@huawei.com> | 2021-06-17 06:35:42 +0900 |
|---|---|---|
| committer | Yuki Okushi <yuki.okushi@huawei.com> | 2021-09-17 13:13:28 +0900 |
| commit | 378300a63d1951e2718a6b0a077439fc1b14742b (patch) | |
| tree | 8a982f7ef97c997308268d9de13532a72e313104 /compiler/rustc_errors/src | |
| parent | 78a46efff06558674b51c10d8d81758285746ab5 (diff) | |
| download | rust-378300a63d1951e2718a6b0a077439fc1b14742b.tar.gz rust-378300a63d1951e2718a6b0a077439fc1b14742b.zip | |
Make diagnostics clearer for `?` operators
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 232cf4bdb7f..41a73268f46 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -74,6 +74,10 @@ impl DiagnosticStyledString { pub fn highlighted<S: Into<String>>(t: S) -> DiagnosticStyledString { DiagnosticStyledString(vec![StringPart::Highlighted(t.into())]) } + + pub fn content(&self) -> String { + self.0.iter().map(|x| x.content()).collect::<String>() + } } #[derive(Debug, PartialEq, Eq)] @@ -82,6 +86,14 @@ pub enum StringPart { Highlighted(String), } +impl StringPart { + pub fn content(&self) -> &str { + match self { + &StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s, + } + } +} + impl Diagnostic { pub fn new(level: Level, message: &str) -> Self { Diagnostic::new_with_code(level, None, message) |
