Auto merge of #116728 - matthiaskrgr:rollup-4xzcsnv, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #115653 (Guarantee that Layout::align returns a non-zero power of two)
 - #116577 (add `SAFETY` block on the usage of unsafe `getuid`)
 - #116618 (Add the V (vector) extension to the riscv64-linux-android target spec)
 - #116679 (Remove some unnecessary `unwrap`s)
 - #116689 (explicitly handle auto trait leakage in coherence)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-10-14 13:17:25 +00:00
commit 495c5ddcf7
12 changed files with 77 additions and 27 deletions

View File

@ -604,8 +604,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return false; return false;
} }
let box_found = Ty::new_box(self.tcx, found); let box_found = Ty::new_box(self.tcx, found);
let pin_box_found = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin).unwrap(); let Some(pin_box_found) = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin) else {
let pin_found = Ty::new_lang_item(self.tcx, found, LangItem::Pin).unwrap(); return false;
};
let Some(pin_found) = Ty::new_lang_item(self.tcx, found, LangItem::Pin) else {
return false;
};
match expected.kind() { match expected.kind() {
ty::Adt(def, _) if Some(def.did()) == pin_did => { ty::Adt(def, _) if Some(def.did()) == pin_did => {
if self.can_coerce(pin_box_found, expected) { if self.can_coerce(pin_box_found, expected) {

View File

@ -1616,7 +1616,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
continue; continue;
} }
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None); let Some(range_def_id) =
lang_item.and_then(|lang_item| self.tcx.lang_items().get(lang_item))
else {
continue;
};
let range_ty = let range_ty =
self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]); self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]);
@ -2539,11 +2543,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Err(_) => (), Err(_) => (),
} }
let pred = ty::TraitRef::new( let Some(unpin_trait) = self.tcx.lang_items().unpin_trait() else {
self.tcx, return;
self.tcx.lang_items().unpin_trait().unwrap(), };
[*rcvr_ty], let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
);
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new( let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
self.tcx, self.tcx,
ObligationCause::misc(rcvr.span, self.body_id), ObligationCause::misc(rcvr.span, self.body_id),

View File

@ -353,7 +353,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
ty::Generator(def_id, ..) => { ty::Generator(def_id, ..) => {
// async fn should be treated as "implementor of `Future`" // async fn should be treated as "implementor of `Future`"
let must_use = if cx.tcx.generator_is_async(def_id) { let must_use = if cx.tcx.generator_is_async(def_id) {
let def_id = cx.tcx.lang_items().future_trait().unwrap(); let def_id = cx.tcx.lang_items().future_trait()?;
is_def_must_use(cx, def_id, span) is_def_must_use(cx, def_id, span)
.map(|inner| MustUsePath::Opaque(Box::new(inner))) .map(|inner| MustUsePath::Opaque(Box::new(inner)))
} else { } else {

View File

@ -9,7 +9,7 @@ pub fn target() -> Target {
options: TargetOptions { options: TargetOptions {
code_model: Some(CodeModel::Medium), code_model: Some(CodeModel::Medium),
cpu: "generic-rv64".into(), cpu: "generic-rv64".into(),
features: "+m,+a,+f,+d,+c,+Zba,+Zbb,+Zbs".into(), features: "+m,+a,+f,+d,+c,+zba,+zbb,+zbs,+v".into(),
llvm_abiname: "lp64d".into(), llvm_abiname: "lp64d".into(),
supported_sanitizers: SanitizerSet::ADDRESS, supported_sanitizers: SanitizerSet::ADDRESS,
max_atomic_width: Some(64), max_atomic_width: Some(64),

View File

@ -136,12 +136,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
// `assemble_candidates_after_normalizing_self_ty`, and we'd // `assemble_candidates_after_normalizing_self_ty`, and we'd
// just be registering an identical candidate here. // just be registering an identical candidate here.
// //
// Returning `Err(NoSolution)` here is ok in `SolverMode::Coherence` // We always return `Err(NoSolution)` here in `SolverMode::Coherence`
// since we'll always be registering an ambiguous candidate in // since we'll always register an ambiguous candidate in
// `assemble_candidates_after_normalizing_self_ty` due to normalizing // `assemble_candidates_after_normalizing_self_ty` due to normalizing
// the TAIT. // the TAIT.
if let ty::Alias(ty::Opaque, opaque_ty) = goal.predicate.self_ty().kind() { if let ty::Alias(ty::Opaque, opaque_ty) = goal.predicate.self_ty().kind() {
if matches!(goal.param_env.reveal(), Reveal::All) if matches!(goal.param_env.reveal(), Reveal::All)
|| matches!(ecx.solver_mode(), SolverMode::Coherence)
|| opaque_ty || opaque_ty
.def_id .def_id
.as_local() .as_local()

View File

@ -492,7 +492,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// this trait and type. // this trait and type.
} }
ty::Param(..) ty::Param(..)
| ty::Alias(ty::Projection | ty::Inherent, ..) | ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ..)
| ty::Placeholder(..) | ty::Placeholder(..)
| ty::Bound(..) => { | ty::Bound(..) => {
// In these cases, we don't know what the actual // In these cases, we don't know what the actual
@ -536,9 +536,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
); );
} }
ty::Alias(_, _) ty::Alias(ty::Opaque, _) => {
if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(..))) => if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(..))) {
{
// We do not generate an auto impl candidate for `impl Trait`s which already // We do not generate an auto impl candidate for `impl Trait`s which already
// reference our auto trait. // reference our auto trait.
// //
@ -548,8 +547,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// //
// Note that this is only sound as projection candidates of opaque types // Note that this is only sound as projection candidates of opaque types
// are always applicable for auto traits. // are always applicable for auto traits.
} else if self.infcx.intercrate {
// We do not emit auto trait candidates for opaque types in coherence.
// Doing so can result in weird dependency cycles.
candidates.ambiguous = true;
} else {
candidates.vec.push(AutoImplCandidate)
}
} }
ty::Alias(_, _) => candidates.vec.push(AutoImplCandidate),
ty::Bool ty::Bool
| ty::Char | ty::Char

View File

@ -130,6 +130,8 @@ impl Layout {
} }
/// The minimum byte alignment for a memory block of this layout. /// The minimum byte alignment for a memory block of this layout.
///
/// The returned alignment is guaranteed to be a power of two.
#[stable(feature = "alloc_layout", since = "1.28.0")] #[stable(feature = "alloc_layout", since = "1.28.0")]
#[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")] #[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")]
#[must_use = "this returns the minimum alignment, \ #[must_use = "this returns the minimum alignment, \

View File

@ -359,6 +359,10 @@ impl Build {
// https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797 // https://github.com/rust-lang/rust/blob/a8a33cf27166d3eabaffc58ed3799e054af3b0c6/src/bootstrap/bootstrap.py#L796-L797
let is_sudo = match env::var_os("SUDO_USER") { let is_sudo = match env::var_os("SUDO_USER") {
Some(_sudo_user) => { Some(_sudo_user) => {
// SAFETY: getuid() system call is always successful and no return value is reserved
// to indicate an error.
//
// For more context, see https://man7.org/linux/man-pages/man2/geteuid.2.html
let uid = unsafe { libc::getuid() }; let uid = unsafe { libc::getuid() };
uid == 0 uid == 0
} }

View File

@ -45,3 +45,19 @@ The riscv64-linux-android target is supported as a Tier 3 target.
A list of all supported targets can be found A list of all supported targets can be found
[here](../platform-support.html) [here](../platform-support.html)
## Architecture Notes
### riscv64-linux-android
Currently the `riscv64-linux-android` target requires the following architecture features/extensions:
* `a` (atomics)
* `d` (double-precision floating-point)
* `c` (compressed instruction set)
* `f` (single-precision floating-point)
* `m` (multiplication and division)
* `v` (vector)
* `Zba` (address calculation instructions)
* `Zbb` (base instructions)
* `Zbs` (single-bit instructions)

View File

@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>` error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
--> $DIR/auto-trait.rs:21:1 --> $DIR/auto-trait-coherence.rs:24:1
| |
LL | impl<T: Send> AnotherTrait for T {} LL | impl<T: Send> AnotherTrait for T {}
| -------------------------------- first implementation here | -------------------------------- first implementation here

View File

@ -0,0 +1,12 @@
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
--> $DIR/auto-trait-coherence.rs:24:1
|
LL | impl<T: Send> AnotherTrait for T {}
| -------------------------------- first implementation here
...
LL | impl AnotherTrait for D<OpaqueType> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0119`.

View File

@ -1,3 +1,6 @@
// revisions: old next
//[next] compile-flags: -Ztrait-solver=next
// Tests that type alias impls traits do not leak auto-traits for // Tests that type alias impls traits do not leak auto-traits for
// the purposes of coherence checking // the purposes of coherence checking
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]