Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
913996b
Remove the match on `ErrorKind::Other`
ChrisDenton Dec 8, 2021
c7f80fc
add tests
b-naber Dec 8, 2021
c025a5d
move core/stream/stream/mod.rs to core/stream/stream.rs
ibraheemdev Dec 8, 2021
9f6da95
fix typo in `intrinsics::raw_eq` docs
WaffleLapkin Dec 8, 2021
42f9104
Fix `Vec::reserve_exact` documentation
dalcde Dec 9, 2021
4b0a9c9
Delete Utf8Lossy::from_str
dtolnay Dec 9, 2021
e18518b
Add unstable book entries for parts of asm that are not being stabilized
Amanieu Dec 9, 2021
caed83d
Add reminder to match the error kind once ` DirectoryNotEmpty` is sta…
ChrisDenton Dec 9, 2021
cebd949
Replace iterator-based set construction by *Set::From<[T; N]>
juniorbassani Dec 9, 2021
8a6f54f
Use more accurate wording in `bootstrap.py` logging
jyn514 Dec 9, 2021
ae6f5fb
If --verbose is passed, print a warning in `bootstrap.py` when downlo…
jyn514 Dec 9, 2021
dfcaac5
Don't print bootstrap caching/ensure info unless `-vv` is passed
jyn514 Dec 9, 2021
6840030
Default to `doc-stage = 2` for the tools profile
jyn514 Dec 9, 2021
777c041
Add pierwill to .mailmap
pierwill Dec 10, 2021
305dd69
Fix since attribute for const_linked_list_new feature
not-my-profile Dec 10, 2021
0aa41be
Rollup merge of #91668 - ChrisDenton:bootstrap-clean-error, r=Mark-Si…
matthiaskrgr Dec 10, 2021
d6e9417
Rollup merge of #91678 - b-naber:tests-for-postpone-const-eval, r=jac…
matthiaskrgr Dec 10, 2021
6451de0
Rollup merge of #91679 - ibraheemdev:stream-mod, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
4286ade
Rollup merge of #91681 - WaffleLapkin:patch-3, r=scottmcm
matthiaskrgr Dec 10, 2021
1d36c6a
Rollup merge of #91686 - dalcde:patch-1, r=dtolnay
matthiaskrgr Dec 10, 2021
2784051
Rollup merge of #91697 - dtolnay:lossyfromstr, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
698ea96
Rollup merge of #91706 - Amanieu:asm_unstable_book2, r=joshtriplett
matthiaskrgr Dec 10, 2021
3beeb75
Rollup merge of #91709 - juniorbassani:use-from-array-in-set-examples…
matthiaskrgr Dec 10, 2021
ca9d14b
Rollup merge of #91716 - jyn514:x.py-defaults, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
6768a07
Rollup merge of #91747 - pierwill:patch-1, r=Mark-Simulacrum
matthiaskrgr Dec 10, 2021
637859b
Rollup merge of #91755 - not-my-profile:fix-const_linked_list_new-sin…
matthiaskrgr Dec 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
b-naber committed Dec 8, 2021
commit c7f80fc0727017a8ad45c37747805facbbb68a72
28 changes: 28 additions & 0 deletions src/test/ui/const-generics/issues/issue-79674.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![feature(const_fn_trait_bound, generic_const_exprs)]
#![allow(incomplete_features)]

trait MiniTypeId {
const TYPE_ID: u64;
}

impl<T> MiniTypeId for T {
const TYPE_ID: u64 = 0;
}

enum Lift<const V: bool> {}

trait IsFalse {}
impl IsFalse for Lift<false> {}

const fn is_same_type<T: MiniTypeId, U: MiniTypeId>() -> bool {
T::TYPE_ID == U::TYPE_ID
}

fn requires_distinct<A, B>(_a: A, _b: B) where
A: MiniTypeId, B: MiniTypeId,
Lift<{is_same_type::<A, B>()}>: IsFalse {}

fn main() {
requires_distinct("str", 12);
//~^ ERROR mismatched types
}
12 changes: 12 additions & 0 deletions src/test/ui/const-generics/issues/issue-79674.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/issue-79674.rs:26:5
|
LL | requires_distinct("str", 12);
| ^^^^^^^^^^^^^^^^^ expected `true`, found `false`
|
= note: expected type `true`
found type `false`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
115 changes: 115 additions & 0 deletions src/test/ui/const-generics/issues/issue-83765.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

trait TensorDimension {
const DIM : usize;
const ISSCALAR : bool = Self::DIM == 0;
fn is_scalar(&self) -> bool {Self::ISSCALAR}
}

trait TensorSize : TensorDimension {
fn size(&self) -> [usize;Self::DIM];
fn inbounds(&self,index : [usize;Self::DIM]) -> bool {
index.iter().zip(self.size().iter()).all(|(i,s)| i < s)
}
}


trait Broadcastable: TensorSize + Sized {
type Element;
fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>;
fn lazy_updim<const NEWDIM : usize>(&self, size : [usize;NEWDIM] ) ->
LazyUpdim<Self,{Self::DIM},NEWDIM>
{
assert!(NEWDIM >= Self::DIM,
"Updimmed tensor cannot have fewer indices than the initial one.");
LazyUpdim {size,reference:&self}
}
fn bmap<T,F :Fn(Self::Element) -> T>(&self,foo : F) -> BMap<T,Self,F,{Self::DIM}>{
BMap {reference:self,closure : foo}
}
}


struct LazyUpdim<'a,T : Broadcastable,const OLDDIM : usize, const DIM : usize> {
size : [usize;DIM],
reference : &'a T
}

impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,{T::DIM},DIM> {
const DIM : usize = DIM;
}

impl<'a,T : Broadcastable,const DIM : usize> TensorSize for LazyUpdim<'a,T,{T::DIM},DIM> {
fn size(&self) -> [usize;DIM] {self.size}
//~^ ERROR method not compatible with trait
}

impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM>
{
type Element = T::Element;
fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
//~^ ERROR method not compatible with trait
assert!(DIM >= T::DIM);
if !self.inbounds(index) {return None}
//~^ ERROR unconstrained generic constant
//~| ERROR mismatched types
let size = self.size();
//~^ ERROR unconstrained generic constant
let newindex : [usize;T::DIM] = Default::default();
//~^ ERROR the trait bound `[usize; _]: Default` is not satisfied
self.reference.bget(newindex)
}
}

struct BMap<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , const DIM: usize> {
reference : &'a T,
closure : F
}

impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R,
const DIM: usize> TensorDimension for BMap<'a,R,T,F,DIM> {

const DIM : usize = DIM;
}
impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
const DIM: usize> TensorSize for BMap<'a,R,T,F,DIM> {

fn size(&self) -> [usize;DIM] {self.reference.size()}
//~^ ERROR unconstrained generic constant
//~| ERROR mismatched types
//~| ERROR method not compatible with trait
}

impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
const DIM: usize> Broadcastable for BMap<'a,R,T,F,DIM> {

type Element = R;
fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
//~^ ERROR method not compatible with trait
self.reference.bget(index).map(&self.closure)
//~^ ERROR unconstrained generic constant
//~| ERROR mismatched types
}
}

impl<T> TensorDimension for Vec<T> {
const DIM : usize = 1;
}
impl<T> TensorSize for Vec<T> {
fn size(&self) -> [usize;1] {[self.len()]}
}
impl<T: Clone> Broadcastable for Vec<T> {
type Element = T;
fn bget(& self,index : [usize;1]) -> Option<T> {
self.get(index[0]).cloned()
}
}

fn main() {
let v = vec![1,2,3];
let bv = v.lazy_updim([3,4]);
let bbv = bv.bmap(|x| x*x);

println!("The size of v is {:?}",bbv.bget([0,2]).expect("Out of bounds."));
}
130 changes: 130 additions & 0 deletions src/test/ui/const-generics/issues/issue-83765.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
error[E0308]: method not compatible with trait
--> $DIR/issue-83765.rs:44:5
|
LL | fn size(&self) -> [usize;DIM] {self.size}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected type `Self::DIM`
found type `DIM`

error[E0308]: method not compatible with trait
--> $DIR/issue-83765.rs:51:5
|
LL | fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected type `Self::DIM`
found type `DIM`

error[E0308]: method not compatible with trait
--> $DIR/issue-83765.rs:78:5
|
LL | fn size(&self) -> [usize;DIM] {self.reference.size()}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected type `Self::DIM`
found type `DIM`

error[E0308]: method not compatible with trait
--> $DIR/issue-83765.rs:88:5
|
LL | fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected type `Self::DIM`
found type `DIM`

error: unconstrained generic constant
--> $DIR/issue-83765.rs:54:18
|
LL | if !self.inbounds(index) {return None}
| ^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
note: required by a bound in `TensorSize::inbounds`
--> $DIR/issue-83765.rs:12:38
|
LL | fn inbounds(&self,index : [usize;Self::DIM]) -> bool {
| ^^^^^^^^^ required by this bound in `TensorSize::inbounds`

error[E0308]: mismatched types
--> $DIR/issue-83765.rs:54:27
|
LL | if !self.inbounds(index) {return None}
| ^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected type `Self::DIM`
found type `DIM`

error: unconstrained generic constant
--> $DIR/issue-83765.rs:57:25
|
LL | let size = self.size();
| ^^^^
|
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
note: required by a bound in `TensorSize::size`
--> $DIR/issue-83765.rs:11:30
|
LL | fn size(&self) -> [usize;Self::DIM];
| ^^^^^^^^^ required by this bound in `TensorSize::size`

error[E0277]: the trait bound `[usize; _]: Default` is not satisfied
--> $DIR/issue-83765.rs:59:41
|
LL | let newindex : [usize;T::DIM] = Default::default();
| ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[usize; _]`
|
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
LL | impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> where [usize; _]: Default
| +++++++++++++++++++++++++

error: unconstrained generic constant
--> $DIR/issue-83765.rs:78:51
|
LL | fn size(&self) -> [usize;DIM] {self.reference.size()}
| ^^^^
|
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
note: required by a bound in `TensorSize::size`
--> $DIR/issue-83765.rs:11:30
|
LL | fn size(&self) -> [usize;Self::DIM];
| ^^^^^^^^^ required by this bound in `TensorSize::size`

error[E0308]: mismatched types
--> $DIR/issue-83765.rs:78:36
|
LL | fn size(&self) -> [usize;DIM] {self.reference.size()}
| ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM`
|
= note: expected type `DIM`
found type `Self::DIM`

error: unconstrained generic constant
--> $DIR/issue-83765.rs:90:24
|
LL | self.reference.bget(index).map(&self.closure)
| ^^^^
|
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
note: required by a bound in `Broadcastable::bget`
--> $DIR/issue-83765.rs:20:33
|
LL | fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>;
| ^^^^^^^^^ required by this bound in `Broadcastable::bget`

error[E0308]: mismatched types
--> $DIR/issue-83765.rs:90:29
|
LL | self.reference.bget(index).map(&self.closure)
| ^^^^^ expected `Self::DIM`, found `DIM`
|
= note: expected type `Self::DIM`
found type `DIM`

error: aborting due to 12 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
20 changes: 20 additions & 0 deletions src/test/ui/const-generics/issues/issue-86033.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// check-pass

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

pub trait IsTrue<const T: bool> {}
impl IsTrue<true> for () {}

pub trait IsZST {}

impl<T> IsZST for T
where
(): IsTrue<{ std::mem::size_of::<T>() == 0 }>
{}

fn _func() -> impl IsZST {
|| {}
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/const-generics/issues/issue-88468.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// check-pass

#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

pub struct Assert<const COND: bool>();
pub trait IsTrue {}
impl IsTrue for Assert<true> {}

pub trait IsNotZST {}
impl<T> IsNotZST for T where Assert<{ std::mem::size_of::<T>() > 0 }>: IsTrue {}

fn main() {}
32 changes: 32 additions & 0 deletions src/test/ui/const-generics/issues/issue-90318.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![feature(const_type_id)]
#![feature(generic_const_exprs)]
#![feature(core_intrinsics)]
#![allow(incomplete_features)]

use std::any::TypeId;

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

fn consume<T: 'static>(_val: T)
where
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
//~^ ERROR: overly complex generic constant
//~| ERROR: calls in constants are limited to constant functions
{
}

fn test<T: 'static>()
where
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
//~^ ERROR: overly complex generic constant
//~| ERROR: calls in constants are limited to constant functions
{
}

fn main() {
let a = ();
consume(0i32);
consume(a);
}
37 changes: 37 additions & 0 deletions src/test/ui/const-generics/issues/issue-90318.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error: overly complex generic constant
--> $DIR/issue-90318.rs:14:8
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
| |
| borrowing is not supported in generic constants
|
= help: consider moving this anonymous constant into a `const` function
= note: this operation may be supported in the future

error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-90318.rs:14:10
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: overly complex generic constant
--> $DIR/issue-90318.rs:22:8
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
| |
| borrowing is not supported in generic constants
|
= help: consider moving this anonymous constant into a `const` function
= note: this operation may be supported in the future

error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
--> $DIR/issue-90318.rs:22:10
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0015`.