Skip to content

Commit 7e393b5

Browse files
committed
Auto merge of #67970 - cjgillot:inherent, r=Centril
Minimize dependencies on trait and infer inside librustc Split from #67953 All commits should pass check on their own. r? @Centril
2 parents 8597644 + 700ac84 commit 7e393b5

Some content is hidden

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

42 files changed

+1512
-1442
lines changed

src/librustc/infer/error_reporting/mod.rs

+192-189
Large diffs are not rendered by default.

src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Error Reporting for static impl Traits.
22
3+
use crate::infer::error_reporting::msg_span_from_free_region;
34
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
45
use crate::infer::lexical_region_resolve::RegionResolutionError;
56
use crate::ty::{BoundRegion, FreeRegion, RegionKind};
@@ -32,7 +33,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
3233
);
3334
err.span_label(sup_origin.span(), "...but this borrow...");
3435

35-
let (lifetime, lt_sp_opt) = self.tcx().msg_span_from_free_region(sup_r);
36+
let (lifetime, lt_sp_opt) = msg_span_from_free_region(self.tcx(), sup_r);
3637
if let Some(lifetime_sp) = lt_sp_opt {
3738
err.span_note(lifetime_sp, &format!("...can't outlive {}", lifetime));
3839
}

src/librustc/infer/error_reporting/note.rs

+70-35
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::infer::error_reporting::note_and_explain_region;
12
use crate::infer::{self, InferCtxt, SubregionOrigin};
23
use crate::middle::region;
34
use crate::ty::error::TypeError;
@@ -167,8 +168,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
167168
infer::Subtype(box trace) => {
168169
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
169170
let mut err = self.report_and_explain_type_error(trace, &terr);
170-
self.tcx.note_and_explain_region(region_scope_tree, &mut err, "", sup, "...");
171-
self.tcx.note_and_explain_region(
171+
note_and_explain_region(self.tcx, region_scope_tree, &mut err, "", sup, "...");
172+
note_and_explain_region(
173+
self.tcx,
172174
region_scope_tree,
173175
&mut err,
174176
"...does not necessarily outlive ",
@@ -185,14 +187,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
185187
"lifetime of reference outlives lifetime of \
186188
borrowed content..."
187189
);
188-
self.tcx.note_and_explain_region(
190+
note_and_explain_region(
191+
self.tcx,
189192
region_scope_tree,
190193
&mut err,
191194
"...the reference is valid for ",
192195
sub,
193196
"...",
194197
);
195-
self.tcx.note_and_explain_region(
198+
note_and_explain_region(
199+
self.tcx,
196200
region_scope_tree,
197201
&mut err,
198202
"...but the borrowed content is only valid for ",
@@ -211,14 +215,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
211215
of captured variable `{}`...",
212216
var_name
213217
);
214-
self.tcx.note_and_explain_region(
218+
note_and_explain_region(
219+
self.tcx,
215220
region_scope_tree,
216221
&mut err,
217222
"...the borrowed pointer is valid for ",
218223
sub,
219224
"...",
220225
);
221-
self.tcx.note_and_explain_region(
226+
note_and_explain_region(
227+
self.tcx,
222228
region_scope_tree,
223229
&mut err,
224230
&format!("...but `{}` is only valid for ", var_name),
@@ -230,14 +236,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
230236
infer::InfStackClosure(span) => {
231237
let mut err =
232238
struct_span_err!(self.tcx.sess, span, E0314, "closure outlives stack frame");
233-
self.tcx.note_and_explain_region(
239+
note_and_explain_region(
240+
self.tcx,
234241
region_scope_tree,
235242
&mut err,
236243
"...the closure must be valid for ",
237244
sub,
238245
"...",
239246
);
240-
self.tcx.note_and_explain_region(
247+
note_and_explain_region(
248+
self.tcx,
241249
region_scope_tree,
242250
&mut err,
243251
"...but the closure's stack frame is only valid \
@@ -254,7 +262,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
254262
E0315,
255263
"cannot invoke closure outside of its lifetime"
256264
);
257-
self.tcx.note_and_explain_region(
265+
note_and_explain_region(
266+
self.tcx,
258267
region_scope_tree,
259268
&mut err,
260269
"the closure is only valid for ",
@@ -270,7 +279,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
270279
E0473,
271280
"dereference of reference outside its lifetime"
272281
);
273-
self.tcx.note_and_explain_region(
282+
note_and_explain_region(
283+
self.tcx,
274284
region_scope_tree,
275285
&mut err,
276286
"the reference is only valid for ",
@@ -288,14 +298,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
288298
enclosing closure",
289299
self.tcx.hir().name(id)
290300
);
291-
self.tcx.note_and_explain_region(
301+
note_and_explain_region(
302+
self.tcx,
292303
region_scope_tree,
293304
&mut err,
294305
"captured variable is valid for ",
295306
sup,
296307
"",
297308
);
298-
self.tcx.note_and_explain_region(
309+
note_and_explain_region(
310+
self.tcx,
299311
region_scope_tree,
300312
&mut err,
301313
"closure is valid for ",
@@ -311,7 +323,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
311323
E0475,
312324
"index of slice outside its lifetime"
313325
);
314-
self.tcx.note_and_explain_region(
326+
note_and_explain_region(
327+
self.tcx,
315328
region_scope_tree,
316329
&mut err,
317330
"the slice is only valid for ",
@@ -328,14 +341,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
328341
"lifetime of the source pointer does not outlive \
329342
lifetime bound of the object type"
330343
);
331-
self.tcx.note_and_explain_region(
344+
note_and_explain_region(
345+
self.tcx,
332346
region_scope_tree,
333347
&mut err,
334348
"object type is valid for ",
335349
sub,
336350
"",
337351
);
338-
self.tcx.note_and_explain_region(
352+
note_and_explain_region(
353+
self.tcx,
339354
region_scope_tree,
340355
&mut err,
341356
"source pointer is only valid for ",
@@ -354,14 +369,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
354369
self.ty_to_string(ty)
355370
);
356371
match *sub {
357-
ty::ReStatic => self.tcx.note_and_explain_region(
372+
ty::ReStatic => note_and_explain_region(
373+
self.tcx,
358374
region_scope_tree,
359375
&mut err,
360376
"type must satisfy ",
361377
sub,
362378
"",
363379
),
364-
_ => self.tcx.note_and_explain_region(
380+
_ => note_and_explain_region(
381+
self.tcx,
365382
region_scope_tree,
366383
&mut err,
367384
"type must outlive ",
@@ -374,14 +391,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
374391
infer::RelateRegionParamBound(span) => {
375392
let mut err =
376393
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
377-
self.tcx.note_and_explain_region(
394+
note_and_explain_region(
395+
self.tcx,
378396
region_scope_tree,
379397
&mut err,
380398
"lifetime parameter instantiated with ",
381399
sup,
382400
"",
383401
);
384-
self.tcx.note_and_explain_region(
402+
note_and_explain_region(
403+
self.tcx,
385404
region_scope_tree,
386405
&mut err,
387406
"but lifetime parameter must outlive ",
@@ -399,7 +418,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
399418
parameter) is not valid at this point",
400419
self.ty_to_string(ty)
401420
);
402-
self.tcx.note_and_explain_region(
421+
note_and_explain_region(
422+
self.tcx,
403423
region_scope_tree,
404424
&mut err,
405425
"type must outlive ",
@@ -416,7 +436,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
416436
"lifetime of method receiver does not outlive the \
417437
method call"
418438
);
419-
self.tcx.note_and_explain_region(
439+
note_and_explain_region(
440+
self.tcx,
420441
region_scope_tree,
421442
&mut err,
422443
"the receiver is only valid for ",
@@ -433,7 +454,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
433454
"lifetime of function argument does not outlive \
434455
the function call"
435456
);
436-
self.tcx.note_and_explain_region(
457+
note_and_explain_region(
458+
self.tcx,
437459
region_scope_tree,
438460
&mut err,
439461
"the function argument is only valid for ",
@@ -450,7 +472,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
450472
"lifetime of return value does not outlive the \
451473
function call"
452474
);
453-
self.tcx.note_and_explain_region(
475+
note_and_explain_region(
476+
self.tcx,
454477
region_scope_tree,
455478
&mut err,
456479
"the return value is only valid for ",
@@ -467,7 +490,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
467490
"lifetime of operand does not outlive the \
468491
operation"
469492
);
470-
self.tcx.note_and_explain_region(
493+
note_and_explain_region(
494+
self.tcx,
471495
region_scope_tree,
472496
&mut err,
473497
"the operand is only valid for ",
@@ -483,7 +507,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
483507
E0484,
484508
"reference is not valid at the time of borrow"
485509
);
486-
self.tcx.note_and_explain_region(
510+
note_and_explain_region(
511+
self.tcx,
487512
region_scope_tree,
488513
&mut err,
489514
"the borrow is only valid for ",
@@ -500,7 +525,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
500525
"automatically reference is not valid at the time \
501526
of borrow"
502527
);
503-
self.tcx.note_and_explain_region(
528+
note_and_explain_region(
529+
self.tcx,
504530
region_scope_tree,
505531
&mut err,
506532
"the automatic borrow is only valid for ",
@@ -518,7 +544,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
518544
not valid during the expression: `{}`",
519545
self.ty_to_string(t)
520546
);
521-
self.tcx.note_and_explain_region(
547+
note_and_explain_region(
548+
self.tcx,
522549
region_scope_tree,
523550
&mut err,
524551
"type is only valid for ",
@@ -536,14 +563,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
536563
called while references are dead"
537564
);
538565
// FIXME (22171): terms "super/subregion" are suboptimal
539-
self.tcx.note_and_explain_region(
566+
note_and_explain_region(
567+
self.tcx,
540568
region_scope_tree,
541569
&mut err,
542570
"superregion: ",
543571
sup,
544572
"",
545573
);
546-
self.tcx.note_and_explain_region(
574+
note_and_explain_region(
575+
self.tcx,
547576
region_scope_tree,
548577
&mut err,
549578
"subregion: ",
@@ -560,7 +589,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
560589
"lifetime of variable does not enclose its \
561590
declaration"
562591
);
563-
self.tcx.note_and_explain_region(
592+
note_and_explain_region(
593+
self.tcx,
564594
region_scope_tree,
565595
&mut err,
566596
"the variable is only valid for ",
@@ -576,7 +606,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
576606
E0489,
577607
"type/lifetime parameter not in scope here"
578608
);
579-
self.tcx.note_and_explain_region(
609+
note_and_explain_region(
610+
self.tcx,
580611
region_scope_tree,
581612
&mut err,
582613
"the parameter is only valid for ",
@@ -593,14 +624,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
593624
"a value of type `{}` is borrowed for too long",
594625
self.ty_to_string(ty)
595626
);
596-
self.tcx.note_and_explain_region(
627+
note_and_explain_region(
628+
self.tcx,
597629
region_scope_tree,
598630
&mut err,
599631
"the type is valid for ",
600632
sub,
601633
"",
602634
);
603-
self.tcx.note_and_explain_region(
635+
note_and_explain_region(
636+
self.tcx,
604637
region_scope_tree,
605638
&mut err,
606639
"but the borrow lasts for ",
@@ -618,14 +651,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
618651
than the data it references",
619652
self.ty_to_string(ty)
620653
);
621-
self.tcx.note_and_explain_region(
654+
note_and_explain_region(
655+
self.tcx,
622656
region_scope_tree,
623657
&mut err,
624658
"the pointer is valid for ",
625659
sub,
626660
"",
627661
);
628-
self.tcx.note_and_explain_region(
662+
note_and_explain_region(
663+
self.tcx,
629664
region_scope_tree,
630665
&mut err,
631666
"but the referenced data is only valid for ",

0 commit comments

Comments
 (0)