Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,31 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
self.can_eq(param_env, goal.trait_ref, trait_assumption.trait_ref)
}

fn can_match_host_effect(
&self,
param_env: ty::ParamEnv<'tcx>,
goal: ty::HostEffectPredicate<'tcx>,
assumption: ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>,
) -> bool {
let assumption = self.instantiate_binder_with_fresh_vars(
DUMMY_SP,
infer::BoundRegionConversionTime::HigherRankedType,
assumption,
);

assumption.constness.satisfies(goal.constness)
&& self.can_eq(param_env, goal.trait_ref, assumption.trait_ref)
}

fn as_host_effect_clause(
predicate: ty::Predicate<'tcx>,
) -> Option<ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>> {
predicate.as_clause().and_then(|clause| match clause.kind().skip_binder() {
ty::ClauseKind::HostEffect(pred) => Some(clause.kind().rebind(pred)),
_ => None,
})
}

fn can_match_projection(
&self,
param_env: ty::ParamEnv<'tcx>,
Expand Down Expand Up @@ -1484,6 +1509,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
.filter_map(|implied| implied.as_trait_clause())
.any(|implied| self.can_match_trait(param_env, error, implied))
})
} else if let Some(error) = Self::as_host_effect_clause(error.predicate) {
self.enter_forall(error, |error| {
elaborate(self.tcx, std::iter::once(cond.predicate))
.filter_map(Self::as_host_effect_clause)
.any(|implied| self.can_match_host_effect(param_env, error, implied))
})
} else if let Some(error) = error.predicate.as_projection_clause() {
self.enter_forall(error, |error| {
elaborate(self.tcx, std::iter::once(cond.predicate))
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/issue-94675.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ impl<'a> Foo<'a> {
const fn spam(&mut self, baz: &mut Vec<u32>) {
self.bar[0] = baz.len();
//~^ ERROR: `Vec<usize>: [const] Index<_>` is not satisfied
//~| ERROR: `Vec<usize>: [const] Index<usize>` is not satisfied
//~| ERROR: `Vec<usize>: [const] IndexMut<usize>` is not satisfied
}
}
Expand Down
13 changes: 1 addition & 12 deletions tests/ui/consts/issue-94675.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ LL | self.bar[0] = baz.len();
note: trait `IndexMut` is implemented but not `const`
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL

error[E0277]: the trait bound `Vec<usize>: [const] Index<usize>` is not satisfied
--> $DIR/issue-94675.rs:11:9
|
LL | self.bar[0] = baz.len();
| ^^^^^^^^^^^
|
note: trait `Index` is implemented but not `const`
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
note: required by a bound in `std::ops::IndexMut::index_mut`
--> $SRC_DIR/core/src/ops/index.rs:LL:COL

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
1 change: 0 additions & 1 deletion tests/ui/traits/const-traits/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
const _: () = {
assert!((const || true)());
//~^ ERROR }: [const] Fn()` is not satisfied
//~| ERROR }: [const] FnMut()` is not satisfied
};

fn main() {}
11 changes: 1 addition & 10 deletions tests/ui/traits/const-traits/call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ error[E0277]: the trait bound `{closure@$DIR/call.rs:7:14: 7:22}: [const] Fn()`
LL | assert!((const || true)());
| ^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `{closure@$DIR/call.rs:7:14: 7:22}: [const] FnMut()` is not satisfied
--> $DIR/call.rs:7:13
|
LL | assert!((const || true)());
| ^^^^^^^^^^^^^^^^^
|
note: required by a bound in `call`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ error[E0277]: the trait bound `{closure@$DIR/const_closure-const_trait_impl-ice-
LL | (const || (()).foo())();
| ^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `{closure@$DIR/const_closure-const_trait_impl-ice-113381.rs:15:6: 15:14}: [const] FnMut()` is not satisfied
--> $DIR/const_closure-const_trait_impl-ice-113381.rs:15:5
|
LL | (const || (()).foo())();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: required by a bound in `call`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ impl Foo for () {
}

fn main() {
// #150052 deduplicate diagnostics for const trait supertraits
// so we only get one error here
(const || { (()).foo() })();
//~^ ERROR: }: [const] Fn()` is not satisfied
//~| ERROR: }: [const] FnMut()` is not satisfied
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
error[E0277]: the trait bound `{closure@$DIR/non-const-op-const-closure-non-const-outer.rs:13:6: 13:14}: [const] Fn()` is not satisfied
--> $DIR/non-const-op-const-closure-non-const-outer.rs:13:5
error[E0277]: the trait bound `{closure@$DIR/non-const-op-const-closure-non-const-outer.rs:15:6: 15:14}: [const] Fn()` is not satisfied
--> $DIR/non-const-op-const-closure-non-const-outer.rs:15:5
|
LL | (const || { (()).foo() })();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `{closure@$DIR/non-const-op-const-closure-non-const-outer.rs:13:6: 13:14}: [const] FnMut()` is not satisfied
--> $DIR/non-const-op-const-closure-non-const-outer.rs:13:5
|
LL | (const || { (()).foo() })();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: required by a bound in `call`
--> $SRC_DIR/core/src/ops/function.rs:LL:COL

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading