- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Add #[rustc_confusables] attribute to allow targeted "no method" error suggestions on standard library types
          #112239
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    Add #[rustc_confusables] attribute to allow targeted "no method" error suggestions on standard library types
  
  #112239
              Conversation
| (rustbot has picked a reviewer for you, use r? to override) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
407117c    to
    7240568      
    Compare
  
    | The suggestion made in the thread seems relevant, to use  Or is it explicitly wanted that if you search for  | 
| 
 Oops, I have no clue how I missed that... I will close this PR then. 
 I think it's just so happens that  Sorry about this! | 
| @jieyouxu note that this is only my private opinion and I don't know if others agree... :) I did not want to discourage you, and it might be too early to close this PR just yet. I think it's definitely worth to discuss having an attribute separate from  I also dimly remember that either the libs (api) team or the rustdoc team expressed that they want to  But on the other hand, adding a  edit: the policy seems to be here. | 
| 
 I suppose I will keep this PR open for now, then, in case having a separate attribute might be useful. 
 I think I will open a separate PR for adding a doc-alias for  | 
| Actually, after grepping through  | 
| Fair points... I think ultimately it's up to the libs team if they want  | 
| I think the problem with doc aliases is that if you have too many, it becomes quite hard to navigate the docs because you search for something and get lots of random other results showing up. In the diagnostics here you don't really have that problem as its only limited to impls on the type. | 
| r? compiler | 
| r? compiler | 
7240568    to
    a7cd813      
    Compare
  
    | These commits modify the  If this was unintentional then you should revert the changes before this PR is merged. | 
a7cd813    to
    dab231d      
    Compare
  
    | @rustbot ready | 
9f97dd8    to
    410870c      
    Compare
  
    | ☔ The latest upstream changes (presumably #113328) made this pull request unmergeable. Please resolve the merge conflicts. | 
410870c    to
    a06fcba      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 3 nits and r=me.
        
          
                compiler/rustc_passes/messages.ftl
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used any more.
        
          
                compiler/rustc_passes/messages.ftl
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove it, it is not used any more.
"no method" errors on standard library types
The standard library developer can annotate methods on e.g.
`BTreeSet::push` with `#[rustc_confusables("insert")]`. When the user
mistypes `btreeset.push()`, `BTreeSet::insert` will be suggested if
there are no other candidates to suggest.
    a06fcba    to
    08c77a6      
    Compare
  
    | @bors r+ | 
| ⌛ Testing commit 08c77a6 with merge c4b1a20fd4e7f3fa31ac9fbf4b3e8dad1f8a912b... | 
| 💔 Test failed - checks-actions | 
| Seems spurious:  | 
| ☀️ Test successful - checks-actions | 
| Finished benchmarking commit (11da267): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 658.073s -> 657.937s (-0.02%) | 
After this PR, the standard library developer can annotate methods on e.g.
BTreeSet::pushwith#[rustc_confusables("insert")]. When the user mistypesbtreeset.push(),BTreeSet::insertwill be suggested if there are no other candidates to suggest. This PR lays the foundations for contributors to addrustc_confusablesannotations to standard library types for targeted suggestions, as specified in #59450, or to address cases such as #108437.Example
Assume
BTreeSetis the standard library type:A new suggestion (which has lower precedence than suggestions for misspellings and only is shown when there are no misspellings suggestions) will be added to hint the user maybe they intended to write
x.insert()instead: