-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Use a Set<T>
instead of a Map<T, bool>
#45736
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ use rustc::ty::maps::{queries, Providers}; | |
use rustc::ty::subst::Substs; | ||
use rustc::traits::Reveal; | ||
use rustc::util::common::ErrorReported; | ||
use rustc::util::nodemap::{ItemLocalMap, NodeSet}; | ||
use rustc::util::nodemap::{ItemLocalSet, NodeSet}; | ||
use rustc::lint::builtin::CONST_ERR; | ||
use rustc::hir::{self, PatKind, RangeEnd}; | ||
use std::rc::Rc; | ||
|
@@ -79,12 +79,12 @@ fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, | |
.expect("rvalue_promotable_map invoked with non-local def-id"); | ||
let body_id = tcx.hir.body_owned_by(node_id); | ||
let body_hir_id = tcx.hir.node_to_hir_id(body_id.node_id); | ||
tcx.rvalue_promotable_map(def_id).contains_key(&body_hir_id.local_id) | ||
tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id) | ||
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. I did this exact thing in clippy, and it was very wrong. I'm fairly certain it was wrong here, too. This checked whether the 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. 👍 |
||
} | ||
|
||
fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
def_id: DefId) | ||
-> Rc<ItemLocalMap<bool>> | ||
-> Rc<ItemLocalSet> | ||
{ | ||
let outer_def_id = tcx.closure_base_def_id(def_id); | ||
if outer_def_id != def_id { | ||
|
@@ -100,7 +100,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, | |
mut_rvalue_borrows: NodeSet(), | ||
param_env: ty::ParamEnv::empty(Reveal::UserFacing), | ||
identity_substs: Substs::empty(), | ||
result_map: ItemLocalMap(), | ||
result: ItemLocalSet(), | ||
}; | ||
|
||
// `def_id` should be a `Body` owner | ||
|
@@ -109,7 +109,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, | |
let body_id = tcx.hir.body_owned_by(node_id); | ||
visitor.visit_nested_body(body_id); | ||
|
||
Rc::new(visitor.result_map) | ||
Rc::new(visitor.result) | ||
} | ||
|
||
struct CheckCrateVisitor<'a, 'tcx: 'a> { | ||
|
@@ -121,7 +121,7 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> { | |
param_env: ty::ParamEnv<'tcx>, | ||
identity_substs: &'tcx Substs<'tcx>, | ||
tables: &'a ty::TypeckTables<'tcx>, | ||
result_map: ItemLocalMap<bool>, | ||
result: ItemLocalSet, | ||
} | ||
|
||
impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { | ||
|
@@ -322,7 +322,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> { | |
} | ||
} | ||
|
||
self.result_map.insert(ex.hir_id.local_id, self.promotable); | ||
if self.promotable { | ||
self.result.insert(ex.hir_id.local_id); | ||
} | ||
self.promotable &= outer; | ||
} | ||
} | ||
|
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 the only change in semantics. We do not panic anymore if
local_id
was never checked for rvalue promotion, we just returnfalse
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.
yeah, seems..ok