diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-09-17 14:09:43 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-17 14:09:43 +0900 |
| commit | f4f7704eddb007c9b5b5a0c5663ab3efe778ca57 (patch) | |
| tree | 8a982f7ef97c997308268d9de13532a72e313104 /compiler/rustc_errors/src | |
| parent | 78a46efff06558674b51c10d8d81758285746ab5 (diff) | |
| parent | 378300a63d1951e2718a6b0a077439fc1b14742b (diff) | |
Rollup merge of #86382 - JohnTitor:try-desugar, r=estebank
Make diagnostics clearer for `?` operators Re-submission of #75029, fixes #71309 This also revives the `content` methods removed by #83185. r? `@estebank`
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) |
