Rollup merge of #140000 - EnzymeAD:autodiff-check-builds, r=onur-ozkan
skip llvm-config in autodiff check builds, when its unavailable
As you suggested, this indeed fixes `./x.py check` builds when autodiff is enabled.
r? ```@onur-ozkan```
closes #139936
Tracking:
- https://github.com/rust-lang/rust/issues/124509
diff --git a/Cargo.lock b/Cargo.lock
index 4441a50..97a90a4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2573,16 +2573,6 @@
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
-name = "os_pipe"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982"
-dependencies = [
- "libc",
- "windows-sys 0.59.0",
-]
-
-[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3142,7 +3132,6 @@
"gimli 0.31.1",
"libc",
"object 0.36.7",
- "os_pipe",
"regex",
"serde_json",
"similar",
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs
index d656d9b..f104400 100644
--- a/compiler/rustc_ast/src/attr/mod.rs
+++ b/compiler/rustc_ast/src/attr/mod.rs
@@ -305,8 +305,8 @@ pub fn ident(&self) -> Option<Ident> {
if let [PathSegment { ident, .. }] = self.path.segments[..] { Some(ident) } else { None }
}
- pub fn name_or_empty(&self) -> Symbol {
- self.ident().unwrap_or_else(Ident::empty).name
+ pub fn name(&self) -> Option<Symbol> {
+ self.ident().map(|ident| ident.name)
}
pub fn has_name(&self, name: Symbol) -> bool {
@@ -511,13 +511,14 @@ pub fn span(&self) -> Span {
}
}
- /// For a single-segment meta item, returns its name; otherwise, returns `None`.
+ /// For a single-segment meta item, returns its identifier; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> {
self.meta_item().and_then(|meta_item| meta_item.ident())
}
- pub fn name_or_empty(&self) -> Symbol {
- self.ident().unwrap_or_else(Ident::empty).name
+ /// For a single-segment meta item, returns its name; otherwise, returns `None`.
+ pub fn name(&self) -> Option<Symbol> {
+ self.ident().map(|ident| ident.name)
}
/// Returns `true` if this list item is a MetaItem with a name of `name`.
@@ -738,9 +739,9 @@ pub trait AttributeExt: Debug {
fn id(&self) -> AttrId;
/// For a single-segment attribute (i.e., `#[attr]` and not `#[path::atrr]`),
- /// return the name of the attribute, else return the empty identifier.
- fn name_or_empty(&self) -> Symbol {
- self.ident().unwrap_or_else(Ident::empty).name
+ /// return the name of the attribute; otherwise, returns `None`.
+ fn name(&self) -> Option<Symbol> {
+ self.ident().map(|ident| ident.name)
}
/// Get the meta item list, `#[attr(meta item list)]`
@@ -752,7 +753,7 @@ fn name_or_empty(&self) -> Symbol {
/// Gets the span of the value literal, as string, when using `#[attr = value]`
fn value_span(&self) -> Option<Span>;
- /// For a single-segment attribute, returns its name; otherwise, returns `None`.
+ /// For a single-segment attribute, returns its ident; otherwise, returns `None`.
fn ident(&self) -> Option<Ident>;
/// Checks whether the path of this attribute matches the name.
@@ -770,6 +771,11 @@ fn has_name(&self, name: Symbol) -> bool {
self.ident().map(|x| x.name == name).unwrap_or(false)
}
+ #[inline]
+ fn has_any_name(&self, names: &[Symbol]) -> bool {
+ names.iter().any(|&name| self.has_name(name))
+ }
+
/// get the span of the entire attribute
fn span(&self) -> Span;
@@ -813,8 +819,8 @@ pub fn id(&self) -> AttrId {
AttributeExt::id(self)
}
- pub fn name_or_empty(&self) -> Symbol {
- AttributeExt::name_or_empty(self)
+ pub fn name(&self) -> Option<Symbol> {
+ AttributeExt::name(self)
}
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
@@ -846,6 +852,11 @@ pub fn has_name(&self, name: Symbol) -> bool {
AttributeExt::has_name(self, name)
}
+ #[inline]
+ pub fn has_any_name(&self, names: &[Symbol]) -> bool {
+ AttributeExt::has_any_name(self, names)
+ }
+
pub fn span(&self) -> Span {
AttributeExt::span(self)
}
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index d8b55be..fc32c4e 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -1310,7 +1310,7 @@ fn lower_maybe_coroutine_body(
// create a fake body so that the entire rest of the compiler doesn't have to deal with
// this as a special case.
return self.lower_fn_body(decl, contract, |this| {
- if attrs.iter().any(|a| a.name_or_empty() == sym::rustc_intrinsic) {
+ if attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic)) {
let span = this.lower_span(span);
let empty_block = hir::Block {
hir_id: this.next_id(),
diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs
index 9a7b7da..1feb3e9 100644
--- a/compiler/rustc_ast_passes/src/ast_validation.rs
+++ b/compiler/rustc_ast_passes/src/ast_validation.rs
@@ -347,7 +347,7 @@ fn check_decl_attrs(&self, fn_decl: &FnDecl) {
sym::forbid,
sym::warn,
];
- !arr.contains(&attr.name_or_empty()) && rustc_attr_parsing::is_builtin_attr(*attr)
+ !attr.has_any_name(&arr) && rustc_attr_parsing::is_builtin_attr(*attr)
})
.for_each(|attr| {
if attr.is_doc_comment() {
@@ -947,8 +947,7 @@ fn visit_item(&mut self, item: &'a Item) {
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
self.check_defaultness(item.span, *defaultness);
- let is_intrinsic =
- item.attrs.iter().any(|a| a.name_or_empty() == sym::rustc_intrinsic);
+ let is_intrinsic = item.attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic));
if body.is_none() && !is_intrinsic {
self.dcx().emit_err(errors::FnWithoutBody {
span: item.span,
diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs
index 48297b2..7cb1fed 100644
--- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs
+++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs
@@ -102,7 +102,7 @@ pub fn eval_condition(
};
match &cfg.kind {
- MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
+ MetaItemKind::List(mis) if cfg.has_name(sym::version) => {
try_gate_cfg(sym::version, cfg.span, sess, features);
let (min_version, span) = match &mis[..] {
[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
@@ -149,18 +149,18 @@ pub fn eval_condition(
// The unwraps below may look dangerous, but we've already asserted
// that they won't fail with the loop above.
- match cfg.name_or_empty() {
- sym::any => mis
+ match cfg.name() {
+ Some(sym::any) => mis
.iter()
// We don't use any() here, because we want to evaluate all cfg condition
// as eval_condition can (and does) extra checks
.fold(false, |res, mi| res | eval_condition(mi, sess, features, eval)),
- sym::all => mis
+ Some(sym::all) => mis
.iter()
// We don't use all() here, because we want to evaluate all cfg condition
// as eval_condition can (and does) extra checks
.fold(true, |res, mi| res & eval_condition(mi, sess, features, eval)),
- sym::not => {
+ Some(sym::not) => {
let [mi] = mis.as_slice() else {
dcx.emit_err(session_diagnostics::ExpectedOneCfgPattern { span: cfg.span });
return false;
@@ -168,7 +168,7 @@ pub fn eval_condition(
!eval_condition(mi, sess, features, eval)
}
- sym::target => {
+ Some(sym::target) => {
if let Some(features) = features
&& !features.cfg_target_compact()
{
diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs
index 3bf03f8..972614a 100644
--- a/compiler/rustc_attr_parsing/src/context.rs
+++ b/compiler/rustc_attr_parsing/src/context.rs
@@ -222,7 +222,7 @@ pub fn parse_attribute_list<'a>(
// if we're only looking for a single attribute,
// skip all the ones we don't care about
if let Some(expected) = self.parse_only {
- if attr.name_or_empty() != expected {
+ if !attr.has_name(expected) {
continue;
}
}
@@ -232,7 +232,7 @@ pub fn parse_attribute_list<'a>(
// that's expanded right? But no, sometimes, when parsing attributes on macros,
// we already use the lowering logic and these are still there. So, when `omit_doc`
// is set we *also* want to ignore these
- if omit_doc == OmitDoc::Skip && attr.name_or_empty() == sym::doc {
+ if omit_doc == OmitDoc::Skip && attr.has_name(sym::doc) {
continue;
}
@@ -250,7 +250,7 @@ pub fn parse_attribute_list<'a>(
}))
}
// // FIXME: make doc attributes go through a proper attribute parser
- // ast::AttrKind::Normal(n) if n.name_or_empty() == sym::doc => {
+ // ast::AttrKind::Normal(n) if n.has_name(sym::doc) => {
// let p = GenericMetaItemParser::from_attr(&n, self.dcx());
//
// attributes.push(Attribute::Parsed(AttributeKind::DocComment {
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index 959cf9f..cf73581 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -2959,21 +2959,27 @@ fn report_local_value_does_not_live_long_enough(
}
}
- let mut err = self.path_does_not_live_long_enough(borrow_span, &format!("`{name}`"));
+ let name = if borrow_span.in_external_macro(self.infcx.tcx.sess.source_map()) {
+ // Don't name local variables in external macros.
+ "value".to_string()
+ } else {
+ format!("`{name}`")
+ };
+
+ let mut err = self.path_does_not_live_long_enough(borrow_span, &name);
if let Some(annotation) = self.annotate_argument_and_return_for_borrow(borrow) {
let region_name = annotation.emit(self, &mut err);
err.span_label(
borrow_span,
- format!("`{name}` would have to be valid for `{region_name}`..."),
+ format!("{name} would have to be valid for `{region_name}`..."),
);
err.span_label(
drop_span,
format!(
- "...but `{}` will be dropped here, when the {} returns",
- name,
+ "...but {name} will be dropped here, when the {} returns",
self.infcx
.tcx
.opt_item_name(self.mir_def_id().to_def_id())
@@ -3011,7 +3017,7 @@ fn report_local_value_does_not_live_long_enough(
}
} else {
err.span_label(borrow_span, "borrowed value does not live long enough");
- err.span_label(drop_span, format!("`{name}` dropped here while still borrowed"));
+ err.span_label(drop_span, format!("{name} dropped here while still borrowed"));
borrow_spans.args_subdiag(&mut err, |args_span| {
crate::session_diagnostics::CaptureArgLabel::Capture {
diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
index f77dda0..a845431 100644
--- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
@@ -95,7 +95,9 @@ pub(crate) fn add_explanation_to_diagnostic<G: EmissionGuarantee>(
&& let hir::def::Res::Local(hir_id) = p.res
&& let hir::Node::Pat(pat) = tcx.hir_node(hir_id)
{
- err.span_label(pat.span, format!("binding `{ident}` declared here"));
+ if !ident.span.in_external_macro(tcx.sess.source_map()) {
+ err.span_label(pat.span, format!("binding `{ident}` declared here"));
+ }
}
}
}
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
index b9197be..d9aac54 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
@@ -527,15 +527,14 @@ pub(crate) fn expand_ext(
item.attrs
.iter()
.filter(|a| {
- [
+ a.has_any_name(&[
sym::allow,
sym::warn,
sym::deny,
sym::forbid,
sym::stable,
sym::unstable,
- ]
- .contains(&a.name_or_empty())
+ ])
})
.cloned(),
);
diff --git a/compiler/rustc_codegen_gcc/.github/workflows/ci.yml b/compiler/rustc_codegen_gcc/.github/workflows/ci.yml
index f96912e..ef02425 100644
--- a/compiler/rustc_codegen_gcc/.github/workflows/ci.yml
+++ b/compiler/rustc_codegen_gcc/.github/workflows/ci.yml
@@ -1,8 +1,10 @@
name: CI
on:
- - push
- - pull_request
+ push:
+ branches:
+ - master
+ pull_request:
permissions:
contents: read
@@ -121,3 +123,22 @@
run: |
cd build_system
cargo test
+
+ # Summary job for the merge queue.
+ # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+ success:
+ needs: [build, duplicates, build_system]
+ # We need to ensure this job does *not* get skipped if its dependencies fail,
+ # because a skipped job is considered a success by GitHub. So we have to
+ # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
+ # when the workflow is canceled manually.
+ if: ${{ !cancelled() }}
+ runs-on: ubuntu-latest
+ steps:
+ # Manually check the status of all dependencies. `if: failure()` does not work.
+ - name: Conclusion
+ run: |
+ # Print the dependent jobs to see them in the CI log
+ jq -C <<< '${{ toJson(needs) }}'
+ # Check if all jobs that we depend on (in the needs array) were successful.
+ jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
diff --git a/compiler/rustc_codegen_gcc/.github/workflows/failures.yml b/compiler/rustc_codegen_gcc/.github/workflows/failures.yml
index d080bbf..bc42eb1 100644
--- a/compiler/rustc_codegen_gcc/.github/workflows/failures.yml
+++ b/compiler/rustc_codegen_gcc/.github/workflows/failures.yml
@@ -2,7 +2,10 @@
name: Failures
on:
- - pull_request
+ push:
+ branches:
+ - master
+ pull_request:
permissions:
contents: read
@@ -108,3 +111,22 @@
echo "Error: 'the compiler unexpectedly panicked' found in output logs. CI Error!!"
exit 1
fi
+
+ # Summary job for the merge queue.
+ # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+ success_failures:
+ needs: [build]
+ # We need to ensure this job does *not* get skipped if its dependencies fail,
+ # because a skipped job is considered a success by GitHub. So we have to
+ # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
+ # when the workflow is canceled manually.
+ if: ${{ !cancelled() }}
+ runs-on: ubuntu-latest
+ steps:
+ # Manually check the status of all dependencies. `if: failure()` does not work.
+ - name: Conclusion
+ run: |
+ # Print the dependent jobs to see them in the CI log
+ jq -C <<< '${{ toJson(needs) }}'
+ # Check if all jobs that we depend on (in the needs array) were successful.
+ jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
diff --git a/compiler/rustc_codegen_gcc/.github/workflows/gcc12.yml b/compiler/rustc_codegen_gcc/.github/workflows/gcc12.yml
index bb9e020..da9a150 100644
--- a/compiler/rustc_codegen_gcc/.github/workflows/gcc12.yml
+++ b/compiler/rustc_codegen_gcc/.github/workflows/gcc12.yml
@@ -1,8 +1,10 @@
name: CI libgccjit 12
on:
- - push
- - pull_request
+ push:
+ branches:
+ - master
+ pull_request:
permissions:
contents: read
@@ -85,3 +87,22 @@
#- name: Run tests
#run: |
#./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features
+
+ # Summary job for the merge queue.
+ # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+ success_gcc12:
+ needs: [build]
+ # We need to ensure this job does *not* get skipped if its dependencies fail,
+ # because a skipped job is considered a success by GitHub. So we have to
+ # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
+ # when the workflow is canceled manually.
+ if: ${{ !cancelled() }}
+ runs-on: ubuntu-latest
+ steps:
+ # Manually check the status of all dependencies. `if: failure()` does not work.
+ - name: Conclusion
+ run: |
+ # Print the dependent jobs to see them in the CI log
+ jq -C <<< '${{ toJson(needs) }}'
+ # Check if all jobs that we depend on (in the needs array) were successful.
+ jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
diff --git a/compiler/rustc_codegen_gcc/.github/workflows/m68k.yml b/compiler/rustc_codegen_gcc/.github/workflows/m68k.yml
index ed1fc02..21731f7 100644
--- a/compiler/rustc_codegen_gcc/.github/workflows/m68k.yml
+++ b/compiler/rustc_codegen_gcc/.github/workflows/m68k.yml
@@ -3,8 +3,10 @@
name: m68k CI
on:
- - push
- - pull_request
+ push:
+ branches:
+ - master
+ pull_request:
permissions:
contents: read
@@ -105,3 +107,22 @@
- name: Run tests
run: |
./y.sh test --release --clean --build-sysroot --sysroot-features compiler_builtins/no-f16-f128 ${{ matrix.commands }}
+
+ # Summary job for the merge queue.
+ # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+ success_m68k:
+ needs: [build]
+ # We need to ensure this job does *not* get skipped if its dependencies fail,
+ # because a skipped job is considered a success by GitHub. So we have to
+ # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
+ # when the workflow is canceled manually.
+ if: ${{ !cancelled() }}
+ runs-on: ubuntu-latest
+ steps:
+ # Manually check the status of all dependencies. `if: failure()` does not work.
+ - name: Conclusion
+ run: |
+ # Print the dependent jobs to see them in the CI log
+ jq -C <<< '${{ toJson(needs) }}'
+ # Check if all jobs that we depend on (in the needs array) were successful.
+ jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
diff --git a/compiler/rustc_codegen_gcc/.github/workflows/release.yml b/compiler/rustc_codegen_gcc/.github/workflows/release.yml
index 886ce90..47a4028 100644
--- a/compiler/rustc_codegen_gcc/.github/workflows/release.yml
+++ b/compiler/rustc_codegen_gcc/.github/workflows/release.yml
@@ -1,8 +1,10 @@
name: CI with sysroot compiled in release mode
on:
- - push
- - pull_request
+ push:
+ branches:
+ - master
+ pull_request:
permissions:
contents: read
@@ -82,3 +84,22 @@
echo "Test is done with LTO enabled, hence inlining should occur across crates"
exit 1
fi
+
+ # Summary job for the merge queue.
+ # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+ success_release:
+ needs: [build]
+ # We need to ensure this job does *not* get skipped if its dependencies fail,
+ # because a skipped job is considered a success by GitHub. So we have to
+ # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
+ # when the workflow is canceled manually.
+ if: ${{ !cancelled() }}
+ runs-on: ubuntu-latest
+ steps:
+ # Manually check the status of all dependencies. `if: failure()` does not work.
+ - name: Conclusion
+ run: |
+ # Print the dependent jobs to see them in the CI log
+ jq -C <<< '${{ toJson(needs) }}'
+ # Check if all jobs that we depend on (in the needs array) were successful.
+ jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
diff --git a/compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml b/compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml
index d5ae614..4b9f48e 100644
--- a/compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml
+++ b/compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml
@@ -1,8 +1,10 @@
name: stdarch tests with sysroot compiled in release mode
on:
- - push
- - pull_request
+ push:
+ branches:
+ - master
+ pull_request:
permissions:
contents: read
@@ -102,3 +104,22 @@
# TODO: remove --skip test_mm512_stream_ps when stdarch is updated in rustc.
# TODO: remove --skip test_tile_ when it's implemented.
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features --cfg stdarch_intel_sde" ./y.sh cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml -- --skip rtm --skip tbm --skip sse4a --skip test_mm512_stream_ps --skip test_tile_
+
+ # Summary job for the merge queue.
+ # ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+ success_stdarch:
+ needs: [build]
+ # We need to ensure this job does *not* get skipped if its dependencies fail,
+ # because a skipped job is considered a success by GitHub. So we have to
+ # overwrite `if:`. We use `!cancelled()` to ensure the job does still not get run
+ # when the workflow is canceled manually.
+ if: ${{ !cancelled() }}
+ runs-on: ubuntu-latest
+ steps:
+ # Manually check the status of all dependencies. `if: failure()` does not work.
+ - name: Conclusion
+ run: |
+ # Print the dependent jobs to see them in the CI log
+ jq -C <<< '${{ toJson(needs) }}'
+ # Check if all jobs that we depend on (in the needs array) were successful.
+ jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
diff --git a/compiler/rustc_codegen_gcc/Cargo.lock b/compiler/rustc_codegen_gcc/Cargo.lock
index 636e75b..832603a 100644
--- a/compiler/rustc_codegen_gcc/Cargo.lock
+++ b/compiler/rustc_codegen_gcc/Cargo.lock
@@ -56,18 +56,18 @@
[[package]]
name = "gccjit"
-version = "2.4.0"
+version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72fd91f4adbf02b53cfc73c97bc33c5f253009043f30c56a5ec08dd5c8094dc8"
+checksum = "2895ddec764de7ac76fe6c056050c4801a80109c066f177a00a9cc8dee02b29b"
dependencies = [
"gccjit_sys",
]
[[package]]
name = "gccjit_sys"
-version = "0.5.0"
+version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0fb7b8f48a75e2cfe78c3d9a980b32771c34ffd12d196021ab3f98c49fbd2f0d"
+checksum = "ac133db68db8a6a8b2c51ef4b18d8ea16682d5814c4641272fe37bbbc223d5f3"
dependencies = [
"libc",
]
diff --git a/compiler/rustc_codegen_gcc/Cargo.toml b/compiler/rustc_codegen_gcc/Cargo.toml
index 63d3735..b50f2a6 100644
--- a/compiler/rustc_codegen_gcc/Cargo.toml
+++ b/compiler/rustc_codegen_gcc/Cargo.toml
@@ -22,7 +22,7 @@
default = ["master"]
[dependencies]
-gccjit = "2.4"
+gccjit = "2.5"
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }
# Local copy.
diff --git a/compiler/rustc_codegen_gcc/Readme.md b/compiler/rustc_codegen_gcc/Readme.md
index e92c16e..d0e4dbb 100644
--- a/compiler/rustc_codegen_gcc/Readme.md
+++ b/compiler/rustc_codegen_gcc/Readme.md
@@ -23,7 +23,7 @@
## Building
**This requires a patched libgccjit in order to work.
-You need to use my [fork of gcc](https://github.com/antoyo/gcc) which already includes these patches.**
+You need to use my [fork of gcc](https://github.com/rust-lang/gcc) which already includes these patches.**
```bash
$ cp config.example.toml config.toml
@@ -40,7 +40,7 @@
To build it (most of these instructions come from [here](https://gcc.gnu.org/onlinedocs/jit/internals/index.html), so don't hesitate to take a look there if you encounter an issue):
```bash
-$ git clone https://github.com/antoyo/gcc
+$ git clone https://github.com/rust-lang/gcc
$ sudo apt install flex libmpfr-dev libgmp-dev libmpc3 libmpc-dev
$ mkdir gcc-build gcc-install
$ cd gcc-build
diff --git a/compiler/rustc_codegen_gcc/build_system/src/clone_gcc.rs b/compiler/rustc_codegen_gcc/build_system/src/clone_gcc.rs
index e28ee87..b49dd47 100644
--- a/compiler/rustc_codegen_gcc/build_system/src/clone_gcc.rs
+++ b/compiler/rustc_codegen_gcc/build_system/src/clone_gcc.rs
@@ -61,7 +61,7 @@ pub fn run() -> Result<(), String> {
return Ok(());
};
- let result = git_clone("https://github.com/antoyo/gcc", Some(&args.out_path), false)?;
+ let result = git_clone("https://github.com/rust-lang/gcc", Some(&args.out_path), false)?;
if result.ran_clone {
let gcc_commit = args.config_info.get_gcc_commit()?;
println!("Checking out GCC commit `{}`...", gcc_commit);
diff --git a/compiler/rustc_codegen_gcc/build_system/src/test.rs b/compiler/rustc_codegen_gcc/build_system/src/test.rs
index 6c29c7d..df4ac85 100644
--- a/compiler/rustc_codegen_gcc/build_system/src/test.rs
+++ b/compiler/rustc_codegen_gcc/build_system/src/test.rs
@@ -529,20 +529,21 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
env.insert("COMPILETEST_FORCE_STAGE0".to_string(), "1".to_string());
- let extra =
- if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
-
- let rustc_args = &format!(
- r#"-Zpanic-abort-tests \
- -Zcodegen-backend="{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}" \
- --sysroot "{sysroot_dir}" -Cpanic=abort{extra}"#,
+ let codegen_backend_path = format!(
+ "{pwd}/target/{channel}/librustc_codegen_gcc.{dylib_ext}",
pwd = std::env::current_dir()
.map_err(|error| format!("`current_dir` failed: {:?}", error))?
.display(),
channel = args.config_info.channel.as_str(),
dylib_ext = args.config_info.dylib_ext,
- sysroot_dir = args.config_info.sysroot_path,
- extra = extra,
+ );
+
+ let extra =
+ if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
+
+ let rustc_args = format!(
+ "-Zpanic-abort-tests -Zcodegen-backend={codegen_backend_path} --sysroot {} -Cpanic=abort{extra}",
+ args.config_info.sysroot_path
);
run_command_with_env(
@@ -677,7 +678,7 @@ fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] libcore");
- let path = get_sysroot_dir().join("sysroot_src/library/core/tests");
+ let path = get_sysroot_dir().join("sysroot_src/library/coretests");
let _ = remove_dir_all(path.join("target"));
run_cargo_command(&[&"test"], Some(&path), env, args)?;
Ok(())
diff --git a/compiler/rustc_codegen_gcc/doc/add-attribute.md b/compiler/rustc_codegen_gcc/doc/add-attribute.md
index ae3bcc5..267c181 100644
--- a/compiler/rustc_codegen_gcc/doc/add-attribute.md
+++ b/compiler/rustc_codegen_gcc/doc/add-attribute.md
@@ -14,4 +14,4 @@
To test it, build `gcc`, run `cargo update -p gccjit` and then you can test the generated output for a given Rust crate.
-[gccjit.rs]: https://github.com/antoyo/gccjit.rs
+[gccjit.rs]: https://github.com/rust-lang/gccjit.rs
diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs
index 5544aee..c554a87 100644
--- a/compiler/rustc_codegen_gcc/example/mini_core.rs
+++ b/compiler/rustc_codegen_gcc/example/mini_core.rs
@@ -51,6 +51,10 @@ impl<T: ?Sized> LegacyReceiver for &T {}
impl<T: ?Sized> LegacyReceiver for &mut T {}
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
+#[lang = "receiver"]
+trait Receiver {
+}
+
#[lang = "copy"]
pub trait Copy {}
@@ -134,6 +138,14 @@ fn mul(self, rhs: Self) -> Self::Output {
}
}
+impl Mul for i32 {
+ type Output = Self;
+
+ fn mul(self, rhs: Self) -> Self::Output {
+ self * rhs
+ }
+}
+
impl Mul for usize {
type Output = Self;
@@ -142,6 +154,14 @@ fn mul(self, rhs: Self) -> Self::Output {
}
}
+impl Mul for isize {
+ type Output = Self;
+
+ fn mul(self, rhs: Self) -> Self::Output {
+ self * rhs
+ }
+}
+
#[lang = "add"]
pub trait Add<RHS = Self> {
type Output;
@@ -165,6 +185,14 @@ fn add(self, rhs: Self) -> Self {
}
}
+impl Add for i32 {
+ type Output = Self;
+
+ fn add(self, rhs: Self) -> Self {
+ self + rhs
+ }
+}
+
impl Add for usize {
type Output = Self;
@@ -196,6 +224,14 @@ fn sub(self, rhs: Self) -> Self {
}
}
+impl Sub for isize {
+ type Output = Self;
+
+ fn sub(self, rhs: Self) -> Self {
+ self - rhs
+ }
+}
+
impl Sub for u8 {
type Output = Self;
@@ -220,6 +256,14 @@ fn sub(self, rhs: Self) -> Self {
}
}
+impl Sub for i32 {
+ type Output = Self;
+
+ fn sub(self, rhs: Self) -> Self {
+ self - rhs
+ }
+}
+
#[lang = "rem"]
pub trait Rem<RHS = Self> {
type Output;
@@ -628,6 +672,10 @@ pub mod libc {
pub fn memcpy(dst: *mut u8, src: *const u8, size: usize);
pub fn memmove(dst: *mut u8, src: *const u8, size: usize);
pub fn strncpy(dst: *mut u8, src: *const u8, size: usize);
+ pub fn fflush(stream: *mut i32) -> i32;
+ pub fn exit(status: i32);
+
+ pub static stdout: *mut i32;
}
}
diff --git a/compiler/rustc_codegen_gcc/libgccjit.version b/compiler/rustc_codegen_gcc/libgccjit.version
index 417fd5b..125b040 100644
--- a/compiler/rustc_codegen_gcc/libgccjit.version
+++ b/compiler/rustc_codegen_gcc/libgccjit.version
@@ -1 +1 @@
-e607be166673a8de9fc07f6f02c60426e556c5f2
+0ea98a1365b81f7488073512c850e8ee951a4afd
diff --git a/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch b/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch
deleted file mode 100644
index 70e3e2b..0000000
--- a/compiler/rustc_codegen_gcc/patches/0022-core-Disable-not-compiling-tests.patch
+++ /dev/null
@@ -1,44 +0,0 @@
-From af0e237f056fa838c77463381a19b0dc993c0a35 Mon Sep 17 00:00:00 2001
-From: None <none@example.com>
-Date: Sun, 1 Sep 2024 11:42:17 -0400
-Subject: [PATCH] Disable not compiling tests
-
----
- library/core/tests/Cargo.toml | 14 ++++++++++++++
- library/core/tests/lib.rs | 1 +
- 2 files changed, 15 insertions(+)
- create mode 100644 library/core/tests/Cargo.toml
-
-diff --git a/library/core/tests/Cargo.toml b/library/core/tests/Cargo.toml
-new file mode 100644
-index 0000000..ca326ac
---- /dev/null
-+++ b/library/core/tests/Cargo.toml
-@@ -0,0 +1,14 @@
-+[workspace]
-+
-+[package]
-+name = "coretests"
-+version = "0.0.0"
-+edition = "2021"
-+
-+[lib]
-+name = "coretests"
-+path = "lib.rs"
-+
-+[dependencies]
-+rand = { version = "0.8.5", default-features = false }
-+rand_xorshift = { version = "0.3.0", default-features = false }
-diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
-index a4a7946..ecfe43f 100644
---- a/library/core/tests/lib.rs
-+++ b/library/core/tests/lib.rs
-@@ -1,4 +1,5 @@
- // tidy-alphabetical-start
-+#![cfg(test)]
- #![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
- #![cfg_attr(test, feature(cfg_match))]
- #![feature(alloc_layout_extra)]
---
-2.47.1
-
diff --git a/compiler/rustc_codegen_gcc/patches/0028-core-Disable-long-running-tests.patch b/compiler/rustc_codegen_gcc/patches/0028-core-Disable-long-running-tests.patch
index dc1beae..20df424 100644
--- a/compiler/rustc_codegen_gcc/patches/0028-core-Disable-long-running-tests.patch
+++ b/compiler/rustc_codegen_gcc/patches/0028-core-Disable-long-running-tests.patch
@@ -1,17 +1,17 @@
-From eb703e627e7a84f1cd8d0d87f0f69da1f0acf765 Mon Sep 17 00:00:00 2001
-From: bjorn3 <bjorn3@users.noreply.github.com>
-Date: Fri, 3 Dec 2021 12:16:30 +0100
+From ec2d0dc77fb484d926b45bb626b0db6a4bb0ab5c Mon Sep 17 00:00:00 2001
+From: None <none@example.com>
+Date: Thu, 27 Mar 2025 09:20:41 -0400
Subject: [PATCH] Disable long running tests
---
- library/core/tests/slice.rs | 2 ++
+ library/coretests/tests/slice.rs | 2 ++
1 file changed, 2 insertions(+)
-diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
-index 8402833..84592e0 100644
---- a/library/core/tests/slice.rs
-+++ b/library/core/tests/slice.rs
-@@ -2462,6 +2462,7 @@ take_tests! {
+diff --git a/library/coretests/tests/slice.rs b/library/coretests/tests/slice.rs
+index d17e681..fba5cd6 100644
+--- a/library/coretests/tests/slice.rs
++++ b/library/coretests/tests/slice.rs
+@@ -2486,6 +2486,7 @@ split_off_tests! {
#[cfg(not(miri))] // unused in Miri
const EMPTY_MAX: &'static [()] = &[(); usize::MAX];
@@ -19,14 +19,14 @@
// can't be a constant due to const mutability rules
#[cfg(not(miri))] // unused in Miri
macro_rules! empty_max_mut {
-@@ -2485,6 +2486,7 @@ take_tests! {
- (take_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()),
- (take_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()),
+@@ -2509,6 +2510,7 @@ split_off_tests! {
+ (split_off_mut_oob_max_range_to_inclusive, (..=usize::MAX), None, empty_max_mut!()),
+ (split_off_mut_in_bounds_max_range_from, (usize::MAX..), Some(&mut [] as _), empty_max_mut!()),
}
+*/
#[test]
fn test_slice_from_ptr_range() {
--
-2.26.2.7.g19db9cfb68
+2.49.0
diff --git a/compiler/rustc_codegen_gcc/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch b/compiler/rustc_codegen_gcc/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch
index c220f53..fa360fe 100644
--- a/compiler/rustc_codegen_gcc/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch
+++ b/compiler/rustc_codegen_gcc/patches/cross_patches/0001-Disable-libstd-and-libtest-dylib.patch
@@ -1,19 +1,18 @@
-From 966beefe08be6045bfcca26079b76a7a80413080 Mon Sep 17 00:00:00 2001
+From b2911e732d1bf0e28872495c4c47af1dad3c7911 Mon Sep 17 00:00:00 2001
From: None <none@example.com>
-Date: Thu, 28 Sep 2023 17:37:38 -0400
+Date: Thu, 27 Mar 2025 14:30:10 -0400
Subject: [PATCH] Disable libstd and libtest dylib
---
- library/std/Cargo.toml | 2 +-
- library/test/Cargo.toml | 2 +-
- 2 files changed, 2 insertions(+), 2 deletions(-)
+ library/std/Cargo.toml | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml
-index 5b21355..cb0c49b 100644
+index 176da60..c183cdb 100644
--- a/library/std/Cargo.toml
+++ b/library/std/Cargo.toml
-@@ -9,7 +9,7 @@ description = "The Rust Standard Library"
- edition = "2021"
+@@ -10,7 +10,7 @@ edition = "2024"
+ autobenches = false
[lib]
-crate-type = ["dylib", "rlib"]
@@ -21,3 +20,6 @@
[dependencies]
alloc = { path = "../alloc", public = true }
+--
+2.49.0
+
diff --git a/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch b/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch
index 9ef5e0e..9d5b2dc 100644
--- a/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch
+++ b/compiler/rustc_codegen_gcc/patches/libgccjit12/0001-core-Disable-portable-simd-test.patch
@@ -1,25 +1,17 @@
-From 124a11ce086952a5794d5cfbaa45175809497b81 Mon Sep 17 00:00:00 2001
+From 1a8f6b8e39f343959d4d2e6b6957a6d780ac3fc0 Mon Sep 17 00:00:00 2001
From: None <none@example.com>
-Date: Sat, 18 Nov 2023 10:50:36 -0500
-Subject: [PATCH] [core] Disable portable-simd test
+Date: Thu, 27 Mar 2025 14:32:14 -0400
+Subject: [PATCH] Disable portable-simd test
---
- library/core/tests/lib.rs | 2 --
- 1 file changed, 2 deletions(-)
+ library/coretests/tests/lib.rs | 1 -
+ 1 file changed, 1 deletion(-)
-diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
-index b71786c..cf484d5 100644
---- a/library/core/tests/lib.rs
-+++ b/library/core/tests/lib.rs
-@@ -87,7 +87,6 @@
- #![feature(numfmt)]
- #![feature(pattern)]
- #![feature(pointer_is_aligned_to)]
--#![feature(portable_simd)]
- #![feature(ptr_metadata)]
- #![feature(slice_from_ptr_range)]
- #![feature(slice_internals)]
-@@ -155,7 +154,6 @@ mod pin;
+diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs
+index 79022fe..9223b2f 100644
+--- a/library/coretests/tests/lib.rs
++++ b/library/coretests/tests/lib.rs
+@@ -165,7 +165,6 @@ mod pin;
mod pin_macro;
mod ptr;
mod result;
@@ -27,4 +19,6 @@
mod slice;
mod str;
mod str_lossy;
--- 2.45.2
+--
+2.49.0
+
diff --git a/compiler/rustc_codegen_gcc/rust-toolchain b/compiler/rustc_codegen_gcc/rust-toolchain
index 940b3de..fd898c5 100644
--- a/compiler/rustc_codegen_gcc/rust-toolchain
+++ b/compiler/rustc_codegen_gcc/rust-toolchain
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2025-01-12"
+channel = "nightly-2025-04-17"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
diff --git a/compiler/rustc_codegen_gcc/src/abi.rs b/compiler/rustc_codegen_gcc/src/abi.rs
index 9fe6baa..a96b18e 100644
--- a/compiler/rustc_codegen_gcc/src/abi.rs
+++ b/compiler/rustc_codegen_gcc/src/abi.rs
@@ -9,6 +9,8 @@
use rustc_middle::ty::layout::LayoutOf;
#[cfg(feature = "master")]
use rustc_session::config;
+#[cfg(feature = "master")]
+use rustc_target::callconv::Conv;
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
use crate::builder::Builder;
@@ -105,6 +107,8 @@ pub trait FnAbiGccExt<'gcc, 'tcx> {
// TODO(antoyo): return a function pointer type instead?
fn gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> FnAbiGcc<'gcc>;
fn ptr_to_gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc>;
+ #[cfg(feature = "master")]
+ fn gcc_cconv(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Option<FnAttribute<'gcc>>;
}
impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
@@ -227,4 +231,47 @@ fn ptr_to_gcc_type(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
);
pointer_type
}
+
+ #[cfg(feature = "master")]
+ fn gcc_cconv(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Option<FnAttribute<'gcc>> {
+ conv_to_fn_attribute(self.conv, &cx.tcx.sess.target.arch)
+ }
+}
+
+#[cfg(feature = "master")]
+pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<'gcc>> {
+ // TODO: handle the calling conventions returning None.
+ let attribute = match conv {
+ Conv::C
+ | Conv::Rust
+ | Conv::CCmseNonSecureCall
+ | Conv::CCmseNonSecureEntry
+ | Conv::RiscvInterrupt { .. } => return None,
+ Conv::Cold => return None,
+ Conv::PreserveMost => return None,
+ Conv::PreserveAll => return None,
+ Conv::GpuKernel => {
+ // TODO(antoyo): remove clippy allow attribute when this is implemented.
+ #[allow(clippy::if_same_then_else)]
+ if arch == "amdgpu" {
+ return None;
+ } else if arch == "nvptx64" {
+ return None;
+ } else {
+ panic!("Architecture {} does not support GpuKernel calling convention", arch);
+ }
+ }
+ Conv::AvrInterrupt => return None,
+ Conv::AvrNonBlockingInterrupt => return None,
+ Conv::ArmAapcs => return None,
+ Conv::Msp430Intr => return None,
+ Conv::X86Fastcall => return None,
+ Conv::X86Intr => return None,
+ Conv::X86Stdcall => return None,
+ Conv::X86ThisCall => return None,
+ Conv::X86VectorCall => return None,
+ Conv::X86_64SysV => FnAttribute::SysvAbi,
+ Conv::X86_64Win64 => FnAttribute::MsAbi,
+ };
+ Some(attribute)
}
diff --git a/compiler/rustc_codegen_gcc/src/asm.rs b/compiler/rustc_codegen_gcc/src/asm.rs
index 415f8af..dbdf37e 100644
--- a/compiler/rustc_codegen_gcc/src/asm.rs
+++ b/compiler/rustc_codegen_gcc/src/asm.rs
@@ -36,7 +36,8 @@
//
// 3. Clobbers. GCC has a separate list of clobbers, and clobbers don't have indexes.
// Contrary, Rust expresses clobbers through "out" operands that aren't tied to
-// a variable (`_`), and such "clobbers" do have index.
+// a variable (`_`), and such "clobbers" do have index. Input operands cannot also
+// be clobbered.
//
// 4. Furthermore, GCC Extended Asm does not support explicit register constraints
// (like `out("eax")`) directly, offering so-called "local register variables"
@@ -161,6 +162,16 @@ fn codegen_inline_asm(
// Also, we don't emit any asm operands immediately; we save them to
// the one of the buffers to be emitted later.
+ let mut input_registers = vec![];
+
+ for op in rust_operands {
+ if let InlineAsmOperandRef::In { reg, .. } = *op {
+ if let ConstraintOrRegister::Register(reg_name) = reg_to_gcc(reg) {
+ input_registers.push(reg_name);
+ }
+ }
+ }
+
// 1. Normal variables (and saving operands to buffers).
for (rust_idx, op) in rust_operands.iter().enumerate() {
match *op {
@@ -183,25 +194,39 @@ fn codegen_inline_asm(
continue;
}
(Register(reg_name), None) => {
- // `clobber_abi` can add lots of clobbers that are not supported by the target,
- // such as AVX-512 registers, so we just ignore unsupported registers
- let is_target_supported =
- reg.reg_class().supported_types(asm_arch, true).iter().any(
- |&(_, feature)| {
- if let Some(feature) = feature {
- self.tcx
- .asm_target_features(instance.def_id())
- .contains(&feature)
- } else {
- true // Register class is unconditionally supported
- }
- },
- );
+ if input_registers.contains(®_name) {
+ // the `clobber_abi` operand is converted into a series of
+ // `lateout("reg") _` operands. Of course, a user could also
+ // explicitly define such an output operand.
+ //
+ // GCC does not allow input registers to be clobbered, so if this out register
+ // is also used as an in register, do not add it to the clobbers list.
+ // it will be treated as a lateout register with `out_place: None`
+ if !late {
+ bug!("input registers can only be used as lateout regisers");
+ }
+ ("r", dummy_output_type(self.cx, reg.reg_class()))
+ } else {
+ // `clobber_abi` can add lots of clobbers that are not supported by the target,
+ // such as AVX-512 registers, so we just ignore unsupported registers
+ let is_target_supported =
+ reg.reg_class().supported_types(asm_arch, true).iter().any(
+ |&(_, feature)| {
+ if let Some(feature) = feature {
+ self.tcx
+ .asm_target_features(instance.def_id())
+ .contains(&feature)
+ } else {
+ true // Register class is unconditionally supported
+ }
+ },
+ );
- if is_target_supported && !clobbers.contains(®_name) {
- clobbers.push(reg_name);
+ if is_target_supported && !clobbers.contains(®_name) {
+ clobbers.push(reg_name);
+ }
+ continue;
}
- continue;
}
};
@@ -230,13 +255,10 @@ fn codegen_inline_asm(
}
InlineAsmOperandRef::InOut { reg, late, in_value, out_place } => {
- let constraint =
- if let ConstraintOrRegister::Constraint(constraint) = reg_to_gcc(reg) {
- constraint
- } else {
- // left for the next pass
- continue;
- };
+ let ConstraintOrRegister::Constraint(constraint) = reg_to_gcc(reg) else {
+ // left for the next pass
+ continue;
+ };
// Rustc frontend guarantees that input and output types are "compatible",
// so we can just use input var's type for the output variable.
@@ -589,114 +611,127 @@ fn estimate_template_length(
}
/// Converts a register class to a GCC constraint code.
-fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
- let constraint = match reg {
- // For vector registers LLVM wants the register name to match the type size.
+fn reg_to_gcc(reg_or_reg_class: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
+ match reg_or_reg_class {
InlineAsmRegOrRegClass::Reg(reg) => {
- match reg {
- InlineAsmReg::X86(_) => {
- // TODO(antoyo): add support for vector register.
- //
- // // For explicit registers, we have to create a register variable: https://stackoverflow.com/a/31774784/389119
- return ConstraintOrRegister::Register(match reg.name() {
- // Some of registers' names does not map 1-1 from rust to gcc
- "st(0)" => "st",
+ ConstraintOrRegister::Register(explicit_reg_to_gcc(reg))
+ }
+ InlineAsmRegOrRegClass::RegClass(reg_class) => {
+ ConstraintOrRegister::Constraint(reg_class_to_gcc(reg_class))
+ }
+ }
+}
- name => name,
- });
+fn explicit_reg_to_gcc(reg: InlineAsmReg) -> &'static str {
+ // For explicit registers, we have to create a register variable: https://stackoverflow.com/a/31774784/389119
+ match reg {
+ InlineAsmReg::X86(reg) => {
+ // TODO(antoyo): add support for vector register.
+ match reg.reg_class() {
+ X86InlineAsmRegClass::reg_byte => {
+ // GCC does not support the `b` suffix, so we just strip it
+ // see https://github.com/rust-lang/rustc_codegen_gcc/issues/485
+ reg.name().trim_end_matches('b')
}
+ _ => match reg.name() {
+ // Some of registers' names does not map 1-1 from rust to gcc
+ "st(0)" => "st",
- _ => unimplemented!(),
+ name => name,
+ },
}
}
- // They can be retrieved from https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
- InlineAsmRegOrRegClass::RegClass(reg) => match reg {
- InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg) => "w",
- InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => "x",
- InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
- unreachable!("clobber-only")
- }
- InlineAsmRegClass::Arm(ArmInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg_low16)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg_low8)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg_low16)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg_low8)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg_low4)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg)
- | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg) => "t",
- InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_upper) => "d",
- InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_pair) => "r",
- InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_iw) => "w",
- InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_ptr) => "e",
- InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
- InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
- unreachable!("clobber-only")
- }
- InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
- InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg_addr) => "a",
- InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg_data) => "d",
- InlineAsmRegClass::CSKY(CSKYInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::CSKY(CSKYInlineAsmRegClass::freg) => "f",
- InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => "d", // more specific than "r"
- InlineAsmRegClass::Mips(MipsInlineAsmRegClass::freg) => "f",
- InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => "r",
- // https://github.com/gcc-mirror/gcc/blob/master/gcc/config/nvptx/nvptx.md -> look for
- // "define_constraint".
- InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => "h",
- InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => "r",
- InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => "l",
- InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
- InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
- InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
- InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
- | InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
- unreachable!("clobber-only")
- }
- InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
- InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
- unreachable!("clobber-only")
- }
- InlineAsmRegClass::X86(X86InlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd) => "Q",
- InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => "q",
- InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg)
- | InlineAsmRegClass::X86(X86InlineAsmRegClass::ymm_reg) => "x",
- InlineAsmRegClass::X86(X86InlineAsmRegClass::zmm_reg) => "v",
- InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg) => "Yk",
- InlineAsmRegClass::X86(
- X86InlineAsmRegClass::kreg0
- | X86InlineAsmRegClass::x87_reg
- | X86InlineAsmRegClass::mmx_reg
- | X86InlineAsmRegClass::tmm_reg,
- ) => unreachable!("clobber-only"),
- InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
- bug!("GCC backend does not support SPIR-V")
- }
- InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
- InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
- InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
- InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg) => "v",
- InlineAsmRegClass::S390x(S390xInlineAsmRegClass::areg) => {
- unreachable!("clobber-only")
- }
- InlineAsmRegClass::Sparc(SparcInlineAsmRegClass::reg) => "r",
- InlineAsmRegClass::Sparc(SparcInlineAsmRegClass::yreg) => unreachable!("clobber-only"),
- InlineAsmRegClass::Err => unreachable!(),
- },
- };
+ _ => unimplemented!(),
+ }
+}
- ConstraintOrRegister::Constraint(constraint)
+/// They can be retrieved from https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
+fn reg_class_to_gcc(reg_class: InlineAsmRegClass) -> &'static str {
+ match reg_class {
+ InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg) => "w",
+ InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => "x",
+ InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
+ unreachable!("clobber-only")
+ }
+ InlineAsmRegClass::Arm(ArmInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg_low16)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg_low8)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg_low16)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg_low8)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg_low4)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::dreg)
+ | InlineAsmRegClass::Arm(ArmInlineAsmRegClass::qreg) => "t",
+ InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_upper) => "d",
+ InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_pair) => "r",
+ InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_iw) => "w",
+ InlineAsmRegClass::Avr(AvrInlineAsmRegClass::reg_ptr) => "e",
+ InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
+ InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
+ unreachable!("clobber-only")
+ }
+ InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
+ InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg_addr) => "a",
+ InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg_data) => "d",
+ InlineAsmRegClass::CSKY(CSKYInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::CSKY(CSKYInlineAsmRegClass::freg) => "f",
+ InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => "d", // more specific than "r"
+ InlineAsmRegClass::Mips(MipsInlineAsmRegClass::freg) => "f",
+ InlineAsmRegClass::Msp430(Msp430InlineAsmRegClass::reg) => "r",
+ // https://github.com/gcc-mirror/gcc/blob/master/gcc/config/nvptx/nvptx.md -> look for
+ // "define_constraint".
+ InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg16) => "h",
+ InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg32) => "r",
+ InlineAsmRegClass::Nvptx(NvptxInlineAsmRegClass::reg64) => "l",
+
+ InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::reg_nonzero) => "b",
+ InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::freg) => "f",
+ InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::vreg) => "v",
+ InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::cr)
+ | InlineAsmRegClass::PowerPC(PowerPCInlineAsmRegClass::xer) => {
+ unreachable!("clobber-only")
+ }
+ InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::freg) => "f",
+ InlineAsmRegClass::RiscV(RiscVInlineAsmRegClass::vreg) => {
+ unreachable!("clobber-only")
+ }
+ InlineAsmRegClass::X86(X86InlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd) => "Q",
+ InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_byte) => "q",
+ InlineAsmRegClass::X86(X86InlineAsmRegClass::xmm_reg)
+ | InlineAsmRegClass::X86(X86InlineAsmRegClass::ymm_reg) => "x",
+ InlineAsmRegClass::X86(X86InlineAsmRegClass::zmm_reg) => "v",
+ InlineAsmRegClass::X86(X86InlineAsmRegClass::kreg) => "Yk",
+ InlineAsmRegClass::X86(
+ X86InlineAsmRegClass::kreg0
+ | X86InlineAsmRegClass::x87_reg
+ | X86InlineAsmRegClass::mmx_reg
+ | X86InlineAsmRegClass::tmm_reg,
+ ) => unreachable!("clobber-only"),
+ InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => {
+ bug!("GCC backend does not support SPIR-V")
+ }
+ InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r",
+ InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg_addr) => "a",
+ InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f",
+ InlineAsmRegClass::S390x(S390xInlineAsmRegClass::vreg) => "v",
+ InlineAsmRegClass::S390x(S390xInlineAsmRegClass::areg) => {
+ unreachable!("clobber-only")
+ }
+ InlineAsmRegClass::Sparc(SparcInlineAsmRegClass::reg) => "r",
+ InlineAsmRegClass::Sparc(SparcInlineAsmRegClass::yreg) => unreachable!("clobber-only"),
+ InlineAsmRegClass::Err => unreachable!(),
+ }
}
/// Type to use for outputs that are discarded. It doesn't really matter what
diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs
index 6573b5b..5c70f4a 100644
--- a/compiler/rustc_codegen_gcc/src/builder.rs
+++ b/compiler/rustc_codegen_gcc/src/builder.rs
@@ -368,16 +368,8 @@ fn function_ptr_call(
let previous_arg_count = args.len();
let orig_args = args;
let args = {
- let function_address_names = self.function_address_names.borrow();
- let original_function_name = function_address_names.get(&func_ptr);
func_ptr = llvm::adjust_function(self.context, &func_name, func_ptr, args);
- llvm::adjust_intrinsic_arguments(
- self,
- gcc_func,
- args.into(),
- &func_name,
- original_function_name,
- )
+ llvm::adjust_intrinsic_arguments(self, gcc_func, args.into(), &func_name)
};
let args_adjusted = args.len() != previous_arg_count;
let args = self.check_ptr_call("call", func_ptr, &args);
@@ -1271,7 +1263,50 @@ fn icmp(&mut self, op: IntPredicate, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RV
}
fn fcmp(&mut self, op: RealPredicate, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
- self.context.new_comparison(self.location, op.to_gcc_comparison(), lhs, rhs)
+ // LLVM has a concept of "unordered compares", where eg ULT returns true if either the two
+ // arguments are unordered (i.e. either is NaN), or the lhs is less than the rhs. GCC does
+ // not natively have this concept, so in some cases we must manually handle NaNs
+ let must_handle_nan = match op {
+ RealPredicate::RealPredicateFalse => unreachable!(),
+ RealPredicate::RealOEQ => false,
+ RealPredicate::RealOGT => false,
+ RealPredicate::RealOGE => false,
+ RealPredicate::RealOLT => false,
+ RealPredicate::RealOLE => false,
+ RealPredicate::RealONE => false,
+ RealPredicate::RealORD => unreachable!(),
+ RealPredicate::RealUNO => unreachable!(),
+ RealPredicate::RealUEQ => false,
+ RealPredicate::RealUGT => true,
+ RealPredicate::RealUGE => true,
+ RealPredicate::RealULT => true,
+ RealPredicate::RealULE => true,
+ RealPredicate::RealUNE => false,
+ RealPredicate::RealPredicateTrue => unreachable!(),
+ };
+
+ let cmp = self.context.new_comparison(self.location, op.to_gcc_comparison(), lhs, rhs);
+
+ if must_handle_nan {
+ let is_nan = self.context.new_binary_op(
+ self.location,
+ BinaryOp::LogicalOr,
+ self.cx.bool_type,
+ // compare a value to itself to check whether it is NaN
+ self.context.new_comparison(self.location, ComparisonOp::NotEquals, lhs, lhs),
+ self.context.new_comparison(self.location, ComparisonOp::NotEquals, rhs, rhs),
+ );
+
+ self.context.new_binary_op(
+ self.location,
+ BinaryOp::LogicalOr,
+ self.cx.bool_type,
+ is_nan,
+ cmp,
+ )
+ } else {
+ cmp
+ }
}
/* Miscellaneous instructions */
diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs
index 1e1f577..7371899 100644
--- a/compiler/rustc_codegen_gcc/src/context.rs
+++ b/compiler/rustc_codegen_gcc/src/context.rs
@@ -23,6 +23,8 @@
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, TlsModel, WasmCAbi, X86Abi,
};
+#[cfg(feature = "master")]
+use crate::abi::conv_to_fn_attribute;
use crate::callee::get_fn;
use crate::common::SignType;
@@ -213,33 +215,7 @@ pub fn new(
let bool_type = context.new_type::<bool>();
let mut functions = FxHashMap::default();
- let builtins = [
- "__builtin_unreachable",
- "abort",
- "__builtin_expect", /*"__builtin_expect_with_probability",*/
- "__builtin_constant_p",
- "__builtin_add_overflow",
- "__builtin_mul_overflow",
- "__builtin_saddll_overflow",
- /*"__builtin_sadd_overflow",*/
- "__builtin_smulll_overflow", /*"__builtin_smul_overflow",*/
- "__builtin_ssubll_overflow",
- /*"__builtin_ssub_overflow",*/ "__builtin_sub_overflow",
- "__builtin_uaddll_overflow",
- "__builtin_uadd_overflow",
- "__builtin_umulll_overflow",
- "__builtin_umul_overflow",
- "__builtin_usubll_overflow",
- "__builtin_usub_overflow",
- "__builtin_powif",
- "__builtin_powi",
- "fabsf",
- "fabs",
- "copysignf",
- "copysign",
- "nearbyintf",
- "nearbyint",
- ];
+ let builtins = ["abort"];
for builtin in builtins.iter() {
functions.insert(builtin.to_string(), context.get_builtin_function(builtin));
@@ -509,7 +485,11 @@ fn apply_target_cpu_attr(&self, _llfn: RValue<'gcc>) {
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
let entry_name = self.sess().target.entry_name.as_ref();
if !self.functions.borrow().contains_key(entry_name) {
- Some(self.declare_entry_fn(entry_name, fn_type, ()))
+ #[cfg(feature = "master")]
+ let conv = conv_to_fn_attribute(self.sess().target.entry_abi, &self.sess().target.arch);
+ #[cfg(not(feature = "master"))]
+ let conv = None;
+ Some(self.declare_entry_fn(entry_name, fn_type, conv))
} else {
// If the symbol already exists, it is an error: for example, the user wrote
// #[no_mangle] extern "C" fn main(..) {..}
@@ -605,7 +585,10 @@ pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
let mut name = String::with_capacity(prefix.len() + 6);
name.push_str(prefix);
name.push('.');
- name.push_str(&(idx as u64).to_base(ALPHANUMERIC_ONLY));
+ // Offset the index by the base so that always at least two characters
+ // are generated. This avoids cases where the suffix is interpreted as
+ // size by the assembler (for m68k: .b, .w, .l).
+ name.push_str(&(idx as u64 + ALPHANUMERIC_ONLY as u64).to_base(ALPHANUMERIC_ONLY));
name
}
}
diff --git a/compiler/rustc_codegen_gcc/src/declare.rs b/compiler/rustc_codegen_gcc/src/declare.rs
index 7cdbe3c..c1ca3eb 100644
--- a/compiler/rustc_codegen_gcc/src/declare.rs
+++ b/compiler/rustc_codegen_gcc/src/declare.rs
@@ -58,7 +58,7 @@ pub fn declare_func(
variadic: bool,
) -> Function<'gcc> {
self.linkage.set(FunctionType::Extern);
- declare_raw_fn(self, name, () /*llvm::CCallConv*/, return_type, params, variadic)
+ declare_raw_fn(self, name, None, return_type, params, variadic)
}
pub fn declare_global(
@@ -92,7 +92,8 @@ pub fn declare_entry_fn(
&self,
name: &str,
_fn_type: Type<'gcc>,
- callconv: (), /*llvm::CCallConv*/
+ #[cfg(feature = "master")] callconv: Option<FnAttribute<'gcc>>,
+ #[cfg(not(feature = "master"))] callconv: Option<()>,
) -> RValue<'gcc> {
// TODO(antoyo): use the fn_type parameter.
let const_string = self.context.new_type::<u8>().make_pointer().make_pointer();
@@ -123,14 +124,11 @@ pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function
#[cfg(feature = "master")]
fn_attributes,
} = fn_abi.gcc_type(self);
- let func = declare_raw_fn(
- self,
- name,
- (), /*fn_abi.llvm_cconv()*/
- return_type,
- &arguments_type,
- is_c_variadic,
- );
+ #[cfg(feature = "master")]
+ let conv = fn_abi.gcc_cconv(self);
+ #[cfg(not(feature = "master"))]
+ let conv = None;
+ let func = declare_raw_fn(self, name, conv, return_type, &arguments_type, is_c_variadic);
self.on_stack_function_params.borrow_mut().insert(func, on_stack_param_indices);
#[cfg(feature = "master")]
for fn_attr in fn_attributes {
@@ -162,7 +160,8 @@ pub fn get_declared_value(&self, name: &str) -> Option<RValue<'gcc>> {
fn declare_raw_fn<'gcc>(
cx: &CodegenCx<'gcc, '_>,
name: &str,
- _callconv: (), /*llvm::CallConv*/
+ #[cfg(feature = "master")] callconv: Option<FnAttribute<'gcc>>,
+ #[cfg(not(feature = "master"))] _callconv: Option<()>,
return_type: Type<'gcc>,
param_types: &[Type<'gcc>],
variadic: bool,
@@ -192,6 +191,10 @@ fn declare_raw_fn<'gcc>(
let name = &mangle_name(name);
let func =
cx.context.new_function(None, cx.linkage.get(), return_type, ¶ms, name, variadic);
+ #[cfg(feature = "master")]
+ if let Some(attribute) = callconv {
+ func.add_attribute(attribute);
+ }
cx.functions.borrow_mut().insert(name.to_string(), func);
#[cfg(feature = "master")]
diff --git a/compiler/rustc_codegen_gcc/src/gcc_util.rs b/compiler/rustc_codegen_gcc/src/gcc_util.rs
index 6eae0c2..202764d 100644
--- a/compiler/rustc_codegen_gcc/src/gcc_util.rs
+++ b/compiler/rustc_codegen_gcc/src/gcc_util.rs
@@ -194,6 +194,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
fn arch_to_gcc(name: &str) -> &str {
match name {
+ "M68000" => "68000",
"M68020" => "68020",
_ => name,
}
diff --git a/compiler/rustc_codegen_gcc/src/int.rs b/compiler/rustc_codegen_gcc/src/int.rs
index f3552d9..9b5b0fd 100644
--- a/compiler/rustc_codegen_gcc/src/int.rs
+++ b/compiler/rustc_codegen_gcc/src/int.rs
@@ -404,7 +404,7 @@ pub fn operation_with_overflow(
let ret_indirect = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
- let result = if ret_indirect {
+ let call = if ret_indirect {
let res_value = self.current_func().new_local(self.location, res_type, "result_value");
let res_addr = res_value.get_address(self.location);
let res_param_type = res_type.make_pointer();
@@ -432,8 +432,17 @@ pub fn operation_with_overflow(
);
self.context.new_call(self.location, func, &[lhs, rhs, overflow_addr])
};
+ // NOTE: we must assign the result of the operation to a variable at this point to make
+ // sure it will be evaluated by libgccjit now.
+ // Otherwise, it will only be evaluated when the rvalue for the call is used somewhere else
+ // and overflow_value will not be initialized at the correct point in the program.
+ let result = self.current_func().new_local(self.location, res_type, "result");
+ self.block.add_assignment(self.location, result, call);
- (result, self.context.new_cast(self.location, overflow_value, self.bool_type).to_rvalue())
+ (
+ result.to_rvalue(),
+ self.context.new_cast(self.location, overflow_value, self.bool_type).to_rvalue(),
+ )
}
pub fn gcc_icmp(
@@ -865,6 +874,7 @@ pub fn gcc_int_cast(&self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<
let value_type = value.get_type();
if self.is_native_int_type_or_bool(dest_typ) && self.is_native_int_type_or_bool(value_type)
{
+ // TODO: use self.location.
self.context.new_cast(None, value, dest_typ)
} else if self.is_native_int_type_or_bool(dest_typ) {
self.context.new_cast(None, self.low(value), dest_typ)
@@ -905,6 +915,7 @@ fn int_to_float_cast(
let name_suffix = match self.type_kind(dest_typ) {
TypeKind::Float => "tisf",
TypeKind::Double => "tidf",
+ TypeKind::FP128 => "tixf",
kind => panic!("cannot cast a non-native integer to type {:?}", kind),
};
let sign = if signed { "" } else { "un" };
diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs b/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs
index 2d731f8..0eebd21 100644
--- a/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs
+++ b/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs
@@ -1,11 +1,90 @@
use std::borrow::Cow;
-use gccjit::{CType, Context, Function, FunctionPtrType, RValue, ToRValue, UnaryOp};
+use gccjit::{CType, Context, Field, Function, FunctionPtrType, RValue, ToRValue, Type};
use rustc_codegen_ssa::traits::BuilderMethods;
use crate::builder::Builder;
use crate::context::CodegenCx;
+fn encode_key_128_type<'a, 'gcc, 'tcx>(
+ builder: &Builder<'a, 'gcc, 'tcx>,
+) -> (Type<'gcc>, Field<'gcc>, Field<'gcc>) {
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let field1 = builder.context.new_field(None, builder.u32_type, "field1");
+ let field2 = builder.context.new_field(None, m128i, "field2");
+ let field3 = builder.context.new_field(None, m128i, "field3");
+ let field4 = builder.context.new_field(None, m128i, "field4");
+ let field5 = builder.context.new_field(None, m128i, "field5");
+ let field6 = builder.context.new_field(None, m128i, "field6");
+ let field7 = builder.context.new_field(None, m128i, "field7");
+ let encode_type = builder.context.new_struct_type(
+ None,
+ "EncodeKey128Output",
+ &[field1, field2, field3, field4, field5, field6, field7],
+ );
+ #[cfg(feature = "master")]
+ encode_type.as_type().set_packed();
+ (encode_type.as_type(), field1, field2)
+}
+
+fn encode_key_256_type<'a, 'gcc, 'tcx>(
+ builder: &Builder<'a, 'gcc, 'tcx>,
+) -> (Type<'gcc>, Field<'gcc>, Field<'gcc>) {
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let field1 = builder.context.new_field(None, builder.u32_type, "field1");
+ let field2 = builder.context.new_field(None, m128i, "field2");
+ let field3 = builder.context.new_field(None, m128i, "field3");
+ let field4 = builder.context.new_field(None, m128i, "field4");
+ let field5 = builder.context.new_field(None, m128i, "field5");
+ let field6 = builder.context.new_field(None, m128i, "field6");
+ let field7 = builder.context.new_field(None, m128i, "field7");
+ let field8 = builder.context.new_field(None, m128i, "field8");
+ let encode_type = builder.context.new_struct_type(
+ None,
+ "EncodeKey256Output",
+ &[field1, field2, field3, field4, field5, field6, field7, field8],
+ );
+ #[cfg(feature = "master")]
+ encode_type.as_type().set_packed();
+ (encode_type.as_type(), field1, field2)
+}
+
+fn aes_output_type<'a, 'gcc, 'tcx>(
+ builder: &Builder<'a, 'gcc, 'tcx>,
+) -> (Type<'gcc>, Field<'gcc>, Field<'gcc>) {
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let field1 = builder.context.new_field(None, builder.u8_type, "field1");
+ let field2 = builder.context.new_field(None, m128i, "field2");
+ let aes_output_type = builder.context.new_struct_type(None, "AesOutput", &[field1, field2]);
+ let typ = aes_output_type.as_type();
+ #[cfg(feature = "master")]
+ typ.set_packed();
+ (typ, field1, field2)
+}
+
+fn wide_aes_output_type<'a, 'gcc, 'tcx>(
+ builder: &Builder<'a, 'gcc, 'tcx>,
+) -> (Type<'gcc>, Field<'gcc>, Field<'gcc>) {
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let field1 = builder.context.new_field(None, builder.u8_type, "field1");
+ let field2 = builder.context.new_field(None, m128i, "field2");
+ let field3 = builder.context.new_field(None, m128i, "field3");
+ let field4 = builder.context.new_field(None, m128i, "field4");
+ let field5 = builder.context.new_field(None, m128i, "field5");
+ let field6 = builder.context.new_field(None, m128i, "field6");
+ let field7 = builder.context.new_field(None, m128i, "field7");
+ let field8 = builder.context.new_field(None, m128i, "field8");
+ let field9 = builder.context.new_field(None, m128i, "field9");
+ let aes_output_type = builder.context.new_struct_type(
+ None,
+ "WideAesOutput",
+ &[field1, field2, field3, field4, field5, field6, field7, field8, field9],
+ );
+ #[cfg(feature = "master")]
+ aes_output_type.as_type().set_packed();
+ (aes_output_type.as_type(), field1, field2)
+}
+
#[cfg_attr(not(feature = "master"), allow(unused_variables))]
pub fn adjust_function<'gcc>(
context: &'gcc Context<'gcc>,
@@ -43,7 +122,6 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
gcc_func: FunctionPtrType<'gcc>,
mut args: Cow<'b, [RValue<'gcc>]>,
func_name: &str,
- original_function_name: Option<&String>,
) -> Cow<'b, [RValue<'gcc>]> {
// TODO: this might not be a good way to workaround the missing tile builtins.
if func_name == "__builtin_trap" {
@@ -504,6 +582,72 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
let arg4 = builder.context.new_rvalue_from_int(arg4_type, -1);
args = vec![a, b, c, arg4, new_args[3]].into();
}
+ "__builtin_ia32_encodekey128_u32" => {
+ let mut new_args = args.to_vec();
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let array_type = builder.context.new_array_type(None, m128i, 6);
+ let result = builder.current_func().new_local(None, array_type, "result");
+ new_args.push(result.get_address(None));
+ args = new_args.into();
+ }
+ "__builtin_ia32_encodekey256_u32" => {
+ let mut new_args = args.to_vec();
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let array_type = builder.context.new_array_type(None, m128i, 7);
+ let result = builder.current_func().new_local(None, array_type, "result");
+ new_args.push(result.get_address(None));
+ args = new_args.into();
+ }
+ "__builtin_ia32_aesenc128kl_u8"
+ | "__builtin_ia32_aesdec128kl_u8"
+ | "__builtin_ia32_aesenc256kl_u8"
+ | "__builtin_ia32_aesdec256kl_u8" => {
+ let mut new_args = vec![];
+ let m128i = builder.context.new_vector_type(builder.i64_type, 2);
+ let result = builder.current_func().new_local(None, m128i, "result");
+ new_args.push(result.get_address(None));
+ new_args.extend(args.to_vec());
+ args = new_args.into();
+ }
+ "__builtin_ia32_aesencwide128kl_u8"
+ | "__builtin_ia32_aesdecwide128kl_u8"
+ | "__builtin_ia32_aesencwide256kl_u8"
+ | "__builtin_ia32_aesdecwide256kl_u8" => {
+ let mut new_args = vec![];
+
+ let mut old_args = args.to_vec();
+ let handle = old_args.swap_remove(0); // Called __P in GCC.
+ let first_value = old_args.swap_remove(0);
+
+ let element_type = first_value.get_type();
+ let array_type = builder.context.new_array_type(None, element_type, 8);
+ let result = builder.current_func().new_local(None, array_type, "result");
+ new_args.push(result.get_address(None));
+
+ let array = builder.current_func().new_local(None, array_type, "array");
+ let input = builder.context.new_array_constructor(
+ None,
+ array_type,
+ &[
+ first_value,
+ old_args.swap_remove(0),
+ old_args.swap_remove(0),
+ old_args.swap_remove(0),
+ old_args.swap_remove(0),
+ old_args.swap_remove(0),
+ old_args.swap_remove(0),
+ old_args.swap_remove(0),
+ ],
+ );
+ builder.llbb().add_assignment(None, array, input);
+ let input_ptr = array.get_address(None);
+ let arg2_type = gcc_func.get_param_type(1);
+ let input_ptr = builder.context.new_cast(None, input_ptr, arg2_type);
+ new_args.push(input_ptr);
+
+ new_args.push(handle);
+ args = new_args.into();
+ }
_ => (),
}
} else {
@@ -541,33 +685,6 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>(
let c = builder.context.new_rvalue_from_vector(None, arg3_type, &[new_args[2]; 2]);
args = vec![a, b, c, new_args[3]].into();
}
- "__builtin_ia32_vfmaddsubpd256"
- | "__builtin_ia32_vfmaddsubps"
- | "__builtin_ia32_vfmaddsubps256"
- | "__builtin_ia32_vfmaddsubpd" => {
- if let Some(original_function_name) = original_function_name {
- match &**original_function_name {
- "llvm.x86.fma.vfmsubadd.pd.256"
- | "llvm.x86.fma.vfmsubadd.ps"
- | "llvm.x86.fma.vfmsubadd.ps.256"
- | "llvm.x86.fma.vfmsubadd.pd" => {
- // NOTE: since both llvm.x86.fma.vfmsubadd.ps and llvm.x86.fma.vfmaddsub.ps maps to
- // __builtin_ia32_vfmaddsubps, only add minus if this comes from a
- // subadd LLVM intrinsic, e.g. _mm256_fmsubadd_pd.
- let mut new_args = args.to_vec();
- let arg3 = &mut new_args[2];
- *arg3 = builder.context.new_unary_op(
- None,
- UnaryOp::Minus,
- arg3.get_type(),
- *arg3,
- );
- args = new_args.into();
- }
- _ => (),
- }
- }
- }
"__builtin_ia32_ldmxcsr" => {
// The builtin __builtin_ia32_ldmxcsr takes an integer value while llvm.x86.sse.ldmxcsr takes a pointer,
// so dereference the pointer.
@@ -728,6 +845,96 @@ pub fn adjust_intrinsic_return_value<'a, 'gcc, 'tcx>(
let f16_type = builder.context.new_c_type(CType::Float16);
return_value = builder.context.new_cast(None, return_value, f16_type);
}
+ "__builtin_ia32_encodekey128_u32" => {
+ // The builtin __builtin_ia32_encodekey128_u32 writes the result in its pointer argument while
+ // llvm.x86.encodekey128 returns a value.
+ // We added a result pointer argument and now need to assign its value to the return_value expected by
+ // the LLVM intrinsic.
+ let (encode_type, field1, field2) = encode_key_128_type(builder);
+ let result = builder.current_func().new_local(None, encode_type, "result");
+ let field1 = result.access_field(None, field1);
+ builder.llbb().add_assignment(None, field1, return_value);
+ let field2 = result.access_field(None, field2);
+ let field2_type = field2.to_rvalue().get_type();
+ let array_type = builder.context.new_array_type(None, field2_type, 6);
+ let ptr = builder.context.new_cast(None, args[2], array_type.make_pointer());
+ let field2_ptr =
+ builder.context.new_cast(None, field2.get_address(None), array_type.make_pointer());
+ builder.llbb().add_assignment(
+ None,
+ field2_ptr.dereference(None),
+ ptr.dereference(None),
+ );
+ return_value = result.to_rvalue();
+ }
+ "__builtin_ia32_encodekey256_u32" => {
+ // The builtin __builtin_ia32_encodekey256_u32 writes the result in its pointer argument while
+ // llvm.x86.encodekey256 returns a value.
+ // We added a result pointer argument and now need to assign its value to the return_value expected by
+ // the LLVM intrinsic.
+ let (encode_type, field1, field2) = encode_key_256_type(builder);
+ let result = builder.current_func().new_local(None, encode_type, "result");
+ let field1 = result.access_field(None, field1);
+ builder.llbb().add_assignment(None, field1, return_value);
+ let field2 = result.access_field(None, field2);
+ let field2_type = field2.to_rvalue().get_type();
+ let array_type = builder.context.new_array_type(None, field2_type, 7);
+ let ptr = builder.context.new_cast(None, args[3], array_type.make_pointer());
+ let field2_ptr =
+ builder.context.new_cast(None, field2.get_address(None), array_type.make_pointer());
+ builder.llbb().add_assignment(
+ None,
+ field2_ptr.dereference(None),
+ ptr.dereference(None),
+ );
+ return_value = result.to_rvalue();
+ }
+ "__builtin_ia32_aesdec128kl_u8"
+ | "__builtin_ia32_aesenc128kl_u8"
+ | "__builtin_ia32_aesdec256kl_u8"
+ | "__builtin_ia32_aesenc256kl_u8" => {
+ // The builtin for aesdec/aesenc writes the result in its pointer argument while
+ // llvm.x86.aesdec128kl returns a value.
+ // We added a result pointer argument and now need to assign its value to the return_value expected by
+ // the LLVM intrinsic.
+ let (aes_output_type, field1, field2) = aes_output_type(builder);
+ let result = builder.current_func().new_local(None, aes_output_type, "result");
+ let field1 = result.access_field(None, field1);
+ builder.llbb().add_assignment(None, field1, return_value);
+ let field2 = result.access_field(None, field2);
+ let ptr = builder.context.new_cast(
+ None,
+ args[0],
+ field2.to_rvalue().get_type().make_pointer(),
+ );
+ builder.llbb().add_assignment(None, field2, ptr.dereference(None));
+ return_value = result.to_rvalue();
+ }
+ "__builtin_ia32_aesencwide128kl_u8"
+ | "__builtin_ia32_aesdecwide128kl_u8"
+ | "__builtin_ia32_aesencwide256kl_u8"
+ | "__builtin_ia32_aesdecwide256kl_u8" => {
+ // The builtin for aesdecwide/aesencwide writes the result in its pointer argument while
+ // llvm.x86.aesencwide128kl returns a value.
+ // We added a result pointer argument and now need to assign its value to the return_value expected by
+ // the LLVM intrinsic.
+ let (aes_output_type, field1, field2) = wide_aes_output_type(builder);
+ let result = builder.current_func().new_local(None, aes_output_type, "result");
+ let field1 = result.access_field(None, field1);
+ builder.llbb().add_assignment(None, field1, return_value);
+ let field2 = result.access_field(None, field2);
+ let field2_type = field2.to_rvalue().get_type();
+ let array_type = builder.context.new_array_type(None, field2_type, 8);
+ let ptr = builder.context.new_cast(None, args[0], array_type.make_pointer());
+ let field2_ptr =
+ builder.context.new_cast(None, field2.get_address(None), array_type.make_pointer());
+ builder.llbb().add_assignment(
+ None,
+ field2_ptr.dereference(None),
+ ptr.dereference(None),
+ );
+ return_value = result.to_rvalue();
+ }
_ => (),
}
@@ -915,16 +1122,6 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
"llvm.ctlz.v4i64" => "__builtin_ia32_vplzcntq_256_mask",
"llvm.ctlz.v2i64" => "__builtin_ia32_vplzcntq_128_mask",
"llvm.ctpop.v32i16" => "__builtin_ia32_vpopcountw_v32hi",
- "llvm.x86.fma.vfmsub.sd" => "__builtin_ia32_vfmsubsd3",
- "llvm.x86.fma.vfmsub.ss" => "__builtin_ia32_vfmsubss3",
- "llvm.x86.fma.vfmsubadd.pd" => "__builtin_ia32_vfmaddsubpd",
- "llvm.x86.fma.vfmsubadd.pd.256" => "__builtin_ia32_vfmaddsubpd256",
- "llvm.x86.fma.vfmsubadd.ps" => "__builtin_ia32_vfmaddsubps",
- "llvm.x86.fma.vfmsubadd.ps.256" => "__builtin_ia32_vfmaddsubps256",
- "llvm.x86.fma.vfnmadd.sd" => "__builtin_ia32_vfnmaddsd3",
- "llvm.x86.fma.vfnmadd.ss" => "__builtin_ia32_vfnmaddss3",
- "llvm.x86.fma.vfnmsub.sd" => "__builtin_ia32_vfnmsubsd3",
- "llvm.x86.fma.vfnmsub.ss" => "__builtin_ia32_vfnmsubss3",
"llvm.x86.avx512.conflict.d.512" => "__builtin_ia32_vpconflictsi_512_mask",
"llvm.x86.avx512.conflict.d.256" => "__builtin_ia32_vpconflictsi_256_mask",
"llvm.x86.avx512.conflict.d.128" => "__builtin_ia32_vpconflictsi_128_mask",
@@ -1002,8 +1199,6 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
"llvm.fshr.v32i16" => "__builtin_ia32_vpshrdv_v32hi",
"llvm.fshr.v16i16" => "__builtin_ia32_vpshrdv_v16hi",
"llvm.fshr.v8i16" => "__builtin_ia32_vpshrdv_v8hi",
- "llvm.x86.fma.vfmadd.sd" => "__builtin_ia32_vfmaddsd3",
- "llvm.x86.fma.vfmadd.ss" => "__builtin_ia32_vfmaddss3",
"llvm.x86.rdrand.64" => "__builtin_ia32_rdrand64_step",
// The above doc points to unknown builtins for the following, so override them:
@@ -1324,6 +1519,16 @@ pub fn intrinsic<'gcc, 'tcx>(name: &str, cx: &CodegenCx<'gcc, 'tcx>) -> Function
"llvm.x86.avx512fp16.mask.vfmadd.cph.256" => "__builtin_ia32_vfmaddcph256_mask3",
"llvm.x86.avx512fp16.mask.vfcmadd.cph.128" => "__builtin_ia32_vfcmaddcph128_mask3",
"llvm.x86.avx512fp16.mask.vfmadd.cph.128" => "__builtin_ia32_vfmaddcph128_mask3",
+ "llvm.x86.encodekey128" => "__builtin_ia32_encodekey128_u32",
+ "llvm.x86.encodekey256" => "__builtin_ia32_encodekey256_u32",
+ "llvm.x86.aesenc128kl" => "__builtin_ia32_aesenc128kl_u8",
+ "llvm.x86.aesdec128kl" => "__builtin_ia32_aesdec128kl_u8",
+ "llvm.x86.aesenc256kl" => "__builtin_ia32_aesenc256kl_u8",
+ "llvm.x86.aesdec256kl" => "__builtin_ia32_aesdec256kl_u8",
+ "llvm.x86.aesencwide128kl" => "__builtin_ia32_aesencwide128kl_u8",
+ "llvm.x86.aesdecwide128kl" => "__builtin_ia32_aesdecwide128kl_u8",
+ "llvm.x86.aesencwide256kl" => "__builtin_ia32_aesencwide256kl_u8",
+ "llvm.x86.aesdecwide256kl" => "__builtin_ia32_aesdecwide256kl_u8",
// TODO: support the tile builtins:
"llvm.x86.ldtilecfg" => "__builtin_trap",
diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
index f386220..d22f422 100644
--- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
+++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
@@ -78,6 +78,7 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
sym::maxnumf64 => "fmax",
sym::copysignf32 => "copysignf",
sym::copysignf64 => "copysign",
+ sym::copysignf128 => "copysignl",
sym::floorf32 => "floorf",
sym::floorf64 => "floor",
sym::ceilf32 => "ceilf",
diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
index 8b454ab..6d40d52 100644
--- a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
+++ b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
@@ -399,7 +399,7 @@ macro_rules! require_simd {
}
#[cfg(feature = "master")]
- if name == sym::simd_insert {
+ if name == sym::simd_insert || name == sym::simd_insert_dyn {
require!(
in_elem == arg_tys[2],
InvalidMonomorphization::InsertedType {
@@ -410,6 +410,8 @@ macro_rules! require_simd {
out_ty: arg_tys[2]
}
);
+
+ // TODO(antoyo): For simd_insert, check if the index is a constant of the correct size.
let vector = args[0].immediate();
let index = args[1].immediate();
let value = args[2].immediate();
@@ -422,13 +424,15 @@ macro_rules! require_simd {
}
#[cfg(feature = "master")]
- if name == sym::simd_extract {
+ if name == sym::simd_extract || name == sym::simd_extract_dyn {
require!(
ret_ty == in_elem,
InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty }
);
+ // TODO(antoyo): For simd_extract, check if the index is a constant of the correct size.
let vector = args[0].immediate();
- return Ok(bx.context.new_vector_access(None, vector, args[1].immediate()).to_rvalue());
+ let index = args[1].immediate();
+ return Ok(bx.context.new_vector_access(None, vector, index).to_rvalue());
}
if name == sym::simd_select {
diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs
index bfa2317..624fdb4 100644
--- a/compiler/rustc_codegen_gcc/src/lib.rs
+++ b/compiler/rustc_codegen_gcc/src/lib.rs
@@ -188,10 +188,10 @@ fn locale_resource(&self) -> &'static str {
crate::DEFAULT_LOCALE_RESOURCE
}
- fn init(&self, sess: &Session) {
+ fn init(&self, _sess: &Session) {
#[cfg(feature = "master")]
{
- let target_cpu = target_cpu(sess);
+ let target_cpu = target_cpu(_sess);
// Get the second TargetInfo with the correct CPU features by setting the arch.
let context = Context::default();
diff --git a/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt b/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt
index 082958b..499c1a9 100644
--- a/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt
+++ b/compiler/rustc_codegen_gcc/tests/failing-ui-tests.txt
@@ -1,11 +1,9 @@
tests/ui/allocator/no_std-alloc-error-handler-custom.rs
tests/ui/allocator/no_std-alloc-error-handler-default.rs
tests/ui/asm/may_unwind.rs
-tests/ui/asm/x86_64/multiple-clobber-abi.rs
tests/ui/functions-closures/parallel-codegen-closures.rs
tests/ui/linkage-attr/linkage1.rs
tests/ui/lto/dylib-works.rs
-tests/ui/numbers-arithmetic/saturating-float-casts.rs
tests/ui/sepcomp/sepcomp-cci.rs
tests/ui/sepcomp/sepcomp-extern.rs
tests/ui/sepcomp/sepcomp-fns-backwards.rs
@@ -33,7 +31,6 @@
tests/ui/parser/unclosed-delimiter-in-dep.rs
tests/ui/consts/missing_span_in_backtrace.rs
tests/ui/drop/dynamic-drop.rs
-tests/ui/issues/issue-40883.rs
tests/ui/issues/issue-43853.rs
tests/ui/issues/issue-47364.rs
tests/ui/macros/rfc-2011-nicer-assert-messages/assert-without-captures-does-not-create-unnecessary-code.rs
@@ -102,14 +99,12 @@
tests/ui/codegen/equal-pointers-unequal/as-cast/inline1.rs
tests/ui/codegen/equal-pointers-unequal/as-cast/print.rs
tests/ui/codegen/equal-pointers-unequal/as-cast/inline2.rs
-tests/ui/codegen/equal-pointers-unequal/as-cast/print3.rs
tests/ui/codegen/equal-pointers-unequal/as-cast/segfault.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/function.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/basic.rs
tests/ui/codegen/equal-pointers-unequal/as-cast/zero.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline1.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print.rs
-tests/ui/codegen/equal-pointers-unequal/exposed-provenance/print3.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/inline2.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/segfault.rs
tests/ui/codegen/equal-pointers-unequal/exposed-provenance/zero.rs
@@ -117,8 +112,9 @@
tests/ui/codegen/equal-pointers-unequal/strict-provenance/function.rs
tests/ui/codegen/equal-pointers-unequal/strict-provenance/print.rs
tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline1.rs
-tests/ui/codegen/equal-pointers-unequal/strict-provenance/print3.rs
tests/ui/codegen/equal-pointers-unequal/strict-provenance/inline2.rs
tests/ui/codegen/equal-pointers-unequal/strict-provenance/segfault.rs
tests/ui/codegen/equal-pointers-unequal/strict-provenance/zero.rs
tests/ui/simd/simd-bitmask-notpow2.rs
+tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs
+tests/ui/uninhabited/uninhabited-transparent-return-abi.rs
diff --git a/compiler/rustc_codegen_gcc/tests/run/abort1.rs b/compiler/rustc_codegen_gcc/tests/run/abort1.rs
index fe46d9a..ff2bb75 100644
--- a/compiler/rustc_codegen_gcc/tests/run/abort1.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/abort1.rs
@@ -3,45 +3,13 @@
// Run-time:
// status: signal
-#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-mod intrinsics {
- use super::Sized;
-
- #[rustc_nounwind]
- #[rustc_intrinsic]
- pub fn abort() -> !;
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
fn test_fail() -> ! {
unsafe { intrinsics::abort() };
diff --git a/compiler/rustc_codegen_gcc/tests/run/abort2.rs b/compiler/rustc_codegen_gcc/tests/run/abort2.rs
index 4123f4f..781f518 100644
--- a/compiler/rustc_codegen_gcc/tests/run/abort2.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/abort2.rs
@@ -3,45 +3,13 @@
// Run-time:
// status: signal
-#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-mod intrinsics {
- use super::Sized;
-
- #[rustc_nounwind]
- #[rustc_intrinsic]
- pub fn abort() -> !;
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
fn fail() -> i32 {
unsafe { intrinsics::abort() };
diff --git a/compiler/rustc_codegen_gcc/tests/run/array.rs b/compiler/rustc_codegen_gcc/tests/run/array.rs
index e18a4ce..3ab0c30 100644
--- a/compiler/rustc_codegen_gcc/tests/run/array.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/array.rs
@@ -8,20 +8,12 @@
// 10
#![feature(no_core)]
-
#![no_std]
#![no_core]
#![no_main]
extern crate mini_core;
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- pub fn puts(s: *const u8) -> i32;
- }
-}
+use mini_core::*;
static mut ONE: usize = 1;
diff --git a/compiler/rustc_codegen_gcc/tests/run/asm.rs b/compiler/rustc_codegen_gcc/tests/run/asm.rs
index 4e05d02..2dbf43b 100644
--- a/compiler/rustc_codegen_gcc/tests/run/asm.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/asm.rs
@@ -174,6 +174,59 @@ extern "C" fn foo() -> u64 {
mem_cpy(array2.as_mut_ptr(), array1.as_ptr(), 3);
}
assert_eq!(array1, array2);
+
+ // in and clobber registers cannot overlap. This tests that the lateout register without an
+ // output place (indicated by the `_`) is not added to the list of clobbered registers
+ let x = 8;
+ let y: i32;
+ unsafe {
+ asm!(
+ "mov rax, rdi",
+ in("rdi") x,
+ lateout("rdi") _,
+ out("rax") y,
+ );
+ }
+ assert_eq!((x, y), (8, 8));
+
+ // sysv64 is the default calling convention on unix systems. The rdi register is
+ // used to pass arguments in the sysv64 calling convention, so this register will be clobbered
+ #[cfg(unix)]
+ {
+ let x = 16;
+ let y: i32;
+ unsafe {
+ asm!(
+ "mov rax, rdi",
+ in("rdi") x,
+ out("rax") y,
+ clobber_abi("sysv64"),
+ );
+ }
+ assert_eq!((x, y), (16, 16));
+ }
+
+ // the `b` suffix for registers in the `reg_byte` register class is not supported in GCC
+ // and needs to be stripped in order to use these registers.
+ unsafe {
+ core::arch::asm!(
+ "",
+ out("al") _,
+ out("bl") _,
+ out("cl") _,
+ out("dl") _,
+ out("sil") _,
+ out("dil") _,
+ out("r8b") _,
+ out("r9b") _,
+ out("r10b") _,
+ out("r11b") _,
+ out("r12b") _,
+ out("r13b") _,
+ out("r14b") _,
+ out("r15b") _,
+ );
+ }
}
#[cfg(not(target_arch = "x86_64"))]
diff --git a/compiler/rustc_codegen_gcc/tests/run/assign.rs b/compiler/rustc_codegen_gcc/tests/run/assign.rs
index 2861558..4535ab5 100644
--- a/compiler/rustc_codegen_gcc/tests/run/assign.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/assign.rs
@@ -5,130 +5,13 @@
// 7 8
// 10
-#![allow(internal_features, unused_attributes)]
-#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs, track_caller)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-impl Copy for *mut i32 {}
-impl Copy for usize {}
-impl Copy for u8 {}
-impl Copy for i8 {}
-impl Copy for i32 {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-#[lang = "panic_location"]
-struct PanicLocation {
- file: &'static str,
- line: u32,
- column: u32,
-}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn puts(s: *const u8) -> i32;
- pub fn fflush(stream: *mut i32) -> i32;
- pub fn printf(format: *const i8, ...) -> i32;
-
- pub static stdout: *mut i32;
- }
-}
-
-mod intrinsics {
- #[rustc_nounwind]
- #[rustc_intrinsic]
- pub fn abort() -> !;
-}
-
-#[lang = "panic"]
-#[track_caller]
-#[no_mangle]
-pub fn panic(_msg: &'static str) -> ! {
- unsafe {
- libc::puts("Panicking\0" as *const str as *const u8);
- libc::fflush(libc::stdout);
- intrinsics::abort();
- }
-}
-
-#[lang = "add"]
-trait Add<RHS = Self> {
- type Output;
-
- fn add(self, rhs: RHS) -> Self::Output;
-}
-
-impl Add for u8 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for i8 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for i32 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for usize {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for isize {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-#[track_caller]
-#[lang = "panic_const_add_overflow"]
-pub fn panic_const_add_overflow() -> ! {
- panic("attempt to add with overflow");
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
fn inc_ref(num: &mut isize) -> isize {
*num = *num + 5;
@@ -139,9 +22,8 @@ fn inc(num: isize) -> isize {
num + 1
}
-
#[no_mangle]
-extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
+extern "C" fn main(mut argc: isize, _argv: *const *const u8) -> i32 {
argc = inc(argc);
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, argc);
diff --git a/compiler/rustc_codegen_gcc/tests/run/closure.rs b/compiler/rustc_codegen_gcc/tests/run/closure.rs
index c7a236f..a8a3fad 100644
--- a/compiler/rustc_codegen_gcc/tests/run/closure.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/closure.rs
@@ -9,55 +9,38 @@
// Both args: 11
#![feature(no_core)]
-
#![no_std]
#![no_core]
#![no_main]
extern crate mini_core;
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
+use mini_core::*;
#[no_mangle]
-extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
+extern "C" fn main(argc: isize, _argv: *const *const u8) -> i32 {
let string = "Arg: %d\n\0";
- let mut closure = || {
- unsafe {
- libc::printf(string as *const str as *const i8, argc);
- }
+ let mut closure = || unsafe {
+ libc::printf(string as *const str as *const i8, argc);
};
closure();
- let mut closure = || {
- unsafe {
- libc::printf("Argument: %d\n\0" as *const str as *const i8, argc);
- }
+ let mut closure = || unsafe {
+ libc::printf("Argument: %d\n\0" as *const str as *const i8, argc);
};
closure();
- let mut closure = |string| {
- unsafe {
- libc::printf(string as *const str as *const i8, argc);
- }
+ let mut closure = |string| unsafe {
+ libc::printf(string as *const str as *const i8, argc);
};
closure("String arg: %d\n\0");
- let mut closure = |arg: isize| {
- unsafe {
- libc::printf("Int argument: %d\n\0" as *const str as *const i8, arg);
- }
+ let mut closure = |arg: isize| unsafe {
+ libc::printf("Int argument: %d\n\0" as *const str as *const i8, arg);
};
closure(argc + 1);
- let mut closure = |string, arg: isize| {
- unsafe {
- libc::printf(string as *const str as *const i8, arg);
- }
+ let mut closure = |string, arg: isize| unsafe {
+ libc::printf(string as *const str as *const i8, arg);
};
closure("Both args: %d\n\0", argc + 10);
diff --git a/compiler/rustc_codegen_gcc/tests/run/condition.rs b/compiler/rustc_codegen_gcc/tests/run/condition.rs
index b023597..bd3b6f7 100644
--- a/compiler/rustc_codegen_gcc/tests/run/condition.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/condition.rs
@@ -6,19 +6,12 @@
// 1
#![feature(no_core)]
-
#![no_std]
#![no_core]
#![no_main]
extern crate mini_core;
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
+use mini_core::*;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
@@ -27,15 +20,14 @@ extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
libc::printf(b"true\n\0" as *const u8 as *const i8);
}
- let string =
- match argc {
- 1 => b"1\n\0",
- 2 => b"2\n\0",
- 3 => b"3\n\0",
- 4 => b"4\n\0",
- 5 => b"5\n\0",
- _ => b"_\n\0",
- };
+ let string = match argc {
+ 1 => b"1\n\0",
+ 2 => b"2\n\0",
+ 3 => b"3\n\0",
+ 4 => b"4\n\0",
+ 5 => b"5\n\0",
+ _ => b"_\n\0",
+ };
libc::printf(string as *const u8 as *const i8);
}
0
diff --git a/compiler/rustc_codegen_gcc/tests/run/empty_main.rs b/compiler/rustc_codegen_gcc/tests/run/empty_main.rs
index 042e440..fe3df5a 100644
--- a/compiler/rustc_codegen_gcc/tests/run/empty_main.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/empty_main.rs
@@ -3,37 +3,13 @@
// Run-time:
// status: 0
-#![feature(auto_traits, lang_items, no_core)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
diff --git a/compiler/rustc_codegen_gcc/tests/run/exit.rs b/compiler/rustc_codegen_gcc/tests/run/exit.rs
index 9a7c91c..e0a5917 100644
--- a/compiler/rustc_codegen_gcc/tests/run/exit.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/exit.rs
@@ -3,44 +3,13 @@
// Run-time:
// status: 2
-#![feature(auto_traits, lang_items, no_core, intrinsics)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn exit(status: i32);
- }
-}
-
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
diff --git a/compiler/rustc_codegen_gcc/tests/run/exit_code.rs b/compiler/rustc_codegen_gcc/tests/run/exit_code.rs
index c50d2b0..376824d 100644
--- a/compiler/rustc_codegen_gcc/tests/run/exit_code.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/exit_code.rs
@@ -3,37 +3,13 @@
// Run-time:
// status: 1
-#![feature(auto_traits, lang_items, no_core)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
diff --git a/compiler/rustc_codegen_gcc/tests/run/float.rs b/compiler/rustc_codegen_gcc/tests/run/float.rs
new file mode 100644
index 0000000..424fa1c
--- /dev/null
+++ b/compiler/rustc_codegen_gcc/tests/run/float.rs
@@ -0,0 +1,28 @@
+// Compiler:
+//
+// Run-time:
+// status: 0
+
+#![feature(const_black_box)]
+
+fn main() {
+ use std::hint::black_box;
+
+ macro_rules! check {
+ ($ty:ty, $expr:expr) => {{
+ const EXPECTED: $ty = $expr;
+ assert_eq!($expr, EXPECTED);
+ }};
+ }
+
+ check!(i32, (black_box(0.0f32) as i32));
+
+ check!(u64, (black_box(f32::NAN) as u64));
+ check!(u128, (black_box(f32::NAN) as u128));
+
+ check!(i64, (black_box(f64::NAN) as i64));
+ check!(u64, (black_box(f64::NAN) as u64));
+
+ check!(i16, (black_box(f32::MIN) as i16));
+ check!(i16, (black_box(f32::MAX) as i16));
+}
diff --git a/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs b/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs
index 98b351e..93b9bae 100644
--- a/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs
@@ -5,19 +5,12 @@
// stdout: 1
#![feature(no_core)]
-
#![no_std]
#![no_core]
#![no_main]
extern crate mini_core;
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
+use mini_core::*;
fn i16_as_i8(a: i16) -> i8 {
a as i8
diff --git a/compiler/rustc_codegen_gcc/tests/run/int.rs b/compiler/rustc_codegen_gcc/tests/run/int.rs
index 58a2680..47b5dea 100644
--- a/compiler/rustc_codegen_gcc/tests/run/int.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/int.rs
@@ -3,9 +3,7 @@
// Run-time:
// status: 0
-/*
- * Code
- */
+#![feature(const_black_box)]
fn main() {
use std::hint::black_box;
diff --git a/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs b/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs
index b021586..fa50d5b 100644
--- a/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs
@@ -1,4 +1,3 @@
-
// Compiler:
//
// Run-time:
@@ -7,139 +6,20 @@
// 6
// 11
-#![allow(internal_features, unused_attributes)]
-#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs, track_caller)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-impl Copy for *mut i32 {}
-impl Copy for usize {}
-impl Copy for u8 {}
-impl Copy for i8 {}
-impl Copy for i32 {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-#[lang = "panic_location"]
-struct PanicLocation {
- file: &'static str,
- line: u32,
- column: u32,
-}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn puts(s: *const u8) -> i32;
- pub fn fflush(stream: *mut i32) -> i32;
- pub fn printf(format: *const i8, ...) -> i32;
-
- pub static stdout: *mut i32;
- }
-}
-
-mod intrinsics {
- #[rustc_nounwind]
- #[rustc_intrinsic]
- pub fn abort() -> !;
-}
-
-#[lang = "panic"]
-#[track_caller]
-#[no_mangle]
-pub fn panic(_msg: &'static str) -> ! {
- unsafe {
- libc::puts("Panicking\0" as *const str as *const u8);
- libc::fflush(libc::stdout);
- intrinsics::abort();
- }
-}
-
-#[lang = "add"]
-trait Add<RHS = Self> {
- type Output;
-
- fn add(self, rhs: RHS) -> Self::Output;
-}
-
-impl Add for u8 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for i8 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for i32 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for usize {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for isize {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-#[track_caller]
-#[lang = "panic_const_add_overflow"]
-pub fn panic_const_add_overflow() -> ! {
- panic("attempt to add with overflow");
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
struct Test {
field: isize,
}
fn test(num: isize) -> Test {
- Test {
- field: num + 1,
- }
+ Test { field: num + 1 }
}
fn update_num(num: &mut isize) {
@@ -147,7 +27,7 @@ fn update_num(num: &mut isize) {
}
#[no_mangle]
-extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
+extern "C" fn main(mut argc: isize, _argv: *const *const u8) -> i32 {
let mut test = test(argc);
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, test.field);
diff --git a/compiler/rustc_codegen_gcc/tests/run/operations.rs b/compiler/rustc_codegen_gcc/tests/run/operations.rs
index 8ba7a4c..a1b0772 100644
--- a/compiler/rustc_codegen_gcc/tests/run/operations.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/operations.rs
@@ -5,229 +5,13 @@
// 39
// 10
-#![allow(internal_features, unused_attributes)]
-#![feature(auto_traits, lang_items, no_core, intrinsics, arbitrary_self_types, rustc_attrs)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-impl Copy for *mut i32 {}
-impl Copy for usize {}
-impl Copy for u8 {}
-impl Copy for i8 {}
-impl Copy for i16 {}
-impl Copy for i32 {}
-
-#[lang = "deref"]
-pub trait Deref {
- type Target: ?Sized;
-
- fn deref(&self) -> &Self::Target;
-}
-
-#[lang = "legacy_receiver"]
-trait LegacyReceiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-#[lang = "panic_location"]
-struct PanicLocation {
- file: &'static str,
- line: u32,
- column: u32,
-}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- pub fn puts(s: *const u8) -> i32;
- pub fn fflush(stream: *mut i32) -> i32;
-
- pub static stdout: *mut i32;
- }
-}
-
-mod intrinsics {
- #[rustc_nounwind]
- #[rustc_intrinsic]
- pub fn abort() -> !;
-}
-
-#[lang = "panic"]
-#[track_caller]
-#[no_mangle]
-pub fn panic(_msg: &'static str) -> ! {
- unsafe {
- libc::puts("Panicking\0" as *const str as *const u8);
- libc::fflush(libc::stdout);
- intrinsics::abort();
- }
-}
-
-#[lang = "add"]
-trait Add<RHS = Self> {
- type Output;
-
- fn add(self, rhs: RHS) -> Self::Output;
-}
-
-impl Add for u8 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for i8 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for i32 {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for usize {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-impl Add for isize {
- type Output = Self;
-
- fn add(self, rhs: Self) -> Self {
- self + rhs
- }
-}
-
-#[lang = "sub"]
-pub trait Sub<RHS = Self> {
- type Output;
-
- fn sub(self, rhs: RHS) -> Self::Output;
-}
-
-impl Sub for usize {
- type Output = Self;
-
- fn sub(self, rhs: Self) -> Self {
- self - rhs
- }
-}
-
-impl Sub for isize {
- type Output = Self;
-
- fn sub(self, rhs: Self) -> Self {
- self - rhs
- }
-}
-
-impl Sub for u8 {
- type Output = Self;
-
- fn sub(self, rhs: Self) -> Self {
- self - rhs
- }
-}
-
-impl Sub for i8 {
- type Output = Self;
-
- fn sub(self, rhs: Self) -> Self {
- self - rhs
- }
-}
-
-impl Sub for i16 {
- type Output = Self;
-
- fn sub(self, rhs: Self) -> Self {
- self - rhs
- }
-}
-
-#[lang = "mul"]
-pub trait Mul<RHS = Self> {
- type Output;
-
- #[must_use]
- fn mul(self, rhs: RHS) -> Self::Output;
-}
-
-impl Mul for u8 {
- type Output = Self;
-
- fn mul(self, rhs: Self) -> Self::Output {
- self * rhs
- }
-}
-
-impl Mul for usize {
- type Output = Self;
-
- fn mul(self, rhs: Self) -> Self::Output {
- self * rhs
- }
-}
-
-impl Mul for isize {
- type Output = Self;
-
- fn mul(self, rhs: Self) -> Self::Output {
- self * rhs
- }
-}
-
-#[track_caller]
-#[lang = "panic_const_add_overflow"]
-pub fn panic_const_add_overflow() -> ! {
- panic("attempt to add with overflow");
-}
-
-#[track_caller]
-#[lang = "panic_const_sub_overflow"]
-pub fn panic_const_sub_overflow() -> ! {
- panic("attempt to subtract with overflow");
-}
-
-#[track_caller]
-#[lang = "panic_const_mul_overflow"]
-pub fn panic_const_mul_overflow() -> ! {
- panic("attempt to multiply with overflow");
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
diff --git a/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs b/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs
index 0ba49e7..c1254c5 100644
--- a/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs
@@ -2,35 +2,32 @@
//
// Run-time:
// status: 0
-// stdout: 1
+// stdout: 10
+// 10
+// 42
#![feature(no_core)]
-
#![no_std]
#![no_core]
#![no_main]
extern crate mini_core;
+use mini_core::*;
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
-
-static mut ONE: usize = 1;
-
-fn make_array() -> [u8; 3] {
- [42, 10, 5]
+fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
+ (
+ a as u8, a as u16, a as u32, a as usize, a as i8, a as i16, a as i32, a as isize, b as u8,
+ b as u32,
+ )
}
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
+ let (a, b, c, d, e, f, g, h, i, j) = int_cast(10, 42);
unsafe {
- let ptr = ONE as *mut usize;
- let value = ptr as usize;
- libc::printf(b"%ld\n\0" as *const u8 as *const i8, value);
+ libc::printf(b"%d\n\0" as *const u8 as *const i8, c);
+ libc::printf(b"%ld\n\0" as *const u8 as *const i8, d);
+ libc::printf(b"%ld\n\0" as *const u8 as *const i8, j);
}
0
}
diff --git a/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs b/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs
index 3cc1e27..c1254c5 100644
--- a/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs
@@ -6,54 +6,13 @@
// 10
// 42
-#![feature(auto_traits, lang_items, no_core, intrinsics)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-#[lang = "copy"]
-pub unsafe trait Copy {}
-
-impl Copy for bool {}
-impl Copy for u8 {}
-impl Copy for u16 {}
-impl Copy for u32 {}
-impl Copy for u64 {}
-impl Copy for usize {}
-impl Copy for i8 {}
-impl Copy for i16 {}
-impl Copy for i32 {}
-impl Copy for isize {}
-impl Copy for f32 {}
-impl Copy for char {}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
-
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "legacy_receiver"]
-trait LegacyReceiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
(
diff --git a/compiler/rustc_codegen_gcc/tests/run/slice.rs b/compiler/rustc_codegen_gcc/tests/run/slice.rs
index 825fcb8..449ccab 100644
--- a/compiler/rustc_codegen_gcc/tests/run/slice.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/slice.rs
@@ -5,26 +5,17 @@
// stdout: 5
#![feature(no_core)]
-
#![no_std]
#![no_core]
#![no_main]
extern crate mini_core;
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
+use mini_core::*;
static mut TWO: usize = 2;
fn index_slice(s: &[u32]) -> u32 {
- unsafe {
- s[TWO]
- }
+ unsafe { s[TWO] }
}
#[no_mangle]
diff --git a/compiler/rustc_codegen_gcc/tests/run/static.rs b/compiler/rustc_codegen_gcc/tests/run/static.rs
index c3c8121..1e36cf4 100644
--- a/compiler/rustc_codegen_gcc/tests/run/static.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/static.rs
@@ -9,70 +9,13 @@
// 12
// 1
-#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "destruct"]
-pub trait Destruct {}
-
-#[lang = "drop"]
-pub trait Drop {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-impl<T: ?Sized> Copy for *mut T {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-mod intrinsics {
- use super::Sized;
-
- #[rustc_nounwind]
- #[rustc_intrinsic]
- pub fn abort() -> !;
-}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
-
-#[lang = "structural_peq"]
-pub trait StructuralPartialEq {}
-
-#[lang = "drop_in_place"]
-#[allow(unconditional_recursion)]
-pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
- // Code here does not matter - this is replaced by the
- // real drop glue by the compiler.
- drop_in_place(to_drop);
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
struct Test {
field: isize,
@@ -84,20 +27,14 @@ struct WithRef {
static mut CONSTANT: isize = 10;
-static mut TEST: Test = Test {
- field: 12,
-};
+static mut TEST: Test = Test { field: 12 };
-static mut TEST2: Test = Test {
- field: 14,
-};
+static mut TEST2: Test = Test { field: 14 };
-static mut WITH_REF: WithRef = WithRef {
- refe: unsafe { &TEST },
-};
+static mut WITH_REF: WithRef = WithRef { refe: unsafe { &TEST } };
#[no_mangle]
-extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
+extern "C" fn main(argc: isize, _argv: *const *const u8) -> i32 {
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, CONSTANT);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, TEST2.field);
diff --git a/compiler/rustc_codegen_gcc/tests/run/structs.rs b/compiler/rustc_codegen_gcc/tests/run/structs.rs
index 59b8f35..da73cbe 100644
--- a/compiler/rustc_codegen_gcc/tests/run/structs.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/structs.rs
@@ -5,44 +5,13 @@
// stdout: 1
// 2
-#![feature(auto_traits, lang_items, no_core, intrinsics)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
struct Test {
field: isize,
diff --git a/compiler/rustc_codegen_gcc/tests/run/tuple.rs b/compiler/rustc_codegen_gcc/tests/run/tuple.rs
index ed60a56..e0f2e95 100644
--- a/compiler/rustc_codegen_gcc/tests/run/tuple.rs
+++ b/compiler/rustc_codegen_gcc/tests/run/tuple.rs
@@ -4,44 +4,13 @@
// status: 0
// stdout: 3
-#![feature(auto_traits, lang_items, no_core, intrinsics)]
-#![allow(internal_features)]
-
+#![feature(no_core)]
#![no_std]
#![no_core]
#![no_main]
-/*
- * Core
- */
-
-// Because we don't have core yet.
-#[lang = "sized"]
-pub trait Sized {}
-
-#[lang = "copy"]
-trait Copy {
-}
-
-impl Copy for isize {}
-
-#[lang = "receiver"]
-trait Receiver {
-}
-
-#[lang = "freeze"]
-pub(crate) unsafe auto trait Freeze {}
-
-mod libc {
- #[link(name = "c")]
- extern "C" {
- pub fn printf(format: *const i8, ...) -> i32;
- }
-}
-
-/*
- * Code
- */
+extern crate mini_core;
+use mini_core::*;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs
index ae2ab32..56fb12d 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs
@@ -247,6 +247,16 @@ pub(super) fn stub<'ll, 'tcx>(
StubInfo { metadata, unique_type_id }
}
+struct AdtStackPopGuard<'ll, 'tcx, 'a> {
+ cx: &'a CodegenCx<'ll, 'tcx>,
+}
+
+impl<'ll, 'tcx, 'a> Drop for AdtStackPopGuard<'ll, 'tcx, 'a> {
+ fn drop(&mut self) {
+ debug_context(self.cx).adt_stack.borrow_mut().pop();
+ }
+}
+
/// This function enables creating debuginfo nodes that can recursively refer to themselves.
/// It will first insert the given stub into the type map and only then execute the `members`
/// and `generics` closures passed in. These closures have access to the stub so they can
@@ -261,6 +271,44 @@ pub(super) fn build_type_with_children<'ll, 'tcx>(
) -> DINodeCreationResult<'ll> {
assert_eq!(debug_context(cx).type_map.di_node_for_unique_id(stub_info.unique_type_id), None);
+ let mut _adt_stack_pop_guard = None;
+ if let UniqueTypeId::Ty(ty, ..) = stub_info.unique_type_id
+ && let ty::Adt(adt_def, args) = ty.kind()
+ {
+ let def_id = adt_def.did();
+ // If any sub type reference the original type definition and the sub type has a type
+ // parameter that strictly contains the original parameter, the original type is a recursive
+ // type that can expanding indefinitely. Example,
+ // ```
+ // enum Recursive<T> {
+ // Recurse(*const Recursive<Wrap<T>>),
+ // Item(T),
+ // }
+ // ```
+ let is_expanding_recursive =
+ debug_context(cx).adt_stack.borrow().iter().any(|(parent_def_id, parent_args)| {
+ if def_id == *parent_def_id {
+ args.iter().zip(parent_args.iter()).any(|(arg, parent_arg)| {
+ if let (Some(arg), Some(parent_arg)) = (arg.as_type(), parent_arg.as_type())
+ {
+ arg != parent_arg && arg.contains(parent_arg)
+ } else {
+ false
+ }
+ })
+ } else {
+ false
+ }
+ });
+ if is_expanding_recursive {
+ // FIXME: indicate that this is an expanding recursive type in stub metadata?
+ return DINodeCreationResult::new(stub_info.metadata, false);
+ } else {
+ debug_context(cx).adt_stack.borrow_mut().push((def_id, args));
+ _adt_stack_pop_guard = Some(AdtStackPopGuard { cx });
+ }
+ }
+
debug_context(cx).type_map.insert(stub_info.unique_type_id, stub_info.metadata);
let members: SmallVec<_> =
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
index 0f94a1d..c508592 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
@@ -66,6 +66,7 @@ pub(crate) struct CodegenUnitDebugContext<'ll, 'tcx> {
created_files: RefCell<UnordMap<Option<(StableSourceFileId, SourceFileHash)>, &'ll DIFile>>,
type_map: metadata::TypeMap<'ll, 'tcx>,
+ adt_stack: RefCell<Vec<(DefId, GenericArgsRef<'tcx>)>>,
namespace_map: RefCell<DefIdMap<&'ll DIScope>>,
recursion_marker_type: OnceCell<&'ll DIType>,
}
@@ -80,6 +81,7 @@ pub(crate) fn new(llmod: &'ll llvm::Module) -> Self {
builder,
created_files: Default::default(),
type_map: Default::default(),
+ adt_stack: Default::default(),
namespace_map: RefCell::new(Default::default()),
recursion_marker_type: OnceCell::new(),
}
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index 8f23a5f..b0c53ec 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -346,20 +346,26 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
no_sanitize_span = Some(attr.span());
if let Some(list) = attr.meta_item_list() {
for item in list.iter() {
- match item.name_or_empty() {
- sym::address => {
+ match item.name() {
+ Some(sym::address) => {
codegen_fn_attrs.no_sanitize |=
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
}
- sym::cfi => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
- sym::kcfi => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
- sym::memory => codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY,
- sym::memtag => codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG,
- sym::shadow_call_stack => {
+ Some(sym::cfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
+ Some(sym::kcfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
+ Some(sym::memory) => {
+ codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY
+ }
+ Some(sym::memtag) => {
+ codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG
+ }
+ Some(sym::shadow_call_stack) => {
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK
}
- sym::thread => codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD,
- sym::hwaddress => {
+ Some(sym::thread) => {
+ codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD
+ }
+ Some(sym::hwaddress) => {
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS
}
_ => {
@@ -420,9 +426,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
continue;
};
- let attrib_to_write = match meta_item.name_or_empty() {
- sym::prefix_nops => &mut prefix,
- sym::entry_nops => &mut entry,
+ let attrib_to_write = match meta_item.name() {
+ Some(sym::prefix_nops) => &mut prefix,
+ Some(sym::entry_nops) => &mut entry,
_ => {
tcx.dcx().emit_err(errors::UnexpectedParameterName {
span: item.span(),
@@ -786,8 +792,7 @@ fn lint_if_mixed(self, tcx: TyCtxt<'_>) {
fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
let attrs = tcx.get_attrs(id, sym::rustc_autodiff);
- let attrs =
- attrs.filter(|attr| attr.name_or_empty() == sym::rustc_autodiff).collect::<Vec<_>>();
+ let attrs = attrs.filter(|attr| attr.has_name(sym::rustc_autodiff)).collect::<Vec<_>>();
// check for exactly one autodiff attribute on placeholder functions.
// There should only be one, since we generate a new placeholder per ad macro.
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs
index 49f6d58..f5eaf7d 100644
--- a/compiler/rustc_expand/src/base.rs
+++ b/compiler/rustc_expand/src/base.rs
@@ -824,10 +824,10 @@ fn collapse_debuginfo_by_name(
return Err(item.span);
}
- match item.name_or_empty() {
- sym::no => Ok(CollapseMacroDebuginfo::No),
- sym::external => Ok(CollapseMacroDebuginfo::External),
- sym::yes => Ok(CollapseMacroDebuginfo::Yes),
+ match item.name() {
+ Some(sym::no) => Ok(CollapseMacroDebuginfo::No),
+ Some(sym::external) => Ok(CollapseMacroDebuginfo::External),
+ Some(sym::yes) => Ok(CollapseMacroDebuginfo::Yes),
_ => Err(item.path.span),
}
}
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index 1b53947..1e26d66 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -2053,8 +2053,8 @@ fn flat_map_node<Node: InvocationCollectorNode<OutputTy: Default>>(
) -> Node::OutputTy {
loop {
return match self.take_first_attr(&mut node) {
- Some((attr, pos, derives)) => match attr.name_or_empty() {
- sym::cfg => {
+ Some((attr, pos, derives)) => match attr.name() {
+ Some(sym::cfg) => {
let (res, meta_item) = self.expand_cfg_true(&mut node, attr, pos);
if res {
continue;
@@ -2071,7 +2071,7 @@ fn flat_map_node<Node: InvocationCollectorNode<OutputTy: Default>>(
}
Default::default()
}
- sym::cfg_attr => {
+ Some(sym::cfg_attr) => {
self.expand_cfg_attr(&mut node, &attr, pos);
continue;
}
@@ -2144,8 +2144,8 @@ fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
) {
loop {
return match self.take_first_attr(node) {
- Some((attr, pos, derives)) => match attr.name_or_empty() {
- sym::cfg => {
+ Some((attr, pos, derives)) => match attr.name() {
+ Some(sym::cfg) => {
let span = attr.span;
if self.expand_cfg_true(node, attr, pos).0 {
continue;
@@ -2154,7 +2154,7 @@ fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
node.expand_cfg_false(self, pos, span);
continue;
}
- sym::cfg_attr => {
+ Some(sym::cfg_attr) => {
self.expand_cfg_attr(node, &attr, pos);
continue;
}
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 3f5269e..d02c767 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -1237,7 +1237,7 @@ fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
Attribute::Parsed(AttributeKind::DocComment { kind, comment, .. }) => {
Some((*comment, *kind))
}
- Attribute::Unparsed(_) if self.name_or_empty() == sym::doc => {
+ Attribute::Unparsed(_) if self.has_name(sym::doc) => {
self.value_str().map(|s| (s, CommentKind::Line))
}
_ => None,
@@ -1262,8 +1262,8 @@ pub fn id(&self) -> AttrId {
}
#[inline]
- pub fn name_or_empty(&self) -> Symbol {
- AttributeExt::name_or_empty(self)
+ pub fn name(&self) -> Option<Symbol> {
+ AttributeExt::name(self)
}
#[inline]
@@ -1302,6 +1302,11 @@ pub fn has_name(&self, name: Symbol) -> bool {
}
#[inline]
+ pub fn has_any_name(&self, names: &[Symbol]) -> bool {
+ AttributeExt::has_any_name(self, names)
+ }
+
+ #[inline]
pub fn span(&self) -> Span {
AttributeExt::span(self)
}
diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs
index b3eade8..99e495d 100644
--- a/compiler/rustc_hir_analysis/src/autoderef.rs
+++ b/compiler/rustc_hir_analysis/src/autoderef.rs
@@ -2,8 +2,8 @@
use rustc_infer::traits::PredicateObligations;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_session::Limit;
-use rustc_span::Span;
use rustc_span::def_id::{LOCAL_CRATE, LocalDefId};
+use rustc_span::{ErrorGuaranteed, Span};
use rustc_trait_selection::traits::ObligationCtxt;
use tracing::{debug, instrument};
@@ -259,7 +259,11 @@ pub fn silence_errors(mut self) -> Self {
}
}
-pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
+pub fn report_autoderef_recursion_limit_error<'tcx>(
+ tcx: TyCtxt<'tcx>,
+ span: Span,
+ ty: Ty<'tcx>,
+) -> ErrorGuaranteed {
// We've reached the recursion limit, error gracefully.
let suggested_limit = match tcx.recursion_limit() {
Limit(0) => Limit(2),
@@ -270,5 +274,5 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
ty,
suggested_limit,
crate_name: tcx.crate_name(LOCAL_CRATE),
- });
+ })
}
diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs
index 0511f4e..f5e0f01 100644
--- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs
+++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs
@@ -1000,6 +1000,8 @@ fn walk_pat(
// determines whether to borrow *at the level of the deref pattern* rather than
// borrowing the bound place (since that inner place is inside the temporary that
// stores the result of calling `deref()`/`deref_mut()` so can't be captured).
+ // HACK: this could be a fake pattern corresponding to a deref inserted by match
+ // ergonomics, in which case `pat.hir_id` will be the id of the subpattern.
let mutable = self.cx.typeck_results().pat_has_ref_mut_binding(subpattern);
let mutability =
if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };
@@ -1227,9 +1229,9 @@ fn pat_ty_adjusted(&self, pat: &hir::Pat<'_>) -> Result<Ty<'tcx>, Cx::Error> {
// actually this is somewhat "disjoint" from the code below
// that aims to account for `ref x`.
if let Some(vec) = self.cx.typeck_results().pat_adjustments().get(pat.hir_id) {
- if let Some(first_ty) = vec.first() {
- debug!("pat_ty(pat={:?}) found adjusted ty `{:?}`", pat, first_ty);
- return Ok(*first_ty);
+ if let Some(first_adjust) = vec.first() {
+ debug!("pat_ty(pat={:?}) found adjustment `{:?}`", pat, first_adjust);
+ return Ok(first_adjust.source);
}
} else if let PatKind::Ref(subpat, _) = pat.kind
&& self.cx.typeck_results().skipped_ref_pats().contains(pat.hir_id)
@@ -1680,12 +1682,31 @@ fn cat_pattern<F>(
// Then we see that to get the same result, we must start with
// `deref { deref { place_foo }}` instead of `place_foo` since the pattern is now `Some(x,)`
// and not `&&Some(x,)`, even though its assigned type is that of `&&Some(x,)`.
- for _ in
- 0..self.cx.typeck_results().pat_adjustments().get(pat.hir_id).map_or(0, |v| v.len())
- {
+ let typeck_results = self.cx.typeck_results();
+ let adjustments: &[adjustment::PatAdjustment<'tcx>] =
+ typeck_results.pat_adjustments().get(pat.hir_id).map_or(&[], |v| &**v);
+ let mut adjusts = adjustments.iter().peekable();
+ while let Some(adjust) = adjusts.next() {
debug!("applying adjustment to place_with_id={:?}", place_with_id);
- place_with_id = self.cat_deref(pat.hir_id, place_with_id)?;
+ place_with_id = match adjust.kind {
+ adjustment::PatAdjust::BuiltinDeref => self.cat_deref(pat.hir_id, place_with_id)?,
+ adjustment::PatAdjust::OverloadedDeref => {
+ // This adjustment corresponds to an overloaded deref; it borrows the scrutinee to
+ // call `Deref::deref` or `DerefMut::deref_mut`. Invoke the callback before setting
+ // `place_with_id` to the temporary storing the result of the deref.
+ // HACK(dianne): giving the callback a fake deref pattern makes sure it behaves the
+ // same as it would if this were an explicit deref pattern.
+ op(&place_with_id, &hir::Pat { kind: PatKind::Deref(pat), ..*pat })?;
+ let target_ty = match adjusts.peek() {
+ Some(&&next_adjust) => next_adjust.source,
+ // At the end of the deref chain, we get `pat`'s scrutinee.
+ None => self.pat_ty_unadjusted(pat)?,
+ };
+ self.pat_deref_temp(pat.hir_id, pat, target_ty)?
+ }
+ };
}
+ drop(typeck_results); // explicitly release borrow of typeck results, just in case.
let place_with_id = place_with_id; // lose mutability
debug!("applied adjustment derefs to get place_with_id={:?}", place_with_id);
@@ -1788,14 +1809,8 @@ fn cat_pattern<F>(
self.cat_pattern(subplace, subpat, op)?;
}
PatKind::Deref(subpat) => {
- let mutable = self.cx.typeck_results().pat_has_ref_mut_binding(subpat);
- let mutability = if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };
- let re_erased = self.cx.tcx().lifetimes.re_erased;
let ty = self.pat_ty_adjusted(subpat)?;
- let ty = Ty::new_ref(self.cx.tcx(), re_erased, ty, mutability);
- // A deref pattern generates a temporary.
- let base = self.cat_rvalue(pat.hir_id, ty);
- let place = self.cat_deref(pat.hir_id, base)?;
+ let place = self.pat_deref_temp(pat.hir_id, subpat, ty)?;
self.cat_pattern(place, subpat, op)?;
}
@@ -1848,6 +1863,23 @@ fn cat_pattern<F>(
Ok(())
}
+ /// Represents the place of the temp that stores the scrutinee of a deref pattern's interior.
+ fn pat_deref_temp(
+ &self,
+ hir_id: HirId,
+ inner: &hir::Pat<'_>,
+ target_ty: Ty<'tcx>,
+ ) -> Result<PlaceWithHirId<'tcx>, Cx::Error> {
+ let mutable = self.cx.typeck_results().pat_has_ref_mut_binding(inner);
+ let mutability = if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };
+ let re_erased = self.cx.tcx().lifetimes.re_erased;
+ let ty = Ty::new_ref(self.cx.tcx(), re_erased, target_ty, mutability);
+ // A deref pattern stores the result of `Deref::deref` or `DerefMut::deref_mut` ...
+ let base = self.cat_rvalue(hir_id, ty);
+ // ... and the inner pattern matches on the place behind that reference.
+ self.cat_deref(hir_id, base)
+ }
+
fn is_multivariant_adt(&self, ty: Ty<'tcx>, span: Span) -> bool {
if let ty::Adt(def, _) = self.cx.try_structurally_resolve_type(span, ty).kind() {
// Note that if a non-exhaustive SingleVariant is defined in another crate, we need
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
index 74cc818..934820e 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs
@@ -488,7 +488,7 @@ fn parse_never_type_options_attr(
item.span(),
format!(
"unknown or duplicate never type option: `{}` (supported: `fallback`, `diverging_block_default`)",
- item.name_or_empty()
+ item.name().unwrap()
),
);
}
diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs
index ba4396a..1d3a081 100644
--- a/compiler/rustc_hir_typeck/src/method/probe.rs
+++ b/compiler/rustc_hir_typeck/src/method/probe.rs
@@ -2334,8 +2334,9 @@ fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
let hir_id = self.fcx.tcx.local_def_id_to_hir_id(local_def_id);
let attrs = self.fcx.tcx.hir_attrs(hir_id);
for attr in attrs {
- if sym::doc == attr.name_or_empty() {
- } else if sym::rustc_confusables == attr.name_or_empty() {
+ if attr.has_name(sym::doc) {
+ // do nothing
+ } else if attr.has_name(sym::rustc_confusables) {
let Some(confusables) = attr.meta_item_list() else {
continue;
};
@@ -2355,7 +2356,7 @@ fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
continue;
};
for v in values {
- if v.name_or_empty() != sym::alias {
+ if !v.has_name(sym::alias) {
continue;
}
if let Some(nested) = v.meta_item_list() {
diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs
index fbc783c..e5e4fc7 100644
--- a/compiler/rustc_hir_typeck/src/pat.rs
+++ b/compiler/rustc_hir_typeck/src/pat.rs
@@ -9,11 +9,13 @@
Applicability, Diag, ErrorGuaranteed, MultiSpan, pluralize, struct_span_code_err,
};
use rustc_hir::def::{CtorKind, DefKind, Res};
+use rustc_hir::def_id::DefId;
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{
self as hir, BindingMode, ByRef, ExprKind, HirId, LangItem, Mutability, Pat, PatExpr,
PatExprKind, PatKind, expr_needs_parens,
};
+use rustc_hir_analysis::autoderef::report_autoderef_recursion_limit_error;
use rustc_infer::infer;
use rustc_middle::traits::PatternOriginExpr;
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
@@ -29,11 +31,12 @@
use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
use tracing::{debug, instrument, trace};
use ty::VariantDef;
+use ty::adjustment::{PatAdjust, PatAdjustment};
use super::report_unexpected_variant_res;
use crate::expectation::Expectation;
use crate::gather_locals::DeclOrigin;
-use crate::{FnCtxt, LoweredTy, errors};
+use crate::{FnCtxt, errors};
const CANNOT_IMPLICITLY_DEREF_POINTER_TRAIT_OBJ: &str = "\
This error indicates that a pointer to a trait type cannot be implicitly dereferenced by a \
@@ -161,12 +164,35 @@ fn demand_eqtype_pat(
/// Mode for adjusting the expected type and binding mode.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum AdjustMode {
- /// Peel off all immediate reference types.
- Peel,
+ /// Peel off all immediate reference types. If the `deref_patterns` feature is enabled, this
+ /// also peels smart pointer ADTs.
+ Peel { kind: PeelKind },
/// Pass on the input binding mode and expected type.
Pass,
}
+/// Restrictions on what types to peel when adjusting the expected type and binding mode.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+enum PeelKind {
+ /// Only peel reference types. This is used for explicit `deref!(_)` patterns, which dereference
+ /// any number of `&`/`&mut` references, plus a single smart pointer.
+ ExplicitDerefPat,
+ /// Implicitly peel any number of references, and if `deref_patterns` is enabled, smart pointer
+ /// ADTs. In order to peel only as much as necessary for the pattern to match, the `until_adt`
+ /// field contains the ADT def that the pattern is a constructor for, if applicable, so that we
+ /// don't peel it. See [`ResolvedPat`] for more information.
+ Implicit { until_adt: Option<DefId> },
+}
+
+impl AdjustMode {
+ const fn peel_until_adt(opt_adt_def: Option<DefId>) -> AdjustMode {
+ AdjustMode::Peel { kind: PeelKind::Implicit { until_adt: opt_adt_def } }
+ }
+ const fn peel_all() -> AdjustMode {
+ AdjustMode::peel_until_adt(None)
+ }
+}
+
/// `ref mut` bindings (explicit or match-ergonomics) are not allowed behind an `&` reference.
/// Normally, the borrow checker enforces this, but for (currently experimental) match ergonomics,
/// we track this when typing patterns for two purposes:
@@ -242,6 +268,47 @@ enum InheritedRefMatchRule {
},
}
+/// When checking patterns containing paths, we need to know the path's resolution to determine
+/// whether to apply match ergonomics and implicitly dereference the scrutinee. For instance, when
+/// the `deref_patterns` feature is enabled and we're matching against a scrutinee of type
+/// `Cow<'a, Option<u8>>`, we insert an implicit dereference to allow the pattern `Some(_)` to type,
+/// but we must not dereference it when checking the pattern `Cow::Borrowed(_)`.
+///
+/// `ResolvedPat` contains the information from resolution needed to determine match ergonomics
+/// adjustments, and to finish checking the pattern once we know its adjusted type.
+#[derive(Clone, Copy, Debug)]
+struct ResolvedPat<'tcx> {
+ /// The type of the pattern, to be checked against the type of the scrutinee after peeling. This
+ /// is also used to avoid peeling the scrutinee's constructors (see the `Cow` example above).
+ ty: Ty<'tcx>,
+ kind: ResolvedPatKind<'tcx>,
+}
+
+#[derive(Clone, Copy, Debug)]
+enum ResolvedPatKind<'tcx> {
+ Path { res: Res, pat_res: Res, segments: &'tcx [hir::PathSegment<'tcx>] },
+ Struct { variant: &'tcx VariantDef },
+ TupleStruct { res: Res, variant: &'tcx VariantDef },
+}
+
+impl<'tcx> ResolvedPat<'tcx> {
+ fn adjust_mode(&self) -> AdjustMode {
+ if let ResolvedPatKind::Path { res, .. } = self.kind
+ && matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))
+ {
+ // These constants can be of a reference type, e.g. `const X: &u8 = &0;`.
+ // Peeling the reference types too early will cause type checking failures.
+ // Although it would be possible to *also* peel the types of the constants too.
+ AdjustMode::Pass
+ } else {
+ // The remaining possible resolutions for path, struct, and tuple struct patterns are
+ // ADT constructors. As such, we may peel references freely, but we must not peel the
+ // ADT itself from the scrutinee if it's a smart pointer.
+ AdjustMode::peel_until_adt(self.ty.ty_adt_def().map(|adt| adt.did()))
+ }
+ }
+}
+
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Experimental pattern feature: after matching against a shared reference, do we limit the
/// default binding mode in subpatterns to be `ref` when it would otherwise be `ref mut`?
@@ -318,16 +385,35 @@ pub(crate) fn check_pat_top(
/// Conversely, inside this module, `check_pat_top` should never be used.
#[instrument(level = "debug", skip(self, pat_info))]
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'tcx>) {
+ // For patterns containing paths, we need the path's resolution to determine whether to
+ // implicitly dereference the scrutinee before matching.
let opt_path_res = match pat.kind {
PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), hir_id, span }) => {
- Some(self.resolve_ty_and_res_fully_qualified_call(qpath, *hir_id, *span))
+ Some(self.resolve_pat_path(*hir_id, *span, qpath))
}
+ PatKind::Struct(ref qpath, ..) => Some(self.resolve_pat_struct(pat, qpath)),
+ PatKind::TupleStruct(ref qpath, ..) => Some(self.resolve_pat_tuple_struct(pat, qpath)),
_ => None,
};
- let adjust_mode = self.calc_adjust_mode(pat, opt_path_res.map(|(res, ..)| res));
+ let adjust_mode = self.calc_adjust_mode(pat, opt_path_res);
let ty = self.check_pat_inner(pat, opt_path_res, adjust_mode, expected, pat_info);
self.write_ty(pat.hir_id, ty);
+ // If we implicitly inserted overloaded dereferences before matching, check the pattern to
+ // see if the dereferenced types need `DerefMut` bounds.
+ if let Some(derefed_tys) = self.typeck_results.borrow().pat_adjustments().get(pat.hir_id)
+ && derefed_tys.iter().any(|adjust| adjust.kind == PatAdjust::OverloadedDeref)
+ {
+ self.register_deref_mut_bounds_if_needed(
+ pat.span,
+ pat,
+ derefed_tys.iter().filter_map(|adjust| match adjust.kind {
+ PatAdjust::OverloadedDeref => Some(adjust.source),
+ PatAdjust::BuiltinDeref => None,
+ }),
+ );
+ }
+
// (note_1): In most of the cases where (note_1) is referenced
// (literals and constants being the exception), we relate types
// using strict equality, even though subtyping would be sufficient.
@@ -375,7 +461,7 @@ fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<
fn check_pat_inner(
&self,
pat: &'tcx Pat<'tcx>,
- opt_path_res: Option<(Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>])>,
+ opt_path_res: Option<Result<ResolvedPat<'tcx>, ErrorGuaranteed>>,
adjust_mode: AdjustMode,
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx>,
@@ -389,7 +475,7 @@ fn check_pat_inner(
}
// Resolve type if needed.
- let expected = if let AdjustMode::Peel = adjust_mode
+ let expected = if let AdjustMode::Peel { .. } = adjust_mode
&& pat.default_binding_modes
{
self.try_structurally_resolve_type(pat.span, expected)
@@ -402,7 +488,7 @@ fn check_pat_inner(
match pat.kind {
// Peel off a `&` or `&mut` from the scrutinee type. See the examples in
// `tests/ui/rfcs/rfc-2005-default-binding-mode`.
- _ if let AdjustMode::Peel = adjust_mode
+ _ if let AdjustMode::Peel { .. } = adjust_mode
&& pat.default_binding_modes
&& let ty::Ref(_, inner_ty, inner_mutability) = *expected.kind() =>
{
@@ -415,7 +501,7 @@ fn check_pat_inner(
.pat_adjustments_mut()
.entry(pat.hir_id)
.or_default()
- .push(expected);
+ .push(PatAdjustment { kind: PatAdjust::BuiltinDeref, source: expected });
let mut binding_mode = ByRef::Yes(match pat_info.binding_mode {
// If default binding mode is by value, make it `ref` or `ref mut`
@@ -442,19 +528,68 @@ fn check_pat_inner(
// Recurse with the new expected type.
self.check_pat_inner(pat, opt_path_res, adjust_mode, inner_ty, new_pat_info)
}
+ // If `deref_patterns` is enabled, peel a smart pointer from the scrutinee type. See the
+ // examples in `tests/ui/pattern/deref_patterns/`.
+ _ if self.tcx.features().deref_patterns()
+ && let AdjustMode::Peel { kind: PeelKind::Implicit { until_adt } } = adjust_mode
+ && pat.default_binding_modes
+ // For simplicity, only apply overloaded derefs if `expected` is a known ADT.
+ // FIXME(deref_patterns): we'll get better diagnostics for users trying to
+ // implicitly deref generics if we allow them here, but primitives, tuples, and
+ // inference vars definitely should be stopped. Figure out what makes most sense.
+ && let ty::Adt(scrutinee_adt, _) = *expected.kind()
+ // Don't peel if the pattern type already matches the scrutinee. E.g., stop here if
+ // matching on a `Cow<'a, T>` scrutinee with a `Cow::Owned(_)` pattern.
+ && until_adt != Some(scrutinee_adt.did())
+ // At this point, the pattern isn't able to match `expected` without peeling. Check
+ // that it implements `Deref` before assuming it's a smart pointer, to get a normal
+ // type error instead of a missing impl error if not. This only checks for `Deref`,
+ // not `DerefPure`: we require that too, but we want a trait error if it's missing.
+ && let Some(deref_trait) = self.tcx.lang_items().deref_trait()
+ && self
+ .type_implements_trait(deref_trait, [expected], self.param_env)
+ .may_apply() =>
+ {
+ debug!("scrutinee ty {expected:?} is a smart pointer, inserting overloaded deref");
+ // The scrutinee is a smart pointer; implicitly dereference it. This adds a
+ // requirement that `expected: DerefPure`.
+ let mut inner_ty = self.deref_pat_target(pat.span, expected);
+ // Once we've checked `pat`, we'll add a `DerefMut` bound if it contains any
+ // `ref mut` bindings. See `Self::register_deref_mut_bounds_if_needed`.
+
+ let mut typeck_results = self.typeck_results.borrow_mut();
+ let mut pat_adjustments_table = typeck_results.pat_adjustments_mut();
+ let pat_adjustments = pat_adjustments_table.entry(pat.hir_id).or_default();
+ // We may reach the recursion limit if a user matches on a type `T` satisfying
+ // `T: Deref<Target = T>`; error gracefully in this case.
+ // FIXME(deref_patterns): If `deref_patterns` stabilizes, it may make sense to move
+ // this check out of this branch. Alternatively, this loop could be implemented with
+ // autoderef and this check removed. For now though, don't break code compiling on
+ // stable with lots of `&`s and a low recursion limit, if anyone's done that.
+ if self.tcx.recursion_limit().value_within_limit(pat_adjustments.len()) {
+ // Preserve the smart pointer type for THIR lowering and closure upvar analysis.
+ pat_adjustments
+ .push(PatAdjustment { kind: PatAdjust::OverloadedDeref, source: expected });
+ } else {
+ let guar = report_autoderef_recursion_limit_error(self.tcx, pat.span, expected);
+ inner_ty = Ty::new_error(self.tcx, guar);
+ }
+ drop(typeck_results);
+
+ // Recurse, using the old pat info to keep `current_depth` to its old value.
+ // Peeling smart pointers does not update the default binding mode.
+ self.check_pat_inner(pat, opt_path_res, adjust_mode, inner_ty, old_pat_info)
+ }
PatKind::Missing | PatKind::Wild | PatKind::Err(_) => expected,
// We allow any type here; we ensure that the type is uninhabited during match checking.
PatKind::Never => expected,
- PatKind::Expr(PatExpr { kind: PatExprKind::Path(qpath), hir_id, span }) => {
- let ty = self.check_pat_path(
- *hir_id,
- pat.hir_id,
- *span,
- qpath,
- opt_path_res.unwrap(),
- expected,
- &pat_info.top_info,
- );
+ PatKind::Expr(PatExpr { kind: PatExprKind::Path(_), hir_id, .. }) => {
+ let ty = match opt_path_res.unwrap() {
+ Ok(ref pr) => {
+ self.check_pat_path(pat.hir_id, pat.span, pr, expected, &pat_info.top_info)
+ }
+ Err(guar) => Ty::new_error(self.tcx, guar),
+ };
self.write_ty(*hir_id, ty);
ty
}
@@ -465,12 +600,32 @@ fn check_pat_inner(
PatKind::Binding(ba, var_id, ident, sub) => {
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
}
- PatKind::TupleStruct(ref qpath, subpats, ddpos) => {
- self.check_pat_tuple_struct(pat, qpath, subpats, ddpos, expected, pat_info)
- }
- PatKind::Struct(ref qpath, fields, has_rest_pat) => {
- self.check_pat_struct(pat, qpath, fields, has_rest_pat, expected, pat_info)
- }
+ PatKind::TupleStruct(ref qpath, subpats, ddpos) => match opt_path_res.unwrap() {
+ Ok(ResolvedPat { ty, kind: ResolvedPatKind::TupleStruct { res, variant } }) => self
+ .check_pat_tuple_struct(
+ pat, qpath, subpats, ddpos, res, ty, variant, expected, pat_info,
+ ),
+ Err(guar) => {
+ let ty_err = Ty::new_error(self.tcx, guar);
+ for subpat in subpats {
+ self.check_pat(subpat, ty_err, pat_info);
+ }
+ ty_err
+ }
+ Ok(pr) => span_bug!(pat.span, "tuple struct pattern resolved to {pr:?}"),
+ },
+ PatKind::Struct(_, fields, has_rest_pat) => match opt_path_res.unwrap() {
+ Ok(ResolvedPat { ty, kind: ResolvedPatKind::Struct { variant } }) => self
+ .check_pat_struct(pat, fields, has_rest_pat, ty, variant, expected, pat_info),
+ Err(guar) => {
+ let ty_err = Ty::new_error(self.tcx, guar);
+ for field in fields {
+ self.check_pat(field.pat, ty_err, pat_info);
+ }
+ ty_err
+ }
+ Ok(pr) => span_bug!(pat.span, "struct pattern resolved to {pr:?}"),
+ },
PatKind::Guard(pat, cond) => {
self.check_pat(pat, expected, pat_info);
self.check_expr_has_type_or_error(cond, self.tcx.types.bool, |_| {});
@@ -496,31 +651,32 @@ fn check_pat_inner(
/// How should the binding mode and expected type be adjusted?
///
- /// When the pattern is a path pattern, `opt_path_res` must be `Some(res)`.
- fn calc_adjust_mode(&self, pat: &'tcx Pat<'tcx>, opt_path_res: Option<Res>) -> AdjustMode {
+ /// When the pattern contains a path, `opt_path_res` must be `Some(path_res)`.
+ fn calc_adjust_mode(
+ &self,
+ pat: &'tcx Pat<'tcx>,
+ opt_path_res: Option<Result<ResolvedPat<'tcx>, ErrorGuaranteed>>,
+ ) -> AdjustMode {
match &pat.kind {
// Type checking these product-like types successfully always require
// that the expected type be of those types and not reference types.
+ PatKind::Tuple(..)
+ | PatKind::Range(..)
+ | PatKind::Slice(..) => AdjustMode::peel_all(),
+ // When checking an explicit deref pattern, only peel reference types.
+ // FIXME(deref_patterns): If box patterns and deref patterns need to coexist, box
+ // patterns may want `PeelKind::Implicit`, stopping on encountering a box.
+ | PatKind::Box(_)
+ | PatKind::Deref(_) => AdjustMode::Peel { kind: PeelKind::ExplicitDerefPat },
+ // A never pattern behaves somewhat like a literal or unit variant.
+ PatKind::Never => AdjustMode::peel_all(),
+ // For patterns with paths, how we peel the scrutinee depends on the path's resolution.
PatKind::Struct(..)
| PatKind::TupleStruct(..)
- | PatKind::Tuple(..)
- | PatKind::Box(_)
- | PatKind::Deref(_)
- | PatKind::Range(..)
- | PatKind::Slice(..) => AdjustMode::Peel,
- // A never pattern behaves somewhat like a literal or unit variant.
- PatKind::Never => AdjustMode::Peel,
- PatKind::Expr(PatExpr { kind: PatExprKind::Path(_), .. }) => match opt_path_res.unwrap() {
- // These constants can be of a reference type, e.g. `const X: &u8 = &0;`.
- // Peeling the reference types too early will cause type checking failures.
- // Although it would be possible to *also* peel the types of the constants too.
- Res::Def(DefKind::Const | DefKind::AssocConst, _) => AdjustMode::Pass,
- // In the `ValueNS`, we have `SelfCtor(..) | Ctor(_, Const), _)` remaining which
- // could successfully compile. The former being `Self` requires a unit struct.
- // In either case, and unlike constants, the pattern itself cannot be
- // a reference type wherefore peeling doesn't give up any expressiveness.
- _ => AdjustMode::Peel,
- },
+ | PatKind::Expr(PatExpr { kind: PatExprKind::Path(_), .. }) => {
+ // If there was an error resolving the path, default to peeling everything.
+ opt_path_res.unwrap().map_or(AdjustMode::peel_all(), |pr| pr.adjust_mode())
+ }
// String and byte-string literals result in types `&str` and `&[u8]` respectively.
// All other literals result in non-reference types.
@@ -529,7 +685,17 @@ fn calc_adjust_mode(&self, pat: &'tcx Pat<'tcx>, opt_path_res: Option<Res>) -> A
// Call `resolve_vars_if_possible` here for inline const blocks.
PatKind::Expr(lt) => match self.resolve_vars_if_possible(self.check_pat_expr_unadjusted(lt)).kind() {
ty::Ref(..) => AdjustMode::Pass,
- _ => AdjustMode::Peel,
+ _ => {
+ // Path patterns have already been handled, and inline const blocks currently
+ // aren't possible to write, so any handling for them would be untested.
+ if cfg!(debug_assertions)
+ && self.tcx.features().deref_patterns()
+ && !matches!(lt.kind, PatExprKind::Lit { .. })
+ {
+ span_bug!(lt.span, "FIXME(deref_patterns): adjust mode unimplemented for {:?}", lt.kind);
+ }
+ AdjustMode::peel_all()
+ }
},
// Ref patterns are complicated, we handle them in `check_pat_ref`.
@@ -1112,27 +1278,26 @@ fn check_dereferenceable(
Ok(())
}
- fn check_pat_struct(
+ fn resolve_pat_struct(
&self,
pat: &'tcx Pat<'tcx>,
qpath: &hir::QPath<'tcx>,
+ ) -> Result<ResolvedPat<'tcx>, ErrorGuaranteed> {
+ // Resolve the path and check the definition for errors.
+ let (variant, pat_ty) = self.check_struct_path(qpath, pat.hir_id)?;
+ Ok(ResolvedPat { ty: pat_ty, kind: ResolvedPatKind::Struct { variant } })
+ }
+
+ fn check_pat_struct(
+ &self,
+ pat: &'tcx Pat<'tcx>,
fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool,
+ pat_ty: Ty<'tcx>,
+ variant: &'tcx VariantDef,
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
- // Resolve the path and check the definition for errors.
- let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) {
- Ok(data) => data,
- Err(guar) => {
- let err = Ty::new_error(self.tcx, guar);
- for field in fields {
- self.check_pat(field.pat, err, pat_info);
- }
- return err;
- }
- };
-
// Type-check the path.
let _ = self.demand_eqtype_pat(pat.span, expected, pat_ty, &pat_info.top_info);
@@ -1143,31 +1308,27 @@ fn check_pat_struct(
}
}
- fn check_pat_path(
+ fn resolve_pat_path(
&self,
path_id: HirId,
- pat_id_for_diag: HirId,
span: Span,
- qpath: &hir::QPath<'_>,
- path_resolution: (Res, Option<LoweredTy<'tcx>>, &'tcx [hir::PathSegment<'tcx>]),
- expected: Ty<'tcx>,
- ti: &TopInfo<'tcx>,
- ) -> Ty<'tcx> {
+ qpath: &'tcx hir::QPath<'_>,
+ ) -> Result<ResolvedPat<'tcx>, ErrorGuaranteed> {
let tcx = self.tcx;
- // We have already resolved the path.
- let (res, opt_ty, segments) = path_resolution;
+ let (res, opt_ty, segments) =
+ self.resolve_ty_and_res_fully_qualified_call(qpath, path_id, span);
match res {
Res::Err => {
let e =
self.dcx().span_delayed_bug(qpath.span(), "`Res::Err` but no error emitted");
self.set_tainted_by_errors(e);
- return Ty::new_error(tcx, e);
+ return Err(e);
}
Res::Def(DefKind::AssocFn | DefKind::Ctor(_, CtorKind::Fn) | DefKind::Variant, _) => {
let expected = "unit struct, unit variant or constant";
let e = report_unexpected_variant_res(tcx, res, None, qpath, span, E0533, expected);
- return Ty::new_error(tcx, e);
+ return Err(e);
}
Res::SelfCtor(def_id) => {
if let ty::Adt(adt_def, _) = *tcx.type_of(def_id).skip_binder().kind()
@@ -1185,7 +1346,7 @@ fn check_pat_path(
E0533,
"unit struct",
);
- return Ty::new_error(tcx, e);
+ return Err(e);
}
}
Res::Def(
@@ -1198,15 +1359,26 @@ fn check_pat_path(
_ => bug!("unexpected pattern resolution: {:?}", res),
}
- // Type-check the path.
+ // Find the type of the path pattern, for later checking.
let (pat_ty, pat_res) =
self.instantiate_value_path(segments, opt_ty, res, span, span, path_id);
+ Ok(ResolvedPat { ty: pat_ty, kind: ResolvedPatKind::Path { res, pat_res, segments } })
+ }
+
+ fn check_pat_path(
+ &self,
+ pat_id_for_diag: HirId,
+ span: Span,
+ resolved: &ResolvedPat<'tcx>,
+ expected: Ty<'tcx>,
+ ti: &TopInfo<'tcx>,
+ ) -> Ty<'tcx> {
if let Err(err) =
- self.demand_suptype_with_origin(&self.pattern_cause(ti, span), expected, pat_ty)
+ self.demand_suptype_with_origin(&self.pattern_cause(ti, span), expected, resolved.ty)
{
- self.emit_bad_pat_path(err, pat_id_for_diag, span, res, pat_res, pat_ty, segments);
+ self.emit_bad_pat_path(err, pat_id_for_diag, span, resolved);
}
- pat_ty
+ resolved.ty
}
fn maybe_suggest_range_literal(
@@ -1249,11 +1421,12 @@ fn emit_bad_pat_path(
mut e: Diag<'_>,
hir_id: HirId,
pat_span: Span,
- res: Res,
- pat_res: Res,
- pat_ty: Ty<'tcx>,
- segments: &'tcx [hir::PathSegment<'tcx>],
+ resolved_pat: &ResolvedPat<'tcx>,
) {
+ let ResolvedPatKind::Path { res, pat_res, segments } = resolved_pat.kind else {
+ span_bug!(pat_span, "unexpected resolution for path pattern: {resolved_pat:?}");
+ };
+
if let Some(span) = self.tcx.hir_res_span(pat_res) {
e.span_label(span, format!("{} defined here", res.descr()));
if let [hir::PathSegment { ident, .. }] = &*segments {
@@ -1276,7 +1449,7 @@ fn emit_bad_pat_path(
);
}
_ => {
- let (type_def_id, item_def_id) = match pat_ty.kind() {
+ let (type_def_id, item_def_id) = match resolved_pat.ty.kind() {
ty::Adt(def, _) => match res {
Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)),
_ => (None, None),
@@ -1316,12 +1489,61 @@ fn emit_bad_pat_path(
e.emit();
}
+ fn resolve_pat_tuple_struct(
+ &self,
+ pat: &'tcx Pat<'tcx>,
+ qpath: &'tcx hir::QPath<'tcx>,
+ ) -> Result<ResolvedPat<'tcx>, ErrorGuaranteed> {
+ let tcx = self.tcx;
+ let report_unexpected_res = |res: Res| {
+ let expected = "tuple struct or tuple variant";
+ let e = report_unexpected_variant_res(tcx, res, None, qpath, pat.span, E0164, expected);
+ Err(e)
+ };
+
+ // Resolve the path and check the definition for errors.
+ let (res, opt_ty, segments) =
+ self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span);
+ if res == Res::Err {
+ let e = self.dcx().span_delayed_bug(pat.span, "`Res::Err` but no error emitted");
+ self.set_tainted_by_errors(e);
+ return Err(e);
+ }
+
+ // Type-check the path.
+ let (pat_ty, res) =
+ self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
+ if !pat_ty.is_fn() {
+ return report_unexpected_res(res);
+ }
+
+ let variant = match res {
+ Res::Err => {
+ self.dcx().span_bug(pat.span, "`Res::Err` but no error emitted");
+ }
+ Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => {
+ return report_unexpected_res(res);
+ }
+ Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res),
+ _ => bug!("unexpected pattern resolution: {:?}", res),
+ };
+
+ // Replace constructor type with constructed type for tuple struct patterns.
+ let pat_ty = pat_ty.fn_sig(tcx).output();
+ let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
+
+ Ok(ResolvedPat { ty: pat_ty, kind: ResolvedPatKind::TupleStruct { res, variant } })
+ }
+
fn check_pat_tuple_struct(
&self,
pat: &'tcx Pat<'tcx>,
qpath: &'tcx hir::QPath<'tcx>,
subpats: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos,
+ res: Res,
+ pat_ty: Ty<'tcx>,
+ variant: &'tcx VariantDef,
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
@@ -1331,46 +1553,6 @@ fn check_pat_tuple_struct(
self.check_pat(pat, Ty::new_error(tcx, e), pat_info);
}
};
- let report_unexpected_res = |res: Res| {
- let expected = "tuple struct or tuple variant";
- let e = report_unexpected_variant_res(tcx, res, None, qpath, pat.span, E0164, expected);
- on_error(e);
- e
- };
-
- // Resolve the path and check the definition for errors.
- let (res, opt_ty, segments) =
- self.resolve_ty_and_res_fully_qualified_call(qpath, pat.hir_id, pat.span);
- if res == Res::Err {
- let e = self.dcx().span_delayed_bug(pat.span, "`Res::Err` but no error emitted");
- self.set_tainted_by_errors(e);
- on_error(e);
- return Ty::new_error(tcx, e);
- }
-
- // Type-check the path.
- let (pat_ty, res) =
- self.instantiate_value_path(segments, opt_ty, res, pat.span, pat.span, pat.hir_id);
- if !pat_ty.is_fn() {
- let e = report_unexpected_res(res);
- return Ty::new_error(tcx, e);
- }
-
- let variant = match res {
- Res::Err => {
- self.dcx().span_bug(pat.span, "`Res::Err` but no error emitted");
- }
- Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => {
- let e = report_unexpected_res(res);
- return Ty::new_error(tcx, e);
- }
- Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res),
- _ => bug!("unexpected pattern resolution: {:?}", res),
- };
-
- // Replace constructor type with constructed type for tuple struct patterns.
- let pat_ty = pat_ty.fn_sig(tcx).output();
- let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
// Type-check the tuple struct pattern against the expected type.
let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, &pat_info.top_info);
@@ -2255,36 +2437,49 @@ fn check_pat_deref(
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
- let tcx = self.tcx;
+ let target_ty = self.deref_pat_target(span, expected);
+ self.check_pat(inner, target_ty, pat_info);
+ self.register_deref_mut_bounds_if_needed(span, inner, [expected]);
+ expected
+ }
+
+ fn deref_pat_target(&self, span: Span, source_ty: Ty<'tcx>) -> Ty<'tcx> {
// Register a `DerefPure` bound, which is required by all `deref!()` pats.
+ let tcx = self.tcx;
self.register_bound(
- expected,
+ source_ty,
tcx.require_lang_item(hir::LangItem::DerefPure, Some(span)),
self.misc(span),
);
- // <expected as Deref>::Target
- let ty = Ty::new_projection(
+ // The expected type for the deref pat's inner pattern is `<expected as Deref>::Target`.
+ let target_ty = Ty::new_projection(
tcx,
tcx.require_lang_item(hir::LangItem::DerefTarget, Some(span)),
- [expected],
+ [source_ty],
);
- let ty = self.normalize(span, ty);
- let ty = self.try_structurally_resolve_type(span, ty);
- self.check_pat(inner, ty, pat_info);
+ let target_ty = self.normalize(span, target_ty);
+ self.try_structurally_resolve_type(span, target_ty)
+ }
- // Check if the pattern has any `ref mut` bindings, which would require
- // `DerefMut` to be emitted in MIR building instead of just `Deref`.
- // We do this *after* checking the inner pattern, since we want to make
- // sure to apply any match-ergonomics adjustments.
+ /// Check if the interior of a deref pattern (either explicit or implicit) has any `ref mut`
+ /// bindings, which would require `DerefMut` to be emitted in MIR building instead of just
+ /// `Deref`. We do this *after* checking the inner pattern, since we want to make sure to
+ /// account for `ref mut` binding modes inherited from implicitly dereferencing `&mut` refs.
+ fn register_deref_mut_bounds_if_needed(
+ &self,
+ span: Span,
+ inner: &'tcx Pat<'tcx>,
+ derefed_tys: impl IntoIterator<Item = Ty<'tcx>>,
+ ) {
if self.typeck_results.borrow().pat_has_ref_mut_binding(inner) {
- self.register_bound(
- expected,
- tcx.require_lang_item(hir::LangItem::DerefMut, Some(span)),
- self.misc(span),
- );
+ for mutably_derefed_ty in derefed_tys {
+ self.register_bound(
+ mutably_derefed_ty,
+ self.tcx.require_lang_item(hir::LangItem::DerefMut, Some(span)),
+ self.misc(span),
+ );
+ }
}
-
- expected
}
// Precondition: Pat is Ref(inner)
diff --git a/compiler/rustc_incremental/messages.ftl b/compiler/rustc_incremental/messages.ftl
index 2a65101..bbc1fab 100644
--- a/compiler/rustc_incremental/messages.ftl
+++ b/compiler/rustc_incremental/messages.ftl
@@ -93,7 +93,7 @@
incremental_undefined_clean_dirty_assertions_item =
clean/dirty auto-assertions not yet defined for Node::Item.node={$kind}
-incremental_unknown_item = unknown item `{$name}`
+incremental_unknown_rustc_clean_argument = unknown `rustc_clean` argument
incremental_unrecognized_depnode = unrecognized `DepNode` variant: {$name}
diff --git a/compiler/rustc_incremental/src/errors.rs b/compiler/rustc_incremental/src/errors.rs
index b4a2073..dbc72d0 100644
--- a/compiler/rustc_incremental/src/errors.rs
+++ b/compiler/rustc_incremental/src/errors.rs
@@ -107,11 +107,10 @@ pub(crate) struct NotLoaded<'a> {
}
#[derive(Diagnostic)]
-#[diag(incremental_unknown_item)]
-pub(crate) struct UnknownItem {
+#[diag(incremental_unknown_rustc_clean_argument)]
+pub(crate) struct UnknownRustcCleanArgument {
#[primary_span]
pub span: Span,
- pub name: Symbol,
}
#[derive(Diagnostic)]
diff --git a/compiler/rustc_incremental/src/persist/dirty_clean.rs b/compiler/rustc_incremental/src/persist/dirty_clean.rs
index d40a0d5..6416625 100644
--- a/compiler/rustc_incremental/src/persist/dirty_clean.rs
+++ b/compiler/rustc_incremental/src/persist/dirty_clean.rs
@@ -405,8 +405,7 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
debug!("check_config: searching for cfg {:?}", value);
cfg = Some(config.contains(&(value, None)));
} else if !(item.has_name(EXCEPT) || item.has_name(LOADED_FROM_DISK)) {
- tcx.dcx()
- .emit_err(errors::UnknownItem { span: attr.span(), name: item.name_or_empty() });
+ tcx.dcx().emit_err(errors::UnknownRustcCleanArgument { span: item.span() });
}
}
diff --git a/compiler/rustc_index/src/slice.rs b/compiler/rustc_index/src/slice.rs
index 67ac805..d2702bd 100644
--- a/compiler/rustc_index/src/slice.rs
+++ b/compiler/rustc_index/src/slice.rs
@@ -1,6 +1,6 @@
use std::fmt;
use std::marker::PhantomData;
-use std::ops::{Index, IndexMut};
+use std::ops::{Index, IndexMut, RangeBounds};
use std::slice::GetDisjointMutError::*;
use std::slice::{self, SliceIndex};
@@ -105,6 +105,17 @@ pub fn swap(&mut self, a: I, b: I) {
}
#[inline]
+ pub fn copy_within(
+ &mut self,
+ src: impl IntoSliceIdx<I, [T], Output: RangeBounds<usize>>,
+ dest: I,
+ ) where
+ T: Copy,
+ {
+ self.raw.copy_within(src.into_slice_idx(), dest.index());
+ }
+
+ #[inline]
pub fn get<R: IntoSliceIdx<I, [T]>>(
&self,
index: R,
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index d405d04..5c8c51c 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -818,8 +818,8 @@ macro_rules! tracked {
tracked!(min_function_alignment, Some(Align::EIGHT));
tracked!(mir_emit_retag, true);
tracked!(mir_enable_passes, vec![("DestProp".to_string(), false)]);
- tracked!(mir_keep_place_mention, true);
tracked!(mir_opt_level, Some(4));
+ tracked!(mir_preserve_ub, true);
tracked!(move_size_limit, Some(4096));
tracked!(mutable_noalias, false);
tracked!(next_solver, NextSolverConfig { coherence: true, globally: true });
diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs
index 7fdbae3..b4069b3 100644
--- a/compiler/rustc_lint_defs/src/lib.rs
+++ b/compiler/rustc_lint_defs/src/lib.rs
@@ -249,7 +249,7 @@ pub fn from_str(x: &str) -> Option<Self> {
/// Converts an `Attribute` to a level.
pub fn from_attr(attr: &impl AttributeExt) -> Option<(Self, Option<LintExpectationId>)> {
- Self::from_symbol(attr.name_or_empty(), || Some(attr.id()))
+ attr.name().and_then(|name| Self::from_symbol(name, || Some(attr.id())))
}
/// Converts a `Symbol` to a level.
diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index cfb0de8..cee9cff 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -226,8 +226,8 @@ fn process_module(&mut self, module: &ForeignModule) {
let mut wasm_import_module = None;
let mut import_name_type = None;
for item in items.iter() {
- match item.name_or_empty() {
- sym::name => {
+ match item.name() {
+ Some(sym::name) => {
if name.is_some() {
sess.dcx().emit_err(errors::MultipleNamesInLink { span: item.span() });
continue;
@@ -242,7 +242,7 @@ fn process_module(&mut self, module: &ForeignModule) {
}
name = Some((link_name, span));
}
- sym::kind => {
+ Some(sym::kind) => {
if kind.is_some() {
sess.dcx().emit_err(errors::MultipleKindsInLink { span: item.span() });
continue;
@@ -304,7 +304,7 @@ fn process_module(&mut self, module: &ForeignModule) {
};
kind = Some(link_kind);
}
- sym::modifiers => {
+ Some(sym::modifiers) => {
if modifiers.is_some() {
sess.dcx()
.emit_err(errors::MultipleLinkModifiers { span: item.span() });
@@ -316,7 +316,7 @@ fn process_module(&mut self, module: &ForeignModule) {
};
modifiers = Some((link_modifiers, item.name_value_literal_span().unwrap()));
}
- sym::cfg => {
+ Some(sym::cfg) => {
if cfg.is_some() {
sess.dcx().emit_err(errors::MultipleCfgs { span: item.span() });
continue;
@@ -346,7 +346,7 @@ fn process_module(&mut self, module: &ForeignModule) {
}
cfg = Some(link_cfg.clone());
}
- sym::wasm_import_module => {
+ Some(sym::wasm_import_module) => {
if wasm_import_module.is_some() {
sess.dcx().emit_err(errors::MultipleWasmImport { span: item.span() });
continue;
@@ -357,7 +357,7 @@ fn process_module(&mut self, module: &ForeignModule) {
};
wasm_import_module = Some((link_wasm_import_module, item.span()));
}
- sym::import_name_type => {
+ Some(sym::import_name_type) => {
if import_name_type.is_some() {
sess.dcx()
.emit_err(errors::MultipleImportNameType { span: item.span() });
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 177318b..3ea61d1 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -821,7 +821,9 @@ struct AnalyzeAttrState<'a> {
#[inline]
fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> bool {
let mut should_encode = false;
- if !rustc_feature::encode_cross_crate(attr.name_or_empty()) {
+ if let Some(name) = attr.name()
+ && !rustc_feature::encode_cross_crate(name)
+ {
// Attributes not marked encode-cross-crate don't need to be encoded for downstream crates.
} else if attr.doc_str().is_some() {
// We keep all doc comments reachable to rustdoc because they might be "imported" into
diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs
index 3425da4..a61a6c5 100644
--- a/compiler/rustc_middle/src/ty/adjustment.rs
+++ b/compiler/rustc_middle/src/ty/adjustment.rs
@@ -214,3 +214,25 @@ pub enum CustomCoerceUnsized {
/// Records the index of the field being coerced.
Struct(FieldIdx),
}
+
+/// Represents an implicit coercion applied to the scrutinee of a match before testing a pattern
+/// against it. Currently, this is used only for implicit dereferences.
+#[derive(Clone, Copy, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
+pub struct PatAdjustment<'tcx> {
+ pub kind: PatAdjust,
+ /// The type of the scrutinee before the adjustment is applied, or the "adjusted type" of the
+ /// pattern.
+ pub source: Ty<'tcx>,
+}
+
+/// Represents implicit coercions of patterns' types, rather than values' types.
+#[derive(Clone, Copy, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)]
+#[derive(TypeFoldable, TypeVisitable)]
+pub enum PatAdjust {
+ /// An implicit dereference before matching, such as when matching the pattern `0` against a
+ /// scrutinee of type `&u8` or `&mut u8`.
+ BuiltinDeref,
+ /// An implicit call to `Deref(Mut)::deref(_mut)` before matching, such as when matching the
+ /// pattern `[..]` against a scrutinee of type `Vec<T>`.
+ OverloadedDeref,
+}
diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs
index 66517c9..d92b4f9 100644
--- a/compiler/rustc_middle/src/ty/adt.rs
+++ b/compiler/rustc_middle/src/ty/adt.rs
@@ -55,8 +55,6 @@ impl AdtFlags: u16 {
const IS_UNSAFE_CELL = 1 << 9;
/// Indicates whether the type is `UnsafePinned`.
const IS_UNSAFE_PINNED = 1 << 10;
- /// Indicates whether the type is anonymous.
- const IS_ANONYMOUS = 1 << 11;
}
}
rustc_data_structures::external_bitflags_debug! { AdtFlags }
diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs
index 40eef54..2686166 100644
--- a/compiler/rustc_middle/src/ty/structural_impls.rs
+++ b/compiler/rustc_middle/src/ty/structural_impls.rs
@@ -60,6 +60,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
}
}
+impl<'tcx> fmt::Debug for ty::adjustment::PatAdjustment<'tcx> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{} -> {:?}", self.source, self.kind)
+ }
+}
+
impl fmt::Debug for ty::BoundRegionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs
index 90c6ef6..4c5c669 100644
--- a/compiler/rustc_middle/src/ty/typeck_results.rs
+++ b/compiler/rustc_middle/src/ty/typeck_results.rs
@@ -77,8 +77,8 @@ pub struct TypeckResults<'tcx> {
/// to a form valid in all Editions, either as a lint diagnostic or hard error.
rust_2024_migration_desugared_pats: ItemLocalMap<Rust2024IncompatiblePatInfo>,
- /// Stores the types which were implicitly dereferenced in pattern binding modes
- /// for later usage in THIR lowering. For example,
+ /// Stores the types which were implicitly dereferenced in pattern binding modes or deref
+ /// patterns for later usage in THIR lowering. For example,
///
/// ```
/// match &&Some(5i32) {
@@ -86,11 +86,20 @@ pub struct TypeckResults<'tcx> {
/// _ => {},
/// }
/// ```
- /// leads to a `vec![&&Option<i32>, &Option<i32>]`. Empty vectors are not stored.
+ /// leads to a `vec![&&Option<i32>, &Option<i32>]` and
+ ///
+ /// ```
+ /// #![feature(deref_patterns)]
+ /// match &Box::new(Some(5i32)) {
+ /// Some(n) => {},
+ /// _ => {},
+ /// }
+ /// ```
+ /// leads to a `vec![&Box<Option<i32>>, Box<Option<i32>>]`. Empty vectors are not stored.
///
/// See:
/// <https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md#definitions>
- pat_adjustments: ItemLocalMap<Vec<Ty<'tcx>>>,
+ pat_adjustments: ItemLocalMap<Vec<ty::adjustment::PatAdjustment<'tcx>>>,
/// Set of reference patterns that match against a match-ergonomics inserted reference
/// (as opposed to against a reference in the scrutinee type).
@@ -403,11 +412,15 @@ pub fn pat_binding_modes_mut(&mut self) -> LocalTableInContextMut<'_, BindingMod
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.pat_binding_modes }
}
- pub fn pat_adjustments(&self) -> LocalTableInContext<'_, Vec<Ty<'tcx>>> {
+ pub fn pat_adjustments(
+ &self,
+ ) -> LocalTableInContext<'_, Vec<ty::adjustment::PatAdjustment<'tcx>>> {
LocalTableInContext { hir_owner: self.hir_owner, data: &self.pat_adjustments }
}
- pub fn pat_adjustments_mut(&mut self) -> LocalTableInContextMut<'_, Vec<Ty<'tcx>>> {
+ pub fn pat_adjustments_mut(
+ &mut self,
+ ) -> LocalTableInContextMut<'_, Vec<ty::adjustment::PatAdjustment<'tcx>>> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.pat_adjustments }
}
diff --git a/compiler/rustc_mir_build/src/builder/custom/mod.rs b/compiler/rustc_mir_build/src/builder/custom/mod.rs
index bfc1681..902a6e7 100644
--- a/compiler/rustc_mir_build/src/builder/custom/mod.rs
+++ b/compiler/rustc_mir_build/src/builder/custom/mod.rs
@@ -103,8 +103,9 @@ fn parse_attribute(attr: &Attribute) -> MirPhase {
let mut dialect: Option<String> = None;
let mut phase: Option<String> = None;
+ // Not handling errors properly for this internal attribute; will just abort on errors.
for nested in meta_items {
- let name = nested.name_or_empty();
+ let name = nested.name().unwrap();
let value = nested.value_str().unwrap().as_str().to_string();
match name.as_str() {
"dialect" => {
diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs
index 8ca9ab5..59a52ae 100644
--- a/compiler/rustc_mir_build/src/builder/mod.rs
+++ b/compiler/rustc_mir_build/src/builder/mod.rs
@@ -485,7 +485,7 @@ fn construct_fn<'tcx>(
};
if let Some(custom_mir_attr) =
- tcx.hir_attrs(fn_id).iter().find(|attr| attr.name_or_empty() == sym::custom_mir)
+ tcx.hir_attrs(fn_id).iter().find(|attr| attr.has_name(sym::custom_mir))
{
return custom::build_custom_mir(
tcx,
diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs
index b3daed8..2f593b9 100644
--- a/compiler/rustc_mir_build/src/thir/cx/mod.rs
+++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs
@@ -113,7 +113,7 @@ fn new(tcx: TyCtxt<'tcx>, def: LocalDefId) -> Self {
apply_adjustments: tcx
.hir_attrs(hir_id)
.iter()
- .all(|attr| attr.name_or_empty() != rustc_span::sym::custom_mir),
+ .all(|attr| !attr.has_name(rustc_span::sym::custom_mir)),
}
}
diff --git a/compiler/rustc_mir_build/src/thir/pattern/migration.rs b/compiler/rustc_mir_build/src/thir/pattern/migration.rs
index bd7787b..12c457f 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/migration.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/migration.rs
@@ -4,8 +4,7 @@
use rustc_errors::MultiSpan;
use rustc_hir::{BindingMode, ByRef, HirId, Mutability};
use rustc_lint as lint;
-use rustc_middle::span_bug;
-use rustc_middle::ty::{self, Rust2024IncompatiblePatInfo, Ty, TyCtxt};
+use rustc_middle::ty::{self, Rust2024IncompatiblePatInfo, TyCtxt};
use rustc_span::{Ident, Span};
use crate::errors::{Rust2024IncompatiblePat, Rust2024IncompatiblePatSugg};
@@ -87,19 +86,18 @@ pub(super) fn emit<'tcx>(self, tcx: TyCtxt<'tcx>, pat_id: HirId) {
}
/// Tracks when we're lowering a pattern that implicitly dereferences the scrutinee.
- /// This should only be called when the pattern type adjustments list `adjustments` is
- /// non-empty. Returns the prior default binding mode; this should be followed by a call to
- /// [`PatMigration::leave_ref`] to restore it when we leave the pattern.
+ /// This should only be called when the pattern type adjustments list `adjustments` contains an
+ /// implicit deref of a reference type. Returns the prior default binding mode; this should be
+ /// followed by a call to [`PatMigration::leave_ref`] to restore it when we leave the pattern.
pub(super) fn visit_implicit_derefs<'tcx>(
&mut self,
pat_span: Span,
- adjustments: &[Ty<'tcx>],
+ adjustments: &[ty::adjustment::PatAdjustment<'tcx>],
) -> Option<(Span, Mutability)> {
- let implicit_deref_mutbls = adjustments.iter().map(|ref_ty| {
- let &ty::Ref(_, _, mutbl) = ref_ty.kind() else {
- span_bug!(pat_span, "pattern implicitly dereferences a non-ref type");
- };
- mutbl
+ // Implicitly dereferencing references changes the default binding mode, but implicit derefs
+ // of smart pointers do not. Thus, we only consider implicit derefs of reference types.
+ let implicit_deref_mutbls = adjustments.iter().filter_map(|adjust| {
+ if let &ty::Ref(_, _, mutbl) = adjust.source.kind() { Some(mutbl) } else { None }
});
if !self.info.suggest_eliding_modes {
diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs
index 73d60cf..8f058ef 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs
@@ -18,6 +18,7 @@
use rustc_middle::thir::{
Ascription, FieldPat, LocalVarId, Pat, PatKind, PatRange, PatRangeBoundary,
};
+use rustc_middle::ty::adjustment::{PatAdjust, PatAdjustment};
use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, TyCtxt, TypingMode};
use rustc_middle::{bug, span_bug};
@@ -63,13 +64,15 @@ pub(super) fn pat_from_hir<'a, 'tcx>(
impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
fn lower_pattern(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
- let adjustments: &[Ty<'tcx>] =
+ let adjustments: &[PatAdjustment<'tcx>] =
self.typeck_results.pat_adjustments().get(pat.hir_id).map_or(&[], |v| &**v);
// Track the default binding mode for the Rust 2024 migration suggestion.
+ // Implicitly dereferencing references changes the default binding mode, but implicit deref
+ // patterns do not. Only track binding mode changes if a ref type is in the adjustments.
let mut opt_old_mode_span = None;
if let Some(s) = &mut self.rust_2024_migration
- && !adjustments.is_empty()
+ && adjustments.iter().any(|adjust| adjust.kind == PatAdjust::BuiltinDeref)
{
opt_old_mode_span = s.visit_implicit_derefs(pat.span, adjustments);
}
@@ -102,17 +105,23 @@ fn lower_pattern(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
_ => self.lower_pattern_unadjusted(pat),
};
- let adjusted_pat = adjustments.iter().rev().fold(unadjusted_pat, |thir_pat, ref_ty| {
- debug!("{:?}: wrapping pattern with type {:?}", thir_pat, ref_ty);
- Box::new(Pat {
- span: thir_pat.span,
- ty: *ref_ty,
- kind: PatKind::Deref { subpattern: thir_pat },
- })
+ let adjusted_pat = adjustments.iter().rev().fold(unadjusted_pat, |thir_pat, adjust| {
+ debug!("{:?}: wrapping pattern with adjustment {:?}", thir_pat, adjust);
+ let span = thir_pat.span;
+ let kind = match adjust.kind {
+ PatAdjust::BuiltinDeref => PatKind::Deref { subpattern: thir_pat },
+ PatAdjust::OverloadedDeref => {
+ let mutable = self.typeck_results.pat_has_ref_mut_binding(pat);
+ let mutability =
+ if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };
+ PatKind::DerefPattern { subpattern: thir_pat, mutability }
+ }
+ };
+ Box::new(Pat { span, ty: adjust.source, kind })
});
if let Some(s) = &mut self.rust_2024_migration
- && !adjustments.is_empty()
+ && adjustments.iter().any(|adjust| adjust.kind == PatAdjust::BuiltinDeref)
{
s.leave_ref(opt_old_mode_span);
}
diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
index c436b8c..95f488a 100644
--- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
+++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs
@@ -109,27 +109,29 @@ fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Result<Self, ()> {
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));
for attr in rustc_mir_attrs {
- let attr_result = if attr.has_name(sym::borrowck_graphviz_postflow) {
- Self::set_field(&mut ret.basename_and_suffix, tcx, &attr, |s| {
- let path = PathBuf::from(s.to_string());
- match path.file_name() {
- Some(_) => Ok(path),
- None => {
- tcx.dcx().emit_err(PathMustEndInFilename { span: attr.span() });
+ let attr_result = match attr.name() {
+ Some(name @ sym::borrowck_graphviz_postflow) => {
+ Self::set_field(&mut ret.basename_and_suffix, tcx, name, &attr, |s| {
+ let path = PathBuf::from(s.to_string());
+ match path.file_name() {
+ Some(_) => Ok(path),
+ None => {
+ tcx.dcx().emit_err(PathMustEndInFilename { span: attr.span() });
+ Err(())
+ }
+ }
+ })
+ }
+ Some(name @ sym::borrowck_graphviz_format) => {
+ Self::set_field(&mut ret.formatter, tcx, name, &attr, |s| match s {
+ sym::two_phase => Ok(s),
+ _ => {
+ tcx.dcx().emit_err(UnknownFormatter { span: attr.span() });
Err(())
}
- }
- })
- } else if attr.has_name(sym::borrowck_graphviz_format) {
- Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
- sym::two_phase => Ok(s),
- _ => {
- tcx.dcx().emit_err(UnknownFormatter { span: attr.span() });
- Err(())
- }
- })
- } else {
- Ok(())
+ })
+ }
+ _ => Ok(()),
};
result = result.and(attr_result);
@@ -141,12 +143,12 @@ fn parse(tcx: TyCtxt<'_>, def_id: DefId) -> Result<Self, ()> {
fn set_field<T>(
field: &mut Option<T>,
tcx: TyCtxt<'_>,
+ name: Symbol,
attr: &ast::MetaItemInner,
mapper: impl FnOnce(Symbol) -> Result<T, ()>,
) -> Result<(), ()> {
if field.is_some() {
- tcx.dcx()
- .emit_err(DuplicateValuesFor { span: attr.span(), name: attr.name_or_empty() });
+ tcx.dcx().emit_err(DuplicateValuesFor { span: attr.span(), name });
return Err(());
}
@@ -156,7 +158,7 @@ fn set_field<T>(
Ok(())
} else {
tcx.dcx()
- .emit_err(RequiresAnArgument { span: attr.span(), name: attr.name_or_empty() });
+ .emit_err(RequiresAnArgument { span: attr.span(), name: attr.name().unwrap() });
Err(())
}
}
diff --git a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
index d49f5d9..c7feb9e 100644
--- a/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
+++ b/compiler/rustc_mir_transform/src/early_otherwise_branch.rs
@@ -223,7 +223,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// Since this optimization adds new basic blocks and invalidates others,
// clean up the cfg to make it nicer for other passes
if should_cleanup {
- simplify_cfg(body);
+ simplify_cfg(tcx, body);
}
}
diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs
index 69e80ed..c573219 100644
--- a/compiler/rustc_mir_transform/src/inline.rs
+++ b/compiler/rustc_mir_transform/src/inline.rs
@@ -63,7 +63,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let _guard = span.enter();
if inline::<NormalInliner<'tcx>>(tcx, body) {
debug!("running simplify cfg on {:?}", body.source);
- simplify_cfg(body);
+ simplify_cfg(tcx, body);
deref_finder(tcx, body);
}
}
@@ -99,7 +99,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let _guard = span.enter();
if inline::<ForceInliner<'tcx>>(tcx, body) {
debug!("running simplify cfg on {:?}", body.source);
- simplify_cfg(body);
+ simplify_cfg(tcx, body);
deref_finder(tcx, body);
}
}
diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs
index 5059837..b372411 100644
--- a/compiler/rustc_mir_transform/src/match_branches.rs
+++ b/compiler/rustc_mir_transform/src/match_branches.rs
@@ -43,7 +43,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
}
if should_cleanup {
- simplify_cfg(body);
+ simplify_cfg(tcx, body);
}
}
diff --git a/compiler/rustc_mir_transform/src/remove_place_mention.rs b/compiler/rustc_mir_transform/src/remove_place_mention.rs
index 15fe77d..cb598ce 100644
--- a/compiler/rustc_mir_transform/src/remove_place_mention.rs
+++ b/compiler/rustc_mir_transform/src/remove_place_mention.rs
@@ -8,7 +8,7 @@
impl<'tcx> crate::MirPass<'tcx> for RemovePlaceMention {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
- !sess.opts.unstable_opts.mir_keep_place_mention
+ !sess.opts.unstable_opts.mir_preserve_ub
}
fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
diff --git a/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs
index 8a8cdaf..43f8050 100644
--- a/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs
+++ b/compiler/rustc_mir_transform/src/remove_unneeded_drops.rs
@@ -35,7 +35,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// if we applied optimizations, we potentially have some cfg to cleanup to
// make it easier for further passes
if should_simplify {
- simplify_cfg(body);
+ simplify_cfg(tcx, body);
}
}
diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs
index 5947637..4f2cce8 100644
--- a/compiler/rustc_mir_transform/src/simplify.rs
+++ b/compiler/rustc_mir_transform/src/simplify.rs
@@ -26,6 +26,13 @@
//! Here the block (`{ return; }`) has the return type `char`, rather than `()`, but the MIR we
//! naively generate still contains the `_a = ()` write in the unreachable block "after" the
//! return.
+//!
+//! **WARNING**: This is one of the few optimizations that runs on built and analysis MIR, and
+//! so its effects may affect the type-checking, borrow-checking, and other analysis of MIR.
+//! We must be extremely careful to only apply optimizations that preserve UB and all
+//! non-determinism, since changes here can affect which programs compile in an insta-stable way.
+//! The normal logic that a program with UB can be changed to do anything does not apply to
+//! pre-"runtime" MIR!
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
@@ -66,8 +73,8 @@ fn name(&self) -> &'static str {
}
}
-pub(super) fn simplify_cfg(body: &mut Body<'_>) {
- CfgSimplifier::new(body).simplify();
+pub(super) fn simplify_cfg<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+ CfgSimplifier::new(tcx, body).simplify();
remove_dead_blocks(body);
// FIXME: Should probably be moved into some kind of pass manager
@@ -79,9 +86,9 @@ fn name(&self) -> &'static str {
self.name()
}
- fn run_pass(&self, _: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!("SimplifyCfg({:?}) - simplifying {:?}", self.name(), body.source);
- simplify_cfg(body);
+ simplify_cfg(tcx, body);
}
fn is_required(&self) -> bool {
@@ -90,12 +97,13 @@ fn is_required(&self) -> bool {
}
struct CfgSimplifier<'a, 'tcx> {
+ preserve_switch_reads: bool,
basic_blocks: &'a mut IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
pred_count: IndexVec<BasicBlock, u32>,
}
impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
- fn new(body: &'a mut Body<'tcx>) -> Self {
+ fn new(tcx: TyCtxt<'tcx>, body: &'a mut Body<'tcx>) -> Self {
let mut pred_count = IndexVec::from_elem(0u32, &body.basic_blocks);
// we can't use mir.predecessors() here because that counts
@@ -110,9 +118,12 @@ fn new(body: &'a mut Body<'tcx>) -> Self {
}
}
+ // Preserve `SwitchInt` reads on built and analysis MIR, or if `-Zmir-preserve-ub`.
+ let preserve_switch_reads = matches!(body.phase, MirPhase::Built | MirPhase::Analysis(_))
+ || tcx.sess.opts.unstable_opts.mir_preserve_ub;
let basic_blocks = body.basic_blocks_mut();
- CfgSimplifier { basic_blocks, pred_count }
+ CfgSimplifier { preserve_switch_reads, basic_blocks, pred_count }
}
fn simplify(mut self) {
@@ -253,9 +264,15 @@ fn merge_successor(
// turn a branch with all successors identical to a goto
fn simplify_branch(&mut self, terminator: &mut Terminator<'tcx>) -> bool {
- match terminator.kind {
- TerminatorKind::SwitchInt { .. } => {}
- _ => return false,
+ // Removing a `SwitchInt` terminator may remove reads that result in UB,
+ // so we must not apply this optimization before borrowck or when
+ // `-Zmir-preserve-ub` is set.
+ if self.preserve_switch_reads {
+ return false;
+ }
+
+ let TerminatorKind::SwitchInt { .. } = terminator.kind else {
+ return false;
};
let first_succ = {
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index df44b3c..71cc814 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1884,13 +1884,15 @@ fn parse_expr_break(&mut self) -> PResult<'a, P<Expr>> {
let mut expr = self.parse_expr_opt()?;
if let Some(expr) = &mut expr {
if label.is_some()
- && matches!(
- expr.kind,
+ && match &expr.kind {
ExprKind::While(_, _, None)
- | ExprKind::ForLoop { label: None, .. }
- | ExprKind::Loop(_, None, _)
- | ExprKind::Block(_, None)
- )
+ | ExprKind::ForLoop { label: None, .. }
+ | ExprKind::Loop(_, None, _) => true,
+ ExprKind::Block(block, None) => {
+ matches!(block.rules, BlockCheckMode::Default)
+ }
+ _ => false,
+ }
{
self.psess.buffer_lint(
BREAK_WITH_LABEL_AND_LOOP,
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl
index 6ee5e35..99789b7 100644
--- a/compiler/rustc_passes/messages.ftl
+++ b/compiler/rustc_passes/messages.ftl
@@ -404,7 +404,7 @@
passes_invalid_attr_at_crate_level_item =
the inner attribute doesn't annotate this {$kind}
-passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
+passes_invalid_macro_export_arguments = invalid `#[macro_export]` argument
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments
@@ -771,8 +771,8 @@
.label_orig = any code following this expression is unreachable
.note = this expression has type `{$ty}`, which is uninhabited
-passes_unrecognized_field =
- unrecognized field name `{$name}`
+passes_unrecognized_argument =
+ unrecognized argument
passes_unstable_attr_for_already_stable_feature =
can't mark as unstable using an already stable feature
diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs
index 671b7d7..b139ed6 100644
--- a/compiler/rustc_passes/src/abi_test.rs
+++ b/compiler/rustc_passes/src/abi_test.rs
@@ -9,7 +9,7 @@
use rustc_target::callconv::FnAbi;
use super::layout_test::ensure_wf;
-use crate::errors::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedField};
+use crate::errors::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedArgument};
pub fn test_abi(tcx: TyCtxt<'_>) {
if !tcx.features().rustc_attrs() {
@@ -77,8 +77,8 @@ fn dump_abi_of_fn_item(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
// The `..` are the names of fields to dump.
let meta_items = attr.meta_item_list().unwrap_or_default();
for meta_item in meta_items {
- match meta_item.name_or_empty() {
- sym::debug => {
+ match meta_item.name() {
+ Some(sym::debug) => {
let fn_name = tcx.item_name(item_def_id.into());
tcx.dcx().emit_err(AbiOf {
span: tcx.def_span(item_def_id),
@@ -88,8 +88,8 @@ fn dump_abi_of_fn_item(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
});
}
- name => {
- tcx.dcx().emit_err(UnrecognizedField { span: meta_item.span(), name });
+ _ => {
+ tcx.dcx().emit_err(UnrecognizedArgument { span: meta_item.span() });
}
}
}
@@ -118,8 +118,8 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
}
let meta_items = attr.meta_item_list().unwrap_or_default();
for meta_item in meta_items {
- match meta_item.name_or_empty() {
- sym::debug => {
+ match meta_item.name() {
+ Some(sym::debug) => {
let ty::FnPtr(sig_tys, hdr) = ty.kind() else {
span_bug!(
meta_item.span(),
@@ -138,7 +138,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
let fn_name = tcx.item_name(item_def_id.into());
tcx.dcx().emit_err(AbiOf { span, fn_name, fn_abi: format!("{:#?}", abi) });
}
- sym::assert_eq => {
+ Some(sym::assert_eq) => {
let ty::Tuple(fields) = ty.kind() else {
span_bug!(
meta_item.span(),
@@ -188,8 +188,8 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
});
}
}
- name => {
- tcx.dcx().emit_err(UnrecognizedField { span: meta_item.span(), name });
+ _ => {
+ tcx.dcx().emit_err(UnrecognizedArgument { span: meta_item.span() });
}
}
}
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 4227925..cbe5058 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -523,9 +523,9 @@ fn check_optimize(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Ta
fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
if let Some(list) = attr.meta_item_list() {
for item in list.iter() {
- let sym = item.name_or_empty();
+ let sym = item.name();
match sym {
- sym::address | sym::hwaddress => {
+ Some(s @ sym::address | s @ sym::hwaddress) => {
let is_valid =
matches!(target, Target::Fn | Target::Method(..) | Target::Static);
if !is_valid {
@@ -533,7 +533,7 @@ fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
attr_span: item.span(),
defn_span: span,
accepted_kind: "a function or static",
- attr_str: sym.as_str(),
+ attr_str: s.as_str(),
});
}
}
@@ -544,7 +544,10 @@ fn check_no_sanitize(&self, attr: &Attribute, span: Span, target: Target) {
attr_span: item.span(),
defn_span: span,
accepted_kind: "a function",
- attr_str: sym.as_str(),
+ attr_str: &match sym {
+ Some(name) => name.to_string(),
+ None => "...".to_string(),
+ },
});
}
}
@@ -561,12 +564,15 @@ fn check_generic_attr(
allowed_target: Target,
) {
if target != allowed_target {
+ let path = attr.path();
+ let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
+ let attr_name = path.join("::");
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span(),
errors::OnlyHasEffectOn {
- attr_name: attr.name_or_empty(),
+ attr_name,
target_name: allowed_target.name().replace(' ', "_"),
},
);
@@ -589,7 +595,8 @@ fn check_naked(
// * `#[track_caller]`
// * `#[test]`, `#[ignore]`, `#[should_panic]`
//
- // NOTE: when making changes to this list, check that `error_codes/E0736.md` remains accurate
+ // NOTE: when making changes to this list, check that `error_codes/E0736.md` remains
+ // accurate.
const ALLOW_LIST: &[rustc_span::Symbol] = &[
// conditional compilation
sym::cfg_trace,
@@ -672,11 +679,11 @@ fn check_naked(
}
}
- if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
+ if !other_attr.has_any_name(ALLOW_LIST) {
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
span: other_attr.span(),
naked_span: attr.span(),
- attr: other_attr.name_or_empty(),
+ attr: other_attr.name().unwrap(),
});
return;
@@ -1150,7 +1157,7 @@ fn check_doc_inline(
) {
match target {
Target::Use | Target::ExternCrate => {
- let do_inline = meta.name_or_empty() == sym::inline;
+ let do_inline = meta.has_name(sym::inline);
if let Some((prev_inline, prev_span)) = *specified_inline {
if do_inline != prev_inline {
let mut spans = MultiSpan::from_spans(vec![prev_span, meta.span()]);
@@ -1260,8 +1267,8 @@ fn check_attr_crate_level(
fn check_test_attr(&self, meta: &MetaItemInner, hir_id: HirId) {
if let Some(metas) = meta.meta_item_list() {
for i_meta in metas {
- match (i_meta.name_or_empty(), i_meta.meta_item()) {
- (sym::attr | sym::no_crate_inject, _) => {}
+ match (i_meta.name(), i_meta.meta_item()) {
+ (Some(sym::attr | sym::no_crate_inject), _) => {}
(_, Some(m)) => {
self.tcx.emit_node_span_lint(
INVALID_DOC_ATTRIBUTES,
@@ -1322,61 +1329,63 @@ fn check_doc_attrs(
if let Some(list) = attr.meta_item_list() {
for meta in &list {
if let Some(i_meta) = meta.meta_item() {
- match i_meta.name_or_empty() {
- sym::alias => {
+ match i_meta.name() {
+ Some(sym::alias) => {
if self.check_attr_not_crate_level(meta, hir_id, "alias") {
self.check_doc_alias(meta, hir_id, target, aliases);
}
}
- sym::keyword => {
+ Some(sym::keyword) => {
if self.check_attr_not_crate_level(meta, hir_id, "keyword") {
self.check_doc_keyword(meta, hir_id);
}
}
- sym::fake_variadic => {
+ Some(sym::fake_variadic) => {
if self.check_attr_not_crate_level(meta, hir_id, "fake_variadic") {
self.check_doc_fake_variadic(meta, hir_id);
}
}
- sym::search_unbox => {
+ Some(sym::search_unbox) => {
if self.check_attr_not_crate_level(meta, hir_id, "fake_variadic") {
self.check_doc_search_unbox(meta, hir_id);
}
}
- sym::test => {
+ Some(sym::test) => {
if self.check_attr_crate_level(attr, meta, hir_id) {
self.check_test_attr(meta, hir_id);
}
}
- sym::html_favicon_url
- | sym::html_logo_url
- | sym::html_playground_url
- | sym::issue_tracker_base_url
- | sym::html_root_url
- | sym::html_no_source => {
+ Some(
+ sym::html_favicon_url
+ | sym::html_logo_url
+ | sym::html_playground_url
+ | sym::issue_tracker_base_url
+ | sym::html_root_url
+ | sym::html_no_source,
+ ) => {
self.check_attr_crate_level(attr, meta, hir_id);
}
- sym::cfg_hide => {
+ Some(sym::cfg_hide) => {
if self.check_attr_crate_level(attr, meta, hir_id) {
self.check_doc_cfg_hide(meta, hir_id);
}
}
- sym::inline | sym::no_inline => {
+ Some(sym::inline | sym::no_inline) => {
self.check_doc_inline(attr, meta, hir_id, target, specified_inline)
}
- sym::masked => self.check_doc_masked(attr, meta, hir_id, target),
+ Some(sym::masked) => self.check_doc_masked(attr, meta, hir_id, target),
- sym::cfg | sym::hidden | sym::notable_trait => {}
+ Some(sym::cfg | sym::hidden | sym::notable_trait) => {}
- sym::rust_logo => {
+ Some(sym::rust_logo) => {
if self.check_attr_crate_level(attr, meta, hir_id)
&& !self.tcx.features().rustdoc_internals()
{
@@ -2299,7 +2308,7 @@ fn check_deprecated(&self, hir_id: HirId, attr: &Attribute, _span: Span, target:
}
fn check_macro_use(&self, hir_id: HirId, attr: &Attribute, target: Target) {
- let name = attr.name_or_empty();
+ let name = attr.name().unwrap();
match target {
Target::ExternCrate | Target::Mod => {}
_ => {
@@ -2331,12 +2340,12 @@ fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) {
attr.span(),
errors::MacroExport::TooManyItems,
);
- } else if meta_item_list[0].name_or_empty() != sym::local_inner_macros {
+ } else if !meta_item_list[0].has_name(sym::local_inner_macros) {
self.tcx.emit_node_span_lint(
INVALID_MACRO_EXPORT_ARGUMENTS,
hir_id,
meta_item_list[0].span(),
- errors::MacroExport::UnknownItem { name: meta_item_list[0].name_or_empty() },
+ errors::MacroExport::InvalidArgument,
);
}
} else {
@@ -2381,33 +2390,28 @@ fn check_unused_attribute(&self, hir_id: HirId, attr: &Attribute) {
}
// Warn on useless empty attributes.
- let note = if (matches!(
- attr.name_or_empty(),
- sym::macro_use
- | sym::allow
- | sym::expect
- | sym::warn
- | sym::deny
- | sym::forbid
- | sym::feature
- | sym::target_feature
- ) && attr.meta_item_list().is_some_and(|list| list.is_empty()))
+ let note = if attr.has_any_name(&[
+ sym::macro_use,
+ sym::allow,
+ sym::expect,
+ sym::warn,
+ sym::deny,
+ sym::forbid,
+ sym::feature,
+ sym::target_feature,
+ ]) && attr.meta_item_list().is_some_and(|list| list.is_empty())
{
- errors::UnusedNote::EmptyList { name: attr.name_or_empty() }
- } else if matches!(
- attr.name_or_empty(),
- sym::allow | sym::warn | sym::deny | sym::forbid | sym::expect
- ) && let Some(meta) = attr.meta_item_list()
+ errors::UnusedNote::EmptyList { name: attr.name().unwrap() }
+ } else if attr.has_any_name(&[sym::allow, sym::warn, sym::deny, sym::forbid, sym::expect])
+ && let Some(meta) = attr.meta_item_list()
&& let [meta] = meta.as_slice()
&& let Some(item) = meta.meta_item()
&& let MetaItemKind::NameValue(_) = &item.kind
&& item.path == sym::reason
{
- errors::UnusedNote::NoLints { name: attr.name_or_empty() }
- } else if matches!(
- attr.name_or_empty(),
- sym::allow | sym::warn | sym::deny | sym::forbid | sym::expect
- ) && let Some(meta) = attr.meta_item_list()
+ errors::UnusedNote::NoLints { name: attr.name().unwrap() }
+ } else if attr.has_any_name(&[sym::allow, sym::warn, sym::deny, sym::forbid, sym::expect])
+ && let Some(meta) = attr.meta_item_list()
&& meta.iter().any(|meta| {
meta.meta_item().map_or(false, |item| item.path == sym::linker_messages)
})
@@ -2440,7 +2444,7 @@ fn check_unused_attribute(&self, hir_id: HirId, attr: &Attribute) {
return;
}
}
- } else if attr.name_or_empty() == sym::default_method_body_is_const {
+ } else if attr.has_name(sym::default_method_body_is_const) {
errors::UnusedNote::DefaultMethodBodyConst
} else {
return;
@@ -2897,10 +2901,11 @@ fn check_duplicates(
if matches!(duplicates, WarnFollowingWordOnly) && !attr.is_word() {
return;
}
+ let attr_name = attr.name().unwrap();
match duplicates {
DuplicatesOk => {}
WarnFollowing | FutureWarnFollowing | WarnFollowingWordOnly | FutureWarnPreceding => {
- match seen.entry(attr.name_or_empty()) {
+ match seen.entry(attr_name) {
Entry::Occupied(mut entry) => {
let (this, other) = if matches!(duplicates, FutureWarnPreceding) {
let to_remove = entry.insert(attr.span());
@@ -2927,7 +2932,7 @@ fn check_duplicates(
}
}
}
- ErrorFollowing | ErrorPreceding => match seen.entry(attr.name_or_empty()) {
+ ErrorFollowing | ErrorPreceding => match seen.entry(attr_name) {
Entry::Occupied(mut entry) => {
let (this, other) = if matches!(duplicates, ErrorPreceding) {
let to_remove = entry.insert(attr.span());
@@ -2935,11 +2940,7 @@ fn check_duplicates(
} else {
(attr.span(), *entry.get())
};
- tcx.dcx().emit_err(errors::UnusedMultiple {
- this,
- other,
- name: attr.name_or_empty(),
- });
+ tcx.dcx().emit_err(errors::UnusedMultiple { this, other, name: attr_name });
}
Entry::Vacant(entry) => {
entry.insert(attr.span());
diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs
index 062d56a..7a7a817 100644
--- a/compiler/rustc_passes/src/debugger_visualizer.rs
+++ b/compiler/rustc_passes/src/debugger_visualizer.rs
@@ -28,17 +28,17 @@ fn check_for_debugger_visualizer(&mut self, attr: &Attribute) {
return;
};
- let (visualizer_type, visualizer_path) =
- match (meta_item.name_or_empty(), meta_item.value_str()) {
- (sym::natvis_file, Some(value)) => (DebuggerVisualizerType::Natvis, value),
- (sym::gdb_script_file, Some(value)) => {
- (DebuggerVisualizerType::GdbPrettyPrinter, value)
- }
- (_, _) => {
- self.sess.dcx().emit_err(DebugVisualizerInvalid { span: meta_item.span });
- return;
- }
- };
+ let (visualizer_type, visualizer_path) = match (meta_item.name(), meta_item.value_str())
+ {
+ (Some(sym::natvis_file), Some(value)) => (DebuggerVisualizerType::Natvis, value),
+ (Some(sym::gdb_script_file), Some(value)) => {
+ (DebuggerVisualizerType::GdbPrettyPrinter, value)
+ }
+ (_, _) => {
+ self.sess.dcx().emit_err(DebugVisualizerInvalid { span: meta_item.span });
+ return;
+ }
+ };
let file = match resolve_path(&self.sess, visualizer_path.as_str(), attr.span) {
Ok(file) => file,
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs
index 995fc85..4052264 100644
--- a/compiler/rustc_passes/src/errors.rs
+++ b/compiler/rustc_passes/src/errors.rs
@@ -756,7 +756,7 @@ pub(crate) enum MacroExport {
OnDeclMacro,
#[diag(passes_invalid_macro_export_arguments)]
- UnknownItem { name: Symbol },
+ InvalidArgument,
#[diag(passes_invalid_macro_export_arguments_too_many_items)]
TooManyItems,
@@ -1045,11 +1045,10 @@ pub(crate) struct AbiInvalidAttribute {
}
#[derive(Diagnostic)]
-#[diag(passes_unrecognized_field)]
-pub(crate) struct UnrecognizedField {
+#[diag(passes_unrecognized_argument)]
+pub(crate) struct UnrecognizedArgument {
#[primary_span]
pub span: Span,
- pub name: Symbol,
}
#[derive(Diagnostic)]
@@ -1433,7 +1432,7 @@ pub(crate) struct UselessAssignment<'a> {
#[derive(LintDiagnostic)]
#[diag(passes_only_has_effect_on)]
pub(crate) struct OnlyHasEffectOn {
- pub attr_name: Symbol,
+ pub attr_name: String,
pub target_name: String,
}
diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs
index d4512c9..a19faf0 100644
--- a/compiler/rustc_passes/src/layout_test.rs
+++ b/compiler/rustc_passes/src/layout_test.rs
@@ -13,7 +13,7 @@
use crate::errors::{
LayoutAbi, LayoutAlign, LayoutHomogeneousAggregate, LayoutInvalidAttribute, LayoutOf,
- LayoutSize, UnrecognizedField,
+ LayoutSize, UnrecognizedArgument,
};
pub fn test_layout(tcx: TyCtxt<'_>) {
@@ -79,28 +79,28 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
// The `..` are the names of fields to dump.
let meta_items = attr.meta_item_list().unwrap_or_default();
for meta_item in meta_items {
- match meta_item.name_or_empty() {
+ match meta_item.name() {
// FIXME: this never was about ABI and now this dump arg is confusing
- sym::abi => {
+ Some(sym::abi) => {
tcx.dcx().emit_err(LayoutAbi {
span,
abi: format!("{:?}", ty_layout.backend_repr),
});
}
- sym::align => {
+ Some(sym::align) => {
tcx.dcx().emit_err(LayoutAlign {
span,
align: format!("{:?}", ty_layout.align),
});
}
- sym::size => {
+ Some(sym::size) => {
tcx.dcx()
.emit_err(LayoutSize { span, size: format!("{:?}", ty_layout.size) });
}
- sym::homogeneous_aggregate => {
+ Some(sym::homogeneous_aggregate) => {
tcx.dcx().emit_err(LayoutHomogeneousAggregate {
span,
homogeneous_aggregate: format!(
@@ -111,15 +111,15 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
});
}
- sym::debug => {
+ Some(sym::debug) => {
let normalized_ty = tcx.normalize_erasing_regions(typing_env, ty);
// FIXME: using the `Debug` impl here isn't ideal.
let ty_layout = format!("{:#?}", *ty_layout);
tcx.dcx().emit_err(LayoutOf { span, normalized_ty, ty_layout });
}
- name => {
- tcx.dcx().emit_err(UnrecognizedField { span: meta_item.span(), name });
+ _ => {
+ tcx.dcx().emit_err(UnrecognizedArgument { span: meta_item.span() });
}
}
}
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index 1b0794f..36eee5f 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -2322,12 +2322,12 @@ pub(crate) fn parse_align(slot: &mut Option<Align>, v: Option<&str>) -> bool {
mir_include_spans: MirIncludeSpans = (MirIncludeSpans::default(), parse_mir_include_spans, [UNTRACKED],
"include extra comments in mir pretty printing, like line numbers and statement indices, \
details about types, etc. (boolean for all passes, 'nll' to enable in NLL MIR only, default: 'nll')"),
- mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
- "keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
- (default: no)"),
#[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")]
mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
"MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
+ mir_preserve_ub: bool = (false, parse_bool, [TRACKED],
+ "keep place mention statements and reads in trivial SwitchInt terminators, which are interpreted \
+ e.g., by miri; implies -Zmir-opt-level=0 (default: no)"),
mir_strip_debuginfo: MirStripDebugInfo = (MirStripDebugInfo::None, parse_mir_strip_debuginfo, [TRACKED],
"Whether to remove some of the MIR debug info from methods. Default: None"),
move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 8f75cc5..f7b10d3 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -1186,6 +1186,7 @@
instruction_set,
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
integral,
+ internal_features,
into_async_iter_into_iter,
into_future,
into_iter,
@@ -2216,7 +2217,6 @@
unsafe_extern_blocks,
unsafe_fields,
unsafe_no_drop_flag,
- unsafe_pin_internals,
unsafe_pinned,
unsafe_unpin,
unsize,
diff --git a/compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs b/compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs
index 233a1c4..91ab311 100644
--- a/compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs
+++ b/compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs
@@ -7,6 +7,12 @@ pub(crate) fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
+ // On Windows 7 32-bit, the alignment characteristic of the TLS Directory
+ // don't appear to be respected by the PE Loader, leading to crashes. As
+ // a result, let's disable has_thread_local to make sure TLS goes through
+ // the emulation layer.
+ // See https://github.com/rust-lang/rust/issues/138903
+ base.has_thread_local = false;
base.add_pre_link_args(
LinkerFlavor::Msvc(Lld::No),
diff --git a/diff b/diff
deleted file mode 100644
index e69de29..0000000
--- a/diff
+++ /dev/null
diff --git a/library/Cargo.lock b/library/Cargo.lock
index 29e0e13..e4f1c4e 100644
--- a/library/Cargo.lock
+++ b/library/Cargo.lock
@@ -67,9 +67,9 @@
[[package]]
name = "compiler_builtins"
-version = "0.1.153"
+version = "0.1.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "926ef6a360c15a911023352fd6969c51605d70495406f735beb1ca0257448e59"
+checksum = "341e0830ca6170a4fcf02e92e57daf4b6f10142d48da32a547023867a6c8b35e"
dependencies = [
"cc",
"rustc-std-workspace-core",
diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml
index ee8cb9d..cedbd33 100644
--- a/library/alloc/Cargo.toml
+++ b/library/alloc/Cargo.toml
@@ -16,7 +16,7 @@
[dependencies]
core = { path = "../core", public = true }
-compiler_builtins = { version = "=0.1.153", features = ['rustc-dep-of-std'] }
+compiler_builtins = { version = "=0.1.155", features = ['rustc-dep-of-std'] }
[features]
compiler-builtins-mem = ['compiler_builtins/mem']
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs
index f6743c6..ef8548d 100644
--- a/library/alloc/src/ffi/c_str.rs
+++ b/library/alloc/src/ffi/c_str.rs
@@ -1116,7 +1116,7 @@ impl CStr {
/// with the corresponding <code>&[str]</code> slice. Otherwise, it will
/// replace any invalid UTF-8 sequences with
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
- /// <code>[Cow]::[Owned]\(&[str])</code> with the result.
+ /// <code>[Cow]::[Owned]\([String])</code> with the result.
///
/// [str]: prim@str "str"
/// [Borrowed]: Cow::Borrowed
diff --git a/library/core/src/iter/adapters/enumerate.rs b/library/core/src/iter/adapters/enumerate.rs
index bd093e2..f7b9f0b 100644
--- a/library/core/src/iter/adapters/enumerate.rs
+++ b/library/core/src/iter/adapters/enumerate.rs
@@ -23,6 +23,39 @@ impl<I> Enumerate<I> {
pub(in crate::iter) fn new(iter: I) -> Enumerate<I> {
Enumerate { iter, count: 0 }
}
+
+ /// Retrieve the current position of the iterator.
+ ///
+ /// If the iterator has not advanced, the position returned will be 0.
+ ///
+ /// The position may also exceed the bounds of the iterator to allow for calculating
+ /// the displacement of the iterator from following calls to [`Iterator::next`].
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(next_index)]
+ ///
+ /// let arr = ['a', 'b'];
+ ///
+ /// let mut iter = arr.iter().enumerate();
+ ///
+ /// assert_eq!(iter.next_index(), 0);
+ /// assert_eq!(iter.next(), Some((0, &'a')));
+ ///
+ /// assert_eq!(iter.next_index(), 1);
+ /// assert_eq!(iter.next_index(), 1);
+ /// assert_eq!(iter.next(), Some((1, &'b')));
+ ///
+ /// assert_eq!(iter.next_index(), 2);
+ /// assert_eq!(iter.next(), None);
+ /// assert_eq!(iter.next_index(), 2);
+ /// ```
+ #[inline]
+ #[unstable(feature = "next_index", issue = "130711")]
+ pub fn next_index(&self) -> usize {
+ self.count
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]
diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs
index 48ed5ae..9e6acf0 100644
--- a/library/core/src/pin.rs
+++ b/library/core/src/pin.rs
@@ -1092,24 +1092,15 @@
#[rustc_pub_transparent]
#[derive(Copy, Clone)]
pub struct Pin<Ptr> {
- // FIXME(#93176): this field is made `#[unstable] #[doc(hidden)] pub` to:
- // - deter downstream users from accessing it (which would be unsound!),
- // - let the `pin!` macro access it (such a macro requires using struct
- // literal syntax in order to benefit from lifetime extension).
- //
- // However, if the `Deref` impl exposes a field with the same name as this
- // field, then the two will collide, resulting in a confusing error when the
- // user attempts to access the field through a `Pin<Ptr>`. Therefore, the
- // name `__pointer` is designed to be unlikely to collide with any other
- // field. Long-term, macro hygiene is expected to offer a more robust
- // alternative, alongside `unsafe` fields.
- #[unstable(feature = "unsafe_pin_internals", issue = "none")]
- #[doc(hidden)]
- pub __pointer: Ptr,
+ /// Only public for bootstrap.
+ #[cfg(bootstrap)]
+ pub pointer: Ptr,
+ #[cfg(not(bootstrap))]
+ pointer: Ptr,
}
// The following implementations aren't derived in order to avoid soundness
-// issues. `&self.__pointer` should not be accessible to untrusted trait
+// issues. `&self.pointer` should not be accessible to untrusted trait
// implementations.
//
// See <https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73> for more details.
@@ -1223,7 +1214,7 @@ pub const fn new(pointer: Ptr) -> Pin<Ptr> {
#[rustc_const_stable(feature = "const_pin", since = "1.84.0")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
pub const fn into_inner(pin: Pin<Ptr>) -> Ptr {
- pin.__pointer
+ pin.pointer
}
}
@@ -1360,7 +1351,7 @@ impl<Ptr: Deref> Pin<Ptr> {
#[rustc_const_stable(feature = "const_pin", since = "1.84.0")]
#[stable(feature = "pin", since = "1.33.0")]
pub const unsafe fn new_unchecked(pointer: Ptr) -> Pin<Ptr> {
- Pin { __pointer: pointer }
+ Pin { pointer }
}
/// Gets a shared reference to the pinned value this [`Pin`] points to.
@@ -1374,7 +1365,7 @@ impl<Ptr: Deref> Pin<Ptr> {
#[inline(always)]
pub fn as_ref(&self) -> Pin<&Ptr::Target> {
// SAFETY: see documentation on this function
- unsafe { Pin::new_unchecked(&*self.__pointer) }
+ unsafe { Pin::new_unchecked(&*self.pointer) }
}
}
@@ -1418,7 +1409,7 @@ impl<Ptr: DerefMut> Pin<Ptr> {
#[inline(always)]
pub fn as_mut(&mut self) -> Pin<&mut Ptr::Target> {
// SAFETY: see documentation on this function
- unsafe { Pin::new_unchecked(&mut *self.__pointer) }
+ unsafe { Pin::new_unchecked(&mut *self.pointer) }
}
/// Gets `Pin<&mut T>` to the underlying pinned value from this nested `Pin`-pointer.
@@ -1485,7 +1476,7 @@ pub fn set(&mut self, value: Ptr::Target)
where
Ptr::Target: Sized,
{
- *(self.__pointer) = value;
+ *(self.pointer) = value;
}
}
@@ -1513,7 +1504,7 @@ impl<Ptr: Deref> Pin<Ptr> {
#[rustc_const_stable(feature = "const_pin", since = "1.84.0")]
#[stable(feature = "pin_into_inner", since = "1.39.0")]
pub const unsafe fn into_inner_unchecked(pin: Pin<Ptr>) -> Ptr {
- pin.__pointer
+ pin.pointer
}
}
@@ -1539,7 +1530,7 @@ pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
U: ?Sized,
F: FnOnce(&T) -> &U,
{
- let pointer = &*self.__pointer;
+ let pointer = &*self.pointer;
let new_pointer = func(pointer);
// SAFETY: the safety contract for `new_unchecked` must be
@@ -1569,7 +1560,7 @@ pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
#[rustc_const_stable(feature = "const_pin", since = "1.84.0")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn get_ref(self) -> &'a T {
- self.__pointer
+ self.pointer
}
}
@@ -1580,7 +1571,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
#[rustc_const_stable(feature = "const_pin", since = "1.84.0")]
#[stable(feature = "pin", since = "1.33.0")]
pub const fn into_ref(self) -> Pin<&'a T> {
- Pin { __pointer: self.__pointer }
+ Pin { pointer: self.pointer }
}
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -1600,7 +1591,7 @@ pub const fn get_mut(self) -> &'a mut T
where
T: Unpin,
{
- self.__pointer
+ self.pointer
}
/// Gets a mutable reference to the data inside of this `Pin`.
@@ -1618,7 +1609,7 @@ pub const fn get_mut(self) -> &'a mut T
#[stable(feature = "pin", since = "1.33.0")]
#[rustc_const_stable(feature = "const_pin", since = "1.84.0")]
pub const unsafe fn get_unchecked_mut(self) -> &'a mut T {
- self.__pointer
+ self.pointer
}
/// Constructs a new pin by mapping the interior value.
@@ -1705,21 +1696,21 @@ impl<Ptr: LegacyReceiver> LegacyReceiver for Pin<Ptr> {}
#[stable(feature = "pin", since = "1.33.0")]
impl<Ptr: fmt::Debug> fmt::Debug for Pin<Ptr> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt::Debug::fmt(&self.__pointer, f)
+ fmt::Debug::fmt(&self.pointer, f)
}
}
#[stable(feature = "pin", since = "1.33.0")]
impl<Ptr: fmt::Display> fmt::Display for Pin<Ptr> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt::Display::fmt(&self.__pointer, f)
+ fmt::Display::fmt(&self.pointer, f)
}
}
#[stable(feature = "pin", since = "1.33.0")]
impl<Ptr: fmt::Pointer> fmt::Pointer for Pin<Ptr> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- fmt::Pointer::fmt(&self.__pointer, f)
+ fmt::Pointer::fmt(&self.pointer, f)
}
}
@@ -1945,80 +1936,22 @@ unsafe impl<T: ?Sized> PinCoerceUnsized for *mut T {}
/// constructor.
///
/// [`Box::pin`]: ../../std/boxed/struct.Box.html#method.pin
+#[cfg(not(bootstrap))]
#[stable(feature = "pin_macro", since = "1.68.0")]
#[rustc_macro_transparency = "semitransparent"]
-#[allow_internal_unstable(unsafe_pin_internals)]
-#[rustc_macro_edition_2021]
+#[allow_internal_unstable(super_let)]
pub macro pin($value:expr $(,)?) {
- // This is `Pin::new_unchecked(&mut { $value })`, so, for starters, let's
- // review such a hypothetical macro (that any user-code could define):
- //
- // ```rust
- // macro_rules! pin {( $value:expr ) => (
- // match &mut { $value } { at_value => unsafe { // Do not wrap `$value` in an `unsafe` block.
- // $crate::pin::Pin::<&mut _>::new_unchecked(at_value)
- // }}
- // )}
- // ```
- //
- // Safety:
- // - `type P = &mut _`. There are thus no pathological `Deref{,Mut}` impls
- // that would break `Pin`'s invariants.
- // - `{ $value }` is braced, making it a _block expression_, thus **moving**
- // the given `$value`, and making it _become an **anonymous** temporary_.
- // By virtue of being anonymous, it can no longer be accessed, thus
- // preventing any attempts to `mem::replace` it or `mem::forget` it, _etc._
- //
- // This gives us a `pin!` definition that is sound, and which works, but only
- // in certain scenarios:
- // - If the `pin!(value)` expression is _directly_ fed to a function call:
- // `let poll = pin!(fut).poll(cx);`
- // - If the `pin!(value)` expression is part of a scrutinee:
- // ```rust
- // match pin!(fut) { pinned_fut => {
- // pinned_fut.as_mut().poll(...);
- // pinned_fut.as_mut().poll(...);
- // }} // <- `fut` is dropped here.
- // ```
- // Alas, it doesn't work for the more straight-forward use-case: `let` bindings.
- // ```rust
- // let pinned_fut = pin!(fut); // <- temporary value is freed at the end of this statement
- // pinned_fut.poll(...) // error[E0716]: temporary value dropped while borrowed
- // // note: consider using a `let` binding to create a longer lived value
- // ```
- // - Issues such as this one are the ones motivating https://github.com/rust-lang/rfcs/pull/66
- //
- // This makes such a macro incredibly unergonomic in practice, and the reason most macros
- // out there had to take the path of being a statement/binding macro (_e.g._, `pin!(future);`)
- // instead of featuring the more intuitive ergonomics of an expression macro.
- //
- // Luckily, there is a way to avoid the problem. Indeed, the problem stems from the fact that a
- // temporary is dropped at the end of its enclosing statement when it is part of the parameters
- // given to function call, which has precisely been the case with our `Pin::new_unchecked()`!
- // For instance,
- // ```rust
- // let p = Pin::new_unchecked(&mut <temporary>);
- // ```
- // becomes:
- // ```rust
- // let p = { let mut anon = <temporary>; &mut anon };
- // ```
- //
- // However, when using a literal braced struct to construct the value, references to temporaries
- // can then be taken. This makes Rust change the lifespan of such temporaries so that they are,
- // instead, dropped _at the end of the enscoping block_.
- // For instance,
- // ```rust
- // let p = Pin { __pointer: &mut <temporary> };
- // ```
- // becomes:
- // ```rust
- // let mut anon = <temporary>;
- // let p = Pin { __pointer: &mut anon };
- // ```
- // which is *exactly* what we want.
- //
- // See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
- // for more info.
- $crate::pin::Pin::<&mut _> { __pointer: &mut { $value } }
+ {
+ super let mut pinned = $value;
+ // SAFETY: The value is pinned: it is the local above which cannot be named outside this macro.
+ unsafe { $crate::pin::Pin::new_unchecked(&mut pinned) }
+ }
+}
+
+/// Only for bootstrap.
+#[cfg(bootstrap)]
+#[stable(feature = "pin_macro", since = "1.68.0")]
+#[rustc_macro_transparency = "semitransparent"]
+pub macro pin($value:expr $(,)?) {
+ $crate::pin::Pin::<&mut _> { pointer: &mut { $value } }
}
diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs
index 0854e31..2d86995 100644
--- a/library/core/src/ptr/const_ptr.rs
+++ b/library/core/src/ptr/const_ptr.rs
@@ -1739,3 +1739,11 @@ fn ge(&self, other: &*const T) -> bool {
*self >= *other
}
}
+
+#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
+impl<T: ?Sized + Thin> Default for *const T {
+ /// Returns the default value of [`null()`][crate::ptr::null].
+ fn default() -> Self {
+ crate::ptr::null()
+ }
+}
diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs
index e297749..df49eed 100644
--- a/library/core/src/ptr/mut_ptr.rs
+++ b/library/core/src/ptr/mut_ptr.rs
@@ -2156,3 +2156,11 @@ fn ge(&self, other: &*mut T) -> bool {
*self >= *other
}
}
+
+#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
+impl<T: ?Sized + Thin> Default for *mut T {
+ /// Returns the default value of [`null_mut()`][crate::ptr::null_mut].
+ fn default() -> Self {
+ crate::ptr::null_mut()
+ }
+}
diff --git a/library/coretests/tests/iter/adapters/enumerate.rs b/library/coretests/tests/iter/adapters/enumerate.rs
index b57d51c..2294f85 100644
--- a/library/coretests/tests/iter/adapters/enumerate.rs
+++ b/library/coretests/tests/iter/adapters/enumerate.rs
@@ -120,3 +120,13 @@ fn test_double_ended_enumerate() {
assert_eq!(it.next_back(), Some((2, 3)));
assert_eq!(it.next(), None);
}
+
+#[test]
+fn test_empty_iterator_enumerate_next_index() {
+ let mut it = empty::<i32>().enumerate();
+ assert_eq!(it.next_index(), 0);
+ assert_eq!(it.next_index(), 0);
+ assert_eq!(it.next(), None);
+ assert_eq!(it.next_index(), 0);
+ assert_eq!(it.next_index(), 0);
+}
diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs
index 1c43bfe..ac11157 100644
--- a/library/coretests/tests/lib.rs
+++ b/library/coretests/tests/lib.rs
@@ -63,6 +63,7 @@
#![feature(maybe_uninit_write_slice)]
#![feature(min_specialization)]
#![feature(never_type)]
+#![feature(next_index)]
#![feature(numfmt)]
#![feature(pattern)]
#![feature(pointer_is_aligned_to)]
diff --git a/library/coretests/tests/pin_macro.rs b/library/coretests/tests/pin_macro.rs
index bfbfa8d..3174c91 100644
--- a/library/coretests/tests/pin_macro.rs
+++ b/library/coretests/tests/pin_macro.rs
@@ -38,6 +38,7 @@ fn rust_2024_expr() {
}
#[test]
+#[cfg(not(bootstrap))]
fn temp_lifetime() {
// Check that temporary lifetimes work as in Rust 2021.
// Regression test for https://github.com/rust-lang/rust/issues/138596
diff --git a/library/coretests/tests/ptr.rs b/library/coretests/tests/ptr.rs
index cc5f794..7d6e4ea 100644
--- a/library/coretests/tests/ptr.rs
+++ b/library/coretests/tests/ptr.rs
@@ -1020,3 +1020,20 @@ fn test_ptr_swap_nonoverlapping_is_untyped() {
ptr_swap_nonoverlapping_is_untyped_inner();
const { ptr_swap_nonoverlapping_is_untyped_inner() };
}
+
+#[test]
+fn test_ptr_default() {
+ #[derive(Default)]
+ struct PtrDefaultTest {
+ ptr: *const u64,
+ }
+ let default = PtrDefaultTest::default();
+ assert!(default.ptr.is_null());
+
+ #[derive(Default)]
+ struct PtrMutDefaultTest {
+ ptr: *mut u64,
+ }
+ let default = PtrMutDefaultTest::default();
+ assert!(default.ptr.is_null());
+}
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml
index 6b70ff7..917a470 100644
--- a/library/std/Cargo.toml
+++ b/library/std/Cargo.toml
@@ -18,7 +18,7 @@
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
-compiler_builtins = { version = "=0.1.153" }
+compiler_builtins = { version = "=0.1.155" }
unwind = { path = "../unwind" }
hashbrown = { version = "0.15", default-features = false, features = [
'rustc-dep-of-std',
diff --git a/library/std/src/sync/mpmc/list.rs b/library/std/src/sync/mpmc/list.rs
index d88914f..1c6acb2 100644
--- a/library/std/src/sync/mpmc/list.rs
+++ b/library/std/src/sync/mpmc/list.rs
@@ -213,6 +213,11 @@ fn start_send(&self, token: &mut Token) -> bool {
.compare_exchange(block, new, Ordering::Release, Ordering::Relaxed)
.is_ok()
{
+ // This yield point leaves the channel in a half-initialized state where the
+ // tail.block pointer is set but the head.block is not. This is used to
+ // facilitate the test in src/tools/miri/tests/pass/issues/issue-139553.rs
+ #[cfg(miri)]
+ crate::thread::yield_now();
self.head.block.store(new, Ordering::Release);
block = new;
} else {
@@ -564,9 +569,15 @@ fn discard_all_messages(&self) {
// In that case, just wait until it gets initialized.
while block.is_null() {
backoff.spin_heavy();
- block = self.head.block.load(Ordering::Acquire);
+ block = self.head.block.swap(ptr::null_mut(), Ordering::AcqRel);
}
}
+ // After this point `head.block` is not modified again and it will be deallocated if it's
+ // non-null. The `Drop` code of the channel, which runs after this function, also attempts
+ // to deallocate `head.block` if it's non-null. Therefore this function must maintain the
+ // invariant that if a deallocation of head.block is attemped then it must also be set to
+ // NULL. Failing to do so will lead to the Drop code attempting a double free. For this
+ // reason both reads above do an atomic swap instead of a simple atomic load.
unsafe {
// Drop all messages between head and tail and deallocate the heap-allocated blocks.
diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs
index 687fc32..bc8817b 100644
--- a/library/std/src/sys/fs/unix.rs
+++ b/library/std/src/sys/fs/unix.rs
@@ -12,10 +12,11 @@
all(target_os = "linux", not(target_env = "musl")),
target_os = "android",
target_os = "fuchsia",
- target_os = "hurd"
+ target_os = "hurd",
+ target_os = "illumos",
))]
use libc::dirfd;
-#[cfg(target_os = "fuchsia")]
+#[cfg(any(target_os = "fuchsia", target_os = "illumos"))]
use libc::fstatat as fstatat64;
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
use libc::fstatat64;
@@ -892,7 +893,8 @@ pub fn file_name(&self) -> OsString {
all(target_os = "linux", not(target_env = "musl")),
target_os = "android",
target_os = "fuchsia",
- target_os = "hurd"
+ target_os = "hurd",
+ target_os = "illumos",
),
not(miri) // no dirfd on Miri
))]
@@ -922,6 +924,7 @@ pub fn metadata(&self) -> io::Result<FileAttr> {
target_os = "android",
target_os = "fuchsia",
target_os = "hurd",
+ target_os = "illumos",
)),
miri
))]
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 106a04d..68fa42e 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -155,7 +155,7 @@ fn run(self, builder: &Builder<'_>) {
// When using `download-rustc`, we already have artifacts for the host available. Don't
// recompile them.
- if builder.download_rustc() && builder.is_builder_target(target)
+ if builder.download_rustc() && builder.config.is_host_target(target)
// NOTE: the beta compiler may generate different artifacts than the downloaded compiler, so
// its artifacts can't be reused.
&& compiler.stage != 0
@@ -229,7 +229,7 @@ fn run(self, builder: &Builder<'_>) {
// The LLD wrappers and `rust-lld` are self-contained linking components that can be
// necessary to link the stdlib on some targets. We'll also need to copy these binaries to
// the `stage0-sysroot` to ensure the linker is found when bootstrapping on such a target.
- if compiler.stage == 0 && builder.is_builder_target(compiler.host) {
+ if compiler.stage == 0 && builder.config.is_host_target(compiler.host) {
trace!(
"(build == host) copying linking components to `stage0-sysroot` for bootstrapping"
);
@@ -1373,7 +1373,7 @@ pub fn rustc_cargo_env(
/// Pass down configuration from the LLVM build into the build of
/// rustc_llvm and rustc_codegen_llvm.
fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection) {
- if builder.is_rust_llvm(target) {
+ if builder.config.is_rust_llvm(target) {
cargo.env("LLVM_RUSTLLVM", "1");
}
if builder.config.llvm_enzyme {
@@ -2181,7 +2181,7 @@ fn run(self, builder: &Builder<'_>) -> Compiler {
debug!("copying codegen backends to sysroot");
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
- if builder.config.lld_enabled {
+ if builder.config.lld_enabled && !builder.config.is_system_llvm(target_compiler.host) {
builder.ensure(crate::core::build_steps::tool::LldWrapper {
build_compiler,
target_compiler,
@@ -2531,7 +2531,9 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
// FIXME: to make things simpler for now, limit this to the host and target where we know
// `strip -g` is both available and will fix the issue, i.e. on a x64 linux host that is not
// cross-compiling. Expand this to other appropriate targets in the future.
- if target != "x86_64-unknown-linux-gnu" || !builder.is_builder_target(target) || !path.exists()
+ if target != "x86_64-unknown-linux-gnu"
+ || !builder.config.is_host_target(target)
+ || !path.exists()
{
return;
}
diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs
index 83f71ae..ed90ede 100644
--- a/src/bootstrap/src/core/build_steps/dist.rs
+++ b/src/bootstrap/src/core/build_steps/dist.rs
@@ -612,7 +612,7 @@ fn run(self, builder: &Builder<'_>) {
fn skip_host_target_lib(builder: &Builder<'_>, compiler: Compiler) -> bool {
// The only true set of target libraries came from the build triple, so
// let's reduce redundant work by only producing archives from that host.
- if !builder.is_builder_target(compiler.host) {
+ if !builder.config.is_host_target(compiler.host) {
builder.info("\tskipping, not a build host");
true
} else {
@@ -671,7 +671,8 @@ fn copy_target_libs(
&self_contained_dst.join(path.file_name().unwrap()),
FileType::NativeLibrary,
);
- } else if dependency_type == DependencyType::Target || builder.is_builder_target(target) {
+ } else if dependency_type == DependencyType::Target || builder.config.is_host_target(target)
+ {
builder.copy_link(&path, &dst.join(path.file_name().unwrap()), FileType::NativeLibrary);
}
}
@@ -824,7 +825,7 @@ fn make_run(run: RunConfig<'_>) {
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
let compiler = self.compiler;
let target = self.target;
- if !builder.is_builder_target(compiler.host) {
+ if !builder.config.is_host_target(compiler.host) {
return None;
}
@@ -2118,7 +2119,7 @@ fn maybe_install_llvm(
//
// If the LLVM is coming from ourselves (just from CI) though, we
// still want to install it, as it otherwise won't be available.
- if builder.is_system_llvm(target) {
+ if builder.config.is_system_llvm(target) {
trace!("system LLVM requested, no install");
return false;
}
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
index 6e84b83..6f6839a 100644
--- a/src/bootstrap/src/core/build_steps/llvm.rs
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
@@ -485,7 +485,7 @@ fn run(self, builder: &Builder<'_>) -> LlvmResult {
}
// https://llvm.org/docs/HowToCrossCompileLLVM.html
- if !builder.is_builder_target(target) {
+ if !builder.config.is_host_target(target) {
let LlvmResult { llvm_config, .. } =
builder.ensure(Llvm { target: builder.config.build });
if !builder.config.dry_run() {
@@ -637,7 +637,7 @@ fn configure_cmake(
}
cfg.target(&target.triple).host(&builder.config.build.triple);
- if !builder.is_builder_target(target) {
+ if !builder.config.is_host_target(target) {
cfg.define("CMAKE_CROSSCOMPILING", "True");
// NOTE: Ideally, we wouldn't have to do this, and `cmake-rs` would just handle it for us.
@@ -1098,7 +1098,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
.define("LLVM_CMAKE_DIR", llvm_cmake_dir)
.define("LLVM_INCLUDE_TESTS", "OFF");
- if !builder.is_builder_target(target) {
+ if !builder.config.is_host_target(target) {
// Use the host llvm-tblgen binary.
cfg.define(
"LLVM_TABLEGEN_EXE",
diff --git a/src/bootstrap/src/core/build_steps/setup.rs b/src/bootstrap/src/core/build_steps/setup.rs
index 80d9213..83083e1 100644
--- a/src/bootstrap/src/core/build_steps/setup.rs
+++ b/src/bootstrap/src/core/build_steps/setup.rs
@@ -584,6 +584,7 @@ fn hashes(&self) -> &'static [&'static str] {
"51068d4747a13732440d1a8b8f432603badb1864fa431d83d0fd4f8fa57039e0",
"d29af4d949bbe2371eac928a3c31cf9496b1701aa1c45f11cd6c759865ad5c45",
"b5dd299b93dca3ceeb9b335f929293cb3d4bf4977866fbe7ceeac2a8a9f99088",
+ "631c837b0e98ae35fd48b0e5f743b1ca60adadf2d0a2b23566ba25df372cf1a9",
],
EditorKind::Helix => &[
"2d3069b8cf1b977e5d4023965eb6199597755e6c96c185ed5f2854f98b83d233",
@@ -602,10 +603,12 @@ fn hashes(&self) -> &'static [&'static str] {
"4eecb58a2168b252077369da446c30ed0e658301efe69691979d1ef0443928f4",
"c394386e6133bbf29ffd32c8af0bb3d4aac354cba9ee051f29612aa9350f8f8d",
"e53e9129ca5ee5dcbd6ec8b68c2d87376474eb154992deba3c6d9ab1703e0717",
+ "f954316090936c7e590c253ca9d524008375882fa13c5b41d7e2547a896ff893",
],
EditorKind::Zed => &[
"bbce727c269d1bd0c98afef4d612eb4ce27aea3c3a8968c5f10b31affbc40b6c",
"a5380cf5dd9328731aecc5dfb240d16dac46ed272126b9728006151ef42f5909",
+ "2e96bf0d443852b12f016c8fc9840ab3d0a2b4fe0b0fb3a157e8d74d5e7e0e26",
],
}
}
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
index b1a3bba..096f7de 100644
--- a/src/bootstrap/src/core/build_steps/test.rs
+++ b/src/bootstrap/src/core/build_steps/test.rs
@@ -1894,7 +1894,7 @@ fn run(self, builder: &Builder<'_>) {
.arg(llvm_components.trim());
llvm_components_passed = true;
}
- if !builder.is_rust_llvm(target) {
+ if !builder.config.is_rust_llvm(target) {
cmd.arg("--system-llvm");
}
@@ -2668,7 +2668,7 @@ fn run(self, builder: &Builder<'_>) {
cargo
} else {
// Also prepare a sysroot for the target.
- if !builder.is_builder_target(target) {
+ if !builder.config.is_host_target(target) {
builder.ensure(compile::Std::new(compiler, target).force_recompile(true));
builder.ensure(RemoteCopyLibs { compiler, target });
}
diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs
index fd3b28e..5de824e 100644
--- a/src/bootstrap/src/core/builder/tests.rs
+++ b/src/bootstrap/src/core/builder/tests.rs
@@ -1107,8 +1107,8 @@ fn test_is_builder_target() {
let build = Build::new(config);
let builder = Builder::new(&build);
- assert!(builder.is_builder_target(target1));
- assert!(!builder.is_builder_target(target2));
+ assert!(builder.config.is_host_target(target1));
+ assert!(!builder.config.is_host_target(target2));
}
}
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index 2266e61..cd97066 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -2397,6 +2397,12 @@ fn get_table(option: &str) -> Result<TomlConfig, toml::de::Error> {
);
}
+ if config.lld_enabled && config.is_system_llvm(config.build) {
+ eprintln!(
+ "Warning: LLD is enabled when using external llvm-config. LLD will not be built and copied to the sysroot."
+ );
+ }
+
let default_std_features = BTreeSet::from([String::from("panic-unwind")]);
config.rust_std_features = std_features.unwrap_or(default_std_features);
@@ -3240,6 +3246,42 @@ pub fn last_modified_commit(
Some(commit.to_string())
}
+
+ /// Checks if the given target is the same as the host target.
+ pub fn is_host_target(&self, target: TargetSelection) -> bool {
+ self.build == target
+ }
+
+ /// Returns `true` if this is an external version of LLVM not managed by bootstrap.
+ /// In particular, we expect llvm sources to be available when this is false.
+ ///
+ /// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
+ pub fn is_system_llvm(&self, target: TargetSelection) -> bool {
+ match self.target_config.get(&target) {
+ Some(Target { llvm_config: Some(_), .. }) => {
+ let ci_llvm = self.llvm_from_ci && self.is_host_target(target);
+ !ci_llvm
+ }
+ // We're building from the in-tree src/llvm-project sources.
+ Some(Target { llvm_config: None, .. }) => false,
+ None => false,
+ }
+ }
+
+ /// Returns `true` if this is our custom, patched, version of LLVM.
+ ///
+ /// This does not necessarily imply that we're managing the `llvm-project` submodule.
+ pub fn is_rust_llvm(&self, target: TargetSelection) -> bool {
+ match self.target_config.get(&target) {
+ // We're using a user-controlled version of LLVM. The user has explicitly told us whether the version has our patches.
+ // (They might be wrong, but that's not a supported use-case.)
+ // In particular, this tries to support `submodules = false` and `patches = false`, for using a newer version of LLVM that's not through `rust-lang/llvm-project`.
+ Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
+ // The user hasn't promised the patches match.
+ // This only has our patches if it's downloaded from CI or built from source.
+ _ => !self.is_system_llvm(target),
+ }
+ }
}
/// Compares the current `Llvm` options against those in the CI LLVM builder and detects any incompatible options.
diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs
index 9e4a72b..eb0bf1d 100644
--- a/src/bootstrap/src/core/sanity.rs
+++ b/src/bootstrap/src/core/sanity.rs
@@ -326,7 +326,7 @@ pub fn check(build: &mut Build) {
if target.contains("musl") && !target.contains("unikraft") {
// If this is a native target (host is also musl) and no musl-root is given,
// fall back to the system toolchain in /usr before giving up
- if build.musl_root(*target).is_none() && build.is_builder_target(*target) {
+ if build.musl_root(*target).is_none() && build.config.is_host_target(*target) {
let target = build.config.target_config.entry(*target).or_default();
target.musl_root = Some("/usr".into());
}
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index 1a513a2..88d1815 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -35,7 +35,7 @@
use crate::core::builder;
use crate::core::builder::Kind;
-use crate::core::config::{DryRun, LldMode, LlvmLibunwind, Target, TargetSelection, flags};
+use crate::core::config::{DryRun, LldMode, LlvmLibunwind, TargetSelection, flags};
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command};
use crate::utils::helpers::{
self, dir_is_empty, exe, libdir, output, set_file_times, split_debuginfo, symlink_dir,
@@ -803,7 +803,7 @@ fn cargo_out(&self, compiler: Compiler, mode: Mode, target: TargetSelection) ->
/// Note that if LLVM is configured externally then the directory returned
/// will likely be empty.
fn llvm_out(&self, target: TargetSelection) -> PathBuf {
- if self.config.llvm_from_ci && self.is_builder_target(target) {
+ if self.config.llvm_from_ci && self.config.is_host_target(target) {
self.config.ci_llvm_root()
} else {
self.out.join(target).join("llvm")
@@ -851,37 +851,6 @@ fn vendored_crates_path(&self) -> Option<PathBuf> {
if self.config.vendor { Some(self.src.join(VENDOR_DIR)) } else { None }
}
- /// Returns `true` if this is an external version of LLVM not managed by bootstrap.
- /// In particular, we expect llvm sources to be available when this is false.
- ///
- /// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
- fn is_system_llvm(&self, target: TargetSelection) -> bool {
- match self.config.target_config.get(&target) {
- Some(Target { llvm_config: Some(_), .. }) => {
- let ci_llvm = self.config.llvm_from_ci && self.is_builder_target(target);
- !ci_llvm
- }
- // We're building from the in-tree src/llvm-project sources.
- Some(Target { llvm_config: None, .. }) => false,
- None => false,
- }
- }
-
- /// Returns `true` if this is our custom, patched, version of LLVM.
- ///
- /// This does not necessarily imply that we're managing the `llvm-project` submodule.
- fn is_rust_llvm(&self, target: TargetSelection) -> bool {
- match self.config.target_config.get(&target) {
- // We're using a user-controlled version of LLVM. The user has explicitly told us whether the version has our patches.
- // (They might be wrong, but that's not a supported use-case.)
- // In particular, this tries to support `submodules = false` and `patches = false`, for using a newer version of LLVM that's not through `rust-lang/llvm-project`.
- Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
- // The user hasn't promised the patches match.
- // This only has our patches if it's downloaded from CI or built from source.
- _ => !self.is_system_llvm(target),
- }
- }
-
/// Returns the path to `FileCheck` binary for the specified target
fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf {
let target_config = self.config.target_config.get(&target);
@@ -1356,7 +1325,7 @@ fn linker(&self, target: TargetSelection) -> Option<PathBuf> {
// need to use CXX compiler as linker to resolve the exception functions
// that are only existed in CXX libraries
Some(self.cxx.borrow()[&target].path().into())
- } else if !self.is_builder_target(target)
+ } else if !self.config.is_host_target(target)
&& helpers::use_host_linker(target)
&& !target.is_msvc()
{
@@ -2025,11 +1994,6 @@ fn colored_stream_inner<R, F, C>(&self, constructor: C, is_tty: bool, f: F) -> R
stream.reset().unwrap();
result
}
-
- /// Checks if the given target is the same as the builder target.
- fn is_builder_target(&self, target: TargetSelection) -> bool {
- self.config.build == target
- }
}
#[cfg(unix)]
diff --git a/src/doc/unstable-book/src/language-features/box-patterns.md b/src/doc/unstable-book/src/language-features/box-patterns.md
index a1ac096..c8a15b8 100644
--- a/src/doc/unstable-book/src/language-features/box-patterns.md
+++ b/src/doc/unstable-book/src/language-features/box-patterns.md
@@ -6,6 +6,8 @@
------------------------
+> **Note**: This feature will be superseded by [`deref_patterns`] in the future.
+
Box patterns let you match on `Box<T>`s:
@@ -28,3 +30,5 @@
}
}
```
+
+[`deref_patterns`]: ./deref-patterns.md
diff --git a/src/doc/unstable-book/src/language-features/deref-patterns.md b/src/doc/unstable-book/src/language-features/deref-patterns.md
new file mode 100644
index 0000000..d0102a6
--- /dev/null
+++ b/src/doc/unstable-book/src/language-features/deref-patterns.md
@@ -0,0 +1,57 @@
+# `deref_patterns`
+
+The tracking issue for this feature is: [#87121]
+
+[#87121]: https://github.com/rust-lang/rust/issues/87121
+
+------------------------
+
+> **Note**: This feature is incomplete. In the future, it is meant to supersede
+> [`box_patterns`](./box-patterns.md) and [`string_deref_patterns`](./string-deref-patterns.md).
+
+This feature permits pattern matching on [smart pointers in the standard library] through their
+`Deref` target types, either implicitly or with explicit `deref!(_)` patterns (the syntax of which
+is currently a placeholder).
+
+```rust
+#![feature(deref_patterns)]
+#![allow(incomplete_features)]
+
+let mut v = vec![Box::new(Some(0))];
+
+// Implicit dereferences are inserted when a pattern can match against the
+// result of repeatedly dereferencing but can't match against a smart
+// pointer itself. This works alongside match ergonomics for references.
+if let [Some(x)] = &mut v {
+ *x += 1;
+}
+
+// Explicit `deref!(_)` patterns may instead be used when finer control is
+// needed, e.g. to dereference only a single smart pointer, or to bind the
+// the result of dereferencing to a variable.
+if let deref!([deref!(opt_x @ Some(1))]) = &mut v {
+ opt_x.as_mut().map(|x| *x += 1);
+}
+
+assert_eq!(v, [Box::new(Some(2))]);
+```
+
+Without this feature, it may be necessary to introduce temporaries to represent dereferenced places
+when matching on nested structures:
+
+```rust
+let mut v = vec![Box::new(Some(0))];
+if let [b] = &mut *v {
+ if let Some(x) = &mut **b {
+ *x += 1;
+ }
+}
+if let [b] = &mut *v {
+ if let opt_x @ Some(1) = &mut **b {
+ opt_x.as_mut().map(|x| *x += 1);
+ }
+}
+assert_eq!(v, [Box::new(Some(2))]);
+```
+
+[smart pointers in the standard library]: https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors
diff --git a/src/doc/unstable-book/src/language-features/string-deref-patterns.md b/src/doc/unstable-book/src/language-features/string-deref-patterns.md
index 3723830..366bb15 100644
--- a/src/doc/unstable-book/src/language-features/string-deref-patterns.md
+++ b/src/doc/unstable-book/src/language-features/string-deref-patterns.md
@@ -6,6 +6,8 @@
------------------------
+> **Note**: This feature will be superseded by [`deref_patterns`] in the future.
+
This feature permits pattern matching `String` to `&str` through [its `Deref` implementation].
```rust
@@ -42,4 +44,5 @@
}
```
+[`deref_patterns`]: ./deref-patterns.md
[its `Deref` implementation]: https://doc.rust-lang.org/std/string/struct.String.html#impl-Deref-for-String
diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis
index 8a441cf..8fe87a9 100644
--- a/src/etc/natvis/libcore.natvis
+++ b/src/etc/natvis/libcore.natvis
@@ -69,9 +69,9 @@
</Type>
<Type Name="core::pin::Pin<*>">
- <DisplayString>Pin({(void*)__pointer}: {__pointer})</DisplayString>
+ <DisplayString>Pin({(void*)pointer}: {pointer})</DisplayString>
<Expand>
- <ExpandedItem>__pointer</ExpandedItem>
+ <ExpandedItem>pointer</ExpandedItem>
</Expand>
</Type>
diff --git a/src/etc/rust_analyzer_eglot.el b/src/etc/rust_analyzer_eglot.el
index 6b40371..90bd38a 100644
--- a/src/etc/rust_analyzer_eglot.el
+++ b/src/etc/rust_analyzer_eglot.el
@@ -8,10 +8,11 @@
"check"
"--json-output"])
:linkedProjects ["Cargo.toml"
- "src/bootstrap/Cargo.toml"
- "src/tools/rust-analyzer/Cargo.toml"
"compiler/rustc_codegen_cranelift/Cargo.toml"
- "compiler/rustc_codegen_gcc/Cargo.toml"]
+ "compiler/rustc_codegen_gcc/Cargo.toml"
+ "library/Cargo.toml"
+ "src/bootstrap/Cargo.toml"
+ "src/tools/rust-analyzer/Cargo.toml"]
:rustfmt ( :overrideCommand ["build/host/rustfmt/bin/rustfmt"
"--edition=2021"])
:procMacro ( :server "build/host/stage0/libexec/rust-analyzer-proc-macro-srv"
diff --git a/src/etc/rust_analyzer_settings.json b/src/etc/rust_analyzer_settings.json
index da7d326..5ce886a 100644
--- a/src/etc/rust_analyzer_settings.json
+++ b/src/etc/rust_analyzer_settings.json
@@ -9,11 +9,11 @@
],
"rust-analyzer.linkedProjects": [
"Cargo.toml",
+ "compiler/rustc_codegen_cranelift/Cargo.toml",
+ "compiler/rustc_codegen_gcc/Cargo.toml",
"library/Cargo.toml",
"src/bootstrap/Cargo.toml",
- "src/tools/rust-analyzer/Cargo.toml",
- "compiler/rustc_codegen_cranelift/Cargo.toml",
- "compiler/rustc_codegen_gcc/Cargo.toml"
+ "src/tools/rust-analyzer/Cargo.toml"
],
"rust-analyzer.rustfmt.overrideCommand": [
"${workspaceFolder}/build/host/rustfmt/bin/rustfmt",
@@ -36,5 +36,10 @@
},
"rust-analyzer.server.extraEnv": {
"RUSTUP_TOOLCHAIN": "nightly"
+ },
+ "files.associations": {
+ "*.fixed": "rust",
+ "*.pp": "rust",
+ "*.mir": "rust"
}
}
diff --git a/src/etc/rust_analyzer_zed.json b/src/etc/rust_analyzer_zed.json
index abc6ddb..3461ff8 100644
--- a/src/etc/rust_analyzer_zed.json
+++ b/src/etc/rust_analyzer_zed.json
@@ -21,15 +21,15 @@
},
"linkedProjects": [
"Cargo.toml",
+ "compiler/rustc_codegen_cranelift/Cargo.toml",
+ "compiler/rustc_codegen_gcc/Cargo.toml",
"library/Cargo.toml",
"src/bootstrap/Cargo.toml",
- "src/tools/rust-analyzer/Cargo.toml",
- "compiler/rustc_codegen_cranelift/Cargo.toml",
- "compiler/rustc_codegen_gcc/Cargo.toml"
+ "src/tools/rust-analyzer/Cargo.toml"
],
"procMacro": {
- "enable": true,
- "server": "${workspaceFolder}/build/host/stage0/libexec/rust-analyzer-proc-macro-srv"
+ "enable": true,
+ "server": "${workspaceFolder}/build/host/stage0/libexec/rust-analyzer-proc-macro-srv"
},
"rustc": {
"source": "./Cargo.toml"
@@ -47,5 +47,8 @@
}
}
}
+ },
+ "file_types": {
+ "Rust": ["fixed", "pp", "mir"]
}
}
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index fe9dc9a..034ecb2 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1052,7 +1052,7 @@ fn clean_fn_or_proc_macro<'tcx>(
match macro_kind {
Some(kind) => clean_proc_macro(item, name, kind, cx),
None => {
- let mut func = clean_function(cx, sig, generics, FunctionArgs::Body(body_id));
+ let mut func = clean_function(cx, sig, generics, ParamsSrc::Body(body_id));
clean_fn_decl_legacy_const_generics(&mut func, attrs);
FunctionItem(func)
}
@@ -1071,16 +1071,11 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
for (pos, literal) in meta_item_list.iter().filter_map(|meta| meta.lit()).enumerate() {
match literal.kind {
ast::LitKind::Int(a, _) => {
- let param = func.generics.params.remove(0);
- if let GenericParamDef {
- name,
- kind: GenericParamDefKind::Const { ty, .. },
- ..
- } = param
- {
- func.decl.inputs.values.insert(
+ let GenericParamDef { name, kind, .. } = func.generics.params.remove(0);
+ if let GenericParamDefKind::Const { ty, .. } = kind {
+ func.decl.inputs.insert(
a.get() as _,
- Argument { name: Some(name), type_: *ty, is_const: true },
+ Parameter { name: Some(name), type_: *ty, is_const: true },
);
} else {
panic!("unexpected non const in position {pos}");
@@ -1092,7 +1087,7 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
}
}
-enum FunctionArgs<'tcx> {
+enum ParamsSrc<'tcx> {
Body(hir::BodyId),
Idents(&'tcx [Option<Ident>]),
}
@@ -1101,86 +1096,62 @@ fn clean_function<'tcx>(
cx: &mut DocContext<'tcx>,
sig: &hir::FnSig<'tcx>,
generics: &hir::Generics<'tcx>,
- args: FunctionArgs<'tcx>,
+ params: ParamsSrc<'tcx>,
) -> Box<Function> {
let (generics, decl) = enter_impl_trait(cx, |cx| {
- // NOTE: generics must be cleaned before args
+ // NOTE: Generics must be cleaned before params.
let generics = clean_generics(generics, cx);
- let args = match args {
- FunctionArgs::Body(body_id) => {
- clean_args_from_types_and_body_id(cx, sig.decl.inputs, body_id)
- }
- FunctionArgs::Idents(idents) => {
- clean_args_from_types_and_names(cx, sig.decl.inputs, idents)
- }
+ let params = match params {
+ ParamsSrc::Body(body_id) => clean_params_via_body(cx, sig.decl.inputs, body_id),
+ // Let's not perpetuate anon params from Rust 2015; use `_` for them.
+ ParamsSrc::Idents(idents) => clean_params(cx, sig.decl.inputs, idents, |ident| {
+ Some(ident.map_or(kw::Underscore, |ident| ident.name))
+ }),
};
- let decl = clean_fn_decl_with_args(cx, sig.decl, Some(&sig.header), args);
+ let decl = clean_fn_decl_with_params(cx, sig.decl, Some(&sig.header), params);
(generics, decl)
});
Box::new(Function { decl, generics })
}
-fn clean_args_from_types_and_names<'tcx>(
+fn clean_params<'tcx>(
cx: &mut DocContext<'tcx>,
types: &[hir::Ty<'tcx>],
idents: &[Option<Ident>],
-) -> Arguments {
- fn nonempty_name(ident: &Option<Ident>) -> Option<Symbol> {
- if let Some(ident) = ident
- && ident.name != kw::Underscore
- {
- Some(ident.name)
- } else {
- None
- }
- }
-
- // If at least one argument has a name, use `_` as the name of unnamed
- // arguments. Otherwise omit argument names.
- let default_name = if idents.iter().any(|ident| nonempty_name(ident).is_some()) {
- Some(kw::Underscore)
- } else {
- None
- };
-
- Arguments {
- values: types
- .iter()
- .enumerate()
- .map(|(i, ty)| Argument {
- type_: clean_ty(ty, cx),
- name: idents.get(i).and_then(nonempty_name).or(default_name),
- is_const: false,
- })
- .collect(),
- }
+ postprocess: impl Fn(Option<Ident>) -> Option<Symbol>,
+) -> Vec<Parameter> {
+ types
+ .iter()
+ .enumerate()
+ .map(|(i, ty)| Parameter {
+ name: postprocess(idents[i]),
+ type_: clean_ty(ty, cx),
+ is_const: false,
+ })
+ .collect()
}
-fn clean_args_from_types_and_body_id<'tcx>(
+fn clean_params_via_body<'tcx>(
cx: &mut DocContext<'tcx>,
types: &[hir::Ty<'tcx>],
body_id: hir::BodyId,
-) -> Arguments {
- let body = cx.tcx.hir_body(body_id);
-
- Arguments {
- values: types
- .iter()
- .zip(body.params)
- .map(|(ty, param)| Argument {
- name: Some(name_from_pat(param.pat)),
- type_: clean_ty(ty, cx),
- is_const: false,
- })
- .collect(),
- }
+) -> Vec<Parameter> {
+ types
+ .iter()
+ .zip(cx.tcx.hir_body(body_id).params)
+ .map(|(ty, param)| Parameter {
+ name: Some(name_from_pat(param.pat)),
+ type_: clean_ty(ty, cx),
+ is_const: false,
+ })
+ .collect()
}
-fn clean_fn_decl_with_args<'tcx>(
+fn clean_fn_decl_with_params<'tcx>(
cx: &mut DocContext<'tcx>,
decl: &hir::FnDecl<'tcx>,
header: Option<&hir::FnHeader>,
- args: Arguments,
+ params: Vec<Parameter>,
) -> FnDecl {
let mut output = match decl.output {
hir::FnRetTy::Return(typ) => clean_ty(typ, cx),
@@ -1191,7 +1162,7 @@ fn clean_fn_decl_with_args<'tcx>(
{
output = output.sugared_async_return_type();
}
- FnDecl { inputs: args, output, c_variadic: decl.c_variadic }
+ FnDecl { inputs: params, output, c_variadic: decl.c_variadic }
}
fn clean_poly_fn_sig<'tcx>(
@@ -1199,10 +1170,6 @@ fn clean_poly_fn_sig<'tcx>(
did: Option<DefId>,
sig: ty::PolyFnSig<'tcx>,
) -> FnDecl {
- let mut names = did.map_or(&[] as &[_], |did| cx.tcx.fn_arg_idents(did)).iter();
-
- // We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
- // but shouldn't change any code meaning.
let mut output = clean_middle_ty(sig.output(), cx, None, None);
// If the return type isn't an `impl Trait`, we can safely assume that this
@@ -1215,25 +1182,25 @@ fn clean_poly_fn_sig<'tcx>(
output = output.sugared_async_return_type();
}
- FnDecl {
- output,
- c_variadic: sig.skip_binder().c_variadic,
- inputs: Arguments {
- values: sig
- .inputs()
- .iter()
- .map(|t| Argument {
- type_: clean_middle_ty(t.map_bound(|t| *t), cx, None, None),
- name: Some(if let Some(Some(ident)) = names.next() {
- ident.name
- } else {
- kw::Underscore
- }),
- is_const: false,
- })
- .collect(),
- },
- }
+ let mut idents = did.map(|did| cx.tcx.fn_arg_idents(did)).unwrap_or_default().iter().copied();
+
+ // If this comes from a fn item, let's not perpetuate anon params from Rust 2015; use `_` for them.
+ // If this comes from a fn ptr ty, we just keep params unnamed since it's more conventional stylistically.
+ // Since the param name is not part of the semantic type, these params never bear a name unlike
+ // in the HIR case, thus we can't peform any fancy fallback logic unlike `clean_bare_fn_ty`.
+ let fallback = did.map(|_| kw::Underscore);
+
+ let params = sig
+ .inputs()
+ .iter()
+ .map(|ty| Parameter {
+ name: idents.next().flatten().map(|ident| ident.name).or(fallback),
+ type_: clean_middle_ty(ty.map_bound(|ty| *ty), cx, None, None),
+ is_const: false,
+ })
+ .collect();
+
+ FnDecl { inputs: params, output, c_variadic: sig.skip_binder().c_variadic }
}
fn clean_trait_ref<'tcx>(trait_ref: &hir::TraitRef<'tcx>, cx: &mut DocContext<'tcx>) -> Path {
@@ -1273,11 +1240,11 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
RequiredAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
- let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Body(body));
+ let m = clean_function(cx, sig, trait_item.generics, ParamsSrc::Body(body));
MethodItem(m, None)
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(idents)) => {
- let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Idents(idents));
+ let m = clean_function(cx, sig, trait_item.generics, ParamsSrc::Idents(idents));
RequiredMethodItem(m)
}
hir::TraitItemKind::Type(bounds, Some(default)) => {
@@ -1318,7 +1285,7 @@ pub(crate) fn clean_impl_item<'tcx>(
type_: clean_ty(ty, cx),
})),
hir::ImplItemKind::Fn(ref sig, body) => {
- let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
+ let m = clean_function(cx, sig, impl_.generics, ParamsSrc::Body(body));
let defaultness = cx.tcx.defaultness(impl_.owner_id);
MethodItem(m, Some(defaultness))
}
@@ -1390,14 +1357,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
}
ty::AssocItemContainer::Trait => tcx.types.self_param,
};
- let self_arg_ty =
+ let self_param_ty =
tcx.fn_sig(assoc_item.def_id).instantiate_identity().input(0).skip_binder();
- if self_arg_ty == self_ty {
- item.decl.inputs.values[0].type_ = SelfTy;
- } else if let ty::Ref(_, ty, _) = *self_arg_ty.kind()
+ if self_param_ty == self_ty {
+ item.decl.inputs[0].type_ = SelfTy;
+ } else if let ty::Ref(_, ty, _) = *self_param_ty.kind()
&& ty == self_ty
{
- match item.decl.inputs.values[0].type_ {
+ match item.decl.inputs[0].type_ {
BorrowedRef { ref mut type_, .. } => **type_ = SelfTy,
_ => unreachable!(),
}
@@ -2611,15 +2578,25 @@ fn clean_bare_fn_ty<'tcx>(
cx: &mut DocContext<'tcx>,
) -> BareFunctionDecl {
let (generic_params, decl) = enter_impl_trait(cx, |cx| {
- // NOTE: generics must be cleaned before args
+ // NOTE: Generics must be cleaned before params.
let generic_params = bare_fn
.generic_params
.iter()
.filter(|p| !is_elided_lifetime(p))
.map(|x| clean_generic_param(cx, None, x))
.collect();
- let args = clean_args_from_types_and_names(cx, bare_fn.decl.inputs, bare_fn.param_idents);
- let decl = clean_fn_decl_with_args(cx, bare_fn.decl, None, args);
+ // Since it's more conventional stylistically, elide the name of all params called `_`
+ // unless there's at least one interestingly named param in which case don't elide any
+ // name since mixing named and unnamed params is less legible.
+ let filter = |ident: Option<Ident>| {
+ ident.map(|ident| ident.name).filter(|&ident| ident != kw::Underscore)
+ };
+ let fallback =
+ bare_fn.param_idents.iter().copied().find_map(filter).map(|_| kw::Underscore);
+ let params = clean_params(cx, bare_fn.decl.inputs, bare_fn.param_idents, |ident| {
+ filter(ident).or(fallback)
+ });
+ let decl = clean_fn_decl_with_params(cx, bare_fn.decl, None, params);
(generic_params, decl)
});
BareFunctionDecl { safety: bare_fn.safety, abi: bare_fn.abi, decl, generic_params }
@@ -2629,7 +2606,6 @@ fn clean_unsafe_binder_ty<'tcx>(
unsafe_binder_ty: &hir::UnsafeBinderTy<'tcx>,
cx: &mut DocContext<'tcx>,
) -> UnsafeBinderTy {
- // NOTE: generics must be cleaned before args
let generic_params = unsafe_binder_ty
.generic_params
.iter()
@@ -3155,7 +3131,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
cx.with_param_env(def_id, |cx| {
let kind = match item.kind {
hir::ForeignItemKind::Fn(sig, idents, generics) => ForeignFunctionItem(
- clean_function(cx, &sig, generics, FunctionArgs::Idents(idents)),
+ clean_function(cx, &sig, generics, ParamsSrc::Idents(idents)),
sig.header.safety(),
),
hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem(
diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs
index f58cdfc..bbe11bf 100644
--- a/src/librustdoc/clean/types.rs
+++ b/src/librustdoc/clean/types.rs
@@ -788,7 +788,7 @@ pub(crate) fn attributes(&self, tcx: TyCtxt<'_>, cache: &Cache, is_json: bool) -
}
_ => Some(rustc_hir_pretty::attribute_to_string(&tcx, attr)),
}
- } else if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
+ } else if attr.has_any_name(ALLOWED_ATTRIBUTES) {
Some(
rustc_hir_pretty::attribute_to_string(&tcx, attr)
.replace("\\\n", "")
@@ -1407,32 +1407,28 @@ pub(crate) struct Function {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct FnDecl {
- pub(crate) inputs: Arguments,
+ pub(crate) inputs: Vec<Parameter>,
pub(crate) output: Type,
pub(crate) c_variadic: bool,
}
impl FnDecl {
pub(crate) fn receiver_type(&self) -> Option<&Type> {
- self.inputs.values.first().and_then(|v| v.to_receiver())
+ self.inputs.first().and_then(|v| v.to_receiver())
}
}
+/// A function parameter.
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
-pub(crate) struct Arguments {
- pub(crate) values: Vec<Argument>,
-}
-
-#[derive(Clone, PartialEq, Eq, Debug, Hash)]
-pub(crate) struct Argument {
- pub(crate) type_: Type,
+pub(crate) struct Parameter {
pub(crate) name: Option<Symbol>,
+ pub(crate) type_: Type,
/// This field is used to represent "const" arguments from the `rustc_legacy_const_generics`
/// feature. More information in <https://github.com/rust-lang/rust/issues/83167>.
pub(crate) is_const: bool,
}
-impl Argument {
+impl Parameter {
pub(crate) fn to_receiver(&self) -> Option<&Type> {
if self.name == Some(kw::SelfLower) { Some(&self.type_) } else { None }
}
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 8ee08ed..af7986d 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -303,13 +303,12 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
debug!("trying to get a name from pattern: {p:?}");
Symbol::intern(&match &p.kind {
- // FIXME(never_patterns): does this make sense?
- PatKind::Missing => unreachable!(),
- PatKind::Wild
- | PatKind::Err(_)
+ PatKind::Err(_)
+ | PatKind::Missing // Let's not perpetuate anon params from Rust 2015; use `_` for them.
| PatKind::Never
+ | PatKind::Range(..)
| PatKind::Struct(..)
- | PatKind::Range(..) => {
+ | PatKind::Wild => {
return kw::Underscore;
}
PatKind::Binding(_, _, ident, _) => return ident.name,
diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs
index 41688b4..9d1c9ff 100644
--- a/src/librustdoc/core.rs
+++ b/src/librustdoc/core.rs
@@ -412,9 +412,7 @@ pub(crate) fn run_global_ctxt(
// Process all of the crate attributes, extracting plugin metadata along
// with the passes which we are supposed to run.
for attr in krate.module.attrs.lists(sym::doc) {
- let name = attr.name_or_empty();
-
- if attr.is_word() && name == sym::document_private_items {
+ if attr.is_word() && attr.has_name(sym::document_private_items) {
ctxt.render_options.document_private = true;
}
}
diff --git a/src/librustdoc/doctest/make.rs b/src/librustdoc/doctest/make.rs
index 4edd543..d5c965f 100644
--- a/src/librustdoc/doctest/make.rs
+++ b/src/librustdoc/doctest/make.rs
@@ -345,7 +345,7 @@ fn push_to_s(s: &mut String, source: &str, span: rustc_span::Span, prev_span_hi:
fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option<&str>) -> bool {
let mut is_extern_crate = false;
if !info.has_global_allocator
- && item.attrs.iter().any(|attr| attr.name_or_empty() == sym::global_allocator)
+ && item.attrs.iter().any(|attr| attr.has_name(sym::global_allocator))
{
info.has_global_allocator = true;
}
@@ -377,7 +377,7 @@ fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option<
}
let mut prev_span_hi = 0;
- let not_crate_attrs = [sym::forbid, sym::allow, sym::warn, sym::deny, sym::expect];
+ let not_crate_attrs = &[sym::forbid, sym::allow, sym::warn, sym::deny, sym::expect];
let parsed = parser.parse_item(rustc_parse::parser::ForceCollect::No);
let result = match parsed {
@@ -386,17 +386,13 @@ fn check_item(item: &ast::Item, info: &mut ParseSourceInfo, crate_name: &Option<
&& let Some(ref body) = fn_item.body =>
{
for attr in &item.attrs {
- let attr_name = attr.name_or_empty();
-
- if attr.style == AttrStyle::Outer || not_crate_attrs.contains(&attr_name) {
+ if attr.style == AttrStyle::Outer || attr.has_any_name(not_crate_attrs) {
// There is one exception to these attributes:
// `#![allow(internal_features)]`. If this attribute is used, we need to
// consider it only as a crate-level attribute.
- if attr_name == sym::allow
+ if attr.has_name(sym::allow)
&& let Some(list) = attr.meta_item_list()
- && list.iter().any(|sub_attr| {
- sub_attr.name_or_empty().as_str() == "internal_features"
- })
+ && list.iter().any(|sub_attr| sub_attr.has_name(sym::internal_features))
{
push_to_s(&mut info.crate_attrs, source, attr.span, &mut prev_span_hi);
} else {
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 9ac328f..299fd6b 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -1186,8 +1186,8 @@ fn print_type(
{
primitive_link(f, PrimitiveType::Array, format_args!("[{name}; N]"), cx)?;
} else if let clean::BareFunction(bare_fn) = &type_
- && let [clean::Argument { type_: clean::Type::Generic(name), .. }] =
- &bare_fn.decl.inputs.values[..]
+ && let [clean::Parameter { type_: clean::Type::Generic(name), .. }] =
+ &bare_fn.decl.inputs[..]
&& (self.kind.is_fake_variadic() || self.kind.is_auto())
{
// Hardcoded anchor library/core/src/primitive_docs.rs
@@ -1234,22 +1234,20 @@ fn print_type(
}
}
-impl clean::Arguments {
- pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
- fmt::from_fn(move |f| {
- self.values
- .iter()
- .map(|input| {
- fmt::from_fn(|f| {
- if let Some(name) = input.name {
- write!(f, "{}: ", name)?;
- }
- input.type_.print(cx).fmt(f)
- })
+pub(crate) fn print_params(params: &[clean::Parameter], cx: &Context<'_>) -> impl Display {
+ fmt::from_fn(move |f| {
+ params
+ .iter()
+ .map(|param| {
+ fmt::from_fn(|f| {
+ if let Some(name) = param.name {
+ write!(f, "{}: ", name)?;
+ }
+ param.type_.print(cx).fmt(f)
})
- .joined(", ", f)
- })
- }
+ })
+ .joined(", ", f)
+ })
}
// Implements Write but only counts the bytes "written".
@@ -1281,16 +1279,16 @@ pub(crate) fn print(&self, cx: &Context<'_>) -> impl Display {
if f.alternate() {
write!(
f,
- "({args:#}{ellipsis}){arrow:#}",
- args = self.inputs.print(cx),
+ "({params:#}{ellipsis}){arrow:#}",
+ params = print_params(&self.inputs, cx),
ellipsis = ellipsis,
arrow = self.print_output(cx)
)
} else {
write!(
f,
- "({args}{ellipsis}){arrow}",
- args = self.inputs.print(cx),
+ "({params}{ellipsis}){arrow}",
+ params = print_params(&self.inputs, cx),
ellipsis = ellipsis,
arrow = self.print_output(cx)
)
@@ -1336,14 +1334,14 @@ fn inner_full_print(
write!(f, "(")?;
if let Some(n) = line_wrapping_indent
- && !self.inputs.values.is_empty()
+ && !self.inputs.is_empty()
{
write!(f, "\n{}", Indent(n + 4))?;
}
- let last_input_index = self.inputs.values.len().checked_sub(1);
- for (i, input) in self.inputs.values.iter().enumerate() {
- if let Some(selfty) = input.to_receiver() {
+ let last_input_index = self.inputs.len().checked_sub(1);
+ for (i, param) in self.inputs.iter().enumerate() {
+ if let Some(selfty) = param.to_receiver() {
match selfty {
clean::SelfTy => {
write!(f, "self")?;
@@ -1361,13 +1359,13 @@ fn inner_full_print(
}
}
} else {
- if input.is_const {
+ if param.is_const {
write!(f, "const ")?;
}
- if let Some(name) = input.name {
+ if let Some(name) = param.name {
write!(f, "{}: ", name)?;
}
- input.type_.print(cx).fmt(f)?;
+ param.type_.print(cx).fmt(f)?;
}
match (line_wrapping_indent, last_input_index) {
(_, None) => (),
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 596ac66..f22935d 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -521,23 +521,23 @@ fn init(
// Crawl the crate attributes looking for attributes which control how we're
// going to emit HTML
for attr in krate.module.attrs.lists(sym::doc) {
- match (attr.name_or_empty(), attr.value_str()) {
- (sym::html_favicon_url, Some(s)) => {
+ match (attr.name(), attr.value_str()) {
+ (Some(sym::html_favicon_url), Some(s)) => {
layout.favicon = s.to_string();
}
- (sym::html_logo_url, Some(s)) => {
+ (Some(sym::html_logo_url), Some(s)) => {
layout.logo = s.to_string();
}
- (sym::html_playground_url, Some(s)) => {
+ (Some(sym::html_playground_url), Some(s)) => {
playground = Some(markdown::Playground {
crate_name: Some(krate.name(tcx)),
url: s.to_string(),
});
}
- (sym::issue_tracker_base_url, Some(s)) => {
+ (Some(sym::issue_tracker_base_url), Some(s)) => {
issue_tracker_base_url = Some(s.to_string());
}
- (sym::html_no_source, None) if attr.is_word() => {
+ (Some(sym::html_no_source), None) if attr.is_word() => {
include_sources = false;
}
_ => {}
diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs
index 1360ab9..aff8684 100644
--- a/src/librustdoc/html/render/search_index.rs
+++ b/src/librustdoc/html/render/search_index.rs
@@ -1112,7 +1112,7 @@ fn simplify_fn_type<'a, 'tcx>(
}
Type::BareFunction(ref bf) => {
let mut ty_generics = Vec::new();
- for ty in bf.decl.inputs.values.iter().map(|arg| &arg.type_) {
+ for ty in bf.decl.inputs.iter().map(|arg| &arg.type_) {
simplify_fn_type(
self_,
generics,
@@ -1418,15 +1418,15 @@ fn get_fn_inputs_and_outputs(
(None, &func.generics)
};
- let mut arg_types = Vec::new();
- for arg in decl.inputs.values.iter() {
+ let mut param_types = Vec::new();
+ for param in decl.inputs.iter() {
simplify_fn_type(
self_,
generics,
- &arg.type_,
+ ¶m.type_,
tcx,
0,
- &mut arg_types,
+ &mut param_types,
&mut rgen,
false,
cache,
@@ -1439,7 +1439,7 @@ fn get_fn_inputs_and_outputs(
let mut simplified_params = rgen.into_iter().collect::<Vec<_>>();
simplified_params.sort_by_key(|(_, (idx, _))| -idx);
(
- arg_types,
+ param_types,
ret_types,
simplified_params
.iter()
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index 5d85a46..f446c9f 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -84,8 +84,8 @@ fn convert_span(&self, span: clean::Span) -> Option<Span> {
let lo = span.lo(self.sess());
Some(Span {
filename: local_path,
- begin: (lo.line, lo.col.to_usize()),
- end: (hi.line, hi.col.to_usize()),
+ begin: (lo.line, lo.col.to_usize() + 1),
+ end: (hi.line, hi.col.to_usize() + 1),
})
} else {
None
@@ -609,11 +609,12 @@ fn from_clean(decl: clean::FnDecl, renderer: &JsonRenderer<'_>) -> Self {
let clean::FnDecl { inputs, output, c_variadic } = decl;
FunctionSignature {
inputs: inputs
- .values
.into_iter()
- // `_` is the most sensible name for missing param names.
- .map(|arg| {
- (arg.name.unwrap_or(kw::Underscore).to_string(), arg.type_.into_json(renderer))
+ .map(|param| {
+ // `_` is the most sensible name for missing param names.
+ let name = param.name.unwrap_or(kw::Underscore).to_string();
+ let type_ = param.type_.into_json(renderer);
+ (name, type_)
})
.collect(),
output: if output.is_unit() { None } else { Some(output.into_json(renderer)) },
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs
index ba27eed..131a12c 100644
--- a/src/librustdoc/json/mod.rs
+++ b/src/librustdoc/json/mod.rs
@@ -14,6 +14,7 @@
use std::path::PathBuf;
use std::rc::Rc;
+use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
@@ -123,6 +124,58 @@ fn serialize_and_write<T: Write>(
}
}
+fn target(sess: &rustc_session::Session) -> types::Target {
+ // Build a set of which features are enabled on this target
+ let globally_enabled_features: FxHashSet<&str> =
+ sess.unstable_target_features.iter().map(|name| name.as_str()).collect();
+
+ // Build a map of target feature stability by feature name
+ use rustc_target::target_features::Stability;
+ let feature_stability: FxHashMap<&str, Stability> = sess
+ .target
+ .rust_target_features()
+ .into_iter()
+ .copied()
+ .map(|(name, stability, _)| (name, stability))
+ .collect();
+
+ types::Target {
+ triple: sess.opts.target_triple.tuple().into(),
+ target_features: sess
+ .target
+ .rust_target_features()
+ .into_iter()
+ .copied()
+ .filter(|(_, stability, _)| {
+ // Describe only target features which the user can toggle
+ stability.toggle_allowed().is_ok()
+ })
+ .map(|(name, stability, implied_features)| {
+ types::TargetFeature {
+ name: name.into(),
+ unstable_feature_gate: match stability {
+ Stability::Unstable(feature_gate) => Some(feature_gate.as_str().into()),
+ _ => None,
+ },
+ implies_features: implied_features
+ .into_iter()
+ .copied()
+ .filter(|name| {
+ // Imply only target features which the user can toggle
+ feature_stability
+ .get(name)
+ .map(|stability| stability.toggle_allowed().is_ok())
+ .unwrap_or(false)
+ })
+ .map(String::from)
+ .collect(),
+ globally_enabled: globally_enabled_features.contains(name),
+ }
+ })
+ .collect(),
+ }
+}
+
impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
fn descr() -> &'static str {
"json"
@@ -248,6 +301,12 @@ fn after_krate(&mut self) -> Result<(), Error> {
let e = ExternalCrate { crate_num: LOCAL_CRATE };
let index = (*self.index).clone().into_inner();
+ // Note that tcx.rust_target_features is inappropriate here because rustdoc tries to run for
+ // multiple targets: https://github.com/rust-lang/rust/pull/137632
+ //
+ // We want to describe a single target, so pass tcx.sess rather than tcx.
+ let target = target(self.tcx.sess);
+
debug!("Constructing Output");
let output_crate = types::Crate {
root: self.id_from_item_default(e.def_id().into()),
@@ -288,6 +347,7 @@ fn after_krate(&mut self) -> Result<(), Error> {
)
})
.collect(),
+ target,
format_version: types::FORMAT_VERSION,
};
if let Some(ref out_dir) = self.out_dir {
diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs
index 137fe4c..64223b5 100644
--- a/src/rustdoc-json-types/lib.rs
+++ b/src/rustdoc-json-types/lib.rs
@@ -30,7 +30,7 @@
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
-pub const FORMAT_VERSION: u32 = 43;
+pub const FORMAT_VERSION: u32 = 45;
/// The root of the emitted JSON blob.
///
@@ -52,11 +52,67 @@ pub struct Crate {
pub paths: HashMap<Id, ItemSummary>,
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
pub external_crates: HashMap<u32, ExternalCrate>,
+ /// Information about the target for which this documentation was generated
+ pub target: Target,
/// A single version number to be used in the future when making backwards incompatible changes
/// to the JSON output.
pub format_version: u32,
}
+/// Information about a target
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Target {
+ /// The target triple for which this documentation was generated
+ pub triple: String,
+ /// A list of features valid for use in `#[target_feature]` attributes
+ /// for the target where this rustdoc JSON was generated.
+ pub target_features: Vec<TargetFeature>,
+}
+
+/// Information about a target feature.
+///
+/// Rust target features are used to influence code generation, especially around selecting
+/// instructions which are not universally supported by the target architecture.
+///
+/// Target features are commonly enabled by the [`#[target_feature]` attribute][1] to influence code
+/// generation for a particular function, and less commonly enabled by compiler options like
+/// `-Ctarget-feature` or `-Ctarget-cpu`. Targets themselves automatically enable certain target
+/// features by default, for example because the target's ABI specification requires saving specific
+/// registers which only exist in an architectural extension.
+///
+/// Target features can imply other target features: for example, x86-64 `avx2` implies `avx`, and
+/// aarch64 `sve2` implies `sve`, since both of these architectural extensions depend on their
+/// predecessors.
+///
+/// Target features can be probed at compile time by [`#[cfg(target_feature)]`][2] or `cfg!(…)`
+/// conditional compilation to determine whether a target feature is enabled in a particular
+/// context.
+///
+/// [1]: https://doc.rust-lang.org/stable/reference/attributes/codegen.html#the-target_feature-attribute
+/// [2]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_feature
+#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
+pub struct TargetFeature {
+ /// The name of this target feature.
+ pub name: String,
+ /// Other target features which are implied by this target feature, if any.
+ pub implies_features: Vec<String>,
+ /// If this target feature is unstable, the name of the associated language feature gate.
+ pub unstable_feature_gate: Option<String>,
+ /// Whether this feature is globally enabled for this compilation session.
+ ///
+ /// Target features can be globally enabled implicitly as a result of the target's definition.
+ /// For example, x86-64 hardware floating point ABIs require saving x87 and SSE2 registers,
+ /// which in turn requires globally enabling the `x87` and `sse2` target features so that the
+ /// generated machine code conforms to the target's ABI.
+ ///
+ /// Target features can also be globally enabled explicitly as a result of compiler flags like
+ /// [`-Ctarget-feature`][1] or [`-Ctarget-cpu`][2].
+ ///
+ /// [1]: https://doc.rust-lang.org/beta/rustc/codegen-options/index.html#target-feature
+ /// [2]: https://doc.rust-lang.org/beta/rustc/codegen-options/index.html#target-cpu
+ pub globally_enabled: bool,
+}
+
/// Metadata of a crate, either the same crate on which `rustdoc` was invoked, or its dependency.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ExternalCrate {
@@ -149,9 +205,9 @@ pub struct Item {
pub struct Span {
/// The path to the source file for this span relative to the path `rustdoc` was invoked with.
pub filename: PathBuf,
- /// Zero indexed Line and Column of the first character of the `Span`
+ /// One indexed Line and Column of the first character of the `Span`.
pub begin: (usize, usize),
- /// Zero indexed Line and Column of the last character of the `Span`
+ /// One indexed Line and Column of the last character of the `Span`.
pub end: (usize, usize),
}
diff --git a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs
index 8f1a1ee..96d3f71 100644
--- a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs
+++ b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs
@@ -179,7 +179,7 @@ fn find_first_mismatch(cx: &LateContext<'_>, pat: &Pat<'_>) -> Option<(Span, Mut
};
if let Some(adjustments) = cx.typeck_results().pat_adjustments().get(adjust_pat.hir_id) {
if let [first, ..] = **adjustments {
- if let ty::Ref(.., mutability) = *first.kind() {
+ if let ty::Ref(.., mutability) = *first.source.kind() {
let level = if p.hir_id == pat.hir_id {
Level::Top
} else {
diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs
index 9f450d6..f715fc8 100644
--- a/src/tools/clippy/clippy_utils/src/lib.rs
+++ b/src/tools/clippy/clippy_utils/src/lib.rs
@@ -2363,14 +2363,14 @@ pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
cx.tcx
.hir_attrs(hir::CRATE_HIR_ID)
.iter()
- .any(|attr| attr.name_or_empty() == sym::no_std)
+ .any(|attr| attr.has_name(sym::no_std))
}
pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
cx.tcx
.hir_attrs(hir::CRATE_HIR_ID)
.iter()
- .any(|attr| attr.name_or_empty() == sym::no_core)
+ .any(|attr| attr.has_name(sym::no_core))
}
/// Check if parent of a hir node is a trait implementation block.
diff --git a/src/tools/compiletest/src/directive-list.rs b/src/tools/compiletest/src/directive-list.rs
index 44c52c8..1449e9a 100644
--- a/src/tools/compiletest/src/directive-list.rs
+++ b/src/tools/compiletest/src/directive-list.rs
@@ -178,6 +178,7 @@
"only-32bit",
"only-64bit",
"only-aarch64",
+ "only-aarch64-apple-darwin",
"only-aarch64-unknown-linux-gnu",
"only-apple",
"only-arm",
@@ -191,6 +192,7 @@
"only-gnu",
"only-i686-pc-windows-gnu",
"only-i686-pc-windows-msvc",
+ "only-i686-unknown-linux-gnu",
"only-ios",
"only-linux",
"only-loongarch64",
@@ -222,6 +224,7 @@
"only-windows-msvc",
"only-x86",
"only-x86_64",
+ "only-x86_64-apple-darwin",
"only-x86_64-fortanix-unknown-sgx",
"only-x86_64-pc-windows-gnu",
"only-x86_64-pc-windows-msvc",
diff --git a/src/tools/jsondocck/src/main.rs b/src/tools/jsondocck/src/main.rs
index 54249fb..79e4198 100644
--- a/src/tools/jsondocck/src/main.rs
+++ b/src/tools/jsondocck/src/main.rs
@@ -156,7 +156,7 @@ fn parse<'a>(command_name: &str, negated: bool, args: &'a [String]) -> Option<(S
r#"
//@\s+
(?P<negated>!?)
- (?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
+ (?P<cmd>[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)
(?P<args>.*)$
"#,
)
diff --git a/src/tools/jsondoclint/src/validator/tests.rs b/src/tools/jsondoclint/src/validator/tests.rs
index 28deb7e..dd0b4ac 100644
--- a/src/tools/jsondoclint/src/validator/tests.rs
+++ b/src/tools/jsondoclint/src/validator/tests.rs
@@ -42,6 +42,7 @@ fn errors_on_missing_links() {
)]),
paths: FxHashMap::default(),
external_crates: FxHashMap::default(),
+ target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: rustdoc_json_types::FORMAT_VERSION,
};
@@ -112,6 +113,7 @@ fn errors_on_local_in_paths_and_not_index() {
},
)]),
external_crates: FxHashMap::default(),
+ target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: rustdoc_json_types::FORMAT_VERSION,
};
@@ -216,6 +218,7 @@ fn errors_on_missing_path() {
ItemSummary { crate_id: 0, path: vec!["foo".to_owned()], kind: ItemKind::Module },
)]),
external_crates: FxHashMap::default(),
+ target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: rustdoc_json_types::FORMAT_VERSION,
};
@@ -259,6 +262,7 @@ fn checks_local_crate_id_is_correct() {
)]),
paths: FxHashMap::default(),
external_crates: FxHashMap::default(),
+ target: rustdoc_json_types::Target { triple: "".to_string(), target_features: vec![] },
format_version: FORMAT_VERSION,
};
check(&krate, &[]);
diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs
index 5921ba8..b6b2684 100644
--- a/src/tools/miri/src/lib.rs
+++ b/src/tools/miri/src/lib.rs
@@ -169,7 +169,7 @@
"-Zalways-encode-mir",
"-Zextra-const-ub-checks",
"-Zmir-emit-retag",
- "-Zmir-keep-place-mention",
+ "-Zmir-preserve-ub",
"-Zmir-opt-level=0",
"-Zmir-enable-passes=-CheckAlignment,-CheckNull",
// Deduplicating diagnostics means we miss events when tracking what happens during an
diff --git a/src/tools/miri/tests/fail/read_from_trivial_switch.rs b/src/tools/miri/tests/fail/read_from_trivial_switch.rs
new file mode 100644
index 0000000..d34b1cd
--- /dev/null
+++ b/src/tools/miri/tests/fail/read_from_trivial_switch.rs
@@ -0,0 +1,14 @@
+// Ensure that we don't optimize out `SwitchInt` reads even if that terminator
+// branches to the same basic block on every target, since the operand may have
+// side-effects that affect analysis of the MIR.
+//
+// See <https://github.com/rust-lang/miri/issues/4237>.
+
+use std::mem::MaybeUninit;
+
+fn main() {
+ let uninit: MaybeUninit<i32> = MaybeUninit::uninit();
+ let bad_ref: &i32 = unsafe { uninit.assume_init_ref() };
+ let &(0 | _) = bad_ref;
+ //~^ ERROR: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
+}
diff --git a/src/tools/miri/tests/fail/read_from_trivial_switch.stderr b/src/tools/miri/tests/fail/read_from_trivial_switch.stderr
new file mode 100644
index 0000000..6b3d453
--- /dev/null
+++ b/src/tools/miri/tests/fail/read_from_trivial_switch.stderr
@@ -0,0 +1,15 @@
+error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
+ --> tests/fail/read_from_trivial_switch.rs:LL:CC
+ |
+LL | let &(0 | _) = bad_ref;
+ | ^^^^^^^^ using uninitialized data, but this operation requires initialized memory
+ |
+ = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
+ = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
+ = note: BACKTRACE:
+ = note: inside `main` at tests/fail/read_from_trivial_switch.rs:LL:CC
+
+note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
+
+error: aborting due to 1 previous error
+
diff --git a/src/tools/miri/tests/pass/issues/issue-139553.rs b/src/tools/miri/tests/pass/issues/issue-139553.rs
new file mode 100644
index 0000000..119d589
--- /dev/null
+++ b/src/tools/miri/tests/pass/issues/issue-139553.rs
@@ -0,0 +1,45 @@
+//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-compare-exchange-weak-failure-rate=0
+use std::sync::mpsc::channel;
+use std::thread;
+
+/// This test aims to trigger a race condition that causes a double free in the unbounded channel
+/// implementation. The test relies on a particular thread scheduling to happen as annotated by the
+/// comments below.
+fn main() {
+ let (s1, r) = channel::<u64>();
+ let s2 = s1.clone();
+
+ let t1 = thread::spawn(move || {
+ // 1. The first action executed is an attempt to send the first value in the channel. This
+ // will begin to initialize the channel but will stop at a critical momement as
+ // indicated by the `yield_now()` call in the `start_send` method of the implementation.
+ let _ = s1.send(42);
+ // 4. The sender is re-scheduled and it finishes the initialization of the channel by
+ // setting head.block to the same value as tail.block. It then proceeds to publish its
+ // value but observes that the channel has already disconnected (due to the concurrent
+ // call of `discard_all_messages`) and aborts the send.
+ });
+ std::thread::yield_now();
+
+ // 2. A second sender attempts to send a value while the channel is in a half-initialized
+ // state. Here, half-initialized means that the `tail.block` pointer points to a valid block
+ // but `head.block` is still null. This condition is ensured by the yield of step 1. When
+ // this call returns the channel state has tail.index != head.index, tail.block != NULL, and
+ // head.block = NULL.
+ s2.send(42).unwrap();
+ // 3. This thread continues with dropping the one and only receiver. When all receivers are
+ // gone `discard_all_messages` will attempt to drop all currently sent values and
+ // de-allocate all the blocks. If `tail.block != NULL` but `head.block = NULL` the
+ // implementation waits for the initializing sender to finish by spinning/yielding.
+ drop(r);
+ // 5. This thread is rescheduled and `discard_all_messages` observes the head.block pointer set
+ // by step 4 and proceeds with deallocation. In the problematic version of the code
+ // `head.block` is simply read via an `Acquire` load and not swapped with NULL. After this
+ // call returns the channel state has tail.index = head.index, tail.block = NULL, and
+ // head.block != NULL.
+ t1.join().unwrap();
+ // 6. The last sender (s2) is dropped here which also attempts to cleanup any data in the
+ // channel. It observes `tail.index = head.index` and so it doesn't attempt to cleanup any
+ // messages but it also observes that `head.block != NULL` and attempts to deallocate it.
+ // This is however already deallocated by `discard_all_messages`, leading to a double free.
+}
diff --git a/src/tools/nix-dev-shell/flake.nix b/src/tools/nix-dev-shell/flake.nix
index 1b838bd..b8287de 100644
--- a/src/tools/nix-dev-shell/flake.nix
+++ b/src/tools/nix-dev-shell/flake.nix
@@ -1,32 +1,24 @@
{
description = "rustc dev shell";
- inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
- flake-utils.url = "github:numtide/flake-utils";
- };
+ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
- outputs = { self, nixpkgs, flake-utils, ... }:
- flake-utils.lib.eachDefaultSystem (system:
- let
- pkgs = import nixpkgs { inherit system; };
- x = import ./x { inherit pkgs; };
- in
- {
- devShells.default = with pkgs; mkShell {
- name = "rustc-dev-shell";
- nativeBuildInputs = with pkgs; [
- binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
- ];
- buildInputs = with pkgs; [
- openssl glibc.out glibc.static x
- ];
- # Avoid creating text files for ICEs.
- RUSTC_ICE = "0";
- # Provide `libstdc++.so.6` for the self-contained lld.
- # Provide `libz.so.1`.
- LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
- };
- }
- );
+ outputs =
+ {
+ self,
+ nixpkgs,
+ }:
+ let
+ inherit (nixpkgs) lib;
+ forEachSystem = lib.genAttrs lib.systems.flakeExposed;
+ in
+ {
+ devShells = forEachSystem (system: {
+ default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { };
+ });
+
+ packages = forEachSystem (system: {
+ default = nixpkgs.legacyPackages.${system}.callPackage ./x { };
+ });
+ };
}
diff --git a/src/tools/nix-dev-shell/shell.nix b/src/tools/nix-dev-shell/shell.nix
index a3f5969..0adbacf 100644
--- a/src/tools/nix-dev-shell/shell.nix
+++ b/src/tools/nix-dev-shell/shell.nix
@@ -1,18 +1,26 @@
-{ pkgs ? import <nixpkgs> {} }:
-let
- x = import ./x { inherit pkgs; };
+{
+ pkgs ? import <nixpkgs> { },
+}:
+let
+ inherit (pkgs.lib) lists attrsets;
+
+ x = pkgs.callPackage ./x { };
+ inherit (x.passthru) cacert env;
in
pkgs.mkShell {
- name = "rustc";
- nativeBuildInputs = with pkgs; [
- binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
- ];
- buildInputs = with pkgs; [
- openssl glibc.out glibc.static x
- ];
- # Avoid creating text files for ICEs.
- RUSTC_ICE = "0";
- # Provide `libstdc++.so.6` for the self-contained lld.
- # Provide `libz.so.1`
- LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
+ name = "rustc-shell";
+
+ inputsFrom = [ x ];
+ packages = [
+ pkgs.git
+ pkgs.nix
+ x
+ # Get the runtime deps of the x wrapper
+ ] ++ lists.flatten (attrsets.attrValues env);
+
+ env = {
+ # Avoid creating text files for ICEs.
+ RUSTC_ICE = 0;
+ SSL_CERT_FILE = cacert;
+ };
}
diff --git a/src/tools/nix-dev-shell/x/default.nix b/src/tools/nix-dev-shell/x/default.nix
index e6dfbad..422c1c4 100644
--- a/src/tools/nix-dev-shell/x/default.nix
+++ b/src/tools/nix-dev-shell/x/default.nix
@@ -1,22 +1,83 @@
{
- pkgs ? import <nixpkgs> { },
+ pkgs,
+ lib,
+ stdenv,
+ rustc,
+ python3,
+ makeBinaryWrapper,
+ # Bootstrap
+ curl,
+ pkg-config,
+ libiconv,
+ openssl,
+ patchelf,
+ cacert,
+ zlib,
+ # LLVM Deps
+ ninja,
+ cmake,
+ glibc,
}:
-pkgs.stdenv.mkDerivation {
- name = "x";
+stdenv.mkDerivation (self: {
+ strictDeps = true;
+ name = "x-none";
+
+ outputs = [
+ "out"
+ "unwrapped"
+ ];
src = ./x.rs;
dontUnpack = true;
- nativeBuildInputs = with pkgs; [ rustc ];
+ nativeBuildInputs = [
+ rustc
+ makeBinaryWrapper
+ ];
+ env.PYTHON = python3.interpreter;
buildPhase = ''
- PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
+ rustc -Copt-level=3 --crate-name x $src --out-dir $unwrapped/bin
'';
- meta = with pkgs.lib; {
+ installPhase =
+ let
+ inherit (self.passthru) cacert env;
+ in
+ ''
+ makeWrapper $unwrapped/bin/x $out/bin/x \
+ --set-default SSL_CERT_FILE ${cacert} \
+ --prefix CPATH ";" "${lib.makeSearchPath "include" env.cpath}" \
+ --prefix PATH : ${lib.makeBinPath env.path} \
+ --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath env.ldLib}
+ '';
+
+ # For accessing them in the devshell
+ passthru = {
+ env = {
+ cpath = [ libiconv ];
+ path = [
+ python3
+ patchelf
+ curl
+ pkg-config
+ cmake
+ ninja
+ stdenv.cc
+ ];
+ ldLib = [
+ openssl
+ zlib
+ stdenv.cc.cc.lib
+ ];
+ };
+ cacert = "${cacert}/etc/ssl/certs/ca-bundle.crt";
+ };
+
+ meta = {
description = "Helper for rust-lang/rust x.py";
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
- license = licenses.mit;
+ license = lib.licenses.mit;
mainProgram = "x";
};
-}
+})
diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml
index f9beffe..15ed03a 100644
--- a/src/tools/run-make-support/Cargo.toml
+++ b/src/tools/run-make-support/Cargo.toml
@@ -14,9 +14,5 @@
serde_json = "1.0"
libc = "0.2"
-# FIXME(#137532): replace `os_pipe` with `anonymous_pipe` once it stabilizes and
-# reaches beta.
-os_pipe = "1.2.1"
-
[lib]
crate-type = ["lib", "dylib"]
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index c75d500..f37b38a 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -41,8 +41,6 @@ pub mod rfs {
pub use gimli;
pub use libc;
pub use object;
-// FIXME(#137532): replace with std `anonymous_pipe` once it stabilizes and reaches beta.
-pub use os_pipe;
pub use regex;
pub use serde_json;
pub use similar;
diff --git a/tests/codegen/issues/issue-101082.rs b/tests/codegen/issues/issue-101082.rs
index 96cdff6..8d15921 100644
--- a/tests/codegen/issues/issue-101082.rs
+++ b/tests/codegen/issues/issue-101082.rs
@@ -12,6 +12,7 @@
// at the time still sometimes fails, so only verify it for the power-of-two size
// - https://github.com/llvm/llvm-project/issues/134735
//@[x86-64-v3] only-x86_64
+//@[x86-64-v3] min-llvm-version: 21
//@[x86-64-v3] compile-flags: -Ctarget-cpu=x86-64-v3
#![crate_type = "lib"]
@@ -19,16 +20,7 @@
#[no_mangle]
pub fn test() -> usize {
// CHECK-LABEL: @test(
- // host: ret {{i64|i32}} 165
- // x86-64: ret {{i64|i32}} 165
-
- // FIXME: Now that this autovectorizes via a masked load, it doesn't actually
- // const-fold for certain widths. The `test_eight` case below shows that, yes,
- // what we're emitting *can* be const-folded, except that the way LLVM does it
- // for certain widths doesn't today. We should be able to put this back to
- // the same check after <https://github.com/llvm/llvm-project/issues/134513>
- // x86-64-v3: masked.load
-
+ // CHECK: ret {{i64|i32}} 165
let values = [23, 16, 54, 3, 60, 9];
let mut acc = 0;
for item in values {
diff --git a/tests/crashes/100618.rs b/tests/crashes/100618.rs
deleted file mode 100644
index 911c409..0000000
--- a/tests/crashes/100618.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-//@ known-bug: #100618
-//@ compile-flags: -Cdebuginfo=2
-
-//@ only-x86_64
-enum Foo<T: 'static> {
- Value(T),
- Recursive(&'static Foo<Option<T>>),
-}
-
-fn main() {
- let _x = Foo::Value(());
-}
diff --git a/tests/crashes/115994.rs b/tests/crashes/115994.rs
deleted file mode 100644
index 23d1507..0000000
--- a/tests/crashes/115994.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-//@ known-bug: #115994
-//@ compile-flags: -Cdebuginfo=2 --crate-type lib
-
-// To prevent "overflow while adding drop-check rules".
-use std::mem::ManuallyDrop;
-
-pub enum Foo<U> {
- Leaf(U),
-
- Branch(BoxedFoo<BoxedFoo<U>>),
-}
-
-pub type BoxedFoo<U> = ManuallyDrop<Box<Foo<U>>>;
-
-pub fn test() -> Foo<usize> {
- todo!()
-}
diff --git a/tests/crashes/121538.rs b/tests/crashes/121538.rs
deleted file mode 100644
index f18bad8..0000000
--- a/tests/crashes/121538.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-//@ known-bug: #121538
-//@ compile-flags: -Cdebuginfo=2
-
-use std::marker::PhantomData;
-
-struct Digit<T> {
- elem: T
-}
-
-struct Node<T:'static> { m: PhantomData<&'static T> }
-
-enum FingerTree<T:'static> {
- Single(T),
-
- Deep(
- Digit<T>,
- Node<FingerTree<Node<T>>>,
- )
-}
-
-enum Wrapper<T:'static> {
- Simple,
- Other(FingerTree<T>),
-}
-
-fn main() {
- let w =
- Some(Wrapper::Simple::<u32>);
-
-}
diff --git a/tests/debuginfo/recursive-enum.rs b/tests/debuginfo/recursive-enum.rs
index c2c3e71..b861e6d 100644
--- a/tests/debuginfo/recursive-enum.rs
+++ b/tests/debuginfo/recursive-enum.rs
@@ -4,7 +4,7 @@
// gdb-command:run
// Test whether compiling a recursive enum definition crashes debug info generation. The test case
-// is taken from issue #11083.
+// is taken from issue #11083 and #135093.
#![allow(unused_variables)]
#![feature(omit_gdb_pretty_printer_section)]
@@ -18,6 +18,21 @@ struct WindowCallbacks<'a> {
pos_callback: Option<Box<FnMut(&Window, i32, i32) + 'a>>,
}
+enum ExpandingRecursive<T> {
+ Recurse(Indirect<T>),
+ Item(T),
+}
+
+struct Indirect<U> {
+ rec: *const ExpandingRecursive<Option<U>>,
+}
+
+
fn main() {
let x = WindowCallbacks { pos_callback: None };
+
+ // EXPANDING RECURSIVE
+ let expanding_recursive: ExpandingRecursive<u64> = ExpandingRecursive::Recurse(Indirect {
+ rec: &ExpandingRecursive::Item(Option::Some(42)),
+ });
}
diff --git a/tests/crashes/107362.rs b/tests/debuginfo/recursive-type-with-gat.rs
similarity index 96%
rename from tests/crashes/107362.rs
rename to tests/debuginfo/recursive-type-with-gat.rs
index 8d55d61..b8a67d8 100644
--- a/tests/crashes/107362.rs
+++ b/tests/debuginfo/recursive-type-with-gat.rs
@@ -1,4 +1,3 @@
-//@ known-bug: #107362
//@ compile-flags: -Cdebuginfo=2
pub trait Functor
diff --git a/tests/mir-opt/building/match/exponential_or.match_tuple.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/exponential_or.match_tuple.SimplifyCfg-initial.after.mir
index d52241b..2a965fe 100644
--- a/tests/mir-opt/building/match/exponential_or.match_tuple.SimplifyCfg-initial.after.mir
+++ b/tests/mir-opt/building/match/exponential_or.match_tuple.SimplifyCfg-initial.after.mir
@@ -24,43 +24,47 @@
bb1: {
_0 = const 0_u32;
- goto -> bb10;
+ goto -> bb11;
}
bb2: {
- _2 = discriminant((_1.2: std::option::Option<i32>));
- switchInt(move _2) -> [0: bb4, 1: bb3, otherwise: bb1];
+ switchInt(copy (_1.1: bool)) -> [0: bb3, otherwise: bb3];
}
bb3: {
- switchInt(copy (((_1.2: std::option::Option<i32>) as Some).0: i32)) -> [1: bb4, 8: bb4, otherwise: bb1];
+ _2 = discriminant((_1.2: std::option::Option<i32>));
+ switchInt(move _2) -> [0: bb5, 1: bb4, otherwise: bb1];
}
bb4: {
- _5 = Le(const 6_u32, copy (_1.3: u32));
- switchInt(move _5) -> [0: bb5, otherwise: bb7];
+ switchInt(copy (((_1.2: std::option::Option<i32>) as Some).0: i32)) -> [1: bb5, 8: bb5, otherwise: bb1];
}
bb5: {
- _3 = Le(const 13_u32, copy (_1.3: u32));
- switchInt(move _3) -> [0: bb1, otherwise: bb6];
+ _5 = Le(const 6_u32, copy (_1.3: u32));
+ switchInt(move _5) -> [0: bb6, otherwise: bb8];
}
bb6: {
- _4 = Le(copy (_1.3: u32), const 16_u32);
- switchInt(move _4) -> [0: bb1, otherwise: bb8];
+ _3 = Le(const 13_u32, copy (_1.3: u32));
+ switchInt(move _3) -> [0: bb1, otherwise: bb7];
}
bb7: {
- _6 = Le(copy (_1.3: u32), const 9_u32);
- switchInt(move _6) -> [0: bb5, otherwise: bb8];
+ _4 = Le(copy (_1.3: u32), const 16_u32);
+ switchInt(move _4) -> [0: bb1, otherwise: bb9];
}
bb8: {
- falseEdge -> [real: bb9, imaginary: bb1];
+ _6 = Le(copy (_1.3: u32), const 9_u32);
+ switchInt(move _6) -> [0: bb6, otherwise: bb9];
}
bb9: {
+ falseEdge -> [real: bb10, imaginary: bb1];
+ }
+
+ bb10: {
StorageLive(_7);
_7 = copy (_1.0: u32);
StorageLive(_8);
@@ -74,10 +78,10 @@
StorageDead(_9);
StorageDead(_8);
StorageDead(_7);
- goto -> bb10;
+ goto -> bb11;
}
- bb10: {
+ bb11: {
return;
}
}
diff --git a/tests/mir-opt/dead-store-elimination/place_mention.rs b/tests/mir-opt/dead-store-elimination/place_mention.rs
index 5e4a286..1848a02 100644
--- a/tests/mir-opt/dead-store-elimination/place_mention.rs
+++ b/tests/mir-opt/dead-store-elimination/place_mention.rs
@@ -2,7 +2,7 @@
// and don't remove it as a dead store.
//
//@ test-mir-pass: DeadStoreElimination-initial
-//@ compile-flags: -Zmir-keep-place-mention
+//@ compile-flags: -Zmir-preserve-ub
// EMIT_MIR place_mention.main.DeadStoreElimination-initial.diff
fn main() {
diff --git a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff
index 56d4d50..151580d 100644
--- a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff
+++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff
@@ -33,7 +33,7 @@
- _4 = g() -> [return: bb1, unwind unreachable];
+ _4 = {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8 (#0)};
+ _3 = &mut _4;
-+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}> { __pointer: copy _3 };
++ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}> { pointer: copy _3 };
+ StorageDead(_3);
+ StorageLive(_5);
+ _5 = const false;
diff --git a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff
index 751916a..6196fc0 100644
--- a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff
+++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff
@@ -33,7 +33,7 @@
- _4 = g() -> [return: bb1, unwind continue];
+ _4 = {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8 (#0)};
+ _3 = &mut _4;
-+ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}> { __pointer: copy _3 };
++ _2 = Pin::<&mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}> { pointer: copy _3 };
+ StorageDead(_3);
+ StorageLive(_5);
+ _5 = const false;
diff --git "a/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-abort.diff" "b/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-abort.diff"
index e49d7ce..1e9a6dd 100644
--- "a/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-abort.diff"
+++ "b/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-abort.diff"
@@ -121,7 +121,7 @@
- }
-
- bb2: {
-+ _4 = Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}> { __pointer: copy _5 };
++ _4 = Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}> { pointer: copy _5 };
StorageDead(_5);
StorageLive(_6);
StorageLive(_7);
@@ -218,7 +218,7 @@
+ _37 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
+ _21 = &mut (((*_37) as variant#3).1: std::future::Ready<()>);
+ _20 = &mut (*_21);
-+ _19 = Pin::<&mut std::future::Ready<()>> { __pointer: copy _20 };
++ _19 = Pin::<&mut std::future::Ready<()>> { pointer: copy _20 };
+ StorageDead(_20);
+ StorageLive(_22);
+ StorageLive(_23);
@@ -239,7 +239,7 @@
+ _48 = &mut (_19.0: &mut std::future::Ready<()>);
+ _45 = copy (_19.0: &mut std::future::Ready<()>);
+ StorageDead(_48);
-+ _47 = Pin::<&mut std::future::Ready<()>> { __pointer: copy _45 };
++ _47 = Pin::<&mut std::future::Ready<()>> { pointer: copy _45 };
+ StorageDead(_47);
+ _44 = &mut ((*_45).0: std::option::Option<()>);
+ StorageLive(_49);
diff --git "a/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-unwind.diff" "b/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-unwind.diff"
index e7aed556..94b89a31 100644
--- "a/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-unwind.diff"
+++ "b/tests/mir-opt/inline_coroutine_body.run2-\173closure\0430\175.Inline.panic-unwind.diff"
@@ -123,7 +123,7 @@
- }
-
- bb2: {
-+ _4 = Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}> { __pointer: copy _5 };
++ _4 = Pin::<&mut {async fn body of ActionPermit<'_, T>::perform()}> { pointer: copy _5 };
StorageDead(_5);
StorageLive(_6);
StorageLive(_7);
@@ -235,7 +235,7 @@
+ _37 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
+ _21 = &mut (((*_37) as variant#3).1: std::future::Ready<()>);
+ _20 = &mut (*_21);
-+ _19 = Pin::<&mut std::future::Ready<()>> { __pointer: copy _20 };
++ _19 = Pin::<&mut std::future::Ready<()>> { pointer: copy _20 };
+ StorageDead(_20);
+ StorageLive(_22);
+ StorageLive(_23);
@@ -256,7 +256,7 @@
+ _50 = &mut (_19.0: &mut std::future::Ready<()>);
+ _47 = copy (_19.0: &mut std::future::Ready<()>);
+ StorageDead(_50);
-+ _49 = Pin::<&mut std::future::Ready<()>> { __pointer: copy _47 };
++ _49 = Pin::<&mut std::future::Ready<()>> { pointer: copy _47 };
+ StorageDead(_49);
+ _46 = &mut ((*_47).0: std::option::Option<()>);
+ StorageLive(_51);
diff --git a/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir b/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir
index 889ff6f..be0931e 100644
--- a/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir
+++ b/tests/mir-opt/or_pattern.single_switchint.SimplifyCfg-initial.after.mir
@@ -14,7 +14,7 @@
}
bb1: {
- switchInt(copy (_2.0: i32)) -> [3: bb8, 4: bb8, otherwise: bb7];
+ switchInt(copy (_2.0: i32)) -> [3: bb9, 4: bb9, otherwise: bb8];
}
bb2: {
@@ -22,7 +22,7 @@
}
bb3: {
- falseEdge -> [real: bb12, imaginary: bb4];
+ falseEdge -> [real: bb14, imaginary: bb4];
}
bb4: {
@@ -30,43 +30,51 @@
}
bb5: {
- falseEdge -> [real: bb11, imaginary: bb6];
+ falseEdge -> [real: bb13, imaginary: bb6];
}
bb6: {
- falseEdge -> [real: bb10, imaginary: bb1];
+ switchInt(copy (_2.1: bool)) -> [0: bb7, otherwise: bb7];
}
bb7: {
- _1 = const 5_i32;
- goto -> bb13;
+ falseEdge -> [real: bb12, imaginary: bb1];
}
bb8: {
- falseEdge -> [real: bb9, imaginary: bb7];
+ _1 = const 5_i32;
+ goto -> bb15;
}
bb9: {
- _1 = const 4_i32;
- goto -> bb13;
+ switchInt(copy (_2.1: bool)) -> [0: bb10, otherwise: bb10];
}
bb10: {
- _1 = const 3_i32;
- goto -> bb13;
+ falseEdge -> [real: bb11, imaginary: bb8];
}
bb11: {
- _1 = const 2_i32;
- goto -> bb13;
+ _1 = const 4_i32;
+ goto -> bb15;
}
bb12: {
- _1 = const 1_i32;
- goto -> bb13;
+ _1 = const 3_i32;
+ goto -> bb15;
}
bb13: {
+ _1 = const 2_i32;
+ goto -> bb15;
+ }
+
+ bb14: {
+ _1 = const 1_i32;
+ goto -> bb15;
+ }
+
+ bb15: {
StorageDead(_2);
StorageDead(_1);
_0 = const ();
diff --git a/tests/mir-opt/read_from_trivial_switch.main.SimplifyCfg-initial.diff b/tests/mir-opt/read_from_trivial_switch.main.SimplifyCfg-initial.diff
new file mode 100644
index 0000000..8775840
--- /dev/null
+++ b/tests/mir-opt/read_from_trivial_switch.main.SimplifyCfg-initial.diff
@@ -0,0 +1,49 @@
+- // MIR for `main` before SimplifyCfg-initial
++ // MIR for `main` after SimplifyCfg-initial
+
+ fn main() -> () {
+ let mut _0: ();
+ let _1: &i32;
+ let _2: i32;
+ scope 1 {
+ debug ref_ => _1;
+ scope 2 {
+ }
+ }
+
+ bb0: {
+ StorageLive(_1);
+ StorageLive(_2);
+ _2 = const 1_i32;
+ _1 = &_2;
+ FakeRead(ForLet(None), _1);
+ PlaceMention(_1);
+- switchInt(copy (*_1)) -> [0: bb2, otherwise: bb1];
++ switchInt(copy (*_1)) -> [0: bb1, otherwise: bb1];
+ }
+
+ bb1: {
+- goto -> bb5;
+- }
+-
+- bb2: {
+- goto -> bb5;
+- }
+-
+- bb3: {
+- goto -> bb1;
+- }
+-
+- bb4: {
+- FakeRead(ForMatchedPlace(None), _1);
+- unreachable;
+- }
+-
+- bb5: {
+ _0 = const ();
+ StorageDead(_2);
+ StorageDead(_1);
+ return;
+ }
+ }
+
diff --git a/tests/mir-opt/read_from_trivial_switch.rs b/tests/mir-opt/read_from_trivial_switch.rs
new file mode 100644
index 0000000..1c64c1d
--- /dev/null
+++ b/tests/mir-opt/read_from_trivial_switch.rs
@@ -0,0 +1,15 @@
+// Ensure that we don't optimize out `SwitchInt` reads even if that terminator
+// branches to the same basic block on every target, since the operand may have
+// side-effects that affect analysis of the MIR.
+//
+// See <https://github.com/rust-lang/miri/issues/4237>.
+
+//@ test-mir-pass: SimplifyCfg-initial
+//@ compile-flags: -Zmir-preserve-ub
+
+// EMIT_MIR read_from_trivial_switch.main.SimplifyCfg-initial.diff
+fn main() {
+ let ref_ = &1i32;
+ // CHECK: switchInt
+ let &(0 | _) = ref_;
+}
diff --git a/tests/pretty/postfix-yield.rs b/tests/pretty/postfix-yield.rs
index f76e814..60380a40 100644
--- a/tests/pretty/postfix-yield.rs
+++ b/tests/pretty/postfix-yield.rs
@@ -2,7 +2,8 @@
//@ edition: 2024
//@ pp-exact
-#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr)]
+#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr,
+stmt_expr_attributes)]
use std::ops::{Coroutine, CoroutineState};
use std::pin::pin;
diff --git a/tests/run-make/broken-pipe-no-ice/rmake.rs b/tests/run-make/broken-pipe-no-ice/rmake.rs
index 3e54b57..0521b39 100644
--- a/tests/run-make/broken-pipe-no-ice/rmake.rs
+++ b/tests/run-make/broken-pipe-no-ice/rmake.rs
@@ -14,9 +14,7 @@
use std::io::Read;
use std::process::{Command, Stdio};
-// FIXME(#137532): replace `os_pipe` dependency with std `anonymous_pipe` once that stabilizes and
-// reaches beta.
-use run_make_support::{env_var, os_pipe};
+use run_make_support::env_var;
#[derive(Debug, PartialEq)]
enum Binary {
@@ -25,7 +23,7 @@ enum Binary {
}
fn check_broken_pipe_handled_gracefully(bin: Binary, mut cmd: Command) {
- let (reader, writer) = os_pipe::pipe().unwrap();
+ let (reader, writer) = std::io::pipe().unwrap();
drop(reader); // close read-end
cmd.stdout(writer).stderr(Stdio::piped());
diff --git a/tests/rustdoc-json/impls/auto.rs b/tests/rustdoc-json/impls/auto.rs
index f94f733..ce47d1b 100644
--- a/tests/rustdoc-json/impls/auto.rs
+++ b/tests/rustdoc-json/impls/auto.rs
@@ -15,8 +15,8 @@ pub fn baz(&self) {}
}
// Testing spans, so all tests below code
-//@ is "$.index[?(@.docs=='has span')].span.begin" "[13, 0]"
-//@ is "$.index[?(@.docs=='has span')].span.end" "[15, 1]"
+//@ is "$.index[?(@.docs=='has span')].span.begin" "[13, 1]"
+//@ is "$.index[?(@.docs=='has span')].span.end" "[15, 2]"
// FIXME: this doesn't work due to https://github.com/freestrings/jsonpath/issues/91
// is "$.index[?(@.inner.impl.is_synthetic==true)].span" null
pub struct Foo;
diff --git a/tests/rustdoc-json/span.rs b/tests/rustdoc-json/span.rs
new file mode 100644
index 0000000..c96879d
--- /dev/null
+++ b/tests/rustdoc-json/span.rs
@@ -0,0 +1,4 @@
+pub mod bar {}
+// This test ensures that spans are 1-indexed.
+//@ is "$.index[?(@.name=='span')].span.begin" "[1, 1]"
+//@ is "$.index[?(@.name=='bar')].span.begin" "[1, 1]"
diff --git a/tests/rustdoc-json/targets/aarch64_apple_darwin.rs b/tests/rustdoc-json/targets/aarch64_apple_darwin.rs
new file mode 100644
index 0000000..c6ae551
--- /dev/null
+++ b/tests/rustdoc-json/targets/aarch64_apple_darwin.rs
@@ -0,0 +1,14 @@
+//@ only-aarch64-apple-darwin
+
+//@ is "$.target.triple" \"aarch64-apple-darwin\"
+//@ is "$.target.target_features[?(@.name=='vh')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='sve')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='sve2')].implies_features" '["sve"]'
+//@ is "$.target.target_features[?(@.name=='sve2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='cssc')].unstable_feature_gate" '"aarch64_unstable_target_feature"'
+//@ is "$.target.target_features[?(@.name=='v9a')].unstable_feature_gate" '"aarch64_ver_target_feature"'
+
+// Ensure we don't look like x86-64
+//@ !has "$.target.target_features[?(@.name=='avx2')]"
diff --git a/tests/rustdoc-json/targets/aarch64_reflects_compiler_options.rs b/tests/rustdoc-json/targets/aarch64_reflects_compiler_options.rs
new file mode 100644
index 0000000..f91221e
--- /dev/null
+++ b/tests/rustdoc-json/targets/aarch64_reflects_compiler_options.rs
@@ -0,0 +1,10 @@
+//@ only-aarch64
+
+// If we enable SVE Bit Permute, we should see that it is enabled
+//@ compile-flags: -Ctarget-feature=+sve2-bitperm
+//@ is "$.target.target_features[?(@.name=='sve2-bitperm')].globally_enabled" true
+
+// As well as its dependency chain
+//@ is "$.target.target_features[?(@.name=='sve2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='sve')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='neon')].globally_enabled" true
diff --git a/tests/rustdoc-json/targets/aarch64_unknown_linux_gnu.rs b/tests/rustdoc-json/targets/aarch64_unknown_linux_gnu.rs
new file mode 100644
index 0000000..9139b00
--- /dev/null
+++ b/tests/rustdoc-json/targets/aarch64_unknown_linux_gnu.rs
@@ -0,0 +1,14 @@
+//@ only-aarch64-unknown-linux-gnu
+
+//@ is "$.target.triple" \"aarch64-unknown-linux-gnu\"
+//@ is "$.target.target_features[?(@.name=='neon')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='sve')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='sve2')].implies_features" '["sve"]'
+//@ is "$.target.target_features[?(@.name=='sve2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='cssc')].unstable_feature_gate" '"aarch64_unstable_target_feature"'
+//@ is "$.target.target_features[?(@.name=='v9a')].unstable_feature_gate" '"aarch64_ver_target_feature"'
+
+// Ensure we don't look like x86-64
+//@ !has "$.target.target_features[?(@.name=='avx2')]"
diff --git a/tests/rustdoc-json/targets/i686_pc_windows_msvc.rs b/tests/rustdoc-json/targets/i686_pc_windows_msvc.rs
new file mode 100644
index 0000000..088c741
--- /dev/null
+++ b/tests/rustdoc-json/targets/i686_pc_windows_msvc.rs
@@ -0,0 +1,14 @@
+//@ only-i686-pc-windows-msvc
+
+//@ is "$.target.triple" \"i686-pc-windows-msvc\"
+//@ is "$.target.target_features[?(@.name=='sse2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='avx2')].implies_features" '["avx"]'
+//@ is "$.target.target_features[?(@.name=='avx2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='amx-tile')].unstable_feature_gate" '"x86_amx_intrinsics"'
+//@ is "$.target.target_features[?(@.name=='x87')].unstable_feature_gate" '"x87_target_feature"'
+
+// Ensure we don't look like aarch64
+//@ !has "$.target.target_features[?(@.name=='sve2')]"
diff --git a/tests/rustdoc-json/targets/i686_unknown_linux_gnu.rs b/tests/rustdoc-json/targets/i686_unknown_linux_gnu.rs
new file mode 100644
index 0000000..03788b0
--- /dev/null
+++ b/tests/rustdoc-json/targets/i686_unknown_linux_gnu.rs
@@ -0,0 +1,14 @@
+//@ only-i686-unknown-linux-gnu
+
+//@ is "$.target.triple" \"i686-unknown-linux-gnu\"
+//@ is "$.target.target_features[?(@.name=='sse2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='avx2')].implies_features" '["avx"]'
+//@ is "$.target.target_features[?(@.name=='avx2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='amx-tile')].unstable_feature_gate" '"x86_amx_intrinsics"'
+//@ is "$.target.target_features[?(@.name=='x87')].unstable_feature_gate" '"x87_target_feature"'
+
+// Ensure we don't look like aarch64
+//@ !has "$.target.target_features[?(@.name=='sve2')]"
diff --git a/tests/rustdoc-json/targets/x86_64_apple_darwin.rs b/tests/rustdoc-json/targets/x86_64_apple_darwin.rs
new file mode 100644
index 0000000..a46f913
--- /dev/null
+++ b/tests/rustdoc-json/targets/x86_64_apple_darwin.rs
@@ -0,0 +1,14 @@
+//@ only-x86_64-apple-darwin
+
+//@ is "$.target.triple" \"x86_64-apple-darwin\"
+//@ is "$.target.target_features[?(@.name=='sse2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='avx2')].implies_features" '["avx"]'
+//@ is "$.target.target_features[?(@.name=='avx2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='amx-tile')].unstable_feature_gate" '"x86_amx_intrinsics"'
+//@ is "$.target.target_features[?(@.name=='x87')].unstable_feature_gate" '"x87_target_feature"'
+
+// Ensure we don't look like aarch64
+//@ !has "$.target.target_features[?(@.name=='sve2')]"
diff --git a/tests/rustdoc-json/targets/x86_64_pc_windows_gnu.rs b/tests/rustdoc-json/targets/x86_64_pc_windows_gnu.rs
new file mode 100644
index 0000000..7da12eb
--- /dev/null
+++ b/tests/rustdoc-json/targets/x86_64_pc_windows_gnu.rs
@@ -0,0 +1,14 @@
+//@ only-x86_64-pc-windows-gnu
+
+//@ is "$.target.triple" \"x86_64-pc-windows-gnu\"
+//@ is "$.target.target_features[?(@.name=='sse2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='avx2')].implies_features" '["avx"]'
+//@ is "$.target.target_features[?(@.name=='avx2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='amx-tile')].unstable_feature_gate" '"x86_amx_intrinsics"'
+//@ is "$.target.target_features[?(@.name=='x87')].unstable_feature_gate" '"x87_target_feature"'
+
+// Ensure we don't look like aarch64
+//@ !has "$.target.target_features[?(@.name=='sve2')]"
diff --git a/tests/rustdoc-json/targets/x86_64_pc_windows_msvc.rs b/tests/rustdoc-json/targets/x86_64_pc_windows_msvc.rs
new file mode 100644
index 0000000..d55f577
--- /dev/null
+++ b/tests/rustdoc-json/targets/x86_64_pc_windows_msvc.rs
@@ -0,0 +1,14 @@
+//@ only-x86_64-pc-windows-msvc
+
+//@ is "$.target.triple" \"x86_64-pc-windows-msvc\"
+//@ is "$.target.target_features[?(@.name=='sse2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='avx2')].implies_features" '["avx"]'
+//@ is "$.target.target_features[?(@.name=='avx2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='amx-tile')].unstable_feature_gate" '"x86_amx_intrinsics"'
+//@ is "$.target.target_features[?(@.name=='x87')].unstable_feature_gate" '"x87_target_feature"'
+
+// Ensure we don't look like aarch64
+//@ !has "$.target.target_features[?(@.name=='sve2')]"
diff --git a/tests/rustdoc-json/targets/x86_64_reflects_compiler_options.rs b/tests/rustdoc-json/targets/x86_64_reflects_compiler_options.rs
new file mode 100644
index 0000000..ba029b0
--- /dev/null
+++ b/tests/rustdoc-json/targets/x86_64_reflects_compiler_options.rs
@@ -0,0 +1,10 @@
+//@ only-x86_64
+
+// If we enable AVX2, we should see that it is enabled
+//@ compile-flags: -Ctarget-feature=+avx2
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" true
+
+// As well as its dependency chain
+//@ is "$.target.target_features[?(@.name=='avx')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='sse4.2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='sse4.1')].globally_enabled" true
diff --git a/tests/rustdoc-json/targets/x86_64_unknown_linux_gnu.rs b/tests/rustdoc-json/targets/x86_64_unknown_linux_gnu.rs
new file mode 100644
index 0000000..3372fe7
--- /dev/null
+++ b/tests/rustdoc-json/targets/x86_64_unknown_linux_gnu.rs
@@ -0,0 +1,14 @@
+//@ only-x86_64-unknown-linux-gnu
+
+//@ is "$.target.triple" \"x86_64-unknown-linux-gnu\"
+//@ is "$.target.target_features[?(@.name=='sse2')].globally_enabled" true
+//@ is "$.target.target_features[?(@.name=='avx2')].globally_enabled" false
+//@ has "$.target.target_features[?(@.name=='avx2')].implies_features" '["avx"]'
+//@ is "$.target.target_features[?(@.name=='avx2')].unstable_feature_gate" null
+
+// If this breaks due to stabilization, check rustc_target::target_features for a replacement
+//@ is "$.target.target_features[?(@.name=='amx-tile')].unstable_feature_gate" '"x86_amx_intrinsics"'
+//@ is "$.target.target_features[?(@.name=='x87')].unstable_feature_gate" '"x87_target_feature"'
+
+// Ensure we don't look like aarch64
+//@ !has "$.target.target_features[?(@.name=='sve2')]"
diff --git a/tests/rustdoc/anon-fn-params.rs b/tests/rustdoc/anon-fn-params.rs
new file mode 100644
index 0000000..9af1af3
--- /dev/null
+++ b/tests/rustdoc/anon-fn-params.rs
@@ -0,0 +1,25 @@
+// Test that we render the deprecated anonymous trait function parameters from Rust 2015 as
+// underscores in order not to perpetuate it and for legibility.
+
+//@ edition: 2015
+#![expect(anonymous_parameters)]
+
+// Check the "local case" (HIR cleaning) //
+
+//@ has anon_fn_params/trait.Trait.html
+pub trait Trait {
+ //@ has - '//*[@id="tymethod.required"]' 'fn required(_: Option<i32>, _: impl Fn(&str) -> bool)'
+ fn required(Option<i32>, impl Fn(&str) -> bool);
+ //@ has - '//*[@id="method.provided"]' 'fn provided(_: [i32; 2])'
+ fn provided([i32; 2]) {}
+}
+
+// Check the "extern case" (middle cleaning) //
+
+//@ aux-build: ext-anon-fn-params.rs
+extern crate ext_anon_fn_params;
+
+//@ has anon_fn_params/trait.ExtTrait.html
+//@ has - '//*[@id="tymethod.required"]' 'fn required(_: Option<i32>, _: impl Fn(&str) -> bool)'
+//@ has - '//*[@id="method.provided"]' 'fn provided(_: [i32; 2])'
+pub use ext_anon_fn_params::Trait as ExtTrait;
diff --git a/tests/rustdoc/assoc-fns.rs b/tests/rustdoc/assoc-fns.rs
new file mode 100644
index 0000000..6ffbebc
--- /dev/null
+++ b/tests/rustdoc/assoc-fns.rs
@@ -0,0 +1,13 @@
+// Basic testing for associated functions (in traits, trait impls & inherent impls).
+
+//@ has assoc_fns/trait.Trait.html
+pub trait Trait {
+ //@ has - '//*[@id="tymethod.required"]' 'fn required(first: i32, second: &str)'
+ fn required(first: i32, second: &str);
+
+ //@ has - '//*[@id="method.provided"]' 'fn provided(only: ())'
+ fn provided(only: ()) {}
+
+ //@ has - '//*[@id="tymethod.params_are_unnamed"]' 'fn params_are_unnamed(_: i32, _: u32)'
+ fn params_are_unnamed(_: i32, _: u32);
+}
diff --git a/tests/rustdoc/auxiliary/ext-anon-fn-params.rs b/tests/rustdoc/auxiliary/ext-anon-fn-params.rs
new file mode 100644
index 0000000..1acb919
--- /dev/null
+++ b/tests/rustdoc/auxiliary/ext-anon-fn-params.rs
@@ -0,0 +1,7 @@
+//@ edition: 2015
+#![expect(anonymous_parameters)]
+
+pub trait Trait {
+ fn required(Option<i32>, impl Fn(&str) -> bool);
+ fn provided([i32; 2]) {}
+}
diff --git a/tests/rustdoc/ffi.rs b/tests/rustdoc/ffi.rs
index 5ba7cdb..524fb0e 100644
--- a/tests/rustdoc/ffi.rs
+++ b/tests/rustdoc/ffi.rs
@@ -9,4 +9,8 @@
extern "C" {
//@ has ffi/fn.another.html //pre 'pub unsafe extern "C" fn another(cold_as_ice: u32)'
pub fn another(cold_as_ice: u32);
+
+ //@ has ffi/fn.params_are_unnamed.html //pre \
+ // 'pub unsafe extern "C" fn params_are_unnamed(_: i32, _: u32)'
+ pub fn params_are_unnamed(_: i32, _: u32);
}
diff --git a/tests/rustdoc/inline_cross/auxiliary/fn-type.rs b/tests/rustdoc/inline_cross/auxiliary/fn-ptr-ty.rs
similarity index 100%
rename from tests/rustdoc/inline_cross/auxiliary/fn-type.rs
rename to tests/rustdoc/inline_cross/auxiliary/fn-ptr-ty.rs
diff --git a/tests/rustdoc/inline_cross/default-generic-args.rs b/tests/rustdoc/inline_cross/default-generic-args.rs
index 0469221..5124fbd 100644
--- a/tests/rustdoc/inline_cross/default-generic-args.rs
+++ b/tests/rustdoc/inline_cross/default-generic-args.rs
@@ -53,17 +53,17 @@
//@ has user/type.H0.html
// Check that we handle higher-ranked regions correctly:
-//@ has - '//*[@class="rust item-decl"]//code' "fn(_: for<'a> fn(_: Re<'a>))"
+//@ has - '//*[@class="rust item-decl"]//code' "fn(for<'a> fn(Re<'a>))"
pub use default_generic_args::H0;
//@ has user/type.H1.html
// Check that we don't conflate distinct universially quantified regions (#1):
-//@ has - '//*[@class="rust item-decl"]//code' "for<'b> fn(_: for<'a> fn(_: Re<'a, &'b ()>))"
+//@ has - '//*[@class="rust item-decl"]//code' "for<'b> fn(for<'a> fn(Re<'a, &'b ()>))"
pub use default_generic_args::H1;
//@ has user/type.H2.html
// Check that we don't conflate distinct universially quantified regions (#2):
-//@ has - '//*[@class="rust item-decl"]//code' "for<'a> fn(_: for<'b> fn(_: Re<'a, &'b ()>))"
+//@ has - '//*[@class="rust item-decl"]//code' "for<'a> fn(for<'b> fn(Re<'a, &'b ()>))"
pub use default_generic_args::H2;
//@ has user/type.P0.html
@@ -86,7 +86,7 @@
// Demonstrates that we currently don't elide generic arguments that are alpha-equivalent to their
// respective generic parameter (after instantiation) for perf reasons (it would require us to
// create an inference context).
-//@ has - '//*[@class="rust item-decl"]//code' "Alpha<for<'arbitrary> fn(_: &'arbitrary ())>"
+//@ has - '//*[@class="rust item-decl"]//code' "Alpha<for<'arbitrary> fn(&'arbitrary ())>"
pub use default_generic_args::A1;
//@ has user/type.M0.html
diff --git a/tests/rustdoc/inline_cross/fn-type.rs b/tests/rustdoc/inline_cross/fn-ptr-ty.rs
similarity index 71%
rename from tests/rustdoc/inline_cross/fn-type.rs
rename to tests/rustdoc/inline_cross/fn-ptr-ty.rs
index 8db6f65..0105962 100644
--- a/tests/rustdoc/inline_cross/fn-type.rs
+++ b/tests/rustdoc/inline_cross/fn-ptr-ty.rs
@@ -2,11 +2,11 @@
// They should be rendered exactly as the user wrote it, i.e., in source order and with unused
// parameters present, not stripped.
-//@ aux-crate:fn_type=fn-type.rs
+//@ aux-crate:fn_ptr_ty=fn-ptr-ty.rs
//@ edition: 2021
#![crate_name = "user"]
//@ has user/type.F.html
//@ has - '//*[@class="rust item-decl"]//code' \
-// "for<'z, 'a, '_unused> fn(_: &'z for<'b> fn(_: &'b str), _: &'a ()) -> &'a ();"
-pub use fn_type::F;
+// "for<'z, 'a, '_unused> fn(&'z for<'b> fn(&'b str), &'a ()) -> &'a ();"
+pub use fn_ptr_ty::F;
diff --git a/tests/rustdoc/inline_cross/impl_trait.rs b/tests/rustdoc/inline_cross/impl_trait.rs
index e6baf33..468ac08 100644
--- a/tests/rustdoc/inline_cross/impl_trait.rs
+++ b/tests/rustdoc/inline_cross/impl_trait.rs
@@ -29,7 +29,7 @@
//@ has impl_trait/fn.func5.html
//@ has - '//pre[@class="rust item-decl"]' "func5("
//@ has - '//pre[@class="rust item-decl"]' "_f: impl for<'any> Fn(&'any str, &'any str) -> bool + for<'r> Other<T<'r> = ()>,"
-//@ has - '//pre[@class="rust item-decl"]' "_a: impl for<'beta, 'alpha, '_gamma> Auxiliary<'alpha, Item<'beta> = fn(_: &'beta ())>"
+//@ has - '//pre[@class="rust item-decl"]' "_a: impl for<'beta, 'alpha, '_gamma> Auxiliary<'alpha, Item<'beta> = fn(&'beta ())>"
//@ !has - '//pre[@class="rust item-decl"]' 'where'
pub use impl_trait_aux::func5;
diff --git a/tests/ui/abi/debug.rs b/tests/ui/abi/debug.rs
index 6dbc316..c0d8de0 100644
--- a/tests/ui/abi/debug.rs
+++ b/tests/ui/abi/debug.rs
@@ -52,3 +52,6 @@ fn assoc_test(&self) { } //~ ERROR: fn_abi
#[rustc_abi(assert_eq)]
type TestAbiEqNonsense = (fn((str, str)), fn((str, str))); //~ ERROR: cannot be known at compilation time
+
+#[rustc_abi("assert_eq")] //~ ERROR unrecognized argument
+type Bad = u32;
diff --git a/tests/ui/abi/debug.stderr b/tests/ui/abi/debug.stderr
index 2239ba0..480f3f0 100644
--- a/tests/ui/abi/debug.stderr
+++ b/tests/ui/abi/debug.stderr
@@ -906,6 +906,12 @@
= help: the trait `Sized` is not implemented for `str`
= note: only the last element of a tuple may have a dynamically sized type
+error: unrecognized argument
+ --> $DIR/debug.rs:56:13
+ |
+LL | #[rustc_abi("assert_eq")]
+ | ^^^^^^^^^^^
+
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:29:5
|
@@ -1004,6 +1010,6 @@
LL | fn assoc_test(&self) { }
| ^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 11 previous errors
+error: aborting due to 12 previous errors
For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr b/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr
index a1ea2b4..dc8e424 100644
--- a/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr
+++ b/tests/ui/async-await/pin-ergonomics/reborrow-once.stderr
@@ -1,4 +1,4 @@
-error[E0499]: cannot borrow `*x.__pointer` as mutable more than once at a time
+error[E0499]: cannot borrow `*x.pointer` as mutable more than once at a time
--> $DIR/reborrow-once.rs:12:14
|
LL | twice(x, x);
diff --git a/tests/ui/attributes/check-builtin-attr-ice.rs b/tests/ui/attributes/check-builtin-attr-ice.rs
index 9ef5890..7745849 100644
--- a/tests/ui/attributes/check-builtin-attr-ice.rs
+++ b/tests/ui/attributes/check-builtin-attr-ice.rs
@@ -39,13 +39,17 @@
// Notably, `should_panic` is a `AttributeType::Normal` attribute that is checked separately.
+#![deny(unused_attributes)]
+
struct Foo {
#[should_panic::skip]
//~^ ERROR failed to resolve
+ //~| ERROR `#[should_panic::skip]` only has an effect on functions
pub field: u8,
#[should_panic::a::b::c]
//~^ ERROR failed to resolve
+ //~| ERROR `#[should_panic::a::b::c]` only has an effect on functions
pub field2: u8,
}
diff --git a/tests/ui/attributes/check-builtin-attr-ice.stderr b/tests/ui/attributes/check-builtin-attr-ice.stderr
index 06a4769..4f26f71 100644
--- a/tests/ui/attributes/check-builtin-attr-ice.stderr
+++ b/tests/ui/attributes/check-builtin-attr-ice.stderr
@@ -1,21 +1,39 @@
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `should_panic`
- --> $DIR/check-builtin-attr-ice.rs:43:7
+ --> $DIR/check-builtin-attr-ice.rs:45:7
|
LL | #[should_panic::skip]
| ^^^^^^^^^^^^ use of unresolved module or unlinked crate `should_panic`
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `should_panic`
- --> $DIR/check-builtin-attr-ice.rs:47:7
+ --> $DIR/check-builtin-attr-ice.rs:50:7
|
LL | #[should_panic::a::b::c]
| ^^^^^^^^^^^^ use of unresolved module or unlinked crate `should_panic`
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `deny`
- --> $DIR/check-builtin-attr-ice.rs:55:7
+ --> $DIR/check-builtin-attr-ice.rs:59:7
|
LL | #[deny::skip]
| ^^^^ use of unresolved module or unlinked crate `deny`
-error: aborting due to 3 previous errors
+error: `#[should_panic::skip]` only has an effect on functions
+ --> $DIR/check-builtin-attr-ice.rs:45:5
+ |
+LL | #[should_panic::skip]
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/check-builtin-attr-ice.rs:42:9
+ |
+LL | #![deny(unused_attributes)]
+ | ^^^^^^^^^^^^^^^^^
+
+error: `#[should_panic::a::b::c]` only has an effect on functions
+ --> $DIR/check-builtin-attr-ice.rs:50:5
+ |
+LL | #[should_panic::a::b::c]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0433`.
diff --git a/tests/ui/attributes/invalid_macro_export_argument.deny.stderr b/tests/ui/attributes/invalid_macro_export_argument.deny.stderr
index 644acc2..9d44bd1 100644
--- a/tests/ui/attributes/invalid_macro_export_argument.deny.stderr
+++ b/tests/ui/attributes/invalid_macro_export_argument.deny.stderr
@@ -10,11 +10,17 @@
LL | #![cfg_attr(deny, deny(invalid_macro_export_arguments))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: `not_local_inner_macros` isn't a valid `#[macro_export]` argument
+error: invalid `#[macro_export]` argument
--> $DIR/invalid_macro_export_argument.rs:13:16
|
LL | #[macro_export(not_local_inner_macros)]
| ^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 2 previous errors
+error: invalid `#[macro_export]` argument
+ --> $DIR/invalid_macro_export_argument.rs:33:16
+ |
+LL | #[macro_export("blah")]
+ | ^^^^^^
+
+error: aborting due to 3 previous errors
diff --git a/tests/ui/attributes/invalid_macro_export_argument.rs b/tests/ui/attributes/invalid_macro_export_argument.rs
index 96f6699..c5fe39d 100644
--- a/tests/ui/attributes/invalid_macro_export_argument.rs
+++ b/tests/ui/attributes/invalid_macro_export_argument.rs
@@ -11,7 +11,7 @@ macro_rules! a {
}
#[macro_export(not_local_inner_macros)]
-//[deny]~^ ERROR `not_local_inner_macros` isn't a valid `#[macro_export]` argument
+//[deny]~^ ERROR invalid `#[macro_export]` argument
macro_rules! b {
() => ()
}
@@ -30,4 +30,10 @@ macro_rules! e {
() => ()
}
+#[macro_export("blah")]
+//[deny]~^ ERROR invalid `#[macro_export]` argument
+macro_rules! f {
+ () => ()
+}
+
fn main() {}
diff --git a/tests/ui/attributes/no-sanitize.rs b/tests/ui/attributes/no-sanitize.rs
index 8c79866..ddf909b 100644
--- a/tests/ui/attributes/no-sanitize.rs
+++ b/tests/ui/attributes/no-sanitize.rs
@@ -38,3 +38,8 @@ fn valid() {}
#[no_sanitize(address)]
static VALID : i32 = 0;
+
+#[no_sanitize("address")]
+//~^ ERROR `#[no_sanitize(...)]` should be applied to a function
+//~| ERROR invalid argument for `no_sanitize`
+static VALID2 : i32 = 0;
diff --git a/tests/ui/attributes/no-sanitize.stderr b/tests/ui/attributes/no-sanitize.stderr
index 9b0b76e..8d5fbb1 100644
--- a/tests/ui/attributes/no-sanitize.stderr
+++ b/tests/ui/attributes/no-sanitize.stderr
@@ -59,5 +59,22 @@
LL | static INVALID : i32 = 0;
| ------------------------- not a function
-error: aborting due to 7 previous errors
+error: `#[no_sanitize(...)]` should be applied to a function
+ --> $DIR/no-sanitize.rs:42:15
+ |
+LL | #[no_sanitize("address")]
+ | ^^^^^^^^^
+...
+LL | static VALID2 : i32 = 0;
+ | ------------------------ not a function
+
+error: invalid argument for `no_sanitize`
+ --> $DIR/no-sanitize.rs:42:15
+ |
+LL | #[no_sanitize("address")]
+ | ^^^^^^^^^
+ |
+ = note: expected one of: `address`, `cfi`, `hwaddress`, `kcfi`, `memory`, `memtag`, `shadow-call-stack`, or `thread`
+
+error: aborting due to 9 previous errors
diff --git a/tests/ui/coroutine/postfix-yield.rs b/tests/ui/coroutine/postfix-yield.rs
index ff84313..f2fdceb 100644
--- a/tests/ui/coroutine/postfix-yield.rs
+++ b/tests/ui/coroutine/postfix-yield.rs
@@ -3,7 +3,7 @@
//@ run-pass
//@ edition: 2024
-#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr)]
+#![feature(gen_blocks, coroutines, coroutine_trait, yield_expr, stmt_expr_attributes)]
use std::ops::{Coroutine, CoroutineState};
use std::pin::pin;
diff --git a/tests/ui/errors/pic-linker.rs b/tests/ui/errors/pic-linker.rs
index d909899..36495ca 100644
--- a/tests/ui/errors/pic-linker.rs
+++ b/tests/ui/errors/pic-linker.rs
@@ -5,6 +5,7 @@
//@ ignore-windows
//@ ignore-macos
//@ ignore-cross-compile
+//@ ignore-aix
//@ compile-flags: -Clink-args=-Wl,-z,text
//@ run-pass
diff --git a/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs b/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs
deleted file mode 100644
index deb5a2f..0000000
--- a/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-//@ edition:2018
-#![forbid(internal_features, unsafe_code)]
-#![feature(unsafe_pin_internals)]
-//~^ ERROR the feature `unsafe_pin_internals` is internal to the compiler or standard library
-
-use core::{marker::PhantomPinned, pin::Pin};
-
-/// The `unsafe_pin_internals` is indeed unsound.
-fn non_unsafe_pin_new_unchecked<T>(pointer: &mut T) -> Pin<&mut T> {
- Pin { __pointer: pointer }
-}
-
-fn main() {
- let mut self_referential = PhantomPinned;
- let _: Pin<&mut PhantomPinned> = non_unsafe_pin_new_unchecked(&mut self_referential);
-}
diff --git a/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.stderr b/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.stderr
deleted file mode 100644
index fc9bcd9..0000000
--- a/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.stderr
+++ /dev/null
@@ -1,15 +0,0 @@
-error: the feature `unsafe_pin_internals` is internal to the compiler or standard library
- --> $DIR/feature-gate-unsafe_pin_internals.rs:3:12
- |
-LL | #![feature(unsafe_pin_internals)]
- | ^^^^^^^^^^^^^^^^^^^^
- |
- = note: using it is strongly discouraged
-note: the lint level is defined here
- --> $DIR/feature-gate-unsafe_pin_internals.rs:2:11
- |
-LL | #![forbid(internal_features, unsafe_code)]
- | ^^^^^^^^^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/lint/break-with-label-and-unsafe-block.rs b/tests/ui/lint/break-with-label-and-unsafe-block.rs
new file mode 100644
index 0000000..a76a576
--- /dev/null
+++ b/tests/ui/lint/break-with-label-and-unsafe-block.rs
@@ -0,0 +1,11 @@
+//@ check-pass
+
+#![deny(break_with_label_and_loop)]
+
+unsafe fn foo() -> i32 { 42 }
+
+fn main () {
+ 'label: loop {
+ break 'label unsafe { foo() }
+ };
+}
diff --git a/tests/ui/pattern/deref-patterns/bindings.rs b/tests/ui/pattern/deref-patterns/bindings.rs
index 5881e41..c14d57f 100644
--- a/tests/ui/pattern/deref-patterns/bindings.rs
+++ b/tests/ui/pattern/deref-patterns/bindings.rs
@@ -1,7 +1,9 @@
+//@ revisions: explicit implicit
//@ run-pass
#![feature(deref_patterns)]
#![allow(incomplete_features)]
+#[cfg(explicit)]
fn simple_vec(vec: Vec<u32>) -> u32 {
match vec {
deref!([]) => 100,
@@ -13,6 +15,19 @@ fn simple_vec(vec: Vec<u32>) -> u32 {
}
}
+#[cfg(implicit)]
+fn simple_vec(vec: Vec<u32>) -> u32 {
+ match vec {
+ [] => 100,
+ [x] if x == 4 => x + 4,
+ [x] => x,
+ [1, x] => x + 200,
+ deref!(ref slice) => slice.iter().sum(),
+ _ => 2000,
+ }
+}
+
+#[cfg(explicit)]
fn nested_vec(vecvec: Vec<Vec<u32>>) -> u32 {
match vecvec {
deref!([]) => 0,
@@ -24,6 +39,19 @@ fn nested_vec(vecvec: Vec<Vec<u32>>) -> u32 {
}
}
+#[cfg(implicit)]
+fn nested_vec(vecvec: Vec<Vec<u32>>) -> u32 {
+ match vecvec {
+ [] => 0,
+ [[x]] => x,
+ [[0, x] | [1, x]] => x,
+ [ref x] => x.iter().sum(),
+ [[], [1, x, y]] => y - x,
+ _ => 2000,
+ }
+}
+
+#[cfg(explicit)]
fn ref_mut(val: u32) -> u32 {
let mut b = Box::new(0u32);
match &mut b {
@@ -37,6 +65,21 @@ fn ref_mut(val: u32) -> u32 {
*x
}
+#[cfg(implicit)]
+fn ref_mut(val: u32) -> u32 {
+ let mut b = Box::new((0u32,));
+ match &mut b {
+ (_x,) if false => unreachable!(),
+ (x,) => {
+ *x = val;
+ }
+ _ => unreachable!(),
+ }
+ let (x,) = &b else { unreachable!() };
+ *x
+}
+
+#[cfg(explicit)]
#[rustfmt::skip]
fn or_and_guard(tuple: (u32, u32)) -> u32 {
let mut sum = 0;
@@ -48,6 +91,18 @@ fn or_and_guard(tuple: (u32, u32)) -> u32 {
sum
}
+#[cfg(implicit)]
+#[rustfmt::skip]
+fn or_and_guard(tuple: (u32, u32)) -> u32 {
+ let mut sum = 0;
+ let b = Box::new(tuple);
+ match b {
+ (x, _) | (_, x) if { sum += x; false } => {},
+ _ => {},
+ }
+ sum
+}
+
fn main() {
assert_eq!(simple_vec(vec![1]), 1);
assert_eq!(simple_vec(vec![1, 2]), 202);
diff --git a/tests/ui/pattern/deref-patterns/branch.rs b/tests/ui/pattern/deref-patterns/branch.rs
index 1bac100..9d72b35 100644
--- a/tests/ui/pattern/deref-patterns/branch.rs
+++ b/tests/ui/pattern/deref-patterns/branch.rs
@@ -1,8 +1,10 @@
+//@ revisions: explicit implicit
//@ run-pass
// Test the execution of deref patterns.
#![feature(deref_patterns)]
#![allow(incomplete_features)]
+#[cfg(explicit)]
fn branch(vec: Vec<u32>) -> u32 {
match vec {
deref!([]) => 0,
@@ -12,6 +14,17 @@ fn branch(vec: Vec<u32>) -> u32 {
}
}
+#[cfg(implicit)]
+fn branch(vec: Vec<u32>) -> u32 {
+ match vec {
+ [] => 0,
+ [1, _, 3] => 1,
+ [2, ..] => 2,
+ _ => 1000,
+ }
+}
+
+#[cfg(explicit)]
fn nested(vec: Vec<Vec<u32>>) -> u32 {
match vec {
deref!([deref!([]), ..]) => 1,
@@ -20,6 +33,15 @@ fn nested(vec: Vec<Vec<u32>>) -> u32 {
}
}
+#[cfg(implicit)]
+fn nested(vec: Vec<Vec<u32>>) -> u32 {
+ match vec {
+ [[], ..] => 1,
+ [[0, ..], [1, ..]] => 2,
+ _ => 1000,
+ }
+}
+
fn main() {
assert!(matches!(Vec::<u32>::new(), deref!([])));
assert!(matches!(vec![1], deref!([1])));
diff --git a/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.rs b/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.rs
index 84b5ec0..791776b 100644
--- a/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.rs
+++ b/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.rs
@@ -21,4 +21,22 @@ fn cant_move_out_rc(rc: Rc<Struct>) -> Struct {
}
}
+struct Container(Struct);
+
+fn cant_move_out_box_implicit(b: Box<Container>) -> Struct {
+ match b {
+ //~^ ERROR: cannot move out of a shared reference
+ Container(x) => x,
+ _ => unreachable!(),
+ }
+}
+
+fn cant_move_out_rc_implicit(rc: Rc<Container>) -> Struct {
+ match rc {
+ //~^ ERROR: cannot move out of a shared reference
+ Container(x) => x,
+ _ => unreachable!(),
+ }
+}
+
fn main() {}
diff --git a/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr b/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr
index 2cf435b..1887800 100644
--- a/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr
+++ b/tests/ui/pattern/deref-patterns/cant_move_out_of_pattern.stderr
@@ -32,6 +32,40 @@
LL | deref!(ref x) => x,
| +++
-error: aborting due to 2 previous errors
+error[E0507]: cannot move out of a shared reference
+ --> $DIR/cant_move_out_of_pattern.rs:27:11
+ |
+LL | match b {
+ | ^
+LL |
+LL | Container(x) => x,
+ | -
+ | |
+ | data moved here
+ | move occurs because `x` has type `Struct`, which does not implement the `Copy` trait
+ |
+help: consider borrowing the pattern binding
+ |
+LL | Container(ref x) => x,
+ | +++
+
+error[E0507]: cannot move out of a shared reference
+ --> $DIR/cant_move_out_of_pattern.rs:35:11
+ |
+LL | match rc {
+ | ^^
+LL |
+LL | Container(x) => x,
+ | -
+ | |
+ | data moved here
+ | move occurs because `x` has type `Struct`, which does not implement the `Copy` trait
+ |
+help: consider borrowing the pattern binding
+ |
+LL | Container(ref x) => x,
+ | +++
+
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0507`.
diff --git a/tests/ui/pattern/deref-patterns/closure_capture.rs b/tests/ui/pattern/deref-patterns/closure_capture.rs
index fc0dded..08586b6 100644
--- a/tests/ui/pattern/deref-patterns/closure_capture.rs
+++ b/tests/ui/pattern/deref-patterns/closure_capture.rs
@@ -11,6 +11,15 @@ fn main() {
assert_eq!(b.len(), 3);
f();
+ let v = vec![1, 2, 3];
+ let f = || {
+ // this should count as a borrow of `v` as a whole
+ let [.., x] = v else { unreachable!() };
+ assert_eq!(x, 3);
+ };
+ assert_eq!(v, [1, 2, 3]);
+ f();
+
let mut b = Box::new("aaa".to_string());
let mut f = || {
let deref!(ref mut s) = b else { unreachable!() };
@@ -18,4 +27,22 @@ fn main() {
};
f();
assert_eq!(b.len(), 5);
+
+ let mut v = vec![1, 2, 3];
+ let mut f = || {
+ // this should count as a mutable borrow of `v` as a whole
+ let [.., ref mut x] = v else { unreachable!() };
+ *x = 4;
+ };
+ f();
+ assert_eq!(v, [1, 2, 4]);
+
+ let mut v = vec![1, 2, 3];
+ let mut f = || {
+ // here, `[.., x]` is adjusted by both an overloaded deref and a builtin deref
+ let [.., x] = &mut v else { unreachable!() };
+ *x = 4;
+ };
+ f();
+ assert_eq!(v, [1, 2, 4]);
}
diff --git a/tests/ui/pattern/deref-patterns/fake_borrows.rs b/tests/ui/pattern/deref-patterns/fake_borrows.rs
index 35fa9cb..bf614d7 100644
--- a/tests/ui/pattern/deref-patterns/fake_borrows.rs
+++ b/tests/ui/pattern/deref-patterns/fake_borrows.rs
@@ -11,4 +11,11 @@ fn main() {
deref!(false) => {}
_ => {},
}
+ match b {
+ true => {}
+ _ if { *b = true; false } => {}
+ //~^ ERROR cannot assign `*b` in match guard
+ false => {}
+ _ => {},
+ }
}
diff --git a/tests/ui/pattern/deref-patterns/fake_borrows.stderr b/tests/ui/pattern/deref-patterns/fake_borrows.stderr
index 6a591e6..8c06023 100644
--- a/tests/ui/pattern/deref-patterns/fake_borrows.stderr
+++ b/tests/ui/pattern/deref-patterns/fake_borrows.stderr
@@ -7,6 +7,15 @@
LL | _ if { *b = true; false } => {}
| ^^^^^^^^^ cannot assign
-error: aborting due to 1 previous error
+error[E0510]: cannot assign `*b` in match guard
+ --> $DIR/fake_borrows.rs:16:16
+ |
+LL | match b {
+ | - value is immutable in match guard
+LL | true => {}
+LL | _ if { *b = true; false } => {}
+ | ^^^^^^^^^ cannot assign
+
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0510`.
diff --git a/tests/ui/pattern/deref-patterns/implicit-const-deref.rs b/tests/ui/pattern/deref-patterns/implicit-const-deref.rs
new file mode 100644
index 0000000..70f8962
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/implicit-const-deref.rs
@@ -0,0 +1,19 @@
+//! Test that we get an error about structural equality rather than a type error when attempting to
+//! use const patterns of library pointer types. Currently there aren't any smart pointers that can
+//! be used in constant patterns, but we still need to make sure we don't implicitly dereference the
+//! scrutinee and end up with a type error; this would prevent us from reporting that only constants
+//! supporting structural equality can be used as patterns.
+#![feature(deref_patterns)]
+#![allow(incomplete_features)]
+
+const EMPTY: Vec<()> = Vec::new();
+
+fn main() {
+ // FIXME(inline_const_pat): if `inline_const_pat` is reinstated, there should be a case here for
+ // inline const block patterns as well; they're checked differently than named constants.
+ match vec![()] {
+ EMPTY => {}
+ //~^ ERROR: constant of non-structural type `Vec<()>` in a pattern
+ _ => {}
+ }
+}
diff --git a/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr b/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr
new file mode 100644
index 0000000..21d09ec4
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/implicit-const-deref.stderr
@@ -0,0 +1,16 @@
+error: constant of non-structural type `Vec<()>` in a pattern
+ --> $DIR/implicit-const-deref.rs:15:9
+ |
+LL | const EMPTY: Vec<()> = Vec::new();
+ | -------------------- constant defined here
+...
+LL | EMPTY => {}
+ | ^^^^^ constant of non-structural type
+ --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
+ |
+ = note: `Vec<()>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
+ |
+ = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/pattern/deref-patterns/implicit-cow-deref.rs b/tests/ui/pattern/deref-patterns/implicit-cow-deref.rs
new file mode 100644
index 0000000..a9b8de8
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/implicit-cow-deref.rs
@@ -0,0 +1,45 @@
+//@ run-pass
+//! Test that implicit deref patterns interact as expected with `Cow` constructor patterns.
+#![feature(deref_patterns)]
+#![allow(incomplete_features)]
+
+use std::borrow::Cow;
+
+fn main() {
+ let cow: Cow<'static, [u8]> = Cow::Borrowed(&[1, 2, 3]);
+
+ match cow {
+ [..] => {}
+ _ => unreachable!(),
+ }
+
+ match cow {
+ Cow::Borrowed(_) => {}
+ Cow::Owned(_) => unreachable!(),
+ }
+
+ match Box::new(&cow) {
+ Cow::Borrowed { 0: _ } => {}
+ Cow::Owned { 0: _ } => unreachable!(),
+ _ => unreachable!(),
+ }
+
+ let cow_of_cow: Cow<'_, Cow<'static, [u8]>> = Cow::Owned(cow);
+
+ match cow_of_cow {
+ [..] => {}
+ _ => unreachable!(),
+ }
+
+ // This matches on the outer `Cow` (the owned one).
+ match cow_of_cow {
+ Cow::Borrowed(_) => unreachable!(),
+ Cow::Owned(_) => {}
+ }
+
+ match Box::new(&cow_of_cow) {
+ Cow::Borrowed { 0: _ } => unreachable!(),
+ Cow::Owned { 0: _ } => {}
+ _ => unreachable!(),
+ }
+}
diff --git a/tests/ui/pattern/deref-patterns/needs-gate.rs b/tests/ui/pattern/deref-patterns/needs-gate.rs
new file mode 100644
index 0000000..2d5ec45
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/needs-gate.rs
@@ -0,0 +1,15 @@
+// gate-test-deref_patterns
+
+fn main() {
+ match Box::new(0) {
+ deref!(0) => {}
+ //~^ ERROR: use of unstable library feature `deref_patterns`: placeholder syntax for deref patterns
+ _ => {}
+ }
+
+ match Box::new(0) {
+ 0 => {}
+ //~^ ERROR: mismatched types
+ _ => {}
+ }
+}
diff --git a/tests/ui/pattern/deref-patterns/needs-gate.stderr b/tests/ui/pattern/deref-patterns/needs-gate.stderr
new file mode 100644
index 0000000..8687b5d
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/needs-gate.stderr
@@ -0,0 +1,29 @@
+error[E0658]: use of unstable library feature `deref_patterns`: placeholder syntax for deref patterns
+ --> $DIR/needs-gate.rs:5:9
+ |
+LL | deref!(0) => {}
+ | ^^^^^
+ |
+ = note: see issue #87121 <https://github.com/rust-lang/rust/issues/87121> for more information
+ = help: add `#![feature(deref_patterns)]` to the crate attributes to enable
+ = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error[E0308]: mismatched types
+ --> $DIR/needs-gate.rs:11:9
+ |
+LL | match Box::new(0) {
+ | ----------- this expression has type `Box<{integer}>`
+LL | 0 => {}
+ | ^ expected `Box<{integer}>`, found integer
+ |
+ = note: expected struct `Box<{integer}>`
+ found type `{integer}`
+help: consider dereferencing to access the inner value using the Deref trait
+ |
+LL | match *Box::new(0) {
+ | +
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0308, E0658.
+For more information about an error, try `rustc --explain E0308`.
diff --git a/tests/ui/pattern/deref-patterns/recursion-limit.rs b/tests/ui/pattern/deref-patterns/recursion-limit.rs
new file mode 100644
index 0000000..c5fe520
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/recursion-limit.rs
@@ -0,0 +1,23 @@
+//! Test that implicit deref patterns respect the recursion limit
+#![feature(deref_patterns)]
+#![allow(incomplete_features)]
+#![recursion_limit = "8"]
+
+use std::ops::Deref;
+
+struct Cyclic;
+impl Deref for Cyclic {
+ type Target = Cyclic;
+ fn deref(&self) -> &Cyclic {
+ &Cyclic
+ }
+}
+
+fn main() {
+ match &Box::new(Cyclic) {
+ () => {}
+ //~^ ERROR: reached the recursion limit while auto-dereferencing `Cyclic`
+ //~| ERROR: the trait bound `Cyclic: DerefPure` is not satisfied
+ _ => {}
+ }
+}
diff --git a/tests/ui/pattern/deref-patterns/recursion-limit.stderr b/tests/ui/pattern/deref-patterns/recursion-limit.stderr
new file mode 100644
index 0000000..9a83d1e
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/recursion-limit.stderr
@@ -0,0 +1,18 @@
+error[E0055]: reached the recursion limit while auto-dereferencing `Cyclic`
+ --> $DIR/recursion-limit.rs:18:9
+ |
+LL | () => {}
+ | ^^ deref recursion limit reached
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "16"]` attribute to your crate (`recursion_limit`)
+
+error[E0277]: the trait bound `Cyclic: DerefPure` is not satisfied
+ --> $DIR/recursion-limit.rs:18:9
+ |
+LL | () => {}
+ | ^^ the trait `DerefPure` is not implemented for `Cyclic`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0055, E0277.
+For more information about an error, try `rustc --explain E0055`.
diff --git a/tests/ui/pattern/deref-patterns/ref-mut.rs b/tests/ui/pattern/deref-patterns/ref-mut.rs
index 1918008..4373867 100644
--- a/tests/ui/pattern/deref-patterns/ref-mut.rs
+++ b/tests/ui/pattern/deref-patterns/ref-mut.rs
@@ -8,10 +8,19 @@ fn main() {
deref!(x) => {}
_ => {}
}
+ match &mut vec![1] {
+ [x] => {}
+ _ => {}
+ }
match &mut Rc::new(1) {
deref!(x) => {}
//~^ ERROR the trait bound `Rc<{integer}>: DerefMut` is not satisfied
_ => {}
}
+ match &mut Rc::new((1,)) {
+ (x,) => {}
+ //~^ ERROR the trait bound `Rc<({integer},)>: DerefMut` is not satisfied
+ _ => {}
+ }
}
diff --git a/tests/ui/pattern/deref-patterns/ref-mut.stderr b/tests/ui/pattern/deref-patterns/ref-mut.stderr
index 41f1c30..24a35b4 100644
--- a/tests/ui/pattern/deref-patterns/ref-mut.stderr
+++ b/tests/ui/pattern/deref-patterns/ref-mut.stderr
@@ -8,13 +8,19 @@
= note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `Rc<{integer}>: DerefMut` is not satisfied
- --> $DIR/ref-mut.rs:13:9
+ --> $DIR/ref-mut.rs:17:9
|
LL | deref!(x) => {}
| ^^^^^^^^^ the trait `DerefMut` is not implemented for `Rc<{integer}>`
|
= note: this error originates in the macro `deref` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 1 previous error; 1 warning emitted
+error[E0277]: the trait bound `Rc<({integer},)>: DerefMut` is not satisfied
+ --> $DIR/ref-mut.rs:22:9
+ |
+LL | (x,) => {}
+ | ^^^^ the trait `DerefMut` is not implemented for `Rc<({integer},)>`
+
+error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/pattern/deref-patterns/typeck.rs b/tests/ui/pattern/deref-patterns/typeck.rs
index f23f704..3a7ce9d 100644
--- a/tests/ui/pattern/deref-patterns/typeck.rs
+++ b/tests/ui/pattern/deref-patterns/typeck.rs
@@ -10,26 +10,32 @@ fn main() {
let vec: Vec<u32> = Vec::new();
match vec {
deref!([..]) => {}
+ [..] => {}
_ => {}
}
match Box::new(true) {
deref!(true) => {}
+ true => {}
_ => {}
}
match &Box::new(true) {
deref!(true) => {}
+ true => {}
_ => {}
}
match &Rc::new(0) {
deref!(1..) => {}
+ 1.. => {}
_ => {}
}
let _: &Struct = match &Rc::new(Struct) {
deref!(x) => x,
+ Struct => &Struct,
_ => unreachable!(),
};
let _: &[Struct] = match &Rc::new(vec![Struct]) {
deref!(deref!(x)) => x,
+ [Struct] => &[Struct],
_ => unreachable!(),
};
}
diff --git a/tests/ui/pattern/deref-patterns/typeck_fail.rs b/tests/ui/pattern/deref-patterns/typeck_fail.rs
index 0401184..4b9ad7d 100644
--- a/tests/ui/pattern/deref-patterns/typeck_fail.rs
+++ b/tests/ui/pattern/deref-patterns/typeck_fail.rs
@@ -7,11 +7,22 @@ fn main() {
match "foo".to_string() {
deref!("foo") => {}
//~^ ERROR: mismatched types
+ "foo" => {}
+ //~^ ERROR: mismatched types
_ => {}
}
match &"foo".to_string() {
deref!("foo") => {}
//~^ ERROR: mismatched types
+ "foo" => {}
+ //~^ ERROR: mismatched types
+ _ => {}
+ }
+
+ // Make sure we don't try implicitly dereferncing any ADT.
+ match Some(0) {
+ Ok(0) => {}
+ //~^ ERROR: mismatched types
_ => {}
}
}
diff --git a/tests/ui/pattern/deref-patterns/typeck_fail.stderr b/tests/ui/pattern/deref-patterns/typeck_fail.stderr
index 1c14802..3e2f356 100644
--- a/tests/ui/pattern/deref-patterns/typeck_fail.stderr
+++ b/tests/ui/pattern/deref-patterns/typeck_fail.stderr
@@ -7,13 +7,45 @@
| ^^^^^ expected `str`, found `&str`
error[E0308]: mismatched types
- --> $DIR/typeck_fail.rs:13:16
+ --> $DIR/typeck_fail.rs:10:9
+ |
+LL | match "foo".to_string() {
+ | ----------------- this expression has type `String`
+...
+LL | "foo" => {}
+ | ^^^^^ expected `String`, found `&str`
+
+error[E0308]: mismatched types
+ --> $DIR/typeck_fail.rs:15:16
|
LL | match &"foo".to_string() {
| ------------------ this expression has type `&String`
LL | deref!("foo") => {}
| ^^^^^ expected `str`, found `&str`
-error: aborting due to 2 previous errors
+error[E0308]: mismatched types
+ --> $DIR/typeck_fail.rs:17:9
+ |
+LL | match &"foo".to_string() {
+ | ------------------ this expression has type `&String`
+...
+LL | "foo" => {}
+ | ^^^^^ expected `&String`, found `&str`
+ |
+ = note: expected reference `&String`
+ found reference `&'static str`
+
+error[E0308]: mismatched types
+ --> $DIR/typeck_fail.rs:24:9
+ |
+LL | match Some(0) {
+ | ------- this expression has type `Option<{integer}>`
+LL | Ok(0) => {}
+ | ^^^^^ expected `Option<{integer}>`, found `Result<_, _>`
+ |
+ = note: expected enum `Option<{integer}>`
+ found enum `Result<_, _>`
+
+error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/pattern/deref-patterns/unsatisfied-bounds.rs b/tests/ui/pattern/deref-patterns/unsatisfied-bounds.rs
new file mode 100644
index 0000000..00064b2
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/unsatisfied-bounds.rs
@@ -0,0 +1,21 @@
+#![feature(deref_patterns)]
+#![allow(incomplete_features)]
+
+struct MyPointer;
+
+impl std::ops::Deref for MyPointer {
+ type Target = ();
+ fn deref(&self) -> &() {
+ &()
+ }
+}
+
+fn main() {
+ // Test that we get a trait error if a user attempts implicit deref pats on their own impls.
+ // FIXME(deref_patterns): there should be a special diagnostic for missing `DerefPure`.
+ match MyPointer {
+ () => {}
+ //~^ the trait bound `MyPointer: DerefPure` is not satisfied
+ _ => {}
+ }
+}
diff --git a/tests/ui/pattern/deref-patterns/unsatisfied-bounds.stderr b/tests/ui/pattern/deref-patterns/unsatisfied-bounds.stderr
new file mode 100644
index 0000000..983ce27
--- /dev/null
+++ b/tests/ui/pattern/deref-patterns/unsatisfied-bounds.stderr
@@ -0,0 +1,9 @@
+error[E0277]: the trait bound `MyPointer: DerefPure` is not satisfied
+ --> $DIR/unsatisfied-bounds.rs:17:9
+ |
+LL | () => {}
+ | ^^ the trait `DerefPure` is not implemented for `MyPointer`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/pattern/uninit-trivial.rs b/tests/ui/pattern/uninit-trivial.rs
new file mode 100644
index 0000000..6ea6796
--- /dev/null
+++ b/tests/ui/pattern/uninit-trivial.rs
@@ -0,0 +1,8 @@
+// Regression test for the semantic changes in
+// <https://github.com/rust-lang/rust/pull/139042>.
+
+fn main() {
+ let x;
+ let (0 | _) = x;
+ //~^ ERROR used binding `x` isn't initialized
+}
diff --git a/tests/ui/pattern/uninit-trivial.stderr b/tests/ui/pattern/uninit-trivial.stderr
new file mode 100644
index 0000000..2ff8557
--- /dev/null
+++ b/tests/ui/pattern/uninit-trivial.stderr
@@ -0,0 +1,16 @@
+error[E0381]: used binding `x` isn't initialized
+ --> $DIR/uninit-trivial.rs:6:10
+ |
+LL | let x;
+ | - binding declared here but left uninitialized
+LL | let (0 | _) = x;
+ | ^^^^^ `x` used here but it isn't initialized
+ |
+help: consider assigning a value
+ |
+LL | let x = 42;
+ | ++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0381`.
diff --git a/tests/ui/pin-macro/cant_access_internals.rs b/tests/ui/pin-macro/cant_access_internals.rs
deleted file mode 100644
index 36a47d0..0000000
--- a/tests/ui/pin-macro/cant_access_internals.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-//@ edition:2018
-
-use core::{
- marker::PhantomPinned,
- mem,
- pin::{pin, Pin},
-};
-
-fn main() {
- let mut phantom_pinned = pin!(PhantomPinned);
- mem::take(phantom_pinned.__pointer); //~ ERROR use of unstable library feature `unsafe_pin_internals`
-}
diff --git a/tests/ui/pin-macro/cant_access_internals.stderr b/tests/ui/pin-macro/cant_access_internals.stderr
deleted file mode 100644
index 8ad897b..0000000
--- a/tests/ui/pin-macro/cant_access_internals.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0658]: use of unstable library feature `unsafe_pin_internals`
- --> $DIR/cant_access_internals.rs:11:15
- |
-LL | mem::take(phantom_pinned.__pointer);
- | ^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = help: add `#![feature(unsafe_pin_internals)]` to the crate attributes to enable
- = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
index 8a0244e..e505fe4 100644
--- a/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
+++ b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs
@@ -9,14 +9,14 @@
fn function_call_stops_borrow_extension() {
let phantom_pinned = identity(pin!(PhantomPinned));
- //~^ ERROR temporary value dropped while borrowed
+ //~^ ERROR does not live long enough
stuff(phantom_pinned)
}
fn promotion_only_works_for_the_innermost_block() {
let phantom_pinned = {
let phantom_pinned = pin!(PhantomPinned);
- //~^ ERROR temporary value dropped while borrowed
+ //~^ ERROR does not live long enough
phantom_pinned
};
stuff(phantom_pinned)
diff --git a/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr
index 9df7f0f..43fb82b 100644
--- a/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr
+++ b/tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.stderr
@@ -1,35 +1,29 @@
-error[E0716]: temporary value dropped while borrowed
+error[E0597]: value does not live long enough
--> $DIR/lifetime_errors_on_promotion_misusage.rs:11:35
|
LL | let phantom_pinned = identity(pin!(PhantomPinned));
- | ^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
+ | ^^^^^^^^^^^^^^^^^^^ - value dropped here while still borrowed
| |
- | creates a temporary value which is freed while still in use
+ | borrowed value does not live long enough
LL |
LL | stuff(phantom_pinned)
| -------------- borrow later used here
|
= note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)
-help: consider using a `let` binding to create a longer lived value
- |
-LL ~ let binding = pin!(PhantomPinned);
-LL ~ let phantom_pinned = identity(binding);
- |
-error[E0716]: temporary value dropped while borrowed
+error[E0597]: value does not live long enough
--> $DIR/lifetime_errors_on_promotion_misusage.rs:18:30
|
LL | let phantom_pinned = {
| -------------- borrow later stored here
LL | let phantom_pinned = pin!(PhantomPinned);
- | ^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
+ | ^^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
...
LL | };
- | - temporary value is freed at the end of this statement
+ | - value dropped here while still borrowed
|
- = note: consider using a `let` binding to create a longer lived value
= note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
-For more information about this error, try `rustc --explain E0716`.
+For more information about this error, try `rustc --explain E0597`.
diff --git a/tests/ui/pin-macro/pin_move.stderr b/tests/ui/pin-macro/pin_move.stderr
index c9b8ad9..3f46602 100644
--- a/tests/ui/pin-macro/pin_move.stderr
+++ b/tests/ui/pin-macro/pin_move.stderr
@@ -31,6 +31,11 @@
LL | let mut pointee = NotCopy(PhantomPinned);
LL | pin!(*&mut pointee);
| ------------- you could clone this value
+help: consider removing the dereference here
+ |
+LL - pin!(*&mut pointee);
+LL + pin!(&mut pointee);
+ |
error: aborting due to 2 previous errors