@@ -18,7 +18,7 @@ use rustc::ty::layout::{
1818 HasDataLayout , HasTyCtxt , LayoutError , LayoutOf , Size , TargetDataLayout , TyLayout ,
1919} ;
2020use rustc:: ty:: subst:: { InternalSubsts , Subst } ;
21- use rustc:: ty:: { self , Instance , ParamEnv , Ty , TyCtxt , TypeFoldable } ;
21+ use rustc:: ty:: { self , ConstKind , Instance , ParamEnv , Ty , TyCtxt , TypeFoldable } ;
2222use rustc_data_structures:: fx:: FxHashMap ;
2323use rustc_hir:: def:: DefKind ;
2424use rustc_hir:: def_id:: DefId ;
@@ -441,8 +441,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
441441 Ok ( op) => Some ( op) ,
442442 Err ( error) => {
443443 let err = error_to_const_error ( & self . ecx , error) ;
444- match self . lint_root ( source_info) {
445- Some ( lint_root) if c. literal . needs_subst ( ) => {
444+ if let Some ( lint_root) = self . lint_root ( source_info) {
445+ let lint_only = match c. literal . val {
446+ // Promoteds must lint and not error as the user didn't ask for them
447+ ConstKind :: Unevaluated ( _, _, Some ( _) ) => true ,
448+ // Out of backwards compatibility we cannot report hard errors in unused
449+ // generic functions using associated constants of the generic parameters.
450+ _ => c. literal . needs_subst ( ) ,
451+ } ;
452+ if lint_only {
446453 // Out of backwards compatibility we cannot report hard errors in unused
447454 // generic functions using associated constants of the generic parameters.
448455 err. report_as_lint (
@@ -451,10 +458,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
451458 lint_root,
452459 Some ( c. span ) ,
453460 ) ;
454- }
455- _ => {
461+ } else {
456462 err. report_as_error ( self . ecx . tcx , "erroneous constant used" ) ;
457463 }
464+ } else {
465+ err. report_as_error ( self . ecx . tcx , "erroneous constant used" ) ;
458466 }
459467 None
460468 }
0 commit comments