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 @@ -235,8 +235,9 @@ where
// See <https://github.com/rust-lang/trait-system-refactor-initiative/issues/185>.
ecx.try_evaluate_added_goals()?;

// Add GAT where clauses from the trait's definition.
// FIXME: We don't need these, since these are the type's own WF obligations.
// Add GAT where clauses from the trait's definition. This is necessary
// for soundness until we properly handle implied bounds on binders,
// see tests/ui/generic-associated-types/must-prove-where-clauses-on-norm.rs.
ecx.add_goals(
GoalSource::AliasWellFormed,
cx.own_predicates_of(goal.predicate.def_id())
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2055,6 +2055,9 @@ fn confirm_impl_candidate<'cx, 'tcx>(

// Get obligations corresponding to the predicates from the where-clause of the
// associated type itself.
//
// This is necessary for soundness until we properly handle implied bounds on binders.
// see tests/ui/generic-associated-types/must-prove-where-clauses-on-norm.rs.
// FIXME(mgca): While this supports constants, it is only used for types by default right now
fn assoc_term_own_obligations<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: higher-ranked lifetime error
--> $DIR/must-prove-where-clauses-on-norm.rs:23:61
|
LL | let func: for<'a, 'b> fn((), &'b str) -> &'static str = foo::<()>;
| ^^^^^^^^^
|
= note: could not normalize `for<'b> fn(<() as Trait>::Assoc<'_, 'b>, &'b str) -> &str`

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/must-prove-where-clauses-on-norm.rs:23:61
|
LL | let func: for<'a, 'b> fn((), &'b str) -> &'static str = foo::<()>;
| ------------------------------------------- ^^^^^^^^^ one type is more general than the other
| |
| expected due to this
|
= note: expected fn pointer `for<'b> fn((), &'b _) -> &'static _`
found fn item `for<'b> fn(<() as Trait>::Assoc<'_, 'b>, &'b _) -> &_ {foo::<'_, ()>}`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// We have to prove implied bounds of higher-ranked types at some point.
// Normalizing associated types can drop requirements. This means we need
// to prove well-formedness when normalizing them, at least as long as
// implied bounds are implicit.

trait Trait {
type Assoc<'a, 'b: 'a>;
}

impl Trait for () {
type Assoc<'a, 'b: 'a> = ();
}

fn foo<'a, 'b, T: Trait>(_: <T as Trait>::Assoc<'a, 'b>, x: &'b str) -> &'a str {
x
}

fn main() {
let func: for<'a, 'b> fn((), &'b str) -> &'static str = foo::<()>;
//[current]~^ ERROR higher-ranked lifetime error
//[next]~^^ ERROR mismatched types
let x: &'static str = func((), &String::from("temporary"));
println!("{x}");
}
Loading