Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
9 changes: 9 additions & 0 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
{
rustc_parse::fake_token_stream_for_item(&self.cx.sess.psess, item_inner)
}
Annotatable::Item(item_inner) if item_inner.tokens.is_none() => {
rustc_parse::fake_token_stream_for_item(&self.cx.sess.psess, item_inner)
}
Annotatable::ForeignItem(item_inner) if item_inner.tokens.is_none() => {
rustc_parse::fake_token_stream_for_foreign_item(
&self.cx.sess.psess,
item_inner,
)
}
_ => item.to_tokens(),
};
let attr_item = attr.get_normal_item();
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@ pub fn fake_token_stream_for_item(psess: &ParseSess, item: &ast::Item) -> TokenS
unwrap_or_emit_fatal(source_str_to_stream(psess, filename, source, Some(item.span)))
}

pub fn fake_token_stream_for_foreign_item(
psess: &ParseSess,
item: &ast::ForeignItem,
) -> TokenStream {
let source = pprust::foreign_item_to_string(item);
let filename = FileName::macro_expansion_source_code(&source);
unwrap_or_emit_fatal(source_str_to_stream(psess, filename, source, Some(item.span)))
}

pub fn fake_token_stream_for_crate(psess: &ParseSess, krate: &ast::Crate) -> TokenStream {
let source = pprust::crate_to_string_for_macros(krate);
let filename = FileName::macro_expansion_source_code(&source);
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/eii/ice_contract_attr_on_eii_generated_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ compile-flags: --crate-type rlib

#![feature(extern_item_impls)]
#![feature(contracts)]
//~^ WARN the feature `contracts` is incomplete

#[eii]
#[core::contracts::ensures]
//~^ ERROR contract annotations is only supported in functions with bodies
//~| ERROR contract annotations can only be used on functions
fn implementation() {}
//~^ ERROR cannot find value `implementation` in module `self`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error is sus to me. I think this also needs a test of a real EII, that we call at runtime (// @run-pass) to make sure this works. I have a suspicion that the roundtrip of pretty printing destroys the EII link here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. pretty printing and reparsing doesn't preserve the fact that the EII has an implementation.

30 changes: 30 additions & 0 deletions tests/ui/eii/ice_contract_attr_on_eii_generated_item.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error: contract annotations is only supported in functions with bodies
--> $DIR/ice_contract_attr_on_eii_generated_item.rs:8:1
|
LL | #[core::contracts::ensures]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: contract annotations can only be used on functions
--> $DIR/ice_contract_attr_on_eii_generated_item.rs:8:1
|
LL | #[core::contracts::ensures]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0425]: cannot find value `implementation` in module `self`
--> $DIR/ice_contract_attr_on_eii_generated_item.rs:11:4
|
LL | fn implementation() {}
| ^^^^^^^^^^^^^^ not found in `self`

warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/ice_contract_attr_on_eii_generated_item.rs:4:12
|
LL | #![feature(contracts)]
| ^^^^^^^^^
|
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to 3 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0425`.
Loading