Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 72fdf91

Browse files
committed
Auto merge of rust-lang#126038 - matthiaskrgr:rollup-h4rm3x2, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#124840 (resolve: mark it undetermined if single import is not has any bindings) - rust-lang#125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply) - rust-lang#125648 (Remove unused(?) `~/rustsrc` folder from docker script) - rust-lang#125672 (Add more ABI test cases to miri (RFC 3391)) - rust-lang#125800 (Fix `mut` static task queue in SGX target) - rust-lang#125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters) - rust-lang#125893 (Handle all GVN binops in a single place.) - rust-lang#126008 (Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps) - rust-lang#126032 (Update description of the `IsTerminal` example) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7ebd2bd + fa58891 commit 72fdf91

File tree

37 files changed

+455
-190
lines changed

37 files changed

+455
-190
lines changed

‎compiler/rustc_const_eval/src/interpret/terminator.rs‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,30 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
294294

295295
/// Unwrap types that are guaranteed a null-pointer-optimization
296296
fn unfold_npo(&self, layout: TyAndLayout<'tcx>) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
297-
// Check if this is `Option` wrapping some type.
298-
let inner = match layout.ty.kind() {
299-
ty::Adt(def, args) if self.tcx.is_diagnostic_item(sym::Option, def.did()) => {
300-
args[0].as_type().unwrap()
301-
}
302-
_ => {
303-
// Not an `Option`.
304-
return Ok(layout);
297+
// Check if this is `Option` wrapping some type or if this is `Result` wrapping a 1-ZST and
298+
// another type.
299+
let ty::Adt(def, args) = layout.ty.kind() else {
300+
// Not an ADT, so definitely no NPO.
301+
return Ok(layout);
302+
};
303+
let inner = if self.tcx.is_diagnostic_item(sym::Option, def.did()) {
304+
// The wrapped type is the only arg.
305+
self.layout_of(args[0].as_type().unwrap())?
306+
} else if self.tcx.is_diagnostic_item(sym::Result, def.did()) {
307+
// We want to extract which (if any) of the args is not a 1-ZST.
308+
let lhs = self.layout_of(args[0].as_type().unwrap())?;
309+
let rhs = self.layout_of(args[1].as_type().unwrap())?;
310+
if lhs.is_1zst() {
311+
rhs
312+
} else if rhs.is_1zst() {
313+
lhs
314+
} else {
315+
return Ok(layout); // no NPO
305316
}
317+
} else {
318+
return Ok(layout); // no NPO
306319
};
307-
let inner = self.layout_of(inner)?;
320+
308321
// Check if the inner type is one of the NPO-guaranteed ones.
309322
// For that we first unpeel transparent *structs* (but not unions).
310323
let is_npo = |def: AdtDef<'tcx>| {

‎compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10661066
ty::ImplContainer => {
10671067
if segments.len() == 1 {
10681068
// `<T>::assoc` will end up here, and so
1069-
// can `T::assoc`. It this came from an
1069+
// can `T::assoc`. If this came from an
10701070
// inherent impl, we need to record the
10711071
// `T` for posterity (see `UserSelfTy` for
10721072
// details).
@@ -1416,11 +1416,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14161416
) {
14171417
Ok(ok) => self.register_infer_ok_obligations(ok),
14181418
Err(_) => {
1419-
self.dcx().span_delayed_bug(
1419+
self.dcx().span_bug(
14201420
span,
14211421
format!(
1422-
"instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
1423-
),
1422+
"instantiate_value_path: (UFCS) {self_ty:?} was a subtype of {impl_ty:?} but now is not?",
1423+
),
14241424
);
14251425
}
14261426
}

‎compiler/rustc_hir_typeck/src/method/probe.rs‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_trait_selection::traits::query::method_autoderef::{
4141
use rustc_trait_selection::traits::query::CanonicalTyGoal;
4242
use rustc_trait_selection::traits::ObligationCtxt;
4343
use rustc_trait_selection::traits::{self, ObligationCause};
44+
use std::cell::Cell;
4445
use std::cell::RefCell;
4546
use std::cmp::max;
4647
use std::iter;
@@ -76,8 +77,12 @@ pub(crate) struct ProbeContext<'a, 'tcx> {
7677
/// requested name (by edit distance)
7778
allow_similar_names: bool,
7879

80+
/// List of potential private candidates. Will be trimmed to ones that
81+
/// actually apply and then the result inserted into `private_candidate`
82+
private_candidates: Vec<Candidate<'tcx>>,
83+
7984
/// Some(candidate) if there is a private candidate
80-
private_candidate: Option<(DefKind, DefId)>,
85+
private_candidate: Cell<Option<(DefKind, DefId)>>,
8186

8287
/// Collects near misses when the candidate functions are missing a `self` keyword and is only
8388
/// used for error reporting
@@ -581,7 +586,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
581586
orig_steps_var_values,
582587
steps,
583588
allow_similar_names: false,
584-
private_candidate: None,
589+
private_candidates: Vec::new(),
590+
private_candidate: Cell::new(None),
585591
static_candidates: RefCell::new(Vec::new()),
586592
unsatisfied_predicates: RefCell::new(Vec::new()),
587593
scope_expr_id,
@@ -593,7 +599,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
593599
self.inherent_candidates.clear();
594600
self.extension_candidates.clear();
595601
self.impl_dups.clear();
596-
self.private_candidate = None;
602+
self.private_candidates.clear();
603+
self.private_candidate.set(None);
597604
self.static_candidates.borrow_mut().clear();
598605
self.unsatisfied_predicates.borrow_mut().clear();
599606
}
@@ -617,9 +624,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
617624
} else {
618625
self.extension_candidates.push(candidate);
619626
}
620-
} else if self.private_candidate.is_none() {
621-
self.private_candidate =
622-
Some((candidate.item.kind.as_def_kind(), candidate.item.def_id));
627+
} else {
628+
self.private_candidates.push(candidate);
623629
}
624630
}
625631

@@ -1171,7 +1177,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11711177
let mut possibly_unsatisfied_predicates = Vec::new();
11721178

11731179
for (kind, candidates) in
1174-
&[("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1180+
[("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
11751181
{
11761182
debug!("searching {} candidates", kind);
11771183
let res = self.consider_candidates(
@@ -1185,6 +1191,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11851191
}
11861192
}
11871193

1194+
if self.private_candidate.get().is_none() {
1195+
if let Some(Ok(pick)) =
1196+
self.consider_candidates(self_ty, &self.private_candidates, &mut vec![], None)
1197+
{
1198+
self.private_candidate.set(Some((pick.item.kind.as_def_kind(), pick.item.def_id)));
1199+
}
1200+
}
1201+
11881202
// `pick_method` may be called twice for the same self_ty if no stable methods
11891203
// match. Only extend once.
11901204
if unstable_candidates.is_some() {

‎compiler/rustc_mir_transform/src/gvn.rs‎

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ enum Value<'tcx> {
223223
NullaryOp(NullOp<'tcx>, Ty<'tcx>),
224224
UnaryOp(UnOp, VnIndex),
225225
BinaryOp(BinOp, VnIndex, VnIndex),
226-
CheckedBinaryOp(BinOp, VnIndex, VnIndex), // FIXME get rid of this, work like MIR instead
227226
Cast {
228227
kind: CastKind,
229228
value: VnIndex,
@@ -508,17 +507,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
508507
let val = self.ecx.binary_op(bin_op, &lhs, &rhs).ok()?;
509508
val.into()
510509
}
511-
CheckedBinaryOp(bin_op, lhs, rhs) => {
512-
let lhs = self.evaluated[lhs].as_ref()?;
513-
let lhs = self.ecx.read_immediate(lhs).ok()?;
514-
let rhs = self.evaluated[rhs].as_ref()?;
515-
let rhs = self.ecx.read_immediate(rhs).ok()?;
516-
let val = self
517-
.ecx
518-
.binary_op(bin_op.wrapping_to_overflowing().unwrap(), &lhs, &rhs)
519-
.ok()?;
520-
val.into()
521-
}
522510
Cast { kind, value, from: _, to } => match kind {
523511
CastKind::IntToInt | CastKind::IntToFloat => {
524512
let value = self.evaluated[value].as_ref()?;
@@ -829,17 +817,10 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
829817
let lhs = lhs?;
830818
let rhs = rhs?;
831819

832-
if let Some(op) = op.overflowing_to_wrapping() {
833-
if let Some(value) = self.simplify_binary(op, true, ty, lhs, rhs) {
834-
return Some(value);
835-
}
836-
Value::CheckedBinaryOp(op, lhs, rhs)
837-
} else {
838-
if let Some(value) = self.simplify_binary(op, false, ty, lhs, rhs) {
839-
return Some(value);
840-
}
841-
Value::BinaryOp(op, lhs, rhs)
820+
if let Some(value) = self.simplify_binary(op, ty, lhs, rhs) {
821+
return Some(value);
842822
}
823+
Value::BinaryOp(op, lhs, rhs)
843824
}
844825
Rvalue::UnaryOp(op, ref mut arg) => {
845826
let arg = self.simplify_operand(arg, location)?;
@@ -970,7 +951,6 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
970951
fn simplify_binary(
971952
&mut self,
972953
op: BinOp,
973-
checked: bool,
974954
lhs_ty: Ty<'tcx>,
975955
lhs: VnIndex,
976956
rhs: VnIndex,
@@ -999,22 +979,39 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
999979
use Either::{Left, Right};
1000980
let a = as_bits(lhs).map_or(Right(lhs), Left);
1001981
let b = as_bits(rhs).map_or(Right(rhs), Left);
982+
1002983
let result = match (op, a, b) {
1003984
// Neutral elements.
1004-
(BinOp::Add | BinOp::BitOr | BinOp::BitXor, Left(0), Right(p))
985+
(
986+
BinOp::Add
987+
| BinOp::AddWithOverflow
988+
| BinOp::AddUnchecked
989+
| BinOp::BitOr
990+
| BinOp::BitXor,
991+
Left(0),
992+
Right(p),
993+
)
1005994
| (
1006995
BinOp::Add
996+
| BinOp::AddWithOverflow
997+
| BinOp::AddUnchecked
1007998
| BinOp::BitOr
1008999
| BinOp::BitXor
10091000
| BinOp::Sub
1001+
| BinOp::SubWithOverflow
1002+
| BinOp::SubUnchecked
10101003
| BinOp::Offset
10111004
| BinOp::Shl
10121005
| BinOp::Shr,
10131006
Right(p),
10141007
Left(0),
10151008
)
1016-
| (BinOp::Mul, Left(1), Right(p))
1017-
| (BinOp::Mul | BinOp::Div, Right(p), Left(1)) => p,
1009+
| (BinOp::Mul | BinOp::MulWithOverflow | BinOp::MulUnchecked, Left(1), Right(p))
1010+
| (
1011+
BinOp::Mul | BinOp::MulWithOverflow | BinOp::MulUnchecked | BinOp::Div,
1012+
Right(p),
1013+
Left(1),
1014+
) => p,
10181015
// Attempt to simplify `x & ALL_ONES` to `x`, with `ALL_ONES` depending on type size.
10191016
(BinOp::BitAnd, Right(p), Left(ones)) | (BinOp::BitAnd, Left(ones), Right(p))
10201017
if ones == layout.size.truncate(u128::MAX)
@@ -1023,10 +1020,21 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10231020
p
10241021
}
10251022
// Absorbing elements.
1026-
(BinOp::Mul | BinOp::BitAnd, _, Left(0))
1023+
(
1024+
BinOp::Mul | BinOp::MulWithOverflow | BinOp::MulUnchecked | BinOp::BitAnd,
1025+
_,
1026+
Left(0),
1027+
)
10271028
| (BinOp::Rem, _, Left(1))
10281029
| (
1029-
BinOp::Mul | BinOp::Div | BinOp::Rem | BinOp::BitAnd | BinOp::Shl | BinOp::Shr,
1030+
BinOp::Mul
1031+
| BinOp::MulWithOverflow
1032+
| BinOp::MulUnchecked
1033+
| BinOp::Div
1034+
| BinOp::Rem
1035+
| BinOp::BitAnd
1036+
| BinOp::Shl
1037+
| BinOp::Shr,
10301038
Left(0),
10311039
_,
10321040
) => self.insert_scalar(Scalar::from_uint(0u128, layout.size), lhs_ty),
@@ -1038,7 +1046,9 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10381046
self.insert_scalar(Scalar::from_uint(ones, layout.size), lhs_ty)
10391047
}
10401048
// Sub/Xor with itself.
1041-
(BinOp::Sub | BinOp::BitXor, a, b) if a == b => {
1049+
(BinOp::Sub | BinOp::SubWithOverflow | BinOp::SubUnchecked | BinOp::BitXor, a, b)
1050+
if a == b =>
1051+
{
10421052
self.insert_scalar(Scalar::from_uint(0u128, layout.size), lhs_ty)
10431053
}
10441054
// Comparison:
@@ -1052,7 +1062,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
10521062
_ => return None,
10531063
};
10541064

1055-
if checked {
1065+
if op.is_overflowing() {
10561066
let false_val = self.insert_bool(false);
10571067
Some(self.insert_tuple(vec![result, false_val]))
10581068
} else {

‎compiler/rustc_resolve/src/ident.rs‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
965965
// if it can then our result is not determined and can be invalidated.
966966
for single_import in &resolution.single_imports {
967967
let Some(import_vis) = single_import.vis.get() else {
968+
// This branch handles a cycle in single imports, which occurs
969+
// when we've previously captured the `vis` value during an import
970+
// process.
971+
//
972+
// For example:
973+
// ```
974+
// use a::b;
975+
// use b as a;
976+
// ```
977+
// 1. Steal the `vis` in `use a::b` and attempt to locate `a` in the
978+
// current module.
979+
// 2. Encounter the import `use b as a`, which is a `single_import` for `a`,
980+
// and try to find `b` in the current module.
981+
// 3. Re-encounter the `use a::b` import since it's a `single_import` of `b`.
982+
// This leads to entering this branch.
968983
continue;
969984
};
970985
if !self.is_accessible_from(import_vis, parent_scope.module) {
@@ -979,15 +994,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
979994
// named imports.
980995
continue;
981996
}
997+
982998
let Some(module) = single_import.imported_module.get() else {
983999
return Err((Undetermined, Weak::No));
9841000
};
985-
let ImportKind::Single { source: ident, .. } = single_import.kind else {
1001+
let ImportKind::Single { source: ident, source_bindings, .. } = &single_import.kind
1002+
else {
9861003
unreachable!();
9871004
};
1005+
if binding.map_or(false, |binding| binding.module().is_some())
1006+
&& source_bindings.iter().all(|binding| matches!(binding.get(), Err(Undetermined)))
1007+
{
1008+
// This branch allows the binding to be defined or updated later,
1009+
// avoiding module inconsistency between the resolve process and the finalize process.
1010+
// See more details in #124840
1011+
return Err((Undetermined, Weak::No));
1012+
}
9881013
match self.resolve_ident_in_module(
9891014
module,
990-
ident,
1015+
*ident,
9911016
ns,
9921017
&single_import.parent_scope,
9931018
None,

‎compiler/rustc_resolve/src/imports.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
352352
(old_glob @ true, false) | (old_glob @ false, true) => {
353353
let (glob_binding, nonglob_binding) =
354354
if old_glob { (old_binding, binding) } else { (binding, old_binding) };
355-
if glob_binding.res() != nonglob_binding.res()
356-
&& key.ns == MacroNS
355+
if key.ns == MacroNS
357356
&& nonglob_binding.expansion != LocalExpnId::ROOT
357+
&& glob_binding.res() != nonglob_binding.res()
358358
{
359359
resolution.binding = Some(this.ambiguity(
360360
AmbiguityKind::GlobVsExpanded,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /