Skip to content

Commit de341fe

Browse files
committed
Auto merge of rust-lang#102526 - matthiaskrgr:rollup-9o6p98c, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#102361 (Fix ICE in const_trait check code) - rust-lang#102373 (Flush delayed bugs before codegen) - rust-lang#102483 (create def ids for impl traits during ast lowering) - rust-lang#102490 (Generate synthetic region from `impl` even in closure body within an associated fn) - rust-lang#102492 (Don't lower assoc bindings just to deny them) - rust-lang#102493 (Group together more size assertions.) - rust-lang#102521 (rustdoc: add missing margin to no-docblock methods) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c5b105d + 2fadfe0 commit de341fe

File tree

29 files changed

+209
-92
lines changed

29 files changed

+209
-92
lines changed

Diff for: compiler/rustc_ast/src/token.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ pub enum TokenKind {
256256
Eof,
257257
}
258258

259-
// `TokenKind` is used a lot. Make sure it doesn't unintentionally get bigger.
260-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
261-
rustc_data_structures::static_assert_size!(TokenKind, 16);
262-
263259
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
264260
pub struct Token {
265261
pub kind: TokenKind,
@@ -752,10 +748,6 @@ pub enum Nonterminal {
752748
NtVis(P<ast::Visibility>),
753749
}
754750

755-
// `Nonterminal` is used a lot. Make sure it doesn't unintentionally get bigger.
756-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
757-
rustc_data_structures::static_assert_size!(Nonterminal, 16);
758-
759751
#[derive(Debug, Copy, Clone, PartialEq, Encodable, Decodable)]
760752
pub enum NonterminalKind {
761753
Item,
@@ -894,3 +886,16 @@ where
894886
panic!("interpolated tokens should not be present in the HIR")
895887
}
896888
}
889+
890+
// Some types are used a lot. Make sure they don't unintentionally get bigger.
891+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
892+
mod size_asserts {
893+
use super::*;
894+
use rustc_data_structures::static_assert_size;
895+
// These are in alphabetical order, which is easy to maintain.
896+
static_assert_size!(Lit, 12);
897+
static_assert_size!(LitKind, 2);
898+
static_assert_size!(Nonterminal, 16);
899+
static_assert_size!(Token, 24);
900+
static_assert_size!(TokenKind, 16);
901+
}

Diff for: compiler/rustc_ast/src/tokenstream.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ pub enum TokenTree {
4747
Delimited(DelimSpan, Delimiter, TokenStream),
4848
}
4949

50-
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
51-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
52-
rustc_data_structures::static_assert_size!(TokenTree, 32);
53-
5450
// Ensure all fields of `TokenTree` is `Send` and `Sync`.
5551
#[cfg(parallel_compiler)]
5652
fn _dummy()
@@ -308,10 +304,6 @@ pub struct AttributesData {
308304
#[derive(Clone, Debug, Default, Encodable, Decodable)]
309305
pub struct TokenStream(pub(crate) Lrc<Vec<TokenTree>>);
310306

311-
// `TokenStream` is used a lot. Make sure it doesn't unintentionally get bigger.
312-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
313-
rustc_data_structures::static_assert_size!(TokenStream, 8);
314-
315307
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
316308
pub enum Spacing {
317309
Alone,
@@ -664,3 +656,16 @@ impl DelimSpan {
664656
self.open.with_hi(self.close.hi())
665657
}
666658
}
659+
660+
// Some types are used a lot. Make sure they don't unintentionally get bigger.
661+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
662+
mod size_asserts {
663+
use super::*;
664+
use rustc_data_structures::static_assert_size;
665+
// These are in alphabetical order, which is easy to maintain.
666+
static_assert_size!(AttrTokenStream, 8);
667+
static_assert_size!(AttrTokenTree, 32);
668+
static_assert_size!(LazyAttrTokenStream, 8);
669+
static_assert_size!(TokenStream, 8);
670+
static_assert_size!(TokenTree, 32);
671+
}

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
6161
use rustc_hir::definitions::DefPathData;
6262
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
6363
use rustc_index::vec::{Idx, IndexVec};
64-
use rustc_middle::span_bug;
6564
use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
65+
use rustc_middle::{bug, span_bug};
6666
use rustc_session::parse::feature_err;
6767
use rustc_span::hygiene::MacroKind;
6868
use rustc_span::source_map::DesugaringKind;
@@ -1060,13 +1060,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10601060
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`. We do this by
10611061
// constructing the HIR for `impl bounds...` and then lowering that.
10621062

1063-
let parent_def_id = self.current_hir_id_owner;
10641063
let impl_trait_node_id = self.next_node_id();
1065-
self.create_def(
1066-
parent_def_id.def_id,
1067-
impl_trait_node_id,
1068-
DefPathData::ImplTrait,
1069-
);
10701064

10711065
self.with_dyn_type_scope(false, |this| {
10721066
let node_id = this.next_node_id();
@@ -1357,9 +1351,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13571351
def_node_id,
13581352
bounds,
13591353
false,
1360-
&ImplTraitContext::TypeAliasesOpaqueTy,
1354+
itctx,
13611355
),
13621356
ImplTraitContext::Universal => {
1357+
self.create_def(
1358+
self.current_hir_id_owner.def_id,
1359+
def_node_id,
1360+
DefPathData::ImplTrait,
1361+
);
13631362
let span = t.span;
13641363
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
13651364
let (param, bounds, path) =
@@ -1453,7 +1452,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14531452
// frequently opened issues show.
14541453
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);
14551454

1456-
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
1455+
let opaque_ty_def_id = match origin {
1456+
hir::OpaqueTyOrigin::TyAlias => self.create_def(
1457+
self.current_hir_id_owner.def_id,
1458+
opaque_ty_node_id,
1459+
DefPathData::ImplTrait,
1460+
),
1461+
hir::OpaqueTyOrigin::FnReturn(fn_def_id) => {
1462+
self.create_def(fn_def_id, opaque_ty_node_id, DefPathData::ImplTrait)
1463+
}
1464+
hir::OpaqueTyOrigin::AsyncFn(..) => bug!("unreachable"),
1465+
};
14571466
debug!(?opaque_ty_def_id);
14581467

14591468
// Contains the new lifetime definitions created for the TAIT (if any).

Diff for: compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -864,15 +864,13 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
864864
};
865865

866866
let tcx = self.infcx.tcx;
867-
let body_parent_did = tcx.opt_parent(self.mir_def_id().to_def_id())?;
868-
if tcx.parent(region.def_id) != body_parent_did
869-
|| tcx.def_kind(body_parent_did) != DefKind::Impl
870-
{
867+
let region_parent = tcx.parent(region.def_id);
868+
if tcx.def_kind(region_parent) != DefKind::Impl {
871869
return None;
872870
}
873871

874872
let mut found = false;
875-
tcx.fold_regions(tcx.type_of(body_parent_did), |r: ty::Region<'tcx>, _| {
873+
tcx.fold_regions(tcx.type_of(region_parent), |r: ty::Region<'tcx>, _| {
876874
if *r == ty::ReEarlyBound(region) {
877875
found = true;
878876
}

Diff for: compiler/rustc_errors/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub type PErr<'a> = DiagnosticBuilder<'a, ErrorGuaranteed>;
6666
pub type PResult<'a, T> = Result<T, PErr<'a>>;
6767

6868
// `PResult` is used a lot. Make sure it doesn't unintentionally get bigger.
69-
// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.)
69+
// (See also the comment on `DiagnosticBuilderInner`'s `diagnostic` field.)
7070
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
7171
rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16);
7272
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
@@ -1134,6 +1134,12 @@ impl Handler {
11341134
);
11351135
std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations)
11361136
}
1137+
1138+
pub fn flush_delayed(&self) {
1139+
let mut inner = self.inner.lock();
1140+
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());
1141+
inner.flush_delayed(bugs, "no errors encountered even though `delay_span_bug` issued");
1142+
}
11371143
}
11381144

11391145
impl HandlerInner {

Diff for: compiler/rustc_hir_analysis/src/astconv/generics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
448448
let infer_lifetimes =
449449
(gen_pos != GenericArgPosition::Type || infer_args) && !gen_args.has_lifetime_params();
450450

451-
if gen_pos != GenericArgPosition::Type && !gen_args.bindings.is_empty() {
452-
Self::prohibit_assoc_ty_binding(tcx, gen_args.bindings[0].span);
451+
if gen_pos != GenericArgPosition::Type && let Some(b) = gen_args.bindings.first() {
452+
Self::prohibit_assoc_ty_binding(tcx, b.span);
453453
}
454454

455455
let explicit_late_bound =

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
276276
item_segment.infer_args,
277277
None,
278278
);
279-
let assoc_bindings = self.create_assoc_bindings_for_generic_args(item_segment.args());
280-
281-
if let Some(b) = assoc_bindings.first() {
279+
if let Some(b) = item_segment.args().bindings.first() {
282280
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
283281
}
284282

@@ -605,8 +603,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
605603
None,
606604
);
607605

608-
let assoc_bindings = self.create_assoc_bindings_for_generic_args(item_segment.args());
609-
if let Some(b) = assoc_bindings.first() {
606+
if let Some(b) = item_segment.args().bindings.first() {
610607
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
611608
}
612609

@@ -794,8 +791,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
794791
trait_segment,
795792
is_impl,
796793
);
797-
let assoc_bindings = self.create_assoc_bindings_for_generic_args(trait_segment.args());
798-
if let Some(b) = assoc_bindings.first() {
794+
if let Some(b) = trait_segment.args().bindings.first() {
799795
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
800796
}
801797
ty::TraitRef::new(trait_def_id, substs)
@@ -2207,8 +2203,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22072203

22082204
for segment in segments {
22092205
// Only emit the first error to avoid overloading the user with error messages.
2210-
if let [binding, ..] = segment.args().bindings {
2211-
Self::prohibit_assoc_ty_binding(self.tcx(), binding.span);
2206+
if let Some(b) = segment.args().bindings.first() {
2207+
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
22122208
return true;
22132209
}
22142210
}

Diff for: compiler/rustc_interface/src/queries.rs

+4
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ impl<'tcx> Queries<'tcx> {
246246
// Don't do code generation if there were any errors
247247
self.session().compile_status()?;
248248

249+
// If we have any delayed bugs, for example because we created TyKind::Error earlier,
250+
// it's likely that codegen will only cause more ICEs, obscuring the original problem
251+
self.session().diagnostic().flush_delayed();
252+
249253
// Hook for UI tests.
250254
Self::check_for_rustc_errors_attr(tcx);
251255

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_index::vec::Idx;
1414
use rustc_middle::hir::nested_filter;
1515
use rustc_span::def_id::StableCrateId;
1616
use rustc_span::symbol::{kw, sym, Ident, Symbol};
17-
use rustc_span::Span;
17+
use rustc_span::{Span, DUMMY_SP};
1818
use rustc_target::spec::abi::Abi;
1919

2020
#[inline]
@@ -1131,7 +1131,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
11311131
.filter_map(|(def_id, info)| {
11321132
let _ = info.as_owner()?;
11331133
let def_path_hash = definitions.def_path_hash(def_id);
1134-
let span = resolutions.source_span[def_id];
1134+
let span = resolutions.source_span.get(def_id).unwrap_or(&DUMMY_SP);
11351135
debug_assert_eq!(span.parent(), None);
11361136
Some((def_path_hash, span))
11371137
})

Diff for: compiler/rustc_parse/src/parser/attr_wrapper.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ pub struct AttrWrapper {
3232
start_pos: usize,
3333
}
3434

35-
// This struct is passed around very frequently,
36-
// so make sure it doesn't accidentally get larger
37-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
38-
rustc_data_structures::static_assert_size!(AttrWrapper, 16);
39-
4035
impl AttrWrapper {
4136
pub(super) fn new(attrs: AttrVec, start_pos: usize) -> AttrWrapper {
4237
AttrWrapper { attrs, start_pos }
@@ -96,9 +91,6 @@ struct LazyAttrTokenStreamImpl {
9691
replace_ranges: Box<[ReplaceRange]>,
9792
}
9893

99-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
100-
rustc_data_structures::static_assert_size!(LazyAttrTokenStreamImpl, 144);
101-
10294
impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
10395
fn to_attr_token_stream(&self) -> AttrTokenStream {
10496
// The token produced by the final call to `{,inlined_}next` was not
@@ -461,3 +453,13 @@ fn make_token_stream(
461453
}
462454
AttrTokenStream::new(final_buf.inner)
463455
}
456+
457+
// Some types are used a lot. Make sure they don't unintentionally get bigger.
458+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
459+
mod size_asserts {
460+
use super::*;
461+
use rustc_data_structures::static_assert_size;
462+
// These are in alphabetical order, which is easy to maintain.
463+
static_assert_size!(AttrWrapper, 16);
464+
static_assert_size!(LazyAttrTokenStreamImpl, 144);
465+
}

Diff for: compiler/rustc_passes/src/check_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
198198
of_trait: Some(trait_ref),
199199
..
200200
}) = item.kind
201+
&& let Some(def_id) = trait_ref.trait_def_id()
201202
{
202-
let def_id = trait_ref.trait_def_id().unwrap();
203203
let source_map = tcx.sess.source_map();
204204
if !tcx.has_attr(def_id, sym::const_trait) {
205205
tcx.sess

Diff for: compiler/rustc_query_system/src/ich/hcx.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_session::cstore::CrateStore;
1212
use rustc_session::Session;
1313
use rustc_span::source_map::SourceMap;
1414
use rustc_span::symbol::Symbol;
15-
use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData};
15+
use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData, DUMMY_SP};
1616

1717
/// This is the context state available during incr. comp. hashing. It contains
1818
/// enough information to transform `DefId`s and `HirId`s into stable `DefPath`s (i.e.,
@@ -185,7 +185,7 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> {
185185

186186
#[inline]
187187
fn def_span(&self, def_id: LocalDefId) -> Span {
188-
self.source_span[def_id]
188+
*self.source_span.get(def_id).unwrap_or(&DUMMY_SP)
189189
}
190190

191191
#[inline]

Diff for: compiler/rustc_resolve/src/def_collector.rs

-15
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,6 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
285285
fn visit_ty(&mut self, ty: &'a Ty) {
286286
match ty.kind {
287287
TyKind::MacCall(..) => self.visit_macro_invoc(ty.id),
288-
TyKind::ImplTrait(node_id, _) => {
289-
let parent_def = match self.impl_trait_context {
290-
ImplTraitContext::Universal(item_def) => self.resolver.create_def(
291-
item_def,
292-
node_id,
293-
DefPathData::ImplTrait,
294-
self.expansion.to_expn_id(),
295-
ty.span,
296-
),
297-
ImplTraitContext::Existential => {
298-
self.create_def(node_id, DefPathData::ImplTrait, ty.span)
299-
}
300-
};
301-
self.with_parent(parent_def, |this| visit::walk_ty(this, ty))
302-
}
303288
_ => visit::walk_ty(self, ty),
304289
}
305290
}

Diff for: src/librustdoc/html/render/print_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
718718
if toggled {
719719
write!(w, "<details class=\"rustdoc-toggle method-toggle\" open><summary>");
720720
}
721-
write!(w, "<div id=\"{}\" class=\"method has-srclink\">", id);
721+
write!(w, "<section id=\"{}\" class=\"method has-srclink\">", id);
722722
render_rightside(w, cx, m, t, RenderMode::Normal);
723723
write!(w, "<h4 class=\"code-header\">");
724724
render_assoc_item(
@@ -730,7 +730,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean:
730730
RenderMode::Normal,
731731
);
732732
w.write_str("</h4>");
733-
w.write_str("</div>");
733+
w.write_str("</section>");
734734
if toggled {
735735
write!(w, "</summary>");
736736
w.push_buffer(content);

Diff for: src/librustdoc/html/static/css/rustdoc.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,10 @@ in storage.js plus the media query with (min-width: 701px)
20062006
.method-toggle summary,
20072007
.implementors-toggle summary,
20082008
.impl,
2009-
#implementors-list > .docblock {
2009+
#implementors-list > .docblock,
2010+
.impl-items > section,
2011+
.methods > section
2012+
{
20102013
margin-bottom: 0.75em;
20112014
}
20122015

Diff for: src/test/rustdoc-gui/no-docblock.goml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This test checks that there are margins applied to methods with no docblocks.
2+
goto: file://|DOC_PATH|/test_docs/trait.TraitWithNoDocblocks.html
3+
// Check that the two methods are more than 24px apart.
4+
compare-elements-position-near-false: ("//*[@id='tymethod.first_fn']", "//*[@id='tymethod.second_fn']", {"y": 24})
5+
6+
goto: file://|DOC_PATH|/test_docs/struct.TypeWithNoDocblocks.html
7+
// Check that the two methods are more than 24px apart.
8+
compare-elements-position-near-false: ("//*[@id='method.first_fn']", "//*[@id='method.second_fn']", {"y": 24})

0 commit comments

Comments
 (0)