Skip to content

Commit e51c5ea

Browse files
committed
Auto merge of #115392 - compiler-errors:coherence-spans, r=aliemjay
Don't record spans for predicates in coherence Should improve perf (#115107 (comment)) for #114023 (comment) r? aliemjay
2 parents b1b244d + 4647aea commit e51c5ea

File tree

7 files changed

+19
-37
lines changed

7 files changed

+19
-37
lines changed

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub struct ImplHeader<'tcx> {
238238
pub impl_def_id: DefId,
239239
pub self_ty: Ty<'tcx>,
240240
pub trait_ref: Option<TraitRef<'tcx>>,
241-
pub predicates: Vec<(Predicate<'tcx>, Span)>,
241+
pub predicates: Vec<Predicate<'tcx>>,
242242
}
243243

244244
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]

compiler/rustc_trait_selection/src/traits/coherence.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,14 @@ fn with_fresh_ty_vars<'cx, 'tcx>(
152152
.predicates_of(impl_def_id)
153153
.instantiate(tcx, impl_args)
154154
.iter()
155-
.map(|(c, s)| (c.as_predicate(), s))
155+
.map(|(c, _)| c.as_predicate())
156156
.collect(),
157157
};
158158

159-
let InferOk { value: mut header, obligations } = selcx
160-
.infcx
161-
.at(&ObligationCause::dummy_with_span(tcx.def_span(impl_def_id)), param_env)
162-
.normalize(header);
159+
let InferOk { value: mut header, obligations } =
160+
selcx.infcx.at(&ObligationCause::dummy(), param_env).normalize(header);
163161

164-
header.predicates.extend(obligations.into_iter().map(|o| (o.predicate, o.cause.span)));
162+
header.predicates.extend(obligations.into_iter().map(|o| o.predicate));
165163
header
166164
}
167165

@@ -261,17 +259,11 @@ fn overlap<'tcx>(
261259
infcx.tcx.def_span(impl2_header.impl_def_id),
262260
"the second impl is here",
263261
);
264-
if !failing_obligation.cause.span.is_dummy() {
265-
lint.span_label(
266-
failing_obligation.cause.span,
267-
format!(
268-
"`{}` may be considered to hold in future releases, \
269-
causing the impls to overlap",
270-
infcx
271-
.resolve_vars_if_possible(failing_obligation.predicate)
272-
),
273-
);
274-
}
262+
lint.note(format!(
263+
"`{}` may be considered to hold in future releases, \
264+
causing the impls to overlap",
265+
infcx.resolve_vars_if_possible(failing_obligation.predicate)
266+
));
275267
lint
276268
},
277269
);
@@ -355,8 +347,8 @@ fn impl_intersection_has_impossible_obligation<'cx, 'tcx>(
355347
[&impl1_header.predicates, &impl2_header.predicates]
356348
.into_iter()
357349
.flatten()
358-
.map(|&(predicate, span)| {
359-
Obligation::new(infcx.tcx, ObligationCause::dummy_with_span(span), param_env, predicate)
350+
.map(|&predicate| {
351+
Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, predicate)
360352
})
361353
.chain(obligations.into_iter().cloned())
362354
.find(|obligation: &PredicateObligation<'tcx>| {

tests/ui/coherence/warn-when-cycle-is-error-in-coherence.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ LL | #[derive(PartialEq, Default)]
66
...
77
LL | impl<T, Q> PartialEq<Q> for Interval<T>
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the first impl is here
9-
...
10-
LL | Q: ?Sized + PartialOrd,
11-
| ---------- `Interval<_>: PartialOrd` may be considered to hold in future releases, causing the impls to overlap
129
|
1310
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1411
= note: for more information, see issue #114040 <https://github.com/rust-lang/rust/issues/114040>
1512
= note: impls that are not considered to overlap may be considered to overlap in the future
13+
= note: `Interval<_>: PartialOrd` may be considered to hold in future releases, causing the impls to overlap
1614
note: the lint level is defined here
1715
--> $DIR/warn-when-cycle-is-error-in-coherence.rs:1:9
1816
|

tests/ui/traits/issue-105231.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
//~ ERROR overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send`
12
struct A<T>(B<T>);
23
//~^ ERROR recursive types `A` and `B` have infinite size
34
struct B<T>(A<A<T>>);
45
trait Foo {}
56
impl<T> Foo for T where T: Send {}
6-
//~^ ERROR overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send`
77
impl Foo for B<u8> {}
88

99
fn main() {}

tests/ui/traits/issue-105231.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0072]: recursive types `A` and `B` have infinite size
2-
--> $DIR/issue-105231.rs:1:1
2+
--> $DIR/issue-105231.rs:2:1
33
|
44
LL | struct A<T>(B<T>);
55
| ^^^^^^^^^^^ ---- recursive without indirection
@@ -15,14 +15,10 @@ LL ~ struct B<T>(Box<A<A<T>>>);
1515
|
1616

1717
error[E0275]: overflow evaluating the requirement `A<A<A<A<A<A<A<...>>>>>>>: Send`
18-
--> $DIR/issue-105231.rs:5:28
19-
|
20-
LL | impl<T> Foo for T where T: Send {}
21-
| ^^^^
2218
|
2319
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_105231`)
2420
note: required because it appears within the type `B<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<A<u8>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
25-
--> $DIR/issue-105231.rs:3:8
21+
--> $DIR/issue-105231.rs:4:8
2622
|
2723
LL | struct B<T>(A<A<T>>);
2824
| ^

tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//~ ERROR overflow
12
// A regression test for #111729 checking that we correctly
23
// track recursion depth for obligations returned by confirmation.
34
use std::panic::RefUnwindSafe;
@@ -14,7 +15,6 @@ struct RootDatabase {
1415
}
1516

1617
impl<T: RefUnwindSafe> Database for T {
17-
//~^ ERROR overflow
1818
type Storage = SalsaStorage;
1919
}
2020
impl Database for RootDatabase {

tests/ui/traits/solver-cycles/cycle-via-builtin-auto-trait-impl.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
error[E0275]: overflow evaluating the requirement `Runtime<RootDatabase>: RefUnwindSafe`
2-
--> $DIR/cycle-via-builtin-auto-trait-impl.rs:16:9
3-
|
4-
LL | impl<T: RefUnwindSafe> Database for T {
5-
| ^^^^^^^^^^^^^
62
|
73
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`cycle_via_builtin_auto_trait_impl`)
84
note: required because it appears within the type `RootDatabase`
9-
--> $DIR/cycle-via-builtin-auto-trait-impl.rs:12:8
5+
--> $DIR/cycle-via-builtin-auto-trait-impl.rs:13:8
106
|
117
LL | struct RootDatabase {
128
| ^^^^^^^^^^^^
139
note: required for `RootDatabase` to implement `Database`
14-
--> $DIR/cycle-via-builtin-auto-trait-impl.rs:16:24
10+
--> $DIR/cycle-via-builtin-auto-trait-impl.rs:17:24
1511
|
1612
LL | impl<T: RefUnwindSafe> Database for T {
1713
| ------------- ^^^^^^^^ ^

0 commit comments

Comments
 (0)