Skip to content

Commit cef633d

Browse files
committed
Auto merge of #107187 - matthiaskrgr:rollup-lvwzlg2, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #107102 (Implement some more predicates in the new solver) - #107111 (Fix missing arguments issues and copy-paste bug for fluent) - #107114 (Add note about absolute paths to Path::join) - #107127 (Enable sanitizers for s390x-linux) - #107152 (Migrate scraped-examples top and bottom "borders" to CSS variables) - #107170 (Add myself to .mailmap) - #107174 (rustdoc: Use `DefId(Map,Set)` instead of `FxHash(Map,Set)`) - #107180 (Remove unnecessary `&format!`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8e68090 + 2f7a3a1 commit cef633d

File tree

41 files changed

+484
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+484
-164
lines changed

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Adrien Tétar <adri-from-59@hotmail.fr>
1515
Ahmed Charles <ahmedcharles@gmail.com> <acharles@outlook.com>
1616
Alan Egerton <eggyal@gmail.com>
1717
Alan Stoate <alan.stoate@gmail.com>
18+
Albert Larsan <albert.larsan@gmail.com> Albert Larsan <74931857+albertlarsan68@users.noreply.github.com>
1819
Alessandro Decina <alessandro.d@gmail.com>
1920
Alex Burka <durka42+github@gmail.com> Alex Burka <aburka@seas.upenn.edu>
2021
Alex Hansen <ahansen2@trinity.edu>

compiler/rustc_error_messages/locales/en-US/infer.ftl

+13-13
Original file line numberDiff line numberDiff line change
@@ -268,28 +268,28 @@ infer_but_calling_introduces = {$has_param_name ->
268268
[true] `{$param_name}`
269269
*[false] `fn` parameter
270270
} has {$lifetime_kind ->
271-
[named] lifetime `{$lifetime}`
272-
*[anon] an anonymous lifetime `'_`
273-
} but calling `{assoc_item}` introduces an implicit `'static` lifetime requirement
271+
[true] lifetime `{$lifetime}`
272+
*[false] an anonymous lifetime `'_`
273+
} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement
274274
.label1 = {$has_lifetime ->
275-
[named] lifetime `{$lifetime}`
276-
*[anon] an anonymous lifetime `'_`
275+
[true] lifetime `{$lifetime}`
276+
*[false] an anonymous lifetime `'_`
277277
}
278278
.label2 = ...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
279-
[named] `impl` of `{$impl_path}`
280-
*[anon] inherent `impl`
279+
[true] `impl` of `{$impl_path}`
280+
*[false] inherent `impl`
281281
}
282282
283283
infer_but_needs_to_satisfy = {$has_param_name ->
284284
[true] `{$param_name}`
285285
*[false] `fn` parameter
286286
} has {$has_lifetime ->
287-
[named] lifetime `{$lifetime}`
288-
*[anon] an anonymous lifetime `'_`
287+
[true] lifetime `{$lifetime}`
288+
*[false] an anonymous lifetime `'_`
289289
} but it needs to satisfy a `'static` lifetime requirement
290290
.influencer = this data with {$has_lifetime ->
291-
[named] lifetime `{$lifetime}`
292-
*[anon] an anonymous lifetime `'_`
291+
[true] lifetime `{$lifetime}`
292+
*[false] an anonymous lifetime `'_`
293293
}...
294294
.require = {$spans_empty ->
295295
*[true] ...is used and required to live as long as `'static` here
@@ -302,8 +302,8 @@ infer_more_targeted = {$has_param_name ->
302302
[true] `{$param_name}`
303303
*[false] `fn` parameter
304304
} has {$has_lifetime ->
305-
[named] lifetime `{$lifetime}`
306-
*[anon] an anonymous lifetime `'_`
305+
[true] lifetime `{$lifetime}`
306+
*[false] an anonymous lifetime `'_`
307307
} but calling `{$ident}` introduces an implicit `'static` lifetime requirement
308308
309309
infer_ril_introduced_here = `'static` requirement introduced here

compiler/rustc_infer/src/errors/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,8 @@ pub struct ButNeedsToSatisfy {
927927
#[subdiagnostic]
928928
pub req_introduces_loc: Option<ReqIntroducedLocations>,
929929

930+
pub has_param_name: bool,
931+
pub param_name: String,
930932
pub spans_empty: bool,
931933
pub has_lifetime: bool,
932934
pub lifetime: String,

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9898
let sp = var_origin.span();
9999
let return_sp = sub_origin.span();
100100
let param = self.find_param_with_region(*sup_r, *sub_r)?;
101+
let simple_ident = param.param.pat.simple_ident();
101102
let lifetime_name = if sup_r.has_name() { sup_r.to_string() } else { "'_".to_owned() };
102103

103104
let (mention_influencer, influencer_point) =
@@ -187,7 +188,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
187188
req_introduces_loc: subdiag,
188189

189190
has_lifetime: sup_r.has_name(),
190-
lifetime: sup_r.to_string(),
191+
lifetime: lifetime_name.clone(),
192+
has_param_name: simple_ident.is_some(),
193+
param_name: simple_ident.map(|x| x.to_string()).unwrap_or_default(),
191194
spans_empty,
192195
bound,
193196
};

compiler/rustc_target/src/spec/s390x_unknown_linux_gnu.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::Endian;
2-
use crate::spec::{StackProbeType, Target};
2+
use crate::spec::{SanitizerSet, StackProbeType, Target};
33

44
pub fn target() -> Target {
55
let mut base = super::linux_gnu_base::opts();
@@ -13,6 +13,8 @@ pub fn target() -> Target {
1313
base.max_atomic_width = Some(64);
1414
base.min_global_align = Some(16);
1515
base.stack_probes = StackProbeType::Inline;
16+
base.supported_sanitizers =
17+
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
1618

1719
Target {
1820
llvm_target: "s390x-unknown-linux-gnu".into(),

compiler/rustc_target/src/spec/s390x_unknown_linux_musl.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::Endian;
2-
use crate::spec::{StackProbeType, Target};
2+
use crate::spec::{SanitizerSet, StackProbeType, Target};
33

44
pub fn target() -> Target {
55
let mut base = super::linux_musl_base::opts();
@@ -14,6 +14,8 @@ pub fn target() -> Target {
1414
base.min_global_align = Some(16);
1515
base.static_position_independent_executables = true;
1616
base.stack_probes = StackProbeType::Inline;
17+
base.supported_sanitizers =
18+
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
1719

1820
Target {
1921
llvm_target: "s390x-unknown-linux-musl".into(),

compiler/rustc_trait_selection/src/solve/assembly.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Code shared by trait and projection goals for candidate assembly.
22
33
use super::infcx_ext::InferCtxtExt;
4-
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
4+
use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, QueryResult};
55
use rustc_hir::def_id::DefId;
66
use rustc_infer::traits::query::NoSolution;
77
use rustc_infer::traits::util::elaborate_predicates;
@@ -148,9 +148,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
148148
if goal.predicate.self_ty().is_ty_var() {
149149
return vec![Candidate {
150150
source: CandidateSource::BuiltinImpl,
151-
result: self
152-
.make_canonical_response(Certainty::Maybe(MaybeCause::Ambiguity))
153-
.unwrap(),
151+
result: self.make_canonical_response(Certainty::AMBIGUOUS).unwrap(),
154152
}];
155153
}
156154

compiler/rustc_trait_selection/src/solve/mod.rs

+76-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919

2020
use std::mem;
2121

22+
use rustc_hir::def_id::DefId;
2223
use rustc_infer::infer::canonical::{Canonical, CanonicalVarKind, CanonicalVarValues};
2324
use rustc_infer::infer::canonical::{OriginalQueryValues, QueryRegionConstraints, QueryResponse};
2425
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
2526
use rustc_infer::traits::query::NoSolution;
2627
use rustc_infer::traits::Obligation;
2728
use rustc_middle::infer::canonical::Certainty as OldCertainty;
2829
use rustc_middle::ty::{self, Ty, TyCtxt};
29-
use rustc_middle::ty::{RegionOutlivesPredicate, ToPredicate, TypeOutlivesPredicate};
30+
use rustc_middle::ty::{
31+
CoercePredicate, RegionOutlivesPredicate, SubtypePredicate, ToPredicate, TypeOutlivesPredicate,
32+
};
3033
use rustc_span::DUMMY_SP;
3134

3235
use crate::traits::ObligationCause;
@@ -87,6 +90,8 @@ pub enum Certainty {
8790
}
8891

8992
impl Certainty {
93+
pub const AMBIGUOUS: Certainty = Certainty::Maybe(MaybeCause::Ambiguity);
94+
9095
/// When proving multiple goals using **AND**, e.g. nested obligations for an impl,
9196
/// use this function to unify the certainty of these goals
9297
pub fn unify_and(self, other: Certainty) -> Certainty {
@@ -243,16 +248,28 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
243248
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
244249
self.compute_region_outlives_goal(Goal { param_env, predicate })
245250
}
251+
ty::PredicateKind::Subtype(predicate) => {
252+
self.compute_subtype_goal(Goal { param_env, predicate })
253+
}
254+
ty::PredicateKind::Coerce(predicate) => {
255+
self.compute_coerce_goal(Goal { param_env, predicate })
256+
}
257+
ty::PredicateKind::ClosureKind(def_id, substs, kind) => self
258+
.compute_closure_kind_goal(Goal {
259+
param_env,
260+
predicate: (def_id, substs, kind),
261+
}),
262+
ty::PredicateKind::Ambiguous => self.make_canonical_response(Certainty::AMBIGUOUS),
246263
// FIXME: implement these predicates :)
247264
ty::PredicateKind::WellFormed(_)
248265
| ty::PredicateKind::ObjectSafe(_)
249-
| ty::PredicateKind::ClosureKind(_, _, _)
250-
| ty::PredicateKind::Subtype(_)
251-
| ty::PredicateKind::Coerce(_)
252266
| ty::PredicateKind::ConstEvaluatable(_)
253-
| ty::PredicateKind::ConstEquate(_, _)
254-
| ty::PredicateKind::TypeWellFormedFromEnv(_)
255-
| ty::PredicateKind::Ambiguous => self.make_canonical_response(Certainty::Yes),
267+
| ty::PredicateKind::ConstEquate(_, _) => {
268+
self.make_canonical_response(Certainty::Yes)
269+
}
270+
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
271+
bug!("TypeWellFormedFromEnv is only used for Chalk")
272+
}
256273
}
257274
} else {
258275
let kind = self.infcx.replace_bound_vars_with_placeholders(kind);
@@ -275,6 +292,58 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
275292
) -> QueryResult<'tcx> {
276293
self.make_canonical_response(Certainty::Yes)
277294
}
295+
296+
fn compute_coerce_goal(
297+
&mut self,
298+
goal: Goal<'tcx, CoercePredicate<'tcx>>,
299+
) -> QueryResult<'tcx> {
300+
self.compute_subtype_goal(Goal {
301+
param_env: goal.param_env,
302+
predicate: SubtypePredicate {
303+
a_is_expected: false,
304+
a: goal.predicate.a,
305+
b: goal.predicate.b,
306+
},
307+
})
308+
}
309+
310+
fn compute_subtype_goal(
311+
&mut self,
312+
goal: Goal<'tcx, SubtypePredicate<'tcx>>,
313+
) -> QueryResult<'tcx> {
314+
if goal.predicate.a.is_ty_var() && goal.predicate.b.is_ty_var() {
315+
// FIXME: Do we want to register a subtype relation between these vars?
316+
// That won't actually reflect in the query response, so it seems moot.
317+
self.make_canonical_response(Certainty::AMBIGUOUS)
318+
} else {
319+
self.infcx.probe(|_| {
320+
let InferOk { value: (), obligations } = self
321+
.infcx
322+
.at(&ObligationCause::dummy(), goal.param_env)
323+
.sub(goal.predicate.a, goal.predicate.b)?;
324+
self.evaluate_all_and_make_canonical_response(
325+
obligations.into_iter().map(|pred| pred.into()).collect(),
326+
)
327+
})
328+
}
329+
}
330+
331+
fn compute_closure_kind_goal(
332+
&mut self,
333+
goal: Goal<'tcx, (DefId, ty::SubstsRef<'tcx>, ty::ClosureKind)>,
334+
) -> QueryResult<'tcx> {
335+
let (_, substs, expected_kind) = goal.predicate;
336+
let found_kind = substs.as_closure().kind_ty().to_opt_closure_kind();
337+
338+
let Some(found_kind) = found_kind else {
339+
return self.make_canonical_response(Certainty::AMBIGUOUS);
340+
};
341+
if found_kind.extends(expected_kind) {
342+
self.make_canonical_response(Certainty::Yes)
343+
} else {
344+
Err(NoSolution)
345+
}
346+
}
278347
}
279348

280349
impl<'tcx> EvalCtxt<'_, 'tcx> {

compiler/rustc_trait_selection/src/solve/project_goals.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::traits::{specialization_graph, translate_substs};
33
use super::assembly::{self, Candidate, CandidateSource};
44
use super::infcx_ext::InferCtxtExt;
55
use super::trait_goals::structural_traits;
6-
use super::{Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
6+
use super::{Certainty, EvalCtxt, Goal, QueryResult};
77
use rustc_errors::ErrorGuaranteed;
88
use rustc_hir::def::DefKind;
99
use rustc_hir::def_id::DefId;
@@ -229,8 +229,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
229229
goal.predicate.def_id(),
230230
impl_def_id
231231
)? else {
232-
let certainty = Certainty::Maybe(MaybeCause::Ambiguity);
233-
return ecx.make_canonical_response(trait_ref_certainty.unify_and(certainty));
232+
return ecx.make_canonical_response(trait_ref_certainty.unify_and(Certainty::AMBIGUOUS));
234233
};
235234

236235
if !assoc_def.item.defaultness(tcx).has_value() {
@@ -382,7 +381,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
382381
.to_predicate(ecx.tcx());
383382
Self::consider_assumption(ecx, goal, pred)
384383
} else {
385-
ecx.make_canonical_response(Certainty::Maybe(MaybeCause::Ambiguity))
384+
ecx.make_canonical_response(Certainty::AMBIGUOUS)
386385
}
387386
}
388387

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::iter;
44

55
use super::assembly::{self, Candidate, CandidateSource};
66
use super::infcx_ext::InferCtxtExt;
7-
use super::{Certainty, EvalCtxt, Goal, MaybeCause, QueryResult};
7+
use super::{Certainty, EvalCtxt, Goal, QueryResult};
88
use rustc_hir::def_id::DefId;
99
use rustc_infer::infer::InferCtxt;
1010
use rustc_infer::traits::query::NoSolution;
@@ -133,7 +133,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
133133
goal: Goal<'tcx, Self>,
134134
) -> QueryResult<'tcx> {
135135
if goal.predicate.self_ty().has_non_region_infer() {
136-
return ecx.make_canonical_response(Certainty::Maybe(MaybeCause::Ambiguity));
136+
return ecx.make_canonical_response(Certainty::AMBIGUOUS);
137137
}
138138

139139
let tcx = ecx.tcx();
@@ -171,7 +171,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
171171
.to_predicate(ecx.tcx());
172172
Self::consider_assumption(ecx, goal, pred)
173173
} else {
174-
ecx.make_canonical_response(Certainty::Maybe(MaybeCause::Ambiguity))
174+
ecx.make_canonical_response(Certainty::AMBIGUOUS)
175175
}
176176
}
177177

0 commit comments

Comments
 (0)