- 
                Notifications
    You must be signed in to change notification settings 
- Fork 279
c2rust-analyze: initial implementation of error recovery #876
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
Changes from all commits
45bbc53
              e284b8f
              dbdf047
              f9a28ac
              e75a6cf
              7ac897d
              4a9fdce
              540a7b0
              5d03754
              79f855b
              9298e0d
              f3cb046
              cbf6dc1
              4aeccba
              f84d0ba
              24b9284
              ce24f38
              172808d
              176ecb1
              47ebc33
              cd9d001
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| use crate::borrowck::{AdtMetadata, FieldMetadata, OriginArg, OriginParam}; | ||||||
| use crate::c_void_casts::CVoidCasts; | ||||||
| use crate::labeled_ty::{LabeledTy, LabeledTyCtxt}; | ||||||
| use crate::panic_detail::PanicDetail; | ||||||
| use crate::pointer_id::{ | ||||||
| GlobalPointerTable, LocalPointerTable, NextGlobalPointerId, NextLocalPointerId, PointerTable, | ||||||
| PointerTableMut, | ||||||
|  | @@ -272,7 +273,13 @@ pub struct GlobalAnalysisCtxt<'tcx> { | |||||
|  | ||||||
| ptr_info: GlobalPointerTable<PointerInfo>, | ||||||
|  | ||||||
| /// Map from a function to all of its callers. | ||||||
| pub fn_callers: HashMap<DefId, Vec<DefId>>, | ||||||
|  | ||||||
| pub fn_sigs: HashMap<DefId, LFnSig<'tcx>>, | ||||||
| /// `DefId`s of functions where analysis failed, and a [`PanicDetail`] explaining the reason | ||||||
| /// for each failure. | ||||||
| pub fns_failed: HashMap<DefId, PanicDetail>, | ||||||
|  | ||||||
| pub field_ltys: HashMap<DefId, LTy<'tcx>>, | ||||||
|  | ||||||
|  | @@ -522,7 +529,9 @@ impl<'tcx> GlobalAnalysisCtxt<'tcx> { | |||||
| tcx, | ||||||
| lcx: LabeledTyCtxt::new(tcx), | ||||||
| ptr_info: GlobalPointerTable::empty(), | ||||||
| fn_callers: HashMap::new(), | ||||||
| fn_sigs: HashMap::new(), | ||||||
| fns_failed: HashMap::new(), | ||||||
| field_ltys: HashMap::new(), | ||||||
| static_tys: HashMap::new(), | ||||||
| addr_of_static: HashMap::new(), | ||||||
|  | @@ -566,7 +575,9 @@ impl<'tcx> GlobalAnalysisCtxt<'tcx> { | |||||
| tcx: _, | ||||||
| lcx, | ||||||
| ref mut ptr_info, | ||||||
| fn_callers: _, | ||||||
| ref mut fn_sigs, | ||||||
| fns_failed: _, | ||||||
| ref mut field_ltys, | ||||||
| ref mut static_tys, | ||||||
| ref mut addr_of_static, | ||||||
|  | @@ -620,6 +631,27 @@ impl<'tcx> GlobalAnalysisCtxt<'tcx> { | |||||
| self.assign_pointer_to_field(field); | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| pub fn fn_failed(&mut self, did: DefId) -> bool { | ||||||
| self.fns_failed.contains_key(&did) | ||||||
| } | ||||||
|  | ||||||
| pub fn mark_fn_failed(&mut self, did: DefId, detail: PanicDetail) { | ||||||
| if self.fns_failed.contains_key(&did) { | ||||||
| return; | ||||||
| } | ||||||
|  | ||||||
| self.fns_failed.insert(did, detail); | ||||||
|  | ||||||
| // This is the first time marking `did` as failed, so also mark all of its callers. | ||||||
| let callers = self.fn_callers.get(&did).cloned().unwrap_or(Vec::new()); | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only removes a type hint that might be useful for the reader. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a false positive in Clippy.  "This is only bad if it allocates or does some non-trivial amount of work," but "The lint also cannot figure out whether the function you call is actually expensive to call or not."  In this case the function being called is  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is a slightly different warning.  When it suggests using a closure that calls a  That said, I don't really want to spend time debating the merits of  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 There's no good reason to make this change. The fact that Clippy suggested it isn't a good reason on its own, because Clippy often gives bad advice. (Any clippy lints that do regularly give good advice tend to get uplifted into rustc.) 
 I disagree.  Knowing the type of  As far as I know, the official policy for this repo does not require the code to be clippy-clean. Unless that changes (which I would oppose), I don't see any value in making the code (very slightly) worse just to appease the tool. | ||||||
| for caller in callers { | ||||||
| self.mark_fn_failed( | ||||||
| caller, | ||||||
| PanicDetail::new(format!("analysis failed on callee {:?}", did)), | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| impl<'a, 'tcx> AnalysisCtxt<'a, 'tcx> { | ||||||
|  | ||||||
Uh oh!
There was an error while loading. Please reload this page.