-
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
Try filtering out non-const impls when we expect const impls #87375
Try filtering out non-const impls when we expect const impls #87375
Conversation
Some changes occurred in src/tools/clippy. cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
@@ -285,6 +285,7 @@ impl AutoTraitFinder<'tcx> { | |||
def_id: trait_did, | |||
substs: infcx.tcx.mk_substs_trait(ty, &[]), | |||
}, | |||
constness: hir::Constness::NotConst, |
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.
similarly here, do we want Const
if we are in a const context?
@@ -702,7 +702,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru | |||
let (predicate, binders, _named_regions) = | |||
collect_bound_vars(interner, interner.tcx, self.kind()); | |||
match predicate { | |||
ty::PredicateKind::Trait(predicate, _) => Some(chalk_ir::Binders::new( | |||
ty::PredicateKind::Trait(predicate) => Some(chalk_ir::Binders::new( | |||
binders, | |||
chalk_solve::rust_ir::InlineBound::TraitBound( | |||
predicate.trait_ref.lower_into(interner), |
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 think we need to start tracking this information in chalk, too
only got half way through, will look more tomorrow |
This comment has been minimized.
This comment has been minimized.
2ea3e1d
to
663dfe6
Compare
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.
6e9dbcb
to
52d8288
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Aaaah why do we have these cursed tests of |
This comment has been minimized.
This comment has been minimized.
9023ae5
to
5f19f12
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
Outdated
Show resolved
Hide resolved
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
impl<K, V> BTreeMap<K, V> { | ||
// N.B. bound not on function to avoid unnecessary | ||
// const bound on `Ord`: see #87375 | ||
impl<K: Ord, V> BTreeMap<K, V> { |
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 should not make a difference at all. All bounds on the impl must apply for functions defined inside, too.
if this truly fixes things, that is a bug. Instead we should use a ?const Ord
bound
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.
Hmmmm, are you saying bounds on impls should be treated as const bounds when the functions inside them are const? That would break a lot of existing code I think.
impl<T: Clone> MyType {
fn a() { ... }; // T: Clone
const fn b() { ... }; // T: const Clone?
}
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.
Only code using feature gates, stable code already doesn't allow this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=428faddc9d2bce802ab7423fdfa7db33
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.
Wow, I really didn't know this. But can we use ?const
inside liballoc? That feature is marked as incomplete.
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... I guess we are just going to break ppl using btreemap in const contexts? Or try to remove the bound in a separate PR first?
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.
From the crater run I think not many people are using these functions. I don't think we should remove the bound because it might require more work when re-adding the bound back. I'm fine with breaking BTree{Map,Set}::new for now.
This comment has been minimized.
This comment has been minimized.
fdc54d1
to
48a4868
Compare
This comment has been minimized.
This comment has been minimized.
48a4868
to
74627c1
Compare
@bors r+ rollup=never |
📌 Commit 74627c1 has been approved by |
@@ -293,6 +316,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | |||
self.infcx.tcx | |||
} | |||
|
|||
/// returns `true` if the predicate is considered `const` to |
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.
/// returns `true` if the predicate is considered `const` to | |
/// Returns `true` if the predicate is considered `const` to |
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 will change this after this lands or on this PR if CI fails
fn select_where_possible( | ||
&mut self, | ||
infcx: &InferCtxt<'_, 'tcx>, | ||
) -> Result<(), Vec<FulfillmentError<'tcx>>>; | ||
|
||
// FIXME this should not provide a default body for chalk as chalk should be updated |
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.
// FIXME this should not provide a default body for chalk as chalk should be updated | |
// FIXME(fee1-dead): this should not provide a default body for chalk as chalk should be updated |
fn prove_predicate(&mut self, mut predicate: Predicate<'tcx>) { | ||
if let PredicateKind::Trait(mut tr) = predicate.kind().skip_binder() { | ||
if let hir::Constness::Const = tr.constness { | ||
// FIXME check if we actually want to prove const predicates inside AscribeUserType |
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.
// FIXME check if we actually want to prove const predicates inside AscribeUserType | |
// FIXME(fee1-dead): check if we actually want to prove const predicates inside AscribeUserType |
#[allow(dead_code)] | ||
pub const MY_STRING: String = String::new(); | ||
|
||
// FIXME remove this struct once we put `K: ?const Ord` on BTreeMap::new. |
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.
// FIXME remove this struct once we put `K: ?const Ord` on BTreeMap::new. | |
// FIXME(fee1-dead): remove this struct once we put `K: ?const Ord` on BTreeMap::new. |
@@ -23,6 +23,10 @@ | |||
#![feature(slice_partition_dedup)] | |||
#![feature(vec_spare_capacity)] | |||
#![feature(string_remove_matches)] | |||
#![feature(const_btree_new)] | |||
#![feature(const_trait_impl)] | |||
// FIXME remove this when const_trait_impl is not incomplete anymore |
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.
// FIXME remove this when const_trait_impl is not incomplete anymore | |
// FIXME(fee1-dead): remove this when const_trait_impl is not incomplete anymore |
☀️ Test successful - checks-actions |
TL;DR: Associated types on const impls are now bounded; we now disallow calling a const function with bounds when the specified type param only has a non-const impl.
r? @oli-obk