Skip to content

Commit dda6272

Browse files
committed
Auto merge of #117627 - matthiaskrgr:rollup-22w6fp8, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #117578 (Derive `TyEncodable`/`TyDecodable` in `rustc_type_ir`) - #117592 (Use the correct span when emitting the `env!` result) - #117609 (Distinguish crates with the same name in type errors) - #117613 (Remove from vacation and compiler review group) - #117615 (Couple of small changes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f9b6446 + e63ec25 commit dda6272

File tree

21 files changed

+127
-513
lines changed

21 files changed

+127
-513
lines changed

compiler/rustc_builtin_macros/src/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn expand_env<'cx>(
108108

109109
return DummyResult::any(sp);
110110
}
111-
Some(value) => cx.expr_str(sp, value),
111+
Some(value) => cx.expr_str(span, value),
112112
};
113113
MacEager::expr(e)
114114
}

compiler/rustc_codegen_ssa/src/traits/backend.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ pub trait CodegenBackend {
104104
outputs: &OutputFilenames,
105105
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed>;
106106

107-
/// This is called on the returned `Box<dyn Any>` from `join_codegen`
108-
///
109-
/// # Panics
110-
///
111-
/// Panics when the passed `Box<dyn Any>` was not returned by `join_codegen`.
107+
/// This is called on the returned `CodegenResults` from `join_codegen`
112108
fn link(
113109
&self,
114110
sess: &Session,

compiler/rustc_driver_impl/src/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_session::cstore::MetadataLoader;
4141
use rustc_session::getopts::{self, Matches};
4242
use rustc_session::lint::{Lint, LintId};
4343
use rustc_session::{config, EarlyErrorHandler, Session};
44+
use rustc_span::def_id::LOCAL_CRATE;
4445
use rustc_span::source_map::FileLoader;
4546
use rustc_span::symbol::sym;
4647
use rustc_span::FileName;
@@ -421,8 +422,12 @@ fn run_compiler(
421422
// effects of writing the dep-info and reporting errors.
422423
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
423424
} else {
424-
let krate = queries.parse()?.steal();
425-
pretty::print(sess, *ppm, pretty::PrintExtra::AfterParsing { krate });
425+
let krate = queries.parse()?;
426+
pretty::print(
427+
sess,
428+
*ppm,
429+
pretty::PrintExtra::AfterParsing { krate: &*krate.borrow() },
430+
);
426431
}
427432
trace!("finished pretty-printing");
428433
return early_exit();
@@ -477,8 +482,7 @@ fn run_compiler(
477482
}
478483

479484
if sess.opts.unstable_opts.print_vtable_sizes {
480-
let crate_name =
481-
compiler.session().opts.crate_name.as_deref().unwrap_or("<UNKNOWN_CRATE>");
485+
let crate_name = queries.global_ctxt()?.enter(|tcx| tcx.crate_name(LOCAL_CRATE));
482486

483487
sess.code_stats.print_vtable_sizes(crate_name);
484488
}

compiler/rustc_driver_impl/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn write_or_print(out: &str, sess: &Session) {
217217
// Extra data for pretty-printing, the form of which depends on what kind of
218218
// pretty-printing we are doing.
219219
pub enum PrintExtra<'tcx> {
220-
AfterParsing { krate: ast::Crate },
220+
AfterParsing { krate: &'tcx ast::Crate },
221221
NeedsAstMap { tcx: TyCtxt<'tcx> },
222222
}
223223

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18241824
let expected_defid = expected_adt.did();
18251825

18261826
diagnostic.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types"));
1827+
let have_same_crate_name = self.tcx.crate_name(found_defid.krate) == self.tcx.crate_name(expected_defid.krate);
18271828
for (defid, name) in
18281829
[(found_defid, found_name), (expected_defid, expected_name)]
18291830
{
@@ -1843,7 +1844,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18431844
format!("{name} is defined in the current crate")
18441845
} else {
18451846
let crate_name = self.tcx.crate_name(defid.krate);
1846-
format!("{name} is defined in crate `{crate_name}`")
1847+
diagnostic.span_note(def_span, format!("{name} is defined in crate `{crate_name}`"));
1848+
1849+
// If these are named the same, give a hint about why the compiler thinks they're different.
1850+
if have_same_crate_name {
1851+
let crate_paths = self.tcx.crate_extern_paths(defid.krate);
1852+
diagnostic.note(format!("`{crate_name}` was loaded from {}", crate_paths[0].display()));
1853+
}
1854+
1855+
continue;
18471856
};
18481857
diagnostic.span_note(def_span, msg);
18491858
}

compiler/rustc_macros/src/serialize.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ use syn::spanned::Spanned;
55

66
pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
77
let decoder_ty = quote! { __D };
8-
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
9-
s.add_impl_generic(parse_quote! { 'tcx });
10-
}
11-
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder<I = ::rustc_middle::ty::TyCtxt<'tcx>>});
12-
s.add_bounds(synstructure::AddBounds::Generics);
8+
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
9+
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
10+
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
11+
quote! { <I = I> }
12+
} else {
13+
quote! {}
14+
};
15+
16+
s.add_impl_generic(parse_quote! {#decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound });
17+
s.add_bounds(synstructure::AddBounds::Fields);
1318

1419
decodable_body(s, decoder_ty)
1520
}
@@ -97,12 +102,17 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
97102
}
98103

99104
pub fn type_encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
100-
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
101-
s.add_impl_generic(parse_quote! {'tcx});
102-
}
105+
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
106+
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
107+
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
108+
quote! { <I = I> }
109+
} else {
110+
quote! {}
111+
};
112+
103113
let encoder_ty = quote! { __E };
104-
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder<I = ::rustc_middle::ty::TyCtxt<'tcx>>});
105-
s.add_bounds(synstructure::AddBounds::Generics);
114+
s.add_impl_generic(parse_quote! {#encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound });
115+
s.add_bounds(synstructure::AddBounds::Fields);
106116

107117
encodable_body(s, encoder_ty, false)
108118
}

compiler/rustc_session/src/code_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl CodeStats {
226226
}
227227
}
228228

229-
pub fn print_vtable_sizes(&self, crate_name: &str) {
229+
pub fn print_vtable_sizes(&self, crate_name: Symbol) {
230230
let mut infos =
231231
std::mem::take(&mut *self.vtable_sizes.lock()).into_values().collect::<Vec<_>>();
232232

compiler/rustc_type_ir/src/canonical.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ use std::hash::Hash;
33
use std::ops::ControlFlow;
44

55
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
6-
use rustc_serialize::{Decodable, Encodable};
76

87
use crate::fold::{FallibleTypeFolder, TypeFoldable};
98
use crate::visit::{TypeVisitable, TypeVisitor};
10-
use crate::TyDecoder;
11-
use crate::{HashStableContext, Interner, TyEncoder, UniverseIndex};
9+
use crate::{HashStableContext, Interner, UniverseIndex};
1210

1311
/// A "canonicalized" type `V` is one where all free inference
1412
/// variables have been rewritten to "canonical vars". These are
1513
/// numbered starting from 0 in order of first appearance.
1614
#[derive(derivative::Derivative)]
1715
#[derivative(Clone(bound = "V: Clone"), Hash(bound = "V: Hash"))]
16+
#[derive(TyEncodable, TyDecodable)]
1817
pub struct Canonical<I: Interner, V> {
1918
pub value: V,
2019
pub max_universe: UniverseIndex,
@@ -127,27 +126,3 @@ where
127126
self.variables.visit_with(folder)
128127
}
129128
}
130-
131-
impl<I: Interner, E: TyEncoder<I = I>, V: Encodable<E>> Encodable<E> for Canonical<I, V>
132-
where
133-
I::CanonicalVars: Encodable<E>,
134-
{
135-
fn encode(&self, s: &mut E) {
136-
self.value.encode(s);
137-
self.max_universe.encode(s);
138-
self.variables.encode(s);
139-
}
140-
}
141-
142-
impl<I: Interner, D: TyDecoder<I = I>, V: Decodable<D>> Decodable<D> for Canonical<I, V>
143-
where
144-
I::CanonicalVars: Decodable<D>,
145-
{
146-
fn decode(d: &mut D) -> Self {
147-
Canonical {
148-
value: Decodable::decode(d),
149-
max_universe: Decodable::decode(d),
150-
variables: Decodable::decode(d),
151-
}
152-
}
153-
}

compiler/rustc_type_ir/src/const_kind.rs

+2-66
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use rustc_data_structures::stable_hasher::HashStable;
22
use rustc_data_structures::stable_hasher::StableHasher;
3-
use rustc_serialize::{Decodable, Decoder, Encodable};
43
use std::fmt;
54

6-
use crate::{
7-
DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, TyDecoder,
8-
TyEncoder, WithInfcx,
9-
};
5+
use crate::{DebruijnIndex, DebugWithInfcx, HashStableContext, InferCtxtLike, Interner, WithInfcx};
106

117
use self::ConstKind::*;
128

@@ -20,6 +16,7 @@ use self::ConstKind::*;
2016
Ord = "feature_allow_slow_enum",
2117
Hash(bound = "")
2218
)]
19+
#[derive(TyEncodable, TyDecodable)]
2320
pub enum ConstKind<I: Interner> {
2421
/// A const generic parameter.
2522
Param(I::ParamConst),
@@ -92,67 +89,6 @@ where
9289
}
9390
}
9491

95-
impl<I: Interner, D: TyDecoder<I = I>> Decodable<D> for ConstKind<I>
96-
where
97-
I::ParamConst: Decodable<D>,
98-
I::InferConst: Decodable<D>,
99-
I::BoundConst: Decodable<D>,
100-
I::PlaceholderConst: Decodable<D>,
101-
I::AliasConst: Decodable<D>,
102-
I::ValueConst: Decodable<D>,
103-
I::ErrorGuaranteed: Decodable<D>,
104-
I::ExprConst: Decodable<D>,
105-
{
106-
fn decode(d: &mut D) -> Self {
107-
match Decoder::read_usize(d) {
108-
0 => Param(Decodable::decode(d)),
109-
1 => Infer(Decodable::decode(d)),
110-
2 => Bound(Decodable::decode(d), Decodable::decode(d)),
111-
3 => Placeholder(Decodable::decode(d)),
112-
4 => Unevaluated(Decodable::decode(d)),
113-
5 => Value(Decodable::decode(d)),
114-
6 => Error(Decodable::decode(d)),
115-
7 => Expr(Decodable::decode(d)),
116-
_ => panic!(
117-
"{}",
118-
format!(
119-
"invalid enum variant tag while decoding `{}`, expected 0..{}",
120-
"ConstKind", 8,
121-
)
122-
),
123-
}
124-
}
125-
}
126-
127-
impl<I: Interner, E: TyEncoder<I = I>> Encodable<E> for ConstKind<I>
128-
where
129-
I::ParamConst: Encodable<E>,
130-
I::InferConst: Encodable<E>,
131-
I::BoundConst: Encodable<E>,
132-
I::PlaceholderConst: Encodable<E>,
133-
I::AliasConst: Encodable<E>,
134-
I::ValueConst: Encodable<E>,
135-
I::ErrorGuaranteed: Encodable<E>,
136-
I::ExprConst: Encodable<E>,
137-
{
138-
fn encode(&self, e: &mut E) {
139-
let disc = const_kind_discriminant(self);
140-
match self {
141-
Param(p) => e.emit_enum_variant(disc, |e| p.encode(e)),
142-
Infer(i) => e.emit_enum_variant(disc, |e| i.encode(e)),
143-
Bound(d, b) => e.emit_enum_variant(disc, |e| {
144-
d.encode(e);
145-
b.encode(e);
146-
}),
147-
Placeholder(p) => e.emit_enum_variant(disc, |e| p.encode(e)),
148-
Unevaluated(u) => e.emit_enum_variant(disc, |e| u.encode(e)),
149-
Value(v) => e.emit_enum_variant(disc, |e| v.encode(e)),
150-
Error(er) => e.emit_enum_variant(disc, |e| er.encode(e)),
151-
Expr(ex) => e.emit_enum_variant(disc, |e| ex.encode(e)),
152-
}
153-
}
154-
}
155-
15692
impl<I: Interner> PartialEq for ConstKind<I> {
15793
fn eq(&self, other: &Self) -> bool {
15894
match (self, other) {

compiler/rustc_type_ir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#![deny(rustc::diagnostic_outside_of_impl)]
1111
#![allow(internal_features)]
1212

13+
extern crate self as rustc_type_ir;
14+
1315
#[macro_use]
1416
extern crate bitflags;
1517
#[macro_use]

0 commit comments

Comments
 (0)