Skip to content

Methods of const traits are const#135541

Merged
bors merged 1 commit into
rust-lang:masterfrom
oli-obk:push-lqlmstussztp
Jan 16, 2025
Merged

Methods of const traits are const#135541
bors merged 1 commit into
rust-lang:masterfrom
oli-obk:push-lqlmstussztp

Conversation

@oli-obk

@oli-obk oli-obk commented Jan 15, 2025

Copy link
Copy Markdown
Contributor

Just a small FIXME that gets resolved.

I think the constness query should not cover all const callable things

@rustbot

rustbot commented Jan 15, 2025

Copy link
Copy Markdown
Collaborator

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 15, 2025
@rustbot

rustbot commented Jan 15, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 15, 2025
hir::Constness::NotConst
}
}
_ => hir::Constness::NotConst,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This catch all is a bit sad, but since a parent could be anything that a fn is in, it could be a module, another fn, anything really.

Imran-imtiaz48

This comment was marked as spam.

@compiler-errors compiler-errors 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.

r=me

@@ -6,12 +6,16 @@ use rustc_middle::ty::TyCtxt;

fn parent_impl_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {

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 u rename this to parent_impl_or_trait_constness?

@oli-obk

oli-obk commented Jan 15, 2025

Copy link
Copy Markdown
Contributor Author

@bors r=compiler-errors

@bors

bors commented Jan 15, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit a61cd86 has been approved by compiler-errors

It is now in the queue for this repository.

@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 Jan 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2025
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#135497 (fix typo in typenames of pin documentation)
 - rust-lang#135522 (add incremental test for issue 135514)
 - rust-lang#135523 (const traits: remove some known-bug that do not seem to make sense)
 - rust-lang#135535 (Add GUI test for rust-lang#135499)
 - rust-lang#135541 (Methods of const traits are const)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2ea07de into rust-lang:master Jan 16, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 16, 2025
Rollup merge of rust-lang#135541 - oli-obk:push-lqlmstussztp, r=compiler-errors

Methods of const traits are const

Just a small FIXME that gets resolved.

I think the `constness` query should not cover all const callable things
@rustbot rustbot added this to the 1.86.0 milestone Jan 16, 2025
@matthiaskrgr

Copy link
Copy Markdown
Member

Uuh, I'm seeing a bunch of new false positives for the clippy::missing-const-for-fn lint popping up, presumably due to this change.

For example

//@ run-pass
use std::ops::Add;

fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
    a + b
}

fn main() {
    println!("a + b is {}", f::<f32>(100f32, 200f32));
}

now lints

warning: this could be a `const fn`
 --> ./tests/ui/issues/issue-22258.rs:4:1
  |
4 | / fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
5 | |     a + b
6 | | }
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
  = note: requested on the command line with `-W clippy::missing-const-for-fn`
help: make the function `const`
  |
4 | const fn f<T: Add>(a: T, b: T) -> <T as Add>::Output {
  | +++++

which is not correct

@oli-obk oli-obk deleted the push-lqlmstussztp branch January 16, 2025 17:39
@oli-obk

oli-obk commented Jan 16, 2025

Copy link
Copy Markdown
Contributor Author

yes, the clippy lint needs to look at const stability of traits. The add trait specifically is unstably const

github-actions Bot pushed a commit to tautschnig/verify-rust-std that referenced this pull request Mar 11, 2025
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#135497 (fix typo in typenames of pin documentation)
 - rust-lang#135522 (add incremental test for issue 135514)
 - rust-lang#135523 (const traits: remove some known-bug that do not seem to make sense)
 - rust-lang#135535 (Add GUI test for rust-lang#135499)
 - rust-lang#135541 (Methods of const traits are const)

r? `@ghost`
`@rustbot` modify labels: rollup
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants