]> git.proxmox.com Git - rustc.git/blob - src/libsyntax/attr/builtin.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / src / libsyntax / attr / builtin.rs
1 //! Parsing and validation of builtin attributes
2
3 use ast::{self, Attribute, MetaItem, Name, NestedMetaItemKind};
4 use errors::{Applicability, Handler};
5 use feature_gate::{Features, GatedCfg};
6 use parse::ParseSess;
7 use syntax_pos::{symbol::Symbol, Span};
8
9 use super::{list_contains_name, mark_used, MetaItemKind};
10
11 enum AttrError {
12 MultipleItem(Name),
13 UnknownMetaItem(Name, &'static [&'static str]),
14 MissingSince,
15 MissingFeature,
16 MultipleStabilityLevels,
17 UnsupportedLiteral(&'static str, /* is_bytestr */ bool),
18 }
19
20 fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
21 let diag = &sess.span_diagnostic;
22 match error {
23 AttrError::MultipleItem(item) => span_err!(diag, span, E0538,
24 "multiple '{}' items", item),
25 AttrError::UnknownMetaItem(item, expected) => {
26 let expected = expected
27 .iter()
28 .map(|name| format!("`{}`", name))
29 .collect::<Vec<_>>();
30 struct_span_err!(diag, span, E0541, "unknown meta item '{}'", item)
31 .span_label(span, format!("expected one of {}", expected.join(", ")))
32 .emit();
33 }
34 AttrError::MissingSince => span_err!(diag, span, E0542, "missing 'since'"),
35 AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"),
36 AttrError::MultipleStabilityLevels => span_err!(diag, span, E0544,
37 "multiple stability levels"),
38 AttrError::UnsupportedLiteral(
39 msg,
40 is_bytestr,
41 ) => {
42 let mut err = struct_span_err!(diag, span, E0565, "{}", msg);
43 if is_bytestr {
44 if let Ok(lint_str) = sess.source_map().span_to_snippet(span) {
45 err.span_suggestion_with_applicability(
46 span,
47 "consider removing the prefix",
48 format!("{}", &lint_str[1..]),
49 Applicability::MaybeIncorrect,
50 );
51 }
52 }
53 err.emit();
54 }
55 }
56 }
57
58 #[derive(Copy, Clone, Hash, PartialEq, RustcEncodable, RustcDecodable)]
59 pub enum InlineAttr {
60 None,
61 Hint,
62 Always,
63 Never,
64 }
65
66 #[derive(Copy, Clone, PartialEq)]
67 pub enum UnwindAttr {
68 Allowed,
69 Aborts,
70 }
71
72 /// Determine what `#[unwind]` attribute is present in `attrs`, if any.
73 pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Option<UnwindAttr> {
74 let syntax_error = |attr: &Attribute| {
75 mark_used(attr);
76 diagnostic.map(|d| {
77 span_err!(d, attr.span, E0633, "malformed `#[unwind]` attribute");
78 });
79 None
80 };
81
82 attrs.iter().fold(None, |ia, attr| {
83 if attr.path != "unwind" {
84 return ia;
85 }
86 let meta = match attr.meta() {
87 Some(meta) => meta.node,
88 None => return ia,
89 };
90 match meta {
91 MetaItemKind::Word => {
92 syntax_error(attr)
93 }
94 MetaItemKind::List(ref items) => {
95 mark_used(attr);
96 if items.len() != 1 {
97 syntax_error(attr)
98 } else if list_contains_name(&items[..], "allowed") {
99 Some(UnwindAttr::Allowed)
100 } else if list_contains_name(&items[..], "aborts") {
101 Some(UnwindAttr::Aborts)
102 } else {
103 syntax_error(attr)
104 }
105 }
106 _ => ia,
107 }
108 })
109 }
110
111 /// Represents the #[stable], #[unstable], #[rustc_{deprecated,const_unstable}] attributes.
112 #[derive(RustcEncodable, RustcDecodable, Clone, Debug, PartialEq, Eq, Hash)]
113 pub struct Stability {
114 pub level: StabilityLevel,
115 pub feature: Symbol,
116 pub rustc_depr: Option<RustcDeprecation>,
117 /// `None` means the function is stable but needs to be a stable const fn, too
118 /// `Some` contains the feature gate required to be able to use the function
119 /// as const fn
120 pub const_stability: Option<Symbol>,
121 /// whether the function has a `#[rustc_promotable]` attribute
122 pub promotable: bool,
123 }
124
125 /// The available stability levels.
126 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
127 pub enum StabilityLevel {
128 // Reason for the current stability level and the relevant rust-lang issue
129 Unstable { reason: Option<Symbol>, issue: u32 },
130 Stable { since: Symbol },
131 }
132
133 impl StabilityLevel {
134 pub fn is_unstable(&self) -> bool {
135 if let StabilityLevel::Unstable {..} = *self {
136 true
137 } else {
138 false
139 }
140 }
141 pub fn is_stable(&self) -> bool {
142 if let StabilityLevel::Stable {..} = *self {
143 true
144 } else {
145 false
146 }
147 }
148 }
149
150 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
151 pub struct RustcDeprecation {
152 pub since: Symbol,
153 pub reason: Symbol,
154 }
155
156 /// Check if `attrs` contains an attribute like `#![feature(feature_name)]`.
157 /// This will not perform any "sanity checks" on the form of the attributes.
158 pub fn contains_feature_attr(attrs: &[Attribute], feature_name: &str) -> bool {
159 attrs.iter().any(|item| {
160 item.check_name("feature") &&
161 item.meta_item_list().map(|list| {
162 list.iter().any(|mi| {
163 mi.word().map(|w| w.name() == feature_name)
164 .unwrap_or(false)
165 })
166 }).unwrap_or(false)
167 })
168 }
169
170 /// Find the first stability attribute. `None` if none exists.
171 pub fn find_stability(sess: &ParseSess, attrs: &[Attribute],
172 item_sp: Span) -> Option<Stability> {
173 find_stability_generic(sess, attrs.iter(), item_sp)
174 }
175
176 fn find_stability_generic<'a, I>(sess: &ParseSess,
177 attrs_iter: I,
178 item_sp: Span)
179 -> Option<Stability>
180 where I: Iterator<Item = &'a Attribute>
181 {
182 use self::StabilityLevel::*;
183
184 let mut stab: Option<Stability> = None;
185 let mut rustc_depr: Option<RustcDeprecation> = None;
186 let mut rustc_const_unstable: Option<Symbol> = None;
187 let mut promotable = false;
188 let diagnostic = &sess.span_diagnostic;
189
190 'outer: for attr in attrs_iter {
191 if ![
192 "rustc_deprecated",
193 "rustc_const_unstable",
194 "unstable",
195 "stable",
196 "rustc_promotable",
197 ].iter().any(|&s| attr.path == s) {
198 continue // not a stability level
199 }
200
201 mark_used(attr);
202
203 let meta = attr.meta();
204
205 if attr.path == "rustc_promotable" {
206 promotable = true;
207 }
208 // attributes with data
209 else if let Some(MetaItem { node: MetaItemKind::List(ref metas), .. }) = meta {
210 let meta = meta.as_ref().unwrap();
211 let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
212 if item.is_some() {
213 handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name()));
214 return false
215 }
216 if let Some(v) = meta.value_str() {
217 *item = Some(v);
218 true
219 } else {
220 span_err!(diagnostic, meta.span, E0539, "incorrect meta item");
221 false
222 }
223 };
224
225 macro_rules! get_meta {
226 ($($name:ident),+) => {
227 $(
228 let mut $name = None;
229 )+
230 for meta in metas {
231 if let Some(mi) = meta.meta_item() {
232 match &*mi.name().as_str() {
233 $(
234 stringify!($name)
235 => if !get(mi, &mut $name) { continue 'outer },
236 )+
237 _ => {
238 let expected = &[ $( stringify!($name) ),+ ];
239 handle_errors(
240 sess,
241 mi.span,
242 AttrError::UnknownMetaItem(mi.name(), expected),
243 );
244 continue 'outer
245 }
246 }
247 } else {
248 handle_errors(
249 sess,
250 meta.span,
251 AttrError::UnsupportedLiteral(
252 "unsupported literal",
253 false,
254 ),
255 );
256 continue 'outer
257 }
258 }
259 }
260 }
261
262 match &*meta.name().as_str() {
263 "rustc_deprecated" => {
264 if rustc_depr.is_some() {
265 span_err!(diagnostic, item_sp, E0540,
266 "multiple rustc_deprecated attributes");
267 continue 'outer
268 }
269
270 get_meta!(since, reason);
271
272 match (since, reason) {
273 (Some(since), Some(reason)) => {
274 rustc_depr = Some(RustcDeprecation {
275 since,
276 reason,
277 })
278 }
279 (None, _) => {
280 handle_errors(sess, attr.span(), AttrError::MissingSince);
281 continue
282 }
283 _ => {
284 span_err!(diagnostic, attr.span(), E0543, "missing 'reason'");
285 continue
286 }
287 }
288 }
289 "rustc_const_unstable" => {
290 if rustc_const_unstable.is_some() {
291 span_err!(diagnostic, item_sp, E0553,
292 "multiple rustc_const_unstable attributes");
293 continue 'outer
294 }
295
296 get_meta!(feature);
297 if let Some(feature) = feature {
298 rustc_const_unstable = Some(feature);
299 } else {
300 span_err!(diagnostic, attr.span(), E0629, "missing 'feature'");
301 continue
302 }
303 }
304 "unstable" => {
305 if stab.is_some() {
306 handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels);
307 break
308 }
309
310 let mut feature = None;
311 let mut reason = None;
312 let mut issue = None;
313 for meta in metas {
314 if let Some(mi) = meta.meta_item() {
315 match &*mi.name().as_str() {
316 "feature" => if !get(mi, &mut feature) { continue 'outer },
317 "reason" => if !get(mi, &mut reason) { continue 'outer },
318 "issue" => if !get(mi, &mut issue) { continue 'outer },
319 _ => {
320 handle_errors(
321 sess,
322 meta.span,
323 AttrError::UnknownMetaItem(
324 mi.name(),
325 &["feature", "reason", "issue"]
326 ),
327 );
328 continue 'outer
329 }
330 }
331 } else {
332 handle_errors(
333 sess,
334 meta.span,
335 AttrError::UnsupportedLiteral(
336 "unsupported literal",
337 false,
338 ),
339 );
340 continue 'outer
341 }
342 }
343
344 match (feature, reason, issue) {
345 (Some(feature), reason, Some(issue)) => {
346 stab = Some(Stability {
347 level: Unstable {
348 reason,
349 issue: {
350 if let Ok(issue) = issue.as_str().parse() {
351 issue
352 } else {
353 span_err!(diagnostic, attr.span(), E0545,
354 "incorrect 'issue'");
355 continue
356 }
357 }
358 },
359 feature,
360 rustc_depr: None,
361 const_stability: None,
362 promotable: false,
363 })
364 }
365 (None, _, _) => {
366 handle_errors(sess, attr.span(), AttrError::MissingFeature);
367 continue
368 }
369 _ => {
370 span_err!(diagnostic, attr.span(), E0547, "missing 'issue'");
371 continue
372 }
373 }
374 }
375 "stable" => {
376 if stab.is_some() {
377 handle_errors(sess, attr.span(), AttrError::MultipleStabilityLevels);
378 break
379 }
380
381 let mut feature = None;
382 let mut since = None;
383 for meta in metas {
384 match &meta.node {
385 NestedMetaItemKind::MetaItem(mi) => {
386 match &*mi.name().as_str() {
387 "feature" => if !get(mi, &mut feature) { continue 'outer },
388 "since" => if !get(mi, &mut since) { continue 'outer },
389 _ => {
390 handle_errors(
391 sess,
392 meta.span,
393 AttrError::UnknownMetaItem(
394 mi.name(), &["since", "note"],
395 ),
396 );
397 continue 'outer
398 }
399 }
400 },
401 NestedMetaItemKind::Literal(lit) => {
402 handle_errors(
403 sess,
404 lit.span,
405 AttrError::UnsupportedLiteral(
406 "unsupported literal",
407 false,
408 ),
409 );
410 continue 'outer
411 }
412 }
413 }
414
415 match (feature, since) {
416 (Some(feature), Some(since)) => {
417 stab = Some(Stability {
418 level: Stable {
419 since,
420 },
421 feature,
422 rustc_depr: None,
423 const_stability: None,
424 promotable: false,
425 })
426 }
427 (None, _) => {
428 handle_errors(sess, attr.span(), AttrError::MissingFeature);
429 continue
430 }
431 _ => {
432 handle_errors(sess, attr.span(), AttrError::MissingSince);
433 continue
434 }
435 }
436 }
437 _ => unreachable!()
438 }
439 } else {
440 span_err!(diagnostic, attr.span(), E0548, "incorrect stability attribute type");
441 continue
442 }
443 }
444
445 // Merge the deprecation info into the stability info
446 if let Some(rustc_depr) = rustc_depr {
447 if let Some(ref mut stab) = stab {
448 stab.rustc_depr = Some(rustc_depr);
449 } else {
450 span_err!(diagnostic, item_sp, E0549,
451 "rustc_deprecated attribute must be paired with \
452 either stable or unstable attribute");
453 }
454 }
455
456 // Merge the const-unstable info into the stability info
457 if let Some(feature) = rustc_const_unstable {
458 if let Some(ref mut stab) = stab {
459 stab.const_stability = Some(feature);
460 } else {
461 span_err!(diagnostic, item_sp, E0630,
462 "rustc_const_unstable attribute must be paired with \
463 either stable or unstable attribute");
464 }
465 }
466
467 // Merge the const-unstable info into the stability info
468 if promotable {
469 if let Some(ref mut stab) = stab {
470 stab.promotable = true;
471 } else {
472 span_err!(diagnostic, item_sp, E0717,
473 "rustc_promotable attribute must be paired with \
474 either stable or unstable attribute");
475 }
476 }
477
478 stab
479 }
480
481 pub fn find_crate_name(attrs: &[Attribute]) -> Option<Symbol> {
482 super::first_attr_value_str_by_name(attrs, "crate_name")
483 }
484
485 /// Tests if a cfg-pattern matches the cfg set
486 pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) -> bool {
487 eval_condition(cfg, sess, &mut |cfg| {
488 if let (Some(feats), Some(gated_cfg)) = (features, GatedCfg::gate(cfg)) {
489 gated_cfg.check_and_emit(sess, feats);
490 }
491 let error = |span, msg| { sess.span_diagnostic.span_err(span, msg); true };
492 if cfg.ident.segments.len() != 1 {
493 return error(cfg.ident.span, "`cfg` predicate key must be an identifier");
494 }
495 match &cfg.node {
496 MetaItemKind::List(..) => {
497 error(cfg.span, "unexpected parentheses after `cfg` predicate key")
498 }
499 MetaItemKind::NameValue(lit) if !lit.node.is_str() => {
500 handle_errors(
501 sess,
502 lit.span,
503 AttrError::UnsupportedLiteral(
504 "literal in `cfg` predicate value must be a string",
505 lit.node.is_bytestr()
506 ),
507 );
508 true
509 }
510 MetaItemKind::NameValue(..) | MetaItemKind::Word => {
511 sess.config.contains(&(cfg.name(), cfg.value_str()))
512 }
513 }
514 })
515 }
516
517 /// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
518 /// evaluate individual items.
519 pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
520 -> bool
521 where F: FnMut(&ast::MetaItem) -> bool
522 {
523 match cfg.node {
524 ast::MetaItemKind::List(ref mis) => {
525 for mi in mis.iter() {
526 if !mi.is_meta_item() {
527 handle_errors(
528 sess,
529 mi.span,
530 AttrError::UnsupportedLiteral(
531 "unsupported literal",
532 false
533 ),
534 );
535 return false;
536 }
537 }
538
539 // The unwraps below may look dangerous, but we've already asserted
540 // that they won't fail with the loop above.
541 match &*cfg.name().as_str() {
542 "any" => mis.iter().any(|mi| {
543 eval_condition(mi.meta_item().unwrap(), sess, eval)
544 }),
545 "all" => mis.iter().all(|mi| {
546 eval_condition(mi.meta_item().unwrap(), sess, eval)
547 }),
548 "not" => {
549 if mis.len() != 1 {
550 span_err!(sess.span_diagnostic, cfg.span, E0536, "expected 1 cfg-pattern");
551 return false;
552 }
553
554 !eval_condition(mis[0].meta_item().unwrap(), sess, eval)
555 },
556 p => {
557 span_err!(sess.span_diagnostic, cfg.span, E0537, "invalid predicate `{}`", p);
558 false
559 }
560 }
561 },
562 ast::MetaItemKind::Word | ast::MetaItemKind::NameValue(..) => {
563 eval(cfg)
564 }
565 }
566 }
567
568
569 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Clone, Debug, Eq, Hash)]
570 pub struct Deprecation {
571 pub since: Option<Symbol>,
572 pub note: Option<Symbol>,
573 }
574
575 /// Find the deprecation attribute. `None` if none exists.
576 pub fn find_deprecation(sess: &ParseSess, attrs: &[Attribute],
577 item_sp: Span) -> Option<Deprecation> {
578 find_deprecation_generic(sess, attrs.iter(), item_sp)
579 }
580
581 fn find_deprecation_generic<'a, I>(sess: &ParseSess,
582 attrs_iter: I,
583 item_sp: Span)
584 -> Option<Deprecation>
585 where I: Iterator<Item = &'a Attribute>
586 {
587 let mut depr: Option<Deprecation> = None;
588 let diagnostic = &sess.span_diagnostic;
589
590 'outer: for attr in attrs_iter {
591 if attr.path != "deprecated" {
592 continue
593 }
594
595 mark_used(attr);
596
597 if depr.is_some() {
598 span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes");
599 break
600 }
601
602 depr = if let Some(metas) = attr.meta_item_list() {
603 let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
604 if item.is_some() {
605 handle_errors(sess, meta.span, AttrError::MultipleItem(meta.name()));
606 return false
607 }
608 if let Some(v) = meta.value_str() {
609 *item = Some(v);
610 true
611 } else {
612 if let Some(lit) = meta.name_value_literal() {
613 handle_errors(
614 sess,
615 lit.span,
616 AttrError::UnsupportedLiteral(
617 "literal in `deprecated` \
618 value must be a string",
619 lit.node.is_bytestr()
620 ),
621 );
622 } else {
623 span_err!(diagnostic, meta.span, E0551, "incorrect meta item");
624 }
625
626 false
627 }
628 };
629
630 let mut since = None;
631 let mut note = None;
632 for meta in metas {
633 match &meta.node {
634 NestedMetaItemKind::MetaItem(mi) => {
635 match &*mi.name().as_str() {
636 "since" => if !get(mi, &mut since) { continue 'outer },
637 "note" => if !get(mi, &mut note) { continue 'outer },
638 _ => {
639 handle_errors(
640 sess,
641 meta.span,
642 AttrError::UnknownMetaItem(mi.name(), &["since", "note"]),
643 );
644 continue 'outer
645 }
646 }
647 }
648 NestedMetaItemKind::Literal(lit) => {
649 handle_errors(
650 sess,
651 lit.span,
652 AttrError::UnsupportedLiteral(
653 "item in `deprecated` must be a key/value pair",
654 false,
655 ),
656 );
657 continue 'outer
658 }
659 }
660 }
661
662 Some(Deprecation {since: since, note: note})
663 } else {
664 Some(Deprecation{since: None, note: None})
665 }
666 }
667
668 depr
669 }
670
671 #[derive(PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
672 pub enum ReprAttr {
673 ReprInt(IntType),
674 ReprC,
675 ReprPacked(u32),
676 ReprSimd,
677 ReprTransparent,
678 ReprAlign(u32),
679 }
680
681 #[derive(Eq, Hash, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
682 pub enum IntType {
683 SignedInt(ast::IntTy),
684 UnsignedInt(ast::UintTy)
685 }
686
687 impl IntType {
688 #[inline]
689 pub fn is_signed(self) -> bool {
690 use self::IntType::*;
691
692 match self {
693 SignedInt(..) => true,
694 UnsignedInt(..) => false
695 }
696 }
697 }
698
699 /// Parse #[repr(...)] forms.
700 ///
701 /// Valid repr contents: any of the primitive integral type names (see
702 /// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
703 /// the same discriminant size that the corresponding C enum would or C
704 /// structure layout, `packed` to remove padding, and `transparent` to elegate representation
705 /// concerns to the only non-ZST field.
706 pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
707 use self::ReprAttr::*;
708
709 let mut acc = Vec::new();
710 let diagnostic = &sess.span_diagnostic;
711 if attr.path == "repr" {
712 if let Some(items) = attr.meta_item_list() {
713 mark_used(attr);
714 for item in items {
715 if !item.is_meta_item() {
716 handle_errors(
717 sess,
718 item.span,
719 AttrError::UnsupportedLiteral(
720 "meta item in `repr` must be an identifier",
721 false,
722 ),
723 );
724 continue
725 }
726
727 let mut recognised = false;
728 if let Some(mi) = item.word() {
729 let word = &*mi.name().as_str();
730 let hint = match word {
731 "C" => Some(ReprC),
732 "packed" => Some(ReprPacked(1)),
733 "simd" => Some(ReprSimd),
734 "transparent" => Some(ReprTransparent),
735 _ => match int_type_of_word(word) {
736 Some(ity) => Some(ReprInt(ity)),
737 None => {
738 None
739 }
740 }
741 };
742
743 if let Some(h) = hint {
744 recognised = true;
745 acc.push(h);
746 }
747 } else if let Some((name, value)) = item.name_value_literal() {
748 let parse_alignment = |node: &ast::LitKind| -> Result<u32, &'static str> {
749 if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
750 if literal.is_power_of_two() {
751 // rustc::ty::layout::Align restricts align to <= 2^29
752 if *literal <= 1 << 29 {
753 Ok(*literal as u32)
754 } else {
755 Err("larger than 2^29")
756 }
757 } else {
758 Err("not a power of two")
759 }
760 } else {
761 Err("not an unsuffixed integer")
762 }
763 };
764
765 let mut literal_error = None;
766 if name == "align" {
767 recognised = true;
768 match parse_alignment(&value.node) {
769 Ok(literal) => acc.push(ReprAlign(literal)),
770 Err(message) => literal_error = Some(message)
771 };
772 }
773 else if name == "packed" {
774 recognised = true;
775 match parse_alignment(&value.node) {
776 Ok(literal) => acc.push(ReprPacked(literal)),
777 Err(message) => literal_error = Some(message)
778 };
779 }
780 if let Some(literal_error) = literal_error {
781 span_err!(diagnostic, item.span, E0589,
782 "invalid `repr(align)` attribute: {}", literal_error);
783 }
784 } else {
785 if let Some(meta_item) = item.meta_item() {
786 if meta_item.name() == "align" {
787 if let MetaItemKind::NameValue(ref value) = meta_item.node {
788 recognised = true;
789 let mut err = struct_span_err!(diagnostic, item.span, E0693,
790 "incorrect `repr(align)` attribute format");
791 match value.node {
792 ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
793 err.span_suggestion_with_applicability(
794 item.span,
795 "use parentheses instead",
796 format!("align({})", int),
797 Applicability::MachineApplicable
798 );
799 }
800 ast::LitKind::Str(s, _) => {
801 err.span_suggestion_with_applicability(
802 item.span,
803 "use parentheses instead",
804 format!("align({})", s),
805 Applicability::MachineApplicable
806 );
807 }
808 _ => {}
809 }
810 err.emit();
811 }
812 }
813 }
814 }
815 if !recognised {
816 // Not a word we recognize
817 span_err!(diagnostic, item.span, E0552,
818 "unrecognized representation hint");
819 }
820 }
821 }
822 }
823 acc
824 }
825
826 fn int_type_of_word(s: &str) -> Option<IntType> {
827 use self::IntType::*;
828
829 match s {
830 "i8" => Some(SignedInt(ast::IntTy::I8)),
831 "u8" => Some(UnsignedInt(ast::UintTy::U8)),
832 "i16" => Some(SignedInt(ast::IntTy::I16)),
833 "u16" => Some(UnsignedInt(ast::UintTy::U16)),
834 "i32" => Some(SignedInt(ast::IntTy::I32)),
835 "u32" => Some(UnsignedInt(ast::UintTy::U32)),
836 "i64" => Some(SignedInt(ast::IntTy::I64)),
837 "u64" => Some(UnsignedInt(ast::UintTy::U64)),
838 "i128" => Some(SignedInt(ast::IntTy::I128)),
839 "u128" => Some(UnsignedInt(ast::UintTy::U128)),
840 "isize" => Some(SignedInt(ast::IntTy::Isize)),
841 "usize" => Some(UnsignedInt(ast::UintTy::Usize)),
842 _ => None
843 }
844 }