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

Don't create dummy if val has escaping bounds var #105694

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
@@ -451,19 +451,21 @@ impl<'tcx> WfPredicates<'tcx> {
GenericArgKind::Const(ct) => {
match ct.kind() {
ty::ConstKind::Unevaluated(uv) => {
let obligations = self.nominal_obligations(uv.def.did, uv.substs);
self.out.extend(obligations);

let predicate =
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct));
let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
self.tcx(),
cause,
self.recursion_depth,
self.param_env,
predicate,
));
if !ct.has_escaping_bound_vars() {
Copy link
Contributor

Choose a reason for hiding this comment

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

While this fixes the ICE this is probably unsound around inline consts and const generics.

We should not skip logic if there are excess bound vars outside of possibly diagnostics. The right fix here would be to find out where the binder was skipped and stop doing that. This will require wrappig some function arguments in binders at call sites to the current function.

Copy link
Contributor

@oli-obk oli-obk Dec 16, 2022

Choose a reason for hiding this comment

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

Ah... this is "ok" because it can't cause unsoundness at present and fixing it in the way I described would cause errors about things having to live for 'static.

Please add a comment explaining why not adding these obligations is ok

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'm not really sure how I feel about this change overall. I don't like adding yet another place that we're not registering WF with bound vars.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm willing to work on another solution, but I am not sure where to start for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could keep the binders around, but then we'd do higher ranked trait solving which just tells us that all lifetimes must be 'static. So basically turning the ICE into an error

let obligations = self.nominal_obligations(uv.def.did, uv.substs);
self.out.extend(obligations);

let predicate =
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct));
let cause = self.cause(traits::WellFormed(None));
self.out.push(traits::Obligation::with_depth(
self.tcx(),
cause,
self.recursion_depth,
self.param_env,
predicate,
));
}
}
ty::ConstKind::Infer(_) => {
let cause = self.cause(traits::WellFormed(None));
14 changes: 14 additions & 0 deletions src/test/ui/const-generics/issue-105689.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// check-pass
// edition:2021
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

#[allow(unused)]
async fn foo<'a>() {
let _data = &mut [0u8; { 1 + 4 }];
bar().await
}

async fn bar() {}

fn main() {}