Skip to content

Add #[rustc_error] annotation, which causes trans to signal an error #22278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2015

Conversation

nikomatsakis
Copy link
Contributor

Add #[rustc_error] annotation, which causes trans to signal an error
if found on the main() function. This lets you write tests that live
in compile-fail but are expected to compile successfully. This is
handy when you have many small variations on a theme that you want to
keep together, and you are just testing the type checker, not the
runtime semantics.

r? @pnkfelix

if found on the `main()` function. This lets you write tests that live
in `compile-fail` but are expected to compile successfully. This is
handy when you have many small variations on a theme that you want to
keep together, and you are just testing the type checker, not the
runtime semantics.
@nikomatsakis
Copy link
Contributor Author

I didn't bother with a feature gate because:

  1. this attribute unconditionally errors, and we always allow errors to become successful
  2. there is a separate plan to feature-gate recognized attributes

// error in trans. This is used to write compile-fail tests
// that actually test that compilation succeeds without
// reporting an error.
if ty::has_attr(ccx.tcx(), local_def(node_id), "rustc_error") {
Copy link
Member

Choose a reason for hiding this comment

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

I am not clear on why you are limiting use of this attribute to fn main(), and having it no-op elsewhere.

I would have had it error everywhere, entry or not, especially since the fact that it errors is the basis of the argument for why it does not need a feature gate.

@pnkfelix
Copy link
Member

@bors r+ b597cbe rollup

@nikomatsakis
Copy link
Contributor Author

@bors r+ fb05f28

@nikomatsakis
Copy link
Contributor Author

@bors rollup

@pnkfelix
Copy link
Member

(niko addressed my feedback with commit b597cbe, but then that did not bootstrap, so he dropped it off again. maybe i will look at that later.)

@nikomatsakis
Copy link
Contributor Author

I tried to make it work everywhere but that required just a bit more work so screw it. I still think my reasoning is sound. If you use it elsewhere, that's fine, but if you use it on main, you'll get an error. We are free to remove it later if we want. In any case, we currently claim all attribute names so...

@nikomatsakis
Copy link
Contributor Author

(For future reference, the problem was that method def-ids cause ty::has_attr to panic.)

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Feb 13, 2015
…sakis

Add `#[rustc_error]` annotation, which causes trans to signal an error
if found on the `main()` function. This lets you write tests that live
in `compile-fail` but are expected to compile successfully. This is
handy when you have many small variations on a theme that you want to
keep together, and you are just testing the type checker, not the
runtime semantics.

r? @pnkfelix
@brson
Copy link
Contributor

brson commented Feb 13, 2015

I would prefer if we not add new attributes without gates or RFCs. This is a language feature.

@nikomatsakis
Copy link
Contributor Author

@brson I disagree, for the reasons listed here: #22278 (comment)

That said, I just want to write my tests, so if you'd rather they have a feature gate, that's fine too.

@nikomatsakis
Copy link
Contributor Author

(Going through an RFC seems like overkill.)

@nikomatsakis
Copy link
Contributor Author

(Though, I think that the plan to only allow a white-listed set of attributes kind of covers the feature-gate, as well.)

@nikomatsakis
Copy link
Contributor Author

Meh. Upon further reflection I decided @brson is probably right. I'll open another PR feature-gating this and a couple of other similar "introspection" annotations -- this can get folded into the more general feature-gate at some later time.

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Feb 14, 2015
…sakis

Add `#[rustc_error]` annotation, which causes trans to signal an error
if found on the `main()` function. This lets you write tests that live
in `compile-fail` but are expected to compile successfully. This is
handy when you have many small variations on a theme that you want to
keep together, and you are just testing the type checker, not the
runtime semantics.

r? @pnkfelix
@nikomatsakis
Copy link
Contributor Author

See #22336

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Feb 15, 2015
…sakis

Add `#[rustc_error]` annotation, which causes trans to signal an error
if found on the `main()` function. This lets you write tests that live
in `compile-fail` but are expected to compile successfully. This is
handy when you have many small variations on a theme that you want to
keep together, and you are just testing the type checker, not the
runtime semantics.

r? @pnkfelix
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 15, 2015
…sakis

 Add `#[rustc_error]` annotation, which causes trans to signal an error
if found on the `main()` function. This lets you write tests that live
in `compile-fail` but are expected to compile successfully. This is
handy when you have many small variations on a theme that you want to
keep together, and you are just testing the type checker, not the
runtime semantics.

r? @pnkfelix
@bors bors merged commit fb05f28 into rust-lang:master Feb 16, 2015
@nikomatsakis nikomatsakis deleted the rustc-error branch March 30, 2016 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants