Skip to content

Commit 2d3f828

Browse files
committed
internal constraints are better than placeholder outlives
1 parent 4919d55 commit 2d3f828

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,9 +1726,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17261726
// `BoringNoLocation` constraints can point to user-written code, but are less
17271727
// specific, and are not used for relations that would make sense to blame.
17281728
ConstraintCategory::BoringNoLocation => 6,
1729-
// Do not blame internal constraints.
1730-
ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 7,
1731-
ConstraintCategory::Internal => 8,
1729+
// Do not blame internal constraints if we can avoid it. Never blame
1730+
// the `'region: 'static` constraints introduced by placeholder outlives.
1731+
ConstraintCategory::Internal => 7,
1732+
ConstraintCategory::OutlivesUnnameablePlaceholder(_) => 8,
17321733
};
17331734

17341735
debug!("constraint {constraint:?} category: {category:?}, interest: {interest:?}");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ compile-flags: -Zdeduplicate-diagnostics=yes
2+
3+
// Regression test for #146467.
4+
trait Trait { type Assoc; }
5+
6+
impl Trait for fn(&()) { type Assoc = (); }
7+
8+
fn f(_: for<'a> fn(<fn(&'a ()) as Trait>::Assoc)) {}
9+
//~^ ERROR implementation of `Trait` is not general enough
10+
//~| ERROR higher-ranked subtype error
11+
12+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: implementation of `Trait` is not general enough
2+
--> $DIR/do-not-blame-outlives-static-ice.rs:8:9
3+
|
4+
LL | fn f(_: for<'a> fn(<fn(&'a ()) as Trait>::Assoc)) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
6+
|
7+
= note: `for<'a> fn(&'a ())` must implement `Trait`, for any lifetime `'0`...
8+
= note: ...but `Trait` is actually implemented for the type `for<'a> fn(&'a ())`
9+
10+
error: higher-ranked subtype error
11+
--> $DIR/do-not-blame-outlives-static-ice.rs:8:1
12+
|
13+
LL | fn f(_: for<'a> fn(<fn(&'a ()) as Trait>::Assoc)) {}
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to 2 previous errors
17+

0 commit comments

Comments
 (0)