Skip to content
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

Fix exceeding bitshifts not emitting for assoc. consts (properly this time, I swear!) #71663

Merged
merged 19 commits into from
May 3, 2020

Conversation

jumbatm
Copy link
Contributor

@jumbatm jumbatm commented Apr 29, 2020

Fixes #69021 and fixes #71353.

As described in #71353 (comment), this PR:

  • adds a variant of try_validation! called try_validation_pat! that allows specific failures to be turned into validation failures (but returns the rest, unchanged), and
  • allows InvalidProgram to be returned out of validation

r? @RalfJung

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 29, 2020
@RalfJung
Copy link
Member

Cc @rust-lang/wg-const-eval

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

I love it, this is very precisely targetting the issue, I wonder if we should extend the use of try_validation_pat to other situations (out of scope for this PR obviously).

Do we have a test for the ICE that was caused by the earlier fix? Just to make sure we don't regress that case again :)

src/librustc_mir/interpret/validity.rs Outdated Show resolved Hide resolved
src/librustc_mir/interpret/validity.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member

Do we have a test for the ICE that was caused by the earlier fix? Just to make sure we don't regress that case again :)

Yes we do: src/test/ui/consts/const-eval/ice-generic-assoc-const.rs. Except that this PR breaks that test again, which obviously it should not do.

@jumbatm jumbatm force-pushed the caller-handles-validation-error branch from 9de5632 to bd18ad4 Compare May 1, 2020 12:48
@jumbatm jumbatm requested a review from RalfJung May 3, 2020 00:44
}
/// Like try_validation, but will throw a validation error if any of the patterns in $p are
/// matched. Other errors are passed back to the caller, unchanged. This lets you use the patterns
/// as a kind of validation blacklist:
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it more of a whitelist? Unexpected errors will bubble up to the root and cause ICEs.

Err(_) => throw_validation_failure!($what, $where),
// We catch the error and turn it into a validation failure. We are okay with
// allocation here as this can only slow down builds that fail anyway.
$( Err(InterpErrorInfo { kind: $p, .. }) )|+ =>
Copy link
Member

Choose a reason for hiding this comment

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

Wow this is advanced macro magic, cool stuff.

///
/// ```
/// let v = try_validation_pat!(some_fn(), some_path, {
/// Foo | Bar | Baz => { "{:?}", some_failure } expected { "{}", expected_value },
Copy link
Member

Choose a reason for hiding this comment

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

This is great. :D

I think my one complaint is that using curly braces to delemit parameters is a bit odd. We don't write format_args!{ "{:?}", some_failure } either. But I don't have a better proposal off the top of my head either... @oli-obk any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't come up with a nicer syntax off the top of my head. Parens would definitely look worse:

Foo | Bar | Baz => ("{:?}", some_failure) expected("{}", expected_value),

I think it's fine as it is.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, let's go with curly braces then.

Should we replace expected by @expected or so to more clearly mark it as a keyword? Not sure what the usual macro conventions are, this is certainly something I have seen before.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's standing out enough by the definitely not-legal-rust syntax. But I wouldn't mind an additional @ if you think that makes it clearer.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, let's go with this for now, we can always change it later.

@RalfJung
Copy link
Member

RalfJung commented May 3, 2020

Thanks @jumbatm!
@bors r+

@bors
Copy link
Contributor

bors commented May 3, 2020

📌 Commit bd18ad4 has been approved by RalfJung

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 3, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 3, 2020
Rollup of 4 pull requests

Successful merges:

 - rust-lang#71398 (Add `RefCell::take`)
 - rust-lang#71663 (Fix exceeding bitshifts not emitting for assoc. consts (properly this time, I swear!))
 - rust-lang#71726 (Suggest deref when coercing `ty::Ref` to `ty::RawPtr` with arbitrary mutability)
 - rust-lang#71808 (Add long error explanation for E0539)

Failed merges:

r? @ghost
@bors bors merged commit 5b17290 into rust-lang:master May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type validation mistreats layout errors "exceeding_bitshifts" lint does not work in associated consts
5 participants