6
6
//! If you wonder why there's no `early.rs`, that's because it's split into three files -
7
7
//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
8
8
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 } ;
11
10
use crate :: { BindingKey , Used } ;
12
11
use crate :: { Module , ModuleOrUniformRoot , NameBinding , ParentScope , PathResult } ;
13
12
use crate :: { ResolutionError , Resolver , Segment , UseError } ;
@@ -17,7 +16,7 @@ use rustc_ast::visit::{walk_list, AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor}
17
16
use rustc_ast:: * ;
18
17
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
19
18
use rustc_errors:: {
20
- codes:: * , struct_span_code_err , Applicability , DiagArgValue , IntoDiagArg , StashKey ,
19
+ codes:: * , Applicability , DiagArgValue , IntoDiagArg , StashKey ,
21
20
} ;
22
21
use rustc_hir:: def:: Namespace :: { self , * } ;
23
22
use 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> {
1666
1665
) ;
1667
1666
}
1668
1667
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) ;
1680
1668
if elided {
1669
+ let mut suggestion = None ;
1681
1670
for rib in self . lifetime_ribs [ i..] . iter ( ) . rev ( ) {
1682
1671
if let LifetimeRibKind :: Generics {
1683
1672
span,
1684
1673
kind : LifetimeBinderKind :: PolyTrait | LifetimeBinderKind :: WhereBound ,
1685
1674
..
1686
1675
} = & rib. kind
1687
1676
{
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
+ } ) ;
1696
1682
break ;
1697
1683
}
1698
1684
}
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
+ } ;
1701
1694
self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , elision_candidate) ;
1702
1695
return ;
1703
1696
}
@@ -1863,13 +1856,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1863
1856
// async fn foo(_: std::cell::Ref<u32>) { ... }
1864
1857
LifetimeRibKind :: AnonymousCreateParameter { report_in_path : true , .. }
1865
1858
| LifetimeRibKind :: AnonymousWarn ( _) => {
1859
+ let mut err =
1860
+ self . r . dcx ( ) . create_err ( errors:: ImplicitElidedLifetimeNotAllowedHere {
1861
+ span : path_span,
1862
+ } ) ;
1866
1863
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
- ) ;
1873
1864
rustc_errors:: add_elided_lifetime_in_path_suggestion (
1874
1865
sess. source_map ( ) ,
1875
1866
& mut err,
@@ -2313,7 +2304,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2313
2304
let report_error = |this : & Self , ns| {
2314
2305
if this. should_report_errs ( ) {
2315
2306
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 } ) ;
2317
2308
}
2318
2309
} ;
2319
2310
@@ -2633,29 +2624,19 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2633
2624
}
2634
2625
2635
2626
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 } ) ;
2644
2630
// Record lifetime res, so lowering knows there is something fishy.
2645
2631
self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
2646
2632
continue ;
2647
2633
}
2648
2634
2649
2635
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
+ } ) ;
2659
2640
// Record lifetime res, so lowering knows there is something fishy.
2660
2641
self . record_lifetime_param ( param. id , LifetimeRes :: Error ) ;
2661
2642
continue ;
0 commit comments