Skip to content

Commit

Permalink
Check alias args for WF even if they have escaping bound vars
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 10, 2024
1 parent 5974fe8 commit 6143a2c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 49 deletions.
30 changes: 2 additions & 28 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
let obligations = self.nominal_obligations(data.def_id, data.args);
self.out.extend(obligations);

self.compute_projection_args(data.args);
data.args.visit_with(self);
}

/// Pushes the obligations required for an inherent alias to be WF
Expand Down Expand Up @@ -493,33 +493,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.extend(obligations);
}

self.compute_projection_args(data.args);
}

fn compute_projection_args(&mut self, args: GenericArgsRef<'tcx>) {
let tcx = self.tcx();
let cause = self.cause(traits::WellFormed(None));
let param_env = self.param_env;
let depth = self.recursion_depth;

self.out.extend(
args.iter()
.filter(|arg| {
matches!(arg.unpack(), GenericArgKind::Type(..) | GenericArgKind::Const(..))
})
.filter(|arg| !arg.has_escaping_bound_vars())
.map(|arg| {
traits::Obligation::with_depth(
tcx,
cause.clone(),
depth,
param_env,
ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(
arg,
))),
)
}),
);
data.args.visit_with(self);
}

fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/inference/issue-80409.compat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: the trait bound `TFsm: Fsm` is not satisfied
--> $DIR/issue-80409.rs:25:26
|
LL | fn on_entry<TAction: Fn(&mut StateContext<'_, TFsm>)>(&self, _action: TAction) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Fsm` is not implemented for `TFsm`
|
note: required by a bound in `StateContext`
--> $DIR/issue-80409.rs:33:31
|
LL | struct StateContext<'a, TFsm: Fsm> {
| ^^^ required by this bound in `StateContext`
help: consider restricting type parameter `TFsm`
|
LL | impl<TFsm: Fsm> FsmStateBuilder<TFsm> {
| +++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
25 changes: 15 additions & 10 deletions tests/ui/inference/issue-80409.no-compat.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
error: internal compiler error: error performing operation: fully_perform
--> $DIR/issue-80409.rs:49:30
error[E0277]: the trait bound `TFsm: Fsm` is not satisfied
--> $DIR/issue-80409.rs:25:26
|
LL | builder.state().on_entry(|_| {});
| ^^^
LL | fn on_entry<TAction: Fn(&mut StateContext<'_, TFsm>)>(&self, _action: TAction) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Fsm` is not implemented for `TFsm`
|
note:
--> $DIR/issue-80409.rs:49:30
note: required by a bound in `StateContext`
--> $DIR/issue-80409.rs:33:31
|
LL | builder.state().on_entry(|_| {});
| ^^^
LL | struct StateContext<'a, TFsm: Fsm> {
| ^^^ required by this bound in `StateContext`
help: consider restricting type parameter `TFsm`
|
LL | impl<TFsm: Fsm> FsmStateBuilder<TFsm> {
| +++++

error: aborting due to 1 previous error

query stack during panic:
end of query stack
For more information about this error, try `rustc --explain E0277`.
12 changes: 1 addition & 11 deletions tests/ui/inference/issue-80409.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// This should not pass, because `usize: Fsm` does not hold. However, it currently ICEs.

// ignore-tidy-linelength

//@ revisions: compat no-compat
//@[compat] check-pass
//@[no-compat] compile-flags: -Zno-implied-bounds-compat
//@[no-compat] check-fail
//@[no-compat] known-bug: #80409
//@[no-compat] failure-status: 101
//@[no-compat] normalize-stderr-test "delayed at.*" -> ""
//@[no-compat] normalize-stderr-test "note: .*\n\n" -> ""
//@[no-compat] normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
//@[no-compat] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
//@[no-compat] rustc-env:RUST_BACKTRACE=0

#![allow(unreachable_code, unused)]

Expand All @@ -34,6 +23,7 @@ struct FsmStateBuilder<TFsm> {

impl<TFsm> FsmStateBuilder<TFsm> {
fn on_entry<TAction: Fn(&mut StateContext<'_, TFsm>)>(&self, _action: TAction) {}
//~^ ERROR the trait bound `TFsm: Fsm` is not satisfied
}

trait Fsm {
Expand Down

0 comments on commit 6143a2c

Please sign in to comment.