Skip to content

Commit

Permalink
Migrate limit error
Browse files Browse the repository at this point in the history
  • Loading branch information
MingyuChen1 committed Sep 1, 2022
1 parent 00cd965 commit b37e645
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/middle.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ middle_conflict_types =
middle_previous_use_here =
previous use here
middle_limit_invalid =
`limit` must be a non-negative integer
.label = {$error_str}
10 changes: 10 additions & 0 deletions compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ pub enum TypeMismatchReason {
span: Span,
},
}

#[derive(SessionDiagnostic)]
#[diag(middle::limit_invalid)]
pub struct LimitInvalid<'a> {
#[primary_span]
pub span: Span,
#[label]
pub value_span: Span,
pub error_str: &'a str,
}
8 changes: 2 additions & 6 deletions compiler/rustc_middle/src/middle/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! just peeks and looks for that attribute.

use crate::bug;
use crate::error::LimitInvalid;
use crate::ty;
use rustc_ast::Attribute;
use rustc_session::Session;
Expand Down Expand Up @@ -56,9 +57,6 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u
match s.as_str().parse() {
Ok(n) => return Limit::new(n),
Err(e) => {
let mut err =
sess.struct_span_err(attr.span, "`limit` must be a non-negative integer");

let value_span = attr
.meta()
.and_then(|meta| meta.name_value_literal_span())
Expand All @@ -74,9 +72,7 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
};

err.span_label(value_span, error_str);
err.emit();
sess.emit_err(LimitInvalid { span: attr.span, value_span, error_str });
}
}
}
Expand Down

0 comments on commit b37e645

Please sign in to comment.