@@ -8,6 +8,7 @@ use rustc_hir as hir;
8
8
use rustc_hir:: def_id:: DefId ;
9
9
use rustc_infer:: infer:: TyCtxtInferExt ;
10
10
use rustc_infer:: traits:: { ImplSource , Obligation , ObligationCause } ;
11
+ use rustc_middle:: middle:: stability;
11
12
use rustc_middle:: mir:: CallSource ;
12
13
use rustc_middle:: span_bug;
13
14
use rustc_middle:: ty:: print:: { PrintTraitRefExt as _, with_no_trimmed_paths} ;
@@ -305,38 +306,37 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
305
306
306
307
/// A call to an `#[unstable]` const fn or `#[rustc_const_unstable]` function.
307
308
///
308
- /// Contains the names of the features that would allow the use of this function.
309
+ /// Contains the names of the features that would allow the use of this function,
310
+ /// as well as an optional reason and github issue link for diagnostics.
309
311
#[ derive( Debug ) ]
310
312
pub ( crate ) struct FnCallUnstable {
311
313
pub def_id : DefId ,
312
- pub features : SmallVec < [ Symbol ; 1 ] > ,
314
+ pub features : SmallVec < [ stability :: EvalDenial ; 1 ] > ,
313
315
pub safe_to_expose_on_stable : bool ,
314
316
}
315
317
316
318
impl < ' tcx > NonConstOp < ' tcx > for FnCallUnstable {
317
319
fn status_in_item ( & self , _ccx : & ConstCx < ' _ , ' tcx > ) -> Status {
318
320
Status :: Unstable {
319
- gates : self . features . clone ( ) ,
321
+ gates : self . features . iter ( ) . map ( |d| d . feature ) . collect ( ) ,
320
322
safe_to_expose_on_stable : self . safe_to_expose_on_stable ,
321
323
is_function_call : true ,
322
324
}
323
325
}
324
326
325
327
fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> Diag < ' tcx > {
326
- let mut err = ccx. dcx ( ) . create_err ( errors:: UnstableConstFn {
328
+ let ( features, info) = stability:: unstable_notes ( & self . features ) ;
329
+ // Only suggest adding `#![feature]` on nightly.
330
+ let nightly_subdiags =
331
+ stability:: unstable_nightly_subdiags ( & ccx. tcx . sess , & self . features , None ) ;
332
+
333
+ ccx. dcx ( ) . create_err ( errors:: UnstableConstFn {
327
334
span,
328
335
def_path : ccx. tcx . def_path_str ( self . def_id ) ,
329
- } ) ;
330
- // FIXME: make this translatable
331
- #[ allow( rustc:: untranslatable_diagnostic) ]
332
- if ccx. tcx . sess . is_nightly_build ( ) {
333
- err. help ( format ! (
334
- "add `#![feature({})]` to the crate attributes to enable" ,
335
- self . features. iter( ) . map( Symbol :: as_str) . intersperse( ", " ) . collect:: <String >( ) ,
336
- ) ) ;
337
- }
338
-
339
- err
336
+ features,
337
+ info,
338
+ nightly_subdiags,
339
+ } )
340
340
}
341
341
}
342
342
@@ -356,18 +356,18 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicNonConst {
356
356
}
357
357
}
358
358
359
- /// A call to an intrinsic that is just not const-callable at all .
359
+ /// A call to an intrinsic that is const-unstable .
360
360
#[ derive( Debug ) ]
361
361
pub ( crate ) struct IntrinsicUnstable {
362
362
pub name : Symbol ,
363
- pub features : SmallVec < [ Symbol ; 1 ] > ,
363
+ pub features : SmallVec < [ stability :: EvalDenial ; 1 ] > ,
364
364
pub const_stable_indirect : bool ,
365
365
}
366
366
367
367
impl < ' tcx > NonConstOp < ' tcx > for IntrinsicUnstable {
368
368
fn status_in_item ( & self , _ccx : & ConstCx < ' _ , ' tcx > ) -> Status {
369
369
Status :: Unstable {
370
- gates : self . features . clone ( ) ,
370
+ gates : self . features . iter ( ) . map ( |d| d . feature ) . collect ( ) ,
371
371
safe_to_expose_on_stable : self . const_stable_indirect ,
372
372
// We do *not* want to suggest to mark the intrinsic as `const_stable_indirect`,
373
373
// that's not a trivial change!
@@ -376,10 +376,17 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
376
376
}
377
377
378
378
fn build_error ( & self , ccx : & ConstCx < ' _ , ' tcx > , span : Span ) -> Diag < ' tcx > {
379
+ let ( features, info) = stability:: unstable_notes ( & self . features ) ;
380
+ // Only suggest adding `#![feature]` on nightly.
381
+ let nightly_subdiags =
382
+ stability:: unstable_nightly_subdiags ( & ccx. tcx . sess , & self . features , None ) ;
383
+
379
384
ccx. dcx ( ) . create_err ( errors:: UnstableIntrinsic {
380
385
span,
381
386
name : self . name ,
382
- feature : self . features . iter ( ) . map ( Symbol :: as_str) . intersperse ( ", " ) . collect ( ) ,
387
+ features,
388
+ info,
389
+ nightly_subdiags,
383
390
} )
384
391
}
385
392
}
0 commit comments