Skip to content

Commit e77e8eb

Browse files
Don't store spans in assumed_wf_types actually
1 parent 0bddce5 commit e77e8eb

File tree

7 files changed

+43
-63
lines changed

7 files changed

+43
-63
lines changed

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ rustc_queries! {
803803
///
804804
/// Note that we've liberated the late bound regions of function signatures, so
805805
/// this can not be used to check whether these types are well formed.
806-
query assumed_wf_types(key: DefId) -> &'tcx [(Ty<'tcx>, Span)] {
806+
query assumed_wf_types(key: DefId) -> &'tcx ty::List<Ty<'tcx>> {
807807
desc { |tcx| "computing the implied bounds of `{}`", tcx.def_path_str(key) }
808808
}
809809

compiler/rustc_trait_selection/src/traits/engine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
191191
let assumed_wf_types = tcx.assumed_wf_types(def_id);
192192
let mut implied_bounds = FxIndexSet::default();
193193
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
194-
for &(ty, ty_span) in assumed_wf_types {
195-
let span = if ty_span.is_dummy() { span } else { ty_span };
194+
let cause = ObligationCause::misc(span, hir_id);
195+
for ty in assumed_wf_types {
196196
// FIXME(@lcnr): rustc currently does not check wf for types
197197
// pre-normalization, meaning that implied bounds are sometimes
198198
// incorrect. See #100910 for more details.
@@ -205,7 +205,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
205205
// sound and then uncomment this line again.
206206

207207
// implied_bounds.insert(ty);
208-
let normalized = self.normalize(&ObligationCause::misc(span, hir_id), param_env, ty);
208+
let normalized = self.normalize(&cause, param_env, ty);
209209
implied_bounds.insert(normalized);
210210
}
211211
implied_bounds
+10-57
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,33 @@
11
use crate::rustc_middle::ty::DefIdTree;
2-
use rustc_hir::{self as hir, def::DefKind, def_id::DefId};
2+
use rustc_hir::{def::DefKind, def_id::DefId};
33
use rustc_middle::ty::{self, Ty, TyCtxt};
4-
use rustc_span::{Span, DUMMY_SP};
54

65
pub fn provide(providers: &mut ty::query::Providers) {
76
*providers = ty::query::Providers { assumed_wf_types, ..*providers };
87
}
98

10-
fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &[(Ty<'_>, Span)] {
9+
fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
1110
match tcx.def_kind(def_id) {
1211
DefKind::Fn => {
1312
let sig = tcx.fn_sig(def_id);
1413
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig);
15-
if let Some(node) = tcx.hir().get_if_local(def_id)
16-
&& let Some(decl) = node.fn_decl()
17-
{
18-
assert_eq!(decl.inputs.len(), liberated_sig.inputs().len());
19-
tcx.arena.alloc_from_iter(std::iter::zip(
20-
liberated_sig.inputs_and_output,
21-
decl.inputs.iter().map(|ty| ty.span).chain([decl.output.span()]),
22-
))
23-
} else {
24-
tcx.arena.alloc_from_iter(
25-
liberated_sig.inputs_and_output.iter().map(|ty| (ty, DUMMY_SP)),
26-
)
27-
}
14+
liberated_sig.inputs_and_output
2815
}
2916
DefKind::AssocFn => {
3017
let sig = tcx.fn_sig(def_id);
3118
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig);
32-
let assumed_wf_types = tcx.assumed_wf_types(tcx.parent(def_id));
33-
if let Some(node) = tcx.hir().get_if_local(def_id)
34-
&& let Some(decl) = node.fn_decl()
35-
{
36-
assert_eq!(decl.inputs.len(), liberated_sig.inputs().len());
37-
tcx.arena.alloc_from_iter(assumed_wf_types.iter().copied().chain(std::iter::zip(
38-
liberated_sig.inputs_and_output,
39-
decl.inputs.iter().map(|ty| ty.span).chain([decl.output.span()]),
40-
)))
41-
} else {
42-
tcx.arena.alloc_from_iter(assumed_wf_types.iter().copied().chain(
43-
liberated_sig.inputs_and_output.iter().map(|ty| (ty, DUMMY_SP)),
44-
))
45-
}
19+
let mut assumed_wf_types: Vec<_> =
20+
tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into();
21+
assumed_wf_types.extend(liberated_sig.inputs_and_output);
22+
tcx.intern_type_list(&assumed_wf_types)
4623
}
4724
DefKind::Impl => match tcx.impl_trait_ref(def_id) {
4825
Some(trait_ref) => {
4926
let types: Vec<_> = trait_ref.substs.types().collect();
50-
let self_span = if let Some(hir::Node::Item(hir::Item {
51-
kind: hir::ItemKind::Impl(impl_),
52-
..
53-
})) = tcx.hir().get_if_local(def_id)
54-
{
55-
impl_.self_ty.span
56-
} else {
57-
DUMMY_SP
58-
};
59-
tcx.arena.alloc_from_iter(std::iter::zip(
60-
types,
61-
// FIXME: reliable way of getting trait ref substs...
62-
[self_span].into_iter().chain(std::iter::repeat(DUMMY_SP)),
63-
))
27+
tcx.intern_type_list(&types)
6428
}
6529
// Only the impl self type
66-
None => {
67-
let span = if let Some(hir::Node::Item(hir::Item {
68-
kind: hir::ItemKind::Impl(impl_),
69-
..
70-
})) = tcx.hir().get_if_local(def_id)
71-
{
72-
impl_.self_ty.span
73-
} else {
74-
DUMMY_SP
75-
};
76-
tcx.arena.alloc_from_iter([(tcx.type_of(def_id), span)])
77-
}
30+
None => tcx.intern_type_list(&[tcx.type_of(def_id)]),
7831
},
7932
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
8033
DefKind::Mod
@@ -103,6 +56,6 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &[(Ty<'_>, Span)] {
10356
| DefKind::LifetimeParam
10457
| DefKind::GlobalAsm
10558
| DefKind::Closure
106-
| DefKind::Generator => &[],
59+
| DefKind::Generator => ty::List::empty(),
10760
}
10861
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ trait Trait2<'a> {
77

88
fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
99
//~^ ERROR the trait bound `for<'a> (): Trait2<'a>` is not satisfied
10+
//~| ERROR the trait bound `for<'a> (): Trait2<'a>` is not satisfied
1011
let _e: (usize, usize) = unsafe{mem::transmute(param)};
1112
}
1213

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
44
LL | fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
55
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
66

7-
error: aborting due to previous error
7+
error[E0277]: the trait bound `for<'a> (): Trait2<'a>` is not satisfied
8+
--> $DIR/issue-35570.rs:8:1
9+
|
10+
LL | / fn _ice(param: Box<dyn for <'a> Trait1<<() as Trait2<'a>>::Ty>>) {
11+
LL | |
12+
LL | |
13+
LL | | let _e: (usize, usize) = unsafe{mem::transmute(param)};
14+
LL | | }
15+
| |_^ the trait `for<'a> Trait2<'a>` is not implemented for `()`
16+
17+
error: aborting due to 2 previous errors
818

919
For more information about this error, try `rustc --explain E0277`.

src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait Trait2<'a, 'b> {
2020
// do not infer that.
2121
fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
2222
//~^ ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
23+
//~| ERROR the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
2324
{
2425
}
2526

src/test/ui/regions/regions-implied-bounds-projection-gap-hr-1.stderr

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ help: consider restricting type parameter `T`
99
LL | fn callee<'x, 'y, T: for<'z> Trait2<'y, 'z>>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
1010
| ++++++++++++++++++++++++
1111

12-
error: aborting due to previous error
12+
error[E0277]: the trait bound `for<'z> T: Trait2<'y, 'z>` is not satisfied
13+
--> $DIR/regions-implied-bounds-projection-gap-hr-1.rs:21:1
14+
|
15+
LL | / fn callee<'x, 'y, T>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
16+
LL | |
17+
LL | |
18+
LL | | {
19+
LL | | }
20+
| |_^ the trait `for<'z> Trait2<'y, 'z>` is not implemented for `T`
21+
|
22+
help: consider restricting type parameter `T`
23+
|
24+
LL | fn callee<'x, 'y, T: for<'z> Trait2<'y, 'z>>(t: &'x dyn for<'z> Trait1< <T as Trait2<'y, 'z>>::Foo >)
25+
| ++++++++++++++++++++++++
26+
27+
error: aborting due to 2 previous errors
1328

1429
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)