Skip to content

Commit 52f3c71

Browse files
committed
Auto merge of #127898 - matthiaskrgr:rollup-lkkpoui, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #127077 (Make language around `ToOwned` for `BorrowedFd` more precise) - #127783 (Put the dots back in RTN pretty printing) - #127787 (Migrate `atomic-lock-free` to `rmake`) - #127810 (Rename `tcx` to `cx` in `rustc_type_ir`) - #127878 (Fix associated item removal suggestion) - #127886 (Accurate `use` rename suggestion span) - #127888 (More accurate span for type parameter suggestion) - #127889 (More accurate span for anonymous argument suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4bb2f27 + 77e5bbf commit 52f3c71

File tree

80 files changed

+550
-383
lines changed

Some content is hidden

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

80 files changed

+550
-383
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/relate_tys.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
309309
}
310310

311311
impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
312-
fn tcx(&self) -> TyCtxt<'tcx> {
312+
fn cx(&self) -> TyCtxt<'tcx> {
313313
self.type_checker.infcx.tcx
314314
}
315315

@@ -370,7 +370,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
370370
// shouldn't ever fail. Instead, it unconditionally emits an
371371
// alias-relate goal.
372372
assert!(!self.type_checker.infcx.next_trait_solver());
373-
self.tcx().dcx().span_delayed_bug(
373+
self.cx().dcx().span_delayed_bug(
374374
self.span(),
375375
"failure to relate an opaque to itself should result in an error later on",
376376
);
@@ -540,7 +540,7 @@ impl<'bccx, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating
540540
&mut self,
541541
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
542542
) {
543-
let tcx = self.tcx();
543+
let tcx = self.cx();
544544
let param_env = self.param_env();
545545
self.register_goals(
546546
obligations.into_iter().map(|to_pred| Goal::new(tcx, param_env, to_pred)),
@@ -559,7 +559,7 @@ impl<'bccx, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating
559559
.into_iter()
560560
.map(|goal| {
561561
Obligation::new(
562-
self.tcx(),
562+
self.cx(),
563563
ObligationCause::dummy_with_span(self.span()),
564564
goal.param_env,
565565
goal.predicate,

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,12 @@ pub fn prohibit_assoc_item_constraint(
12571257
};
12581258

12591259
// Now emit the suggestion
1260-
if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(removal_span) {
1261-
e.span_suggestion_verbose(
1262-
removal_span,
1263-
format!("consider removing this associated item {}", constraint.kind.descr()),
1264-
suggestion,
1265-
Applicability::MaybeIncorrect,
1266-
);
1267-
}
1260+
e.span_suggestion_verbose(
1261+
removal_span,
1262+
format!("consider removing this associated item {}", constraint.kind.descr()),
1263+
"",
1264+
Applicability::MaybeIncorrect,
1265+
);
12681266
};
12691267

12701268
// Suggest replacing the associated item binding with a generic argument.
@@ -1340,11 +1338,13 @@ pub fn prohibit_assoc_item_constraint(
13401338
format!("<{lifetimes}{type_with_constraints}>"),
13411339
)
13421340
};
1343-
let suggestions =
1344-
vec![param_decl, (constraint.span, format!("{}", matching_param.name))];
1341+
let suggestions = vec![
1342+
param_decl,
1343+
(constraint.span.with_lo(constraint.ident.span.hi()), String::new()),
1344+
];
13451345

13461346
err.multipart_suggestion_verbose(
1347-
format!("declare the type parameter right after the `impl` keyword"),
1347+
"declare the type parameter right after the `impl` keyword",
13481348
suggestions,
13491349
Applicability::MaybeIncorrect,
13501350
);

Diff for: compiler/rustc_infer/src/error_reporting/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1930,7 +1930,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19301930
struct SameTypeModuloInfer<'a, 'tcx>(&'a InferCtxt<'tcx>);
19311931

19321932
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for SameTypeModuloInfer<'_, 'tcx> {
1933-
fn tcx(&self) -> TyCtxt<'tcx> {
1933+
fn cx(&self) -> TyCtxt<'tcx> {
19341934
self.0.tcx
19351935
}
19361936

Diff for: compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx>
137137
"MatchAgainstHigherRankedOutlives"
138138
}
139139

140-
fn tcx(&self) -> TyCtxt<'tcx> {
140+
fn cx(&self) -> TyCtxt<'tcx> {
141141
self.tcx
142142
}
143143

Diff for: compiler/rustc_infer/src/infer/relate/generalize.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
372372

373373
let is_nested_alias = mem::replace(&mut self.in_alias, true);
374374
let result = match self.relate(alias, alias) {
375-
Ok(alias) => Ok(alias.to_ty(self.tcx())),
375+
Ok(alias) => Ok(alias.to_ty(self.cx())),
376376
Err(e) => {
377377
if is_nested_alias {
378378
return Err(e);
@@ -397,7 +397,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
397397
}
398398

399399
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
400-
fn tcx(&self) -> TyCtxt<'tcx> {
400+
fn cx(&self) -> TyCtxt<'tcx> {
401401
self.infcx.tcx
402402
}
403403

@@ -417,7 +417,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
417417
// (e.g., #41849).
418418
relate::relate_args_invariantly(self, a_arg, b_arg)
419419
} else {
420-
let tcx = self.tcx();
420+
let tcx = self.cx();
421421
let opt_variances = tcx.variances_of(item_def_id);
422422
relate::relate_args_with_variances(
423423
self,
@@ -525,7 +525,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
525525
}
526526

527527
debug!("replacing original vid={:?} with new={:?}", vid, new_var_id);
528-
Ok(Ty::new_var(self.tcx(), new_var_id))
528+
Ok(Ty::new_var(self.cx(), new_var_id))
529529
}
530530
}
531531
}
@@ -654,7 +654,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
654654
{
655655
variable_table.union(vid, new_var_id);
656656
}
657-
Ok(ty::Const::new_var(self.tcx(), new_var_id))
657+
Ok(ty::Const::new_var(self.cx(), new_var_id))
658658
}
659659
}
660660
}
@@ -672,7 +672,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
672672
args,
673673
args,
674674
)?;
675-
Ok(ty::Const::new_unevaluated(self.tcx(), ty::UnevaluatedConst { def, args }))
675+
Ok(ty::Const::new_unevaluated(self.cx(), ty::UnevaluatedConst { def, args }))
676676
}
677677
ty::ConstKind::Placeholder(placeholder) => {
678678
if self.for_universe.can_name(placeholder.universe) {

Diff for: compiler/rustc_infer/src/infer/relate/glb.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
2727
"Glb"
2828
}
2929

30-
fn tcx(&self) -> TyCtxt<'tcx> {
30+
fn cx(&self) -> TyCtxt<'tcx> {
3131
self.fields.tcx()
3232
}
3333

@@ -61,7 +61,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
6161
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
6262
// GLB(&'static u8, &'a u8) == &RegionLUB('static, 'a) u8 == &'static u8
6363
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
64-
self.tcx(),
64+
self.cx(),
6565
origin,
6666
a,
6767
b,

Diff for: compiler/rustc_infer/src/infer/relate/lub.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
2727
"Lub"
2828
}
2929

30-
fn tcx(&self) -> TyCtxt<'tcx> {
30+
fn cx(&self) -> TyCtxt<'tcx> {
3131
self.fields.tcx()
3232
}
3333

@@ -61,7 +61,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
6161
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
6262
// LUB(&'static u8, &'a u8) == &RegionGLB('static, 'a) u8 == &'a u8
6363
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
64-
self.tcx(),
64+
self.cx(),
6565
origin,
6666
a,
6767
b,

Diff for: compiler/rustc_infer/src/infer/relate/type_relating.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
3232
"TypeRelating"
3333
}
3434

35-
fn tcx(&self) -> TyCtxt<'tcx> {
35+
fn cx(&self) -> TyCtxt<'tcx> {
3636
self.fields.infcx.tcx
3737
}
3838

@@ -48,7 +48,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
4848
// (e.g., #41849).
4949
relate_args_invariantly(self, a_arg, b_arg)
5050
} else {
51-
let tcx = self.tcx();
51+
let tcx = self.cx();
5252
let opt_variances = tcx.variances_of(item_def_id);
5353
relate_args_with_variances(self, item_def_id, opt_variances, a_arg, b_arg, false)
5454
}
@@ -88,7 +88,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
8888
// can't make progress on `A <: B` if both A and B are
8989
// type variables, so record an obligation.
9090
self.fields.goals.push(Goal::new(
91-
self.tcx(),
91+
self.cx(),
9292
self.fields.param_env,
9393
ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate {
9494
a_is_expected: true,
@@ -101,7 +101,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
101101
// can't make progress on `B <: A` if both A and B are
102102
// type variables, so record an obligation.
103103
self.fields.goals.push(Goal::new(
104-
self.tcx(),
104+
self.cx(),
105105
self.fields.param_env,
106106
ty::Binder::dummy(ty::PredicateKind::Subtype(ty::SubtypePredicate {
107107
a_is_expected: false,
@@ -134,7 +134,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
134134

135135
(&ty::Error(e), _) | (_, &ty::Error(e)) => {
136136
infcx.set_tainted_by_errors(e);
137-
return Ok(Ty::new_error(self.tcx(), e));
137+
return Ok(Ty::new_error(self.cx(), e));
138138
}
139139

140140
(

Diff for: compiler/rustc_macros/src/lift.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStre
4545
quote! {
4646
type Lifted = #lifted;
4747

48-
fn lift_to_tcx(self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> {
48+
fn lift_to_interner(self, __tcx: ::rustc_middle::ty::TyCtxt<'__lifted>) -> Option<#lifted> {
4949
Some(match self { #body })
5050
}
5151
},

Diff for: compiler/rustc_middle/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ macro_rules! TrivialLiftImpls {
5959
$(
6060
impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty {
6161
type Lifted = Self;
62-
fn lift_to_tcx(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
62+
fn lift_to_interner(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
6363
Some(self)
6464
}
6565
}

Diff for: compiler/rustc_middle/src/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ impl<'tcx> TyCtxt<'tcx> {
14841484
}
14851485

14861486
pub fn lift<T: Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> {
1487-
value.lift_to_tcx(self)
1487+
value.lift_to_interner(self)
14881488
}
14891489

14901490
/// Creates a type context. To use the context call `fn enter` which
@@ -2087,7 +2087,7 @@ macro_rules! nop_lift {
20872087
($set:ident; $ty:ty => $lifted:ty) => {
20882088
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for $ty {
20892089
type Lifted = $lifted;
2090-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
2090+
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
20912091
// Assert that the set has the right type.
20922092
// Given an argument that has an interned type, the return type has the type of
20932093
// the corresponding interner set. This won't actually return anything, we're
@@ -2122,7 +2122,7 @@ macro_rules! nop_list_lift {
21222122
($set:ident; $ty:ty => $lifted:ty) => {
21232123
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<$ty> {
21242124
type Lifted = &'tcx List<$lifted>;
2125-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
2125+
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
21262126
// Assert that the set has the right type.
21272127
if false {
21282128
let _x: &InternedSet<'tcx, List<$lifted>> = &tcx.interners.$set;
@@ -2160,7 +2160,7 @@ macro_rules! nop_slice_lift {
21602160
($ty:ty => $lifted:ty) => {
21612161
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a [$ty] {
21622162
type Lifted = &'tcx [$lifted];
2163-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
2163+
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
21642164
if self.is_empty() {
21652165
return Some(&[]);
21662166
}

Diff for: compiler/rustc_middle/src/ty/generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'tcx> GenericArg<'tcx> {
308308
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for GenericArg<'a> {
309309
type Lifted = GenericArg<'tcx>;
310310

311-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
311+
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
312312
match self.unpack() {
313313
GenericArgKind::Lifetime(lt) => tcx.lift(lt).map(|lt| lt.into()),
314314
GenericArgKind::Type(ty) => tcx.lift(ty).map(|ty| ty.into()),

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
12141214
&& let ty::Alias(_, alias_ty) =
12151215
self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind()
12161216
&& alias_ty.def_id == def_id
1217+
&& let generics = self.tcx().generics_of(fn_def_id)
1218+
// FIXME(return_type_notation): We only support lifetime params for now.
1219+
&& generics.own_params.iter().all(|param| matches!(param.kind, ty::GenericParamDefKind::Lifetime))
12171220
{
1218-
let num_args = self.tcx().generics_of(fn_def_id).count();
1221+
let num_args = generics.count();
12191222
write!(self, " {{ ")?;
12201223
self.print_def_path(fn_def_id, &args[..num_args])?;
1221-
write!(self, "() }}")?;
1224+
write!(self, "(..) }}")?;
12221225
}
12231226

12241227
Ok(())

Diff for: compiler/rustc_middle/src/ty/relate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'tcx> Relate<TyCtxt<'tcx>> for ty::Pattern<'tcx> {
6969
if inc_a != inc_b {
7070
todo!()
7171
}
72-
Ok(relation.tcx().mk_pat(ty::PatternKind::Range { start, end, include_end: inc_a }))
72+
Ok(relation.cx().mk_pat(ty::PatternKind::Range { start, end, include_end: inc_a }))
7373
}
7474
}
7575
}
@@ -81,7 +81,7 @@ impl<'tcx> Relate<TyCtxt<'tcx>> for &'tcx ty::List<ty::PolyExistentialPredicate<
8181
a: Self,
8282
b: Self,
8383
) -> RelateResult<'tcx, Self> {
84-
let tcx = relation.tcx();
84+
let tcx = relation.cx();
8585

8686
// FIXME: this is wasteful, but want to do a perf run to see how slow it is.
8787
// We need to perform this deduplication as we sometimes generate duplicate projections

Diff for: compiler/rustc_middle/src/ty/structural_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ TrivialTypeTraversalAndLiftImpls! {
283283

284284
impl<'tcx, T: Lift<TyCtxt<'tcx>>> Lift<TyCtxt<'tcx>> for Option<T> {
285285
type Lifted = Option<T::Lifted>;
286-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
286+
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
287287
Some(match self {
288288
Some(x) => Some(tcx.lift(x)?),
289289
None => None,
@@ -293,7 +293,7 @@ impl<'tcx, T: Lift<TyCtxt<'tcx>>> Lift<TyCtxt<'tcx>> for Option<T> {
293293

294294
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for Term<'a> {
295295
type Lifted = ty::Term<'tcx>;
296-
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
296+
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
297297
match self.unpack() {
298298
TermKind::Ty(ty) => tcx.lift(ty).map(Into::into),
299299
TermKind::Const(c) => tcx.lift(c).map(Into::into),

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2240,11 +2240,11 @@ impl<'a> Parser<'a> {
22402240
}
22412241
_ => {
22422242
// Otherwise, try to get a type and emit a suggestion.
2243-
if let Some(ty) = pat.to_ty() {
2243+
if let Some(_) = pat.to_ty() {
22442244
err.span_suggestion_verbose(
2245-
pat.span,
2245+
pat.span.shrink_to_lo(),
22462246
"explicitly ignore the parameter name",
2247-
format!("_: {}", pprust::ty_to_string(&ty)),
2247+
"_: ".to_string(),
22482248
Applicability::MachineApplicable,
22492249
);
22502250
err.note(rfc_note);
@@ -2256,7 +2256,7 @@ impl<'a> Parser<'a> {
22562256

22572257
// `fn foo(a, b) {}`, `fn foo(a<x>, b<y>) {}` or `fn foo(usize, usize) {}`
22582258
if first_param {
2259-
err.span_suggestion(
2259+
err.span_suggestion_verbose(
22602260
self_span,
22612261
"if this is a `self` type, give it a parameter name",
22622262
self_sugg,
@@ -2266,14 +2266,14 @@ impl<'a> Parser<'a> {
22662266
// Avoid suggesting that `fn foo(HashMap<u32>)` is fixed with a change to
22672267
// `fn foo(HashMap: TypeName<u32>)`.
22682268
if self.token != token::Lt {
2269-
err.span_suggestion(
2269+
err.span_suggestion_verbose(
22702270
param_span,
22712271
"if this is a parameter name, give it a type",
22722272
param_sugg,
22732273
Applicability::HasPlaceholders,
22742274
);
22752275
}
2276-
err.span_suggestion(
2276+
err.span_suggestion_verbose(
22772277
type_span,
22782278
"if this is a type, explicitly ignore the parameter name",
22792279
type_sugg,

0 commit comments

Comments
 (0)