Skip to content

Get rid of StructurallyRelateAliases#158731

Open
adwinwhite wants to merge 3 commits into
rust-lang:mainfrom
adwinwhite:rid-structurally-relate-aliases
Open

Get rid of StructurallyRelateAliases#158731
adwinwhite wants to merge 3 commits into
rust-lang:mainfrom
adwinwhite:rid-structurally-relate-aliases

Conversation

@adwinwhite

@adwinwhite adwinwhite commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Part of #155345

Finally we can get rid of the last use of StructurallyRelateAliases::Yes.

r? lcnr

@rustbot

rustbot commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

changes to the core type system

cc @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jul 3, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests/ui/mismatched_types/closure-mismatch.rs#next stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/mismatched_types/closure-mismatch.next/closure-mismatch.next.stderr`
diff of stderr:

- error[E0277]: the trait bound `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}: Foo` is not satisfied
+ error[E0277]: the trait bound `for<'a> {closure@$DIR/closure-mismatch.rs:12:9: 12:12}: Foo` is not satisfied
2   --> $DIR/closure-mismatch.rs:12:9
3    |
4 LL |     baz(|_| ());

-    |     --- ^^^^^^ unsatisfied trait bound
+    |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@$DIR/closure-mismatch.rs:12:9: 12:12}`
6    |     |
7    |     required by a bound introduced by this call
8    |

-    = help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}`
-    = note: expected a closure with signature `for<'a> fn(&'a ())`
-               found a closure with signature `fn(&())`
- note: this is a known limitation of the trait solver that will be lifted in the future
-   --> $DIR/closure-mismatch.rs:12:9
-    |
- LL |     baz(|_| ());
-    |     ----^^^----
-    |     |   |
-    |     |   the trait solver is unable to infer the generic types that should be inferred from this argument
-    |     add turbofish arguments to this call to specify the types manually, even if it's redundant
- note: required for `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}` to implement `Foo`
+ note: required for `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}` to implement `for<'a> Foo`
21   --> $DIR/closure-mismatch.rs:7:18
22    |
23 LL | impl<T: Fn(&())> Foo for T {}

29    |
30 LL | fn baz<T: Foo>(_: T) {}
31    |           ^^^ required by this bound in `baz`
+ help: consider borrowing here
+    |
+ LL |     baz(&|_| ());
+    |         +
32 
- error[E0277]: the trait bound `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}: Foo` is not satisfied
+ error[E0277]: the trait bound `for<'a> {closure@$DIR/closure-mismatch.rs:16:9: 16:12}: Foo` is not satisfied
34   --> $DIR/closure-mismatch.rs:16:9
35    |
36 LL |     baz(|x| ());

-    |     --- ^^^^^^ unsatisfied trait bound
+    |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@$DIR/closure-mismatch.rs:16:9: 16:12}`
38    |     |
39    |     required by a bound introduced by this call
40    |

-    = help: the trait `for<'a> FnOnce(&'a ())` is not implemented for closure `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}`
-    = note: expected a closure with signature `for<'a> fn(&'a ())`
-               found a closure with signature `fn(&())`
- note: this is a known limitation of the trait solver that will be lifted in the future
-   --> $DIR/closure-mismatch.rs:16:9
-    |
- LL |     baz(|x| ());
-    |     ----^^^----
-    |     |   |
-    |     |   the trait solver is unable to infer the generic types that should be inferred from this argument
-    |     add turbofish arguments to this call to specify the types manually, even if it's redundant
- note: required for `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}` to implement `Foo`
+ note: required for `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}` to implement `for<'a> Foo`
53   --> $DIR/closure-mismatch.rs:7:18
54    |
55 LL | impl<T: Fn(&())> Foo for T {}

61    |
62 LL | fn baz<T: Foo>(_: T) {}
63    |           ^^^ required by this bound in `baz`
+ help: consider borrowing here
+    |
+ LL |     baz(&|x| ());
+    |         +
64 
65 error: aborting due to 2 previous errors
66 

Note: some mismatched output was normalized before being compared
- error[E0277]: the trait bound `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9: 12:12}: Foo` is not satisfied
-   --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9
-    |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9: 12:12}`
- note: required for `{closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9: 12:12}` to implement `for<'a> Foo`
-   --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:7:18
- error[E0277]: the trait bound `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9: 16:12}: Foo` is not satisfied
-   --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9
-    |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9: 16:12}`
- note: required for `{closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9: 16:12}` to implement `for<'a> Foo`
-   --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:7:18
+ error[E0277]: the trait bound `for<'a> {closure@$DIR/closure-mismatch.rs:12:9: 12:12}: Foo` is not satisfied
+    |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@$DIR/closure-mismatch.rs:12:9: 12:12}`
+ note: required for `{closure@$DIR/closure-mismatch.rs:12:9: 12:12}` to implement `for<'a> Foo`
+ help: consider borrowing here
+    |
+ LL |     baz(&|_| ());
+    |         +
+ error[E0277]: the trait bound `for<'a> {closure@$DIR/closure-mismatch.rs:16:9: 16:12}: Foo` is not satisfied
+    |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@$DIR/closure-mismatch.rs:16:9: 16:12}`
+ note: required for `{closure@$DIR/closure-mismatch.rs:16:9: 16:12}` to implement `for<'a> Foo`
+ help: consider borrowing here
+    |
+ LL |     baz(&|x| ());
+    |         +


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args mismatched_types/closure-mismatch.rs`

error in revision `next`: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/mismatched_types/closure-mismatch.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "next" "--check-cfg" "cfg(test,FALSE,current,next)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/mismatched_types/closure-mismatch.next" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Znext-solver"
stdout: none
--- stderr -------------------------------
error[E0277]: the trait bound `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9: 12:12}: Foo` is not satisfied
##[error]  --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9
   |
LL |     baz(|_| ());
   |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9: 12:12}`
   |     |
   |     required by a bound introduced by this call
   |
note: required for `{closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:12:9: 12:12}` to implement `for<'a> Foo`
  --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:7:18
   |
LL | impl<T: Fn(&())> Foo for T {}
   |         -------  ^^^     ^
   |         |
   |         unsatisfied trait bound introduced here
note: required by a bound in `baz`
  --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:9:11
   |
LL | fn baz<T: Foo>(_: T) {}
   |           ^^^ required by this bound in `baz`
help: consider borrowing here
   |
LL |     baz(&|_| ());
   |         +

error[E0277]: the trait bound `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9: 16:12}: Foo` is not satisfied
##[error]  --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9
   |
LL |     baz(|x| ());
   |     --- ^^^^^^ the trait `for<'a> Foo` is not implemented for `for<'a> {closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9: 16:12}`
   |     |
   |     required by a bound introduced by this call
   |
note: required for `{closure@/checkout/tests/ui/mismatched_types/closure-mismatch.rs:16:9: 16:12}` to implement `for<'a> Foo`
  --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:7:18
   |
LL | impl<T: Fn(&())> Foo for T {}
   |         -------  ^^^     ^
   |         |
   |         unsatisfied trait bound introduced here
note: required by a bound in `baz`
  --> /checkout/tests/ui/mismatched_types/closure-mismatch.rs:9:11
   |
LL | fn baz<T: Foo>(_: T) {}
   |           ^^^ required by this bound in `baz`
help: consider borrowing here
   |
LL |     baz(&|x| ());
   |         +

error: aborting due to 2 previous errors

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

self.inner.borrow_mut().const_unification_table().union(a, b);
}

fn equate_ty_var_raw(&self, vid: ty::TyVid, ty: Ty<'tcx>) {

@lcnr lcnr Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please name them instantiate instead of equate

View changes since the review

})
}

/// Enforce that `a` is equal to `b`.

@lcnr lcnr Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should comment

  • how is it different from eq
  • why does it exist
  • where is it used

View changes since the review

}

(ty::Infer(ty::TyVar(a_vid)), _) => {
infcx.equate_ty_var_raw(a_vid, b);

@lcnr lcnr Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a debug_assert to instantiate_ty_var_raw tht the type we instantiate it with does not refer to anything from a higher universe?

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for regions and consts :>

Comment on lines +340 to +341
let a = infcx.shallow_resolve_const(a);
let b = infcx.shallow_resolve_const(b);

@lcnr lcnr Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to not do that but debug_assert that this is a noop?

View changes since the review

Comment on lines +380 to +381
if let Some(a_inner) = a.no_bound_vars()
&& let Some(b_inner) = b.no_bound_vars()

@lcnr lcnr Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a and b have exactly the same bound vars here. we don't have to bother with the rebinding 🤔 actually, we can just recurse without instantiating bound vars at all

we can just assert that the bound vars are equal, and then recurse :>

View changes since the review

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful ❤️ i love rigid aliases

View changes since this review

@rust-bors

rust-bors Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #158795) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants