Extend lang items to assert correct target.

This commit extends the existing lang items functionality to assert
that the `#[lang_item]` attribute is only found on the appropriate item
for any given lang item. That is, language items representing traits
must only ever have their corresponding attribute placed on a trait, for
example.
This commit is contained in:
David Wood 2018-10-11 19:36:51 +02:00
parent a534216fa6
commit 2ecce7ccc5
No known key found for this signature in database
GPG key ID: 01760B4F9F53F154
9 changed files with 286 additions and 153 deletions

View file

@ -10,7 +10,7 @@
#![feature(lang_items)]
#[lang = "panic_impl"]
#[lang = "arc"]
struct Foo; //~ ERROR E0152
fn main() {

View file

@ -1,10 +1,10 @@
error[E0152]: duplicate lang item found: `panic_impl`.
error[E0152]: duplicate lang item found: `arc`.
--> $DIR/E0152.rs:14:1
|
LL | struct Foo; //~ ERROR E0152
| ^^^^^^^^^^^
|
= note: first defined in crate `std`.
= note: first defined in crate `alloc`.
error: aborting due to previous error

View file

@ -0,0 +1,17 @@
// Copyright 2013 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(lang_items)]
// Arc is expected to be a struct, so this will error.
#[lang = "arc"]
static X: u32 = 42;
fn main() {}

View file

@ -0,0 +1,9 @@
error[E0718]: `arc` language item must be applied to a struct
--> $DIR/E0718.rs:14:1
|
LL | #[lang = "arc"]
| ^^^^^^^^^^^^^^^ attribute should be applied to a struct, not a static item
error: aborting due to previous error
For more information about this error, try `rustc --explain E0718`.

View file

@ -0,0 +1,18 @@
// 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.
// compile-flags:-C panic=abort
#![no_std]
#![no_main]
#[panic_handler]
#[no_mangle]
static X: u32 = 42;

View file

@ -0,0 +1,11 @@
error[E0718]: `panic_impl` language item must be applied to a function
--> $DIR/panic-handler-wrong-location.rs:16:1
|
LL | #[panic_handler]
| ^^^^^^^^^^^^^^^^ attribute should be applied to a function, not a static item
error: `#[panic_handler]` function required, but not found
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0718`.