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

lazy_type_alias: causes error no nominal type found for inherent implementation #114216

Closed
matthiaskrgr opened this issue Jul 29, 2023 · 1 comment · Fixed by #120780
Closed
Assignees
Labels
C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

I tried this code:
tests/rustdoc/deref/deref-typedef.rs

#![crate_name = "foo"]

// @has 'foo/struct.Bar.html'
// @has '-' '//*[@id="deref-methods-FooJ"]' 'Methods from Deref<Target = FooJ>'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_a"]' 'pub fn foo_a(&self)'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_b"]' 'pub fn foo_b(&self)'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_c"]' 'pub fn foo_c(&self)'
// @has '-' '//*[@class="impl-items"]//*[@id="method.foo_j"]' 'pub fn foo_j(&self)'
// @has '-' '//div[@class="sidebar-elems"]//h3/a[@href="#deref-methods-FooJ"]' 'Methods from Deref<Target=FooJ>'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_a"]' 'foo_a'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_b"]' 'foo_b'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_c"]' 'foo_c'
// @has '-' '//*[@class="sidebar-elems"]//section//a[@href="#method.foo_j"]' 'foo_j'

pub struct FooA;
pub type FooB = FooA;
pub type FooC = FooB;
pub type FooD = FooC;
pub type FooE = FooD;
pub type FooF = FooE;
pub type FooG = FooF;
pub type FooH = FooG;
pub type FooI = FooH;
pub type FooJ = FooI;

impl FooA {
    pub fn foo_a(&self) {}
}

impl FooB {
    pub fn foo_b(&self) {}
}

impl FooC {
    pub fn foo_c(&self) {}
}

impl FooJ {
    pub fn foo_j(&self) {}
}

pub struct Bar;
impl std::ops::Deref for Bar {
    type Target = FooJ;
    fn deref(&self) -> &Self::Target { unimplemented!() }
}

without `-Zcrate-attr=feature(lazy_type_alias)´: no warnings

with -Zcrate-attr=feature(lazy_type_alias):

error[E0118]: no nominal type found for inherent implementation
  --> tests/rustdoc/deref/deref-typedef.rs:30:1
   |
30 | impl FooB {
   | ^^^^^^^^^ impl requires a nominal type
   |
   = note: either implement a trait on it or create a newtype to wrap it instead

error[E0118]: no nominal type found for inherent implementation
  --> tests/rustdoc/deref/deref-typedef.rs:34:1
   |
34 | impl FooC {
   | ^^^^^^^^^ impl requires a nominal type
   |
   = note: either implement a trait on it or create a newtype to wrap it instead

error[E0118]: no nominal type found for inherent implementation
  --> tests/rustdoc/deref/deref-typedef.rs:38:1
   |
38 | impl FooJ {
   | ^^^^^^^^^ impl requires a nominal type
   |
   = note: either implement a trait on it or create a newtype to wrap it instead

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0118`.
rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5
@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` labels Jul 29, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
@compiler-errors compiler-errors added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 29, 2023
@matthiaskrgr
Copy link
Member Author

#![feature(lazy_type_alias)]
pub struct FooA;
pub type FooJ = FooA;

impl FooJ {}

@compiler-errors compiler-errors removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jul 29, 2023
@fmease fmease self-assigned this Oct 13, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 17, 2024
Properly deal with weak alias types as self types of impls

Fixes rust-lang#114216.
Fixes rust-lang#116100.

Not super happy about the two ad hoc “normalization” implementations for weak alias types:

1. In `inherent_impls`: The “peeling”, normalization to [“WHNF”][whnf]: Semantically that's exactly what we want (neither proper normalization nor shallow normalization would be correct here). Basically a weak alias type is “nominal” (well...^^) if the WHNF is nominal. [rust-lang#97974](rust-lang#97974) followed the same approach.
2. In `constrained_generic_params`: Generic parameters are constrained by a weak alias type if the corresp. “normalized” type constrains them (where we only normalize *weak* alias types not arbitrary ones). Weak alias types are injective if the corresp. “normalized” type is injective.

Both have ad hoc overflow detection mechanisms.

**Coherence** is handled in rust-lang#117164.

r? `@oli-obk` or types

[whnf]: https://en.wikipedia.org/wiki/Lambda_calculus_definition#Weak_head_normal_form
@bors bors closed this as completed in d3df8ff Feb 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants