-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Allow variant discriminant initializers to refer to other initializer… #50072
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustc/ty/mod.rs
Outdated
explicit_value.checked_add(tcx, offset as u128).0 | ||
} | ||
|
||
/// Yields a DefId for the discriminant, an offset to add to it and an initial discriminant |
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.
Looks like this was cut off (missing "and"?).
src/librustc_mir/hair/cx/expr.rs
Outdated
.cast_kinds() | ||
.get(source.hir_id) { | ||
// Convert the lexpr to a vexpr. | ||
ExprKind::Use { source: source.to_ref() } |
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.
Self-reminder that this check should always apply (i.e. be higher up than the variant check) because of things like Enum::Variant as Enum
.
So this basically narrowly allows referring to other variants, as long as you cast it to an int? |
Yes. This is what was happening before, too. |
9c9793a
to
3e35d77
Compare
@eddyb done |
Ping @eddyb |
src/librustc_mir/hair/cx/expr.rs
Outdated
ExprKind::Cast { source: source.to_ref() } | ||
// check whether this is casting an enum variant discriminant | ||
// to prevent cycles, we refer to the discriminant initializer | ||
// which is probably `isize` and thus doesn't need to know the |
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.
s/probably isize
and thus doesn't need to know/always an integer and (hopefully) doesn't need to know
src/librustc_mir/hair/cx/expr.rs
Outdated
}; | ||
ExprKind::Cast { source: source.to_ref() } | ||
} else { | ||
ExprKind::Cast { source: source.to_ref() } |
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.
Can this line be deduplicated?
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.
the source
binding is of different type
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 about the result of calling .to_ref()
?
src/librustc_mir/hair/cx/expr.rs
Outdated
}, | ||
None => mk_const( | ||
cx.tcx(), | ||
ConstVal::Value(Value::ByVal(PrimVal::Bytes(offset as u128))), |
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.
Can this mk_const
be deduplicated between the two match
arms?
src/librustc_mir/hair/cx/expr.rs
Outdated
None | ||
}; | ||
if let Some((did, offset, ty)) = var { | ||
let mk_const = |tcx: ty::TyCtxt<'a, 'gcx, 'tcx>, val| Expr { |
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.
Does this need to take tcx
? It should have cx
in scope - worst case, you do a let tcx = cx.tcx();
before the closure.
src/librustc_mir/hair/cx/expr.rs
Outdated
@@ -664,10 +664,11 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, | |||
}, | |||
None => offset, | |||
}; | |||
ExprKind::Cast { source: source.to_ref() } | |||
source.to_ref() |
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.
Hmm, if I think more about this, mk_const
should also call .to_ref()
, to reduce the number of calls further (and to avoid having an inner source
variable too.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors r+ p=5 |
📌 Commit 33f9c7e has been approved by |
⌛ Testing commit 33f9c7e6fe684883c0e54149245d7fc189940768 with merge dc769e14f23510fff06476b4a31bc9b27ec4e4fb... |
Oops, I was hoping @oli-obk would get to fix it in time and didn't cancel my r+ 😞. |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
…s of the same enum
@bors r=eddyb p=5 sorry about that. Yesterday I had no PC available to me to actually check stuff. |
📌 Commit 195c9f4 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
…s of the same enum
r? @eddyb
fixes the 2.4 failure of #49765
cc @durka @retep998