Skip to content

Commit a0cd8a2

Browse files
committed
Fix more ui tests
1 parent 6dfe452 commit a0cd8a2

File tree

11 files changed

+67
-46
lines changed

11 files changed

+67
-46
lines changed

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl<'tcx> TraitRef<'tcx> {
816816
}
817817

818818
// TODO remove this hack!
819-
pub fn normalize_constness_equate(&self, tcx: TyCtxt<'tcx>, actual: &mut Self) {
819+
pub fn normalize_constness_equate(&self, tcx: TyCtxt<'tcx>, actual: &mut SubstsRef<'tcx>) {
820820
if self.constness() == ty::ConstnessArg::Not {
821821
*actual = tcx.mk_substs(actual.iter().filter(|arg| match arg.unpack() {
822822
ty::subst::GenericArgKind::Constness(_) => false,

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
4848
// when const_trait_impl not enabled, all const predicates are unimplemented
4949
if obligation.predicate.constness() == ty::ConstnessArg::Const {
5050
if !self.tcx().features().enabled(sym::const_trait_impl) {
51-
return Err(SelectionError::Unimplemented)
51+
return Err(SelectionError::Unimplemented);
5252
}
5353
}
5454
// TODO rm

compiler/rustc_trait_selection/src/traits/select/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2155,10 +2155,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21552155
self.infcx().replace_bound_vars_with_placeholders(obligation.predicate);
21562156
let placeholder_obligation_trait_ref = placeholder_obligation.trait_ref;
21572157

2158-
let impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
2158+
let mut impl_substs = self.infcx.fresh_substs_for_item(obligation.cause.span, impl_def_id);
21592159

2160-
let mut impl_trait_ref = impl_trait_ref.subst(self.tcx(), impl_substs);
2161-
placeholder_obligation_trait_ref.normalize_constness_equate(self.tcx(), &mut impl_trait_ref);
2160+
placeholder_obligation_trait_ref.normalize_constness_equate(self.tcx(), &mut impl_substs);
2161+
2162+
let impl_trait_ref = impl_trait_ref.subst(self.tcx(), impl_substs);
21622163

21632164
debug!(?impl_trait_ref);
21642165

compiler/rustc_typeck/src/check/method/probe.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18431843
};
18441844
self.next_const_var(self.tcx.type_of(param.def_id), origin).into()
18451845
}
1846-
GenericParamDefKind::Constness => self.fcx.constness().into(),
1846+
// there is no need to require constness even when we are in a const context.
1847+
// just check if the trait is implemented.
1848+
GenericParamDefKind::Constness => ty::ConstnessArg::Not.into(),
18471849
})
18481850
}
18491851

compiler/rustc_typeck/src/check/wfcheck.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -1833,20 +1833,10 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI
18331833
let /* mut */ pred = fcx.normalize_associated_types_in(span, pred);
18341834
let hir_node = fcx.tcx.hir().find(id);
18351835

1836-
if fcx.constness() == ty::ConstnessArg::Not {
1837-
struct NotConstFolder<'tcx>(TyCtxt<'tcx>); // TODO justify this hack
1838-
1839-
impl<'tcx> ty::TypeFolder<'tcx> for NotConstFolder<'tcx> {
1840-
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
1841-
self.0
1842-
}
1843-
fn fold_constness(&mut self, _: ty::ConstnessArg) -> ty::ConstnessArg {
1844-
ty::ConstnessArg::Not
1845-
}
1846-
}
1847-
1848-
pred = pred.fold_with(&mut NotConstFolder(fcx.tcx))
1849-
}
1836+
// TODO
1837+
/*if fcx.constness() == ty::ConstnessArg::Not {
1838+
pred = pred.without_const(fcx.tcx)
1839+
}*/
18501840

18511841
// only use the span of the predicate clause (#90869)
18521842

compiler/rustc_typeck/src/collect.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,9 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
16241624
};
16251625

16261626
let has_self = opt_self.is_some();
1627-
let has_constness = tcx.has_attr(def_id, sym::const_trait) || (tcx.def_kind(def_id) == DefKind::Impl && tcx.impl_constness(def_id) == hir::Constness::Const);
1627+
let has_constness = tcx.has_attr(def_id, sym::const_trait)
1628+
|| (tcx.def_kind(def_id) == DefKind::Impl
1629+
&& tcx.impl_constness(def_id) == hir::Constness::Const);
16281630
let mut parent_has_self = false;
16291631
let mut parent_has_constness = false;
16301632
let mut own_start = has_self as u32;

src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ pub const fn add_i32(a: i32, b: i32) -> i32 {
2323

2424
pub const fn add_u32(a: u32, b: u32) -> u32 {
2525
a.plus(b)
26-
//~^ ERROR no method named `plus` found for type `u32` in the current scope
26+
//~^ ERROR the trait bound
27+
//~| ERROR cannot call
2728
}
2829

2930
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
error[E0599]: no method named `plus` found for type `u32` in the current scope
1+
error[E0277]: the trait bound `u32: Plus<Const>` is not satisfied
22
--> $DIR/call-const-trait-method-fail.rs:25:7
33
|
44
LL | a.plus(b)
5-
| ^^^^ method not found in `u32`
5+
| ^^^^^^^ the trait `Plus<Const>` is not implemented for `u32`
66
|
7-
= help: items from traits can only be used if the trait is implemented and in scope
8-
note: `Plus` defines an item `plus`, perhaps you need to implement it
9-
--> $DIR/call-const-trait-method-fail.rs:4:1
7+
note: the trait `Plus<Not>` is implemented for `u32`, but that implementation is not `const`
8+
--> $DIR/call-const-trait-method-fail.rs:25:7
9+
|
10+
LL | a.plus(b)
11+
| ^^^^^^^
12+
= help: the following other types implement trait `Plus<Not>`:
13+
<i32 as Plus<Const>>
14+
<u32 as Plus<Not>>
15+
16+
error[E0015]: cannot call non-const fn `<u32 as Plus<Const>>::plus` in constant functions
17+
--> $DIR/call-const-trait-method-fail.rs:25:7
18+
|
19+
LL | a.plus(b)
20+
| ^^^^^^^
1021
|
11-
LL | pub trait Plus {
12-
| ^^^^^^^^^^^^^^
22+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1323

1424
error: aborting due to 2 previous errors
1525

16-
For more information about this error, try `rustc --explain E0599`.
26+
Some errors have detailed explanations: E0015, E0277.
27+
For more information about an error, try `rustc --explain E0015`.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
error[E0599]: no method named `func` found for struct `cross_crate::NonConst` in the current scope
2-
--> $DIR/cross-crate.rs:10:14
1+
error[E0277]: the trait bound `NonConst: MyTrait<Const>` is not satisfied
2+
--> $DIR/cross-crate.rs:15:14
3+
|
4+
LL | NonConst.func();
5+
| ^^^^^^ the trait `MyTrait<Const>` is not implemented for `NonConst`
6+
|
7+
note: the trait `MyTrait<Not>` is implemented for `NonConst`, but that implementation is not `const`
8+
--> $DIR/cross-crate.rs:15:14
39
|
410
LL | NonConst.func();
5-
| ^^^^ method not found in `cross_crate::NonConst`
11+
| ^^^^^^
12+
= help: the trait `MyTrait<Not>` is implemented for `NonConst`
613

7-
error[E0599]: no method named `func` found for struct `cross_crate::NonConst` in the current scope
14+
error[E0015]: cannot call non-const fn `<NonConst as MyTrait<Const>>::func` in constant functions
815
--> $DIR/cross-crate.rs:15:14
916
|
1017
LL | NonConst.func();
11-
| ^^^^ method not found in `cross_crate::NonConst`
18+
| ^^^^^^
19+
|
20+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1221

1322
error: aborting due to 2 previous errors
1423

15-
For more information about this error, try `rustc --explain E0599`.
24+
Some errors have detailed explanations: E0015, E0277.
25+
For more information about an error, try `rustc --explain E0015`.

src/test/ui/rfc-2632-const-trait-impl/cross-crate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ fn non_const_context() {
1212
}
1313

1414
const fn const_context() {
15-
NonConst.func(); //~ ERROR: cannot call non-const fn
15+
NonConst.func(); //~ ERROR: cannot call
1616
//[gated]~^ ERROR: the trait bound
1717
Const.func();
18-
//[stock]~^ ERROR: cannot call non-const fn
18+
//[stock]~^ ERROR: cannot call
1919
}
2020

2121
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
error[E0599]: no method named `func` found for struct `cross_crate::NonConst` in the current scope
2-
--> $DIR/cross-crate.rs:10:14
1+
error[E0015]: cannot call non-const fn `<NonConst as MyTrait<Const>>::func` in constant functions
2+
--> $DIR/cross-crate.rs:15:14
33
|
44
LL | NonConst.func();
5-
| ^^^^ method not found in `cross_crate::NonConst`
5+
| ^^^^^^
6+
|
7+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
68

7-
error[E0599]: no method named `func` found for struct `cross_crate::NonConst` in the current scope
8-
--> $DIR/cross-crate.rs:15:14
9+
error[E0015]: cannot call non-const fn `<Const as MyTrait<Const>>::func` in constant functions
10+
--> $DIR/cross-crate.rs:17:11
911
|
10-
LL | NonConst.func();
11-
| ^^^^ method not found in `cross_crate::NonConst`
12+
LL | Const.func();
13+
| ^^^^^^
14+
|
15+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1216

1317
error: aborting due to 2 previous errors
1418

15-
For more information about this error, try `rustc --explain E0599`.
19+
For more information about this error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)