Skip to content

Commit cb1c06f

Browse files
authored
Merge branch 'rust-lang:master' into master
2 parents b146525 + 91d8da1 commit cb1c06f

File tree

57 files changed

+934
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+934
-258
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::type_::Type;
44
use rustc_codegen_ssa::traits::*;
55
use rustc_middle::bug;
66
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
7-
use rustc_middle::ty::print::with_no_trimmed_paths;
7+
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
88
use rustc_middle::ty::{self, Ty, TypeFoldable};
99
use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape};
1010
use rustc_target::abi::{Int, Pointer, F32, F64};
@@ -43,7 +43,8 @@ fn uncached_llvm_type<'a, 'tcx>(
4343
// in problematically distinct types due to HRTB and subtyping (see #47638).
4444
// ty::Dynamic(..) |
4545
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str => {
46-
let mut name = with_no_trimmed_paths(|| layout.ty.to_string());
46+
let mut name =
47+
with_no_visible_paths(|| with_no_trimmed_paths(|| layout.ty.to_string()));
4748
if let (&ty::Adt(def, _), &Variants::Single { index }) =
4849
(layout.ty.kind(), &layout.variants)
4950
{

compiler/rustc_codegen_ssa/src/mir/block.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_index::vec::Idx;
1515
use rustc_middle::mir::AssertKind;
1616
use rustc_middle::mir::{self, SwitchTargets};
1717
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
18-
use rustc_middle::ty::print::with_no_trimmed_paths;
18+
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1919
use rustc_middle::ty::{self, Instance, Ty, TypeFoldable};
2020
use rustc_span::source_map::Span;
2121
use rustc_span::{sym, Symbol};
@@ -476,15 +476,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
476476
UninitValid => !layout.might_permit_raw_init(bx, /*zero:*/ false),
477477
};
478478
if do_panic {
479-
let msg_str = with_no_trimmed_paths(|| {
480-
if layout.abi.is_uninhabited() {
481-
// Use this error even for the other intrinsics as it is more precise.
482-
format!("attempted to instantiate uninhabited type `{}`", ty)
483-
} else if intrinsic == ZeroValid {
484-
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
485-
} else {
486-
format!("attempted to leave type `{}` uninitialized, which is invalid", ty)
487-
}
479+
let msg_str = with_no_visible_paths(|| {
480+
with_no_trimmed_paths(|| {
481+
if layout.abi.is_uninhabited() {
482+
// Use this error even for the other intrinsics as it is more precise.
483+
format!("attempted to instantiate uninhabited type `{}`", ty)
484+
} else if intrinsic == ZeroValid {
485+
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
486+
} else {
487+
format!(
488+
"attempted to leave type `{}` uninitialized, which is invalid",
489+
ty
490+
)
491+
}
492+
})
488493
});
489494
let msg = bx.const_str(Symbol::intern(&msg_str));
490495
let location = self.get_caller_location(bx, source_info).immediate();

compiler/rustc_infer/src/infer/combine.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
// is also useful to track which value is the "expected" value in
2323
// terms of error reporting.
2424

25+
use super::equate::Equate;
2526
use super::glb::Glb;
2627
use super::lub::Lub;
2728
use super::sub::Sub;
2829
use super::type_variable::TypeVariableValue;
2930
use super::unify_key::replace_if_possible;
3031
use super::unify_key::{ConstVarValue, ConstVariableValue};
3132
use super::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
32-
use super::{equate::Equate, type_variable::Diverging};
3333
use super::{InferCtxt, MiscVariable, TypeTrace};
3434

3535
use crate::traits::{Obligation, PredicateObligations};
@@ -645,7 +645,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
645645
.inner
646646
.borrow_mut()
647647
.type_variables()
648-
.new_var(self.for_universe, Diverging::NotDiverging, origin);
648+
.new_var(self.for_universe, origin);
649649
let u = self.tcx().mk_ty_var(new_var_id);
650650

651651
// Record that we replaced `vid` with `new_var_id` as part of a generalization
@@ -885,11 +885,12 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
885885

886886
let origin =
887887
*self.infcx.inner.borrow_mut().type_variables().var_origin(vid);
888-
let new_var_id = self.infcx.inner.borrow_mut().type_variables().new_var(
889-
self.for_universe,
890-
Diverging::NotDiverging,
891-
origin,
892-
);
888+
let new_var_id = self
889+
.infcx
890+
.inner
891+
.borrow_mut()
892+
.type_variables()
893+
.new_var(self.for_universe, origin);
893894
let u = self.tcx().mk_ty_var(new_var_id);
894895
debug!(
895896
"ConstInferUnifier: replacing original vid={:?} with new={:?}",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! inference graph arose so that we can explain to the user what gave
88
//! rise to a particular error.
99
//!
10-
//! The basis of the system are the "origin" types. An "origin" is the
10+
//! The system is based around a set of "origin" types. An "origin" is the
1111
//! reason that a constraint or inference variable arose. There are
1212
//! different "origin" enums for different kinds of constraints/variables
1313
//! (e.g., `TypeOrigin`, `RegionVariableOrigin`). An origin always has

compiler/rustc_infer/src/infer/mod.rs

+10-25
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, Veri
4646
use self::region_constraints::{
4747
RegionConstraintCollector, RegionConstraintStorage, RegionSnapshot,
4848
};
49-
use self::type_variable::{Diverging, TypeVariableOrigin, TypeVariableOriginKind};
49+
use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
5050

5151
pub mod at;
5252
pub mod canonical;
@@ -702,17 +702,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
702702
t.fold_with(&mut self.freshener())
703703
}
704704

705-
/// Returns whether `ty` is a diverging type variable or not.
706-
/// (If `ty` is not a type variable at all, returns not diverging.)
707-
///
708-
/// No attempt is made to resolve `ty`.
709-
pub fn type_var_diverges(&'a self, ty: Ty<'_>) -> Diverging {
710-
match *ty.kind() {
711-
ty::Infer(ty::TyVar(vid)) => self.inner.borrow_mut().type_variables().var_diverges(vid),
712-
_ => Diverging::NotDiverging,
713-
}
714-
}
715-
716705
/// Returns the origin of the type variable identified by `vid`, or `None`
717706
/// if this is not a type variable.
718707
///
@@ -1071,31 +1060,28 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10711060
})
10721061
}
10731062

1074-
pub fn next_ty_var_id(&self, diverging: Diverging, origin: TypeVariableOrigin) -> TyVid {
1075-
self.inner.borrow_mut().type_variables().new_var(self.universe(), diverging, origin)
1063+
/// Number of type variables created so far.
1064+
pub fn num_ty_vars(&self) -> usize {
1065+
self.inner.borrow_mut().type_variables().num_vars()
1066+
}
1067+
1068+
pub fn next_ty_var_id(&self, origin: TypeVariableOrigin) -> TyVid {
1069+
self.inner.borrow_mut().type_variables().new_var(self.universe(), origin)
10761070
}
10771071

10781072
pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
1079-
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::NotDiverging, origin))
1073+
self.tcx.mk_ty_var(self.next_ty_var_id(origin))
10801074
}
10811075

10821076
pub fn next_ty_var_in_universe(
10831077
&self,
10841078
origin: TypeVariableOrigin,
10851079
universe: ty::UniverseIndex,
10861080
) -> Ty<'tcx> {
1087-
let vid = self.inner.borrow_mut().type_variables().new_var(
1088-
universe,
1089-
Diverging::NotDiverging,
1090-
origin,
1091-
);
1081+
let vid = self.inner.borrow_mut().type_variables().new_var(universe, origin);
10921082
self.tcx.mk_ty_var(vid)
10931083
}
10941084

1095-
pub fn next_diverging_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
1096-
self.tcx.mk_ty_var(self.next_ty_var_id(Diverging::Diverges, origin))
1097-
}
1098-
10991085
pub fn next_const_var(
11001086
&self,
11011087
ty: Ty<'tcx>,
@@ -1207,7 +1193,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12071193
// as the substitutions for the default, `(T, U)`.
12081194
let ty_var_id = self.inner.borrow_mut().type_variables().new_var(
12091195
self.universe(),
1210-
Diverging::NotDiverging,
12111196
TypeVariableOrigin {
12121197
kind: TypeVariableOriginKind::TypeParameterDefinition(
12131198
param.name,

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
//! constituents)
2323
2424
use crate::infer::combine::ConstEquateRelation;
25-
use crate::infer::type_variable::Diverging;
2625
use crate::infer::InferCtxt;
2726
use crate::infer::{ConstVarValue, ConstVariableValue};
2827
use rustc_data_structures::fx::FxHashMap;
@@ -927,8 +926,7 @@ where
927926
// Replacing with a new variable in the universe `self.universe`,
928927
// it will be unified later with the original type variable in
929928
// the universe `_universe`.
930-
let new_var_id =
931-
variables.new_var(self.universe, Diverging::NotDiverging, origin);
929+
let new_var_id = variables.new_var(self.universe, origin);
932930

933931
let u = self.tcx().mk_ty_var(new_var_id);
934932
debug!("generalize: replacing original vid={:?} with new={:?}", vid, u);

compiler/rustc_infer/src/infer/type_variable.rs

+7-22
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,16 @@ pub enum TypeVariableOriginKind {
129129
SubstitutionPlaceholder,
130130
AutoDeref,
131131
AdjustmentType,
132-
DivergingFn,
132+
133+
/// In type check, when we are type checking a function that
134+
/// returns `-> dyn Foo`, we substitute a type variable for the
135+
/// return type for diagnostic purposes.
136+
DynReturnFn,
133137
LatticeVariable,
134138
}
135139

136140
pub(crate) struct TypeVariableData {
137141
origin: TypeVariableOrigin,
138-
diverging: Diverging,
139-
}
140-
141-
#[derive(Copy, Clone, Debug)]
142-
pub enum Diverging {
143-
NotDiverging,
144-
Diverges,
145142
}
146143

147144
#[derive(Copy, Clone, Debug)]
@@ -191,14 +188,6 @@ impl<'tcx> TypeVariableStorage<'tcx> {
191188
}
192189

193190
impl<'tcx> TypeVariableTable<'_, 'tcx> {
194-
/// Returns the diverges flag given when `vid` was created.
195-
///
196-
/// Note that this function does not return care whether
197-
/// `vid` has been unified with something else or not.
198-
pub fn var_diverges(&self, vid: ty::TyVid) -> Diverging {
199-
self.storage.values.get(vid.index()).diverging
200-
}
201-
202191
/// Returns the origin that was given when `vid` was created.
203192
///
204193
/// Note that this function does not return care whether
@@ -260,21 +249,17 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
260249
pub fn new_var(
261250
&mut self,
262251
universe: ty::UniverseIndex,
263-
diverging: Diverging,
264252
origin: TypeVariableOrigin,
265253
) -> ty::TyVid {
266254
let eq_key = self.eq_relations().new_key(TypeVariableValue::Unknown { universe });
267255

268256
let sub_key = self.sub_relations().new_key(());
269257
assert_eq!(eq_key.vid, sub_key);
270258

271-
let index = self.values().push(TypeVariableData { origin, diverging });
259+
let index = self.values().push(TypeVariableData { origin });
272260
assert_eq!(eq_key.vid.as_u32(), index as u32);
273261

274-
debug!(
275-
"new_var(index={:?}, universe={:?}, diverging={:?}, origin={:?}",
276-
eq_key.vid, universe, diverging, origin,
277-
);
262+
debug!("new_var(index={:?}, universe={:?}, origin={:?}", eq_key.vid, universe, origin,);
278263

279264
eq_key.vid
280265
}

compiler/rustc_infer/src/traits/engine.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::infer::InferCtxt;
22
use crate::traits::Obligation;
3+
use rustc_data_structures::fx::FxHashMap;
34
use rustc_hir as hir;
45
use rustc_hir::def_id::DefId;
56
use rustc_middle::ty::{self, ToPredicate, Ty, WithConstness};
@@ -73,6 +74,8 @@ pub trait TraitEngine<'tcx>: 'tcx {
7374
}
7475

7576
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
77+
78+
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;
7679
}
7780

7881
pub trait TraitEngineExt<'tcx> {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ rustc_queries! {
599599
desc { "computing the inferred outlives predicates for items in this crate" }
600600
}
601601

602-
/// Maps from an impl/trait `DefId to a list of the `DefId`s of its items.
602+
/// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
603603
query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
604604
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
605605
}

compiler/rustc_middle/src/ty/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -2090,3 +2090,16 @@ impl<'tcx> fmt::Debug for SymbolName<'tcx> {
20902090
fmt::Display::fmt(&self.name, fmt)
20912091
}
20922092
}
2093+
2094+
#[derive(Debug, Default, Copy, Clone)]
2095+
pub struct FoundRelationships {
2096+
/// This is true if we identified that this Ty (`?T`) is found in a `?T: Foo`
2097+
/// obligation, where:
2098+
///
2099+
/// * `Foo` is not `Sized`
2100+
/// * `(): Foo` may be satisfied
2101+
pub self_in_trait: bool,
2102+
/// This is true if we identified that this Ty (`?T`) is found in a `<_ as
2103+
/// _>::AssocType = ?T`
2104+
pub output: bool,
2105+
}

compiler/rustc_middle/src/ty/print/pretty.rs

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ thread_local! {
5959
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = const { Cell::new(false) };
6060
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
6161
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
62+
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
6263
}
6364

6465
/// Avoids running any queries during any prints that occur
@@ -112,6 +113,16 @@ pub fn with_no_trimmed_paths<F: FnOnce() -> R, R>(f: F) -> R {
112113
})
113114
}
114115

116+
/// Prevent selection of visible paths. `Display` impl of DefId will prefer visible (public) reexports of types as paths.
117+
pub fn with_no_visible_paths<F: FnOnce() -> R, R>(f: F) -> R {
118+
NO_VISIBLE_PATH.with(|flag| {
119+
let old = flag.replace(true);
120+
let result = f();
121+
flag.set(old);
122+
result
123+
})
124+
}
125+
115126
/// The "region highlights" are used to control region printing during
116127
/// specific error messages. When a "region highlight" is enabled, it
117128
/// gives an alternate way to print specific regions. For now, we
@@ -268,6 +279,10 @@ pub trait PrettyPrinter<'tcx>:
268279
/// from at least one local module, and returns `true`. If the crate defining `def_id` is
269280
/// declared with an `extern crate`, the path is guaranteed to use the `extern crate`.
270281
fn try_print_visible_def_path(self, def_id: DefId) -> Result<(Self, bool), Self::Error> {
282+
if NO_VISIBLE_PATH.with(|flag| flag.get()) {
283+
return Ok((self, false));
284+
}
285+
271286
let mut callers = Vec::new();
272287
self.try_print_visible_def_path_recur(def_id, &mut callers)
273288
}

compiler/rustc_middle/src/ty/sty.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,14 @@ impl<'tcx> TyS<'tcx> {
16721672
matches!(self.kind(), Infer(TyVar(_)))
16731673
}
16741674

1675+
#[inline]
1676+
pub fn ty_vid(&self) -> Option<ty::TyVid> {
1677+
match self.kind() {
1678+
&Infer(TyVar(vid)) => Some(vid),
1679+
_ => None,
1680+
}
1681+
}
1682+
16751683
#[inline]
16761684
pub fn is_ty_infer(&self) -> bool {
16771685
matches!(self.kind(), Infer(_))

compiler/rustc_parse/src/parser/expr.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,20 @@ impl<'a> Parser<'a> {
15681568

15691569
pub(super) fn parse_lit(&mut self) -> PResult<'a, Lit> {
15701570
self.parse_opt_lit().ok_or_else(|| {
1571+
if let token::Interpolated(inner) = &self.token.kind {
1572+
let expr = match inner.as_ref() {
1573+
token::NtExpr(expr) => Some(expr),
1574+
token::NtLiteral(expr) => Some(expr),
1575+
_ => None,
1576+
};
1577+
if let Some(expr) = expr {
1578+
if matches!(expr.kind, ExprKind::Err) {
1579+
self.diagnostic()
1580+
.delay_span_bug(self.token.span, &"invalid interpolated expression");
1581+
return self.diagnostic().struct_dummy();
1582+
}
1583+
}
1584+
}
15711585
let msg = format!("unexpected token: {}", super::token_descr(&self.token));
15721586
self.struct_span_err(self.token.span, &msg)
15731587
})

compiler/rustc_query_impl/src/plumbing.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,13 @@ macro_rules! define_queries {
321321
pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame {
322322
let kind = dep_graph::DepKind::$name;
323323
let name = stringify!($name);
324-
let description = ty::print::with_forced_impl_filename_line(
324+
// Disable visible paths printing for performance reasons.
325+
// Showing visible path instead of any path is not that important in production.
326+
let description = ty::print::with_no_visible_paths(
327+
|| ty::print::with_forced_impl_filename_line(
325328
// Force filename-line mode to avoid invoking `type_of` query.
326329
|| queries::$name::describe(tcx, key)
327-
);
330+
));
328331
let description = if tcx.sess.verbose() {
329332
format!("{} [{}]", description, name)
330333
} else {

0 commit comments

Comments
 (0)