Skip to content

Commit bca8b4d

Browse files
committed
Auto merge of rust-lang#107408 - matthiaskrgr:rollup-b5vz2ow, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader) - rust-lang#104252 (Stabilize the const_socketaddr feature) - rust-lang#105524 (Replace libc::{type} with crate::ffi::{type}) - rust-lang#107096 (Detect references to non-existant messages in Fluent resources) - rust-lang#107355 (Add regression test for rust-lang#60755) - rust-lang#107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`) - rust-lang#107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`) - rust-lang#107391 (rustdoc: remove inline javascript from copy-path button) - rust-lang#107398 (Remove `ControlFlow::{BREAK, CONTINUE}`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d8da513 + c95707a commit bca8b4d

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

+557
-312
lines changed

compiler/rustc_error_messages/locales/en-US/codegen_gcc.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ codegen_gcc_invalid_monomorphization_unsupported_element =
2323
invalid monomorphization of `{$name}` intrinsic: unsupported {$name} from `{$in_ty}` with element `{$elem_ty}` to `{$ret_ty}`
2424
2525
codegen_gcc_invalid_monomorphization_invalid_bitmask =
26-
invalid monomorphization of `{$name}` intrinsic: invalid bitmask `{ty}`, expected `u{$expected_int_bits}` or `[u8; {$expected_bytes}]`
26+
invalid monomorphization of `{$name}` intrinsic: invalid bitmask `{$ty}`, expected `u{$expected_int_bits}` or `[u8; {$expected_bytes}]`
2727
2828
codegen_gcc_invalid_monomorphization_simd_shuffle =
2929
invalid monomorphization of `{$name}` intrinsic: simd_shuffle index must be an array of `u32`, got `{$ty}`

compiler/rustc_error_messages/locales/en-US/codegen_ssa.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ codegen_ssa_extract_bundled_libs_write_file = failed to write file '{$rlib}': {$
179179
180180
codegen_ssa_unsupported_arch = unsupported arch `{$arch}` for os `{$os}`
181181
182-
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {error}
182+
codegen_ssa_apple_sdk_error_sdk_path = failed to get {$sdk_name} SDK path: {$error}
183183
184-
codegen_ssa_read_file = failed to read file: {message}
184+
codegen_ssa_read_file = failed to read file: {$message}
185185
186186
codegen_ssa_unsupported_link_self_contained = option `-C link-self-contained` is not supported on this target
187187

compiler/rustc_infer/src/infer/combine.rs

+26-88
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ use rustc_middle::traits::ObligationCause;
3737
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3838
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
3939
use rustc_middle::ty::subst::SubstsRef;
40-
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitable};
40+
use rustc_middle::ty::{
41+
self, FallibleTypeFolder, InferConst, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable,
42+
TypeVisitable,
43+
};
4144
use rustc_middle::ty::{IntType, UintType};
4245
use rustc_span::{Span, DUMMY_SP};
4346

@@ -140,8 +143,6 @@ impl<'tcx> InferCtxt<'tcx> {
140143
let a = self.shallow_resolve(a);
141144
let b = self.shallow_resolve(b);
142145

143-
let a_is_expected = relation.a_is_expected();
144-
145146
match (a.kind(), b.kind()) {
146147
(
147148
ty::ConstKind::Infer(InferConst::Var(a_vid)),
@@ -158,11 +159,11 @@ impl<'tcx> InferCtxt<'tcx> {
158159
}
159160

160161
(ty::ConstKind::Infer(InferConst::Var(vid)), _) => {
161-
return self.unify_const_variable(relation.param_env(), vid, b, a_is_expected);
162+
return self.unify_const_variable(vid, b);
162163
}
163164

164165
(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
165-
return self.unify_const_variable(relation.param_env(), vid, a, !a_is_expected);
166+
return self.unify_const_variable(vid, a);
166167
}
167168
(ty::ConstKind::Unevaluated(..), _) if self.tcx.lazy_normalization() => {
168169
// FIXME(#59490): Need to remove the leak check to accommodate
@@ -223,10 +224,8 @@ impl<'tcx> InferCtxt<'tcx> {
223224
#[instrument(level = "debug", skip(self))]
224225
fn unify_const_variable(
225226
&self,
226-
param_env: ty::ParamEnv<'tcx>,
227227
target_vid: ty::ConstVid<'tcx>,
228228
ct: ty::Const<'tcx>,
229-
vid_is_expected: bool,
230229
) -> RelateResult<'tcx, ty::Const<'tcx>> {
231230
let (for_universe, span) = {
232231
let mut inner = self.inner.borrow_mut();
@@ -239,8 +238,12 @@ impl<'tcx> InferCtxt<'tcx> {
239238
ConstVariableValue::Unknown { universe } => (universe, var_value.origin.span),
240239
}
241240
};
242-
let value = ConstInferUnifier { infcx: self, span, param_env, for_universe, target_vid }
243-
.relate(ct, ct)?;
241+
let value = ct.try_fold_with(&mut ConstInferUnifier {
242+
infcx: self,
243+
span,
244+
for_universe,
245+
target_vid,
246+
})?;
244247

245248
self.inner.borrow_mut().const_unification_table().union_value(
246249
target_vid,
@@ -800,8 +803,6 @@ struct ConstInferUnifier<'cx, 'tcx> {
800803

801804
span: Span,
802805

803-
param_env: ty::ParamEnv<'tcx>,
804-
805806
for_universe: ty::UniverseIndex,
806807

807808
/// The vid of the const variable that is in the process of being
@@ -810,69 +811,23 @@ struct ConstInferUnifier<'cx, 'tcx> {
810811
target_vid: ty::ConstVid<'tcx>,
811812
}
812813

813-
// We use `TypeRelation` here to propagate `RelateResult` upwards.
814-
//
815-
// Both inputs are expected to be the same.
816-
impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
817-
fn tcx(&self) -> TyCtxt<'tcx> {
818-
self.infcx.tcx
819-
}
820-
821-
fn intercrate(&self) -> bool {
822-
assert!(!self.infcx.intercrate);
823-
false
824-
}
825-
826-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
827-
self.param_env
828-
}
829-
830-
fn tag(&self) -> &'static str {
831-
"ConstInferUnifier"
832-
}
833-
834-
fn a_is_expected(&self) -> bool {
835-
true
836-
}
837-
838-
fn mark_ambiguous(&mut self) {
839-
bug!()
840-
}
841-
842-
fn relate_with_variance<T: Relate<'tcx>>(
843-
&mut self,
844-
_variance: ty::Variance,
845-
_info: ty::VarianceDiagInfo<'tcx>,
846-
a: T,
847-
b: T,
848-
) -> RelateResult<'tcx, T> {
849-
// We don't care about variance here.
850-
self.relate(a, b)
851-
}
814+
impl<'tcx> FallibleTypeFolder<'tcx> for ConstInferUnifier<'_, 'tcx> {
815+
type Error = TypeError<'tcx>;
852816

853-
fn binders<T>(
854-
&mut self,
855-
a: ty::Binder<'tcx, T>,
856-
b: ty::Binder<'tcx, T>,
857-
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
858-
where
859-
T: Relate<'tcx>,
860-
{
861-
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
817+
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
818+
self.infcx.tcx
862819
}
863820

864821
#[instrument(level = "debug", skip(self), ret)]
865-
fn tys(&mut self, t: Ty<'tcx>, _t: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
866-
debug_assert_eq!(t, _t);
867-
822+
fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result<Ty<'tcx>, TypeError<'tcx>> {
868823
match t.kind() {
869824
&ty::Infer(ty::TyVar(vid)) => {
870825
let vid = self.infcx.inner.borrow_mut().type_variables().root_var(vid);
871826
let probe = self.infcx.inner.borrow_mut().type_variables().probe(vid);
872827
match probe {
873828
TypeVariableValue::Known { value: u } => {
874829
debug!("ConstOccursChecker: known value {:?}", u);
875-
self.tys(u, u)
830+
u.try_fold_with(self)
876831
}
877832
TypeVariableValue::Unknown { universe } => {
878833
if self.for_universe.can_name(universe) {
@@ -892,16 +847,15 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
892847
}
893848
}
894849
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => Ok(t),
895-
_ => relate::super_relate_tys(self, t, t),
850+
_ => t.try_super_fold_with(self),
896851
}
897852
}
898853

899-
fn regions(
854+
#[instrument(level = "debug", skip(self), ret)]
855+
fn try_fold_region(
900856
&mut self,
901857
r: ty::Region<'tcx>,
902-
_r: ty::Region<'tcx>,
903-
) -> RelateResult<'tcx, ty::Region<'tcx>> {
904-
debug_assert_eq!(r, _r);
858+
) -> Result<ty::Region<'tcx>, TypeError<'tcx>> {
905859
debug!("ConstInferUnifier: r={:?}", r);
906860

907861
match *r {
@@ -930,14 +884,8 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
930884
}
931885
}
932886

933-
#[instrument(level = "debug", skip(self))]
934-
fn consts(
935-
&mut self,
936-
c: ty::Const<'tcx>,
937-
_c: ty::Const<'tcx>,
938-
) -> RelateResult<'tcx, ty::Const<'tcx>> {
939-
debug_assert_eq!(c, _c);
940-
887+
#[instrument(level = "debug", skip(self), ret)]
888+
fn try_fold_const(&mut self, c: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, TypeError<'tcx>> {
941889
match c.kind() {
942890
ty::ConstKind::Infer(InferConst::Var(vid)) => {
943891
// Check if the current unification would end up
@@ -958,7 +906,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
958906
let var_value =
959907
self.infcx.inner.borrow_mut().const_unification_table().probe_value(vid);
960908
match var_value.val {
961-
ConstVariableValue::Known { value: u } => self.consts(u, u),
909+
ConstVariableValue::Known { value: u } => u.try_fold_with(self),
962910
ConstVariableValue::Unknown { universe } => {
963911
if self.for_universe.can_name(universe) {
964912
Ok(c)
@@ -977,17 +925,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
977925
}
978926
}
979927
}
980-
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
981-
let substs = self.relate_with_variance(
982-
ty::Variance::Invariant,
983-
ty::VarianceDiagInfo::default(),
984-
substs,
985-
substs,
986-
)?;
987-
988-
Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty()))
989-
}
990-
_ => relate::super_relate_consts(self, c, c),
928+
_ => c.try_super_fold_with(self),
991929
}
992930
}
993931
}

compiler/rustc_macros/src/diagnostics/fluent.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use annotate_snippets::{
44
};
55
use fluent_bundle::{FluentBundle, FluentError, FluentResource};
66
use fluent_syntax::{
7-
ast::{Attribute, Entry, Identifier, Message},
7+
ast::{
8+
Attribute, Entry, Expression, Identifier, InlineExpression, Message, Pattern,
9+
PatternElement,
10+
},
811
parser::ParserError,
912
};
1013
use proc_macro::{Diagnostic, Level, Span};
@@ -185,9 +188,12 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
185188
};
186189

187190
let mut constants = TokenStream::new();
191+
let mut messagerefs = Vec::new();
188192
for entry in resource.entries() {
189193
let span = res.krate.span();
190-
if let Entry::Message(Message { id: Identifier { name }, attributes, .. }) = entry {
194+
if let Entry::Message(Message { id: Identifier { name }, attributes, value, .. }) =
195+
entry
196+
{
191197
let _ = previous_defns.entry(name.to_string()).or_insert(path_span);
192198

193199
if name.contains('-') {
@@ -200,6 +206,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
200206
.emit();
201207
}
202208

209+
if let Some(Pattern { elements }) = value {
210+
for elt in elements {
211+
if let PatternElement::Placeable {
212+
expression:
213+
Expression::Inline(InlineExpression::MessageReference { id, .. }),
214+
} = elt
215+
{
216+
messagerefs.push((id.name, *name));
217+
}
218+
}
219+
}
220+
203221
// Require that the message name starts with the crate name
204222
// `hir_typeck_foo_bar` (in `hir_typeck.ftl`)
205223
// `const_eval_baz` (in `const_eval.ftl`)
@@ -258,6 +276,18 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
258276
}
259277
}
260278

279+
for (mref, name) in messagerefs.into_iter() {
280+
if !previous_defns.contains_key(mref) {
281+
Diagnostic::spanned(
282+
path_span,
283+
Level::Error,
284+
format!("referenced message `{mref}` does not exist (in message `{name}`)"),
285+
)
286+
.help(&format!("you may have meant to use a variable reference (`{{${mref}}}`)"))
287+
.emit();
288+
}
289+
}
290+
261291
if let Err(errs) = bundle.add_resource(resource) {
262292
for e in errs {
263293
match e {

compiler/rustc_middle/src/ty/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub use generics::*;
3131
use rustc_ast as ast;
3232
use rustc_ast::node_id::NodeMap;
3333
use rustc_attr as attr;
34-
use rustc_data_structures::fingerprint::Fingerprint;
3534
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
3635
use rustc_data_structures::intern::Interned;
3736
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -453,18 +452,6 @@ pub struct CReaderCacheKey {
453452
#[rustc_pass_by_value]
454453
pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
455454

456-
impl<'tcx> TyCtxt<'tcx> {
457-
/// A "bool" type used in rustc_mir_transform unit tests when we
458-
/// have not spun up a TyCtxt.
459-
pub const BOOL_TY_FOR_UNIT_TESTING: Ty<'tcx> =
460-
Ty(Interned::new_unchecked(&WithCachedTypeInfo {
461-
internee: ty::Bool,
462-
stable_hash: Fingerprint::ZERO,
463-
flags: TypeFlags::empty(),
464-
outer_exclusive_binder: DebruijnIndex::from_usize(0),
465-
}));
466-
}
467-
468455
impl ty::EarlyBoundRegion {
469456
/// Does this early bound region have a name? Early bound regions normally
470457
/// always have names except when using anonymous lifetimes (`'_`).

0 commit comments

Comments
 (0)