Migrate limit error
This commit is contained in:
parent
00cd965046
commit
b37e645d80
3 changed files with 16 additions and 6 deletions
|
@ -11,3 +11,7 @@ middle_conflict_types =
|
||||||
|
|
||||||
middle_previous_use_here =
|
middle_previous_use_here =
|
||||||
previous use here
|
previous use here
|
||||||
|
|
||||||
|
middle_limit_invalid =
|
||||||
|
`limit` must be a non-negative integer
|
||||||
|
.label = {$error_str}
|
||||||
|
|
|
@ -38,3 +38,13 @@ pub enum TypeMismatchReason {
|
||||||
span: Span,
|
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,
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
//! just peeks and looks for that attribute.
|
//! just peeks and looks for that attribute.
|
||||||
|
|
||||||
use crate::bug;
|
use crate::bug;
|
||||||
|
use crate::error::LimitInvalid;
|
||||||
use crate::ty;
|
use crate::ty;
|
||||||
use rustc_ast::Attribute;
|
use rustc_ast::Attribute;
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
|
@ -56,9 +57,6 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u
|
||||||
match s.as_str().parse() {
|
match s.as_str().parse() {
|
||||||
Ok(n) => return Limit::new(n),
|
Ok(n) => return Limit::new(n),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let mut err =
|
|
||||||
sess.struct_span_err(attr.span, "`limit` must be a non-negative integer");
|
|
||||||
|
|
||||||
let value_span = attr
|
let value_span = attr
|
||||||
.meta()
|
.meta()
|
||||||
.and_then(|meta| meta.name_value_literal_span())
|
.and_then(|meta| meta.name_value_literal_span())
|
||||||
|
@ -74,9 +72,7 @@ fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: u
|
||||||
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
|
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
|
||||||
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
|
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
|
||||||
};
|
};
|
||||||
|
sess.emit_err(LimitInvalid { span: attr.span, value_span, error_str });
|
||||||
err.span_label(value_span, error_str);
|
|
||||||
err.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue