Skip to content

Commit 89e4e1f

Browse files
committed
Auto merge of #102139 - Dylan-DPC:rollup-ljlipt8, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #101598 (Update rustc's information on Android's sanitizers) - #102036 (Remove use of `io::ErrorKind::Other` in std) - #102037 (Make cycle errors recoverable) - #102069 (Skip `Equate` relation in `handle_opaque_type`) - #102076 (rustc_transmute: fix big-endian discriminants) - #102107 (Add missing space between notable trait tooltip and where clause) - #102119 (Fix a typo “pararmeter” in error message) - #102131 (Added which number is computed in compute_float.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8ab71ab + 33b7ff1 commit 89e4e1f

File tree

26 files changed

+126
-63
lines changed

26 files changed

+126
-63
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1090,11 +1090,12 @@ fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut d
10901090
// both executables and dynamic shared objects. Everywhere else the runtimes
10911091
// are currently distributed as static libraries which should be linked to
10921092
// executables only.
1093-
let needs_runtime = match crate_type {
1094-
CrateType::Executable => true,
1095-
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
1096-
CrateType::Rlib | CrateType::Staticlib => false,
1097-
};
1093+
let needs_runtime = !sess.target.is_like_android
1094+
&& match crate_type {
1095+
CrateType::Executable => true,
1096+
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
1097+
CrateType::Rlib | CrateType::Staticlib => false,
1098+
};
10981099

10991100
if !needs_runtime {
11001101
return;

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+26-11
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ pub trait ForestObligation: Clone + Debug {
9595
pub trait ObligationProcessor {
9696
type Obligation: ForestObligation;
9797
type Error: Debug;
98+
type OUT: OutcomeTrait<
99+
Obligation = Self::Obligation,
100+
Error = Error<Self::Obligation, Self::Error>,
101+
>;
98102

99103
fn needs_process_obligation(&self, obligation: &Self::Obligation) -> bool;
100104

@@ -111,7 +115,11 @@ pub trait ObligationProcessor {
111115
/// In other words, if we had O1 which required O2 which required
112116
/// O3 which required O1, we would give an iterator yielding O1,
113117
/// O2, O3 (O1 is not yielded twice).
114-
fn process_backedge<'c, I>(&mut self, cycle: I, _marker: PhantomData<&'c Self::Obligation>)
118+
fn process_backedge<'c, I>(
119+
&mut self,
120+
cycle: I,
121+
_marker: PhantomData<&'c Self::Obligation>,
122+
) -> Result<(), Self::Error>
115123
where
116124
I: Clone + Iterator<Item = &'c Self::Obligation>;
117125
}
@@ -402,12 +410,11 @@ impl<O: ForestObligation> ObligationForest<O> {
402410

403411
/// Performs a fixpoint computation over the obligation list.
404412
#[inline(never)]
405-
pub fn process_obligations<P, OUT>(&mut self, processor: &mut P) -> OUT
413+
pub fn process_obligations<P>(&mut self, processor: &mut P) -> P::OUT
406414
where
407415
P: ObligationProcessor<Obligation = O>,
408-
OUT: OutcomeTrait<Obligation = O, Error = Error<O, P::Error>>,
409416
{
410-
let mut outcome = OUT::new();
417+
let mut outcome = P::OUT::new();
411418

412419
// Fixpoint computation: we repeat until the inner loop stalls.
413420
loop {
@@ -473,7 +480,7 @@ impl<O: ForestObligation> ObligationForest<O> {
473480
}
474481

475482
self.mark_successes();
476-
self.process_cycles(processor);
483+
self.process_cycles(processor, &mut outcome);
477484
self.compress(|obl| outcome.record_completed(obl));
478485
}
479486

@@ -558,7 +565,7 @@ impl<O: ForestObligation> ObligationForest<O> {
558565

559566
/// Report cycles between all `Success` nodes, and convert all `Success`
560567
/// nodes to `Done`. This must be called after `mark_successes`.
561-
fn process_cycles<P>(&mut self, processor: &mut P)
568+
fn process_cycles<P>(&mut self, processor: &mut P, outcome: &mut P::OUT)
562569
where
563570
P: ObligationProcessor<Obligation = O>,
564571
{
@@ -568,16 +575,21 @@ impl<O: ForestObligation> ObligationForest<O> {
568575
// to handle the no-op cases immediately to avoid the cost of the
569576
// function call.
570577
if node.state.get() == NodeState::Success {
571-
self.find_cycles_from_node(&mut stack, processor, index);
578+
self.find_cycles_from_node(&mut stack, processor, index, outcome);
572579
}
573580
}
574581

575582
debug_assert!(stack.is_empty());
576583
self.reused_node_vec = stack;
577584
}
578585

579-
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
580-
where
586+
fn find_cycles_from_node<P>(
587+
&self,
588+
stack: &mut Vec<usize>,
589+
processor: &mut P,
590+
index: usize,
591+
outcome: &mut P::OUT,
592+
) where
581593
P: ObligationProcessor<Obligation = O>,
582594
{
583595
let node = &self.nodes[index];
@@ -586,17 +598,20 @@ impl<O: ForestObligation> ObligationForest<O> {
586598
None => {
587599
stack.push(index);
588600
for &dep_index in node.dependents.iter() {
589-
self.find_cycles_from_node(stack, processor, dep_index);
601+
self.find_cycles_from_node(stack, processor, dep_index, outcome);
590602
}
591603
stack.pop();
592604
node.state.set(NodeState::Done);
593605
}
594606
Some(rpos) => {
595607
// Cycle detected.
596-
processor.process_backedge(
608+
let result = processor.process_backedge(
597609
stack[rpos..].iter().map(|&i| &self.nodes[i].obligation),
598610
PhantomData,
599611
);
612+
if let Err(err) = result {
613+
outcome.record_error(Error { error: err, backtrace: self.error_at(index) });
614+
}
600615
}
601616
}
602617
}

compiler/rustc_data_structures/src/obligation_forest/tests.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ where
6464
{
6565
type Obligation = O;
6666
type Error = E;
67+
type OUT = TestOutcome<O, E>;
6768

6869
fn needs_process_obligation(&self, _obligation: &Self::Obligation) -> bool {
6970
true
@@ -76,10 +77,15 @@ where
7677
(self.process_obligation)(obligation)
7778
}
7879

79-
fn process_backedge<'c, I>(&mut self, _cycle: I, _marker: PhantomData<&'c Self::Obligation>)
80+
fn process_backedge<'c, I>(
81+
&mut self,
82+
_cycle: I,
83+
_marker: PhantomData<&'c Self::Obligation>,
84+
) -> Result<(), Self::Error>
8085
where
8186
I: Clone + Iterator<Item = &'c Self::Obligation>,
8287
{
88+
Ok(())
8389
}
8490
}
8591

compiler/rustc_infer/src/infer/opaque_types.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_data_structures::sync::Lrc;
77
use rustc_data_structures::vec_map::VecMap;
88
use rustc_hir as hir;
99
use rustc_middle::traits::ObligationCause;
10+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1011
use rustc_middle::ty::fold::BottomUpFolder;
1112
use rustc_middle::ty::GenericArgKind;
1213
use rustc_middle::ty::{
@@ -176,16 +177,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
176177
} else if let Some(res) = process(b, a) {
177178
res
178179
} else {
179-
// Rerun equality check, but this time error out due to
180-
// different types.
181-
match self.at(cause, param_env).define_opaque_types(false).eq(a, b) {
182-
Ok(_) => span_bug!(
183-
cause.span,
184-
"opaque types are never equal to anything but themselves: {:#?}",
185-
(a.kind(), b.kind())
186-
),
187-
Err(e) => Err(e),
188-
}
180+
let (a, b) = self.resolve_vars_if_possible((a, b));
181+
Err(TypeError::Sorts(ExpectedFound::new(true, a, b)))
189182
}
190183
}
191184

compiler/rustc_infer/src/traits/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ pub struct FulfillmentError<'tcx> {
113113

114114
#[derive(Clone)]
115115
pub enum FulfillmentErrorCode<'tcx> {
116+
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
117+
CodeCycle(Vec<Obligation<'tcx, ty::Predicate<'tcx>>>),
116118
CodeSelectionError(SelectionError<'tcx>),
117119
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
118120
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate

compiler/rustc_infer/src/traits/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
4747
write!(f, "CodeConstEquateError({:?}, {:?})", a, b)
4848
}
4949
super::CodeAmbiguity => write!(f, "Ambiguity"),
50+
super::CodeCycle(ref cycle) => write!(f, "Cycle({:?})", cycle),
5051
}
5152
}
5253
}

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
173173
span,
174174
span_label: match res {
175175
Res::Def(kind, def_id) if kind == DefKind::TyParam => {
176-
self.def_span(def_id).map(|span| (span, "found this type pararmeter"))
176+
self.def_span(def_id).map(|span| (span, "found this type parameter"))
177177
}
178178
_ => None,
179179
},

compiler/rustc_target/src/spec/android_base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use crate::spec::TargetOptions;
1+
use crate::spec::{SanitizerSet, TargetOptions};
22

33
pub fn opts() -> TargetOptions {
44
let mut base = super::linux_base::opts();
55
base.os = "android".into();
6+
base.is_like_android = true;
67
base.default_dwarf_version = 2;
78
base.has_thread_local = false;
9+
base.supported_sanitizers = SanitizerSet::ADDRESS;
810
// This is for backward compatibility, see https://github.com/rust-lang/rust/issues/49867
911
// for context. (At that time, there was no `-C force-unwind-tables`, so the only solution
1012
// was to always emit `uwtable`).

compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use crate::spec::{LinkerFlavor, StackProbeType, Target};
1+
use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target};
22

33
pub fn target() -> Target {
44
let mut base = super::linux_gnu_base::opts();
55
base.cpu = "pentium4".into();
66
base.max_atomic_width = Some(64);
7+
base.supported_sanitizers = SanitizerSet::ADDRESS;
78
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m32"]);
89
// don't use probe-stack=inline-asm until rust#83139 and rust#84667 are resolved
910
base.stack_probes = StackProbeType::Call;

compiler/rustc_target/src/spec/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,8 @@ pub struct TargetOptions {
13811381
pub is_like_msvc: bool,
13821382
/// Whether a target toolchain is like WASM.
13831383
pub is_like_wasm: bool,
1384+
/// Whether a target toolchain is like Android, implying a Linux kernel and a Bionic libc
1385+
pub is_like_android: bool,
13841386
/// Default supported version of DWARF on this platform.
13851387
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
13861388
pub default_dwarf_version: u32,
@@ -1673,6 +1675,7 @@ impl Default for TargetOptions {
16731675
is_like_windows: false,
16741676
is_like_msvc: false,
16751677
is_like_wasm: false,
1678+
is_like_android: false,
16761679
default_dwarf_version: 4,
16771680
allows_weak_linkage: true,
16781681
has_rpath: false,
@@ -2320,6 +2323,7 @@ impl Target {
23202323
key!(is_like_windows, bool);
23212324
key!(is_like_msvc, bool);
23222325
key!(is_like_wasm, bool);
2326+
key!(is_like_android, bool);
23232327
key!(default_dwarf_version, u32);
23242328
key!(allows_weak_linkage, bool);
23252329
key!(has_rpath, bool);
@@ -2570,6 +2574,7 @@ impl ToJson for Target {
25702574
target_option_val!(is_like_windows);
25712575
target_option_val!(is_like_msvc);
25722576
target_option_val!(is_like_wasm);
2577+
target_option_val!(is_like_android);
25732578
target_option_val!(default_dwarf_version);
25742579
target_option_val!(allows_weak_linkage);
25752580
target_option_val!(has_rpath);

compiler/rustc_trait_selection/src/traits/codegen.rs

+10
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
// general routines.
55

66
use crate::infer::{DefiningAnchor, TyCtxtInferExt};
7+
use crate::traits::error_reporting::InferCtxtExt;
78
use crate::traits::{
89
ImplSource, Obligation, ObligationCause, SelectionContext, TraitEngine, TraitEngineExt,
910
Unimplemented,
1011
};
12+
use rustc_infer::traits::FulfillmentErrorCode;
1113
use rustc_middle::traits::CodegenObligationError;
1214
use rustc_middle::ty::{self, TyCtxt};
1315

@@ -62,6 +64,14 @@ pub fn codegen_select_candidate<'tcx>(
6264
// optimization to stop iterating early.
6365
let errors = fulfill_cx.select_all_or_error(&infcx);
6466
if !errors.is_empty() {
67+
// `rustc_monomorphize::collector` assumes there are no type errors.
68+
// Cycle errors are the only post-monomorphization errors possible; emit them now so
69+
// `rustc_ty_utils::resolve_associated_item` doesn't return `None` post-monomorphization.
70+
for err in errors {
71+
if let FulfillmentErrorCode::CodeCycle(cycle) = err.code {
72+
infcx.report_overflow_error_cycle(&cycle);
73+
}
74+
}
6575
return Err(CodegenObligationError::FulfillmentError);
6676
}
6777

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
15401540
}
15411541
diag.emit();
15421542
}
1543+
FulfillmentErrorCode::CodeCycle(ref cycle) => {
1544+
self.report_overflow_error_cycle(cycle);
1545+
}
15431546
}
15441547
}
15451548

compiler/rustc_trait_selection/src/traits/fulfill.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ use super::Unimplemented;
2525
use super::{FulfillmentError, FulfillmentErrorCode};
2626
use super::{ObligationCause, PredicateObligation};
2727

28-
use crate::traits::error_reporting::InferCtxtExt as _;
2928
use crate::traits::project::PolyProjectionObligation;
3029
use crate::traits::project::ProjectionCacheKeyExt as _;
31-
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
30+
use crate::traits::query::evaluate_obligation::InferCtxtExt;
3231

3332
impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
3433
/// Note that we include both the `ParamEnv` and the `Predicate`,
@@ -224,6 +223,7 @@ fn mk_pending(os: Vec<PredicateObligation<'_>>) -> Vec<PendingPredicateObligatio
224223
impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
225224
type Obligation = PendingPredicateObligation<'tcx>;
226225
type Error = FulfillmentErrorCode<'tcx>;
226+
type OUT = Outcome<Self::Obligation, Self::Error>;
227227

228228
/// Identifies whether a predicate obligation needs processing.
229229
///
@@ -594,14 +594,16 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
594594
&mut self,
595595
cycle: I,
596596
_marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
597-
) where
597+
) -> Result<(), FulfillmentErrorCode<'tcx>>
598+
where
598599
I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
599600
{
600601
if self.selcx.coinductive_match(cycle.clone().map(|s| s.obligation.predicate)) {
601602
debug!("process_child_obligations: coinductive match");
603+
Ok(())
602604
} else {
603605
let cycle: Vec<_> = cycle.map(|c| c.obligation.clone()).collect();
604-
self.selcx.infcx().report_overflow_error_cycle(&cycle);
606+
Err(FulfillmentErrorCode::CodeCycle(cycle))
605607
}
606608
}
607609
}

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

+2-14
Original file line numberDiff line numberDiff line change
@@ -226,27 +226,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
226226
}
227227

228228
pub fn intercrate(infcx: &'cx InferCtxt<'cx, 'tcx>) -> SelectionContext<'cx, 'tcx> {
229-
SelectionContext {
230-
infcx,
231-
freshener: infcx.freshener_keep_static(),
232-
intercrate: true,
233-
intercrate_ambiguity_causes: None,
234-
query_mode: TraitQueryMode::Standard,
235-
}
229+
SelectionContext { intercrate: true, ..SelectionContext::new(infcx) }
236230
}
237231

238232
pub fn with_query_mode(
239233
infcx: &'cx InferCtxt<'cx, 'tcx>,
240234
query_mode: TraitQueryMode,
241235
) -> SelectionContext<'cx, 'tcx> {
242236
debug!(?query_mode, "with_query_mode");
243-
SelectionContext {
244-
infcx,
245-
freshener: infcx.freshener_keep_static(),
246-
intercrate: false,
247-
intercrate_ambiguity_causes: None,
248-
query_mode,
249-
}
237+
SelectionContext { query_mode, ..SelectionContext::new(infcx) }
250238
}
251239

252240
/// Enables tracking of intercrate ambiguity causes. See

0 commit comments

Comments
 (0)