Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
d119977
Diagnose inactive code in macros
ChayimFriedman2 May 6, 2026
be18690
Allow disabling the inactive-code diagnostic in code
ChayimFriedman2 May 6, 2026
468c78a
std::random: use little-endian for reproducibility
hanna-kruppe Jun 4, 2026
6dfb135
Respect `references.exclude[Tests/Imports]` in references lens
ChayimFriedman2 Jun 28, 2026
41954a2
internal: Port `ExprScopes` over to visitor fully
Veykril Jul 19, 2026
388818c
internal: Make stdout/stderr explicit in JsonLinesParser
Wilfred Jun 22, 2026
047fb62
restrict visibility of mapping methods
bit-aloo Jul 24, 2026
95048dc
remove clone_for_updates entirely,
bit-aloo Jul 24, 2026
df6ded5
remove clone_for_update from AstNode
bit-aloo Jul 24, 2026
507ea9e
make syntax editor void of any mutable API
bit-aloo Jul 24, 2026
01c1b9a
update mapping for element and remove for node
bit-aloo Jul 24, 2026
70c3ea6
update edits with new annotation semantics
bit-aloo Jul 24, 2026
6877440
Refactor edit_algo around immutable syntax tree with better semantics
bit-aloo Jul 24, 2026
e818be7
Merge pull request #22660 from ChayimFriedman2/exclude-refs-lens
ShoyuVanilla Jul 27, 2026
29f0e76
Merge pull request #22306 from ChayimFriedman2/inactive-code
ShoyuVanilla Jul 27, 2026
49d4204
fix: resolve path on all namespaces and return resolution based on vi…
ChayimFriedman2 May 17, 2026
9fb185d
Suggest mutable method when iterating over binding
estebank Jul 27, 2026
31086e2
fix: Only parse stdout in discover protocol
Wilfred Jun 22, 2026
2108f92
Merge pull request #22903 from Wilfred/stderr_discovery
ShoyuVanilla Jul 27, 2026
a1e1cb1
Merge pull request #22743 from dfireBird/fix-nameref-classify
ChayimFriedman2 Jul 27, 2026
de3c5b6
internal: Spelling and grammar fixes
Wilfred Jul 27, 2026
9c13c1f
fix: don't pick a discriminant type larger than typeck's
shulaoda Jul 27, 2026
edccf1e
Merge pull request #22931 from Wilfred/grammar_futzing
lnicola Jul 27, 2026
1da028b
fix: use char counts in progress bar
AayushMainali-Github Jul 27, 2026
f19f3ee
Merge pull request #22909 from AayushMainali-Github/fix/22844-unicode…
ChayimFriedman2 Jul 27, 2026
5c28d00
Merge pull request #22932 from shulaoda/07-27-fix_don_t_pick_a_discri…
ChayimFriedman2 Jul 27, 2026
e86cdb5
fix: don't panic on a qualified path whose trait is not a trait
shulaoda Jul 28, 2026
7d13615
Merge pull request #22930 from shulaoda/07-27-fix_don_t_panic_on_a_qu…
ChayimFriedman2 Jul 28, 2026
e42a814
fix: Failed to lookup MACRO_CALL@... in this Semantics due to include!
Wilfred Jul 22, 2026
48e3675
Merge pull request #22933 from Wilfred/fix/inline-macro-included-file
Veykril Jul 28, 2026
db60d94
internal: update next-solver to 0.166
ada4a Jul 28, 2026
2a82c4b
fix(vfs): use component-based path prefix matching for virtual paths
cuishuang Jul 28, 2026
209fb20
Merge pull request #22939 from ada4a/push-kmnplvwwunpy
ChayimFriedman2 Jul 28, 2026
6f943df
Merge pull request #22940 from cuishuang/master
ChayimFriedman2 Jul 28, 2026
0248a75
Reformat snippet docs so that they appear in the book
ian-h-chamberlain Jul 28, 2026
c919046
Merge pull request #22942 from ian-h-chamberlain/fix/snippet-document…
ChayimFriedman2 Jul 28, 2026
02f2944
Mark auto traits as coinductive
ChayimFriedman2 Jul 28, 2026
13901c0
Store liberated closure sigs in InferenceResult
ChayimFriedman2 Jul 29, 2026
6146254
Merge pull request #22943 from ChayimFriedman2/coinductive-auto
Veykril Jul 29, 2026
0cae0a1
Merge pull request #22945 from ChayimFriedman2/liberated-sigs
Veykril Jul 29, 2026
a6a9f65
Report a config error for postfix snippets with item scope
Joshuaisikah Jul 29, 2026
8cba7c7
Merge pull request #22937 from Joshuaisikah/warn-postfix-snippet-item…
ChayimFriedman2 Jul 29, 2026
c5ccd5b
hir-ty, ide-diagnostics: use E0057 vs E0061 for arg-count mismatch
kivancgnlp Jul 29, 2026
d1bfa49
Implement `slice_get_unchecked` mir shim
Veykril Jul 29, 2026
945c8fa
Recursively patch addresses of slices
Veykril Jul 29, 2026
0c06249
Merge pull request #22947 from kivancgnlp/fn-trait-arg-count
ChayimFriedman2 Jul 29, 2026
7fab15a
fix: avoid escaping bound vars in closure MIR parameter types
edragain2nd Jul 28, 2026
1a74a27
Merge pull request #22938 from edragain2nd/fix/hrtb_closure
ChayimFriedman2 Jul 29, 2026
56a1c0d
Double stack size for threads to 16MiB
ChayimFriedman2 Jul 29, 2026
97c95c6
fix: no hint with similar name raw-ident arg
A4-Tacks Jul 29, 2026
b562f1d
Merge pull request #22957 from A4-Tacks/raw-arg-hints
ChayimFriedman2 Jul 29, 2026
883659d
Revert "Remove lockfile-path support for Cargo versions below 1.94.0"
nilehmann Jul 29, 2026
743519a
Merge pull request #22958 from nilehmann/push-xszpmkosrpqw
ChayimFriedman2 Jul 30, 2026
c828771
Support `CovariantUnsafeCell`
ChayimFriedman2 Jul 30, 2026
129d0df
Merge pull request #22959 from ChayimFriedman2/covariant-unsafe-cell
ChayimFriedman2 Jul 30, 2026
def6823
Add comment on replacements_are_disjoint method and better upmap syntax
bit-aloo Jul 30, 2026
5815534
Merge pull request #22808 from bit-aloo/2026-07-15-remove-mutable-row…
ChayimFriedman2 Jul 30, 2026
1d5bcea
Avoid having a separate query for defined opaques
ChayimFriedman2 Jul 30, 2026
735a39d
Do not alloc anon consts for bare paths in blocks
ChayimFriedman2 Jul 30, 2026
13b4a5e
Use format! instead of string
tyler-breisacher-zipline Jul 31, 2026
378751b
Merge pull request #22967 from tyler-breisacher-zipline/format
ChayimFriedman2 Jul 31, 2026
036c57f
Remove add_tabstop_after_token from source change
bit-aloo Jul 31, 2026
5030272
Remove add_tabstop_before_token and adapt generate_derive assist
bit-aloo Jul 31, 2026
e761d02
Remove add_tabstop_before_token fomr source_change
bit-aloo Jul 31, 2026
06917be
Remove add_placeholder_snippet fomr source_change
bit-aloo Jul 31, 2026
5a6c923
Remove add_tabstop_before from source_change
bit-aloo Jul 31, 2026
f5601fa
Remove add_snippet from source change
bit-aloo Jul 31, 2026
72a9c71
removed PlaceSnippet and its unused SnippetBuilder
bit-aloo Jul 31, 2026
d19e404
Removed unused From<IntMap<FileId, TextEdit>>, and the extend variant.
bit-aloo Jul 31, 2026
0e85865
Merge pull request #22969 from bit-aloo/2026-07-31-simplify-source-ch…
ChayimFriedman2 Jul 31, 2026
1f5c92a
fix: Fix glob imports overriding later specific imports
kristoff3r Jul 22, 2026
174cb70
Merge pull request #22886 from kristoff3r/glob-type-mismatch
ShoyuVanilla Jul 31, 2026
2945d4d
fix: show qualified paths when type names collide in E0308
rit3sh-x Jul 30, 2026
fb3920f
Merge pull request #22964 from rit3sh-x/fix/22331-qualified-paths-on-…
ChayimFriedman2 Jul 31, 2026
f37e635
Merge pull request #22965 from ChayimFriedman2/bare-path-const
Veykril Jul 31, 2026
a2930f8
Merge pull request #22966 from ChayimFriedman2/no-relowering-opaques
Veykril Jul 31, 2026
f55e9c1
Merge pull request #22956 from ChayimFriedman2/big-stack
ChayimFriedman2 Jul 31, 2026
ed4e817
Merge pull request #22948 from Veykril/lukaswirth/push-ppkyzvvwuppt
Veykril Aug 1, 2026
e7a327f
Merge pull request #22864 from Veykril/lukaswirth/push-kswvmlyvmvsv
Veykril Aug 1, 2026
6b5fd96
fix: don't panic on a self-referential `impl Trait` function
shulaoda Aug 1, 2026
b33c51e
fix: recognize format arguments after a backslash in raw strings
shulaoda Aug 1, 2026
f4a95b6
Merge pull request #22992 from shulaoda/08-02-fix_don_t_panic_on_a_se…
ChayimFriedman2 Aug 1, 2026
c973eb0
fix: detect the rust-analyzer component in a multi-line components array
Musteab Aug 1, 2026
01db4e1
Do not store references in `ExprScope`'s visitor
ChayimFriedman2 Aug 2, 2026
fb409cb
Merge pull request #22993 from shulaoda/08-02-fix_recognize_format_ar…
ChayimFriedman2 Aug 2, 2026
889a940
Bump rowan to 0.17.0
bit-aloo Jul 31, 2026
9c3358a
Adapt to borrowed Rowan green nodes
bit-aloo Jul 31, 2026
f12a136
Remove the obsolete TokenText wrapper
bit-aloo Jul 31, 2026
29133df
Fix tokenText removal fallout
bit-aloo Aug 2, 2026
fa05017
Remove absolute versioning in rowan import
bit-aloo Aug 2, 2026
fc8cdcf
Merge pull request #22998 from bit-aloo/2026-08-02-bump-rowan-0.17
ChayimFriedman2 Aug 2, 2026
b1ea7ce
Capture the components array and check it for rust-analyzer
Musteab Aug 2, 2026
21038a8
Merge pull request #22996 from Musteab/fix-multiline-components-detec…
ChayimFriedman2 Aug 2, 2026
9cebc26
fix: add reference for same name param coerce matches
A4-Tacks Aug 2, 2026
08e0d56
Use as_reference() api
A4-Tacks Aug 2, 2026
95f1a80
fix: parse postfix range inside closure in access
A4-Tacks Aug 2, 2026
95b4e46
minor: variant eval error use source instead of node debug
A4-Tacks Aug 2, 2026
dc281b4
Correctly handle unlinked module edge cases
George-Ogden Aug 1, 2026
bb376fa
Merge pull request #22977 from George-Ogden/linked-module-names
A4-Tacks Aug 2, 2026
ed3a7e7
Merge pull request #23005 from A4-Tacks/variant-eval-err-src
Veykril Aug 2, 2026
abea8c8
Merge pull request #22997 from ChayimFriedman2/expr-scope-visitor
Veykril Aug 2, 2026
9395b57
Merge pull request #23004 from A4-Tacks/postfix-range-no-rhs-parse
ChayimFriedman2 Aug 2, 2026
c1dcbfc
Move instantiate_with_errors from local_ty into param
A4-Tacks Aug 2, 2026
382d5d4
Merge pull request #23003 from A4-Tacks/coerce-func-param-comp
ChayimFriedman2 Aug 2, 2026
81b7445
Replace some older path-handling tests with snapshot tests
Zalathar Jul 31, 2026
122881b
Snapshot test for `./x test rustdoc --skip=rustdoc`
Zalathar Aug 3, 2026
d4e34c9
Do not take `doc(cfg())` into account when filtering doctests
GuillaumeGomez Jul 9, 2026
7bb6021
Add regression test for `doc(cfg())` doctest (non-)filtering
GuillaumeGomez Jul 9, 2026
bfc0d0d
Ignore std doctests if not run on the right OS
GuillaumeGomez Jul 9, 2026
20cf32e
Fix new windows doc code example
GuillaumeGomez Aug 3, 2026
6c07a43
Don't produce mutated/filtered PathSets during command-line matching
Zalathar Jul 31, 2026
5aff738
Derive the allocator used by tools from rustc's allocator
Zoxc Jul 30, 2026
25f20f5
Add a regression test for casting a `fn` item with an illegal `self` …
jakubadamw Aug 2, 2026
cfafd15
Add a regression test for a trait alias mentioning `Self` in a trait …
jakubadamw Aug 2, 2026
17446a6
Add a regression test for the layout of an unsafe binder over an opaq…
jakubadamw Aug 2, 2026
6f4fdb0
Add a regression test for transmuting a `usize` to a `rust-call` fn p…
jakubadamw Aug 2, 2026
a0efa72
Add a regression test for MIR validation of a nested type-alias `impl…
jakubadamw Aug 2, 2026
6250519
Restore a crash test for a higher-ranked generic associated type
jakubadamw Aug 2, 2026
28b62fa
Add a regression test for a malformed `impl Trait` in an associated t…
jakubadamw Aug 2, 2026
3d3bf13
perf: single-pass for lower/upper case conversion
fereidani Aug 4, 2026
2cba42a
remove unused source file
adwinwhite Aug 4, 2026
c316115
normalize in relations, not generalize, when relating infer with alias
khyperia Aug 4, 2026
3dc2ef8
normalize the field ty in relate_type_and_user_type
khyperia Aug 4, 2026
c7fc5f2
Add reflection method for field names
oli-obk Jul 16, 2026
20d5e78
Add reflection method for field offsets
oli-obk Jul 16, 2026
538f556
Add reflection method for fetching non-exhaustiveness
oli-obk Jul 21, 2026
9381472
Generalize some arguments to allow more kinds of input
oli-obk Jul 22, 2026
cecd4a4
Add reflection method for getting a type's generic args
oli-obk Jul 22, 2026
691f045
Add missing `cfg_attr` on doc tests in stdlib `os` module
GuillaumeGomez Aug 3, 2026
08a1b42
implement -Zllvm-target-feature
RalfJung Aug 3, 2026
c82207c
improve error message on missing target feature prefix
RalfJung Aug 3, 2026
66175a7
clarify non-determinism docs for algebraic operations
RalfJung Aug 4, 2026
fec6eeb
Reduce number of miri tests executed on PR CI
Kobzol Aug 4, 2026
50a2894
Rollup merge of #160426 - lnicola:sync-from-ra, r=lnicola
JonathanBrouwer Aug 4, 2026
f445f74
Rollup merge of #160372 - Zoxc:alloc-bin, r=Kobzol
JonathanBrouwer Aug 4, 2026
3b74268
Rollup merge of #159727 - oli-obk:reflection_stuff, r=JohnTitor
JonathanBrouwer Aug 4, 2026
ca41fa9
Rollup merge of #160443 - khyperia:move-normalize-to-relations, r=lcnr
JonathanBrouwer Aug 4, 2026
75fad49
Rollup merge of #160457 - RalfJung:llvm-target-feature, r=folkertdev
JonathanBrouwer Aug 4, 2026
c38ed9f
Rollup merge of #160480 - fereidani:to_ascii_upperlowercase, r=joshtr…
JonathanBrouwer Aug 4, 2026
cef136f
Rollup merge of #160502 - Kobzol:miri-pr-ci, r=RalfJung
JonathanBrouwer Aug 4, 2026
29e978c
Rollup merge of #157430 - hanna-kruppe:random-endian, r=joshtriplett
JonathanBrouwer Aug 4, 2026
f35a2a8
Rollup merge of #159014 - GuillaumeGomez:doc-cfg-filter-doctest, r=Urgau
JonathanBrouwer Aug 4, 2026
7ef4a28
Rollup merge of #160001 - estebank:issue-49839, r=adwinwhite
JonathanBrouwer Aug 4, 2026
a03719f
Rollup merge of #160407 - jakubadamw:e-needs-test, r=nnethercote
JonathanBrouwer Aug 4, 2026
c89ca9d
Rollup merge of #160430 - Zalathar:filtration, r=jieyouxu
JonathanBrouwer Aug 4, 2026
3ead4ec
Rollup merge of #160486 - adwinwhite:remove-old-visitor, r=lqd
JonathanBrouwer Aug 4, 2026
c121f54
Rollup merge of #160496 - RalfJung:algebraic-nondet, r=Darksonn
JonathanBrouwer Aug 4, 2026
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
2 changes: 1 addition & 1 deletion compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ features = ['override_allocator_on_supported_platforms']
[features]
# tidy-alphabetical-start
check_only = ['rustc_driver_impl/check_only']
jemalloc = ['dep:tikv-jemalloc-sys']
jemalloc = ['dep:tikv-jemalloc-sys', 'rustc_driver_impl/jemalloc']
llvm = ['rustc_driver_impl/llvm']
llvm_offload = ['rustc_driver_impl/llvm_offload']
max_level_info = ['rustc_driver_impl/max_level_info']
Expand Down
17 changes: 6 additions & 11 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ use std::process::ExitCode;

// A note about jemalloc: rustc uses jemalloc when built for CI and
// distribution. The obvious way to do this is with the `#[global_allocator]`
// mechanism. However, for complicated reasons (see
// https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001 for some
// details) that mechanism doesn't work here. Also, we'd like to use a
// consistent allocator across the rustc <-> llvm boundary, and
// `#[global_allocator]` wouldn't provide that.
// mechanism. However, that would not affect LLVM's C / C++ allocations and we also want
// to use a single allocator in the process to reduce memory usage.
//
// Instead, we use a lower-level mechanism, namely the
// `"override_allocator_on_supported_platforms"` Cargo feature of jemalloc-sys.
Expand All @@ -20,15 +17,14 @@ use std::process::ExitCode;
// of `malloc`, `free`, etc.. This means that Rust's `System` allocator, which
// calls `libc::malloc()` et al., is actually calling into jemalloc.
//
// This override happens for the entire process, ensuring that there's no mixup
// of C allocators across dylibs / binaries, notably the rustc <-> llvm boundary.
//
// A consequence of not using `GlobalAlloc` (and the `tikv-jemallocator` crate
// provides an impl of that trait, which is called `Jemalloc`) is that we
// cannot use the sized deallocation APIs (`sdallocx`) that jemalloc provides.
// It's unclear how much performance is lost because of this.
//
// NOTE: Even though Cargo passes `--extern` with `tikv_jemalloc_sys`, we still need to `use` the
// crate for the compiler to see the `#[used]`, see https://github.com/rust-lang/rust/issues/64402.
// This is similarly required if we used a crate with `#[global_allocator]`.
//
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
// https://github.com/rust-lang/rustc-perf/blob/master/collector/README.md#profiling
Expand All @@ -37,8 +33,7 @@ use std::process::ExitCode;
// to compare their performance, see
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
// for an example of how to do so.
#[cfg(feature = "jemalloc")]
use tikv_jemalloc_sys as _;
rustc_driver::override_c_allocator_in_binary!();

fn main() -> ExitCode {
rustc_driver::main()
Expand Down
114 changes: 64 additions & 50 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,62 +1086,76 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
}
}
}
if let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id())
&& let Block(block, _) = body.value.kind
let Some(body) = tcx.hir_maybe_body_owned_by(self.mir_def_id()) else { return };
let Block(block, _) = body.value.kind else { return };
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
// expression with that span in order to identify potential fixes when encountering a
// read-only iterator that should be mutable.
let mut expr = if let ControlFlow::Break(expr) = (Finder { span }).visit_block(block)
&& let Call(_, [expr]) = expr.kind
{
// `span` corresponds to the expression being iterated, find the `for`-loop desugared
// expression with that span in order to identify potential fixes when encountering a
// read-only iterator that should be mutable.
if let ControlFlow::Break(expr) = (Finder { span }).visit_block(block)
&& let Call(_, [expr]) = expr.kind
{
match expr.kind {
MethodCall(path_segment, _, _, span) => {
// We have `for _ in iter.read_only_iter()`, try to
// suggest `for _ in iter.mutable_iter()` instead.
let opt_suggestions = tcx
.typeck(path_segment.hir_id.owner.def_id)
.type_dependent_def_id(expr.hir_id)
.and_then(|def_id| tcx.impl_of_assoc(def_id))
.map(|def_id| tcx.associated_items(def_id))
.map(|assoc_items| {
assoc_items
.in_definition_order()
.map(|assoc_item_def| assoc_item_def.ident(tcx))
.filter(|&ident| {
let original_method_ident = path_segment.ident;
original_method_ident != ident
&& ident.as_str().starts_with(
&original_method_ident.name.to_string(),
)
})
.map(|ident| format!("{ident}()"))
.peekable()
});
expr
} else {
return;
};
loop {
match expr.kind {
MethodCall(path_segment, _, _, span) => {
// We have `for _ in iter.read_only_iter()`, try to
// suggest `for _ in iter.mutable_iter()` instead.
let opt_suggestions = tcx
.typeck(path_segment.hir_id.owner.def_id)
.type_dependent_def_id(expr.hir_id)
.and_then(|def_id| tcx.impl_of_assoc(def_id))
.map(|def_id| tcx.associated_items(def_id))
.map(|assoc_items| {
assoc_items
.in_definition_order()
.map(|assoc_item_def| assoc_item_def.ident(tcx))
.filter(|&ident| {
let original_method_ident = path_segment.ident;
original_method_ident != ident
&& ident
.as_str()
.starts_with(&original_method_ident.name.to_string())
})
.map(|ident| format!("{ident}()"))
.peekable()
});

if let Some(mut suggestions) = opt_suggestions
&& suggestions.peek().is_some()
{
err.span_suggestions(
span,
"use mutable method",
suggestions,
Applicability::MaybeIncorrect,
);
}
}
AddrOf(BorrowKind::Ref, Mutability::Not, expr) => {
// We have `for _ in &i`, suggest `for _ in &mut i`.
err.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"use a mutable iterator instead",
"mut ",
Applicability::MachineApplicable,
if let Some(mut suggestions) = opt_suggestions
&& suggestions.peek().is_some()
{
err.span_suggestions(
span,
"use mutable method",
suggestions,
Applicability::MaybeIncorrect,
);
}
_ => {}
}
AddrOf(BorrowKind::Ref, Mutability::Not, expr) => {
// We have `for _ in &i`, suggest `for _ in &mut i`.
err.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"use a mutable iterator instead",
"mut ",
Applicability::MachineApplicable,
);
}
ExprKind::Path(hir::QPath::Resolved(None, path))
if let hir::def::Res::Local(hir_id) = path.res
&& let hir::Node::LetStmt(stmt) =
self.infcx.tcx.parent_hir_node(hir_id)
&& let Some(init) = stmt.init =>
{
// We're iterating over a binding, try to suggest changing the binding's expr.
expr = init;
continue;
}
_ => {}
}
break;
}
}

Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let projected_ty = curr_projected_ty.projection_ty_core(
tcx,
proj,
|ty| self.normalize(ty::Unnormalized::new_wip(ty), locations),
|ty, variant_index, field, ()| {
PlaceTy::field_ty(tcx, ty, variant_index, field).skip_norm_wip()
},
|ty| self.normalize(ty, locations),
|()| None,
|_| unreachable!(),
);
curr_projected_ty = projected_ty;
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,19 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
);
}

(&ty::Alias(ty::IsRigid::No, _), _) | (_, &ty::Alias(ty::IsRigid::No, _))
if infcx.next_trait_solver() =>
{
// NOTE(khyperia): If this turns out to be possible, either the caller should
// normalize the alias, or we should normalize the alias here. See the PR that
// introduced this comment for how to do so, which normalizes aliases in other
// relations.
span_bug!(
self.span(),
"it should not be possible to encounter unnormalized aliases in borrowck"
);
}

(&ty::Infer(ty::TyVar(a_vid)), _) => {
infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?
}
Expand Down Expand Up @@ -590,8 +603,4 @@ impl<'b, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_
},
);
}

fn ambient_variance(&self) -> ty::Variance {
self.ambient_variance
}
}
7 changes: 5 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ fn write_output_file<'ll>(
result.into_result().unwrap_or_else(|()| llvm_err(dcx, LlvmError::WriteOutput { path: output }))
}

/// If `for_cfg` is `true` then we are creating this machine for the purpose of populating
/// [`rustc_codegen_ssa::TargetConfig`] based on what LLVM actually enables in this configuration.
/// `-Ctarget-feature` should be ignored in that case since it is already processed separately.
pub(crate) fn create_informational_target_machine(
sess: &Session,
only_base_features: bool,
for_cfg: bool,
) -> OwnedTargetMachine {
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
// Can't use query system here quite yet because this function is invoked before the query
// system/tcx is set up.
let features = llvm_util::global_llvm_features(sess, only_base_features);
let features = llvm_util::global_llvm_features(sess, for_cfg);
target_machine_factory(sess, config::OptLevel::No, &features)(sess.dcx(), config)
}

Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_llvm/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,10 @@ pub(crate) struct IntrinsicWrongArch<'a> {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag("ignoring feature with missing prefix in `-Zllvm-target-feature`: `{$feature}`")]
#[note("features must begin with a `+` to enable or `-` to disable it")]
pub(crate) struct UnknownLlvmTargetFeaturePrefix<'a> {
pub feature: &'a str,
}
29 changes: 26 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,11 @@ fn llvm_features_by_flags(sess: &Session, features: &mut Vec<String>) {

/// The list of LLVM features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
/// `--target` and similar).
pub(crate) fn global_llvm_features(sess: &Session, only_base_features: bool) -> Vec<String> {
///
/// If `for_cfg` is `true` then we are assembling the feature list for the purpose of populating
/// [`rustc_codegen_ssa::TargetConfig`] based on what LLVM actually enables in this configuration.
/// `-Ctarget-feature` should be ignored in that case since it is already processed separately.
pub(crate) fn global_llvm_features(sess: &Session, for_cfg: bool) -> Vec<String> {
// Features that come earlier are overridden by conflicting features later in the string.
// Typically we'll want more explicit settings to override the implicit ones, so:
//
Expand Down Expand Up @@ -725,14 +729,33 @@ pub(crate) fn global_llvm_features(sess: &Session, only_base_features: bool) ->
// Features implied by an implicit or explicit `--target`.
target_features::target_spec_to_backend_features(sess, &mut extend_backend_features);

// -Ctarget-features
if !only_base_features {
// -Ctarget-features. Skipped for `cfg` as there we parse -Ctarget-features directly instead of
// going via an LLVM target machine (which avoids accidentally picking up LLVM-level target
// feature implications that we do not want).
if !for_cfg {
target_features::flag_to_backend_features(sess, extend_backend_features);
}

// We add this in the "base target" so that these show up in `sess.unstable_target_features`.
llvm_features_by_flags(sess, &mut features);

// `-Zllvm-target-features`, all the way at the end to overwrite everything.
// Should be picked up by `cfg` (e.g. if someone enables AVX this way).
for feature in sess.opts.unstable_opts.llvm_target_feature.split(',') {
if feature.is_empty() {
continue;
}
if feature.starts_with('+') || feature.starts_with('-') {
features.push(feature.to_owned());
} else {
// LLVM seems to silently ignore entries without leading `+`/`-`. Let's emit a warning
// to avoid confusion. But only emit this warning once, under `for_cfg`.
if for_cfg {
sess.dcx().emit_warn(diagnostics::UnknownLlvmTargetFeaturePrefix { feature });
}
}
}

features
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ pub(crate) struct XcrunSdkPathWarning {
pub(crate) struct Aarch64SoftfloatNeon;

#[derive(Diagnostic)]
#[diag("unknown feature specified for `-Ctarget-feature`: `{$feature}`")]
#[diag("ignoring feature with missing prefix in `-Ctarget-feature`: `{$feature}`")]
#[note("features must begin with a `+` to enable or `-` to disable it")]
pub(crate) struct UnknownCTargetFeaturePrefix<'a> {
pub feature: &'a str,
Expand Down
69 changes: 66 additions & 3 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use super::error::*;
use crate::diagnostics::{LongRunning, LongRunningWarn};
use crate::interpret::{
self, AllocId, AllocInit, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame,
GlobalAlloc, ImmTy, InterpCx, InterpResult, OpTy, PlaceTy, Pointer, RangeSet, RetagMode,
Scalar, compile_time_machine, ensure_monomorphic_enough, err_inval, interp_ok, throw_exhaust,
throw_inval, throw_ub, throw_ub_format, throw_unsup, throw_unsup_format,
GlobalAlloc, ImmTy, Immediate, InterpCx, InterpResult, OpTy, PlaceTy, Pointer, RangeSet,
RetagMode, Scalar, compile_time_machine, ensure_monomorphic_enough, err_inval, interp_ok,
throw_exhaust, throw_inval, throw_ub, throw_ub_format, throw_unsup, throw_unsup_format,
type_implements_dyn_trait,
};

Expand Down Expand Up @@ -712,6 +712,47 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
ecx.write_scalar(Scalar::from_target_usize(offset, ecx), dest)?;
}

sym::field_representing_type_name => {
let frt_ty = ecx.read_type_id(&args[0])?;

let field_name = if let ty::Adt(def, args) = frt_ty.kind()
&& let Some(FieldInfo { name, .. }) =
def.field_representing_type_info(ecx.tcx.tcx, args)
{
name
} else {
span_bug!(ecx.cur_span(), "expected field representing type, got {frt_ty}")
};
let ptr = ecx.allocate_bytes_dedup(field_name.as_str().as_bytes())?;
ecx.write_immediate(
Immediate::ScalarPair(
Scalar::from_pointer(ptr, ecx),
Scalar::from_target_usize(field_name.as_str().len() as u64, ecx),
),
dest,
)?;
}

sym::field_representing_type_offset => {
let frt_ty = ecx.read_type_id(&args[0])?;

let (ty, variant, field) = if let ty::Adt(def, args) = frt_ty.kind()
&& let Some(FieldInfo { base, variant_idx, field_idx, .. }) =
def.field_representing_type_info(ecx.tcx.tcx, args)
{
(base, variant_idx, field_idx)
} else {
span_bug!(ecx.cur_span(), "expected field representing type, got {frt_ty}")
};
let layout = ecx.layout_of(ty)?;
let cx = ty::layout::LayoutCx::new(ecx.tcx.tcx, ecx.typing_env());

let layout = layout.for_variant(&cx, variant);
let offset = layout.fields.offset(field.index()).bytes();

ecx.write_scalar(Scalar::from_target_usize(offset, ecx), dest)?;
}

sym::field_representing_type_actual_type_id => {
let frt_ty = ecx.read_type_id(&args[0])?;

Expand All @@ -726,6 +767,28 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
ecx.write_type_id(field_ty, dest)?;
}

sym::type_id_generics => {
let ty = ecx.read_type_id(&args[0])?;
ecx.write_type_id_generics(dest, ty)?;
}

sym::non_exhaustive => {
let ty = ecx.read_type_id(&args[0])?;

// FIXME(reflection): need a way to obtain non-exhaustiveness of a variant's fields.
let non_exhaustive = if let ty::Adt(def, _) = ty.kind() {
if def.is_enum() {
def.is_variant_list_non_exhaustive()
} else {
def.non_enum_variant().is_field_list_non_exhaustive()
}
} else {
false
};

ecx.write_scalar(Scalar::from_bool(non_exhaustive), dest)?;
}

_ => {
// We haven't handled the intrinsic, let's see if we can use a fallback body.
if ecx.tcx.intrinsic(instance.def_id()).unwrap().must_be_overridden {
Expand Down
Loading
Loading