@@ -33,7 +33,7 @@ use rustc_session::parse::feature_err;
3333use rustc_span:: edit_distance:: find_best_match_for_name;
3434use rustc_span:: hygiene:: DesugaringKind ;
3535use rustc_span:: source_map:: Spanned ;
36- use rustc_span:: { Ident , Span , Symbol , kw, sym} ;
36+ use rustc_span:: { Ident , Span , Symbol , SyntaxContext , kw, sym} ;
3737use rustc_trait_selection:: infer:: InferCtxtExt ;
3838use rustc_trait_selection:: traits:: { self , ObligationCauseCode , ObligationCtxt } ;
3939use tracing:: { debug, instrument, trace} ;
@@ -220,6 +220,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
220220 self . check_expr_with_expectation_and_needs ( expr, NoExpectation , needs)
221221 }
222222
223+ fn is_todo_macro ( & self , span : Span ) -> bool {
224+ let mut ctxt = span. ctxt ( ) ;
225+ while ctxt != SyntaxContext :: root ( ) {
226+ let data = ctxt. outer_expn_data ( ) ;
227+ if let Some ( def_id) = data. macro_def_id
228+ && self . tcx . is_diagnostic_item ( sym:: todo_macro, def_id)
229+ {
230+ return true ;
231+ }
232+ ctxt = data. call_site . ctxt ( ) ;
233+ }
234+ false
235+ }
236+
223237 /// Check an expr with an expectation type which may be used to eagerly
224238 /// guide inference when evaluating that expr.
225239 #[ instrument( skip( self , expr) , level = "debug" ) ]
@@ -322,7 +336,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
322336 if self . try_structurally_resolve_type ( expr. span , ty) . is_never ( )
323337 && self . expr_guaranteed_to_constitute_read_for_never ( expr)
324338 {
325- self . diverges . set ( self . diverges . get ( ) | Diverges :: always ( expr. span ) ) ;
339+ let diverges = if self . is_todo_macro ( expr. span ) {
340+ // We don't warn for `todo!()` that diverges to avoid flooding the
341+ // user with warnings while they are still working on their code.
342+ Diverges :: WarnedAlways
343+ } else {
344+ Diverges :: always ( expr. span )
345+ } ;
346+ self . diverges . set ( self . diverges . get ( ) | diverges) ;
326347 }
327348
328349 // Record the type, which applies it effects.
0 commit comments