@@ -2306,22 +2306,15 @@ impl Function {
2306
2306
self ,
2307
2307
db : & dyn HirDatabase ,
2308
2308
span_formatter : impl Fn ( FileId , TextRange ) -> String ,
2309
- ) -> String {
2309
+ ) -> Result < String , ConstEvalError > {
2310
2310
let krate = HasModule :: krate ( & self . id , db. upcast ( ) ) ;
2311
2311
let edition = db. crate_graph ( ) [ krate] . edition ;
2312
- let body = match db. monomorphized_mir_body (
2312
+ let body = db. monomorphized_mir_body (
2313
2313
self . id . into ( ) ,
2314
2314
Substitution :: empty ( Interner ) ,
2315
2315
db. trait_environment ( self . id . into ( ) ) ,
2316
- ) {
2317
- Ok ( body) => body,
2318
- Err ( e) => {
2319
- let mut r = String :: new ( ) ;
2320
- _ = e. pretty_print ( & mut r, db, & span_formatter, edition) ;
2321
- return r;
2322
- }
2323
- } ;
2324
- let ( result, output) = interpret_mir ( db, body, false , None ) ;
2316
+ ) ?;
2317
+ let ( result, output) = interpret_mir ( db, body, false , None ) ?;
2325
2318
let mut text = match result {
2326
2319
Ok ( _) => "pass" . to_owned ( ) ,
2327
2320
Err ( e) => {
@@ -2340,7 +2333,7 @@ impl Function {
2340
2333
text += "\n --------- stderr ---------\n " ;
2341
2334
text += & stderr;
2342
2335
}
2343
- text
2336
+ Ok ( text)
2344
2337
}
2345
2338
}
2346
2339
@@ -2563,9 +2556,9 @@ impl Const {
2563
2556
/// Evaluate the constant and return the result as a string.
2564
2557
///
2565
2558
/// This function is intended for IDE assistance, different from [`Const::render_eval`].
2566
- pub fn eval ( self , db : & dyn HirDatabase , edition : Edition ) -> Result < String , ConstEvalError > {
2559
+ pub fn eval ( self , db : & dyn HirDatabase ) -> Result < String , ConstEvalError > {
2567
2560
let c = db. const_eval ( self . id . into ( ) , Substitution :: empty ( Interner ) , None ) ?;
2568
- Ok ( format ! ( "{}" , c. display( db, edition) ) )
2561
+ Ok ( format ! ( "{}" , c. display( db, self . krate ( db ) . edition( db ) ) ) )
2569
2562
}
2570
2563
2571
2564
/// Evaluate the constant and return the result as a string, with more detailed information.
@@ -2640,7 +2633,15 @@ impl Static {
2640
2633
Type :: from_value_def ( db, self . id )
2641
2634
}
2642
2635
2643
- /// Evaluate the constant and return the result as a string, with more detailed information.
2636
+ /// Evaluate the static and return the result as a string.
2637
+ ///
2638
+ /// This function is intended for IDE assistance, different from [`Static::render_eval`].
2639
+ pub fn eval ( self , db : & dyn HirDatabase ) -> Result < String , ConstEvalError > {
2640
+ let c = db. const_eval ( self . id . into ( ) , Substitution :: empty ( Interner ) , None ) ?;
2641
+ Ok ( format ! ( "{}" , c. display( db, self . krate( db) . edition( db) ) ) )
2642
+ }
2643
+
2644
+ /// Evaluate the static and return the result as a string, with more detailed information.
2644
2645
///
2645
2646
/// This function is intended for user-facing display.
2646
2647
pub fn render_eval (
0 commit comments