Skip to content

Commit 27bc496

Browse files
Rollup merge of rust-lang#120485 - chenyukang:yukang-add-query-instability-check, r=michaelwoerister
add missing potential_query_instability for keys and values in hashmap From rust-lang#120435 (comment), These API are also returning iterator, so we need add `potential_query_instability` for them?
2 parents f3f1472 + ad526d8 commit 27bc496

File tree

10 files changed

+55
-7
lines changed

10 files changed

+55
-7
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ fn codegenned_and_inlined_items(tcx: TyCtxt<'_>) -> DefIdSet {
403403
let mut result = items.clone();
404404

405405
for cgu in cgus {
406+
#[allow(rustc::potential_query_instability)]
406407
for item in cgu.items().keys() {
407408
if let mir::mono::MonoItem::Fn(ref instance) = item {
408409
let did = instance.def_id();

compiler/rustc_codegen_ssa/src/assert_module_sources.rs

+1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl CguReuseTracker {
267267

268268
fn check_expected_reuse(&self, sess: &Session) {
269269
if let Some(ref data) = self.data {
270+
#[allow(rustc::potential_query_instability)]
270271
let mut keys = data.expected_reuse.keys().collect::<Vec<_>>();
271272
keys.sort_unstable();
272273
for cgu_name in keys {

compiler/rustc_codegen_ssa/src/back/link.rs

+1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ fn link_dwarf_object<'a>(
682682
}
683683

684684
// Input rlibs contain .o/.dwo files from dependencies.
685+
#[allow(rustc::potential_query_instability)]
685686
let input_rlibs = cg_results
686687
.crate_info
687688
.used_crate_source

compiler/rustc_hir_typeck/src/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19661966
) {
19671967
let len = remaining_fields.len();
19681968

1969+
#[allow(rustc::potential_query_instability)]
19691970
let mut displayable_field_names: Vec<&str> =
19701971
remaining_fields.keys().map(|ident| ident.as_str()).collect();
19711972
// sorting &str primitives here, sort_unstable is ok

compiler/rustc_lint/src/context.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,9 @@ impl LintStore {
326326

327327
/// True if this symbol represents a lint group name.
328328
pub fn is_lint_group(&self, lint_name: Symbol) -> bool {
329-
debug!(
330-
"is_lint_group(lint_name={:?}, lint_groups={:?})",
331-
lint_name,
332-
self.lint_groups.keys().collect::<Vec<_>>()
333-
);
329+
#[allow(rustc::potential_query_instability)]
330+
let lint_groups = self.lint_groups.keys().collect::<Vec<_>>();
331+
debug!("is_lint_group(lint_name={:?}, lint_groups={:?})", lint_name, lint_groups);
334332
let lint_name_str = lint_name.as_str();
335333
self.lint_groups.contains_key(lint_name_str) || {
336334
let warnings_name_str = crate::WARNINGS.name_lower();
@@ -374,8 +372,12 @@ impl LintStore {
374372
None => {
375373
// 1. The tool is currently running, so this lint really doesn't exist.
376374
// FIXME: should this handle tools that never register a lint, like rustfmt?
377-
debug!("lints={:?}", self.by_name.keys().collect::<Vec<_>>());
375+
#[allow(rustc::potential_query_instability)]
376+
let lints = self.by_name.keys().collect::<Vec<_>>();
377+
debug!("lints={:?}", lints);
378378
let tool_prefix = format!("{tool_name}::");
379+
380+
#[allow(rustc::potential_query_instability)]
379381
return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) {
380382
self.no_lint_suggestion(&complete_name, tool_name.as_str())
381383
} else {

compiler/rustc_lint/src/context/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub(super) fn builtin(
185185
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");
186186
}
187187
BuiltinLintDiagnostics::UnexpectedCfgName((name, name_span), value) => {
188+
#[allow(rustc::potential_query_instability)]
188189
let possibilities: Vec<Symbol> =
189190
sess.parse_sess.check_config.expecteds.keys().copied().collect();
190191
let is_from_cargo = std::env::var_os("CARGO").is_some();

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
513513
}
514514

515515
while !vid_map.is_empty() {
516+
#[allow(rustc::potential_query_instability)]
516517
let target = *vid_map.keys().next().expect("Keys somehow empty");
517518
let deps = vid_map.remove(&target).expect("Entry somehow missing");
518519

library/std/src/collections/hash/map.rs

+3
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ impl<K, V, S> HashMap<K, V, S> {
356356
///
357357
/// In the current implementation, iterating over keys takes O(capacity) time
358358
/// instead of O(len) because it internally visits empty buckets too.
359+
#[rustc_lint_query_instability]
359360
#[stable(feature = "rust1", since = "1.0.0")]
360361
pub fn keys(&self) -> Keys<'_, K, V> {
361362
Keys { inner: self.iter() }
@@ -417,6 +418,7 @@ impl<K, V, S> HashMap<K, V, S> {
417418
///
418419
/// In the current implementation, iterating over values takes O(capacity) time
419420
/// instead of O(len) because it internally visits empty buckets too.
421+
#[rustc_lint_query_instability]
420422
#[stable(feature = "rust1", since = "1.0.0")]
421423
pub fn values(&self) -> Values<'_, K, V> {
422424
Values { inner: self.iter() }
@@ -449,6 +451,7 @@ impl<K, V, S> HashMap<K, V, S> {
449451
///
450452
/// In the current implementation, iterating over values takes O(capacity) time
451453
/// instead of O(len) because it internally visits empty buckets too.
454+
#[rustc_lint_query_instability]
452455
#[stable(feature = "map_values_mut", since = "1.10.0")]
453456
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> {
454457
ValuesMut { inner: self.iter_mut() }

tests/ui-fulldeps/internal-lints/query_stability.rs

+13
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ fn main() {
2121

2222
for _ in x {}
2323
//~^ ERROR using `into_iter`
24+
25+
let x = FxHashMap::<u32, i32>::default();
26+
let _ = x.keys();
27+
//~^ ERROR using `keys` can result in unstable query results
28+
29+
let _ = x.values();
30+
//~^ ERROR using `values` can result in unstable query results
31+
32+
let mut x = FxHashMap::<u32, i32>::default();
33+
for val in x.values_mut() {
34+
//~^ ERROR using `values_mut` can result in unstable query results
35+
*val = *val + 10;
36+
}
2437
}

tests/ui-fulldeps/internal-lints/query_stability.stderr

+25-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,29 @@ LL | for _ in x {}
3535
|
3636
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
3737

38-
error: aborting due to 4 previous errors
38+
error: using `keys` can result in unstable query results
39+
--> $DIR/query_stability.rs:26:15
40+
|
41+
LL | let _ = x.keys();
42+
| ^^^^
43+
|
44+
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
45+
46+
error: using `values` can result in unstable query results
47+
--> $DIR/query_stability.rs:29:15
48+
|
49+
LL | let _ = x.values();
50+
| ^^^^^^
51+
|
52+
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
53+
54+
error: using `values_mut` can result in unstable query results
55+
--> $DIR/query_stability.rs:33:18
56+
|
57+
LL | for val in x.values_mut() {
58+
| ^^^^^^^^^^
59+
|
60+
= note: if you believe this case to be fine, allow this lint and add a comment explaining your rationale
61+
62+
error: aborting due to 7 previous errors
3963

0 commit comments

Comments
 (0)