Skip to content

Commit dfe0d21

Browse files
committed
Auto merge of #2971 - rust-lang:rustup2023-07-08, r=RalfJung
Automatic sync from rustc
2 parents 2323ecb + c182669 commit dfe0d21

File tree

116 files changed

+1049
-405
lines changed

Some content is hidden

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

116 files changed

+1049
-405
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub trait LayoutCalculator {
134134
scalar_valid_range: (Bound<u128>, Bound<u128>),
135135
discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool),
136136
discriminants: impl Iterator<Item = (VariantIdx, i128)>,
137-
niche_optimize_enum: bool,
137+
dont_niche_optimize_enum: bool,
138138
always_sized: bool,
139139
) -> Option<LayoutS> {
140140
let dl = self.current_data_layout();
@@ -183,10 +183,10 @@ pub trait LayoutCalculator {
183183
// (Typechecking will reject discriminant-sizing attrs.)
184184

185185
let v = present_first;
186-
let kind = if is_enum || variants[v].is_empty() {
186+
let kind = if is_enum || variants[v].is_empty() || always_sized {
187187
StructKind::AlwaysSized
188188
} else {
189-
if !always_sized { StructKind::MaybeUnsized } else { StructKind::AlwaysSized }
189+
StructKind::MaybeUnsized
190190
};
191191

192192
let mut st = self.univariant(dl, &variants[v], repr, kind)?;
@@ -280,7 +280,7 @@ pub trait LayoutCalculator {
280280
}
281281

282282
let calculate_niche_filling_layout = || -> Option<TmpLayout> {
283-
if niche_optimize_enum {
283+
if dont_niche_optimize_enum {
284284
return None;
285285
}
286286

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2525
use rustc_span::{Span, DUMMY_SP};
2626
use smallvec::{smallvec, SmallVec};
2727

28-
use std::{fmt, iter};
28+
use std::{fmt, iter, mem};
2929

3030
/// When the main Rust parser encounters a syntax-extension invocation, it
3131
/// parses the arguments to the invocation as a token tree. This is a very
@@ -410,8 +410,17 @@ impl TokenStream {
410410
t1.next().is_none() && t2.next().is_none()
411411
}
412412

413-
pub fn map_enumerated<F: FnMut(usize, &TokenTree) -> TokenTree>(self, mut f: F) -> TokenStream {
414-
TokenStream(Lrc::new(self.0.iter().enumerate().map(|(i, tree)| f(i, tree)).collect()))
413+
/// Applies the supplied function to each `TokenTree` and its index in `self`, returning a new `TokenStream`
414+
///
415+
/// It is equivalent to `TokenStream::new(self.trees().cloned().enumerate().map(|(i, tt)| f(i, tt)).collect())`.
416+
pub fn map_enumerated_owned(
417+
mut self,
418+
mut f: impl FnMut(usize, TokenTree) -> TokenTree,
419+
) -> TokenStream {
420+
let owned = Lrc::make_mut(&mut self.0); // clone if necessary
421+
// rely on vec's in-place optimizations to avoid another allocation
422+
*owned = mem::take(owned).into_iter().enumerate().map(|(i, tree)| f(i, tree)).collect();
423+
self
415424
}
416425

417426
/// Create a token stream containing a single token with alone spacing.

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
1010
use rustc_middle::mir::*;
1111
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
1212
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt};
13-
use rustc_middle::ty::{Binder, TraitRef, TypeVisitableExt};
13+
use rustc_middle::ty::{TraitRef, TypeVisitableExt};
1414
use rustc_mir_dataflow::{self, Analysis};
1515
use rustc_span::{sym, Span, Symbol};
1616
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
@@ -755,10 +755,9 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
755755
}
756756

757757
let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
758-
let poly_trait_pred =
759-
Binder::dummy(trait_ref).with_constness(ty::BoundConstness::ConstIfConst);
758+
let trait_ref = trait_ref.with_constness(ty::BoundConstness::ConstIfConst);
760759
let obligation =
761-
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
760+
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
762761

763762
let implsrc = {
764763
let infcx = tcx.infer_ctxt().build();
@@ -776,11 +775,11 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
776775
}
777776
// Closure: Fn{Once|Mut}
778777
Ok(Some(ImplSource::Builtin(_)))
779-
if poly_trait_pred.self_ty().skip_binder().is_closure()
778+
if trait_ref.self_ty().is_closure()
780779
&& tcx.fn_trait_kind_from_def_id(trait_id).is_some() =>
781780
{
782781
let ty::Closure(closure_def_id, substs) =
783-
*poly_trait_pred.self_ty().no_bound_vars().unwrap().kind()
782+
*trait_ref.self_ty().kind()
784783
else {
785784
unreachable!()
786785
};
@@ -840,7 +839,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
840839
tcx,
841840
ObligationCause::dummy_with_span(*fn_span),
842841
param_env,
843-
poly_trait_pred,
842+
trait_ref,
844843
);
845844

846845
// improve diagnostics by showing what failed. Our requirements are stricter this time

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
1010
use rustc_middle::mir::{self, CallSource};
1111
use rustc_middle::ty::print::with_no_trimmed_paths;
1212
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
13+
use rustc_middle::ty::TraitRef;
1314
use rustc_middle::ty::{suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, Ty};
14-
use rustc_middle::ty::{Binder, TraitRef};
1515
use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind};
1616
use rustc_session::parse::feature_err;
1717
use rustc_span::symbol::sym;
@@ -137,12 +137,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
137137
}
138138
}
139139
Adt(..) => {
140-
let obligation = Obligation::new(
141-
tcx,
142-
ObligationCause::dummy(),
143-
param_env,
144-
Binder::dummy(trait_ref),
145-
);
140+
let obligation =
141+
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
146142

147143
let infcx = tcx.infer_ctxt().build();
148144
let mut selcx = SelectionContext::new(&infcx);

compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn register_functions(bundle: &mut FluentBundle) {
226226
pub type LazyFallbackBundle = Lrc<Lazy<FluentBundle, impl FnOnce() -> FluentBundle>>;
227227

228228
/// Return the default `FluentBundle` with standard "en-US" diagnostic messages.
229-
#[instrument(level = "trace")]
229+
#[instrument(level = "trace", skip(resources))]
230230
pub fn fallback_fluent_bundle(
231231
resources: Vec<&'static str>,
232232
with_directionality_markers: bool,
@@ -242,7 +242,6 @@ pub fn fallback_fluent_bundle(
242242
for resource in resources {
243243
let resource = FluentResource::try_new(resource.to_string())
244244
.expect("failed to parse fallback fluent resource");
245-
trace!(?resource);
246245
fallback_bundle.add_resource_overriding(resource);
247246
}
248247

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ fn expand_macro<'cx>(
223223
// Replace all the tokens for the corresponding positions in the macro, to maintain
224224
// proper positions in error reporting, while maintaining the macro_backtrace.
225225
if tts.len() == rhs.tts.len() {
226-
tts = tts.map_enumerated(|i, tt| {
227-
let mut tt = tt.clone();
226+
tts = tts.map_enumerated_owned(|i, mut tt| {
228227
let rhs_tt = &rhs.tts[i];
229228
let ctxt = tt.span().ctxt();
230229
match (&mut tt, rhs_tt) {

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ hir_analysis_static_specialize = cannot specialize on `'static` lifetime
248248
249249
hir_analysis_substs_on_overridden_impl = could not resolve substs on overridden impl
250250
251+
hir_analysis_tait_forward_compat = item constrains opaque type that is not in its signature
252+
.note = this item must mention the opaque type in its signature in order to be able to register hidden types
253+
251254
hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]`
252255
253256
hir_analysis_too_large_static = extern static is too large for the current architecture

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
981981
// intermediate types must be sized.
982982
let needs_drop_copy = || {
983983
packed && {
984-
let ty = tcx.type_of(variant.fields.raw.last().unwrap().did).subst_identity();
984+
let ty = tcx.type_of(variant.tail().did).subst_identity();
985985
let ty = tcx.erase_regions(ty);
986986
if ty.has_infer() {
987987
tcx.sess

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::hir::nested_filter;
66
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
77
use rustc_span::DUMMY_SP;
88

9-
use crate::errors::UnconstrainedOpaqueType;
9+
use crate::errors::{TaitForwardCompat, UnconstrainedOpaqueType};
1010

1111
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions
1212
/// laid for "higher-order pattern unification".
@@ -139,6 +139,15 @@ impl TaitConstraintLocator<'_> {
139139
continue;
140140
}
141141
constrained = true;
142+
if !self.tcx.opaque_types_defined_by(item_def_id).contains(&self.def_id) {
143+
self.tcx.sess.emit_err(TaitForwardCompat {
144+
span: hidden_type.span,
145+
item_span: self
146+
.tcx
147+
.def_ident_span(item_def_id)
148+
.unwrap_or_else(|| self.tcx.def_span(item_def_id)),
149+
});
150+
}
142151
let concrete_type =
143152
self.tcx.erase_regions(hidden_type.remap_generic_params_to_declaration_params(
144153
opaque_type_key,

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ pub struct UnconstrainedOpaqueType {
184184
pub what: &'static str,
185185
}
186186

187+
#[derive(Diagnostic)]
188+
#[diag(hir_analysis_tait_forward_compat)]
189+
#[note]
190+
pub struct TaitForwardCompat {
191+
#[primary_span]
192+
pub span: Span,
193+
#[note]
194+
pub item_span: Span,
195+
}
196+
187197
pub struct MissingTypeParams {
188198
pub span: Span,
189199
pub def_span: Span,

0 commit comments

Comments
 (0)