Rollup merge of #128226 - oli-obk:option_vs_empty_slice, r=petrochenkov

Remove redundant option that was just encoding that a slice was empty

There is already a sanity check ensuring we don't put empty attribute lists into the HIR:

6ef11b81c2/compiler/rustc_ast_lowering/src/lib.rs (L661-L667)
This commit is contained in:
Trevor Gross 2024-07-26 19:03:07 -04:00 committed by GitHub
commit f1cf2f526a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -172,7 +172,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: NodeId, id: NodeId,
hir_id: hir::HirId, hir_id: hir::HirId,
ident: &mut Ident, ident: &mut Ident,
attrs: Option<&'hir [Attribute]>, attrs: &'hir [Attribute],
vis_span: Span, vis_span: Span,
i: &ItemKind, i: &ItemKind,
) -> hir::ItemKind<'hir> { ) -> hir::ItemKind<'hir> {
@ -488,7 +488,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
id: NodeId, id: NodeId,
vis_span: Span, vis_span: Span,
ident: &mut Ident, ident: &mut Ident,
attrs: Option<&'hir [Attribute]>, attrs: &'hir [Attribute],
) -> hir::ItemKind<'hir> { ) -> hir::ItemKind<'hir> {
let path = &tree.prefix; let path = &tree.prefix;
let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect(); let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect();
@ -566,7 +566,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `ItemLocalId` and the new owner. (See `lower_node_id`) // `ItemLocalId` and the new owner. (See `lower_node_id`)
let kind = let kind =
this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs); this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs);
if let Some(attrs) = attrs { if !attrs.is_empty() {
this.attrs.insert(hir::ItemLocalId::ZERO, attrs); this.attrs.insert(hir::ItemLocalId::ZERO, attrs);
} }

View File

@ -913,15 +913,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ret ret
} }
fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> { fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> &'hir [Attribute] {
if attrs.is_empty() { if attrs.is_empty() {
None &[]
} else { } else {
debug_assert_eq!(id.owner, self.current_hir_id_owner); debug_assert_eq!(id.owner, self.current_hir_id_owner);
let ret = self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a))); let ret = self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a)));
debug_assert!(!ret.is_empty()); debug_assert!(!ret.is_empty());
self.attrs.insert(id.local_id, ret); self.attrs.insert(id.local_id, ret);
Some(ret) ret
} }
} }