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.
Avoid stack overflowing when printing unevaluated const
Fixes rust-lang#68104 When printing the DefPath for an unevaluated const, we may end up trying to print the same const again. To avoid infinite recursion, we use the 'verbose' format when we try to re-entrantly print a const. This ensures that the pretty-printing process will always terminate.
- Loading branch information
Showing
3 changed files
with
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![feature(const_generics)] | ||
|
||
pub struct Num<const N: usize>; | ||
|
||
// Braces around const expression causes crash | ||
impl Num<{5}> { | ||
pub fn five(&self) { | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/const-generics/issue-68104-print-stack-overflow.rs
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 @@ | ||
// aux-build:impl-const.rs | ||
// run-pass | ||
|
||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
|
||
extern crate impl_const; | ||
|
||
use impl_const::*; | ||
|
||
pub fn main() { | ||
let n = Num::<5>; | ||
n.five(); | ||
} |