66//! If you wonder why there's no `early.rs`, that's because it's split into three files -
77//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
88
9- use crate :: errors:: ImportsCannotReferTo ;
10- use crate :: { path_names_to_string, rustdoc, BindingError , Finalize , LexicalScopeBinding } ;
9+ use crate :: { errors, path_names_to_string, rustdoc, BindingError , Finalize , LexicalScopeBinding } ;
1110use crate :: { BindingKey , Used } ;
1211use crate :: { Module , ModuleOrUniformRoot , NameBinding , ParentScope , PathResult } ;
1312use crate :: { ResolutionError , Resolver , Segment , UseError } ;
@@ -17,7 +16,7 @@ use rustc_ast::visit::{walk_list, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}
1716use rustc_ast:: * ;
1817use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
1918use rustc_errors:: {
20- codes:: * , struct_span_code_err , Applicability , DiagArgValue , IntoDiagArg , StashKey ,
19+ codes:: * , Applicability , DiagArgValue , IntoDiagArg , StashKey ,
2120} ;
2221use rustc_hir:: def:: Namespace :: { self , * } ;
2322use rustc_hir:: def:: { self , CtorKind , DefKind , LifetimeRes , NonMacroAttrKind , PartialRes , PerNS } ;
@@ -1666,38 +1665,32 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16661665 ) ;
16671666 }
16681667 LifetimeRibKind :: AnonymousReportError => {
1669- let ( msg, note) = if elided {
1670- (
1671- "`&` without an explicit lifetime name cannot be used here" ,
1672- "explicit lifetime name needed here" ,
1673- )
1674- } else {
1675- ( "`'_` cannot be used here" , "`'_` is a reserved lifetime name" )
1676- } ;
1677- let mut diag =
1678- struct_span_code_err ! ( self . r. dcx( ) , lifetime. ident. span, E0637 , "{}" , msg, ) ;
1679- diag. span_label ( lifetime. ident . span , note) ;
16801668 if elided {
1669+ let mut suggestion = None ;
16811670 for rib in self . lifetime_ribs [ i..] . iter ( ) . rev ( ) {
16821671 if let LifetimeRibKind :: Generics {
16831672 span,
16841673 kind : LifetimeBinderKind :: PolyTrait | LifetimeBinderKind :: WhereBound ,
16851674 ..
16861675 } = & rib. kind
16871676 {
1688- diag. multipart_suggestion (
1689- "consider introducing a higher-ranked lifetime here" ,
1690- vec ! [
1691- ( span. shrink_to_lo( ) , "for<'a> " . into( ) ) ,
1692- ( lifetime. ident. span. shrink_to_hi( ) , "'a " . into( ) ) ,
1693- ] ,
1694- Applicability :: MachineApplicable ,
1695- ) ;
1677+ suggestion =
1678+ Some ( errors:: ElidedAnonymousLivetimeReportErrorSuggestion {
1679+ lo : span. shrink_to_lo ( ) ,
1680+ hi : lifetime. ident . span . shrink_to_hi ( ) ,
1681+ } ) ;
16961682 break ;
16971683 }
16981684 }
1699- }
1700- diag. emit ( ) ;
1685+ self . r . dcx ( ) . emit_err ( errors:: ElidedAnonymousLivetimeReportError {
1686+ span : lifetime. ident . span ,
1687+ suggestion,
1688+ } ) ;
1689+ } else {
1690+ self . r . dcx ( ) . emit_err ( errors:: ExplicitAnonymousLivetimeReportError {
1691+ span : lifetime. ident . span ,
1692+ } ) ;
1693+ } ;
17011694 self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , elision_candidate) ;
17021695 return ;
17031696 }
@@ -1863,13 +1856,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
18631856 // async fn foo(_: std::cell::Ref<u32>) { ... }
18641857 LifetimeRibKind :: AnonymousCreateParameter { report_in_path : true , .. }
18651858 | LifetimeRibKind :: AnonymousWarn ( _) => {
1859+ let mut err =
1860+ self . r . dcx ( ) . create_err ( errors:: ImplicitElidedLifetimeNotAllowedHere {
1861+ span : path_span,
1862+ } ) ;
18661863 let sess = self . r . tcx . sess ;
1867- let mut err = struct_span_code_err ! (
1868- sess. dcx( ) ,
1869- path_span,
1870- E0726 ,
1871- "implicit elided lifetime not allowed here"
1872- ) ;
18731864 rustc_errors:: add_elided_lifetime_in_path_suggestion (
18741865 sess. source_map ( ) ,
18751866 & mut err,
@@ -2313,7 +2304,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
23132304 let report_error = |this : & Self , ns| {
23142305 if this. should_report_errs ( ) {
23152306 let what = if ns == TypeNS { "type parameters" } else { "local variables" } ;
2316- this. r . dcx ( ) . emit_err ( ImportsCannotReferTo { span : ident. span , what } ) ;
2307+ this. r . dcx ( ) . emit_err ( errors :: ImportsCannotReferTo { span : ident. span , what } ) ;
23172308 }
23182309 } ;
23192310
@@ -2633,29 +2624,19 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
26332624 }
26342625
26352626 if param. ident . name == kw:: UnderscoreLifetime {
2636- struct_span_code_err ! (
2637- self . r. dcx( ) ,
2638- param. ident. span,
2639- E0637 ,
2640- "`'_` cannot be used here"
2641- )
2642- . with_span_label ( param. ident . span , "`'_` is a reserved lifetime name" )
2643- . emit ( ) ;
2627+ self . r
2628+ . dcx ( )
2629+ . emit_err ( errors:: UnderscoreLifetimeIsReserved { span : param. ident . span } ) ;
26442630 // Record lifetime res, so lowering knows there is something fishy.
26452631 self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
26462632 continue ;
26472633 }
26482634
26492635 if param. ident . name == kw:: StaticLifetime {
2650- struct_span_code_err ! (
2651- self . r. dcx( ) ,
2652- param. ident. span,
2653- E0262 ,
2654- "invalid lifetime parameter name: `{}`" ,
2655- param. ident,
2656- )
2657- . with_span_label ( param. ident . span , "'static is a reserved lifetime name" )
2658- . emit ( ) ;
2636+ self . r . dcx ( ) . emit_err ( errors:: StaticLifetimeIsReserved {
2637+ span : param. ident . span ,
2638+ lifetime : param. ident ,
2639+ } ) ;
26592640 // Record lifetime res, so lowering knows there is something fishy.
26602641 self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
26612642 continue ;
0 commit comments