-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Normalize consts' tys when relating with adt_const_params
#97709
Merged
bors
merged 1 commit into
rust-lang:master
from
compiler-errors:normalize-const-param-ty
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// check-pass | ||
|
||
#![feature(adt_const_params, generic_const_exprs)] | ||
#![allow(incomplete_features)] | ||
|
||
mod lib { | ||
const N_ISLANDS: usize = 4; | ||
const N_BRIDGES: usize = 7; | ||
const BRIDGES: [(usize, usize); 7] = [(0, 1), (0, 1), (0, 2), (0, 3), (0, 3), (1, 2), (2, 3)]; | ||
|
||
pub type Matrix = [[usize; N_ISLANDS]; N_ISLANDS]; | ||
|
||
const EMPTY_MATRIX: Matrix = [[0; N_ISLANDS]; N_ISLANDS]; | ||
|
||
const fn build(mut matrix: Matrix, (to, from): (usize, usize)) -> Matrix { | ||
matrix[to][from] += 1; | ||
matrix[from][to] += 1; | ||
matrix | ||
} | ||
|
||
pub const fn walk(mut matrix: Matrix, from: usize, to: usize) -> Matrix { | ||
matrix[from][to] -= 1; | ||
matrix[to][from] -= 1; | ||
matrix | ||
} | ||
|
||
const fn to_matrix(bridges: [(usize, usize); N_BRIDGES]) -> Matrix { | ||
let matrix = EMPTY_MATRIX; | ||
|
||
let matrix = build(matrix, bridges[0]); | ||
let matrix = build(matrix, bridges[1]); | ||
let matrix = build(matrix, bridges[2]); | ||
let matrix = build(matrix, bridges[3]); | ||
let matrix = build(matrix, bridges[4]); | ||
let matrix = build(matrix, bridges[5]); | ||
let matrix = build(matrix, bridges[6]); | ||
|
||
matrix | ||
} | ||
|
||
const BRIDGE_MATRIX: [[usize; N_ISLANDS]; N_ISLANDS] = to_matrix(BRIDGES); | ||
|
||
pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> { | ||
_p: (), | ||
} | ||
|
||
impl Walk<0, BRIDGE_MATRIX> { | ||
pub const fn new() -> Self { | ||
Self { _p: () } | ||
} | ||
} | ||
|
||
impl<const CURRENT: usize, const REMAINING: Matrix> Walk<CURRENT, REMAINING> { | ||
pub fn proceed_to<const NEXT: usize>( | ||
self, | ||
) -> Walk<NEXT, { walk(REMAINING, CURRENT, NEXT) }> { | ||
Walk { _p: () } | ||
} | ||
} | ||
|
||
pub struct Trophy { | ||
_p: (), | ||
} | ||
|
||
impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> { | ||
pub fn collect_prize(self) -> Trophy { | ||
Trophy { _p: () } | ||
} | ||
} | ||
} | ||
|
||
pub use lib::{Trophy, Walk}; | ||
|
||
fn main() { | ||
// Example, taking the first step | ||
let _ = Walk::new().proceed_to::<1>(); | ||
|
||
// Don't be so eager to collect the trophy | ||
// let trophy = Walk::new() | ||
// .proceed_to::<1>() | ||
// .proceed_to::<0>() | ||
// .collect_prize(); | ||
|
||
// Can't just make a Trophy out of thin air, you must earn it | ||
// let trophy: Trophy = Trophy { _p: () }; | ||
|
||
// Can you collect the Trophy? | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe
normalize_erasing_regions
can panic if normalization fails. Is is guaranteed that this succeeds here (otherwise you might want to usetry_normalize_erasing_regions
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only way it can fail is if there were other errors already. I'd rather address the ICE here if that happens and know about it than silently assume normalization can fail here.