Skip to content

fix type of const params in assoc fns. - #70276

Closed
lcnr wants to merge 3 commits into
rust-lang:masterfrom
lcnr:issue70273
Closed

fix type of const params in assoc fns.#70276
lcnr wants to merge 3 commits into
rust-lang:masterfrom
lcnr:issue70273

Conversation

@lcnr

@lcnrlcnr commented Mar 22, 2020

Copy link
Copy Markdown
Contributor

extends and blocked on #70223

fixes#70273

r? @eddyb cc @varkor

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 22, 2020
@lcnrlcnr changed the title fix type of const params in associated functions.fix type of const params in assoc fns.Mar 22, 2020
Comment threadsrc/librustc_typeck/collect/type_of.rs Outdated

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.

<S as T<123>>::f::<456>() should also work, if you added a const param to f as well.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

will add a test

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.

I mean you'll need to implement it, it won't work with the current approach.

@lcnrlcnrMar 22, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

for whatever reason adding a const param to f actually prevents the ice. not quite sure why, but this is new behavior so lets add a test for it

The following works on the current nightly.

#![feature(const_generics)]//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crashtraitT<constA:usize>{fnl<constN:usize>() -> usize;fnr<constN:usize>() -> usize;}structS;impl<constN:usize>T<N>forS{fnl<constM:usize>() -> usize{N}fnr<constM:usize>() -> usize{M}}fnmain(){assert_eq!(<SasT<123>>::l::<456>(),123);assert_eq!(<SasT<123>>::r::<456>(),456);}

playground

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.

Oh, oops, it's because both the trait and the method have the exact same number of parameters and the same types. Make one of them a bool instead of usize, then you should see how it thinks the method segment has the trait's parameter (which is wrong).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

jup. Quite surprisingly, using usize and u16 works 🤔
but using bool and usize does not work on nightly rn

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.

Yes, because the integer literals will work with any integer type.

@varkorvarkor added the F-const_generics `#![feature(const_generics)]` label Mar 22, 2020
@lcnr

lcnr commented Mar 22, 2020

Copy link
Copy Markdown
ContributorAuthor

I am going to experiment with using the res of the segment instead of the path.

Closing this for now as I don't know how long this will take.

@lcnrlcnr closed this Mar 22, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 24, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 24, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 24, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-const_generics`#![feature(const_generics)]`S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE when using const generics with associated items

5 participants

@lcnr@eddyb@Centril@varkor@rust-highfive