Skip to content

Commit 71d688b

Browse files
committed
TypeVerifier do not walk into required consts
1 parent ad45962 commit 71d688b

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/mod.rs

+23-12
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
328328
}
329329
}
330330

331+
#[instrument(level = "debug", skip(self))]
331332
fn visit_const_operand(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
332-
debug!(?constant, ?location, "visit_const_operand");
333-
334333
self.super_const_operand(constant, location);
335334
let ty = constant.const_.ty();
336335

@@ -339,14 +338,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
339338
self.typeck.constraints.liveness_constraints.add_location(live_region_vid, location);
340339
});
341340

342-
// HACK(compiler-errors): Constants that are gathered into Body.required_consts
343-
// have their locations erased...
344-
let locations = if location != Location::START {
345-
location.to_locations()
346-
} else {
347-
Locations::All(constant.span)
348-
};
349-
341+
let locations = location.to_locations();
350342
if let Some(annotation_index) = constant.user_ty {
351343
if let Err(terr) = self.typeck.relate_type_and_user_type(
352344
constant.const_.ty(),
@@ -491,9 +483,28 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
491483
}
492484
}
493485

486+
#[instrument(level = "debug", skip(self))]
494487
fn visit_body(&mut self, body: &Body<'tcx>) {
495-
// The types of local_decls are checked above which is called in super_body.
496-
self.super_body(body);
488+
// We intentionally do not recursive into `body.required_consts` or
489+
// `body.mentioned_items` here as the MIR at this phase should still
490+
// refer to all items and we don't want to check them multiple times.
491+
492+
for (local, local_decl) in body.local_decls.iter_enumerated() {
493+
self.visit_local_decl(local, local_decl);
494+
}
495+
496+
for (block, block_data) in body.basic_blocks.iter_enumerated() {
497+
let mut location = Location { block, statement_index: 0 };
498+
for stmt in &block_data.statements {
499+
if !stmt.source_info.span.is_dummy() {
500+
self.last_span = stmt.source_info.span;
501+
}
502+
self.visit_statement(stmt, location);
503+
location.statement_index += 1;
504+
}
505+
506+
self.visit_terminator(block_data.terminator(), location);
507+
}
497508
}
498509
}
499510

Diff for: tests/ui/error-codes/E0582.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0308]: mismatched types
1414
--> $DIR/E0582.rs:22:5
1515
|
1616
LL | bar(mk_unexpected_char_err)
17-
| ^^^ one type is more general than the other
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
1818
|
1919
= note: expected enum `Option<&_>`
2020
found enum `Option<&'a _>`

Diff for: tests/ui/higher-ranked/trait-bounds/hrtb-just-for-static.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: implementation of `Foo` is not general enough
22
--> $DIR/hrtb-just-for-static.rs:24:5
33
|
44
LL | want_hrtb::<StaticInt>()
5-
| ^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
66
|
77
= note: `StaticInt` must implement `Foo<&'0 isize>`, for any lifetime `'0`...
88
= note: ...but it actually implements `Foo<&'static isize>`

Diff for: tests/ui/nll/issue-97997.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ fn main() {
1212

1313
<fn(&u8) as Foo>::ASSOC;
1414
//~^ ERROR implementation of `Foo` is not general enough
15-
//~| ERROR implementation of `Foo` is not general enough
1615
}

Diff for: tests/ui/nll/issue-97997.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,5 @@ LL | <fn(&u8) as Foo>::ASSOC;
77
= note: `Foo` would have to be implemented for the type `for<'a> fn(&'a u8)`
88
= note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0`
99

10-
error: implementation of `Foo` is not general enough
11-
--> $DIR/issue-97997.rs:13:5
12-
|
13-
LL | <fn(&u8) as Foo>::ASSOC;
14-
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
15-
|
16-
= note: `Foo` would have to be implemented for the type `for<'a> fn(&'a u8)`
17-
= note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0`
18-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19-
20-
error: aborting due to 2 previous errors
10+
error: aborting due to 1 previous error
2111

Diff for: tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ error[E0310]: the parameter type `A` may not live long enough
2828
--> $DIR/implied_lifetime_wf_check3.rs:52:5
2929
|
3030
LL | test_type_param::assert_static::<A>()
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232
| |
3333
| the parameter type `A` must be valid for the static lifetime...
3434
| ...so that the type `A` will meet its required lifetime bounds

Diff for: tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ error[E0310]: the parameter type `A` may not live long enough
2121
--> $DIR/implied_lifetime_wf_check4_static.rs:17:5
2222
|
2323
LL | assert_static::<A>()
24-
| ^^^^^^^^^^^^^^^^^^
24+
| ^^^^^^^^^^^^^^^^^^^^
2525
| |
2626
| the parameter type `A` must be valid for the static lifetime...
2727
| ...so that the type `A` will meet its required lifetime bounds

0 commit comments

Comments
 (0)