Skip to content

do not promote comparing function pointers#54702

Merged
bors merged 2 commits into
rust-lang:masterfrom
RalfJung:fn-ptr-promotion
Oct 3, 2018
Merged

do not promote comparing function pointers#54702
bors merged 2 commits into
rust-lang:masterfrom
RalfJung:fn-ptr-promotion

Conversation

@RalfJung

Copy link
Copy Markdown
Member

This could break existing code that relied on fn ptr comparison getting promoted to 'static lifetime.

Fixes #54696

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @davidtwco

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2018
&(main as fn() == main as fn());
// Also check nested case
&(&(main as fn()) == &(main as fn()));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does this test verify lack of promotion? Shouldn't we instead have a compile-fail 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.

The promotion causes crashes, because function pointer equality can't be done in constants

@RalfJung RalfJung Sep 30, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can also add a compile-fail test if you want -- though there is no fundamental reason we shouldn't want to promote this in the future, so that test wouldn't be "normative". OTOH, making this code run (and not emit a trap) is "normative".

@arielb1

arielb1 commented Sep 30, 2018

Copy link
Copy Markdown
Contributor

This could break existing code that relied on fn ptr comparison getting promoted to 'static lifetime.

That code is broken anyway

@davidtwco

Copy link
Copy Markdown
Member

r? @arielb1

@rust-highfive rust-highfive assigned arielb1 and unassigned davidtwco Sep 30, 2018
@RalfJung

Copy link
Copy Markdown
Member Author

That code is broken anyway

Fair enough.

@arielb1

arielb1 commented Sep 30, 2018

Copy link
Copy Markdown
Contributor

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned arielb1 Sep 30, 2018
@oli-obk

oli-obk commented Oct 1, 2018

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Oct 1, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 4cbfc93 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2018
@oli-obk oli-obk assigned oli-obk and unassigned eddyb Oct 1, 2018
@dtolnay

dtolnay commented Oct 1, 2018

Copy link
Copy Markdown
Member

@RalfJung does this also fix #54685 or is that a different issue? That one is also comparing function pointers but the discussion is focused on the LLVM side.

@RalfJung

RalfJung commented Oct 1, 2018

Copy link
Copy Markdown
Member Author

@dtolnay That's a different issue, but thanks for pointing me to it.

emilyalbini added a commit to emilyalbini/rust that referenced this pull request Oct 2, 2018
do not promote comparing function pointers

This *could* break existing code that relied on fn ptr comparison getting promoted to `'static` lifetime.

Fixes rust-lang#54696
emilyalbini added a commit to emilyalbini/rust that referenced this pull request Oct 2, 2018
do not promote comparing function pointers

This *could* break existing code that relied on fn ptr comparison getting promoted to `'static` lifetime.

Fixes rust-lang#54696
bors added a commit that referenced this pull request Oct 2, 2018
Rollup of 10 pull requests

Successful merges:

 - #54269 (#53840: Consolidate pattern check errors)
 - #54458 (Allow both explicit and elided lifetimes in the same impl header)
 - #54603 (Add `crate::` to trait suggestions in Rust 2018.)
 - #54648 (Update Cargo's submodule)
 - #54680 (make run-pass tests with empty main just compile-pass tests)
 - #54687 (Use impl_header_lifetime_elision in libcore)
 - #54699 (Re-export `getopts` so custom drivers can reference it.)
 - #54702 (do not promote comparing function pointers)
 - #54728 (Renumber `proc_macro` tracking issues)
 - #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn)

Failed merges:

r? @ghost
@bors bors merged commit 4cbfc93 into rust-lang:master Oct 3, 2018
@RalfJung RalfJung deleted the fn-ptr-promotion branch November 9, 2018 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants