Skip to content

Commit 988eee9

Browse files
committed
Use SpanId in inferred_outlives_of.
1 parent 7249512 commit 988eee9

File tree

28 files changed

+146
-123
lines changed

28 files changed

+146
-123
lines changed

src/librustc_infer/traits/util.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::traits::{Obligation, ObligationCause, PredicateObligation};
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_middle::ty::outlives::Component;
66
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, TyCtxt, WithConstness};
7-
use rustc_span::Span;
7+
use rustc_span::SpanId;
88

99
pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
@@ -112,7 +112,8 @@ pub fn elaborate_predicates<'tcx>(
112112
tcx: TyCtxt<'tcx>,
113113
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
114114
) -> Elaborator<'tcx> {
115-
let obligations = predicates.map(|predicate| predicate_obligation(predicate, None)).collect();
115+
let obligations =
116+
predicates.map(|predicate| predicate_obligation(tcx, predicate, None)).collect();
116117
elaborate_obligations(tcx, obligations)
117118
}
118119

@@ -126,12 +127,13 @@ pub fn elaborate_obligations<'tcx>(
126127
}
127128

128129
fn predicate_obligation<'tcx>(
130+
tcx: TyCtxt<'tcx>,
129131
predicate: ty::Predicate<'tcx>,
130-
span: Option<Span>,
132+
span: Option<SpanId>,
131133
) -> PredicateObligation<'tcx> {
132134
let mut cause = ObligationCause::dummy();
133135
if let Some(span) = span {
134-
cause.span = span;
136+
cause.span = tcx.reify_span(span);
135137
}
136138
Obligation { cause, param_env: ty::ParamEnv::empty(), recursion_depth: 0, predicate }
137139
}
@@ -150,6 +152,7 @@ impl Elaborator<'tcx> {
150152

151153
let obligations = predicates.predicates.iter().map(|(pred, span)| {
152154
predicate_obligation(
155+
tcx,
153156
pred.subst_supertrait(tcx, &data.to_poly_trait_ref()),
154157
Some(*span),
155158
)
@@ -245,7 +248,7 @@ impl Elaborator<'tcx> {
245248
}
246249
})
247250
.filter(|p| visited.insert(p))
248-
.map(|p| predicate_obligation(p, None)),
251+
.map(|p| predicate_obligation(tcx, p, None)),
249252
);
250253
}
251254
}

src/librustc_lint/builtin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_session::lint::FutureIncompatibleInfo;
4242
use rustc_span::edition::Edition;
4343
use rustc_span::source_map::Spanned;
4444
use rustc_span::symbol::{kw, sym, Ident, Symbol};
45-
use rustc_span::{BytePos, Span};
45+
use rustc_span::{BytePos, Span, SpanId};
4646
use rustc_target::abi::VariantIdx;
4747
use rustc_trait_selection::traits::misc::can_type_implement_copy;
4848

@@ -1491,7 +1491,7 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
14911491

14921492
impl ExplicitOutlivesRequirements {
14931493
fn lifetimes_outliving_lifetime<'tcx>(
1494-
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
1494+
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, SpanId)],
14951495
index: u32,
14961496
) -> Vec<ty::Region<'tcx>> {
14971497
inferred_outlives
@@ -1510,7 +1510,7 @@ impl ExplicitOutlivesRequirements {
15101510
}
15111511

15121512
fn lifetimes_outliving_type<'tcx>(
1513-
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
1513+
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, SpanId)],
15141514
index: u32,
15151515
) -> Vec<ty::Region<'tcx>> {
15161516
inferred_outlives
@@ -1529,7 +1529,7 @@ impl ExplicitOutlivesRequirements {
15291529
&self,
15301530
param: &'tcx hir::GenericParam<'tcx>,
15311531
tcx: TyCtxt<'tcx>,
1532-
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
1532+
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, SpanId)],
15331533
ty_generics: &'tcx ty::Generics,
15341534
) -> Vec<ty::Region<'tcx>> {
15351535
let index =

src/librustc_metadata/rmeta/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_serialize::{opaque, Decodable, Decoder, SpecializedDecoder};
3434
use rustc_session::Session;
3535
use rustc_span::source_map::{respan, Spanned};
3636
use rustc_span::symbol::{sym, Ident, Symbol};
37-
use rustc_span::{self, hygiene::MacroKind, BytePos, Pos, Span, DUMMY_SP};
37+
use rustc_span::{self, hygiene::MacroKind, BytePos, Pos, Span, SpanId, DUMMY_SP};
3838

3939
use log::debug;
4040
use proc_macro::bridge::client::ProcMacro;
@@ -837,7 +837,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
837837
&self,
838838
item_id: DefIndex,
839839
tcx: TyCtxt<'tcx>,
840-
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
840+
) -> &'tcx [(ty::Predicate<'tcx>, SpanId)] {
841841
self.root
842842
.tables
843843
.inferred_outlives

src/librustc_metadata/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ impl<'tcx> SpecializedEncoder<interpret::AllocId> for EncodeContext<'tcx> {
253253
}
254254
}
255255

256-
impl<'tcx> SpecializedEncoder<&'tcx [(ty::Predicate<'tcx>, Span)]> for EncodeContext<'tcx> {
256+
impl<'tcx> SpecializedEncoder<&'tcx [(ty::Predicate<'tcx>, SpanId)]> for EncodeContext<'tcx> {
257257
fn specialized_encode(
258258
&mut self,
259-
predicates: &&'tcx [(ty::Predicate<'tcx>, Span)],
259+
predicates: &&'tcx [(ty::Predicate<'tcx>, SpanId)],
260260
) -> Result<(), Self::Error> {
261261
ty_codec::encode_spanned_predicates(self, predicates, |ecx| &mut ecx.predicate_shorthands)
262262
}

src/librustc_metadata/rmeta/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_session::config::SymbolManglingVersion;
2020
use rustc_session::CrateDisambiguator;
2121
use rustc_span::edition::Edition;
2222
use rustc_span::symbol::Symbol;
23-
use rustc_span::{self, Span};
23+
use rustc_span::{self, Span, SpanId};
2424
use rustc_target::spec::{PanicStrategy, TargetTriple};
2525

2626
use std::marker::PhantomData;
@@ -273,7 +273,7 @@ define_tables! {
273273
// as it's an `enum` for which we want to derive (de)serialization,
274274
// so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
275275
// Also, as an optimization, a missing entry indicates an empty `&[]`.
276-
inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>,
276+
inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, SpanId)])>,
277277
super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
278278
mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
279279
promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,

src/librustc_middle/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ rustc_queries! {
245245

246246
/// Returns the inferred outlives predicates (e.g., for `struct
247247
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
248-
query inferred_outlives_of(_: DefId) -> &'tcx [(ty::Predicate<'tcx>, Span)] {}
248+
query inferred_outlives_of(_: DefId) -> &'tcx [(ty::Predicate<'tcx>, SpanId)] {}
249249

250250
/// Maps from the `DefId` of a trait to the list of
251251
/// super-predicates. This is a subset of the full list of
@@ -1048,7 +1048,7 @@ rustc_queries! {
10481048
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
10491049
}
10501050
query maybe_unused_extern_crates(_: CrateNum)
1051-
-> &'tcx [(DefId, Span)] {
1051+
-> &'tcx [(DefId, SpanId)] {
10521052
eval_always
10531053
desc { "looking up all possibly unused extern crates" }
10541054
}

src/librustc_middle/traits/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::ty::{self, AdtKind, Ty, TyCtxt};
1616
use rustc_hir as hir;
1717
use rustc_hir::def_id::DefId;
1818
use rustc_span::symbol::Symbol;
19-
use rustc_span::{Span, DUMMY_SP};
19+
use rustc_span::{Span, SpanId, DUMMY_SP, DUMMY_SPID};
2020
use smallvec::SmallVec;
2121

2222
use std::borrow::Cow;
@@ -568,25 +568,25 @@ pub struct VtableTraitAliasData<'tcx, N> {
568568
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable)]
569569
pub enum ObjectSafetyViolation {
570570
/// `Self: Sized` declared on the trait.
571-
SizedSelf(SmallVec<[Span; 1]>),
571+
SizedSelf(SmallVec<[SpanId; 1]>),
572572

573573
/// Supertrait reference references `Self` an in illegal location
574574
/// (e.g., `trait Foo : Bar<Self>`).
575-
SupertraitSelf(SmallVec<[Span; 1]>),
575+
SupertraitSelf(SmallVec<[SpanId; 1]>),
576576

577577
/// Method has something illegal.
578-
Method(Symbol, MethodViolationCode, Span),
578+
Method(Symbol, MethodViolationCode, SpanId),
579579

580580
/// Associated const.
581-
AssocConst(Symbol, Span),
581+
AssocConst(Symbol, SpanId),
582582
}
583583

584584
impl ObjectSafetyViolation {
585585
pub fn error_msg(&self) -> Cow<'static, str> {
586586
match *self {
587587
ObjectSafetyViolation::SizedSelf(_) => "it requires `Self: Sized`".into(),
588588
ObjectSafetyViolation::SupertraitSelf(ref spans) => {
589-
if spans.iter().any(|sp| *sp != DUMMY_SP) {
589+
if spans.iter().any(|sp| *sp != DUMMY_SPID) {
590590
"it uses `Self` as a type parameter in this".into()
591591
} else {
592592
"it cannot use `Self` as a type parameter in a supertrait or `where`-clause"
@@ -599,7 +599,7 @@ impl ObjectSafetyViolation {
599599
ObjectSafetyViolation::Method(
600600
name,
601601
MethodViolationCode::ReferencesSelfInput(_),
602-
DUMMY_SP,
602+
DUMMY_SPID,
603603
) => format!("method `{}` references the `Self` type in its parameters", name).into(),
604604
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelfInput(_), _) => {
605605
format!("method `{}` references the `Self` type in this parameter", name).into()
@@ -620,14 +620,14 @@ impl ObjectSafetyViolation {
620620
ObjectSafetyViolation::Method(name, MethodViolationCode::UndispatchableReceiver, _) => {
621621
format!("method `{}`'s `self` parameter cannot be dispatched on", name).into()
622622
}
623-
ObjectSafetyViolation::AssocConst(name, DUMMY_SP) => {
623+
ObjectSafetyViolation::AssocConst(name, DUMMY_SPID) => {
624624
format!("it contains associated `const` `{}`", name).into()
625625
}
626626
ObjectSafetyViolation::AssocConst(..) => "it contains this associated `const`".into(),
627627
}
628628
}
629629

630-
pub fn solution(&self) -> Option<(String, Option<(String, Span)>)> {
630+
pub fn solution(&self) -> Option<(String, Option<(String, SpanId)>)> {
631631
Some(match *self {
632632
ObjectSafetyViolation::SizedSelf(_) | ObjectSafetyViolation::SupertraitSelf(_) => {
633633
return None;
@@ -655,15 +655,15 @@ impl ObjectSafetyViolation {
655655
})
656656
}
657657

658-
pub fn spans(&self) -> SmallVec<[Span; 1]> {
659-
// When `span` comes from a separate crate, it'll be `DUMMY_SP`. Treat it as `None` so
658+
pub fn spans(&self) -> SmallVec<[SpanId; 1]> {
659+
// When `span` comes from a separate crate, it'll be `DUMMY_SPID`. Treat it as `None` so
660660
// diagnostics use a `note` instead of a `span_label`.
661661
match self {
662662
ObjectSafetyViolation::SupertraitSelf(spans)
663663
| ObjectSafetyViolation::SizedSelf(spans) => spans.clone(),
664664
ObjectSafetyViolation::AssocConst(_, span)
665665
| ObjectSafetyViolation::Method(_, _, span)
666-
if *span != DUMMY_SP =>
666+
if *span != DUMMY_SPID =>
667667
{
668668
smallvec![*span]
669669
}
@@ -676,7 +676,7 @@ impl ObjectSafetyViolation {
676676
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
677677
pub enum MethodViolationCode {
678678
/// e.g., `fn foo()`
679-
StaticMethod(Option<(&'static str, Span)>),
679+
StaticMethod(Option<(&'static str, SpanId)>),
680680

681681
/// e.g., `fn foo(&self, x: Self)`
682682
ReferencesSelfInput(usize),

src/librustc_middle/ty/codec.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::ty::{self, List, Ty, TyCtxt};
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_hir::def_id::{CrateNum, DefId};
1616
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
17-
use rustc_span::Span;
17+
use rustc_span::SpanId;
1818
use std::hash::Hash;
1919
use std::intrinsics;
2020

@@ -93,7 +93,7 @@ where
9393

9494
pub fn encode_spanned_predicates<'tcx, E, C>(
9595
encoder: &mut E,
96-
predicates: &'tcx [(ty::Predicate<'tcx>, Span)],
96+
predicates: &'tcx [(ty::Predicate<'tcx>, SpanId)],
9797
cache: C,
9898
) -> Result<(), E::Error>
9999
where
@@ -187,7 +187,7 @@ where
187187
#[inline]
188188
pub fn decode_spanned_predicates<D>(
189189
decoder: &mut D,
190-
) -> Result<&'tcx [(ty::Predicate<'tcx>, Span)], D::Error>
190+
) -> Result<&'tcx [(ty::Predicate<'tcx>, SpanId)], D::Error>
191191
where
192192
D: TyDecoder<'tcx>,
193193
{
@@ -356,7 +356,7 @@ macro_rules! implement_ty_decoder {
356356
use $crate::ty::subst::SubstsRef;
357357
use rustc_hir::def_id::{CrateNum};
358358

359-
use rustc_span::Span;
359+
use rustc_span::SpanId;
360360

361361
use super::$DecoderName;
362362

@@ -413,10 +413,10 @@ macro_rules! implement_ty_decoder {
413413
}
414414
}
415415

416-
impl<$($typaram),*> SpecializedDecoder<&'tcx [(ty::Predicate<'tcx>, Span)]>
416+
impl<$($typaram),*> SpecializedDecoder<&'tcx [(ty::Predicate<'tcx>, SpanId)]>
417417
for $DecoderName<$($typaram),*> {
418418
fn specialized_decode(&mut self)
419-
-> Result<&'tcx [(ty::Predicate<'tcx>, Span)], Self::Error> {
419+
-> Result<&'tcx [(ty::Predicate<'tcx>, SpanId)], Self::Error> {
420420
decode_spanned_predicates(self)
421421
}
422422
}

src/librustc_middle/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ pub struct GlobalCtxt<'tcx> {
942942
pub queries: query::Queries<'tcx>,
943943

944944
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
945-
maybe_unused_extern_crates: Vec<(DefId, Span)>,
945+
maybe_unused_extern_crates: Vec<(DefId, SpanId)>,
946946
/// A map of glob use to a set of names it actually imports. Currently only
947947
/// used in save-analysis.
948948
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
@@ -1158,7 +1158,7 @@ impl<'tcx> TyCtxt<'tcx> {
11581158
maybe_unused_extern_crates: resolutions
11591159
.maybe_unused_extern_crates
11601160
.into_iter()
1161-
.map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp))
1161+
.map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp.into()))
11621162
.collect(),
11631163
glob_map: resolutions
11641164
.glob_map

src/librustc_middle/ty/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_serialize::{self, Encodable, Encoder};
3939
use rustc_session::DataTypeKind;
4040
use rustc_span::hygiene::ExpnId;
4141
use rustc_span::symbol::{kw, sym, Ident, Symbol};
42-
use rustc_span::Span;
42+
use rustc_span::{Span, SpanId};
4343
use rustc_target::abi::{Align, VariantIdx};
4444

4545
use std::cell::RefCell;
@@ -1082,7 +1082,7 @@ impl<'tcx> Generics {
10821082
#[derive(Copy, Clone, Default, Debug, RustcEncodable, RustcDecodable, HashStable)]
10831083
pub struct GenericPredicates<'tcx> {
10841084
pub parent: Option<DefId>,
1085-
pub predicates: &'tcx [(Predicate<'tcx>, Span)],
1085+
pub predicates: &'tcx [(Predicate<'tcx>, SpanId)],
10861086
}
10871087

10881088
impl<'tcx> GenericPredicates<'tcx> {
@@ -1206,7 +1206,7 @@ pub struct CratePredicatesMap<'tcx> {
12061206
/// For each struct with outlive bounds, maps to a vector of the
12071207
/// predicate of its outlive bounds. If an item has no outlives
12081208
/// bounds, it will have no entry.
1209-
pub predicates: FxHashMap<DefId, &'tcx [(ty::Predicate<'tcx>, Span)]>,
1209+
pub predicates: FxHashMap<DefId, &'tcx [(ty::Predicate<'tcx>, SpanId)]>,
12101210
}
12111211

12121212
impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> {
@@ -1529,7 +1529,7 @@ impl<'tcx> Predicate<'tcx> {
15291529
#[derive(Clone, Debug, TypeFoldable)]
15301530
pub struct InstantiatedPredicates<'tcx> {
15311531
pub predicates: Vec<Predicate<'tcx>>,
1532-
pub spans: Vec<Span>,
1532+
pub spans: Vec<SpanId>,
15331533
}
15341534

15351535
impl<'tcx> InstantiatedPredicates<'tcx> {

src/librustc_middle/ty/query/on_disk_cache.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_span::hygiene::{ExpnId, SyntaxContext};
2121
use rustc_span::source_map::{SourceMap, StableSourceFileId};
2222
use rustc_span::symbol::Ident;
2323
use rustc_span::CachingSourceMapView;
24-
use rustc_span::{BytePos, SourceFile, Span, DUMMY_SP};
24+
use rustc_span::{BytePos, SourceFile, Span, SpanId, DUMMY_SP};
2525
use std::mem;
2626

2727
const TAG_FILE_FOOTER: u128 = 0xC0FFEE_C0FFEE_C0FFEE_C0FFEE_C0FFEE;
@@ -838,15 +838,15 @@ where
838838
}
839839
}
840840

841-
impl<'a, 'tcx, E> SpecializedEncoder<&'tcx [(ty::Predicate<'tcx>, Span)]>
841+
impl<'a, 'tcx, E> SpecializedEncoder<&'tcx [(ty::Predicate<'tcx>, SpanId)]>
842842
for CacheEncoder<'a, 'tcx, E>
843843
where
844844
E: 'a + TyEncoder,
845845
{
846846
#[inline]
847847
fn specialized_encode(
848848
&mut self,
849-
predicates: &&'tcx [(ty::Predicate<'tcx>, Span)],
849+
predicates: &&'tcx [(ty::Predicate<'tcx>, SpanId)],
850850
) -> Result<(), Self::Error> {
851851
ty_codec::encode_spanned_predicates(self, predicates, |encoder| {
852852
&mut encoder.predicate_shorthands

src/librustc_middle/ty/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ CloneTypeFoldableAndLiftImpls! {
290290
crate::ty::UniverseIndex,
291291
crate::ty::Variance,
292292
::rustc_span::Span,
293+
::rustc_span::SpanId,
293294
}
294295

295296
///////////////////////////////////////////////////////////////////////////

src/librustc_span/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl Ord for Span {
240240
}
241241

242242
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
243+
#[derive(HashStable_Generic)]
243244
pub enum SpanId {
244245
Span(Span),
245246
DefId(DefId),

0 commit comments

Comments
 (0)