Skip to content

Commit 8eb9f70

Browse files
Stop using Key trait randomly
1 parent 6dec76f commit 8eb9f70

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Not in interpret to make sure we do not use private implementation details
22

33
use rustc_abi::{FieldIdx, VariantIdx};
4-
use rustc_middle::query::Key;
54
use rustc_middle::ty::{self, Ty, TyCtxt};
65
use rustc_middle::{bug, mir};
6+
use rustc_span::DUMMY_SP;
77
use tracing::instrument;
88

99
use crate::interpret::InterpCx;
@@ -71,8 +71,7 @@ pub fn tag_for_variant_provider<'tcx>(
7171
let (ty, variant_index) = key.value;
7272
assert!(ty.is_enum());
7373

74-
let ecx =
75-
InterpCx::new(tcx, ty.default_span(tcx), key.typing_env, crate::const_eval::DummyMachine);
74+
let ecx = InterpCx::new(tcx, DUMMY_SP, key.typing_env, crate::const_eval::DummyMachine);
7675

7776
let layout = ecx.layout_of(ty).unwrap();
7877
ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag)

compiler/rustc_lint/src/map_unit_fn.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_hir::{Expr, ExprKind, HirId, Stmt, StmtKind};
2-
use rustc_middle::query::Key;
32
use rustc_middle::ty::{self, Ty};
43
use rustc_session::{declare_lint, declare_lint_pass};
54

@@ -69,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
6968
.span_of_impl(*id)
7069
.unwrap_or(default_span),
7170
argument_label: args[0].span,
72-
map_label: arg_ty.default_span(cx.tcx),
71+
map_label: span,
7372
suggestion: path.ident.span,
7473
replace: "for_each".to_string(),
7574
},
@@ -88,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
8887
.span_of_impl(*id)
8988
.unwrap_or(default_span),
9089
argument_label: args[0].span,
91-
map_label: arg_ty.default_span(cx.tcx),
90+
map_label: span,
9291
suggestion: path.ident.span,
9392
replace: "for_each".to_string(),
9493
},

tests/ui/lint/lint_map_unit_fn.stderr

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ LL + x.iter_mut().for_each(foo);
2525
error: `Iterator::map` call that discard the iterator's values
2626
--> $DIR/lint_map_unit_fn.rs:11:18
2727
|
28-
LL | x.iter_mut().map(|items| {
29-
| ^ -------
30-
| | |
31-
| ____________________|___this function returns `()`, which is likely not what you wanted
32-
| | __________________|
33-
| | |
34-
LL | | |
35-
LL | | | items.sort();
36-
LL | | | });
37-
| | | -^ after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
38-
| | |_____||
39-
| |_______|
40-
| called `Iterator::map` with callable that returns `()`
28+
LL | x.iter_mut().map(|items| {
29+
| ^ -------
30+
| | |
31+
| ___________________|___this function returns `()`, which is likely not what you wanted
32+
| | __________________|
33+
| ||
34+
LL | ||
35+
LL | || items.sort();
36+
LL | || });
37+
| ||_____-^ after this call to map, the resulting iterator is `impl Iterator<Item = ()>`, which means the only information carried by the iterator is the number of items
38+
| |______|
39+
| called `Iterator::map` with callable that returns `()`
4140
|
4241
= note: `Iterator::map`, like many of the methods on `Iterator`, gets executed lazily, meaning that its effects won't be visible until it is iterated
4342
help: you might have meant to use `Iterator::for_each`

0 commit comments

Comments
 (0)