Skip to content

Commit 40aa900

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 c18e075 commit 40aa900

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

compiler/rustc_attr/src/builtin.rs

+13-36
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
}
@@ -391,15 +383,9 @@ pub fn find_const_stability(
391383
sym::rustc_promotable => promotable = true,
392384
sym::rustc_const_stable_indirect => const_stable_indirect = Some(attr.span),
393385
sym::rustc_const_unstable => {
394-
if try_add_unstability(sess, attr, &mut level, &mut stab_spans).is_err() {
395-
break;
396-
}
397-
}
398-
sym::rustc_const_stable => {
399-
if try_add_stability(sess, attr, &mut level, &mut stab_spans).is_err() {
400-
break;
401-
}
386+
try_add_unstability(sess, attr, &mut level, &mut stab_spans)
402387
}
388+
sym::rustc_const_stable => try_add_stability(sess, attr, &mut level, &mut stab_spans),
403389
_ => {}
404390
}
405391
}
@@ -458,9 +444,7 @@ pub fn find_body_stability(
458444

459445
for attr in attrs {
460446
if attr.has_name(sym::rustc_default_body_unstable) {
461-
if try_add_unstability(sess, attr, &mut level, &mut stab_spans).is_err() {
462-
break;
463-
}
447+
try_add_unstability(sess, attr, &mut level, &mut stab_spans);
464448
}
465449
}
466450

@@ -474,15 +458,13 @@ fn try_add_unstability(
474458
attr: &Attribute,
475459
level: &mut Option<StabilityLevel>,
476460
stab_spans: &mut StabilitySpans,
477-
) -> Result<(), ErrorGuaranteed> {
461+
) {
478462
use StabilityLevel::*;
479463

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

519500
/// Collects stability info from a single `stable`/`rustc_const_stable` attribute, `attr`.
@@ -523,18 +504,14 @@ fn try_add_stability(
523504
attr: &Attribute,
524505
level: &mut Option<StabilityLevel>,
525506
stab_spans: &mut StabilitySpans,
526-
) -> Result<(), ErrorGuaranteed> {
507+
) {
527508
// at most one #[stable] attribute is permitted, and not when #[unstable] is present
528509
if level.is_some() {
529-
return Err(sess
530-
.dcx()
531-
.emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span }));
532-
}
533-
if let Some(new_level) = parse_stability(sess, attr) {
510+
sess.dcx().emit_err(session_diagnostics::MultipleStabilityLevels { span: attr.span });
511+
} else if let Some(new_level) = parse_stability(sess, attr) {
534512
*level = Some(new_level.clone());
535513
stab_spans.0.push((new_level, attr.span));
536514
}
537-
Ok(())
538515
}
539516

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

0 commit comments

Comments
 (0)