Skip to content

Commit fa76d42

Browse files
Merge pull request #1 from rust-lang/master
sync fork with upstream (master)
2 parents 2d81989 + 24faa97 commit fa76d42

File tree

9 files changed

+295
-162
lines changed

9 files changed

+295
-162
lines changed

Diff for: src/librustc/diagnostics.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ Erroneous code example:
637637
```compile_fail,E0152
638638
#![feature(lang_items)]
639639
640-
#[lang = "panic_impl"]
641-
struct Foo; // error: duplicate lang item found: `panic_impl`
640+
#[lang = "arc"]
641+
struct Foo; // error: duplicate lang item found: `arc`
642642
```
643643
644644
Lang items are already implemented in the standard library. Unless you are
@@ -2116,6 +2116,20 @@ struct Foo;
21162116
```
21172117
"##,
21182118

2119+
E0718: r##"
2120+
This error indicates that a `#[lang = ".."]` attribute was placed
2121+
on the wrong type of item.
2122+
2123+
Examples of erroneous code:
2124+
2125+
```compile_fail,E0718
2126+
#![feature(lang_items)]
2127+
2128+
#[lang = "arc"]
2129+
static X: u32 = 42;
2130+
```
2131+
"##,
2132+
21192133
}
21202134

21212135

Diff for: src/librustc/hir/check_attr.rs

+57-17
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,80 @@
1414
//! conflicts between multiple such attributes attached to the same
1515
//! item.
1616
17-
use syntax_pos::Span;
18-
use ty::TyCtxt;
19-
2017
use hir;
2118
use hir::intravisit::{self, Visitor, NestedVisitorMap};
19+
use ty::TyCtxt;
20+
use std::fmt::{self, Display};
21+
use syntax_pos::Span;
2222

2323
#[derive(Copy, Clone, PartialEq)]
24-
enum Target {
24+
pub(crate) enum Target {
25+
ExternCrate,
26+
Use,
27+
Static,
28+
Const,
2529
Fn,
30+
Closure,
31+
Mod,
32+
ForeignMod,
33+
GlobalAsm,
34+
Ty,
35+
Existential,
36+
Enum,
2637
Struct,
2738
Union,
28-
Enum,
29-
Const,
30-
ForeignMod,
39+
Trait,
40+
TraitAlias,
41+
Impl,
3142
Expression,
3243
Statement,
33-
Closure,
34-
Static,
35-
Trait,
36-
Other,
44+
}
45+
46+
impl Display for Target {
47+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48+
write!(f, "{}", match *self {
49+
Target::ExternCrate => "extern crate",
50+
Target::Use => "use",
51+
Target::Static => "static item",
52+
Target::Const => "constant item",
53+
Target::Fn => "function",
54+
Target::Closure => "closure",
55+
Target::Mod => "module",
56+
Target::ForeignMod => "foreign module",
57+
Target::GlobalAsm => "global asm",
58+
Target::Ty => "type alias",
59+
Target::Existential => "existential type",
60+
Target::Enum => "enum",
61+
Target::Struct => "struct",
62+
Target::Union => "union",
63+
Target::Trait => "trait",
64+
Target::TraitAlias => "trait alias",
65+
Target::Impl => "item",
66+
Target::Expression => "expression",
67+
Target::Statement => "statement",
68+
})
69+
}
3770
}
3871

3972
impl Target {
40-
fn from_item(item: &hir::Item) -> Target {
73+
pub(crate) fn from_item(item: &hir::Item) -> Target {
4174
match item.node {
75+
hir::ItemKind::ExternCrate(..) => Target::ExternCrate,
76+
hir::ItemKind::Use(..) => Target::Use,
77+
hir::ItemKind::Static(..) => Target::Static,
78+
hir::ItemKind::Const(..) => Target::Const,
4279
hir::ItemKind::Fn(..) => Target::Fn,
80+
hir::ItemKind::Mod(..) => Target::Mod,
81+
hir::ItemKind::ForeignMod(..) => Target::ForeignMod,
82+
hir::ItemKind::GlobalAsm(..) => Target::GlobalAsm,
83+
hir::ItemKind::Ty(..) => Target::Ty,
84+
hir::ItemKind::Existential(..) => Target::Existential,
85+
hir::ItemKind::Enum(..) => Target::Enum,
4386
hir::ItemKind::Struct(..) => Target::Struct,
4487
hir::ItemKind::Union(..) => Target::Union,
45-
hir::ItemKind::Enum(..) => Target::Enum,
46-
hir::ItemKind::Const(..) => Target::Const,
47-
hir::ItemKind::ForeignMod(..) => Target::ForeignMod,
48-
hir::ItemKind::Static(..) => Target::Static,
4988
hir::ItemKind::Trait(..) => Target::Trait,
50-
_ => Target::Other,
89+
hir::ItemKind::TraitAlias(..) => Target::TraitAlias,
90+
hir::ItemKind::Impl(..) => Target::Impl,
5191
}
5292
}
5393
}

Diff for: src/librustc/middle/lang_items.rs

+164-140
Large diffs are not rendered by default.

Diff for: src/test/ui/error-codes/E0152.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![feature(lang_items)]
1212

13-
#[lang = "panic_impl"]
13+
#[lang = "arc"]
1414
struct Foo; //~ ERROR E0152
1515

1616
fn main() {

Diff for: src/test/ui/error-codes/E0152.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0152]: duplicate lang item found: `panic_impl`.
1+
error[E0152]: duplicate lang item found: `arc`.
22
--> $DIR/E0152.rs:14:1
33
|
44
LL | struct Foo; //~ ERROR E0152
55
| ^^^^^^^^^^^
66
|
7-
= note: first defined in crate `std`.
7+
= note: first defined in crate `alloc`.
88

99
error: aborting due to previous error
1010

Diff for: src/test/ui/error-codes/E0718.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(lang_items)]
12+
13+
// Arc is expected to be a struct, so this will error.
14+
#[lang = "arc"]
15+
static X: u32 = 42;
16+
17+
fn main() {}

Diff for: src/test/ui/error-codes/E0718.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0718]: `arc` language item must be applied to a struct
2+
--> $DIR/E0718.rs:14:1
3+
|
4+
LL | #[lang = "arc"]
5+
| ^^^^^^^^^^^^^^^ attribute should be applied to a struct, not a static item
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0718`.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-C panic=abort
12+
13+
#![no_std]
14+
#![no_main]
15+
16+
#[panic_handler]
17+
#[no_mangle]
18+
static X: u32 = 42;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0718]: `panic_impl` language item must be applied to a function
2+
--> $DIR/panic-handler-wrong-location.rs:16:1
3+
|
4+
LL | #[panic_handler]
5+
| ^^^^^^^^^^^^^^^^ attribute should be applied to a function, not a static item
6+
7+
error: `#[panic_handler]` function required, but not found
8+
9+
error: aborting due to 2 previous errors
10+
11+
For more information about this error, try `rustc --explain E0718`.

0 commit comments

Comments
 (0)