diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2021-02-01 14:29:29 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-01 14:29:29 +0100 |
| commit | 21d0e9b8dc297cd78f51b397c55c033673f8be6e (patch) | |
| tree | 627567086330a9da14eaf0374359c96d1377000d /src/test/ui/const-generics | |
| parent | a7a6f013a20fbdf21d77e8ed16f0d8c7b70a7899 (diff) | |
| parent | 6a03f0350d2c6603eab20ca463d1dd4581c64edf (diff) | |
| download | rust-21d0e9b8dc297cd78f51b397c55c033673f8be6e.tar.gz rust-21d0e9b8dc297cd78f51b397c55c033673f8be6e.zip | |
Rollup merge of #79291 - JulianKnodt:ce_priv, r=petrochenkov
Add error message for private fn Attempts to add a more detailed error when a `const_evaluatable` fn from another scope is used inside of a scope which cannot access it. r? ````@lcnr````
Diffstat (limited to 'src/test/ui/const-generics')
| -rw-r--r-- | src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs | 31 | ||||
| -rw-r--r-- | src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr | 43 |
2 files changed, 74 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs new file mode 100644 index 00000000000..9f457fbd346 --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.rs @@ -0,0 +1,31 @@ +#![crate_type = "lib"] +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +pub struct Const<const U: u8>; + +pub trait Trait { + type AssocTy; + fn assoc_fn() -> Self::AssocTy; +} + +impl<const U: u8> Trait for Const<U> +//~^ WARN private type +//~| WARN this was previously +//~| WARN private type +//~| WARN this was previously + +where + Const<{ my_const_fn(U) }>: , +{ + type AssocTy = Const<{ my_const_fn(U) }>; + //~^ ERROR private type + fn assoc_fn() -> Self::AssocTy { + Const + } +} + +const fn my_const_fn(val: u8) -> u8 { + // body of this function doesn't matter + val +} diff --git a/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr new file mode 100644 index 00000000000..842c22c5c67 --- /dev/null +++ b/src/test/ui/const-generics/const_evaluatable_checked/eval-privacy.stderr @@ -0,0 +1,43 @@ +warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) + --> $DIR/eval-privacy.rs:12:1 + | +LL | / impl<const U: u8> Trait for Const<U> +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_^ + | + = note: `#[warn(private_in_public)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> + +warning: private type `fn(u8) -> u8 {my_const_fn}` in public interface (error E0446) + --> $DIR/eval-privacy.rs:12:1 + | +LL | / impl<const U: u8> Trait for Const<U> +LL | | +LL | | +LL | | +... | +LL | | } +LL | | } + | |_^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> + +error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface + --> $DIR/eval-privacy.rs:21:5 + | +LL | type AssocTy = Const<{ my_const_fn(U) }>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type +... +LL | const fn my_const_fn(val: u8) -> u8 { + | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private + +error: aborting due to previous error; 2 warnings emitted + +For more information about this error, try `rustc --explain E0446`. |
