forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#81544 - JulianKnodt:sat_where, r=lcnr
Add better diagnostic for unbounded Abst. Const ~~In the case where a generic abst. const requires a trivial where bound: `where TypeWithConst<const_fn(N)>: ,`, instead of requiring a where bound, just check that only consts are being substituted in to skip over where check.~~ ~~This is pretty sketchy, but I think it works. Presumably, if there is checking for type bounds added later, it can first check nested requirements, and see if they're satisfied by the current `ParamEnv`.~~ Changed the diagnostic to add a better example, which is more practical than what was previously proposed. r? ``@lcnr``
- Loading branch information
Showing
7 changed files
with
93 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![crate_type = "lib"] | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features)] | ||
|
||
const fn complex_maths<T>(n : usize) -> usize { | ||
2 * n + 1 | ||
} | ||
|
||
struct Example<T, const N: usize> { | ||
a: [f32; N], | ||
b: [f32; complex_maths::<T>(N)], | ||
//~^ ERROR unconstrained | ||
c: T, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: unconstrained generic constant | ||
--> $DIR/needs_where_clause.rs:11:6 | ||
| | ||
LL | b: [f32; complex_maths::<T>(N)], | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: try adding a `where` bound using this expression: where [u8; complex_maths::<T>(N)]: Sized | ||
--> $DIR/needs_where_clause.rs:11:12 | ||
| | ||
LL | b: [f32; complex_maths::<T>(N)], | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![feature(const_generics, const_evaluatable_checked)] | ||
#![allow(incomplete_features, unused)] | ||
|
||
const fn complex_maths(n : usize) -> usize { | ||
2 * n + 1 | ||
} | ||
|
||
pub struct Example<const N: usize> { | ||
a: [f32; N], | ||
b: [f32; complex_maths(N)], | ||
//~^ ERROR unconstrained generic | ||
} | ||
|
||
impl<const N: usize> Example<N> { | ||
pub fn new() -> Self { | ||
Self { | ||
a: [0.; N], | ||
b: [0.; complex_maths(N)], | ||
} | ||
} | ||
} | ||
|
||
impl Example<2> { | ||
pub fn sum(&self) -> f32 { | ||
self.a.iter().sum::<f32>() + self.b.iter().sum::<f32>() | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: unconstrained generic constant | ||
--> $DIR/no_where_clause.rs:10:6 | ||
| | ||
LL | b: [f32; complex_maths(N)], | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: try adding a `where` bound using this expression: where [u8; complex_maths(N)]: Sized | ||
--> $DIR/no_where_clause.rs:10:12 | ||
| | ||
LL | b: [f32; complex_maths(N)], | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|