parent
e8cd6cc237
commit
4f840a683a
13 changed files with 149 additions and 137 deletions
|
|
@ -41,6 +41,8 @@ use util::nodemap::FxHashMap;
|
|||
use rustc_const_math::ConstInt;
|
||||
|
||||
use syntax::{abi, ast};
|
||||
use syntax::ast::MetaItemKind;
|
||||
use syntax::attr::{InlineAttr, list_contains_name, mark_used};
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::symbol::{Symbol, keywords};
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
|
@ -1742,6 +1744,39 @@ fn trans_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> TransFnAt
|
|||
} else if attr.check_name("naked") {
|
||||
trans_fn_attrs.flags |= TransFnAttrFlags::NAKED;
|
||||
} else if attr.check_name("inline") {
|
||||
trans_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
|
||||
if attr.path != "inline" {
|
||||
return ia;
|
||||
}
|
||||
let meta = match attr.meta() {
|
||||
Some(meta) => meta.node,
|
||||
None => return ia,
|
||||
};
|
||||
match meta {
|
||||
MetaItemKind::Word => {
|
||||
mark_used(attr);
|
||||
InlineAttr::Hint
|
||||
}
|
||||
MetaItemKind::List(ref items) => {
|
||||
mark_used(attr);
|
||||
if items.len() != 1 {
|
||||
span_err!(tcx.sess.diagnostic(), attr.span, E0534,
|
||||
"expected one argument");
|
||||
InlineAttr::None
|
||||
} else if list_contains_name(&items[..], "always") {
|
||||
InlineAttr::Always
|
||||
} else if list_contains_name(&items[..], "never") {
|
||||
InlineAttr::Never
|
||||
} else {
|
||||
span_err!(tcx.sess.diagnostic(), items[0].span, E0535,
|
||||
"invalid argument");
|
||||
|
||||
InlineAttr::None
|
||||
}
|
||||
}
|
||||
_ => ia,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3705,6 +3705,75 @@ match r {
|
|||
```
|
||||
"##,
|
||||
|
||||
E0534: r##"
|
||||
The `inline` attribute was malformed.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```ignore (compile_fail not working here; see Issue #43707)
|
||||
#[inline()] // error: expected one argument
|
||||
pub fn something() {}
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
The parenthesized `inline` attribute requires the parameter to be specified:
|
||||
|
||||
```
|
||||
#[inline(always)]
|
||||
fn something() {}
|
||||
```
|
||||
|
||||
or:
|
||||
|
||||
```
|
||||
#[inline(never)]
|
||||
fn something() {}
|
||||
```
|
||||
|
||||
Alternatively, a paren-less version of the attribute may be used to hint the
|
||||
compiler about inlining opportunity:
|
||||
|
||||
```
|
||||
#[inline]
|
||||
fn something() {}
|
||||
```
|
||||
|
||||
For more information about the inline attribute, read:
|
||||
https://doc.rust-lang.org/reference.html#inline-attributes
|
||||
"##,
|
||||
|
||||
E0535: r##"
|
||||
An unknown argument was given to the `inline` attribute.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```ignore (compile_fail not working here; see Issue #43707)
|
||||
#[inline(unknown)] // error: invalid argument
|
||||
pub fn something() {}
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
The `inline` attribute only supports two arguments:
|
||||
|
||||
* always
|
||||
* never
|
||||
|
||||
All other arguments given to the `inline` attribute will return this error.
|
||||
Example:
|
||||
|
||||
```
|
||||
#[inline(never)] // ok!
|
||||
pub fn something() {}
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
For more information about the inline attribute, https:
|
||||
read://doc.rust-lang.org/reference.html#inline-attributes
|
||||
"##,
|
||||
|
||||
E0559: r##"
|
||||
An unknown field was specified into an enum's structure variant.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue