Rollup merge of #120485 - chenyukang:yukang-add-query-instability-check, r=michaelwoerister
add missing potential_query_instability for keys and values in hashmap From https://github.com/rust-lang/rust/pull/120435#discussion_r1468883787, These API are also returning iterator, so we need add `potential_query_instability` for them?
This commit is contained in:
commit
27bc496564
@ -403,6 +403,7 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
|
|||||||
let mut result = items.clone();
|
let mut result = items.clone();
|
||||||
|
|
||||||
for cgu in cgus {
|
for cgu in cgus {
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
for item in cgu.items().keys() {
|
for item in cgu.items().keys() {
|
||||||
if let mir::mono::MonoItem::Fn(ref instance) = item {
|
if let mir::mono::MonoItem::Fn(ref instance) = item {
|
||||||
let did = instance.def_id();
|
let did = instance.def_id();
|
||||||
|
@ -267,6 +267,7 @@ fn set_expectation(
|
|||||||
|
|
||||||
fn check_expected_reuse(&self, sess: &Session) {
|
fn check_expected_reuse(&self, sess: &Session) {
|
||||||
if let Some(ref data) = self.data {
|
if let Some(ref data) = self.data {
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
|
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
|
||||||
keys.sort_unstable();
|
keys.sort_unstable();
|
||||||
for cgu_name in keys {
|
for cgu_name in keys {
|
||||||
|
@ -682,6 +682,7 @@ fn read_input(&self, path: &Path) -> std::io::Result<&[u8]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Input rlibs contain .o/.dwo files from dependencies.
|
// Input rlibs contain .o/.dwo files from dependencies.
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
let input_rlibs = cg_results
|
let input_rlibs = cg_results
|
||||||
.crate_info
|
.crate_info
|
||||||
.used_crate_source
|
.used_crate_source
|
||||||
|
@ -1966,6 +1966,7 @@ fn report_missing_fields(
|
|||||||
) {
|
) {
|
||||||
let len = remaining_fields.len();
|
let len = remaining_fields.len();
|
||||||
|
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
let mut displayable_field_names: Vec<&str> =
|
let mut displayable_field_names: Vec<&str> =
|
||||||
remaining_fields.keys().map(|ident| ident.as_str()).collect();
|
remaining_fields.keys().map(|ident| ident.as_str()).collect();
|
||||||
// sorting &str primitives here, sort_unstable is ok
|
// sorting &str primitives here, sort_unstable is ok
|
||||||
|
@ -326,11 +326,9 @@ pub fn find_lints(&self, mut lint_name: &str) -> Result<Vec<LintId>, FindLintErr
|
|||||||
|
|
||||||
/// True if this symbol represents a lint group name.
|
/// True if this symbol represents a lint group name.
|
||||||
pub fn is_lint_group(&self, lint_name: Symbol) -> bool {
|
pub fn is_lint_group(&self, lint_name: Symbol) -> bool {
|
||||||
debug!(
|
#[allow(rustc::potential_query_instability)]
|
||||||
"is_lint_group(lint_name={:?}, lint_groups={:?})",
|
let lint_groups = self.lint_groups.keys().collect::<Vec<_>>();
|
||||||
lint_name,
|
debug!("is_lint_group(lint_name={:?}, lint_groups={:?})", lint_name, lint_groups);
|
||||||
self.lint_groups.keys().collect::<Vec<_>>()
|
|
||||||
);
|
|
||||||
let lint_name_str = lint_name.as_str();
|
let lint_name_str = lint_name.as_str();
|
||||||
self.lint_groups.contains_key(lint_name_str) || {
|
self.lint_groups.contains_key(lint_name_str) || {
|
||||||
let warnings_name_str = crate::WARNINGS.name_lower();
|
let warnings_name_str = crate::WARNINGS.name_lower();
|
||||||
@ -374,8 +372,12 @@ pub fn check_lint_name(
|
|||||||
None => {
|
None => {
|
||||||
// 1. The tool is currently running, so this lint really doesn't exist.
|
// 1. The tool is currently running, so this lint really doesn't exist.
|
||||||
// FIXME: should this handle tools that never register a lint, like rustfmt?
|
// FIXME: should this handle tools that never register a lint, like rustfmt?
|
||||||
debug!("lints={:?}", self.by_name.keys().collect::<Vec<_>>());
|
#[allow(rustc::potential_query_instability)]
|
||||||
|
let lints = self.by_name.keys().collect::<Vec<_>>();
|
||||||
|
debug!("lints={:?}", lints);
|
||||||
let tool_prefix = format!("{tool_name}::");
|
let tool_prefix = format!("{tool_name}::");
|
||||||
|
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) {
|
return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) {
|
||||||
self.no_lint_suggestion(&complete_name, tool_name.as_str())
|
self.no_lint_suggestion(&complete_name, tool_name.as_str())
|
||||||
} else {
|
} else {
|
||||||
|
@ -185,6 +185,7 @@ pub(super) fn builtin(
|
|||||||
db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
|
db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
|
||||||
}
|
}
|
||||||
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
|
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
let possibilities: Vec<Symbol> =
|
let possibilities: Vec<Symbol> =
|
||||||
sess.parse_sess.check_config.expecteds.keys().copied().collect();
|
sess.parse_sess.check_config.expecteds.keys().copied().collect();
|
||||||
let is_from_cargo = std::env::var_os("CARGO").is_some();
|
let is_from_cargo = std::env::var_os("CARGO").is_some();
|
||||||
|
@ -513,6 +513,7 @@ fn map_vid_to_region<'cx>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
while !vid_map.is_empty() {
|
while !vid_map.is_empty() {
|
||||||
|
#[allow(rustc::potential_query_instability)]
|
||||||
let target = *vid_map.keys().next().expect("Keys somehow empty");
|
let target = *vid_map.keys().next().expect("Keys somehow empty");
|
||||||
let deps = vid_map.remove(&target).expect("Entry somehow missing");
|
let deps = vid_map.remove(&target).expect("Entry somehow missing");
|
||||||
|
|
||||||
|
@ -356,6 +356,7 @@ pub fn capacity(&self) -> usize {
|
|||||||
///
|
///
|
||||||
/// In the current implementation, iterating over keys takes O(capacity) time
|
/// In the current implementation, iterating over keys takes O(capacity) time
|
||||||
/// instead of O(len) because it internally visits empty buckets too.
|
/// instead of O(len) because it internally visits empty buckets too.
|
||||||
|
#[rustc_lint_query_instability]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn keys(&self) -> Keys<'_, K, V> {
|
pub fn keys(&self) -> Keys<'_, K, V> {
|
||||||
Keys { inner: self.iter() }
|
Keys { inner: self.iter() }
|
||||||
@ -417,6 +418,7 @@ pub fn into_keys(self) -> IntoKeys<K, V> {
|
|||||||
///
|
///
|
||||||
/// In the current implementation, iterating over values takes O(capacity) time
|
/// In the current implementation, iterating over values takes O(capacity) time
|
||||||
/// instead of O(len) because it internally visits empty buckets too.
|
/// instead of O(len) because it internally visits empty buckets too.
|
||||||
|
#[rustc_lint_query_instability]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn values(&self) -> Values<'_, K, V> {
|
pub fn values(&self) -> Values<'_, K, V> {
|
||||||
Values { inner: self.iter() }
|
Values { inner: self.iter() }
|
||||||
@ -449,6 +451,7 @@ pub fn values(&self) -> Values<'_, K, V> {
|
|||||||
///
|
///
|
||||||
/// In the current implementation, iterating over values takes O(capacity) time
|
/// In the current implementation, iterating over values takes O(capacity) time
|
||||||
/// instead of O(len) because it internally visits empty buckets too.
|
/// instead of O(len) because it internally visits empty buckets too.
|
||||||
|
#[rustc_lint_query_instability]
|
||||||
#[stable(feature = "map_values_mut", since = "1.10.0")]
|
#[stable(feature = "map_values_mut", since = "1.10.0")]
|
||||||
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
|
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
|
||||||
ValuesMut { inner: self.iter_mut() }
|
ValuesMut { inner: self.iter_mut() }
|
||||||
|
@ -21,4 +21,17 @@ fn main() {
|
|||||||
|
|
||||||
for _ in x {}
|
for _ in x {}
|
||||||
//~^ ERROR using `into_iter`
|
//~^ ERROR using `into_iter`
|
||||||
|
|
||||||
|
let x = FxHashMap::<u32, i32>::default();
|
||||||
|
let _ = x.keys();
|
||||||
|
//~^ ERROR using `keys` can result in unstable query results
|
||||||
|
|
||||||
|
let _ = x.values();
|
||||||
|
//~^ ERROR using `values` can result in unstable query results
|
||||||
|
|
||||||
|
let mut x = FxHashMap::<u32, i32>::default();
|
||||||
|
for val in x.values_mut() {
|
||||||
|
//~^ ERROR using `values_mut` can result in unstable query results
|
||||||
|
*val = *val + 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,5 +35,29 @@ LL | for _ in x {}
|
|||||||
|
|
|
|
||||||
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: using `keys` can result in unstable query results
|
||||||
|
--> $DIR/query_stability.rs:26:15
|
||||||
|
|
|
||||||
|
LL | let _ = x.keys();
|
||||||
|
| ^^^^
|
||||||
|
|
|
||||||
|
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
||||||
|
|
||||||
|
error: using `values` can result in unstable query results
|
||||||
|
--> $DIR/query_stability.rs:29:15
|
||||||
|
|
|
||||||
|
LL | let _ = x.values();
|
||||||
|
| ^^^^^^
|
||||||
|
|
|
||||||
|
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
||||||
|
|
||||||
|
error: using `values_mut` can result in unstable query results
|
||||||
|
--> $DIR/query_stability.rs:33:18
|
||||||
|
|
|
||||||
|
LL | for val in x.values_mut() {
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
||||||
|
|
||||||
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user