-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Avoid leaking opaque hidden types via auto trait candidates #159589
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
Open
bit-aloo
wants to merge
6
commits into
rust-lang:main
Choose a base branch
from
bit-aloo:2026-07-29-opaque-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
80e76e4
add opaque test
bit-aloo 6c7dbaf
next-solver: avoid leaking opaque hidden types via auto trait probes
bit-aloo 764e206
define consider_auto_trait_candidate_for_opaque_ty and call it from c…
bit-aloo 568806f
make the match exhaustive again
bit-aloo f6687b0
Don't let thte diagnostic leak the inner types of opaque types
bit-aloo d974280
Add description to test and move consider_auto_trait_candidate_for_o…
bit-aloo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/ui/impl-trait/auto-trait-leakage/auxiliary/opaque-auto-trait-leakage.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| pub struct WaddupGamers<T, U>(Option<T>, U); | ||
|
|
||
| impl<T: Leak<Assoc = U>, U> Unpin for WaddupGamers<T, U> {} | ||
|
|
||
| pub trait Leak { | ||
| type Assoc; | ||
| } | ||
|
|
||
| impl<T> Leak for T { | ||
| type Assoc = T; | ||
| } | ||
|
|
||
| pub fn define<T>() -> impl Sized { | ||
| WaddupGamers(None::<T>, || ()) | ||
| } |
37 changes: 37 additions & 0 deletions
37
tests/ui/impl-trait/auto-trait-leakage/opaque-hidden-ty-inference.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //@ ignore-compare-mode-next-solver | ||
| //@ compile-flags: -Znext-solver | ||
| //@ aux-build:opaque-auto-trait-leakage.rs | ||
|
|
||
|
lcnr marked this conversation as resolved.
|
||
| //! Regression test for https://github.com/rust-lang/rust/issues/134578. | ||
| //! When reporting a failed auto-trait obligation for an opaque type, diagnostics | ||
| //! must not reveal the opaque's hidden type. In this test, the error should refer | ||
| //! only to `impl Sized`, without exposing the concrete type from the auxiliary crate. | ||
|
|
||
| #![feature(type_alias_impl_trait)] | ||
| #![allow(unused)] | ||
|
|
||
| extern crate opaque_auto_trait_leakage as dep; | ||
|
|
||
| use dep::*; | ||
|
|
||
| fn require_auto<T: Unpin>(x: T) -> T { | ||
| x | ||
| } | ||
|
|
||
| type NameMe<T> = impl Sized; | ||
|
|
||
| #[define_opaque(NameMe)] | ||
| fn leak<T>() -> NameMe<T> | ||
| where | ||
| T: Leak<Assoc = NameMe<T>>, | ||
| { | ||
| // Proving `impl Sized: Unpin` must not constrain `NameMe<T>` | ||
| // to the foreign closure hidden inside `define`. | ||
| let opaque = require_auto(define::<T>()); | ||
| //~^ ERROR `impl Sized` cannot be unpinned | ||
| let closure; | ||
| loop {} | ||
| return closure; | ||
| } | ||
|
|
||
| fn main() {} | ||
19 changes: 19 additions & 0 deletions
19
tests/ui/impl-trait/auto-trait-leakage/opaque-hidden-ty-inference.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| error[E0277]: `impl Sized` cannot be unpinned | ||
| --> $DIR/opaque-hidden-ty-inference.rs:30:31 | ||
| | | ||
| LL | let opaque = require_auto(define::<T>()); | ||
| | ------------ ^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `impl Sized` | ||
| | | | ||
| | required by a bound introduced by this call | ||
| | | ||
| = note: consider using the `pin!` macro | ||
| consider using `Box::pin` if you need to access the pinned value outside of the current scope | ||
| note: required by a bound in `require_auto` | ||
| --> $DIR/opaque-hidden-ty-inference.rs:17:20 | ||
| | | ||
| LL | fn require_auto<T: Unpin>(x: T) -> T { | ||
| | ^^^^^ required by this bound in `require_auto` | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.