- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Refactor inner allocation logic of temp dangling pointer lint #133263
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
Conversation
00937d7    to
    c547b45      
    Compare
  
    | 
 And  | 
32e1211    to
    fe17d7a      
    Compare
  
    
      
        
              This comment was marked as outdated.
        
        
      
    
  This comment was marked as outdated.
fe17d7a    to
    308f435      
    Compare
  
    | Having spent the past few days looking over this lint I don't really want to merge this PR as is without a more thorough rework of this lint. It's very hard to review or approve this PR when everything generally seems very adhoc without any clear logic in mind. 
 
 The intention seems to be that if there is a reference anywhere in the adjustments to get to the final  I honestly don't see a way to implement this lint correctly in the general case without turning this into a MIR lint and doing some kind of psuedo-borrowck that attempts to determine what places should be considered "used" by the returned pointer and then checking if they're all live when the returned pointer is used. Other than rewriting this to MIR lint I think a viable path forward would be to stop trying to make the lint so complex and just make it work for "obvious" stuff. You should recurse on the reciever expr looking for anything that constructs a value of the same type that the  We should also make sure not to lint if there are any  On an unrelated note I think it's probably fine to not handle const promotion. Most cases with  Finally, the fact that  | 
| @rustbot author | 
| When I reviewed #128985 (the PR that generalized the  Which then lead me to the same reflection about the difficulty and complexity that it would be and the fact that we probably only want to handle "obvious" case. Which is why the current lint is quite imperfect and why I posted this PR to improve it bit by bit (which I recognized in my original review). 
 Yeah  Recursing into the receiver expression seems like an interesting idea, not sure how complex that would be. | 
| 
 I have looked at this proposal and came over an issue where the owned type is different from the deref type, this is the case for  We could have some sort of attribute to "link" them up but I fear that we will end up with even bigger perf regressions than the one fixed in #133509 where just looking if the method had  I'm not sure what to do. Maybe merge this PR (since I still think it's an improvement IMO) and open an issue about improving the implementation? @rustbot ready | 
| Can we try and find other ways to resolve that performance problem? If the problem is that getting attributes on every method call is too expensive then could we add a cross-crate query which returns a list of defids for methods (and associated owned self type) that we should lint on. That way we would be reading from metadata only once for a relatively small list of defids (which will be cached) compared to having a separate query and metadata reading for every single def you call  | 
This PR refactors the inner allocation logic of the
dangling_pointers_from_temporarieslint by removing the hardcoded list of types and instead taking advantage of the semantics of theas_ptr{,_mut}methods and derefs.cc @GrigorenkoPV
r? compiler