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

generic_const_expr: doc test does not compile while similar lib test compiles fine #94321

Open
tspiteri opened this issue Feb 24, 2022 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tspiteri
Copy link
Contributor

tspiteri commented Feb 24, 2022

Update(fmease, 2024-01-24): #94321 (comment):

This issue goes away if the doc tests have the #![feature(generic_const_exprs)] flag enabled.

I realized thanks to #94287 (comment); maybe a better diagnostic could help here.



The doc test for foo and the test tests::test contain the same code (the only difference is the use statement which has to be different). The lib test passes but the doc test fails to compile.

#![feature(generic_const_exprs)]

pub struct If<const CONDITION: bool>;
pub trait True {}
impl True for If<true> {}

pub struct FixedU64<const FRAC: u32>;

/// ```rust
/// use fcg5::{foo, FixedU64};
/// foo(FixedU64::<4>);
/// ```
pub fn foo<const FRAC: u32>(_fixed: FixedU64<FRAC>)
where
    If<{ FRAC <= 64 }>: True,
{
}

#[cfg(test)]
mod tests {
    #[test]
    fn test() {
        use crate::{foo, FixedU64};
        foo(FixedU64::<4>);
    }
}

cargo +nightly test:

   Compiling fcg5 v0.1.0 (/home/trevor/try/fcg5)
...
    Finished test [unoptimized + debuginfo] target(s) in 0.44s
     Running unittests src/lib.rs (target/debug/deps/fcg5-877f755fe1bd39e7)

running 1 test
test tests::test ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests fcg5
...

running 1 test
test src/lib.rs - foo (line 9) ... FAILED

failures:

---- src/lib.rs - foo (line 9) stdout ----
error[E0277]: the trait bound `If<{_: bool}>: True` is not satisfied
  --> src/lib.rs:11:1
   |
5  | foo(FixedU64::<4>);
   | ^^^ the trait `True` is not implemented for `If<{_: bool}>`
   |
   = help: the following implementations were found:
             <If<true> as True>
note: required by a bound in `foo`
  --> /home/trevor/try/fcg5/src/lib.rs:15:25
   |
15 |     If<{ FRAC <= 64 }>: True,
   |                         ^^^^ required by this bound in `foo`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
Couldn't compile the test.

failures:
    src/lib.rs - foo (line 9)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

error: test failed, to rerun pass '--doc'

Meta

rustc +nightly --version --verbose:

rustc 1.61.0-nightly (532d3cda9 2022-02-23)
binary: rustc
commit-hash: 532d3cda90b8a729cd982548649d32803d265052
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
@tspiteri tspiteri added the C-bug Category: This is a bug. label Feb 24, 2022
@tspiteri
Copy link
Contributor Author

This issue goes away if the doc tests have the #![feature(generic_const_exprs)] flag enabled.

I realized thanks to #94287 (comment); maybe a better diagnostic could help here.

@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-generic_const_exprs `#![feature(generic_const_exprs)]` A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. and removed needs-triage-legacy C-bug Category: This is a bug. labels Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-generic_const_exprs `#![feature(generic_const_exprs)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants