Use the right span for errors about #[deprecated] attributes.
This commit is contained in:
parent
0e2337a5d6
commit
706bc33651
7 changed files with 53 additions and 35 deletions
|
@ -637,19 +637,15 @@ pub struct Deprecation {
|
|||
}
|
||||
|
||||
/// Finds the deprecation attribute. `None` if none exists.
|
||||
pub fn find_deprecation(sess: &Session, attrs: &[Attribute], item_sp: Span) -> Option<Deprecation> {
|
||||
find_deprecation_generic(sess, attrs.iter(), item_sp)
|
||||
pub fn find_deprecation(sess: &Session, attrs: &[Attribute]) -> Option<(Deprecation, Span)> {
|
||||
find_deprecation_generic(sess, attrs.iter())
|
||||
}
|
||||
|
||||
fn find_deprecation_generic<'a, I>(
|
||||
sess: &Session,
|
||||
attrs_iter: I,
|
||||
item_sp: Span,
|
||||
) -> Option<Deprecation>
|
||||
fn find_deprecation_generic<'a, I>(sess: &Session, attrs_iter: I) -> Option<(Deprecation, Span)>
|
||||
where
|
||||
I: Iterator<Item = &'a Attribute>,
|
||||
{
|
||||
let mut depr: Option<Deprecation> = None;
|
||||
let mut depr: Option<(Deprecation, Span)> = None;
|
||||
let diagnostic = &sess.parse_sess.span_diagnostic;
|
||||
|
||||
'outer: for attr in attrs_iter {
|
||||
|
@ -658,8 +654,10 @@ where
|
|||
continue;
|
||||
}
|
||||
|
||||
if depr.is_some() {
|
||||
struct_span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes").emit();
|
||||
if let Some((_, span)) = &depr {
|
||||
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes")
|
||||
.span_note(*span, "first deprecation attribute here")
|
||||
.emit();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -780,7 +778,7 @@ where
|
|||
sess.mark_attr_used(&attr);
|
||||
|
||||
let is_since_rustc_version = sess.check_name(attr, sym::rustc_deprecated);
|
||||
depr = Some(Deprecation { since, note, suggestion, is_since_rustc_version });
|
||||
depr = Some((Deprecation { since, note, suggestion, is_since_rustc_version }, attr.span));
|
||||
}
|
||||
|
||||
depr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue