Auto merge of #111650 - matthiaskrgr:rollup-n7w17v4, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #107680 (Hide repr attribute from doc of types without guaranteed repr) - #111488 (Use error term in projection if missing associated item in new solver) - #111533 (Handle error body in generator layout) - #111573 (Erase `ReError` properly) - #111592 (Change Vec examples to not assert exact capacity except where it is guaranteed) - #111610 (fix(diagnostic): wrap parens for ref impl trait param) - #111642 ([rustdoc] Only keep impl blocks from bodies) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
e77366b57b
25 changed files with 286 additions and 62 deletions
|
@ -1514,8 +1514,8 @@ fn opaque_type_cycle_error(
|
|||
}
|
||||
if tcx.sess.opts.unstable_opts.drop_tracking_mir
|
||||
&& let DefKind::Generator = tcx.def_kind(closure_def_id)
|
||||
&& let Some(generator_layout) = tcx.mir_generator_witnesses(closure_def_id)
|
||||
{
|
||||
let generator_layout = tcx.mir_generator_witnesses(closure_def_id);
|
||||
for interior_ty in &generator_layout.field_tys {
|
||||
label_match(interior_ty.ty, interior_ty.source_info.span);
|
||||
}
|
||||
|
|
|
@ -2633,47 +2633,62 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
Nothing,
|
||||
}
|
||||
let ast_generics = hir.get_generics(id.owner.def_id).unwrap();
|
||||
let (sp, mut introducer) = if let Some(span) =
|
||||
ast_generics.bounds_span_for_suggestions(def_id)
|
||||
{
|
||||
(span, Introducer::Plus)
|
||||
} else if let Some(colon_span) = param.colon_span {
|
||||
(colon_span.shrink_to_hi(), Introducer::Nothing)
|
||||
} else {
|
||||
(param.span.shrink_to_hi(), Introducer::Colon)
|
||||
};
|
||||
if matches!(
|
||||
param.kind,
|
||||
hir::GenericParamKind::Type { synthetic: true, .. },
|
||||
) {
|
||||
introducer = Introducer::Plus
|
||||
}
|
||||
let trait_def_ids: FxHashSet<DefId> = ast_generics
|
||||
.bounds_for_param(def_id)
|
||||
.flat_map(|bp| bp.bounds.iter())
|
||||
.filter_map(|bound| bound.trait_ref()?.trait_def_id())
|
||||
.collect();
|
||||
if !candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) {
|
||||
err.span_suggestions(
|
||||
sp,
|
||||
message(format!(
|
||||
"restrict type parameter `{}` with",
|
||||
param.name.ident(),
|
||||
)),
|
||||
if candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) {
|
||||
return;
|
||||
}
|
||||
let msg = message(format!(
|
||||
"restrict type parameter `{}` with",
|
||||
param.name.ident(),
|
||||
));
|
||||
let bounds_span = ast_generics.bounds_span_for_suggestions(def_id);
|
||||
if rcvr_ty.is_ref() && param.is_impl_trait() && bounds_span.is_some() {
|
||||
err.multipart_suggestions(
|
||||
msg,
|
||||
candidates.iter().map(|t| {
|
||||
format!(
|
||||
"{} {}",
|
||||
match introducer {
|
||||
Introducer::Plus => " +",
|
||||
Introducer::Colon => ":",
|
||||
Introducer::Nothing => "",
|
||||
},
|
||||
self.tcx.def_path_str(t.def_id),
|
||||
)
|
||||
vec![
|
||||
(param.span.shrink_to_lo(), "(".to_string()),
|
||||
(
|
||||
bounds_span.unwrap(),
|
||||
format!(" + {})", self.tcx.def_path_str(t.def_id)),
|
||||
),
|
||||
]
|
||||
}),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let (sp, introducer) = if let Some(span) = bounds_span {
|
||||
(span, Introducer::Plus)
|
||||
} else if let Some(colon_span) = param.colon_span {
|
||||
(colon_span.shrink_to_hi(), Introducer::Nothing)
|
||||
} else if param.is_impl_trait() {
|
||||
(param.span.shrink_to_hi(), Introducer::Plus)
|
||||
} else {
|
||||
(param.span.shrink_to_hi(), Introducer::Colon)
|
||||
};
|
||||
|
||||
err.span_suggestions(
|
||||
sp,
|
||||
msg,
|
||||
candidates.iter().map(|t| {
|
||||
format!(
|
||||
"{} {}",
|
||||
match introducer {
|
||||
Introducer::Plus => " +",
|
||||
Introducer::Colon => ":",
|
||||
Introducer::Nothing => "",
|
||||
},
|
||||
self.tcx.def_path_str(t.def_id)
|
||||
)
|
||||
}),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
return;
|
||||
}
|
||||
Node::Item(hir::Item {
|
||||
|
|
|
@ -1516,8 +1516,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
if encode_opt {
|
||||
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
|
||||
|
||||
if tcx.sess.opts.unstable_opts.drop_tracking_mir && let DefKind::Generator = self.tcx.def_kind(def_id) {
|
||||
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- tcx.mir_generator_witnesses(def_id));
|
||||
if tcx.sess.opts.unstable_opts.drop_tracking_mir
|
||||
&& let DefKind::Generator = self.tcx.def_kind(def_id)
|
||||
&& let Some(witnesses) = tcx.mir_generator_witnesses(def_id)
|
||||
{
|
||||
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses);
|
||||
}
|
||||
}
|
||||
if encode_const {
|
||||
|
|
|
@ -527,7 +527,7 @@ rustc_queries! {
|
|||
}
|
||||
}
|
||||
|
||||
query mir_generator_witnesses(key: DefId) -> &'tcx mir::GeneratorLayout<'tcx> {
|
||||
query mir_generator_witnesses(key: DefId) -> &'tcx Option<mir::GeneratorLayout<'tcx>> {
|
||||
arena_cache
|
||||
desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { key.is_local() }
|
||||
|
|
|
@ -1708,7 +1708,9 @@ impl<'tcx> Region<'tcx> {
|
|||
ty::ReErased => {
|
||||
flags = flags | TypeFlags::HAS_RE_ERASED;
|
||||
}
|
||||
ty::ReError(_) => {}
|
||||
ty::ReError(_) => {
|
||||
flags = flags | TypeFlags::HAS_FREE_REGIONS;
|
||||
}
|
||||
}
|
||||
|
||||
debug!("type_flags({:?}) = {:?}", self, flags);
|
||||
|
|
|
@ -668,10 +668,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self,
|
||||
def_id: DefId,
|
||||
) -> impl Iterator<Item = ty::EarlyBinder<Ty<'tcx>>> {
|
||||
let generator_layout = &self.mir_generator_witnesses(def_id);
|
||||
let generator_layout = self.mir_generator_witnesses(def_id);
|
||||
generator_layout
|
||||
.field_tys
|
||||
.iter()
|
||||
.as_ref()
|
||||
.map_or_else(|| [].iter(), |l| l.field_tys.iter())
|
||||
.filter(|decl| !decl.ignore_for_traits)
|
||||
.map(|decl| ty::EarlyBinder(decl.ty))
|
||||
}
|
||||
|
|
|
@ -1397,7 +1397,7 @@ fn create_cases<'tcx>(
|
|||
pub(crate) fn mir_generator_witnesses<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
) -> GeneratorLayout<'tcx> {
|
||||
) -> Option<GeneratorLayout<'tcx>> {
|
||||
assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
|
||||
|
||||
let (body, _) = tcx.mir_promoted(def_id);
|
||||
|
@ -1410,6 +1410,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
|
|||
// Get the interior types and substs which typeck computed
|
||||
let movable = match *gen_ty.kind() {
|
||||
ty::Generator(_, _, movability) => movability == hir::Movability::Movable,
|
||||
ty::Error(_) => return None,
|
||||
_ => span_bug!(body.span, "unexpected generator type {}", gen_ty),
|
||||
};
|
||||
|
||||
|
@ -1425,7 +1426,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
|
|||
|
||||
check_suspend_tys(tcx, &generator_layout, &body);
|
||||
|
||||
generator_layout
|
||||
Some(generator_layout)
|
||||
}
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
|
|
|
@ -124,10 +124,24 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||
};
|
||||
|
||||
if !assoc_def.item.defaultness(tcx).has_value() {
|
||||
tcx.sess.delay_span_bug(
|
||||
let guar = tcx.sess.delay_span_bug(
|
||||
tcx.def_span(assoc_def.item.def_id),
|
||||
"missing value for assoc item in impl",
|
||||
);
|
||||
let error_term = match assoc_def.item.kind {
|
||||
ty::AssocKind::Const => tcx
|
||||
.const_error(
|
||||
tcx.type_of(goal.predicate.def_id())
|
||||
.subst(tcx, goal.predicate.projection_ty.substs),
|
||||
guar,
|
||||
)
|
||||
.into(),
|
||||
ty::AssocKind::Type => tcx.ty_error(guar).into(),
|
||||
ty::AssocKind::Fn => unreachable!(),
|
||||
};
|
||||
ecx.eq(goal.param_env, goal.predicate.term, error_term)
|
||||
.expect("expected goal term to be fully unconstrained");
|
||||
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
|
||||
}
|
||||
|
||||
// Getting the right substitutions here is complex, e.g. given:
|
||||
|
|
|
@ -2447,10 +2447,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
&& generator_did.is_local()
|
||||
// Try to avoid cycles.
|
||||
&& !generator_within_in_progress_typeck
|
||||
&& let Some(generator_info) = self.tcx.mir_generator_witnesses(generator_did)
|
||||
{
|
||||
let generator_info = &self.tcx.mir_generator_witnesses(generator_did);
|
||||
debug!(?generator_info);
|
||||
|
||||
'find_source: for (variant, source_info) in
|
||||
generator_info.variant_fields.iter().zip(&generator_info.variant_source_info)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue