-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[WIP] rustc_typeck: check well-formedness of type aliases. #54033
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4c9ffde
to
a3f11cf
Compare
This comment has been minimized.
This comment has been minimized.
Add bounds to type aliases (needed by rust-lang/rust#54033).
@bors try (for crater in check mode) |
⌛ Trying commit 013d7f0634496b2d2defd8acce43fcbed1163526 with merge 0ed22d1874786c4c6a348e14674cad1dc19df6a0... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
Okay, so serde is already a problem there, which means we can't easily do the crater run I wanted to do. I'll move to warn on Rust 2015 and only error on Rust 2018. |
@eddyb yeah that sounds reasonable. |
013d7f0
to
0568e27
Compare
@bors try |
⌛ Trying commit 0568e27db5f862d27f210c0dac637870a4c209de with merge ecd082c0984889e4676a3dd794753309c854ab46... |
@craterbot command follows: run start=master#cb6d2dfa8923902b0992a1522dc4a45a9d3ba690 end=try#cfeeefe83c83bceb55d60d7e2be173db7597ed50 mode=check-only |
(just pushed test fixes only, try build shouldn't care) |
☔ The latest upstream changes (presumably #54260) made this pull request unmergeable. Please resolve the merge conflicts. |
@craterbot run start=master#cb6d2dfa8923902b0992a1522dc4a45a9d3ba690 end=try#cfeeefe83c83bceb55d60d7e2be173db7597ed50 mode=check-only |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
let local_id_root = tables.local_id_root?; | ||
assert!(local_id_root.is_local()); | ||
|
||
tables.node_types().iter().filter_map(|(&local_id, &node_ty)| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
such ECS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It'd be nice to pull this out into some sort of helper function, I think? I'd also like to see a comment, something like:
Iterate over the all the things that we've assigned types to. Check whether they represent local variables and, if so, if the type of that local variable references the type we are looking for.
|
||
let span = obligation.cause.span; | ||
let lint = self.get_lint_from_cause_code(&obligation.cause.code); | ||
macro_rules! struct_span_err_or_lint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I feel like I've seen this macro at least twice. Can't we abstract this somehow? Or move it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It specifically takes advantage of variables in scope, so sadly it wouldn't be that easy.
We'd have to take both infcx
and obligation.cause
(instead of tcx.sess
and span
), I think? Maybe it is easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think struct_obligation_err_or_lint
, as a name for the macro?
Also, is it just me or is struct
just not the best word to use?
I almost want to move everything to diagnostic builders so we can get rid of the non-struct_
versions and remove the struct_
prefix.
pub fn report_selection_error(&self, | ||
obligation: &PredicateObligation<'tcx>, | ||
error: &SelectionError<'tcx>, | ||
fallback_has_occurred: bool) | ||
{ | ||
let span = obligation.cause.span; | ||
|
||
let lint = self.get_lint_from_cause_code(&obligation.cause.code); | ||
macro_rules! struct_span_err_or_lint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes 3 times :)
@@ -50,7 +50,6 @@ use syntax_pos::{DUMMY_SP, Span}; | |||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
pub fn report_fulfillment_errors(&self, | |||
errors: &[FulfillmentError<'tcx>], | |||
body_id: Option<hir::BodyId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it we're getting the body_id
from the ObligationCause
here? I had planned to remove that field once we transition to NLL, since it won't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I guess we could thread this info back through then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was only used for the code in need_type_info.rs
that was visiting the HIR so thankfully I think we won't need it!
I actually couldn't visit the HIR because the body_id
on the obligation was sometimes "not large enough" to include the closure that had the offending argument.
🎉 Experiment
|
See #49441 (comment) - TL;DR we can't make "not enough bounds" an error in Rust 2018. |
fcx.body_id, | ||
p, | ||
span)); | ||
&cause, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but fcx.normalize_associated_types_in(span, &predicates)
above should be fcx.inh.normalize_associated_types_in(cause, fcx.param_env, &predicates)
instead.
Ping from triage @eddyb: What is the status of this PR? |
I'm going to close this PR for now. I do plan to start opening some PRs and issuing warnings, per the plan discussed in #55222 |
Enforce that for type aliases (
type Foo<T: Trait> = Bar<T>;
), all the bounds required by the type being aliased (Bar<T>
) are satisfied (e.g. byT: Trait
).On Rust 2015, this is reported as a lint, but on Rust 2018 it's a hard error.
(see #49441 (comment) for more details on the decision taken)
NOTE: this is only the first half, we also need to check declared bounds assuming the RHS type is WF (to ensure the type alias is fully equivalent to its RHS type, everywhere it's used).
EDIT: second half is up at #54090.
Fixes #44075, fixes #51626.
r? @nikomatsakis