Skip to content

Commit e77366b

Browse files
committed
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
2 parents b652d9a + 54a4976 commit e77366b

File tree

25 files changed

+286
-62
lines changed

25 files changed

+286
-62
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,8 @@ fn opaque_type_cycle_error(
15141514
}
15151515
if tcx.sess.opts.unstable_opts.drop_tracking_mir
15161516
&& let DefKind::Generator = tcx.def_kind(closure_def_id)
1517+
&& let Some(generator_layout) = tcx.mir_generator_witnesses(closure_def_id)
15171518
{
1518-
let generator_layout = tcx.mir_generator_witnesses(closure_def_id);
15191519
for interior_ty in &generator_layout.field_tys {
15201520
label_match(interior_ty.ty, interior_ty.source_info.span);
15211521
}

compiler/rustc_hir_typeck/src/method/suggest.rs

+46-31
Original file line numberDiff line numberDiff line change
@@ -2633,47 +2633,62 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26332633
Nothing,
26342634
}
26352635
let ast_generics = hir.get_generics(id.owner.def_id).unwrap();
2636-
let (sp, mut introducer) = if let Some(span) =
2637-
ast_generics.bounds_span_for_suggestions(def_id)
2638-
{
2639-
(span, Introducer::Plus)
2640-
} else if let Some(colon_span) = param.colon_span {
2641-
(colon_span.shrink_to_hi(), Introducer::Nothing)
2642-
} else {
2643-
(param.span.shrink_to_hi(), Introducer::Colon)
2644-
};
2645-
if matches!(
2646-
param.kind,
2647-
hir::GenericParamKind::Type { synthetic: true, .. },
2648-
) {
2649-
introducer = Introducer::Plus
2650-
}
26512636
let trait_def_ids: FxHashSet<DefId> = ast_generics
26522637
.bounds_for_param(def_id)
26532638
.flat_map(|bp| bp.bounds.iter())
26542639
.filter_map(|bound| bound.trait_ref()?.trait_def_id())
26552640
.collect();
2656-
if !candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) {
2657-
err.span_suggestions(
2658-
sp,
2659-
message(format!(
2660-
"restrict type parameter `{}` with",
2661-
param.name.ident(),
2662-
)),
2641+
if candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) {
2642+
return;
2643+
}
2644+
let msg = message(format!(
2645+
"restrict type parameter `{}` with",
2646+
param.name.ident(),
2647+
));
2648+
let bounds_span = ast_generics.bounds_span_for_suggestions(def_id);
2649+
if rcvr_ty.is_ref() && param.is_impl_trait() && bounds_span.is_some() {
2650+
err.multipart_suggestions(
2651+
msg,
26632652
candidates.iter().map(|t| {
2664-
format!(
2665-
"{} {}",
2666-
match introducer {
2667-
Introducer::Plus => " +",
2668-
Introducer::Colon => ":",
2669-
Introducer::Nothing => "",
2670-
},
2671-
self.tcx.def_path_str(t.def_id),
2672-
)
2653+
vec![
2654+
(param.span.shrink_to_lo(), "(".to_string()),
2655+
(
2656+
bounds_span.unwrap(),
2657+
format!(" + {})", self.tcx.def_path_str(t.def_id)),
2658+
),
2659+
]
26732660
}),
26742661
Applicability::MaybeIncorrect,
26752662
);
2663+
return;
26762664
}
2665+
2666+
let (sp, introducer) = if let Some(span) = bounds_span {
2667+
(span, Introducer::Plus)
2668+
} else if let Some(colon_span) = param.colon_span {
2669+
(colon_span.shrink_to_hi(), Introducer::Nothing)
2670+
} else if param.is_impl_trait() {
2671+
(param.span.shrink_to_hi(), Introducer::Plus)
2672+
} else {
2673+
(param.span.shrink_to_hi(), Introducer::Colon)
2674+
};
2675+
2676+
err.span_suggestions(
2677+
sp,
2678+
msg,
2679+
candidates.iter().map(|t| {
2680+
format!(
2681+
"{} {}",
2682+
match introducer {
2683+
Introducer::Plus => " +",
2684+
Introducer::Colon => ":",
2685+
Introducer::Nothing => "",
2686+
},
2687+
self.tcx.def_path_str(t.def_id)
2688+
)
2689+
}),
2690+
Applicability::MaybeIncorrect,
2691+
);
26772692
return;
26782693
}
26792694
Node::Item(hir::Item {

compiler/rustc_metadata/src/rmeta/encoder.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1516,8 +1516,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15161516
if encode_opt {
15171517
record!(self.tables.optimized_mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
15181518

1519-
if tcx.sess.opts.unstable_opts.drop_tracking_mir && let DefKind::Generator = self.tcx.def_kind(def_id) {
1520-
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- tcx.mir_generator_witnesses(def_id));
1519+
if tcx.sess.opts.unstable_opts.drop_tracking_mir
1520+
&& let DefKind::Generator = self.tcx.def_kind(def_id)
1521+
&& let Some(witnesses) = tcx.mir_generator_witnesses(def_id)
1522+
{
1523+
record!(self.tables.mir_generator_witnesses[def_id.to_def_id()] <- witnesses);
15211524
}
15221525
}
15231526
if encode_const {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ rustc_queries! {
527527
}
528528
}
529529

530-
query mir_generator_witnesses(key: DefId) -> &'tcx mir::GeneratorLayout<'tcx> {
530+
query mir_generator_witnesses(key: DefId) -> &'tcx Option<mir::GeneratorLayout<'tcx>> {
531531
arena_cache
532532
desc { |tcx| "generator witness types for `{}`", tcx.def_path_str(key) }
533533
cache_on_disk_if { key.is_local() }

compiler/rustc_middle/src/ty/sty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,9 @@ impl<'tcx> Region<'tcx> {
17081708
ty::ReErased => {
17091709
flags = flags | TypeFlags::HAS_RE_ERASED;
17101710
}
1711-
ty::ReError(_) => {}
1711+
ty::ReError(_) => {
1712+
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1713+
}
17121714
}
17131715

17141716
debug!("type_flags({:?}) = {:?}", self, flags);

compiler/rustc_middle/src/ty/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,10 @@ impl<'tcx> TyCtxt<'tcx> {
668668
self,
669669
def_id: DefId,
670670
) -> impl Iterator<Item = ty::EarlyBinder<Ty<'tcx>>> {
671-
let generator_layout = &self.mir_generator_witnesses(def_id);
671+
let generator_layout = self.mir_generator_witnesses(def_id);
672672
generator_layout
673-
.field_tys
674-
.iter()
673+
.as_ref()
674+
.map_or_else(|| [].iter(), |l| l.field_tys.iter())
675675
.filter(|decl| !decl.ignore_for_traits)
676676
.map(|decl| ty::EarlyBinder(decl.ty))
677677
}

compiler/rustc_mir_transform/src/generator.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ fn create_cases<'tcx>(
13971397
pub(crate) fn mir_generator_witnesses<'tcx>(
13981398
tcx: TyCtxt<'tcx>,
13991399
def_id: LocalDefId,
1400-
) -> GeneratorLayout<'tcx> {
1400+
) -> Option<GeneratorLayout<'tcx>> {
14011401
assert!(tcx.sess.opts.unstable_opts.drop_tracking_mir);
14021402

14031403
let (body, _) = tcx.mir_promoted(def_id);
@@ -1410,6 +1410,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14101410
// Get the interior types and substs which typeck computed
14111411
let movable = match *gen_ty.kind() {
14121412
ty::Generator(_, _, movability) => movability == hir::Movability::Movable,
1413+
ty::Error(_) => return None,
14131414
_ => span_bug!(body.span, "unexpected generator type {}", gen_ty),
14141415
};
14151416

@@ -1425,7 +1426,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14251426

14261427
check_suspend_tys(tcx, &generator_layout, &body);
14271428

1428-
generator_layout
1429+
Some(generator_layout)
14291430
}
14301431

14311432
impl<'tcx> MirPass<'tcx> for StateTransform {

compiler/rustc_trait_selection/src/solve/project_goals.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,24 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
124124
};
125125

126126
if !assoc_def.item.defaultness(tcx).has_value() {
127-
tcx.sess.delay_span_bug(
127+
let guar = tcx.sess.delay_span_bug(
128128
tcx.def_span(assoc_def.item.def_id),
129129
"missing value for assoc item in impl",
130130
);
131+
let error_term = match assoc_def.item.kind {
132+
ty::AssocKind::Const => tcx
133+
.const_error(
134+
tcx.type_of(goal.predicate.def_id())
135+
.subst(tcx, goal.predicate.projection_ty.substs),
136+
guar,
137+
)
138+
.into(),
139+
ty::AssocKind::Type => tcx.ty_error(guar).into(),
140+
ty::AssocKind::Fn => unreachable!(),
141+
};
142+
ecx.eq(goal.param_env, goal.predicate.term, error_term)
143+
.expect("expected goal term to be fully unconstrained");
144+
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
131145
}
132146

133147
// Getting the right substitutions here is complex, e.g. given:

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2447,10 +2447,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24472447
&& generator_did.is_local()
24482448
// Try to avoid cycles.
24492449
&& !generator_within_in_progress_typeck
2450+
&& let Some(generator_info) = self.tcx.mir_generator_witnesses(generator_did)
24502451
{
2451-
let generator_info = &self.tcx.mir_generator_witnesses(generator_did);
24522452
debug!(?generator_info);
2453-
24542453
'find_source: for (variant, source_info) in
24552454
generator_info.variant_fields.iter().zip(&generator_info.variant_source_info)
24562455
{

library/alloc/src/vec/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,14 @@ impl<T, A: Allocator> Vec<T, A> {
646646
///
647647
/// // The vector contains no items, even though it has capacity for more
648648
/// assert_eq!(vec.len(), 0);
649-
/// assert_eq!(vec.capacity(), 10);
649+
/// assert!(vec.capacity() >= 10);
650650
///
651651
/// // These are all done without reallocating...
652652
/// for i in 0..10 {
653653
/// vec.push(i);
654654
/// }
655655
/// assert_eq!(vec.len(), 10);
656-
/// assert_eq!(vec.capacity(), 10);
656+
/// assert!(vec.capacity() >= 10);
657657
///
658658
/// // ...but this may make the vector reallocate
659659
/// vec.push(11);
@@ -877,7 +877,7 @@ impl<T, A: Allocator> Vec<T, A> {
877877
/// ```
878878
/// let mut vec: Vec<i32> = Vec::with_capacity(10);
879879
/// vec.push(42);
880-
/// assert_eq!(vec.capacity(), 10);
880+
/// assert!(vec.capacity() >= 10);
881881
/// ```
882882
#[inline]
883883
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1028,7 +1028,7 @@ impl<T, A: Allocator> Vec<T, A> {
10281028
/// ```
10291029
/// let mut vec = Vec::with_capacity(10);
10301030
/// vec.extend([1, 2, 3]);
1031-
/// assert_eq!(vec.capacity(), 10);
1031+
/// assert!(vec.capacity() >= 10);
10321032
/// vec.shrink_to_fit();
10331033
/// assert!(vec.capacity() >= 3);
10341034
/// ```
@@ -1055,7 +1055,7 @@ impl<T, A: Allocator> Vec<T, A> {
10551055
/// ```
10561056
/// let mut vec = Vec::with_capacity(10);
10571057
/// vec.extend([1, 2, 3]);
1058-
/// assert_eq!(vec.capacity(), 10);
1058+
/// assert!(vec.capacity() >= 10);
10591059
/// vec.shrink_to(4);
10601060
/// assert!(vec.capacity() >= 4);
10611061
/// vec.shrink_to(0);
@@ -1090,7 +1090,7 @@ impl<T, A: Allocator> Vec<T, A> {
10901090
/// let mut vec = Vec::with_capacity(10);
10911091
/// vec.extend([1, 2, 3]);
10921092
///
1093-
/// assert_eq!(vec.capacity(), 10);
1093+
/// assert!(vec.capacity() >= 10);
10941094
/// let slice = vec.into_boxed_slice();
10951095
/// assert_eq!(slice.into_vec().capacity(), 3);
10961096
/// ```

library/core/src/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ where
866866
///
867867
/// A data provider provides values by calling this type's provide methods.
868868
#[unstable(feature = "provide_any", issue = "96024")]
869-
#[repr(transparent)]
869+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
870870
pub struct Demand<'a>(dyn Erased<'a> + 'a);
871871

872872
impl<'a> Demand<'a> {

library/core/src/ffi/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ mod c_long_definition {
203203
// be UB.
204204
#[doc = include_str!("c_void.md")]
205205
#[cfg_attr(not(bootstrap), lang = "c_void")]
206-
#[repr(u8)]
206+
#[cfg_attr(not(doc), repr(u8))] // work around https://github.com/rust-lang/rust/issues/90435
207207
#[stable(feature = "core_c_void", since = "1.30.0")]
208208
pub enum c_void {
209209
#[unstable(
@@ -244,7 +244,7 @@ impl fmt::Debug for c_void {
244244
target_os = "uefi",
245245
windows,
246246
))]
247-
#[repr(transparent)]
247+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
248248
#[unstable(
249249
feature = "c_variadic",
250250
reason = "the `c_variadic` feature has not been properly tested on \
@@ -296,7 +296,7 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
296296
not(target_os = "uefi"),
297297
not(windows),
298298
))]
299-
#[repr(C)]
299+
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
300300
#[derive(Debug)]
301301
#[unstable(
302302
feature = "c_variadic",
@@ -316,7 +316,7 @@ pub struct VaListImpl<'f> {
316316

317317
/// PowerPC ABI implementation of a `va_list`.
318318
#[cfg(all(target_arch = "powerpc", not(target_os = "uefi"), not(windows)))]
319-
#[repr(C)]
319+
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
320320
#[derive(Debug)]
321321
#[unstable(
322322
feature = "c_variadic",
@@ -336,7 +336,7 @@ pub struct VaListImpl<'f> {
336336

337337
/// s390x ABI implementation of a `va_list`.
338338
#[cfg(target_arch = "s390x")]
339-
#[repr(C)]
339+
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
340340
#[derive(Debug)]
341341
#[unstable(
342342
feature = "c_variadic",
@@ -355,7 +355,7 @@ pub struct VaListImpl<'f> {
355355

356356
/// x86_64 ABI implementation of a `va_list`.
357357
#[cfg(all(target_arch = "x86_64", not(target_os = "uefi"), not(windows)))]
358-
#[repr(C)]
358+
#[cfg_attr(not(doc), repr(C))] // work around https://github.com/rust-lang/rust/issues/66401
359359
#[derive(Debug)]
360360
#[unstable(
361361
feature = "c_variadic",
@@ -373,7 +373,7 @@ pub struct VaListImpl<'f> {
373373
}
374374

375375
/// A wrapper for a `va_list`
376-
#[repr(transparent)]
376+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
377377
#[derive(Debug)]
378378
#[unstable(
379379
feature = "c_variadic",

library/core/src/task/wake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl fmt::Debug for Context<'_> {
232232
///
233233
/// [`Future::poll()`]: core::future::Future::poll
234234
/// [`Poll::Pending`]: core::task::Poll::Pending
235-
#[repr(transparent)]
235+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/66401
236236
#[stable(feature = "futures_api", since = "1.36.0")]
237237
pub struct Waker {
238238
waker: RawWaker,

library/portable-simd/crates/core_simd/src/masks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl_element! { isize }
8888
/// The layout of this type is unspecified, and may change between platforms
8989
/// and/or Rust versions, and code should not assume that it is equivalent to
9090
/// `[T; LANES]`.
91-
#[repr(transparent)]
91+
#[cfg_attr(not(doc), repr(transparent))] // work around https://github.com/rust-lang/rust/issues/90435
9292
pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
9393
where
9494
T: MaskElement,

0 commit comments

Comments
 (0)