|
1 | | -use rustc_errors::MultiSpan; |
| 1 | +use rustc_errors::{DiagArgValue, MultiSpan}; |
2 | 2 | use rustc_macros::{Diagnostic, Subdiagnostic}; |
3 | 3 | use rustc_span::{Span, Symbol}; |
4 | 4 |
|
@@ -66,3 +66,114 @@ pub(crate) struct UnsafeAttrOutsideUnsafeLint { |
66 | 66 | #[subdiagnostic] |
67 | 67 | pub suggestion: Option<crate::session_diagnostics::UnsafeAttrOutsideUnsafeSuggestion>, |
68 | 68 | } |
| 69 | + |
| 70 | +#[derive(Diagnostic)] |
| 71 | +#[diag( |
| 72 | + "{$num_suggestions -> |
| 73 | + [1] attribute must be of the form {$suggestions} |
| 74 | + *[other] valid forms for the attribute are {$suggestions} |
| 75 | + }" |
| 76 | +)] |
| 77 | +pub(crate) struct IllFormedAttributeInput { |
| 78 | + pub num_suggestions: usize, |
| 79 | + pub suggestions: DiagArgValue, |
| 80 | + #[note("for more information, visit <{$docs}>")] |
| 81 | + pub has_docs: bool, |
| 82 | + pub docs: &'static str, |
| 83 | + #[subdiagnostic] |
| 84 | + help: Option<IllFormedAttributeInputHelp>, |
| 85 | +} |
| 86 | + |
| 87 | +impl IllFormedAttributeInput { |
| 88 | + pub(crate) fn new( |
| 89 | + suggestions: &[String], |
| 90 | + docs: Option<&'static str>, |
| 91 | + help: Option<&str>, |
| 92 | + ) -> Self { |
| 93 | + Self { |
| 94 | + num_suggestions: suggestions.len(), |
| 95 | + suggestions: DiagArgValue::StrListSepByAnd( |
| 96 | + suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(), |
| 97 | + ), |
| 98 | + has_docs: docs.is_some(), |
| 99 | + docs: docs.unwrap_or(""), |
| 100 | + help: help.map(|h| IllFormedAttributeInputHelp { lint: h.to_string() }), |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +#[derive(Subdiagnostic)] |
| 106 | +#[help( |
| 107 | + "if you meant to silence a warning, consider using #![allow({$lint})] or #![expect({$lint})]" |
| 108 | +)] |
| 109 | +struct IllFormedAttributeInputHelp { |
| 110 | + pub lint: String, |
| 111 | +} |
| 112 | + |
| 113 | +#[derive(Diagnostic)] |
| 114 | +#[diag("unused attribute")] |
| 115 | +#[note( |
| 116 | + "{$valid_without_list -> |
| 117 | + [true] using `{$attr_path}` with an empty list is equivalent to not using a list at all |
| 118 | + *[other] using `{$attr_path}` with an empty list has no effect |
| 119 | + }" |
| 120 | +)] |
| 121 | +pub(crate) struct EmptyAttributeList<'a> { |
| 122 | + #[suggestion( |
| 123 | + "{$valid_without_list -> |
| 124 | + [true] remove these parentheses |
| 125 | + *[other] remove this attribute |
| 126 | + }", |
| 127 | + code = "", |
| 128 | + applicability = "machine-applicable" |
| 129 | + )] |
| 130 | + pub attr_span: Span, |
| 131 | + pub attr_path: &'a str, |
| 132 | + pub valid_without_list: bool, |
| 133 | +} |
| 134 | + |
| 135 | +#[derive(Diagnostic)] |
| 136 | +#[diag("`#[{$name}]` attribute cannot be used on {$target}")] |
| 137 | +#[warning( |
| 138 | + "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" |
| 139 | +)] |
| 140 | +#[help("`#[{$name}]` can {$only}be applied to {$applied}")] |
| 141 | +pub(crate) struct InvalidTargetLint { |
| 142 | + pub name: String, |
| 143 | + pub target: &'static str, |
| 144 | + pub applied: DiagArgValue, |
| 145 | + pub only: &'static str, |
| 146 | + #[suggestion( |
| 147 | + "remove the attribute", |
| 148 | + code = "", |
| 149 | + applicability = "machine-applicable", |
| 150 | + style = "tool-only" |
| 151 | + )] |
| 152 | + pub attr_span: Span, |
| 153 | +} |
| 154 | + |
| 155 | +#[derive(Diagnostic)] |
| 156 | +#[diag( |
| 157 | + "{$is_used_as_inner -> |
| 158 | + [false] crate-level attribute should be an inner attribute: add an exclamation mark: `#![{$name}]` |
| 159 | + *[other] the `#![{$name}]` attribute can only be used at the crate root |
| 160 | + }" |
| 161 | +)] |
| 162 | +pub(crate) struct InvalidAttrStyle<'a> { |
| 163 | + pub name: &'a str, |
| 164 | + pub is_used_as_inner: bool, |
| 165 | + #[note("this attribute does not have an `!`, which means it is applied to this {$target}")] |
| 166 | + pub target_span: Option<Span>, |
| 167 | + pub target: &'static str, |
| 168 | +} |
| 169 | + |
| 170 | +#[derive(Diagnostic)] |
| 171 | +#[diag("doc alias is duplicated")] |
| 172 | +pub(crate) struct DocAliasDuplicated { |
| 173 | + #[label("first defined here")] |
| 174 | + pub first_definition: Span, |
| 175 | +} |
| 176 | + |
| 177 | +#[derive(Diagnostic)] |
| 178 | +#[diag("only `hide` or `show` are allowed in `#[doc(auto_cfg(...))]`")] |
| 179 | +pub(crate) struct DocAutoCfgExpectsHideOrShow; |
0 commit comments