Improve spans of malformed attribute errors · rust-lang/rust@ae39d3d (original) (raw)

File tree

34 files changed

lines changed

34 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ pub fn parse_cfg<S: Stage>(
42 42 args: &ArgParser,
43 43 ) -> Option<CfgEntry> {
44 44 let ArgParser::List(list) = args else {
45 - cx.expected_list(cx.attr_span);
45 + cx.expected_list(cx.attr_span, args);
46 46 return None;
47 47 };
48 48 let Some(single) = list.single() else {
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ impl<S: Stage> SingleAttributeParser for OptimizeParser {
25 25
26 26 fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
27 27 let Some(list) = args.list() else {
28 - cx.expected_list(cx.attr_span);
28 + cx.expected_list(cx.attr_span, args);
29 29 return None;
30 30 };
31 31
@@ -478,7 +478,7 @@ fn parse_tf_attribute<S: Stage>(
478 478 ) -> impl IntoIterator<Item = (Symbol, Span)> {
479 479 let mut features = Vec::new();
480 480 let ArgParser::List(list) = args else {
481 - cx.expected_list(cx.attr_span);
481 + cx.expected_list(cx.attr_span, args);
482 482 return features;
483 483 };
484 484 if list.is_empty() {
@@ -601,7 +601,7 @@ impl<S: Stage> SingleAttributeParser for SanitizeParser {
601 601
602 602 fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
603 603 let Some(list) = args.list() else {
604 - cx.expected_list(cx.attr_span);
604 + cx.expected_list(cx.attr_span, args);
605 605 return None;
606 606 };
607 607
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ impl<S: Stage> AttributeParser for ConfusablesParser {
13 13 template!(List: &[r#""name1", "name2", ..."#]),
14 14 |this, cx, args
15 15 let Some(list) = args.list() else {
16 - cx.expected_list(cx.attr_span);
16 + cx.expected_list(cx.attr_span, args);
17 17 return;
18 18 };
19 19
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ impl<S: Stage> CombineAttributeParser for DebuggerViualizerParser {
21 21 args: &ArgParser,
22 22 ) -> impl IntoIterator<Item = Self::Item> {
23 23 let Some(l) = args.list() else {
24 - cx.expected_list(args.span().unwrap_or(cx.attr_span));
24 + cx.expected_list(cx.attr_span, args);
25 25 return None;
26 26 };
27 27 let Some(single) = l.single() else {
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ impl DocParser {
106 106 }
107 107 Some(sym::attr) => {
108 108 let Some(list) = args.list() else {
109 - cx.expected_list(cx.attr_span);
109 + cx.expected_list(cx.attr_span, args);
110 110 return;
111 111 };
112 112
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ impl<S: Stage> CombineAttributeParser for LinkParser {
76 76 return None;
77 77 }
78 78 _ => {
79 - cx.expected_list(cx.attr_span);
79 + cx.expected_list(cx.attr_span, args);
80 80 return None;
81 81 }
82 82 };
@@ -379,7 +379,7 @@ impl LinkParser {
379 379 return true;
380 380 }
381 381 let Some(link_cfg) = item.args().list() else {
382 - cx.expected_list(item.span());
382 + cx.expected_list(item.span(), item.args());
383 383 return true;
384 384 };
385 385 let Some(link_cfg) = link_cfg.single() else {
Original file line number Diff line number Diff line change
@@ -99,8 +99,8 @@ impl<S: Stage> AttributeParser for MacroUseParser {
99 99 }
100 100 }
101 101 }
102 -ArgParser::NameValue(_) => {
103 - cx.expected_list_or_no_args(span);
102 +ArgParser::NameValue(nv) => {
103 + cx.expected_list_or_no_args(nv.args_span());
104 104 }
105 105 }
106 106 },
@@ -155,8 +155,8 @@ impl<S: Stage> SingleAttributeParser for MacroExportParser {
155 155 }
156 156 }
157 157 }
158 -ArgParser::NameValue(_) => {
159 - cx.expected_list_or_no_args(cx.attr_span);
158 +ArgParser::NameValue(nv) => {
159 + cx.expected_list_or_no_args(nv.args_span());
160 160 return None;
161 161 }
162 162 };
Original file line number Diff line number Diff line change
@@ -41,8 +41,8 @@ impl<S: Stage> SingleAttributeParser for MustUseParser {
41 41 };
42 42 Some(value_str)
43 43 }
44 -ArgParser::List(_) => {
45 - cx.expected_name_value(cx.attr_span, None);
44 +ArgParser::List(list) => {
45 + cx.expected_nv_or_no_args(list.span);
46 46 return None;
47 47 }
48 48 },
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ fn parse_derive_like<S: Stage>(
65 65 if args.no_args().is_ok() && !trait_name_mandatory {
66 66 return Some((None, ThinVec::new()));
67 67 }
68 - cx.expected_list(cx.attr_span);
68 + cx.expected_list(cx.attr_span, args);
69 69 return None;
70 70 };
71 71 let mut items = list.mixed();
@@ -96,15 +96,15 @@ fn parse_derive_like<S: Stage>(
96 96 let mut attributes = ThinVec::new();
97 97 if let Some(attrs) = items.next() {
98 98 let Some(attr_list) = attrs.meta_item() else {
99 - cx.expected_list(attrs.span());
99 + cx.unexpected_literal(attrs.span());
100 100 return None;
101 101 };
102 102 if !attr_list.path().word_is(sym::attributes) {
103 103 cx.expected_specific_argument(attrs.span(), &[sym::attributes]);
104 104 return None;
105 105 }
106 106 let Some(attr_list) = attr_list.args().list() else {
107 - cx.expected_list(attrs.span());
107 + cx.expected_list(attrs.span(), attr_list.args());
108 108 return None;
109 109 };
110 110
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ impl<S: Stage> SingleAttributeParser for CustomMirParser {
27 27
28 28 fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
29 29 let Some(list) = args.list() else {
30 - cx.expected_list(cx.attr_span);
30 + cx.expected_list(cx.attr_span, args);
31 31 return None;
32 32 };
33 33