Skip to content

Commit 9bb9833

Browse files
Add method to Candidate that determines its promotability rules
1 parent 8d78bf6 commit 9bb9833

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/librustc_mir/transform/promote_consts.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ pub enum Candidate {
8080
Argument { bb: BasicBlock, index: usize },
8181
}
8282

83+
impl Candidate {
84+
/// Returns `true` if we should use the "explicit" rules for promotability for this `Candidate`.
85+
fn forces_explicit_promotion(&self) -> bool {
86+
match self {
87+
Candidate::Ref(_) |
88+
Candidate::Repeat(_) => false,
89+
Candidate::Argument { .. } => true,
90+
}
91+
}
92+
}
93+
8394
fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
8495
let attrs = tcx.get_attrs(def_id);
8596
let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?;
@@ -727,11 +738,7 @@ pub fn validate_candidates(
727738
};
728739

729740
candidates.iter().copied().filter(|&candidate| {
730-
validator.explicit = match candidate {
731-
Candidate::Ref(_) |
732-
Candidate::Repeat(_) => false,
733-
Candidate::Argument { .. } => true,
734-
};
741+
validator.explicit = candidate.forces_explicit_promotion();
735742

736743
// FIXME(eddyb) also emit the errors for shuffle indices
737744
// and `#[rustc_args_required_const]` arguments here.

0 commit comments

Comments
 (0)