Skip to content

Commit 01adb7e

Browse files
committed
stop evaluating constants in Relate
1 parent 060f3e0 commit 01adb7e

File tree

7 files changed

+11
-56
lines changed

7 files changed

+11
-56
lines changed

compiler/rustc_middle/src/ty/relate.rs

-4
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,6 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
594594
);
595595
}
596596

597-
let eagerly_eval = |x: ty::Const<'tcx>| x.eval(tcx, relation.param_env());
598-
let a = eagerly_eval(a);
599-
let b = eagerly_eval(b);
600-
601597
// Currently, the values that can be unified are primitive types,
602598
// and those that derive both `PartialEq` and `Eq`, corresponding
603599
// to structural-match types.

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
635635

636636
#[instrument(skip(self), level = "debug")]
637637
fn fold_const(&mut self, constant: ty::Const<'tcx>) -> ty::Const<'tcx> {
638-
if self.selcx.tcx().lazy_normalization() || !self.eager_inference_replacement {
638+
if self.selcx.tcx().lazy_normalization() {
639639
constant
640640
} else {
641641
let constant = constant.super_fold_with(self);

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
495495

496496
pub fn to_const(&self, ast_c: &hir::AnonConst) -> ty::Const<'tcx> {
497497
let const_def_id = self.tcx.hir().local_def_id(ast_c.hir_id);
498+
let span = self.tcx.hir().span(ast_c.hir_id);
498499
let c = ty::Const::from_anon_const(self.tcx, const_def_id);
499-
self.register_wf_obligation(
500-
c.into(),
501-
self.tcx.hir().span(ast_c.hir_id),
502-
ObligationCauseCode::WellFormed(None),
503-
);
504-
c
500+
self.register_wf_obligation(c.into(), span, ObligationCauseCode::WellFormed(None));
501+
self.normalize_associated_types_in(span, c)
505502
}
506503

507504
pub fn const_arg_to_const(

src/test/ui/closures/issue-52437.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ fn main() {
22
[(); &(&'static: loop { |x| {}; }) as *const _ as usize]
33
//~^ ERROR: invalid label name `'static`
44
//~| ERROR: type annotations needed
5-
//~| ERROR mismatched types
65
}

src/test/ui/closures/issue-52437.stderr

+2-11
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ help: consider giving this closure parameter an explicit type
1515
LL | [(); &(&'static: loop { |x: _| {}; }) as *const _ as usize]
1616
| +++
1717

18-
error[E0308]: mismatched types
19-
--> $DIR/issue-52437.rs:2:5
20-
|
21-
LL | fn main() {
22-
| - expected `()` because of default return type
23-
LL | [(); &(&'static: loop { |x| {}; }) as *const _ as usize]
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[(); _]`
25-
26-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
2719

28-
Some errors have detailed explanations: E0282, E0308.
29-
For more information about an error, try `rustc --explain E0282`.
20+
For more information about this error, try `rustc --explain E0282`.

src/test/ui/issues/issue-66706.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ fn a() {
22
[0; [|_: _ &_| ()].len()]
33
//~^ ERROR expected `,`, found `&`
44
//~| ERROR type annotations needed
5-
//~| ERROR mismatched types
65
}
76

87
fn b() {
@@ -13,13 +12,11 @@ fn b() {
1312
fn c() {
1413
[0; [|&_: _ &_| {}; 0 ].len()]
1514
//~^ ERROR expected `,`, found `&`
16-
//~| ERROR mismatched types
1715
}
1816

1917
fn d() {
2018
[0; match [|f @ &ref _| () ] {} ]
2119
//~^ ERROR expected identifier, found reserved identifier `_`
22-
//~| ERROR mismatched types
2320
}
2421

2522
fn main() {}

src/test/ui/issues/issue-66706.stderr

+5-30
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ LL | [0; [|_: _ &_| ()].len()]
77
| help: missing `,`
88

99
error: expected identifier, found reserved identifier `_`
10-
--> $DIR/issue-66706.rs:9:20
10+
--> $DIR/issue-66706.rs:8:20
1111
|
1212
LL | [0; [|f @ &ref _| {} ; 0 ].len() ];
1313
| ^ expected identifier, found reserved identifier
1414

1515
error: expected `,`, found `&`
16-
--> $DIR/issue-66706.rs:14:17
16+
--> $DIR/issue-66706.rs:13:17
1717
|
1818
LL | [0; [|&_: _ &_| {}; 0 ].len()]
1919
| -^ expected `,`
2020
| |
2121
| help: missing `,`
2222

2323
error: expected identifier, found reserved identifier `_`
24-
--> $DIR/issue-66706.rs:20:26
24+
--> $DIR/issue-66706.rs:18:26
2525
|
2626
LL | [0; match [|f @ &ref _| () ] {} ]
2727
| ^ expected identifier, found reserved identifier
@@ -32,31 +32,6 @@ error[E0282]: type annotations needed
3232
LL | [0; [|_: _ &_| ()].len()]
3333
| ^ cannot infer type
3434

35-
error[E0308]: mismatched types
36-
--> $DIR/issue-66706.rs:2:5
37-
|
38-
LL | fn a() {
39-
| - help: try adding a return type: `-> [i32; _]`
40-
LL | [0; [|_: _ &_| ()].len()]
41-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
42-
43-
error[E0308]: mismatched types
44-
--> $DIR/issue-66706.rs:14:5
45-
|
46-
LL | fn c() {
47-
| - help: try adding a return type: `-> [i32; _]`
48-
LL | [0; [|&_: _ &_| {}; 0 ].len()]
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
50-
51-
error[E0308]: mismatched types
52-
--> $DIR/issue-66706.rs:20:5
53-
|
54-
LL | fn d() {
55-
| - help: try adding a return type: `-> [i32; _]`
56-
LL | [0; match [|f @ &ref _| () ] {} ]
57-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found array `[{integer}; _]`
58-
59-
error: aborting due to 8 previous errors
35+
error: aborting due to 5 previous errors
6036

61-
Some errors have detailed explanations: E0282, E0308.
62-
For more information about an error, try `rustc --explain E0282`.
37+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)