mirror of
https://github.com/openharmony/third_party_rust_rust.git
synced 2026-07-19 19:53:38 -04:00
Auto merge of #105248 - matthiaskrgr:rollup-d56k6bc, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #104856 (Don't suggest associated function call for associated const.) - #105123 (Fix passing MACOSX_DEPLOYMENT_TARGET to the linker) - #105142 (Make inline const block `ExprWithBlock`) - #105237 (Add regression test for #79450) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
@@ -21,6 +21,7 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::ForLoop(..)
|
||||
| ast::ExprKind::TryBlock(..)
|
||||
| ast::ExprKind::ConstBlock(..)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
@@ -1876,6 +1875,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
self.tcx.erase_late_bound_regions(value)
|
||||
}
|
||||
|
||||
/// Determine if the given associated item type is relevant in the current context.
|
||||
fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
|
||||
match (self.mode, kind) {
|
||||
(Mode::MethodCall, ty::AssocKind::Fn) => true,
|
||||
(Mode::Path, ty::AssocKind::Const | ty::AssocKind::Fn) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the method with the appropriate name (or return type, as the case may be). If
|
||||
/// `allow_similar_names` is set, find methods with close-matching names.
|
||||
// The length of the returned iterator is nearly always 0 or 1 and this
|
||||
@@ -1888,7 +1896,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
.associated_items(def_id)
|
||||
.in_definition_order()
|
||||
.filter(|x| {
|
||||
if x.kind.namespace() != Namespace::ValueNS {
|
||||
if !self.is_relevant_kind_for_mode(x.kind) {
|
||||
return false;
|
||||
}
|
||||
match lev_distance_with_substrings(name.as_str(), x.name.as_str(), max_dist)
|
||||
@@ -1902,10 +1910,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
} else {
|
||||
self.fcx
|
||||
.associated_value(def_id, name)
|
||||
.filter(|x| self.is_relevant_kind_for_mode(x.kind))
|
||||
.map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
|
||||
}
|
||||
} else {
|
||||
self.tcx.associated_items(def_id).in_definition_order().copied().collect()
|
||||
self.tcx
|
||||
.associated_items(def_id)
|
||||
.in_definition_order()
|
||||
.filter(|x| self.is_relevant_kind_for_mode(x.kind))
|
||||
.copied()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
|
||||
use super::apple_base::{macos_llvm_target, opts, Arch};
|
||||
use crate::spec::{FramePointer, SanitizerSet, Target, TargetOptions};
|
||||
|
||||
pub fn target() -> Target {
|
||||
@@ -10,8 +10,6 @@ pub fn target() -> Target {
|
||||
// FIXME: The leak sanitizer currently fails the tests, see #88132.
|
||||
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
|
||||
|
||||
base.link_env_remove.to_mut().extend(macos_link_env_remove());
|
||||
|
||||
Target {
|
||||
// Clang automatically chooses a more specific target based on
|
||||
// MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::spec::{
|
||||
aarch64_apple_ios_sim, aarch64_apple_watchos_sim, x86_64_apple_ios, x86_64_apple_tvos,
|
||||
x86_64_apple_watchos_sim,
|
||||
aarch64_apple_darwin, aarch64_apple_ios_sim, aarch64_apple_watchos_sim, i686_apple_darwin,
|
||||
x86_64_apple_darwin, x86_64_apple_ios, x86_64_apple_tvos, x86_64_apple_watchos_sim,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -18,3 +18,18 @@ fn simulator_targets_set_abi() {
|
||||
assert_eq!(target.abi, "sim")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macos_link_environment_unmodified() {
|
||||
let all_macos_targets = [
|
||||
aarch64_apple_darwin::target(),
|
||||
i686_apple_darwin::target(),
|
||||
x86_64_apple_darwin::target(),
|
||||
];
|
||||
|
||||
for target in all_macos_targets {
|
||||
// macOS targets should only remove information for cross-compiling, but never
|
||||
// for the host.
|
||||
assert_eq!(target.link_env_remove, crate::spec::cvs!["IPHONEOS_DEPLOYMENT_TARGET"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,16 +72,6 @@ impl Arch {
|
||||
Arm64_sim => "apple-a12",
|
||||
}
|
||||
}
|
||||
|
||||
fn link_env_remove(self) -> StaticCow<[StaticCow<str>]> {
|
||||
match self {
|
||||
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
|
||||
| Arm64_sim => {
|
||||
cvs!["MACOSX_DEPLOYMENT_TARGET"]
|
||||
}
|
||||
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_link_args(os: &'static str, arch: Arch, abi: &'static str) -> LinkArgs {
|
||||
@@ -140,7 +130,7 @@ pub fn opts(os: &'static str, arch: Arch) -> TargetOptions {
|
||||
abi: abi.into(),
|
||||
os: os.into(),
|
||||
cpu: arch.target_cpu().into(),
|
||||
link_env_remove: arch.link_env_remove(),
|
||||
link_env_remove: link_env_remove(arch, os),
|
||||
vendor: "apple".into(),
|
||||
linker_flavor: LinkerFlavor::Darwin(Cc::Yes, Lld::No),
|
||||
// macOS has -dead_strip, which doesn't rely on function_sections
|
||||
@@ -211,20 +201,38 @@ pub fn macos_llvm_target(arch: Arch) -> String {
|
||||
format!("{}-apple-macosx{}.{}.0", arch.target_name(), major, minor)
|
||||
}
|
||||
|
||||
pub fn macos_link_env_remove() -> Vec<StaticCow<str>> {
|
||||
let mut env_remove = Vec::with_capacity(2);
|
||||
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
|
||||
// may occur when we're linking a custom build script while targeting iOS for example.
|
||||
if let Ok(sdkroot) = env::var("SDKROOT") {
|
||||
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform") {
|
||||
env_remove.push("SDKROOT".into())
|
||||
fn link_env_remove(arch: Arch, os: &'static str) -> StaticCow<[StaticCow<str>]> {
|
||||
// Apple platforms only officially support macOS as a host for any compilation.
|
||||
//
|
||||
// If building for macOS, we go ahead and remove any erronous environment state
|
||||
// that's only applicable to cross-OS compilation. Always leave anything for the
|
||||
// host OS alone though.
|
||||
if os == "macos" {
|
||||
let mut env_remove = Vec::with_capacity(2);
|
||||
// Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which
|
||||
// may occur when we're linking a custom build script while targeting iOS for example.
|
||||
if let Ok(sdkroot) = env::var("SDKROOT") {
|
||||
if sdkroot.contains("iPhoneOS.platform") || sdkroot.contains("iPhoneSimulator.platform")
|
||||
{
|
||||
env_remove.push("SDKROOT".into())
|
||||
}
|
||||
}
|
||||
// Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at
|
||||
// "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
|
||||
// although this is apparently ignored when using the linker at "/usr/bin/ld".
|
||||
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
|
||||
env_remove.into()
|
||||
} else {
|
||||
// Otherwise if cross-compiling for a different OS/SDK, remove any part
|
||||
// of the linking environment that's wrong and reversed.
|
||||
match arch {
|
||||
Armv7 | Armv7k | Armv7s | Arm64 | Arm64_32 | I386 | I686 | X86_64 | X86_64_sim
|
||||
| Arm64_sim => {
|
||||
cvs!["MACOSX_DEPLOYMENT_TARGET"]
|
||||
}
|
||||
X86_64_macabi | Arm64_macabi => cvs!["IPHONEOS_DEPLOYMENT_TARGET"],
|
||||
}
|
||||
}
|
||||
// Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at
|
||||
// "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld",
|
||||
// although this is apparently ignored when using the linker at "/usr/bin/ld".
|
||||
env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into());
|
||||
env_remove
|
||||
}
|
||||
|
||||
fn ios_deployment_target() -> (u32, u32) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
|
||||
use super::apple_base::{macos_llvm_target, opts, Arch};
|
||||
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, StackProbeType, Target, TargetOptions};
|
||||
|
||||
pub fn target() -> Target {
|
||||
@@ -7,7 +7,6 @@ pub fn target() -> Target {
|
||||
let mut base = opts("macos", arch);
|
||||
base.max_atomic_width = Some(64);
|
||||
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"]);
|
||||
base.link_env_remove.to_mut().extend(macos_link_env_remove());
|
||||
base.stack_probes = StackProbeType::X86;
|
||||
base.frame_pointer = FramePointer::Always;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::apple_base::{macos_link_env_remove, macos_llvm_target, opts, Arch};
|
||||
use super::apple_base::{macos_llvm_target, opts, Arch};
|
||||
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, SanitizerSet};
|
||||
use crate::spec::{StackProbeType, Target, TargetOptions};
|
||||
|
||||
@@ -8,7 +8,6 @@ pub fn target() -> Target {
|
||||
base.max_atomic_width = Some(128); // core2 supports cmpxchg16b
|
||||
base.frame_pointer = FramePointer::Always;
|
||||
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m64"]);
|
||||
base.link_env_remove.to_mut().extend(macos_link_env_remove());
|
||||
base.stack_probes = StackProbeType::X86;
|
||||
base.supported_sanitizers =
|
||||
SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK | SanitizerSet::THREAD;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# only-macos
|
||||
#
|
||||
# Check that a set deployment target actually makes it to the linker.
|
||||
# This is important since its a compatibility hazard. The linker will
|
||||
# generate load commands differently based on what minimum OS it can assume.
|
||||
|
||||
include ../../run-make-fulldeps/tools.mk
|
||||
|
||||
ifeq ($(strip $(shell uname -m)),arm64)
|
||||
GREP_PATTERN = "minos 11.0"
|
||||
else
|
||||
GREP_PATTERN = "version 10.9"
|
||||
endif
|
||||
|
||||
OUT_FILE=$(TMPDIR)/with_deployment_target.dylib
|
||||
all:
|
||||
env MACOSX_DEPLOYMENT_TARGET=10.9 $(RUSTC) with_deployment_target.rs -o $(OUT_FILE)
|
||||
# XXX: The check is for either the x86_64 minimum OR the aarch64 minimum (M1 starts at macOS 11).
|
||||
# They also use different load commands, so we let that change with each too. The aarch64 check
|
||||
# isn't as robust as the x86 one, but testing both seems unneeded.
|
||||
vtool -show-build $(OUT_FILE) | $(CGREP) -e $(GREP_PATTERN)
|
||||
@@ -0,0 +1,4 @@
|
||||
#![crate_type = "cdylib"]
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn something_and_nothing() {}
|
||||
@@ -0,0 +1,6 @@
|
||||
#![feature(inline_const)]
|
||||
|
||||
fn main() {
|
||||
const { 2 } - const { 1 };
|
||||
//~^ ERROR mismatched types
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/expr-with-block-err.rs:4:13
|
||||
|
|
||||
LL | const { 2 } - const { 1 };
|
||||
| ^ expected `()`, found integer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
@@ -0,0 +1,10 @@
|
||||
// check-pass
|
||||
#![feature(inline_const)]
|
||||
fn main() {
|
||||
match true {
|
||||
true => const {}
|
||||
false => ()
|
||||
}
|
||||
const {}
|
||||
()
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#![feature(const_fmt_arguments_new)]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
#[const_trait]
|
||||
trait Tr {
|
||||
fn req(&self);
|
||||
|
||||
fn prov(&self) {
|
||||
println!("lul"); //~ ERROR: cannot call non-const fn `_print` in constant functions
|
||||
self.req();
|
||||
}
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
||||
impl const Tr for S {
|
||||
fn req(&self) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,12 @@
|
||||
error[E0015]: cannot call non-const fn `_print` in constant functions
|
||||
--> $DIR/issue-79450.rs:9:9
|
||||
|
|
||||
LL | println!("lul");
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
@@ -2,13 +2,7 @@ error[E0599]: no method named `MAX` found for type `u32` in the current scope
|
||||
--> $DIR/dont-suggest-ufcs-for-const.rs:2:11
|
||||
|
|
||||
LL | 1_u32.MAX();
|
||||
| ------^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `u32::MAX()`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
= note: the candidate is defined in an impl for the type `u32`
|
||||
| ^^^ method not found in `u32`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
||||
Reference in New Issue
Block a user