Skip to content

Commit f820b75

Browse files
committed
Auto merge of #139525 - Zalathar:rollup-5t5xsrw, r=Zalathar
Rollup of 10 pull requests Successful merges: - #138676 (Implement overflow for infinite implied lifetime bounds) - #139024 (Make error message for missing fields with `..` and without `..` more consistent) - #139098 (Tell LLVM about impossible niche tags) - #139124 (compiler: report error when trait object type param reference self) - #139321 (Update to new rinja version (askama)) - #139346 (Don't construct preds w escaping bound vars in `diagnostic_hir_wf_check`) - #139386 (make it possible to use stage0 libtest on compiletest) - #139421 (Fix trait upcasting to dyn type with no principal when there are projections) - #139464 (Allow for reparsing failure when reparsing a pasted metavar.) - #139490 (Update some comment/docs related to "extern intrinsic" removal) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e5fefc3 + 42fdd7d commit f820b75

File tree

52 files changed

+1003
-184
lines changed

Some content is hidden

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

52 files changed

+1003
-184
lines changed

Diff for: Cargo.lock

+54-5
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,48 @@ version = "0.7.6"
186186
source = "registry+https://github.com/rust-lang/crates.io-index"
187187
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
188188

189+
[[package]]
190+
name = "askama"
191+
version = "0.13.0"
192+
source = "registry+https://github.com/rust-lang/crates.io-index"
193+
checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543"
194+
dependencies = [
195+
"askama_derive",
196+
"itoa",
197+
"percent-encoding",
198+
"serde",
199+
"serde_json",
200+
]
201+
202+
[[package]]
203+
name = "askama_derive"
204+
version = "0.13.0"
205+
source = "registry+https://github.com/rust-lang/crates.io-index"
206+
checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6"
207+
dependencies = [
208+
"askama_parser",
209+
"basic-toml",
210+
"memchr",
211+
"proc-macro2",
212+
"quote",
213+
"rustc-hash 2.1.1",
214+
"serde",
215+
"serde_derive",
216+
"syn 2.0.100",
217+
]
218+
219+
[[package]]
220+
name = "askama_parser"
221+
version = "0.13.0"
222+
source = "registry+https://github.com/rust-lang/crates.io-index"
223+
checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
224+
dependencies = [
225+
"memchr",
226+
"serde",
227+
"serde_derive",
228+
"winnow 0.7.4",
229+
]
230+
189231
[[package]]
190232
name = "autocfg"
191233
version = "1.4.0"
@@ -1345,8 +1387,8 @@ name = "generate-copyright"
13451387
version = "0.1.0"
13461388
dependencies = [
13471389
"anyhow",
1390+
"askama",
13481391
"cargo_metadata 0.18.1",
1349-
"rinja",
13501392
"serde",
13511393
"serde_json",
13521394
"thiserror 1.0.69",
@@ -3069,9 +3111,7 @@ version = "0.3.5"
30693111
source = "registry+https://github.com/rust-lang/crates.io-index"
30703112
checksum = "3dc4940d00595430b3d7d5a01f6222b5e5b51395d1120bdb28d854bb8abb17a5"
30713113
dependencies = [
3072-
"humansize",
30733114
"itoa",
3074-
"percent-encoding",
30753115
"rinja_derive",
30763116
]
30773117

@@ -4628,6 +4668,7 @@ name = "rustdoc"
46284668
version = "0.0.0"
46294669
dependencies = [
46304670
"arrayvec",
4671+
"askama",
46314672
"base64",
46324673
"expect-test",
46334674
"indexmap",
@@ -4636,7 +4677,6 @@ dependencies = [
46364677
"pulldown-cmark 0.9.6",
46374678
"pulldown-cmark-escape",
46384679
"regex",
4639-
"rinja",
46404680
"rustdoc-json-types",
46414681
"serde",
46424682
"serde_json",
@@ -5426,7 +5466,7 @@ dependencies = [
54265466
"serde",
54275467
"serde_spanned",
54285468
"toml_datetime",
5429-
"winnow",
5469+
"winnow 0.5.40",
54305470
]
54315471

54325472
[[package]]
@@ -6437,6 +6477,15 @@ dependencies = [
64376477
"memchr",
64386478
]
64396479

6480+
[[package]]
6481+
name = "winnow"
6482+
version = "0.7.4"
6483+
source = "registry+https://github.com/rust-lang/crates.io-index"
6484+
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
6485+
dependencies = [
6486+
"memchr",
6487+
]
6488+
64406489
[[package]]
64416490
name = "winsplit"
64426491
version = "0.1.0"

Diff for: bootstrap.example.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# - A new option
2929
# - A change in the default values
3030
#
31-
# If the change-id does not match the version currently in use, x.py will
31+
# If the change-id does not match the version currently in use, x.py will
3232
# display the changes made to the bootstrap.
3333
# To suppress these warnings, you can set change-id = "ignore".
3434
#change-id = <latest change id in src/bootstrap/src/utils/change_tracker.rs>
@@ -442,6 +442,9 @@
442442
# What custom diff tool to use for displaying compiletest tests.
443443
#compiletest-diff-tool = <none>
444444

445+
# Whether to use the precompiled stage0 libtest with compiletest.
446+
#compiletest-use-stage0-libtest = true
447+
445448
# Indicates whether ccache is used when building certain artifacts (e.g. LLVM).
446449
# Set to `true` to use the first `ccache` in PATH, or set an absolute path to use
447450
# a specific version.

Diff for: compiler/rustc_codegen_ssa/src/mir/operand.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::mir::{self, ConstValue};
99
use rustc_middle::ty::Ty;
1010
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1111
use rustc_middle::{bug, span_bug};
12+
use rustc_session::config::OptLevel;
1213
use tracing::{debug, instrument};
1314

1415
use super::place::{PlaceRef, PlaceValue};
@@ -496,6 +497,18 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
496497
_ => (tag_imm, bx.cx().immediate_backend_type(tag_op.layout)),
497498
};
498499

500+
// Layout ensures that we only get here for cases where the discriminant
501+
// value and the variant index match, since that's all `Niche` can encode.
502+
// But for emphasis and debugging, let's double-check one anyway.
503+
debug_assert_eq!(
504+
self.layout
505+
.ty
506+
.discriminant_for_variant(bx.tcx(), untagged_variant)
507+
.unwrap()
508+
.val,
509+
u128::from(untagged_variant.as_u32()),
510+
);
511+
499512
let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32();
500513

501514
// We have a subrange `niche_start..=niche_end` inside `range`.
@@ -537,6 +550,21 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
537550
relative_discr,
538551
bx.cx().const_uint(tag_llty, relative_max as u64),
539552
);
553+
554+
// Thanks to parameter attributes and load metadata, LLVM already knows
555+
// the general valid range of the tag. It's possible, though, for there
556+
// to be an impossible value *in the middle*, which those ranges don't
557+
// communicate, so it's worth an `assume` to let the optimizer know.
558+
if niche_variants.contains(&untagged_variant)
559+
&& bx.cx().sess().opts.optimize != OptLevel::No
560+
{
561+
let impossible =
562+
u64::from(untagged_variant.as_u32() - niche_variants.start().as_u32());
563+
let impossible = bx.cx().const_uint(tag_llty, impossible);
564+
let ne = bx.icmp(IntPredicate::IntNE, relative_discr, impossible);
565+
bx.assume(ne);
566+
}
567+
540568
(is_niche, cast_tag, niche_variants.start().as_u32() as u128)
541569
};
542570

@@ -553,7 +581,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
553581
);
554582

555583
// In principle we could insert assumes on the possible range of `discr`, but
556-
// currently in LLVM this seems to be a pessimization.
584+
// currently in LLVM this isn't worth it because the original `tag` will
585+
// have either a `range` parameter attribute or `!range` metadata,
586+
// or come from a `transmute` that already `assume`d it.
557587

558588
discr
559589
}

Diff for: compiler/rustc_hir_analysis/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ hir_analysis_self_in_impl_self =
486486
`Self` is not valid in the self type of an impl block
487487
.note = replace `Self` with a different type
488488
489+
hir_analysis_self_in_type_alias = `Self` is not allowed in type aliases
490+
.label = `Self` is only available in impls, traits, and concrete type definitions
491+
489492
hir_analysis_self_ty_not_captured = `impl Trait` must mention the `Self` type of the trait in `use<...>`
490493
.label = `Self` type parameter is implicitly captured by this `impl Trait`
491494
.note = currently, all type parameters are required to be mentioned in the precise captures list

Diff for: compiler/rustc_hir_analysis/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1707,3 +1707,11 @@ pub(crate) enum SupertraitItemShadowee {
17071707
traits: DiagSymbolList,
17081708
},
17091709
}
1710+
1711+
#[derive(Diagnostic)]
1712+
#[diag(hir_analysis_self_in_type_alias, code = E0411)]
1713+
pub(crate) struct SelfInTypeAlias {
1714+
#[primary_span]
1715+
#[label]
1716+
pub span: Span,
1717+
}

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use smallvec::{SmallVec, smallvec};
1616
use tracing::{debug, instrument};
1717

1818
use super::HirTyLowerer;
19+
use crate::errors::SelfInTypeAlias;
1920
use crate::hir_ty_lowering::{
2021
GenericArgCountMismatch, GenericArgCountResult, PredicateFilter, RegionInferReason,
2122
};
@@ -125,6 +126,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
125126
// ```
126127
let mut projection_bounds = FxIndexMap::default();
127128
for (proj, proj_span) in elaborated_projection_bounds {
129+
let proj = proj.map_bound(|mut b| {
130+
if let Some(term_ty) = &b.term.as_type() {
131+
let references_self = term_ty.walk().any(|arg| arg == dummy_self.into());
132+
if references_self {
133+
// With trait alias and type alias combined, type resolver
134+
// may not be able to catch all illegal `Self` usages (issue 139082)
135+
let guar = tcx.dcx().emit_err(SelfInTypeAlias { span });
136+
b.term = replace_dummy_self_with_error(tcx, b.term, guar);
137+
}
138+
}
139+
b
140+
});
141+
128142
let key = (
129143
proj.skip_binder().projection_term.def_id,
130144
tcx.anonymize_bound_vars(

Diff for: compiler/rustc_hir_analysis/src/hir_wf_check.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_infer::infer::TyCtxtInferExt;
44
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
55
use rustc_middle::bug;
66
use rustc_middle::query::Providers;
7-
use rustc_middle::ty::{self, TyCtxt, TypingMode, fold_regions};
7+
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, TypingMode, fold_regions};
88
use rustc_span::def_id::LocalDefId;
99
use rustc_trait_selection::traits::{self, ObligationCtxt};
1010
use tracing::debug;
@@ -77,6 +77,15 @@ fn diagnostic_hir_wf_check<'tcx>(
7777
let tcx_ty = fold_regions(self.tcx, tcx_ty, |r, _| {
7878
if r.is_bound() { self.tcx.lifetimes.re_erased } else { r }
7979
});
80+
81+
// We may be checking the WFness of a type in an opaque with a non-lifetime bound.
82+
// Perhaps we could rebind all the escaping bound vars, but they're coming from
83+
// arbitrary debruijn indices and aren't particularly important anyways, since they
84+
// are only coming from `feature(non_lifetime_binders)` anyways.
85+
if tcx_ty.has_escaping_bound_vars() {
86+
return;
87+
}
88+
8089
let cause = traits::ObligationCause::new(
8190
ty.span,
8291
self.def_id,

Diff for: compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub(super) fn infer_predicates(
2424

2525
// If new predicates were added then we need to re-calculate
2626
// all crates since there could be new implied predicates.
27-
loop {
28-
let mut predicates_added = false;
27+
for i in 0.. {
28+
let mut predicates_added = vec![];
2929

3030
// Visit all the crates and infer predicates
3131
for id in tcx.hir_free_items() {
@@ -83,14 +83,27 @@ pub(super) fn infer_predicates(
8383
.get(&item_did.to_def_id())
8484
.map_or(0, |p| p.as_ref().skip_binder().len());
8585
if item_required_predicates.len() > item_predicates_len {
86-
predicates_added = true;
86+
predicates_added.push(item_did);
8787
global_inferred_outlives
8888
.insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
8989
}
9090
}
9191

92-
if !predicates_added {
92+
if predicates_added.is_empty() {
93+
// We've reached a fixed point.
9394
break;
95+
} else if !tcx.recursion_limit().value_within_limit(i) {
96+
let msg = if let &[id] = &predicates_added[..] {
97+
format!("overflow computing implied lifetime bounds for `{}`", tcx.def_path_str(id),)
98+
} else {
99+
"overflow computing implied lifetime bounds".to_string()
100+
};
101+
tcx.dcx()
102+
.struct_span_fatal(
103+
predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
104+
msg,
105+
)
106+
.emit();
94107
}
95108
}
96109

Diff for: compiler/rustc_hir_typeck/src/expr.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2205,8 +2205,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22052205
let fields = listify(&missing_mandatory_fields, |f| format!("`{f}`")).unwrap();
22062206
self.dcx()
22072207
.struct_span_err(
2208-
span.shrink_to_hi(),
2209-
format!("missing mandatory field{s} {fields}"),
2208+
span.shrink_to_lo(),
2209+
format!("missing field{s} {fields} in initializer"),
2210+
)
2211+
.with_span_label(
2212+
span.shrink_to_lo(),
2213+
"fields that do not have a defaulted value must be provided explicitly",
22102214
)
22112215
.emit();
22122216
return;

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,16 @@ impl<'a> Parser<'a> {
782782
// Recovery is disabled when parsing macro arguments, so it must
783783
// also be disabled when reparsing pasted macro arguments,
784784
// otherwise we get inconsistent results (e.g. #137874).
785-
let res = self.with_recovery(Recovery::Forbidden, |this| {
786-
f(this).expect("failed to reparse {mv_kind:?}")
787-
});
785+
let res = self.with_recovery(Recovery::Forbidden, |this| f(this));
786+
787+
let res = match res {
788+
Ok(res) => res,
789+
Err(err) => {
790+
// This can occur in unusual error cases, e.g. #139445.
791+
err.delay_as_bug();
792+
return None;
793+
}
794+
};
788795

789796
if let token::CloseDelim(delim) = self.token.kind
790797
&& let Delimiter::Invisible(InvisibleOrigin::MetaVar(mv_kind)) = delim
@@ -793,7 +800,12 @@ impl<'a> Parser<'a> {
793800
self.bump();
794801
Some(res)
795802
} else {
796-
panic!("no close delim when reparsing {mv_kind:?}");
803+
// This can occur when invalid syntax is passed to a decl macro. E.g. see #139248,
804+
// where the reparse attempt of an invalid expr consumed the trailing invisible
805+
// delimiter.
806+
self.dcx()
807+
.span_delayed_bug(self.token.span, "no close delim with reparsing {mv_kind:?}");
808+
None
797809
}
798810
} else {
799811
None

0 commit comments

Comments
 (0)