Skip to content

Commit f6690a1

Browse files
Add new AttributeExt::opt_style method
1 parent 553600e commit f6690a1

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

compiler/rustc_ast/src/attr/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ impl AttributeExt for Attribute {
206206
}
207207
}
208208

209-
fn style(&self) -> AttrStyle {
210-
self.style
209+
fn opt_style(&self) -> Option<AttrStyle> {
210+
Some(self.style)
211211
}
212212
}
213213

@@ -806,7 +806,11 @@ pub trait AttributeExt: Debug {
806806
/// * `#[doc(...)]` returns `None`.
807807
fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;
808808

809-
fn style(&self) -> AttrStyle;
809+
fn style(&self) -> AttrStyle {
810+
self.opt_style().unwrap()
811+
}
812+
813+
fn opt_style(&self) -> Option<AttrStyle>;
810814
}
811815

812816
// FIXME(fn_delegation): use function delegation instead of manually forwarding

compiler/rustc_hir/src/hir.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1245,11 +1245,11 @@ impl AttributeExt for Attribute {
12451245
}
12461246

12471247
#[inline]
1248-
fn style(&self) -> AttrStyle {
1248+
fn opt_style(&self) -> Option<AttrStyle> {
12491249
match &self {
1250-
Attribute::Unparsed(u) => u.style,
1251-
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => *style,
1252-
_ => panic!(),
1250+
Attribute::Unparsed(u) => Some(u.style),
1251+
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
1252+
_ => None,
12531253
}
12541254
}
12551255
}
@@ -1345,6 +1345,11 @@ impl Attribute {
13451345
pub fn style(&self) -> AttrStyle {
13461346
AttributeExt::style(self)
13471347
}
1348+
1349+
#[inline]
1350+
pub fn opt_style(&self) -> Option<AttrStyle> {
1351+
AttributeExt::opt_style(self)
1352+
}
13481353
}
13491354

13501355
/// Attributes owned by a HIR owner.

0 commit comments

Comments
 (0)