Skip to content

Commit a071044

Browse files
Eagerly resolve vars in predicate during coercion loop
1 parent 77c3cf1 commit a071044

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
636636
Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)))
637637
if traits.contains(&trait_pred.def_id()) =>
638638
{
639+
let trait_pred = self.resolve_vars_if_possible(trait_pred);
639640
if unsize_did == trait_pred.def_id() {
640641
let self_ty = trait_pred.self_ty();
641642
let unsize_ty = trait_pred.trait_ref.substs[1].expect_ty();
@@ -662,7 +663,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
662663
// Uncertain or unimplemented.
663664
Ok(None) => {
664665
if trait_pred.def_id() == unsize_did {
665-
let trait_pred = self.resolve_vars_if_possible(trait_pred);
666666
let self_ty = trait_pred.self_ty();
667667
let unsize_ty = trait_pred.trait_ref.substs[1].expect_ty();
668668
debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_pred);

src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
1010

1111
const ENTRY_LIMIT: usize = 900;
1212
// FIXME: The following limits should be reduced eventually.
13-
const ISSUES_ENTRY_LIMIT: usize = 1896;
13+
const ISSUES_ENTRY_LIMIT: usize = 1894;
1414
const ROOT_ENTRY_LIMIT: usize = 870;
1515

1616
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[

tests/ui/issues/issue-11515.stderr renamed to tests/ui/traits/trait-upcasting/issue-11515.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: cannot cast `dyn Fn()` to `dyn FnMut()`, trait upcasting coercion is experimental
2-
--> $DIR/issue-11515.rs:9:38
2+
--> $DIR/issue-11515.rs:10:38
33
|
44
LL | let test = Box::new(Test { func: closure });
55
| ^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: cannot cast `dyn Fn()` to `dyn FnMut()`, trait upcasting coercion is experimental
2+
--> $DIR/issue-11515.rs:10:38
3+
|
4+
LL | let test = Box::new(Test { func: closure });
5+
| ^^^^^^^
6+
|
7+
= note: see issue #65991 <https://github.com/rust-lang/rust/issues/65991> for more information
8+
= help: add `#![feature(trait_upcasting)]` to the crate attributes to enable
9+
= note: required when coercing `Box<(dyn Fn() + 'static)>` into `Box<(dyn FnMut() + 'static)>`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

tests/ui/issues/issue-11515.rs renamed to tests/ui/traits/trait-upcasting/issue-11515.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
14
struct Test {
25
func: Box<dyn FnMut() + 'static>,
36
}
47

5-
6-
78
fn main() {
89
let closure: Box<dyn Fn() + 'static> = Box::new(|| ());
910
let test = Box::new(Test { func: closure }); //~ ERROR trait upcasting coercion is experimental [E0658]

0 commit comments

Comments
 (0)