Skip to content

Commit 495c5dd

Browse files
committed
Auto merge of rust-lang#116728 - matthiaskrgr:rollup-4xzcsnv, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#115653 (Guarantee that Layout::align returns a non-zero power of two) - rust-lang#116577 (add `SAFETY` block on the usage of unsafe `getuid`) - rust-lang#116618 (Add the V (vector) extension to the riscv64-linux-android target spec) - rust-lang#116679 (Remove some unnecessary `unwrap`s) - rust-lang#116689 (explicitly handle auto trait leakage in coherence) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 96c4dba + 45bcef3 commit 495c5dd

File tree

12 files changed

+77
-27
lines changed

12 files changed

+77
-27
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
604604
return false;
605605
}
606606
let box_found = Ty::new_box(self.tcx, found);
607-
let pin_box_found = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin).unwrap();
608-
let pin_found = Ty::new_lang_item(self.tcx, found, LangItem::Pin).unwrap();
607+
let Some(pin_box_found) = Ty::new_lang_item(self.tcx, box_found, LangItem::Pin) else {
608+
return false;
609+
};
610+
let Some(pin_found) = Ty::new_lang_item(self.tcx, found, LangItem::Pin) else {
611+
return false;
612+
};
609613
match expected.kind() {
610614
ty::Adt(def, _) if Some(def.did()) == pin_did => {
611615
if self.can_coerce(pin_box_found, expected) {

compiler/rustc_hir_typeck/src/method/suggest.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16161616
continue;
16171617
}
16181618

1619-
let range_def_id = self.tcx.require_lang_item(lang_item.unwrap(), None);
1619+
let Some(range_def_id) =
1620+
lang_item.and_then(|lang_item| self.tcx.lang_items().get(lang_item))
1621+
else {
1622+
continue;
1623+
};
16201624
let range_ty =
16211625
self.tcx.type_of(range_def_id).instantiate(self.tcx, &[actual.into()]);
16221626

@@ -2539,11 +2543,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25392543
Err(_) => (),
25402544
}
25412545

2542-
let pred = ty::TraitRef::new(
2543-
self.tcx,
2544-
self.tcx.lang_items().unpin_trait().unwrap(),
2545-
[*rcvr_ty],
2546-
);
2546+
let Some(unpin_trait) = self.tcx.lang_items().unpin_trait() else {
2547+
return;
2548+
};
2549+
let pred = ty::TraitRef::new(self.tcx, unpin_trait, [*rcvr_ty]);
25472550
let unpin = self.predicate_must_hold_considering_regions(&Obligation::new(
25482551
self.tcx,
25492552
ObligationCause::misc(rcvr.span, self.body_id),

compiler/rustc_lint/src/unused.rs

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

compiler/rustc_target/src/spec/riscv64_linux_android.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn target() -> Target {
99
options: TargetOptions {
1010
code_model: Some(CodeModel::Medium),
1111
cpu: "generic-rv64".into(),
12-
features: "+m,+a,+f,+d,+c,+Zba,+Zbb,+Zbs".into(),
12+
features: "+m,+a,+f,+d,+c,+zba,+zbb,+zbs,+v".into(),
1313
llvm_abiname: "lp64d".into(),
1414
supported_sanitizers: SanitizerSet::ADDRESS,
1515
max_atomic_width: Some(64),

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
136136
// `assemble_candidates_after_normalizing_self_ty`, and we'd
137137
// just be registering an identical candidate here.
138138
//
139-
// Returning `Err(NoSolution)` here is ok in `SolverMode::Coherence`
140-
// since we'll always be registering an ambiguous candidate in
139+
// We always return `Err(NoSolution)` here in `SolverMode::Coherence`
140+
// since we'll always register an ambiguous candidate in
141141
// `assemble_candidates_after_normalizing_self_ty` due to normalizing
142142
// the TAIT.
143143
if let ty::Alias(ty::Opaque, opaque_ty) = goal.predicate.self_ty().kind() {
144144
if matches!(goal.param_env.reveal(), Reveal::All)
145+
|| matches!(ecx.solver_mode(), SolverMode::Coherence)
145146
|| opaque_ty
146147
.def_id
147148
.as_local()

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
492492
// this trait and type.
493493
}
494494
ty::Param(..)
495-
| ty::Alias(ty::Projection | ty::Inherent, ..)
495+
| ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ..)
496496
| ty::Placeholder(..)
497497
| ty::Bound(..) => {
498498
// In these cases, we don't know what the actual
@@ -536,20 +536,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
536536
);
537537
}
538538

539-
ty::Alias(_, _)
540-
if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(..))) =>
541-
{
542-
// We do not generate an auto impl candidate for `impl Trait`s which already
543-
// reference our auto trait.
544-
//
545-
// For example during candidate assembly for `impl Send: Send`, we don't have
546-
// to look at the constituent types for this opaque types to figure out that this
547-
// trivially holds.
548-
//
549-
// Note that this is only sound as projection candidates of opaque types
550-
// are always applicable for auto traits.
539+
ty::Alias(ty::Opaque, _) => {
540+
if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate(..))) {
541+
// We do not generate an auto impl candidate for `impl Trait`s which already
542+
// reference our auto trait.
543+
//
544+
// For example during candidate assembly for `impl Send: Send`, we don't have
545+
// to look at the constituent types for this opaque types to figure out that this
546+
// trivially holds.
547+
//
548+
// Note that this is only sound as projection candidates of opaque types
549+
// are always applicable for auto traits.
550+
} else if self.infcx.intercrate {
551+
// We do not emit auto trait candidates for opaque types in coherence.
552+
// Doing so can result in weird dependency cycles.
553+
candidates.ambiguous = true;
554+
} else {
555+
candidates.vec.push(AutoImplCandidate)
556+
}
551557
}
552-
ty::Alias(_, _) => candidates.vec.push(AutoImplCandidate),
553558

554559
ty::Bool
555560
| ty::Char

library/core/src/alloc/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ impl Layout {
130130
}
131131

132132
/// The minimum byte alignment for a memory block of this layout.
133+
///
134+
/// The returned alignment is guaranteed to be a power of two.
133135
#[stable(feature = "alloc_layout", since = "1.28.0")]
134136
#[rustc_const_stable(feature = "const_alloc_layout_size_align", since = "1.50.0")]
135137
#[must_use = "this returns the minimum alignment, \

src/bootstrap/lib.rs

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

src/doc/rustc/src/platform-support/android.md

+16
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,19 @@ The riscv64-linux-android target is supported as a Tier 3 target.
4545

4646
A list of all supported targets can be found
4747
[here](../platform-support.html)
48+
49+
## Architecture Notes
50+
51+
### riscv64-linux-android
52+
53+
Currently the `riscv64-linux-android` target requires the following architecture features/extensions:
54+
55+
* `a` (atomics)
56+
* `d` (double-precision floating-point)
57+
* `c` (compressed instruction set)
58+
* `f` (single-precision floating-point)
59+
* `m` (multiplication and division)
60+
* `v` (vector)
61+
* `Zba` (address calculation instructions)
62+
* `Zbb` (base instructions)
63+
* `Zbs` (single-bit instructions)

tests/ui/impl-trait/auto-trait.stderr renamed to tests/ui/impl-trait/auto-trait-coherence.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
2-
--> $DIR/auto-trait.rs:21:1
2+
--> $DIR/auto-trait-coherence.rs:24:1
33
|
44
LL | impl<T: Send> AnotherTrait for T {}
55
| -------------------------------- first implementation here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<OpaqueType>`
2+
--> $DIR/auto-trait-coherence.rs:24:1
3+
|
4+
LL | impl<T: Send> AnotherTrait for T {}
5+
| -------------------------------- first implementation here
6+
...
7+
LL | impl AnotherTrait for D<OpaqueType> {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `D<OpaqueType>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.

tests/ui/impl-trait/auto-trait.rs renamed to tests/ui/impl-trait/auto-trait-coherence.rs

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

0 commit comments

Comments
 (0)