Skip to content

Rollup of 10 pull requests #139525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fdefffe
compiler: report error when trait object type param reference self
xtexx Mar 30, 2025
6966416
Update to new rinja version (askama)
GuillaumeGomez Apr 3, 2025
f343b9d
Don't construct preds w escaping bound vars in diagnostic_hir_wf_check
compiler-errors Apr 4, 2025
86a7ee6
create new option `build.compiletest-use-stage0-libtest`
onur-ozkan Apr 4, 2025
17fad21
utilize `compiletest_use_stage0_libtest` option
onur-ozkan Apr 4, 2025
afe3834
add change-entry
onur-ozkan Apr 4, 2025
45afefa
Fix trait upcasting to dyn type with no principal when there are proj…
compiler-errors Apr 5, 2025
a6b7a26
Update rinja version in `generate-copyright`
GuillaumeGomez Apr 4, 2025
d37bd4d
Update proc-macro deps list
GuillaumeGomez Apr 3, 2025
1f06a6a
Tell LLVM about impossible niche tags
scottmcm Mar 29, 2025
51e67e2
LLVM18 compatibility fixes in the tests
scottmcm Mar 29, 2025
c830665
enable in-tree std on some runners
onur-ozkan Apr 5, 2025
cae28b5
implement `check` step for `compiletest` separately
onur-ozkan Apr 7, 2025
e1a69da
unstable-book/intrinsics: wordsmith MIR-lowering intrinsic docs
RalfJung Apr 7, 2025
a7400a8
update intrinsics/mod.rs comment about const intrinsics
RalfJung Apr 7, 2025
250b848
Make error message for missing fields with .. and without .. more con…
compiler-errors Mar 27, 2025
268c56e
Implement overflow for infinite implied lifetime bounds
compiler-errors Apr 7, 2025
502f7f9
Address PR feedback
scottmcm Apr 8, 2025
eb5d892
Allow for missing invisible close delim when reparsing an expression.
nnethercote Apr 3, 2025
e177921
Allow for reparsing failure when reparsing a pasted metavar.
nnethercote Apr 7, 2025
742b378
make hover_feature test less fragile
RalfJung Apr 8, 2025
2b1afcb
Rollup merge of #138676 - compiler-errors:overflow-implied-bounds, r=…
Zalathar Apr 8, 2025
6257825
Rollup merge of #139024 - compiler-errors:tweak-default-value-err, r=…
Zalathar Apr 8, 2025
7ffa56c
Rollup merge of #139098 - scottmcm:assert-impossible-tags, r=WaffleLa…
Zalathar Apr 8, 2025
5913c52
Rollup merge of #139124 - xtexx:gh-139082, r=compiler-errors
Zalathar Apr 8, 2025
dd682f7
Rollup merge of #139321 - GuillaumeGomez:update-rinja, r=notriddle,lo…
Zalathar Apr 8, 2025
133cec7
Rollup merge of #139346 - compiler-errors:non-lifetime-binder-diag-hi…
Zalathar Apr 8, 2025
ab80f57
Rollup merge of #139386 - onur-ozkan:configurable-compiletest-libtest…
Zalathar Apr 8, 2025
056756c
Rollup merge of #139421 - compiler-errors:upcast-no-principal-with-pr…
Zalathar Apr 8, 2025
24369ad
Rollup merge of #139464 - nnethercote:fix-139248-AND-fix-139445, r=pe…
Zalathar Apr 8, 2025
42fdd7d
Rollup merge of #139490 - RalfJung:unstable-intrinsics-docs, r=oli-obk
Zalathar Apr 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 54 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,48 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"

[[package]]
name = "askama"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543"
dependencies = [
"askama_derive",
"itoa",
"percent-encoding",
"serde",
"serde_json",
]

[[package]]
name = "askama_derive"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6"
dependencies = [
"askama_parser",
"basic-toml",
"memchr",
"proc-macro2",
"quote",
"rustc-hash 2.1.1",
"serde",
"serde_derive",
"syn 2.0.100",
]

[[package]]
name = "askama_parser"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
dependencies = [
"memchr",
"serde",
"serde_derive",
"winnow 0.7.4",
]

[[package]]
name = "autocfg"
version = "1.4.0"
Expand Down Expand Up @@ -1345,8 +1387,8 @@ name = "generate-copyright"
version = "0.1.0"
dependencies = [
"anyhow",
"askama",
"cargo_metadata 0.18.1",
"rinja",
"serde",
"serde_json",
"thiserror 1.0.69",
Expand Down Expand Up @@ -3069,9 +3111,7 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dc4940d00595430b3d7d5a01f6222b5e5b51395d1120bdb28d854bb8abb17a5"
dependencies = [
"humansize",
"itoa",
"percent-encoding",
"rinja_derive",
]

Expand Down Expand Up @@ -4628,6 +4668,7 @@ name = "rustdoc"
version = "0.0.0"
dependencies = [
"arrayvec",
"askama",
"base64",
"expect-test",
"indexmap",
Expand All @@ -4636,7 +4677,6 @@ dependencies = [
"pulldown-cmark 0.9.6",
"pulldown-cmark-escape",
"regex",
"rinja",
"rustdoc-json-types",
"serde",
"serde_json",
Expand Down Expand Up @@ -5426,7 +5466,7 @@ dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
"winnow 0.5.40",
]

[[package]]
Expand Down Expand Up @@ -6437,6 +6477,15 @@ dependencies = [
"memchr",
]

[[package]]
name = "winnow"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
dependencies = [
"memchr",
]

[[package]]
name = "winsplit"
version = "0.1.0"
Expand Down
5 changes: 4 additions & 1 deletion bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# - A new option
# - A change in the default values
#
# If the change-id does not match the version currently in use, x.py will
# If the change-id does not match the version currently in use, x.py will
# display the changes made to the bootstrap.
# To suppress these warnings, you can set change-id = "ignore".
#change-id = <latest change id in src/bootstrap/src/utils/change_tracker.rs>
Expand Down Expand Up @@ -442,6 +442,9 @@
# What custom diff tool to use for displaying compiletest tests.
#compiletest-diff-tool = <none>

# Whether to use the precompiled stage0 libtest with compiletest.
#compiletest-use-stage0-libtest = true

# Indicates whether ccache is used when building certain artifacts (e.g. LLVM).
# Set to `true` to use the first `ccache` in PATH, or set an absolute path to use
# a specific version.
Expand Down
32 changes: 31 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_middle::mir::{self, ConstValue};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::{bug, span_bug};
use rustc_session::config::OptLevel;
use tracing::{debug, instrument};

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

// Layout ensures that we only get here for cases where the discriminant
// value and the variant index match, since that's all `Niche` can encode.
// But for emphasis and debugging, let's double-check one anyway.
debug_assert_eq!(
self.layout
.ty
.discriminant_for_variant(bx.tcx(), untagged_variant)
.unwrap()
.val,
u128::from(untagged_variant.as_u32()),
);

let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32();

// We have a subrange `niche_start..=niche_end` inside `range`.
Expand Down Expand Up @@ -537,6 +550,21 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
relative_discr,
bx.cx().const_uint(tag_llty, relative_max as u64),
);

// Thanks to parameter attributes and load metadata, LLVM already knows
// the general valid range of the tag. It's possible, though, for there
// to be an impossible value *in the middle*, which those ranges don't
// communicate, so it's worth an `assume` to let the optimizer know.
if niche_variants.contains(&untagged_variant)
&& bx.cx().sess().opts.optimize != OptLevel::No
{
let impossible =
u64::from(untagged_variant.as_u32() - niche_variants.start().as_u32());
let impossible = bx.cx().const_uint(tag_llty, impossible);
let ne = bx.icmp(IntPredicate::IntNE, relative_discr, impossible);
bx.assume(ne);
}

(is_niche, cast_tag, niche_variants.start().as_u32() as u128)
};

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

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

discr
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ hir_analysis_self_in_impl_self =
`Self` is not valid in the self type of an impl block
.note = replace `Self` with a different type

hir_analysis_self_in_type_alias = `Self` is not allowed in type aliases
.label = `Self` is only available in impls, traits, and concrete type definitions

hir_analysis_self_ty_not_captured = `impl Trait` must mention the `Self` type of the trait in `use<...>`
.label = `Self` type parameter is implicitly captured by this `impl Trait`
.note = currently, all type parameters are required to be mentioned in the precise captures list
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,3 +1707,11 @@ pub(crate) enum SupertraitItemShadowee {
traits: DiagSymbolList,
},
}

#[derive(Diagnostic)]
#[diag(hir_analysis_self_in_type_alias, code = E0411)]
pub(crate) struct SelfInTypeAlias {
#[primary_span]
#[label]
pub span: Span,
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use smallvec::{SmallVec, smallvec};
use tracing::{debug, instrument};

use super::HirTyLowerer;
use crate::errors::SelfInTypeAlias;
use crate::hir_ty_lowering::{
GenericArgCountMismatch, GenericArgCountResult, PredicateFilter, RegionInferReason,
};
Expand Down Expand Up @@ -125,6 +126,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// ```
let mut projection_bounds = FxIndexMap::default();
for (proj, proj_span) in elaborated_projection_bounds {
let proj = proj.map_bound(|mut b| {
if let Some(term_ty) = &b.term.as_type() {
let references_self = term_ty.walk().any(|arg| arg == dummy_self.into());
if references_self {
// With trait alias and type alias combined, type resolver
// may not be able to catch all illegal `Self` usages (issue 139082)
let guar = tcx.dcx().emit_err(SelfInTypeAlias { span });
b.term = replace_dummy_self_with_error(tcx, b.term, guar);
}
}
b
});

let key = (
proj.skip_binder().projection_term.def_id,
tcx.anonymize_bound_vars(
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::{ObligationCause, WellFormedLoc};
use rustc_middle::bug;
use rustc_middle::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypingMode, fold_regions};
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, TypingMode, fold_regions};
use rustc_span::def_id::LocalDefId;
use rustc_trait_selection::traits::{self, ObligationCtxt};
use tracing::debug;
Expand Down Expand Up @@ -77,6 +77,15 @@ fn diagnostic_hir_wf_check<'tcx>(
let tcx_ty = fold_regions(self.tcx, tcx_ty, |r, _| {
if r.is_bound() { self.tcx.lifetimes.re_erased } else { r }
});

// We may be checking the WFness of a type in an opaque with a non-lifetime bound.
// Perhaps we could rebind all the escaping bound vars, but they're coming from
// arbitrary debruijn indices and aren't particularly important anyways, since they
// are only coming from `feature(non_lifetime_binders)` anyways.
if tcx_ty.has_escaping_bound_vars() {
return;
}

let cause = traits::ObligationCause::new(
ty.span,
self.def_id,
Expand Down
21 changes: 17 additions & 4 deletions compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub(super) fn infer_predicates(

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

// Visit all the crates and infer predicates
for id in tcx.hir_free_items() {
Expand Down Expand Up @@ -83,14 +83,27 @@ pub(super) fn infer_predicates(
.get(&item_did.to_def_id())
.map_or(0, |p| p.as_ref().skip_binder().len());
if item_required_predicates.len() > item_predicates_len {
predicates_added = true;
predicates_added.push(item_did);
global_inferred_outlives
.insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates));
}
}

if !predicates_added {
if predicates_added.is_empty() {
// We've reached a fixed point.
break;
} else if !tcx.recursion_limit().value_within_limit(i) {
let msg = if let &[id] = &predicates_added[..] {
format!("overflow computing implied lifetime bounds for `{}`", tcx.def_path_str(id),)
} else {
"overflow computing implied lifetime bounds".to_string()
};
tcx.dcx()
.struct_span_fatal(
predicates_added.iter().map(|id| tcx.def_span(*id)).collect::<Vec<_>>(),
msg,
)
.emit();
}
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2205,8 +2205,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let fields = listify(&missing_mandatory_fields, |f| format!("`{f}`")).unwrap();
self.dcx()
.struct_span_err(
span.shrink_to_hi(),
format!("missing mandatory field{s} {fields}"),
span.shrink_to_lo(),
format!("missing field{s} {fields} in initializer"),
)
.with_span_label(
span.shrink_to_lo(),
"fields that do not have a defaulted value must be provided explicitly",
)
.emit();
return;
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,16 @@ impl<'a> Parser<'a> {
// Recovery is disabled when parsing macro arguments, so it must
// also be disabled when reparsing pasted macro arguments,
// otherwise we get inconsistent results (e.g. #137874).
let res = self.with_recovery(Recovery::Forbidden, |this| {
f(this).expect("failed to reparse {mv_kind:?}")
});
let res = self.with_recovery(Recovery::Forbidden, |this| f(this));

let res = match res {
Ok(res) => res,
Err(err) => {
// This can occur in unusual error cases, e.g. #139445.
err.delay_as_bug();
return None;
}
};

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