forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81d7336
commit 322b8d2
Showing
39 changed files
with
656 additions
and
597 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,63 @@ | ||
use rustc_hir::AttributeKind; | ||
use rustc_span::{Symbol, sym}; | ||
use rustc_span::{Span, Symbol, sym}; | ||
use thin_vec::ThinVec; | ||
|
||
use super::{AttributeFilter, AttributeGroup, AttributeMapping}; | ||
use crate::attribute_filter; | ||
use crate::context::AttributeGroupContext; | ||
use crate::parser::ArgParser; | ||
use crate::{attribute_filter, session_diagnostics}; | ||
|
||
// TODO: turn into CombineGroup? | ||
#[derive(Default)] | ||
pub(crate) struct ConfusablesGroup { | ||
confusables: ThinVec<Symbol>, | ||
first_span: Option<Span>, | ||
} | ||
|
||
impl AttributeGroup for ConfusablesGroup { | ||
const ATTRIBUTES: AttributeMapping<Self> = &[(&[sym::rustc_confusables], |this, _cx, args| { | ||
const ATTRIBUTES: AttributeMapping<Self> = &[(&[sym::rustc_confusables], |this, cx, args| { | ||
let Some(list) = args.list() else { | ||
// TODO: error when not a list? Bring validation code here. | ||
// NOTE: currently subsequent attributes are silently ignored using | ||
// tcx.get_attr(). | ||
return; | ||
}; | ||
|
||
if list.is_empty() { | ||
cx.dcx().emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span }); | ||
} | ||
|
||
for param in list.mixed() { | ||
let span = param.span(); | ||
|
||
let Some(lit) = param.lit() else { | ||
// TODO: error when not a lit? Bring validation code here. | ||
// curently silently ignored. | ||
return; | ||
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem { | ||
span, | ||
suggestion: Some(session_diagnostics::IncorrectMetaItemSuggestion { | ||
lo: span.shrink_to_lo(), | ||
hi: span.shrink_to_hi(), | ||
}), | ||
}); | ||
continue; | ||
}; | ||
|
||
this.confusables.push(lit.symbol); | ||
} | ||
|
||
this.first_span.get_or_insert(cx.attr_span); | ||
})]; | ||
|
||
fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option<(AttributeKind, AttributeFilter)> { | ||
Some((AttributeKind::Confusables(self.confusables), attribute_filter!(allow all))) | ||
if self.confusables.is_empty() { | ||
return None; | ||
} | ||
|
||
Some(( | ||
AttributeKind::Confusables { | ||
symbols: self.confusables, | ||
first_span: self.first_span.unwrap(), | ||
}, | ||
attribute_filter!(allow all), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.