Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check alias args for WF even if they have escaping bound vars #123737

Merged
merged 1 commit into from
Jul 3, 2024
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
12 changes: 3 additions & 9 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,6 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
}
}

/// Pushes the obligations required for an alias (except inherent) to be WF
/// into `self.out`.
fn compute_alias_ty(&mut self, data: ty::AliasTy<'tcx>) {
self.compute_alias_term(data.into());
}

/// Pushes the obligations required for an alias (except inherent) to be WF
/// into `self.out`.
fn compute_alias_term(&mut self, data: ty::AliasTerm<'tcx>) {
Expand Down Expand Up @@ -498,7 +492,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
self.out.extend(obligations);
}

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

fn compute_projection_args(&mut self, args: GenericArgsRef<'tcx>) {
Expand Down Expand Up @@ -702,8 +696,8 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
}

ty::Alias(ty::Projection | ty::Opaque | ty::Weak, data) => {
self.compute_alias_ty(data);
return; // Subtree handled by compute_projection.
let obligations = self.nominal_obligations(data.def_id, data.args);
self.out.extend(obligations);
}
ty::Alias(ty::Inherent, data) => {
self.compute_inherent_projection(data);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/higher-ranked/well-formed-aliases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait Trait {
type Gat<U: ?Sized>;
}

fn test<T>(f: for<'a> fn(<&'a T as Trait>::Gat<&'a [str]>)) where for<'a> &'a T: Trait {}
//~^ ERROR the size for values of type `str` cannot be known at compilation time

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/higher-ranked/well-formed-aliases.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/well-formed-aliases.rs:5:52
|
LL | fn test<T>(f: for<'a> fn(<&'a T as Trait>::Gat<&'a [str]>)) where for<'a> &'a T: Trait {}
| ^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
= note: slice and array elements must have `Sized` type

error: aborting due to 1 previous error

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