@@ -12,6 +12,7 @@ use rustc_hir_analysis::autoderef::{self, Autoderef};
1212use rustc_infer:: infer:: canonical:: { Canonical , OriginalQueryValues , QueryResponse } ;
1313use rustc_infer:: infer:: { BoundRegionConversionTime , DefineOpaqueTypes , InferOk , TyCtxtInferExt } ;
1414use rustc_infer:: traits:: { ObligationCauseCode , PredicateObligation , query} ;
15+ use rustc_lint:: builtin:: TRAIT_METHOD_ON_COERCED_NEVER_TYPE ;
1516use rustc_macros:: Diagnostic ;
1617use rustc_middle:: middle:: stability;
1718use rustc_middle:: ty:: elaborate:: supertrait_def_ids;
@@ -394,6 +395,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394395 #[ diag( "type annotations needed" ) ]
395396 struct MissingTypeAnnot ;
396397
398+ #[ derive( Diagnostic ) ]
399+ #[ diag( "trait method call on a coerced never type" ) ]
400+ #[ help( "consider providing a type annotation" ) ]
401+ struct TraitMethodOnCoercedNeverType ;
402+
397403 let mut orig_values = OriginalQueryValues :: default ( ) ;
398404 let predefined_opaques_in_body = if self . next_trait_solver ( ) {
399405 self . tcx . mk_predefined_opaques_in_body_from_iter (
@@ -503,6 +509,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
503509 . iter ( )
504510 . any ( |& candidate_id| self . root_var ( candidate_id) == ty_id)
505511 {
512+ self . tcx . emit_node_span_lint (
513+ TRAIT_METHOD_ON_COERCED_NEVER_TYPE ,
514+ scope_expr_id,
515+ span,
516+ TraitMethodOnCoercedNeverType ,
517+ ) ;
506518 self . demand_eqtype ( span, root_ty, self . tcx . types . never ) ;
507519 } else {
508520 let guar = match * ty. kind ( ) {
0 commit comments