Skip to content

Commit 94149e9

Browse files
authored
Unrolled build for rust-lang#132227
Rollup merge of rust-lang#132227 - compiler-errors:better-const-span, r=Nadrieril Pass constness with span into lower_poly_trait_ref Gives us a span to point at for ~const/const on non-const traits. Split from rust-lang#132209. r? Nadrieril
2 parents 6929a48 + bd95695 commit 94149e9

38 files changed

+241
-254
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
168168
match hir_bound {
169169
hir::GenericBound::Trait(poly_trait_ref) => {
170170
let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers;
171-
// FIXME: We could pass these directly into `lower_poly_trait_ref`
172-
// so that we could use these spans in diagnostics within that function...
173-
let constness = match constness {
174-
hir::BoundConstness::Never => None,
175-
hir::BoundConstness::Always(_) => Some(ty::BoundConstness::Const),
176-
hir::BoundConstness::Maybe(_) => Some(ty::BoundConstness::ConstIfConst),
177-
};
178171
let polarity = match polarity {
179172
rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive,
180173
rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
5050
} = self.lower_poly_trait_ref(
5151
&trait_bound.trait_ref,
5252
trait_bound.span,
53-
None,
53+
hir::BoundConstness::Never,
5454
ty::PredicatePolarity::Positive,
5555
dummy_self,
5656
&mut bounds,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
658658
&self,
659659
trait_ref: &hir::TraitRef<'tcx>,
660660
span: Span,
661-
constness: Option<ty::BoundConstness>,
661+
constness: hir::BoundConstness,
662662
polarity: ty::PredicatePolarity,
663663
self_ty: Ty<'tcx>,
664664
bounds: &mut Bounds<'tcx>,
@@ -681,11 +681,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
681681
Some(self_ty),
682682
);
683683

684-
if let Some(constness) = constness
684+
if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
685685
&& !self.tcx().is_const_trait(trait_def_id)
686686
{
687687
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
688-
span: trait_ref.path.span,
688+
span,
689689
modifier: constness.as_str(),
690690
});
691691
}
@@ -708,7 +708,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
708708
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
709709

710710
match constness {
711-
Some(ty::BoundConstness::Const) => {
711+
hir::BoundConstness::Always(span) => {
712712
if polarity == ty::PredicatePolarity::Positive {
713713
bounds.push_const_bound(
714714
tcx,
@@ -718,13 +718,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
718718
);
719719
}
720720
}
721-
Some(ty::BoundConstness::ConstIfConst) => {
721+
hir::BoundConstness::Maybe(_) => {
722722
// We don't emit a const bound here, since that would mean that we
723723
// unconditionally need to prove a `HostEffect` predicate, even when
724724
// the predicates are being instantiated in a non-const context. This
725725
// is instead handled in the `const_conditions` query.
726726
}
727-
None => {}
727+
hir::BoundConstness::Never => {}
728728
}
729729
}
730730
// On the flip side, when filtering `ConstIfConst` bounds, we only need to convert
@@ -734,12 +734,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
734734
// here because we only call this on self bounds, and deal with the recursive case
735735
// in `lower_assoc_item_constraint`.
736736
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => match constness {
737-
Some(ty::BoundConstness::ConstIfConst) => {
737+
hir::BoundConstness::Maybe(span) => {
738738
if polarity == ty::PredicatePolarity::Positive {
739739
bounds.push_const_bound(tcx, poly_trait_ref, ty::HostPolarity::Maybe, span);
740740
}
741741
}
742-
None | Some(ty::BoundConstness::Const) => {}
742+
hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}
743743
},
744744
}
745745

tests/ui/consts/const-block-const-bound.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error: `~const` can only be applied to `#[const_trait]` traits
2-
--> $DIR/const-block-const-bound.rs:8:22
2+
--> $DIR/const-block-const-bound.rs:8:15
33
|
44
LL | const fn f<T: ~const Destruct>(x: T) {}
5-
| ^^^^^^^^
5+
| ^^^^^^
66

77
error: `~const` can only be applied to `#[const_trait]` traits
8-
--> $DIR/const-block-const-bound.rs:8:22
8+
--> $DIR/const-block-const-bound.rs:8:15
99
|
1010
LL | const fn f<T: ~const Destruct>(x: T) {}
11-
| ^^^^^^^^
11+
| ^^^^^^
1212
|
1313
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1414

tests/ui/consts/fn_trait_refs.stderr

+46-46
Original file line numberDiff line numberDiff line change
@@ -11,168 +11,168 @@ LL | #![feature(const_cmp)]
1111
| ^^^^^^^^^
1212

1313
error: `~const` can only be applied to `#[const_trait]` traits
14-
--> $DIR/fn_trait_refs.rs:13:15
14+
--> $DIR/fn_trait_refs.rs:13:8
1515
|
1616
LL | T: ~const Fn<()> + ~const Destruct,
17-
| ^^^^^^
17+
| ^^^^^^
1818

1919
error: `~const` can only be applied to `#[const_trait]` traits
20-
--> $DIR/fn_trait_refs.rs:13:31
20+
--> $DIR/fn_trait_refs.rs:13:24
2121
|
2222
LL | T: ~const Fn<()> + ~const Destruct,
23-
| ^^^^^^^^
23+
| ^^^^^^
2424

2525
error: `~const` can only be applied to `#[const_trait]` traits
26-
--> $DIR/fn_trait_refs.rs:13:15
26+
--> $DIR/fn_trait_refs.rs:13:8
2727
|
2828
LL | T: ~const Fn<()> + ~const Destruct,
29-
| ^^^^^^
29+
| ^^^^^^
3030
|
3131
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3232

3333
error: `~const` can only be applied to `#[const_trait]` traits
34-
--> $DIR/fn_trait_refs.rs:13:15
34+
--> $DIR/fn_trait_refs.rs:13:8
3535
|
3636
LL | T: ~const Fn<()> + ~const Destruct,
37-
| ^^^^^^
37+
| ^^^^^^
3838
|
3939
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4040

4141
error: `~const` can only be applied to `#[const_trait]` traits
42-
--> $DIR/fn_trait_refs.rs:13:31
42+
--> $DIR/fn_trait_refs.rs:13:24
4343
|
4444
LL | T: ~const Fn<()> + ~const Destruct,
45-
| ^^^^^^^^
45+
| ^^^^^^
4646
|
4747
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4848

4949
error: `~const` can only be applied to `#[const_trait]` traits
50-
--> $DIR/fn_trait_refs.rs:20:15
50+
--> $DIR/fn_trait_refs.rs:20:8
5151
|
5252
LL | T: ~const FnMut<()> + ~const Destruct,
53-
| ^^^^^^^^^
53+
| ^^^^^^
5454

5555
error: `~const` can only be applied to `#[const_trait]` traits
56-
--> $DIR/fn_trait_refs.rs:20:34
56+
--> $DIR/fn_trait_refs.rs:20:27
5757
|
5858
LL | T: ~const FnMut<()> + ~const Destruct,
59-
| ^^^^^^^^
59+
| ^^^^^^
6060

6161
error: `~const` can only be applied to `#[const_trait]` traits
62-
--> $DIR/fn_trait_refs.rs:20:15
62+
--> $DIR/fn_trait_refs.rs:20:8
6363
|
6464
LL | T: ~const FnMut<()> + ~const Destruct,
65-
| ^^^^^^^^^
65+
| ^^^^^^
6666
|
6767
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6868

6969
error: `~const` can only be applied to `#[const_trait]` traits
70-
--> $DIR/fn_trait_refs.rs:20:15
70+
--> $DIR/fn_trait_refs.rs:20:8
7171
|
7272
LL | T: ~const FnMut<()> + ~const Destruct,
73-
| ^^^^^^^^^
73+
| ^^^^^^
7474
|
7575
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
7676

7777
error: `~const` can only be applied to `#[const_trait]` traits
78-
--> $DIR/fn_trait_refs.rs:20:34
78+
--> $DIR/fn_trait_refs.rs:20:27
7979
|
8080
LL | T: ~const FnMut<()> + ~const Destruct,
81-
| ^^^^^^^^
81+
| ^^^^^^
8282
|
8383
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8484

8585
error: `~const` can only be applied to `#[const_trait]` traits
86-
--> $DIR/fn_trait_refs.rs:27:15
86+
--> $DIR/fn_trait_refs.rs:27:8
8787
|
8888
LL | T: ~const FnOnce<()>,
89-
| ^^^^^^^^^^
89+
| ^^^^^^
9090

9191
error: `~const` can only be applied to `#[const_trait]` traits
92-
--> $DIR/fn_trait_refs.rs:27:15
92+
--> $DIR/fn_trait_refs.rs:27:8
9393
|
9494
LL | T: ~const FnOnce<()>,
95-
| ^^^^^^^^^^
95+
| ^^^^^^
9696
|
9797
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9898

9999
error: `~const` can only be applied to `#[const_trait]` traits
100-
--> $DIR/fn_trait_refs.rs:27:15
100+
--> $DIR/fn_trait_refs.rs:27:8
101101
|
102102
LL | T: ~const FnOnce<()>,
103-
| ^^^^^^^^^^
103+
| ^^^^^^
104104
|
105105
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
106106

107107
error: `~const` can only be applied to `#[const_trait]` traits
108-
--> $DIR/fn_trait_refs.rs:34:15
108+
--> $DIR/fn_trait_refs.rs:34:8
109109
|
110110
LL | T: ~const Fn<()> + ~const Destruct,
111-
| ^^^^^^
111+
| ^^^^^^
112112

113113
error: `~const` can only be applied to `#[const_trait]` traits
114-
--> $DIR/fn_trait_refs.rs:34:31
114+
--> $DIR/fn_trait_refs.rs:34:24
115115
|
116116
LL | T: ~const Fn<()> + ~const Destruct,
117-
| ^^^^^^^^
117+
| ^^^^^^
118118

119119
error: `~const` can only be applied to `#[const_trait]` traits
120-
--> $DIR/fn_trait_refs.rs:34:15
120+
--> $DIR/fn_trait_refs.rs:34:8
121121
|
122122
LL | T: ~const Fn<()> + ~const Destruct,
123-
| ^^^^^^
123+
| ^^^^^^
124124
|
125125
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
126126

127127
error: `~const` can only be applied to `#[const_trait]` traits
128-
--> $DIR/fn_trait_refs.rs:34:15
128+
--> $DIR/fn_trait_refs.rs:34:8
129129
|
130130
LL | T: ~const Fn<()> + ~const Destruct,
131-
| ^^^^^^
131+
| ^^^^^^
132132
|
133133
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
134134

135135
error: `~const` can only be applied to `#[const_trait]` traits
136-
--> $DIR/fn_trait_refs.rs:34:31
136+
--> $DIR/fn_trait_refs.rs:34:24
137137
|
138138
LL | T: ~const Fn<()> + ~const Destruct,
139-
| ^^^^^^^^
139+
| ^^^^^^
140140
|
141141
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
142142

143143
error: `~const` can only be applied to `#[const_trait]` traits
144-
--> $DIR/fn_trait_refs.rs:48:15
144+
--> $DIR/fn_trait_refs.rs:48:8
145145
|
146146
LL | T: ~const FnMut<()> + ~const Destruct,
147-
| ^^^^^^^^^
147+
| ^^^^^^
148148

149149
error: `~const` can only be applied to `#[const_trait]` traits
150-
--> $DIR/fn_trait_refs.rs:48:34
150+
--> $DIR/fn_trait_refs.rs:48:27
151151
|
152152
LL | T: ~const FnMut<()> + ~const Destruct,
153-
| ^^^^^^^^
153+
| ^^^^^^
154154

155155
error: `~const` can only be applied to `#[const_trait]` traits
156-
--> $DIR/fn_trait_refs.rs:48:15
156+
--> $DIR/fn_trait_refs.rs:48:8
157157
|
158158
LL | T: ~const FnMut<()> + ~const Destruct,
159-
| ^^^^^^^^^
159+
| ^^^^^^
160160
|
161161
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
162162

163163
error: `~const` can only be applied to `#[const_trait]` traits
164-
--> $DIR/fn_trait_refs.rs:48:15
164+
--> $DIR/fn_trait_refs.rs:48:8
165165
|
166166
LL | T: ~const FnMut<()> + ~const Destruct,
167-
| ^^^^^^^^^
167+
| ^^^^^^
168168
|
169169
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
170170

171171
error: `~const` can only be applied to `#[const_trait]` traits
172-
--> $DIR/fn_trait_refs.rs:48:34
172+
--> $DIR/fn_trait_refs.rs:48:27
173173
|
174174
LL | T: ~const FnMut<()> + ~const Destruct,
175-
| ^^^^^^^^
175+
| ^^^^^^
176176
|
177177
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
178178

tests/ui/consts/unstable-const-fn-in-libcore.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
error: `~const` can only be applied to `#[const_trait]` traits
2-
--> $DIR/unstable-const-fn-in-libcore.rs:19:39
2+
--> $DIR/unstable-const-fn-in-libcore.rs:19:32
33
|
44
LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^
66

77
error: `~const` can only be applied to `#[const_trait]` traits
8-
--> $DIR/unstable-const-fn-in-libcore.rs:19:39
8+
--> $DIR/unstable-const-fn-in-libcore.rs:19:32
99
|
1010
LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
11-
| ^^^^^^^^^^^^^
11+
| ^^^^^^
1212
|
1313
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1414

tests/ui/impl-trait/normalize-tait-in-const.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
error: `~const` can only be applied to `#[const_trait]` traits
2-
--> $DIR/normalize-tait-in-const.rs:26:42
2+
--> $DIR/normalize-tait-in-const.rs:26:35
33
|
44
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
5-
| ^^^^^^^^^^^^^^^^^
5+
| ^^^^^^
66

77
error: `~const` can only be applied to `#[const_trait]` traits
8-
--> $DIR/normalize-tait-in-const.rs:26:69
8+
--> $DIR/normalize-tait-in-const.rs:26:62
99
|
1010
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
11-
| ^^^^^^^^
11+
| ^^^^^^
1212

1313
error: `~const` can only be applied to `#[const_trait]` traits
14-
--> $DIR/normalize-tait-in-const.rs:26:42
14+
--> $DIR/normalize-tait-in-const.rs:26:35
1515
|
1616
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
17-
| ^^^^^^^^^^^^^^^^^
17+
| ^^^^^^
1818
|
1919
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2020

2121
error: `~const` can only be applied to `#[const_trait]` traits
22-
--> $DIR/normalize-tait-in-const.rs:26:69
22+
--> $DIR/normalize-tait-in-const.rs:26:62
2323
|
2424
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
25-
| ^^^^^^^^
25+
| ^^^^^^
2626
|
2727
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
2828

0 commit comments

Comments
 (0)