Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f817d19
std: Mark `ptr::Unique` with `#[doc(hidden)]`
Apr 10, 2018
54d6bcb
alloc: Mark `Box::into_unique` with `#[doc(hidden)]`
Apr 11, 2018
d2dc21d
Add documentation for SyntaxContext::remove_mark
sapphire-arches Apr 21, 2018
263b36b
Implement parent() on `syntax_pos::Span`
sapphire-arches Apr 21, 2018
498dbe4
Implement a least upper bound for marks.
sapphire-arches Apr 21, 2018
a2a9cc6
rustc: Disable threads in LLD for wasm
alexcrichton Apr 26, 2018
d92d193
Don't ICE on tuple struct ctor with incorrect arg count
estebank Apr 26, 2018
73e0c1e
Fix review nits
sapphire-arches Apr 26, 2018
20ad427
rustc: Emit `uwtable` for allocator shims
alexcrichton Apr 27, 2018
3565556
Update `parking_lot` dependencies
alexcrichton Apr 27, 2018
5f2c111
Allow #[inline] on closures
Amanieu Apr 27, 2018
199ee32
stop requiring the feature-gate to use dyn_trait
pvdrz Apr 12, 2018
c86f1c8
removed dyn_trait feature from tests
pvdrz Apr 12, 2018
0efb567
dyn_trait feature-gate just for stage0
pvdrz Apr 12, 2018
55a653d
removed linting for dyn_trait
pvdrz Apr 13, 2018
4bf35f9
updated stderr files and removed feature-gate test for dyn_trait
pvdrz Apr 14, 2018
72a8eb9
fixed rustc version for dyn_trait
pvdrz Apr 15, 2018
cadf251
removed dyn trait attribute from librustdoc
pvdrz Apr 18, 2018
74412d2
fix search load page failure
GuillaumeGomez Apr 27, 2018
b80472d
fixed tests
pvdrz Apr 25, 2018
b5c7cbf
rustdoc asks for dyn_trait feature in stage0
pvdrz Apr 25, 2018
a18e7a6
Rollup merge of #49858 - dmizuk:unique-doc-hidden, r=steveklabnik
kennytm Apr 27, 2018
8b36d9a
Rollup merge of #49968 - christianpoveda:stabilize_dyn, r=nikomatsakis
kennytm Apr 27, 2018
4a961d1
Rollup merge of #50192 - bobtwinkles:libsyntax_extensions, r=jseyfried
kennytm Apr 27, 2018
1c1fd27
Rollup merge of #50251 - alexcrichton:wasm-no-threads, r=eddyb
kennytm Apr 27, 2018
0da4bde
Rollup merge of #50263 - alexcrichton:uwtable-allcoators, r=eddyb
kennytm Apr 27, 2018
28762ed
Rollup merge of #50269 - alexcrichton:update-parking-lot, r=Mark-Simu…
kennytm Apr 27, 2018
3f84ce2
Rollup merge of #50273 - Amanieu:issue-49532, r=alexcrichton
kennytm Apr 27, 2018
e598394
Rollup merge of #50284 - GuillaumeGomez:search-load-failure, r=SimonS…
kennytm Apr 27, 2018
dc6b167
Rollup merge of #50257 - estebank:fix-49560, r=nikomatsakis
kennytm Apr 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow #[inline] on closures
Fixes #49632
  • Loading branch information
Amanieu committed Apr 27, 2018
commit 5f2c111165371b1e59fec9cd90e364ccf08b68ef
15 changes: 10 additions & 5 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum Target {
ForeignMod,
Expression,
Statement,
Closure,
Other,
}

Expand Down Expand Up @@ -103,14 +104,14 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
self.check_repr(item, target);
}

/// Check if an `#[inline]` is applied to a function.
/// Check if an `#[inline]` is applied to a function or a closure.
fn check_inline(&self, attr: &hir::Attribute, span: &Span, target: Target) {
if target != Target::Fn {
if target != Target::Fn && target != Target::Closure {
struct_span_err!(self.tcx.sess,
attr.span,
E0518,
"attribute should be applied to function")
.span_label(*span, "not a function")
"attribute should be applied to function or closure")
.span_label(*span, "not a function or closure")
.emit();
}
}
Expand Down Expand Up @@ -286,9 +287,13 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
}

fn check_expr_attributes(&self, expr: &hir::Expr) {
let target = match expr.node {
hir::ExprClosure(..) => Target::Closure,
_ => Target::Expression,
};
for attr in expr.attrs.iter() {
if attr.check_name("inline") {
self.check_inline(attr, &expr.span, Target::Expression);
self.check_inline(attr, &expr.span, target);
}
if attr.check_name("repr") {
self.emit_repr_error(
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/attr-usage-inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[inline]
fn f() {}

#[inline] //~ ERROR: attribute should be applied to function
#[inline] //~ ERROR: attribute should be applied to function or closure
struct S;

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-31769.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
// except according to those terms.

fn main() {
#[inline] struct Foo; //~ ERROR attribute should be applied to function
#[inline] struct Foo; //~ ERROR attribute should be applied to function or closure
#[repr(C)] fn foo() {} //~ ERROR attribute should be applied to struct, enum or union
}
6 changes: 3 additions & 3 deletions src/test/compile-fail/issue-43988.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ fn main() {

#[inline]
let _a = 4;
//~^^ ERROR attribute should be applied to function
//~^^ ERROR attribute should be applied to function or closure


#[inline(XYZ)]
let _b = 4;
//~^^ ERROR attribute should be applied to function
//~^^ ERROR attribute should be applied to function or closure

#[repr(nothing)]
let _x = 0;
Expand All @@ -40,7 +40,7 @@ fn main() {

#[inline(ABC)]
foo();
//~^^ ERROR attribute should be applied to function
//~^^ ERROR attribute should be applied to function or closure

let _z = #[repr] 1;
//~^ ERROR attribute should not be applied to an expression
Expand Down
17 changes: 17 additions & 0 deletions src/test/run-pass/issue-49632.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(stmt_expr_attributes)]

pub fn main() {
let _x = #[inline(always)] || {};
let _y = #[inline(never)] || {};
let _z = #[inline] || {};
}
8 changes: 4 additions & 4 deletions src/test/ui/error-codes/E0518.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/E0518.rs:11:1
|
LL | #[inline(always)] //~ ERROR: E0518
| ^^^^^^^^^^^^^^^^^
LL | struct Foo;
| ----------- not a function
| ----------- not a function or closure

error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/E0518.rs:14:1
|
LL | #[inline(never)] //~ ERROR: E0518
| ^^^^^^^^^^^^^^^^
LL | / impl Foo {
LL | | }
| |_- not a function
| |_- not a function or closure

error: aborting due to 2 previous errors

Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/feature-gate/issue-43106-gating-of-inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
#![inline = "2100"]

#[inline = "2100"]
//~^ ERROR attribute should be applied to function
//~^ ERROR attribute should be applied to function or closure
mod inline {
mod inner { #![inline="2100"] }
//~^ ERROR attribute should be applied to function
//~^ ERROR attribute should be applied to function or closure

#[inline = "2100"] fn f() { }

#[inline = "2100"] struct S;
//~^ ERROR attribute should be applied to function
//~^ ERROR attribute should be applied to function or closure

#[inline = "2100"] type T = S;
//~^ ERROR attribute should be applied to function
//~^ ERROR attribute should be applied to function or closure

#[inline = "2100"] impl S { }
//~^ ERROR attribute should be applied to function
//~^ ERROR attribute should be applied to function or closure
}

fn main() {}
26 changes: 13 additions & 13 deletions src/test/ui/feature-gate/issue-43106-gating-of-inline.stderr
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-inline.rs:21:1
|
LL | #[inline = "2100"]
| ^^^^^^^^^^^^^^^^^^
LL | //~^ ERROR attribute should be applied to function
LL | //~^ ERROR attribute should be applied to function or closure
LL | / mod inline {
LL | | mod inner { #![inline="2100"] }
LL | | //~^ ERROR attribute should be applied to function
LL | | //~^ ERROR attribute should be applied to function or closure
LL | |
... |
LL | | //~^ ERROR attribute should be applied to function
LL | | //~^ ERROR attribute should be applied to function or closure
LL | | }
| |_- not a function
| |_- not a function or closure

error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-inline.rs:24:17
|
LL | mod inner { #![inline="2100"] }
| ------------^^^^^^^^^^^^^^^^^-- not a function
| ------------^^^^^^^^^^^^^^^^^-- not a function or closure

error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-inline.rs:29:5
|
LL | #[inline = "2100"] struct S;
| ^^^^^^^^^^^^^^^^^^ --------- not a function
| ^^^^^^^^^^^^^^^^^^ --------- not a function or closure

error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-inline.rs:32:5
|
LL | #[inline = "2100"] type T = S;
| ^^^^^^^^^^^^^^^^^^ ----------- not a function
| ^^^^^^^^^^^^^^^^^^ ----------- not a function or closure

error[E0518]: attribute should be applied to function
error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43106-gating-of-inline.rs:35:5
|
LL | #[inline = "2100"] impl S { }
| ^^^^^^^^^^^^^^^^^^ ---------- not a function
| ^^^^^^^^^^^^^^^^^^ ---------- not a function or closure

error: aborting due to 5 previous errors

Expand Down