@@ -28,7 +28,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
28
28
use rustc_span:: edition:: Edition ;
29
29
use rustc_span:: hygiene:: MacroKind ;
30
30
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
31
- use rustc_span:: { BytePos , Span } ;
31
+ use rustc_span:: Span ;
32
32
33
33
use std:: iter;
34
34
use std:: ops:: Deref ;
@@ -351,18 +351,15 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
351
351
return ( err, candidates) ;
352
352
}
353
353
354
- if !self . suggest_missing_let ( & mut err, base_error. span ) {
355
- let mut fallback =
356
- self . suggest_trait_and_bounds ( & mut err, source, res, span, & base_error) ;
354
+ let mut fallback = self . suggest_trait_and_bounds ( & mut err, source, res, span, & base_error) ;
357
355
358
- // if we have suggested using pattern matching, then don't add needless suggestions
359
- // for typos.
360
- fallback |= self . suggest_typo ( & mut err, source, path, span, & base_error) ;
356
+ // if we have suggested using pattern matching, then don't add needless suggestions
357
+ // for typos.
358
+ fallback |= self . suggest_typo ( & mut err, source, path, span, & base_error) ;
361
359
362
- if fallback {
363
- // Fallback label.
364
- err. span_label ( base_error. span , & base_error. fallback_label ) ;
365
- }
360
+ if fallback {
361
+ // Fallback label.
362
+ err. span_label ( base_error. span , & base_error. fallback_label ) ;
366
363
}
367
364
self . err_code_special_cases ( & mut err, source, path, span) ;
368
365
@@ -1802,75 +1799,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
1802
1799
} )
1803
1800
}
1804
1801
1805
- /// Only used in a specific case of type ascription suggestions
1806
- fn get_colon_suggestion_span ( & self , start : Span ) -> Span {
1807
- let sm = self . r . tcx . sess . source_map ( ) ;
1808
- start. to ( sm. next_point ( start) )
1809
- }
1810
-
1811
- #[ instrument( level = "debug" , skip( self , err) ) ]
1812
- fn suggest_missing_let ( & self , err : & mut Diagnostic , base_span : Span ) -> bool {
1813
- let sm = self . r . tcx . sess . source_map ( ) ;
1814
- let base_snippet = sm. span_to_snippet ( base_span) ;
1815
- if let Some ( & sp) = self . diagnostic_metadata . current_type_ascription . last ( ) {
1816
- if let Ok ( snippet) = sm. span_to_snippet ( sp) {
1817
- let len = snippet. trim_end ( ) . len ( ) as u32 ;
1818
- if snippet. trim ( ) == ":" {
1819
- let colon_sp =
1820
- sp. with_lo ( sp. lo ( ) + BytePos ( len - 1 ) ) . with_hi ( sp. lo ( ) + BytePos ( len) ) ;
1821
- let mut show_label = true ;
1822
- if sm. is_multiline ( sp) {
1823
- err. span_suggestion_short (
1824
- colon_sp,
1825
- "maybe you meant to write `;` here" ,
1826
- ";" ,
1827
- Applicability :: MaybeIncorrect ,
1828
- ) ;
1829
- } else {
1830
- let after_colon_sp =
1831
- self . get_colon_suggestion_span ( colon_sp. shrink_to_hi ( ) ) ;
1832
- if snippet. len ( ) == 1 {
1833
- // `foo:bar`
1834
- err. span_suggestion (
1835
- colon_sp,
1836
- "maybe you meant to write a path separator here" ,
1837
- "::" ,
1838
- Applicability :: MaybeIncorrect ,
1839
- ) ;
1840
- show_label = false ;
1841
- if !self
1842
- . r
1843
- . tcx
1844
- . sess
1845
- . parse_sess
1846
- . type_ascription_path_suggestions
1847
- . borrow_mut ( )
1848
- . insert ( colon_sp)
1849
- {
1850
- err. downgrade_to_delayed_bug ( ) ;
1851
- }
1852
- }
1853
- if let Ok ( base_snippet) = base_snippet {
1854
- // Try to find an assignment
1855
- let eq_span = sm. span_look_ahead ( after_colon_sp, Some ( "=" ) , Some ( 50 ) ) ;
1856
- if let Ok ( ref snippet) = sm. span_to_snippet ( eq_span) && snippet == "=" {
1857
- err. span_suggestion (
1858
- base_span,
1859
- "maybe you meant to write an assignment here" ,
1860
- format ! ( "let {}" , base_snippet) ,
1861
- Applicability :: MaybeIncorrect ,
1862
- ) ;
1863
- show_label = false ;
1864
- }
1865
- }
1866
- }
1867
- return show_label;
1868
- }
1869
- }
1870
- }
1871
- false
1872
- }
1873
-
1874
1802
// try to give a suggestion for this pattern: `name = blah`, which is common in other languages
1875
1803
// suggest `let name = blah` to introduce a new binding
1876
1804
fn let_binding_suggestion ( & mut self , err : & mut Diagnostic , ident_span : Span ) -> bool {
0 commit comments