diff options
| author | bors <bors@rust-lang.org> | 2024-09-18 04:01:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-09-18 04:01:51 +0000 |
| commit | f6bcd094abe174a218f7cf406e75521be4199f88 (patch) | |
| tree | 6505fe769ecf4568d5fb8466f19168ce9a0cdb98 /compiler/rustc_errors/src/lib.rs | |
| parent | 60c3673456cb5eba4d6ac4ed22be179deebb6dcf (diff) | |
| parent | c52d58dce1044c896153082272522a1d499e95b0 (diff) | |
| download | rust-f6bcd094abe174a218f7cf406e75521be4199f88.tar.gz rust-f6bcd094abe174a218f7cf406e75521be4199f88.zip | |
Auto merge of #130498 - matthiaskrgr:rollup-tg4d0zi, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #130116 (Implement a Method to Seal `DiagInner`'s Suggestions) - #130489 (Ensure that `keyword_ident` lint doesn't trigger on `'r#kw` lifetime) - #130491 (more crash tests) - #130496 (Fix circular fn_sig queries to correct number of args for methods) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_errors/src/lib.rs')
| -rw-r--r-- | compiler/rustc_errors/src/lib.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 13da1721a4a..094e3010471 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -126,6 +126,41 @@ impl SuggestionStyle { } } +/// Represents the help messages seen on a diagnostic. +#[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] +pub enum Suggestions { + /// Indicates that new suggestions can be added or removed from this diagnostic. + /// + /// `DiagInner`'s new_* methods initialize the `suggestions` field with + /// this variant. Also, this is the default variant for `Suggestions`. + Enabled(Vec<CodeSuggestion>), + /// Indicates that suggestions cannot be added or removed from this diagnostic. + /// + /// Gets toggled when `.seal_suggestions()` is called on the `DiagInner`. + Sealed(Box<[CodeSuggestion]>), + /// Indicates that no suggestion is available for this diagnostic. + /// + /// Gets toggled when `.disable_suggestions()` is called on the `DiagInner`. + Disabled, +} + +impl Suggestions { + /// Returns the underlying list of suggestions. + pub fn unwrap_tag(self) -> Vec<CodeSuggestion> { + match self { + Suggestions::Enabled(suggestions) => suggestions, + Suggestions::Sealed(suggestions) => suggestions.into_vec(), + Suggestions::Disabled => Vec::new(), + } + } +} + +impl Default for Suggestions { + fn default() -> Self { + Self::Enabled(vec![]) + } +} + #[derive(Clone, Debug, PartialEq, Hash, Encodable, Decodable)] pub struct CodeSuggestion { /// Each substitute can have multiple variants due to multiple |
