@@ -4,16 +4,15 @@ use hir::{ConstContext, LangItem};
4
4
use rustc_errors:: codes:: * ;
5
5
use rustc_errors:: { Applicability , Diag , MultiSpan } ;
6
6
use rustc_hir as hir;
7
- use rustc_hir:: def:: DefKind ;
8
7
use rustc_hir:: def_id:: DefId ;
9
8
use rustc_infer:: infer:: TyCtxtInferExt ;
10
9
use rustc_infer:: traits:: { ImplSource , Obligation , ObligationCause } ;
11
10
use rustc_middle:: mir:: CallSource ;
12
11
use rustc_middle:: span_bug;
13
12
use rustc_middle:: ty:: print:: { PrintTraitRefExt as _, with_no_trimmed_paths} ;
14
13
use rustc_middle:: ty:: {
15
- self , Closure , FnDef , FnPtr , GenericArgKind , GenericArgsRef , Param , TraitRef , Ty ,
16
- suggest_constraining_type_param,
14
+ self , AssocItemContainer , Closure , FnDef , FnPtr , GenericArgKind , GenericArgsRef , Param ,
15
+ TraitRef , Ty , suggest_constraining_type_param,
17
16
} ;
18
17
use rustc_session:: parse:: add_feature_diagnostics;
19
18
use rustc_span:: { BytePos , Pos , Span , Symbol , sym} ;
@@ -212,7 +211,6 @@ fn build_error_for_const_call<'tcx>(
212
211
213
212
debug ! ( ?call_kind) ;
214
213
215
- let mut note = true ;
216
214
let mut err = match call_kind {
217
215
CallKind :: Normal { desugaring : Some ( ( kind, self_ty) ) , .. } => {
218
216
macro_rules! error {
@@ -366,16 +364,9 @@ fn build_error_for_const_call<'tcx>(
366
364
kind : ccx. const_kind ( ) ,
367
365
non_or_conditionally,
368
366
} ) ;
369
- let context_span = ccx. tcx . def_span ( ccx. def_id ( ) ) ;
370
- err. span_label ( context_span, format ! (
371
- "calls in {}s are limited to constant functions, tuple structs and tuple variants" ,
372
- ccx. const_kind( ) ,
373
- ) ) ;
374
- note = false ;
375
- let def_kind = ccx. tcx . def_kind ( callee) ;
376
- if let DefKind :: AssocTy | DefKind :: AssocConst | DefKind :: AssocFn = def_kind {
377
- let parent = ccx. tcx . parent ( callee) ;
378
- if let DefKind :: Trait = ccx. tcx . def_kind ( parent)
367
+ if let Some ( item) = ccx. tcx . opt_associated_item ( callee) {
368
+ if let AssocItemContainer :: Trait = item. container
369
+ && let parent = item. container_id ( ccx. tcx )
379
370
&& !ccx. tcx . is_const_trait ( parent)
380
371
{
381
372
let assoc_span = ccx. tcx . def_span ( callee) ;
@@ -410,7 +401,7 @@ fn build_error_for_const_call<'tcx>(
410
401
trait_span. shrink_to_lo ( ) ,
411
402
format ! ( "consider making trait `{trait_name}` const" ) ,
412
403
format ! ( "#[const_trait]\n {indentation}" ) ,
413
- Applicability :: MachineApplicable ,
404
+ Applicability :: MaybeIncorrect ,
414
405
) ;
415
406
} else if !ccx. tcx . sess . is_nightly_build ( ) {
416
407
err. help ( "const traits are not yet supported on stable Rust" ) ;
@@ -427,12 +418,10 @@ fn build_error_for_const_call<'tcx>(
427
418
}
428
419
} ;
429
420
430
- if note {
431
- err. note ( format ! (
432
- "calls in {}s are limited to constant functions, tuple structs and tuple variants" ,
433
- ccx. const_kind( ) ,
434
- ) ) ;
435
- }
421
+ err. note ( format ! (
422
+ "calls in {}s are limited to constant functions, tuple structs and tuple variants" ,
423
+ ccx. const_kind( ) ,
424
+ ) ) ;
436
425
437
426
err
438
427
}
0 commit comments