Skip to content

Commit 8c7c0fa

Browse files
committed
find_stability: don't give up when emitting "multiple stability levels" errors
this makes things a little cleaner. since multiple stability levels are allowed, I think it makes sense too.
1 parent 7317353 commit 8c7c0fa

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

compiler/rustc_attr/src/builtin.rs

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -341,16 +341,8 @@ pub fn find_stability(
341341
for attr in attrs {
342342
match attr.name_or_empty() {
343343
sym::rustc_allowed_through_unstable_modules => allowed_through_unstable_modules = true,
344-
sym::unstable => {
345-
if try_add_unstability(sess, attr, &mut level, &mut stab_spans).is_err() {
346-
break;
347-
}
348-
}
349-
sym::stable => {
350-
if try_add_stability(sess, attr, &mut level, &mut stab_spans).is_err() {
351-
break;
352-
}
353-
}
344+
sym::unstable => try_add_unstability(sess, attr, &mut level, &mut stab_spans),
345+
sym::stable => try_add_stability(sess, attr, &mut level, &mut stab_spans),
354346
_ => {}
355347
}
356348
}
@@ -390,15 +382,9 @@ pub fn find_const_stability(
390382
sym::rustc_promotable => promotable = true,
391383
sym::rustc_const_stable_indirect => const_stable_indirect = Some(attr.span),
392384
sym::rustc_const_unstable => {
393-
if try_add_unstability(sess, attr, &mut level, &mut stab_spans).is_err() {
394-
break;
395-
}
396-
}
397-
sym::rustc_const_stable => {
398-
if try_add_stability(sess, attr, &mut level, &mut stab_spans).is_err() {
399-
break;
400-
}
385+
try_add_unstability(sess, attr, &mut level, &mut stab_spans)
401386
}
387+
sym::rustc_const_stable => try_add_stability(sess, attr, &mut level, &mut stab_spans),
402388
_ => {}
403389
}
404390
}
@@ -457,9 +443,7 @@ pub fn find_body_stability(
457443

458444
for attr in attrs {
459445
if attr.has_name(sym::rustc_default_body_unstable) {
460-
if try_add_unstability(sess, attr, &mut level, &mut stab_spans).is_err() {
461-
break;
462-
}
446+
try_add_unstability(sess, attr, &mut level, &mut stab_spans);
463447
}
464448
}
465449

@@ -473,15 +457,13 @@ fn try_add_unstability(
473457
attr: &Attribute,
474458
level: &mut Option<StabilityLevel>,
475459
stab_spans: &mut StabilitySpans,
476-
) -> Result<(), ErrorGuaranteed> {
460+
) {
477461
use StabilityLevel::*;
478462

479463
match level {
480464
// adding #[unstable] to an item with #[stable] is not permitted
481465
Some(Stable { .. }) => {
482-
return Err(sess
483-
.dcx()
484-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span }));
466+
sess.dcx().emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
485467
}
486468
// if other unstable attributes have been found, attempt to merge them
487469
Some(Unstable { unstables, is_soft })
@@ -493,9 +475,9 @@ fn try_add_unstability(
493475
// stability levels" clear enough, given an update to E0544.md?
494476
// should MultipleStabilityLevels have more fields for diagnostics?
495477
if unstables.iter().any(|u| new_unstable.iter().any(|v| u.feature == v.feature)) {
496-
return Err(sess
497-
.dcx()
498-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span }));
478+
sess.dcx()
479+
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
480+
return;
499481
}
500482
unstables.extend(new_unstable.clone());
501483
// Make the unstability soft if any unstable attributes are marked 'soft'; if an
@@ -512,7 +494,6 @@ fn try_add_unstability(
512494
// if there was an error in `parse_unstability`, it's already been emitted; do nothing
513495
_ => {}
514496
}
515-
Ok(())
516497
}
517498

518499
/// Collects stability info from a single `stable`/`rustc_const_stable` attribute, `attr`.
@@ -522,18 +503,14 @@ fn try_add_stability(
522503
attr: &Attribute,
523504
level: &mut Option<StabilityLevel>,
524505
stab_spans: &mut StabilitySpans,
525-
) -> Result<(), ErrorGuaranteed> {
506+
) {
526507
// at most one #[stable] attribute is permitted, and not when #[unstable] is present
527508
if level.is_some() {
528-
return Err(sess
529-
.dcx()
530-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span }));
531-
}
532-
if let Some(new_level) = parse_stability(sess, attr) {
509+
sess.dcx().emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
510+
} else if let Some(new_level) = parse_stability(sess, attr) {
533511
*level = Some(new_level.clone());
534512
stab_spans.0.push((new_level, attr.span));
535513
}
536-
Ok(())
537514
}
538515

539516
fn insert_or_error(sess: &Session, meta: &MetaItem, item: &mut Option<Symbol>) -> Option<()> {

0 commit comments

Comments
 (0)