mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 02:52:11 +00:00
Merge pull request #19644 from ChayimFriedman2/const-syms
internal: Make predefined symbols `const` instead of `static`
This commit is contained in:
commit
34e7d60e30
72 changed files with 432 additions and 473 deletions
|
|
@ -117,17 +117,20 @@ impl Attrs {
|
|||
}
|
||||
|
||||
impl Attrs {
|
||||
pub fn by_key<'attrs>(&'attrs self, key: &'attrs Symbol) -> AttrQuery<'attrs> {
|
||||
#[inline]
|
||||
pub fn by_key(&self, key: Symbol) -> AttrQuery<'_> {
|
||||
AttrQuery { attrs: self, key }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rust_analyzer_tool(&self) -> impl Iterator<Item = &Attr> {
|
||||
self.iter()
|
||||
.filter(|&attr| attr.path.segments().first().is_some_and(|s| *s == sym::rust_analyzer))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn cfg(&self) -> Option<CfgExpr> {
|
||||
let mut cfgs = self.by_key(&sym::cfg).tt_values().map(CfgExpr::parse);
|
||||
let mut cfgs = self.by_key(sym::cfg).tt_values().map(CfgExpr::parse);
|
||||
let first = cfgs.next()?;
|
||||
match cfgs.next() {
|
||||
Some(second) => {
|
||||
|
|
@ -138,10 +141,12 @@ impl Attrs {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn cfgs(&self) -> impl Iterator<Item = CfgExpr> + '_ {
|
||||
self.by_key(&sym::cfg).tt_values().map(CfgExpr::parse)
|
||||
self.by_key(sym::cfg).tt_values().map(CfgExpr::parse)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool {
|
||||
match self.cfg() {
|
||||
None => true,
|
||||
|
|
@ -149,81 +154,92 @@ impl Attrs {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn lang(&self) -> Option<&Symbol> {
|
||||
self.by_key(&sym::lang).string_value()
|
||||
self.by_key(sym::lang).string_value()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn lang_item(&self) -> Option<LangItem> {
|
||||
self.by_key(&sym::lang).string_value().and_then(LangItem::from_symbol)
|
||||
self.by_key(sym::lang).string_value().and_then(LangItem::from_symbol)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_doc_hidden(&self) -> bool {
|
||||
self.by_key(&sym::doc).tt_values().any(|tt| {
|
||||
self.by_key(sym::doc).tt_values().any(|tt| {
|
||||
tt.top_subtree().delimiter.kind == DelimiterKind::Parenthesis &&
|
||||
matches!(tt.token_trees().flat_tokens(), [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::hidden)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_doc_notable_trait(&self) -> bool {
|
||||
self.by_key(&sym::doc).tt_values().any(|tt| {
|
||||
self.by_key(sym::doc).tt_values().any(|tt| {
|
||||
tt.top_subtree().delimiter.kind == DelimiterKind::Parenthesis &&
|
||||
matches!(tt.token_trees().flat_tokens(), [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.sym == sym::notable_trait)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn doc_exprs(&self) -> impl Iterator<Item = DocExpr> + '_ {
|
||||
self.by_key(&sym::doc).tt_values().map(DocExpr::parse)
|
||||
self.by_key(sym::doc).tt_values().map(DocExpr::parse)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn doc_aliases(&self) -> impl Iterator<Item = Symbol> + '_ {
|
||||
self.doc_exprs().flat_map(|doc_expr| doc_expr.aliases().to_vec())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn export_name(&self) -> Option<&Symbol> {
|
||||
self.by_key(&sym::export_name).string_value()
|
||||
self.by_key(sym::export_name).string_value()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_proc_macro(&self) -> bool {
|
||||
self.by_key(&sym::proc_macro).exists()
|
||||
self.by_key(sym::proc_macro).exists()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_proc_macro_attribute(&self) -> bool {
|
||||
self.by_key(&sym::proc_macro_attribute).exists()
|
||||
self.by_key(sym::proc_macro_attribute).exists()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_proc_macro_derive(&self) -> bool {
|
||||
self.by_key(&sym::proc_macro_derive).exists()
|
||||
self.by_key(sym::proc_macro_derive).exists()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_test(&self) -> bool {
|
||||
self.iter().any(|it| {
|
||||
it.path()
|
||||
.segments()
|
||||
.iter()
|
||||
.rev()
|
||||
.zip(
|
||||
[sym::core.clone(), sym::prelude.clone(), sym::v1.clone(), sym::test.clone()]
|
||||
.iter()
|
||||
.rev(),
|
||||
)
|
||||
.zip([sym::core, sym::prelude, sym::v1, sym::test].iter().rev())
|
||||
.all(|it| it.0 == it.1)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_ignore(&self) -> bool {
|
||||
self.by_key(&sym::ignore).exists()
|
||||
self.by_key(sym::ignore).exists()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_bench(&self) -> bool {
|
||||
self.by_key(&sym::bench).exists()
|
||||
self.by_key(sym::bench).exists()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_unstable(&self) -> bool {
|
||||
self.by_key(&sym::unstable).exists()
|
||||
self.by_key(sym::unstable).exists()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rustc_legacy_const_generics(&self) -> Option<Box<Box<[u32]>>> {
|
||||
self.by_key(&sym::rustc_legacy_const_generics)
|
||||
self.by_key(sym::rustc_legacy_const_generics)
|
||||
.tt_values()
|
||||
.next()
|
||||
.map(parse_rustc_legacy_const_generics)
|
||||
|
|
@ -231,8 +247,9 @@ impl Attrs {
|
|||
.map(Box::new)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn repr(&self) -> Option<ReprOptions> {
|
||||
self.by_key(&sym::repr).tt_values().filter_map(parse_repr_tt).fold(None, |acc, repr| {
|
||||
self.by_key(sym::repr).tt_values().filter_map(parse_repr_tt).fold(None, |acc, repr| {
|
||||
acc.map_or(Some(repr), |mut acc| {
|
||||
merge_repr(&mut acc, repr);
|
||||
Some(acc)
|
||||
|
|
@ -681,36 +698,42 @@ impl AttrSourceMap {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AttrQuery<'attr> {
|
||||
attrs: &'attr Attrs,
|
||||
key: &'attr Symbol,
|
||||
key: Symbol,
|
||||
}
|
||||
|
||||
impl<'attr> AttrQuery<'attr> {
|
||||
#[inline]
|
||||
pub fn tt_values(self) -> impl Iterator<Item = &'attr crate::tt::TopSubtree> {
|
||||
self.attrs().filter_map(|attr| attr.token_tree_value())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn string_value(self) -> Option<&'attr Symbol> {
|
||||
self.attrs().find_map(|attr| attr.string_value())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn string_value_with_span(self) -> Option<(&'attr Symbol, span::Span)> {
|
||||
self.attrs().find_map(|attr| attr.string_value_with_span())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn string_value_unescape(self) -> Option<Cow<'attr, str>> {
|
||||
self.attrs().find_map(|attr| attr.string_value_unescape())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn exists(self) -> bool {
|
||||
self.attrs().next().is_some()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn attrs(self) -> impl Iterator<Item = &'attr Attr> + Clone {
|
||||
let key = self.key;
|
||||
self.attrs.iter().filter(move |attr| attr.path.as_ident().is_some_and(|s| *s == *key))
|
||||
self.attrs.iter().filter(move |attr| attr.path.as_ident().is_some_and(|s| *s == key))
|
||||
}
|
||||
|
||||
/// Find string value for a specific key inside token tree
|
||||
|
|
@ -719,10 +742,11 @@ impl<'attr> AttrQuery<'attr> {
|
|||
/// #[doc(html_root_url = "url")]
|
||||
/// ^^^^^^^^^^^^^ key
|
||||
/// ```
|
||||
pub fn find_string_value_in_tt(self, key: &'attr Symbol) -> Option<&'attr str> {
|
||||
#[inline]
|
||||
pub fn find_string_value_in_tt(self, key: Symbol) -> Option<&'attr str> {
|
||||
self.tt_values().find_map(|tt| {
|
||||
let name = tt.iter()
|
||||
.skip_while(|tt| !matches!(tt, TtElement::Leaf(tt::Leaf::Ident(tt::Ident { sym, ..} )) if *sym == *key))
|
||||
.skip_while(|tt| !matches!(tt, TtElement::Leaf(tt::Leaf::Ident(tt::Ident { sym, ..} )) if *sym == key))
|
||||
.nth(2);
|
||||
|
||||
match name {
|
||||
|
|
|
|||
|
|
@ -51,28 +51,28 @@ impl BuiltinType {
|
|||
#[rustfmt::skip]
|
||||
pub fn all_builtin_types() -> [(Name, BuiltinType); 19] {
|
||||
[
|
||||
(Name::new_symbol_root(sym::char.clone()), BuiltinType::Char),
|
||||
(Name::new_symbol_root(sym::bool.clone()), BuiltinType::Bool),
|
||||
(Name::new_symbol_root(sym::str.clone()), BuiltinType::Str),
|
||||
(Name::new_symbol_root(sym::char), BuiltinType::Char),
|
||||
(Name::new_symbol_root(sym::bool), BuiltinType::Bool),
|
||||
(Name::new_symbol_root(sym::str), BuiltinType::Str),
|
||||
|
||||
(Name::new_symbol_root(sym::isize.clone()), BuiltinType::Int(BuiltinInt::Isize)),
|
||||
(Name::new_symbol_root(sym::i8.clone()), BuiltinType::Int(BuiltinInt::I8)),
|
||||
(Name::new_symbol_root(sym::i16.clone()), BuiltinType::Int(BuiltinInt::I16)),
|
||||
(Name::new_symbol_root(sym::i32.clone()), BuiltinType::Int(BuiltinInt::I32)),
|
||||
(Name::new_symbol_root(sym::i64.clone()), BuiltinType::Int(BuiltinInt::I64)),
|
||||
(Name::new_symbol_root(sym::i128.clone()), BuiltinType::Int(BuiltinInt::I128)),
|
||||
(Name::new_symbol_root(sym::isize), BuiltinType::Int(BuiltinInt::Isize)),
|
||||
(Name::new_symbol_root(sym::i8), BuiltinType::Int(BuiltinInt::I8)),
|
||||
(Name::new_symbol_root(sym::i16), BuiltinType::Int(BuiltinInt::I16)),
|
||||
(Name::new_symbol_root(sym::i32), BuiltinType::Int(BuiltinInt::I32)),
|
||||
(Name::new_symbol_root(sym::i64), BuiltinType::Int(BuiltinInt::I64)),
|
||||
(Name::new_symbol_root(sym::i128), BuiltinType::Int(BuiltinInt::I128)),
|
||||
|
||||
(Name::new_symbol_root(sym::usize.clone()), BuiltinType::Uint(BuiltinUint::Usize)),
|
||||
(Name::new_symbol_root(sym::u8.clone()), BuiltinType::Uint(BuiltinUint::U8)),
|
||||
(Name::new_symbol_root(sym::u16.clone()), BuiltinType::Uint(BuiltinUint::U16)),
|
||||
(Name::new_symbol_root(sym::u32.clone()), BuiltinType::Uint(BuiltinUint::U32)),
|
||||
(Name::new_symbol_root(sym::u64.clone()), BuiltinType::Uint(BuiltinUint::U64)),
|
||||
(Name::new_symbol_root(sym::u128.clone()), BuiltinType::Uint(BuiltinUint::U128)),
|
||||
(Name::new_symbol_root(sym::usize), BuiltinType::Uint(BuiltinUint::Usize)),
|
||||
(Name::new_symbol_root(sym::u8), BuiltinType::Uint(BuiltinUint::U8)),
|
||||
(Name::new_symbol_root(sym::u16), BuiltinType::Uint(BuiltinUint::U16)),
|
||||
(Name::new_symbol_root(sym::u32), BuiltinType::Uint(BuiltinUint::U32)),
|
||||
(Name::new_symbol_root(sym::u64), BuiltinType::Uint(BuiltinUint::U64)),
|
||||
(Name::new_symbol_root(sym::u128), BuiltinType::Uint(BuiltinUint::U128)),
|
||||
|
||||
(Name::new_symbol_root(sym::f16.clone()), BuiltinType::Float(BuiltinFloat::F16)),
|
||||
(Name::new_symbol_root(sym::f32.clone()), BuiltinType::Float(BuiltinFloat::F32)),
|
||||
(Name::new_symbol_root(sym::f64.clone()), BuiltinType::Float(BuiltinFloat::F64)),
|
||||
(Name::new_symbol_root(sym::f128.clone()), BuiltinType::Float(BuiltinFloat::F128)),
|
||||
(Name::new_symbol_root(sym::f16), BuiltinType::Float(BuiltinFloat::F16)),
|
||||
(Name::new_symbol_root(sym::f32), BuiltinType::Float(BuiltinFloat::F32)),
|
||||
(Name::new_symbol_root(sym::f64), BuiltinType::Float(BuiltinFloat::F64)),
|
||||
(Name::new_symbol_root(sym::f128), BuiltinType::Float(BuiltinFloat::F128)),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -86,30 +86,30 @@ impl BuiltinType {
|
|||
impl AsName for BuiltinType {
|
||||
fn as_name(&self) -> Name {
|
||||
match self {
|
||||
BuiltinType::Char => Name::new_symbol_root(sym::char.clone()),
|
||||
BuiltinType::Bool => Name::new_symbol_root(sym::bool.clone()),
|
||||
BuiltinType::Str => Name::new_symbol_root(sym::str.clone()),
|
||||
BuiltinType::Char => Name::new_symbol_root(sym::char),
|
||||
BuiltinType::Bool => Name::new_symbol_root(sym::bool),
|
||||
BuiltinType::Str => Name::new_symbol_root(sym::str),
|
||||
BuiltinType::Int(it) => match it {
|
||||
BuiltinInt::Isize => Name::new_symbol_root(sym::isize.clone()),
|
||||
BuiltinInt::I8 => Name::new_symbol_root(sym::i8.clone()),
|
||||
BuiltinInt::I16 => Name::new_symbol_root(sym::i16.clone()),
|
||||
BuiltinInt::I32 => Name::new_symbol_root(sym::i32.clone()),
|
||||
BuiltinInt::I64 => Name::new_symbol_root(sym::i64.clone()),
|
||||
BuiltinInt::I128 => Name::new_symbol_root(sym::i128.clone()),
|
||||
BuiltinInt::Isize => Name::new_symbol_root(sym::isize),
|
||||
BuiltinInt::I8 => Name::new_symbol_root(sym::i8),
|
||||
BuiltinInt::I16 => Name::new_symbol_root(sym::i16),
|
||||
BuiltinInt::I32 => Name::new_symbol_root(sym::i32),
|
||||
BuiltinInt::I64 => Name::new_symbol_root(sym::i64),
|
||||
BuiltinInt::I128 => Name::new_symbol_root(sym::i128),
|
||||
},
|
||||
BuiltinType::Uint(it) => match it {
|
||||
BuiltinUint::Usize => Name::new_symbol_root(sym::usize.clone()),
|
||||
BuiltinUint::U8 => Name::new_symbol_root(sym::u8.clone()),
|
||||
BuiltinUint::U16 => Name::new_symbol_root(sym::u16.clone()),
|
||||
BuiltinUint::U32 => Name::new_symbol_root(sym::u32.clone()),
|
||||
BuiltinUint::U64 => Name::new_symbol_root(sym::u64.clone()),
|
||||
BuiltinUint::U128 => Name::new_symbol_root(sym::u128.clone()),
|
||||
BuiltinUint::Usize => Name::new_symbol_root(sym::usize),
|
||||
BuiltinUint::U8 => Name::new_symbol_root(sym::u8),
|
||||
BuiltinUint::U16 => Name::new_symbol_root(sym::u16),
|
||||
BuiltinUint::U32 => Name::new_symbol_root(sym::u32),
|
||||
BuiltinUint::U64 => Name::new_symbol_root(sym::u64),
|
||||
BuiltinUint::U128 => Name::new_symbol_root(sym::u128),
|
||||
},
|
||||
BuiltinType::Float(it) => match it {
|
||||
BuiltinFloat::F16 => Name::new_symbol_root(sym::f16.clone()),
|
||||
BuiltinFloat::F32 => Name::new_symbol_root(sym::f32.clone()),
|
||||
BuiltinFloat::F64 => Name::new_symbol_root(sym::f64.clone()),
|
||||
BuiltinFloat::F128 => Name::new_symbol_root(sym::f128.clone()),
|
||||
BuiltinFloat::F16 => Name::new_symbol_root(sym::f16),
|
||||
BuiltinFloat::F32 => Name::new_symbol_root(sym::f32),
|
||||
BuiltinFloat::F64 => Name::new_symbol_root(sym::f64),
|
||||
BuiltinFloat::F128 => Name::new_symbol_root(sym::f128),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -387,8 +387,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: Crate) -> bool {
|
|||
let attrs = item_tree.raw_attrs(AttrOwner::TopLevel);
|
||||
for attr in &**attrs {
|
||||
match attr.path().as_ident() {
|
||||
Some(ident) if *ident == sym::no_std.clone() => return true,
|
||||
Some(ident) if *ident == sym::cfg_attr.clone() => {}
|
||||
Some(ident) if *ident == sym::no_std => return true,
|
||||
Some(ident) if *ident == sym::cfg_attr => {}
|
||||
_ => continue,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ pub(super) fn lower_body(
|
|||
let is_mutable =
|
||||
self_param_syn.mut_token().is_some() && self_param_syn.amp_token().is_none();
|
||||
let binding_id: la_arena::Idx<Binding> = collector.alloc_binding(
|
||||
Name::new_symbol_root(sym::self_.clone()),
|
||||
Name::new_symbol_root(sym::self_),
|
||||
BindingAnnotation::new(is_mutable, false),
|
||||
);
|
||||
self_param = Some(binding_id);
|
||||
|
|
@ -137,7 +137,7 @@ pub(super) fn lower_body(
|
|||
let is_mutable =
|
||||
self_param_syn.mut_token().is_some() && self_param_syn.amp_token().is_none();
|
||||
let binding_id: la_arena::Idx<Binding> = collector.alloc_binding(
|
||||
Name::new_symbol_root(sym::self_.clone()),
|
||||
Name::new_symbol_root(sym::self_),
|
||||
BindingAnnotation::new(is_mutable, false),
|
||||
);
|
||||
let hygiene = self_param_syn
|
||||
|
|
@ -322,7 +322,7 @@ pub(crate) fn lower_function(
|
|||
Some(ty) => collector.lower_type_ref(ty, &mut impl_trait_lower_fn),
|
||||
None => {
|
||||
let self_type = collector.alloc_type_ref_desugared(TypeRef::Path(
|
||||
Name::new_symbol_root(sym::Self_.clone()).into(),
|
||||
Name::new_symbol_root(sym::Self_).into(),
|
||||
));
|
||||
let lifetime = param
|
||||
.lifetime()
|
||||
|
|
@ -375,7 +375,7 @@ pub(crate) fn lower_function(
|
|||
let mut generic_args: Vec<_> =
|
||||
std::iter::repeat_n(None, path.segments().len() - 1).collect();
|
||||
let binding = AssociatedTypeBinding {
|
||||
name: Name::new_symbol_root(sym::Output.clone()),
|
||||
name: Name::new_symbol_root(sym::Output),
|
||||
args: None,
|
||||
type_ref: Some(
|
||||
return_type
|
||||
|
|
@ -631,7 +631,7 @@ impl ExprCollector<'_> {
|
|||
match abi.abi_string() {
|
||||
Some(tok) => Symbol::intern(tok.text_without_quotes()),
|
||||
// `extern` default to be `extern "C"`.
|
||||
_ => sym::C.clone(),
|
||||
_ => sym::C,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -760,7 +760,7 @@ impl ExprCollector<'_> {
|
|||
let bindings = if let Some(ret_type) = ret_type {
|
||||
let type_ref = self.lower_type_ref_opt(ret_type.ty(), impl_trait_lower_fn);
|
||||
Box::new([AssociatedTypeBinding {
|
||||
name: Name::new_symbol_root(sym::Output.clone()),
|
||||
name: Name::new_symbol_root(sym::Output),
|
||||
args: None,
|
||||
type_ref: Some(type_ref),
|
||||
bounds: Box::default(),
|
||||
|
|
@ -769,7 +769,7 @@ impl ExprCollector<'_> {
|
|||
// -> ()
|
||||
let type_ref = self.alloc_type_ref_desugared(TypeRef::unit());
|
||||
Box::new([AssociatedTypeBinding {
|
||||
name: Name::new_symbol_root(sym::Output.clone()),
|
||||
name: Name::new_symbol_root(sym::Output),
|
||||
args: None,
|
||||
type_ref: Some(type_ref),
|
||||
bounds: Box::default(),
|
||||
|
|
@ -2804,12 +2804,12 @@ impl ExprCollector<'_> {
|
|||
let new_v1_formatted = LangItem::FormatArguments.ty_rel_path(
|
||||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(sym::new_v1_formatted.clone()),
|
||||
Name::new_symbol_root(sym::new_v1_formatted),
|
||||
);
|
||||
let unsafe_arg_new = LangItem::FormatUnsafeArg.ty_rel_path(
|
||||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(sym::new.clone()),
|
||||
Name::new_symbol_root(sym::new),
|
||||
);
|
||||
let new_v1_formatted =
|
||||
self.alloc_expr_desugared(new_v1_formatted.map_or(Expr::Missing, Expr::Path));
|
||||
|
|
@ -2924,20 +2924,15 @@ impl ExprCollector<'_> {
|
|||
Some(BuiltinUint::U32),
|
||||
)));
|
||||
|
||||
let position = RecordLitField {
|
||||
name: Name::new_symbol_root(sym::position.clone()),
|
||||
expr: position,
|
||||
};
|
||||
let flags =
|
||||
RecordLitField { name: Name::new_symbol_root(sym::flags.clone()), expr: flags };
|
||||
let position =
|
||||
RecordLitField { name: Name::new_symbol_root(sym::position), expr: position };
|
||||
let flags = RecordLitField { name: Name::new_symbol_root(sym::flags), expr: flags };
|
||||
let precision = RecordLitField {
|
||||
name: Name::new_symbol_root(sym::precision.clone()),
|
||||
name: Name::new_symbol_root(sym::precision),
|
||||
expr: precision_expr,
|
||||
};
|
||||
let width = RecordLitField {
|
||||
name: Name::new_symbol_root(sym::width.clone()),
|
||||
expr: width_expr,
|
||||
};
|
||||
let width =
|
||||
RecordLitField { name: Name::new_symbol_root(sym::width), expr: width_expr };
|
||||
self.alloc_expr_desugared(Expr::RecordLit {
|
||||
path: LangItem::FormatPlaceholder.path(self.db, self.module.krate()).map(Box::new),
|
||||
fields: Box::new([position, flags, precision, width]),
|
||||
|
|
@ -2948,7 +2943,7 @@ impl ExprCollector<'_> {
|
|||
let format_placeholder_new = LangItem::FormatPlaceholder.ty_rel_path(
|
||||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(sym::new.clone()),
|
||||
Name::new_symbol_root(sym::new),
|
||||
);
|
||||
match format_placeholder_new {
|
||||
Some(path) => self.alloc_expr_desugared(Expr::Path(path)),
|
||||
|
|
@ -2972,10 +2967,10 @@ impl ExprCollector<'_> {
|
|||
self.db,
|
||||
self.module.krate(),
|
||||
match alignment {
|
||||
Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left.clone()),
|
||||
Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right.clone()),
|
||||
Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center.clone()),
|
||||
None => Name::new_symbol_root(sym::Unknown.clone()),
|
||||
Some(FormatAlignment::Left) => Name::new_symbol_root(sym::Left),
|
||||
Some(FormatAlignment::Right) => Name::new_symbol_root(sym::Right),
|
||||
Some(FormatAlignment::Center) => Name::new_symbol_root(sym::Center),
|
||||
None => Name::new_symbol_root(sym::Unknown),
|
||||
},
|
||||
);
|
||||
match align {
|
||||
|
|
@ -3024,7 +3019,7 @@ impl ExprCollector<'_> {
|
|||
let count_is = match LangItem::FormatCount.ty_rel_path(
|
||||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(sym::Is.clone()),
|
||||
Name::new_symbol_root(sym::Is),
|
||||
) {
|
||||
Some(count_is) => self.alloc_expr_desugared(Expr::Path(count_is)),
|
||||
None => self.missing_expr(),
|
||||
|
|
@ -3042,7 +3037,7 @@ impl ExprCollector<'_> {
|
|||
let count_param = match LangItem::FormatCount.ty_rel_path(
|
||||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(sym::Param.clone()),
|
||||
Name::new_symbol_root(sym::Param),
|
||||
) {
|
||||
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
|
||||
None => self.missing_expr(),
|
||||
|
|
@ -3060,7 +3055,7 @@ impl ExprCollector<'_> {
|
|||
None => match LangItem::FormatCount.ty_rel_path(
|
||||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(sym::Implied.clone()),
|
||||
Name::new_symbol_root(sym::Implied),
|
||||
) {
|
||||
Some(count_param) => self.alloc_expr_desugared(Expr::Path(count_param)),
|
||||
None => self.missing_expr(),
|
||||
|
|
@ -3083,16 +3078,16 @@ impl ExprCollector<'_> {
|
|||
self.db,
|
||||
self.module.krate(),
|
||||
Name::new_symbol_root(match ty {
|
||||
Format(Display) => sym::new_display.clone(),
|
||||
Format(Debug) => sym::new_debug.clone(),
|
||||
Format(LowerExp) => sym::new_lower_exp.clone(),
|
||||
Format(UpperExp) => sym::new_upper_exp.clone(),
|
||||
Format(Octal) => sym::new_octal.clone(),
|
||||
Format(Pointer) => sym::new_pointer.clone(),
|
||||
Format(Binary) => sym::new_binary.clone(),
|
||||
Format(LowerHex) => sym::new_lower_hex.clone(),
|
||||
Format(UpperHex) => sym::new_upper_hex.clone(),
|
||||
Usize => sym::from_usize.clone(),
|
||||
Format(Display) => sym::new_display,
|
||||
Format(Debug) => sym::new_debug,
|
||||
Format(LowerExp) => sym::new_lower_exp,
|
||||
Format(UpperExp) => sym::new_upper_exp,
|
||||
Format(Octal) => sym::new_octal,
|
||||
Format(Pointer) => sym::new_pointer,
|
||||
Format(Binary) => sym::new_binary,
|
||||
Format(LowerHex) => sym::new_lower_hex,
|
||||
Format(UpperHex) => sym::new_upper_hex,
|
||||
Usize => sym::from_usize,
|
||||
}),
|
||||
) {
|
||||
Some(new_fn) => self.alloc_expr_desugared(Expr::Path(new_fn)),
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ impl<'db, 'c> GenericParamsCollector<'db, 'c> {
|
|||
}
|
||||
|
||||
pub(crate) fn fill_self_param(&mut self, bounds: Option<ast::TypeBoundList>) {
|
||||
let self_ = Name::new_symbol_root(sym::Self_.clone());
|
||||
let self_ = Name::new_symbol_root(sym::Self_);
|
||||
let idx = self.type_or_consts.alloc(
|
||||
TypeParamData {
|
||||
name: Some(self_.clone()),
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ pub(super) fn lower_path(
|
|||
push_segment(&segment, &mut segments, name);
|
||||
}
|
||||
ast::PathSegmentKind::SelfTypeKw => {
|
||||
push_segment(&segment, &mut segments, Name::new_symbol_root(sym::Self_.clone()));
|
||||
push_segment(&segment, &mut segments, Name::new_symbol_root(sym::Self_));
|
||||
}
|
||||
ast::PathSegmentKind::Type { type_ref, trait_ref } => {
|
||||
debug_assert!(path.qualifier().is_none()); // this can only occur at the first segment
|
||||
|
|
|
|||
|
|
@ -532,7 +532,7 @@ fn lower_abi(abi: ast::Abi) -> Symbol {
|
|||
match abi.abi_string() {
|
||||
Some(tok) => Symbol::intern(tok.text_without_quotes()),
|
||||
// `extern` default to be `extern "C"`.
|
||||
_ => sym::C.clone(),
|
||||
_ => sym::C,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -268,24 +268,24 @@ impl DefCollector<'_> {
|
|||
let Some(attr_name) = attr.path.as_ident() else { continue };
|
||||
|
||||
match () {
|
||||
() if *attr_name == sym::recursion_limit.clone() => {
|
||||
() if *attr_name == sym::recursion_limit => {
|
||||
if let Some(limit) = attr.string_value() {
|
||||
if let Ok(limit) = limit.as_str().parse() {
|
||||
crate_data.recursion_limit = Some(limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
() if *attr_name == sym::crate_type.clone() => {
|
||||
() if *attr_name == sym::crate_type => {
|
||||
if attr.string_value() == Some(&sym::proc_dash_macro) {
|
||||
self.is_proc_macro = true;
|
||||
}
|
||||
}
|
||||
() if *attr_name == sym::no_core.clone() => crate_data.no_core = true,
|
||||
() if *attr_name == sym::no_std.clone() => crate_data.no_std = true,
|
||||
() if *attr_name == sym::rustc_coherence_is_core.clone() => {
|
||||
() if *attr_name == sym::no_core => crate_data.no_core = true,
|
||||
() if *attr_name == sym::no_std => crate_data.no_std = true,
|
||||
() if *attr_name == sym::rustc_coherence_is_core => {
|
||||
crate_data.rustc_coherence_is_core = true;
|
||||
}
|
||||
() if *attr_name == sym::feature.clone() => {
|
||||
() if *attr_name == sym::feature => {
|
||||
let features =
|
||||
attr.parse_path_comma_token_tree(self.db).into_iter().flatten().filter_map(
|
||||
|(feat, _)| match feat.segments() {
|
||||
|
|
@ -295,13 +295,13 @@ impl DefCollector<'_> {
|
|||
);
|
||||
crate_data.unstable_features.extend(features);
|
||||
}
|
||||
() if *attr_name == sym::register_attr.clone() => {
|
||||
() if *attr_name == sym::register_attr => {
|
||||
if let Some(ident) = attr.single_ident_value() {
|
||||
crate_data.registered_attrs.push(ident.sym.clone());
|
||||
cov_mark::hit!(register_attr);
|
||||
}
|
||||
}
|
||||
() if *attr_name == sym::register_tool.clone() => {
|
||||
() if *attr_name == sym::register_tool => {
|
||||
if let Some(ident) = attr.single_ident_value() {
|
||||
crate_data.registered_tools.push(ident.sym.clone());
|
||||
cov_mark::hit!(register_tool);
|
||||
|
|
@ -507,20 +507,20 @@ impl DefCollector<'_> {
|
|||
}
|
||||
|
||||
let krate = if self.def_map.data.no_std {
|
||||
Name::new_symbol_root(sym::core.clone())
|
||||
} else if self.local_def_map().extern_prelude().any(|(name, _)| *name == sym::std.clone()) {
|
||||
Name::new_symbol_root(sym::std.clone())
|
||||
Name::new_symbol_root(sym::core)
|
||||
} else if self.local_def_map().extern_prelude().any(|(name, _)| *name == sym::std) {
|
||||
Name::new_symbol_root(sym::std)
|
||||
} else {
|
||||
// If `std` does not exist for some reason, fall back to core. This mostly helps
|
||||
// keep r-a's own tests minimal.
|
||||
Name::new_symbol_root(sym::core.clone())
|
||||
Name::new_symbol_root(sym::core)
|
||||
};
|
||||
|
||||
let edition = match self.def_map.data.edition {
|
||||
Edition::Edition2015 => Name::new_symbol_root(sym::rust_2015.clone()),
|
||||
Edition::Edition2018 => Name::new_symbol_root(sym::rust_2018.clone()),
|
||||
Edition::Edition2021 => Name::new_symbol_root(sym::rust_2021.clone()),
|
||||
Edition::Edition2024 => Name::new_symbol_root(sym::rust_2024.clone()),
|
||||
Edition::Edition2015 => Name::new_symbol_root(sym::rust_2015),
|
||||
Edition::Edition2018 => Name::new_symbol_root(sym::rust_2018),
|
||||
Edition::Edition2021 => Name::new_symbol_root(sym::rust_2021),
|
||||
Edition::Edition2024 => Name::new_symbol_root(sym::rust_2024),
|
||||
};
|
||||
|
||||
let path_kind = match self.def_map.data.edition {
|
||||
|
|
@ -529,7 +529,7 @@ impl DefCollector<'_> {
|
|||
};
|
||||
let path = ModPath::from_segments(
|
||||
path_kind,
|
||||
[krate, Name::new_symbol_root(sym::prelude.clone()), edition],
|
||||
[krate, Name::new_symbol_root(sym::prelude), edition],
|
||||
);
|
||||
|
||||
let (per_ns, _) = self.def_map.resolve_path(
|
||||
|
|
@ -1373,8 +1373,7 @@ impl DefCollector<'_> {
|
|||
MacroDefKind::BuiltInAttr(_, expander)
|
||||
if expander.is_test() || expander.is_bench() || expander.is_test_case()
|
||||
) {
|
||||
let test_is_active =
|
||||
self.cfg_options.check_atom(&CfgAtom::Flag(sym::test.clone()));
|
||||
let test_is_active = self.cfg_options.check_atom(&CfgAtom::Flag(sym::test));
|
||||
if test_is_active {
|
||||
return recollect_without(self);
|
||||
}
|
||||
|
|
@ -1712,7 +1711,7 @@ impl ModCollector<'_, '_> {
|
|||
id: ItemTreeId::new(self.tree_id, item_tree_id),
|
||||
}
|
||||
.intern(db);
|
||||
let is_prelude = attrs.by_key(&sym::prelude_import).exists();
|
||||
let is_prelude = attrs.by_key(sym::prelude_import).exists();
|
||||
Import::from_use(
|
||||
self.item_tree,
|
||||
ItemTreeId::new(self.tree_id, item_tree_id),
|
||||
|
|
@ -1770,7 +1769,7 @@ impl ModCollector<'_, '_> {
|
|||
if !is_self {
|
||||
self.process_macro_use_extern_crate(
|
||||
id,
|
||||
attrs.by_key(&sym::macro_use).attrs(),
|
||||
attrs.by_key(sym::macro_use).attrs(),
|
||||
resolved.krate,
|
||||
);
|
||||
}
|
||||
|
|
@ -2015,8 +2014,8 @@ impl ModCollector<'_, '_> {
|
|||
}
|
||||
|
||||
fn collect_module(&mut self, module_id: FileItemTreeId<Mod>, attrs: &Attrs) {
|
||||
let path_attr = attrs.by_key(&sym::path).string_value_unescape();
|
||||
let is_macro_use = attrs.by_key(&sym::macro_use).exists();
|
||||
let path_attr = attrs.by_key(sym::path).string_value_unescape();
|
||||
let is_macro_use = attrs.by_key(sym::macro_use).exists();
|
||||
let module = &self.item_tree[module_id];
|
||||
match &module.kind {
|
||||
// inline module, just recurse
|
||||
|
|
@ -2093,7 +2092,7 @@ impl ModCollector<'_, '_> {
|
|||
let is_macro_use = is_macro_use
|
||||
|| item_tree
|
||||
.top_level_attrs(db, krate)
|
||||
.by_key(&sym::macro_use)
|
||||
.by_key(sym::macro_use)
|
||||
.exists();
|
||||
if is_macro_use {
|
||||
self.import_all_legacy_macros(module_id);
|
||||
|
|
@ -2252,11 +2251,11 @@ impl ModCollector<'_, '_> {
|
|||
let attrs = self.item_tree.attrs(self.def_collector.db, krate, ModItem::from(id).into());
|
||||
let ast_id = InFile::new(self.file_id(), mac.ast_id.upcast());
|
||||
|
||||
let export_attr = attrs.by_key(&sym::macro_export);
|
||||
let export_attr = || attrs.by_key(sym::macro_export);
|
||||
|
||||
let is_export = export_attr.exists();
|
||||
let is_export = export_attr().exists();
|
||||
let local_inner = if is_export {
|
||||
export_attr.tt_values().flat_map(|it| it.iter()).any(|it| match it {
|
||||
export_attr().tt_values().flat_map(|it| it.iter()).any(|it| match it {
|
||||
tt::TtElement::Leaf(tt::Leaf::Ident(ident)) => ident.sym == sym::local_inner_macros,
|
||||
_ => false,
|
||||
})
|
||||
|
|
@ -2265,17 +2264,17 @@ impl ModCollector<'_, '_> {
|
|||
};
|
||||
|
||||
// Case 1: builtin macros
|
||||
let expander = if attrs.by_key(&sym::rustc_builtin_macro).exists() {
|
||||
let expander = if attrs.by_key(sym::rustc_builtin_macro).exists() {
|
||||
// `#[rustc_builtin_macro = "builtin_name"]` overrides the `macro_rules!` name.
|
||||
let name;
|
||||
let name = match attrs.by_key(&sym::rustc_builtin_macro).string_value_with_span() {
|
||||
let name = match attrs.by_key(sym::rustc_builtin_macro).string_value_with_span() {
|
||||
Some((it, span)) => {
|
||||
name = Name::new_symbol(it.clone(), span.ctx);
|
||||
&name
|
||||
}
|
||||
None => {
|
||||
let explicit_name =
|
||||
attrs.by_key(&sym::rustc_builtin_macro).tt_values().next().and_then(|tt| {
|
||||
attrs.by_key(sym::rustc_builtin_macro).tt_values().next().and_then(|tt| {
|
||||
match tt.token_trees().flat_tokens().first() {
|
||||
Some(tt::TokenTree::Leaf(tt::Leaf::Ident(name))) => Some(name),
|
||||
_ => None,
|
||||
|
|
@ -2305,7 +2304,7 @@ impl ModCollector<'_, '_> {
|
|||
// Case 2: normal `macro_rules!` macro
|
||||
MacroExpander::Declarative
|
||||
};
|
||||
let allow_internal_unsafe = attrs.by_key(&sym::allow_internal_unsafe).exists();
|
||||
let allow_internal_unsafe = attrs.by_key(sym::allow_internal_unsafe).exists();
|
||||
|
||||
let mut flags = MacroRulesLocFlags::empty();
|
||||
flags.set(MacroRulesLocFlags::LOCAL_INNER, local_inner);
|
||||
|
|
@ -2339,14 +2338,14 @@ impl ModCollector<'_, '_> {
|
|||
// Case 1: builtin macros
|
||||
let mut helpers_opt = None;
|
||||
let attrs = self.item_tree.attrs(self.def_collector.db, krate, ModItem::from(id).into());
|
||||
let expander = if attrs.by_key(&sym::rustc_builtin_macro).exists() {
|
||||
let expander = if attrs.by_key(sym::rustc_builtin_macro).exists() {
|
||||
if let Some(expander) = find_builtin_macro(&mac.name) {
|
||||
match expander {
|
||||
Either::Left(it) => MacroExpander::BuiltIn(it),
|
||||
Either::Right(it) => MacroExpander::BuiltInEager(it),
|
||||
}
|
||||
} else if let Some(expander) = find_builtin_derive(&mac.name) {
|
||||
if let Some(attr) = attrs.by_key(&sym::rustc_builtin_macro).tt_values().next() {
|
||||
if let Some(attr) = attrs.by_key(sym::rustc_builtin_macro).tt_values().next() {
|
||||
// NOTE: The item *may* have both `#[rustc_builtin_macro]` and `#[proc_macro_derive]`,
|
||||
// in which case rustc ignores the helper attributes from the latter, but it
|
||||
// "doesn't make sense in practice" (see rust-lang/rust#87027).
|
||||
|
|
@ -2377,7 +2376,7 @@ impl ModCollector<'_, '_> {
|
|||
// Case 2: normal `macro`
|
||||
MacroExpander::Declarative
|
||||
};
|
||||
let allow_internal_unsafe = attrs.by_key(&sym::allow_internal_unsafe).exists();
|
||||
let allow_internal_unsafe = attrs.by_key(sym::allow_internal_unsafe).exists();
|
||||
|
||||
let macro_id = Macro2Loc {
|
||||
container: module,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl Attrs {
|
|||
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::Bang })
|
||||
} else if self.is_proc_macro_attribute() {
|
||||
Some(ProcMacroDef { name: func_name.clone(), kind: ProcMacroKind::Attr })
|
||||
} else if self.by_key(&sym::proc_macro_derive).exists() {
|
||||
} else if self.by_key(sym::proc_macro_derive).exists() {
|
||||
let derive = self.parse_proc_macro_derive();
|
||||
Some(match derive {
|
||||
Some((name, helpers)) => {
|
||||
|
|
@ -52,12 +52,12 @@ impl Attrs {
|
|||
}
|
||||
|
||||
pub fn parse_proc_macro_derive(&self) -> Option<(Name, Box<[Name]>)> {
|
||||
let derive = self.by_key(&sym::proc_macro_derive).tt_values().next()?;
|
||||
let derive = self.by_key(sym::proc_macro_derive).tt_values().next()?;
|
||||
parse_macro_name_and_helper_attrs(derive)
|
||||
}
|
||||
|
||||
pub fn parse_rustc_builtin_macro(&self) -> Option<(Name, Box<[Name]>)> {
|
||||
let derive = self.by_key(&sym::rustc_builtin_macro).tt_values().next()?;
|
||||
let derive = self.by_key(sym::rustc_builtin_macro).tt_values().next()?;
|
||||
parse_macro_name_and_helper_attrs(derive)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ impl Resolver {
|
|||
Scope::ExprScope(_) | Scope::MacroDefScope(_) => continue,
|
||||
Scope::GenericParams { params, def } => {
|
||||
if let &GenericDefId::ImplId(impl_) = def {
|
||||
if *first_name == sym::Self_.clone() {
|
||||
if *first_name == sym::Self_ {
|
||||
return Some((
|
||||
TypeNs::SelfType(impl_),
|
||||
remaining_idx(),
|
||||
|
|
@ -228,7 +228,7 @@ impl Resolver {
|
|||
));
|
||||
}
|
||||
} else if let &GenericDefId::AdtId(adt) = def {
|
||||
if *first_name == sym::Self_.clone() {
|
||||
if *first_name == sym::Self_ {
|
||||
return Some((
|
||||
TypeNs::AdtSelfType(adt),
|
||||
remaining_idx(),
|
||||
|
|
@ -365,7 +365,7 @@ impl Resolver {
|
|||
}
|
||||
};
|
||||
let n_segments = path.segments().len();
|
||||
let tmp = Name::new_symbol_root(sym::self_.clone());
|
||||
let tmp = Name::new_symbol_root(sym::self_);
|
||||
let first_name = if path.is_self() { &tmp } else { path.segments().first()? };
|
||||
let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
|
||||
if skip_to_mod {
|
||||
|
|
@ -397,7 +397,7 @@ impl Resolver {
|
|||
}
|
||||
Scope::GenericParams { params, def } => {
|
||||
if let &GenericDefId::ImplId(impl_) = def {
|
||||
if *first_name == sym::Self_.clone() {
|
||||
if *first_name == sym::Self_ {
|
||||
return Some((
|
||||
ResolveValueResult::ValueNs(ValueNs::ImplSelf(impl_), None),
|
||||
ResolvePathResultPrefixInfo::default(),
|
||||
|
|
@ -425,14 +425,14 @@ impl Resolver {
|
|||
Scope::ExprScope(_) | Scope::MacroDefScope(_) => continue,
|
||||
Scope::GenericParams { params, def } => {
|
||||
if let &GenericDefId::ImplId(impl_) = def {
|
||||
if *first_name == sym::Self_.clone() {
|
||||
if *first_name == sym::Self_ {
|
||||
return Some((
|
||||
ResolveValueResult::Partial(TypeNs::SelfType(impl_), 1, None),
|
||||
ResolvePathResultPrefixInfo::default(),
|
||||
));
|
||||
}
|
||||
} else if let &GenericDefId::AdtId(adt) = def {
|
||||
if *first_name == sym::Self_.clone() {
|
||||
if *first_name == sym::Self_ {
|
||||
let ty = TypeNs::AdtSelfType(adt);
|
||||
return Some((
|
||||
ResolveValueResult::Partial(ty, 1, None),
|
||||
|
|
@ -1004,12 +1004,9 @@ impl Scope {
|
|||
}
|
||||
&Scope::GenericParams { ref params, def: parent } => {
|
||||
if let GenericDefId::ImplId(impl_) = parent {
|
||||
acc.add(
|
||||
&Name::new_symbol_root(sym::Self_.clone()),
|
||||
ScopeDef::ImplSelfType(impl_),
|
||||
);
|
||||
acc.add(&Name::new_symbol_root(sym::Self_), ScopeDef::ImplSelfType(impl_));
|
||||
} else if let GenericDefId::AdtId(adt) = parent {
|
||||
acc.add(&Name::new_symbol_root(sym::Self_.clone()), ScopeDef::AdtSelfType(adt));
|
||||
acc.add(&Name::new_symbol_root(sym::Self_), ScopeDef::AdtSelfType(adt));
|
||||
}
|
||||
|
||||
for (local_id, param) in params.iter_type_or_consts() {
|
||||
|
|
|
|||
|
|
@ -74,10 +74,10 @@ impl StructSignature {
|
|||
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
|
||||
|
||||
let mut flags = StructFlags::empty();
|
||||
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
if attrs.by_key(sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
flags |= StructFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
|
||||
}
|
||||
if attrs.by_key(&sym::fundamental).exists() {
|
||||
if attrs.by_key(sym::fundamental).exists() {
|
||||
flags |= StructFlags::FUNDAMENTAL;
|
||||
}
|
||||
if let Some(lang) = attrs.lang_item() {
|
||||
|
|
@ -131,10 +131,10 @@ impl UnionSignature {
|
|||
let item_tree = loc.id.item_tree(db);
|
||||
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
|
||||
let mut flags = StructFlags::empty();
|
||||
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
if attrs.by_key(sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
flags |= StructFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
|
||||
}
|
||||
if attrs.by_key(&sym::fundamental).exists() {
|
||||
if attrs.by_key(sym::fundamental).exists() {
|
||||
flags |= StructFlags::FUNDAMENTAL;
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ impl EnumSignature {
|
|||
let item_tree = loc.id.item_tree(db);
|
||||
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
|
||||
let mut flags = EnumFlags::empty();
|
||||
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
if attrs.by_key(sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
flags |= EnumFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ impl ConstSignature {
|
|||
let module = loc.container.module(db);
|
||||
let attrs = item_tree.attrs(db, module.krate, ModItem::from(loc.id.value).into());
|
||||
let mut flags = ConstFlags::empty();
|
||||
if attrs.by_key(&sym::rustc_allow_incoherent_impl).exists() {
|
||||
if attrs.by_key(sym::rustc_allow_incoherent_impl).exists() {
|
||||
flags |= ConstFlags::RUSTC_ALLOW_INCOHERENT_IMPL;
|
||||
}
|
||||
let source = loc.source(db);
|
||||
|
|
@ -300,7 +300,7 @@ impl StaticSignature {
|
|||
let module = loc.container.module(db);
|
||||
let attrs = item_tree.attrs(db, module.krate, ModItem::from(loc.id.value).into());
|
||||
let mut flags = StaticFlags::empty();
|
||||
if attrs.by_key(&sym::rustc_allow_incoherent_impl).exists() {
|
||||
if attrs.by_key(sym::rustc_allow_incoherent_impl).exists() {
|
||||
flags |= StaticFlags::RUSTC_ALLOW_INCOHERENT_IMPL;
|
||||
}
|
||||
|
||||
|
|
@ -418,19 +418,19 @@ impl TraitSignature {
|
|||
if source.value.unsafe_token().is_some() {
|
||||
flags.insert(TraitFlags::UNSAFE);
|
||||
}
|
||||
if attrs.by_key(&sym::fundamental).exists() {
|
||||
if attrs.by_key(sym::fundamental).exists() {
|
||||
flags |= TraitFlags::FUNDAMENTAL;
|
||||
}
|
||||
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
if attrs.by_key(sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
flags |= TraitFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPLS;
|
||||
}
|
||||
if attrs.by_key(&sym::rustc_paren_sugar).exists() {
|
||||
if attrs.by_key(sym::rustc_paren_sugar).exists() {
|
||||
flags |= TraitFlags::RUSTC_PAREN_SUGAR;
|
||||
}
|
||||
let mut skip_array_during_method_dispatch =
|
||||
attrs.by_key(&sym::rustc_skip_array_during_method_dispatch).exists();
|
||||
attrs.by_key(sym::rustc_skip_array_during_method_dispatch).exists();
|
||||
let mut skip_boxed_slice_during_method_dispatch = false;
|
||||
for tt in attrs.by_key(&sym::rustc_skip_during_method_dispatch).tt_values() {
|
||||
for tt in attrs.by_key(sym::rustc_skip_during_method_dispatch).tt_values() {
|
||||
for tt in tt.iter() {
|
||||
if let tt::iter::TtElement::Leaf(tt::Leaf::Ident(ident)) = tt {
|
||||
skip_array_during_method_dispatch |= ident.sym == sym::array;
|
||||
|
|
@ -534,11 +534,11 @@ impl FunctionSignature {
|
|||
|
||||
let mut flags = FnFlags::empty();
|
||||
let attrs = item_tree.attrs(db, module.krate, ModItem::from(loc.id.value).into());
|
||||
if attrs.by_key(&sym::rustc_allow_incoherent_impl).exists() {
|
||||
if attrs.by_key(sym::rustc_allow_incoherent_impl).exists() {
|
||||
flags.insert(FnFlags::RUSTC_ALLOW_INCOHERENT_IMPL);
|
||||
}
|
||||
|
||||
if attrs.by_key(&sym::target_feature).exists() {
|
||||
if attrs.by_key(sym::target_feature).exists() {
|
||||
flags.insert(FnFlags::HAS_TARGET_FEATURE);
|
||||
}
|
||||
let legacy_const_generics_indices = attrs.rustc_legacy_const_generics();
|
||||
|
|
@ -546,7 +546,7 @@ impl FunctionSignature {
|
|||
let source = loc.source(db);
|
||||
|
||||
if source.value.unsafe_token().is_some() {
|
||||
if attrs.by_key(&sym::rustc_deprecated_safe_2024).exists() {
|
||||
if attrs.by_key(sym::rustc_deprecated_safe_2024).exists() {
|
||||
flags.insert(FnFlags::DEPRECATED_SAFE_2024);
|
||||
} else {
|
||||
flags.insert(FnFlags::UNSAFE);
|
||||
|
|
@ -569,8 +569,7 @@ impl FunctionSignature {
|
|||
}
|
||||
|
||||
let abi = source.value.abi().map(|abi| {
|
||||
abi.abi_string()
|
||||
.map_or_else(|| sym::C.clone(), |it| Symbol::intern(it.text_without_quotes()))
|
||||
abi.abi_string().map_or_else(|| sym::C, |it| Symbol::intern(it.text_without_quotes()))
|
||||
});
|
||||
let (store, source_map, generic_params, params, ret_type, self_param, variadic) =
|
||||
lower_function(db, module, source, id);
|
||||
|
|
@ -671,10 +670,10 @@ impl TypeAliasSignature {
|
|||
loc.container.module(db).krate(),
|
||||
ModItem::from(loc.id.value).into(),
|
||||
);
|
||||
if attrs.by_key(&sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
if attrs.by_key(sym::rustc_has_incoherent_inherent_impls).exists() {
|
||||
flags.insert(TypeAliasFlags::RUSTC_HAS_INCOHERENT_INHERENT_IMPL);
|
||||
}
|
||||
if attrs.by_key(&sym::rustc_allow_incoherent_impl).exists() {
|
||||
if attrs.by_key(sym::rustc_allow_incoherent_impl).exists() {
|
||||
flags.insert(TypeAliasFlags::RUSTC_ALLOW_INCOHERENT_IMPL);
|
||||
}
|
||||
if matches!(loc.container, ItemContainerId::ExternBlockId(_)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue