Skip to content

Commit b5d336f

Browse files
Rollup merge of #118245 - fee1-dead-contrib:span-tilde-const, r=compiler-errors
Add `Span` to `TraitBoundModifier` This improves diagnostics for the message "`~const` is not allowed here", and also fixes the span that we use when desugaring `~const Tr` into `Tr<host>` in effects desugaring.
2 parents 193e668 + 16040a1 commit b5d336f

20 files changed

+76
-78
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub enum TraitBoundModifier {
301301
Maybe,
302302

303303
/// `~const Trait`
304-
MaybeConst,
304+
MaybeConst(Span),
305305

306306
/// `~const !Trait`
307307
//
@@ -317,8 +317,7 @@ pub enum TraitBoundModifier {
317317
impl TraitBoundModifier {
318318
pub fn to_constness(self) -> Const {
319319
match self {
320-
// FIXME(effects) span
321-
Self::MaybeConst => Const::Yes(DUMMY_SP),
320+
Self::MaybeConst(span) => Const::Yes(span),
322321
_ => Const::No,
323322
}
324323
}
@@ -3155,7 +3154,7 @@ mod size_asserts {
31553154
static_assert_size!(ForeignItem, 96);
31563155
static_assert_size!(ForeignItemKind, 24);
31573156
static_assert_size!(GenericArg, 24);
3158-
static_assert_size!(GenericBound, 56);
3157+
static_assert_size!(GenericBound, 64);
31593158
static_assert_size!(Generics, 40);
31603159
static_assert_size!(Impl, 136);
31613160
static_assert_size!(Item, 136);

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13691369
GenericBound::Trait(
13701370
ty,
13711371
modifier @ (TraitBoundModifier::None
1372-
| TraitBoundModifier::MaybeConst
1372+
| TraitBoundModifier::MaybeConst(_)
13731373
| TraitBoundModifier::Negative),
13741374
) => {
13751375
Some(this.lower_poly_trait_ref(ty, itctx, modifier.to_constness()))
@@ -2227,7 +2227,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22272227
fn lower_trait_bound_modifier(&mut self, f: TraitBoundModifier) -> hir::TraitBoundModifier {
22282228
match f {
22292229
TraitBoundModifier::None => hir::TraitBoundModifier::None,
2230-
TraitBoundModifier::MaybeConst => hir::TraitBoundModifier::MaybeConst,
2230+
TraitBoundModifier::MaybeConst(_) => hir::TraitBoundModifier::MaybeConst,
22312231

22322232
TraitBoundModifier::Negative => {
22332233
if self.tcx.features().negative_bounds {

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12031203
(BoundKind::TraitObject, TraitBoundModifier::Maybe) => {
12041204
self.err_handler().emit_err(errors::OptionalTraitObject { span: poly.span });
12051205
}
1206-
(_, TraitBoundModifier::MaybeConst)
1206+
(_, &TraitBoundModifier::MaybeConst(span))
12071207
if let Some(reason) = &self.disallow_tilde_const =>
12081208
{
12091209
let reason = match reason {
@@ -1224,8 +1224,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12241224
}
12251225
DisallowTildeConstContext::Item => errors::TildeConstReason::Item,
12261226
};
1227-
self.err_handler()
1228-
.emit_err(errors::TildeConstDisallowed { span: bound.span(), reason });
1227+
self.err_handler().emit_err(errors::TildeConstDisallowed { span, reason });
12291228
}
12301229
(_, TraitBoundModifier::MaybeConstMaybe) => {
12311230
self.err_handler().emit_err(errors::OptionalConstExclusive {

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,7 @@ impl<'a> State<'a> {
15151515
TraitBoundModifier::Maybe => {
15161516
self.word("?");
15171517
}
1518-
TraitBoundModifier::MaybeConst => {
1518+
TraitBoundModifier::MaybeConst(_) => {
15191519
self.word_space("~const");
15201520
}
15211521
TraitBoundModifier::MaybeConstNegative => {

Diff for: compiler/rustc_expand/src/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind,
44
use rustc_ast::{attr, token, util::literal};
55
use rustc_span::source_map::Spanned;
66
use rustc_span::symbol::{kw, sym, Ident, Symbol};
7-
use rustc_span::Span;
7+
use rustc_span::{Span, DUMMY_SP};
88
use thin_vec::{thin_vec, ThinVec};
99

1010
impl<'a> ExtCtxt<'a> {
@@ -135,7 +135,7 @@ impl<'a> ExtCtxt<'a> {
135135
ast::GenericBound::Trait(
136136
self.poly_trait_ref(path.span, path),
137137
if is_const {
138-
ast::TraitBoundModifier::MaybeConst
138+
ast::TraitBoundModifier::MaybeConst(DUMMY_SP)
139139
} else {
140140
ast::TraitBoundModifier::None
141141
},

Diff for: compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl BoundModifiers {
3737
(BoundPolarity::Positive, None) => TraitBoundModifier::None,
3838
(BoundPolarity::Negative(_), None) => TraitBoundModifier::Negative,
3939
(BoundPolarity::Maybe(_), None) => TraitBoundModifier::Maybe,
40-
(BoundPolarity::Positive, Some(_)) => TraitBoundModifier::MaybeConst,
40+
(BoundPolarity::Positive, Some(sp)) => TraitBoundModifier::MaybeConst(sp),
4141
(BoundPolarity::Negative(_), Some(_)) => TraitBoundModifier::MaybeConstNegative,
4242
(BoundPolarity::Maybe(_), Some(_)) => TraitBoundModifier::MaybeConstMaybe,
4343
}

Diff for: src/tools/rustfmt/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl Rewrite for ast::GenericBound {
546546
ast::TraitBoundModifier::Maybe => poly_trait_ref
547547
.rewrite(context, shape.offset_left(1)?)
548548
.map(|s| format!("?{}", s)),
549-
ast::TraitBoundModifier::MaybeConst => poly_trait_ref
549+
ast::TraitBoundModifier::MaybeConst(_) => poly_trait_ref
550550
.rewrite(context, shape.offset_left(7)?)
551551
.map(|s| format!("~const {}", s)),
552552
ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/assoc-type-const-bound-usage.rs:7:17
33
|
44
LL | type Assoc: ~const Foo;
5-
| ^^^^^^^^^^
5+
| ^^^^^^
66
|
77
= note: this item cannot have `~const` trait bounds
88

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/assoc-type.rs:17:15
33
|
44
LL | type Bar: ~const std::ops::Add;
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^
66
|
77
= note: this item cannot have `~const` trait bounds
88

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/const-bound-on-not-const-associated-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/const-bound-on-not-const-associated-fn.rs:9:40
33
|
44
LL | fn do_something_else() where Self: ~const MyTrait;
5-
| ^^^^^^^^^^^^^^
5+
| ^^^^^^
66
|
77
note: this function is not `const`, so it cannot have `~const` trait bounds
88
--> $DIR/const-bound-on-not-const-associated-fn.rs:9:8
@@ -14,7 +14,7 @@ error: `~const` is not allowed here
1414
--> $DIR/const-bound-on-not-const-associated-fn.rs:20:32
1515
|
1616
LL | pub fn foo(&self) where T: ~const MyTrait {
17-
| ^^^^^^^^^^^^^^
17+
| ^^^^^^
1818
|
1919
note: this function is not `const`, so it cannot have `~const` trait bounds
2020
--> $DIR/const-bound-on-not-const-associated-fn.rs:20:12

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.precise.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/const-drop.rs:67:38
33
|
44
LL | pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>);
5-
| ^^^^^^^^^^^^^^^^
5+
| ^^^^^^
66
|
77
= note: this item cannot have `~const` trait bounds
88

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop.stock.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/const-drop.rs:67:38
33
|
44
LL | pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>);
5-
| ^^^^^^^^^^^^^^^^
5+
| ^^^^^^
66
|
77
= note: this item cannot have `~const` trait bounds
88

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/super-traits-fail-2.rs:11:12
33
|
44
LL | trait Bar: ~const Foo {}
5-
| ^^^^^^^^^^
5+
| ^^^^^^
66
|
77
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
88
--> $DIR/super-traits-fail-2.rs:11:1

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/super-traits-fail-2.rs:11:12
33
|
44
LL | trait Bar: ~const Foo {}
5-
| ^^^^^^^^^^
5+
| ^^^^^^
66
|
77
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
88
--> $DIR/super-traits-fail-2.rs:11:1

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/super-traits-fail-3.rs:13:12
33
|
44
LL | trait Bar: ~const Foo {}
5-
| ^^^^^^^^^^
5+
| ^^^^^^
66
|
77
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
88
--> $DIR/super-traits-fail-3.rs:13:1

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/super-traits-fail-3.rs:13:12
33
|
44
LL | trait Bar: ~const Foo {}
5-
| ^^^^^^^^^^
5+
| ^^^^^^
66
|
77
note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
88
--> $DIR/super-traits-fail-3.rs:13:1

Diff for: tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: `~const` is not allowed here
22
--> $DIR/tilde-const-and-const-params.rs:9:15
33
|
44
LL | fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> {
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^
66
|
77
note: this function is not `const`, so it cannot have `~const` trait bounds
88
--> $DIR/tilde-const-and-const-params.rs:9:8
@@ -14,7 +14,7 @@ error: `~const` is not allowed here
1414
--> $DIR/tilde-const-and-const-params.rs:27:11
1515
|
1616
LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> {
17-
| ^^^^^^^^^^^^
17+
| ^^^^^^
1818
|
1919
note: this function is not `const`, so it cannot have `~const` trait bounds
2020
--> $DIR/tilde-const-and-const-params.rs:27:4

0 commit comments

Comments
 (0)