Skip to content

rustc_args_required_const should mark its const arguments as const #61180

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

Closed
lu-zero opened this issue May 25, 2019 · 4 comments
Closed

rustc_args_required_const should mark its const arguments as const #61180

lu-zero opened this issue May 25, 2019 · 4 comments
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@lu-zero
Copy link
Contributor

lu-zero commented May 25, 2019

calling a rustc_args_required_const-marked function from a rustc_args_required_const-marked function does not work as intended.

here the playground

#![feature(rustc_attrs)]

trait T {
    #[rustc_args_required_const(1)]
    fn t(self, b: i32);
}

#[inline]
#[rustc_args_required_const(1)]
const fn ex_t(a: u8, b: i32) {
    let _ = a as i32 + b;
}

#[inline]
#[rustc_args_required_const(1)]
fn ex_t2(a: u8, b: i32) {
    ex_t(a, b);
}

impl T for u8 {
    #[rustc_args_required_const(1)]
    fn t(self, b: i32) {
        // println!("{}", b);
        ex_t(self, b);
    }
}

fn main() {
    let a = 42u8;
    
    a.t(42);
}
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 25, 2019
@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label May 26, 2019
@gnzlbg
Copy link
Contributor

gnzlbg commented May 28, 2019

calling a rustc_args_required_const-marked function from a rustc_args_required_const-marked function does not work as intended.

That is not intended to work, so I would close this issue.

@gnzlbg
Copy link
Contributor

gnzlbg commented May 28, 2019

#[rustc_args_required_const(N)] just errors if the N argument is not const. That's it. It is not any sort of magical type-level consts in argument position kind of thing.

You can turn a run-time value into a compile-time constant by, e.g., matching on it, e.g., using match like this: match N { 0 => 0, 1 => 1, ... , _ => 255, }.

@oli-obk
Copy link
Contributor

oli-obk commented May 28, 2019

Some discussion on zulip on this: https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/rustc_args_required_const.20in.20traits

TLDR: I don't think we should add any more features to rustc_args_required_const. We should either go with const generics or have an actual RFC that figures out how to have const generics syntactic sugar in argument position

@Mark-Simulacrum
Copy link
Member

Closing as per the above comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants