@@ -28,7 +28,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
2828use rustc_span:: edition:: Edition ;
2929use rustc_span:: hygiene:: MacroKind ;
3030use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
31- use rustc_span:: { BytePos , Span } ;
31+ use rustc_span:: Span ;
3232
3333use std:: iter;
3434use std:: ops:: Deref ;
@@ -351,18 +351,15 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
351351 return ( err, candidates) ;
352352 }
353353
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) ;
357355
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) ;
361359
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 ) ;
366363 }
367364 self . err_code_special_cases ( & mut err, source, path, span) ;
368365
@@ -1818,75 +1815,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
18181815 } )
18191816 }
18201817
1821- /// Only used in a specific case of type ascription suggestions
1822- fn get_colon_suggestion_span ( & self , start : Span ) -> Span {
1823- let sm = self . r . tcx . sess . source_map ( ) ;
1824- start. to ( sm. next_point ( start) )
1825- }
1826-
1827- #[ instrument( level = "debug" , skip( self , err) ) ]
1828- fn suggest_missing_let ( & self , err : & mut Diagnostic , base_span : Span ) -> bool {
1829- let sm = self . r . tcx . sess . source_map ( ) ;
1830- let base_snippet = sm. span_to_snippet ( base_span) ;
1831- if let Some ( & sp) = self . diagnostic_metadata . current_type_ascription . last ( ) {
1832- if let Ok ( snippet) = sm. span_to_snippet ( sp) {
1833- let len = snippet. trim_end ( ) . len ( ) as u32 ;
1834- if snippet. trim ( ) == ":" {
1835- let colon_sp =
1836- sp. with_lo ( sp. lo ( ) + BytePos ( len - 1 ) ) . with_hi ( sp. lo ( ) + BytePos ( len) ) ;
1837- let mut show_label = true ;
1838- if sm. is_multiline ( sp) {
1839- err. span_suggestion_short (
1840- colon_sp,
1841- "maybe you meant to write `;` here" ,
1842- ";" ,
1843- Applicability :: MaybeIncorrect ,
1844- ) ;
1845- } else {
1846- let after_colon_sp =
1847- self . get_colon_suggestion_span ( colon_sp. shrink_to_hi ( ) ) ;
1848- if snippet. len ( ) == 1 {
1849- // `foo:bar`
1850- err. span_suggestion (
1851- colon_sp,
1852- "maybe you meant to write a path separator here" ,
1853- "::" ,
1854- Applicability :: MaybeIncorrect ,
1855- ) ;
1856- show_label = false ;
1857- if !self
1858- . r
1859- . tcx
1860- . sess
1861- . parse_sess
1862- . type_ascription_path_suggestions
1863- . borrow_mut ( )
1864- . insert ( colon_sp)
1865- {
1866- err. downgrade_to_delayed_bug ( ) ;
1867- }
1868- }
1869- if let Ok ( base_snippet) = base_snippet {
1870- // Try to find an assignment
1871- let eq_span = sm. span_look_ahead ( after_colon_sp, Some ( "=" ) , Some ( 50 ) ) ;
1872- if let Ok ( ref snippet) = sm. span_to_snippet ( eq_span) && snippet == "=" {
1873- err. span_suggestion (
1874- base_span,
1875- "maybe you meant to write an assignment here" ,
1876- format ! ( "let {}" , base_snippet) ,
1877- Applicability :: MaybeIncorrect ,
1878- ) ;
1879- show_label = false ;
1880- }
1881- }
1882- }
1883- return show_label;
1884- }
1885- }
1886- }
1887- false
1888- }
1889-
18901818 // try to give a suggestion for this pattern: `name = blah`, which is common in other languages
18911819 // suggest `let name = blah` to introduce a new binding
18921820 fn let_binding_suggestion ( & mut self , err : & mut Diagnostic , ident_span : Span ) -> bool {
0 commit comments