Skip to content

Commit 487384b

Browse files
authored
Unrolled build for rust-lang#125667
Rollup merge of rust-lang#125667 - oli-obk:taintify, r=TaKO8Ki Silence follow-up errors directly based on error types and regions During type_of, we used to just return an error type if there were any errors encountered. This is problematic, because it means a struct declared as `struct Foo<'static>` will end up not finding any inherent or trait impls because those impl blocks' `Self` type will be `{type error}` instead of `Foo<'re_error>`. Now it's the latter, silencing nonsensical follow-up errors about `Foo` not having any methods. Unfortunately that now allows for new follow-up errors, because borrowck treats `'re_error` as `'static`, causing nonsensical errors about non-error lifetimes not outliving `'static`. So what I also did was to just strip all outlives bounds that borrowck found, thus never letting it check them. There are probably more nuanced ways to do this, but I worried there would be other nonsensical errors if some outlives bounds were missing. Also from the test changes, it looked like an improvement everywhere.
2 parents bc33782 + 39b39da commit 487384b

Some content is hidden

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

43 files changed

+271
-297
lines changed

Diff for: compiler/rustc_borrowck/src/nll.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
125125
placeholder_indices,
126126
placeholder_index_to_region: _,
127127
liveness_constraints,
128-
outlives_constraints,
129-
member_constraints,
128+
mut outlives_constraints,
129+
mut member_constraints,
130130
universe_causes,
131131
type_tests,
132132
} = constraints;
@@ -144,6 +144,16 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
144144
&universal_region_relations,
145145
);
146146

147+
if let Some(guar) = universal_regions.tainted_by_errors() {
148+
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
149+
// outlives bounds that we may end up checking.
150+
outlives_constraints = Default::default();
151+
member_constraints = Default::default();
152+
153+
// Also taint the entire scope.
154+
infcx.set_tainted_by_errors(guar);
155+
}
156+
147157
let mut regioncx = RegionInferenceContext::new(
148158
infcx,
149159
var_origins,

Diff for: compiler/rustc_borrowck/src/universal_regions.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, T
2929
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
3030
use rustc_middle::{bug, span_bug};
3131
use rustc_span::symbol::{kw, sym};
32-
use rustc_span::Symbol;
32+
use rustc_span::{ErrorGuaranteed, Symbol};
33+
use std::cell::Cell;
3334
use std::iter;
3435

3536
use crate::renumber::RegionCtxt;
@@ -186,6 +187,10 @@ struct UniversalRegionIndices<'tcx> {
186187

187188
/// The vid assigned to `'static`. Used only for diagnostics.
188189
pub fr_static: RegionVid,
190+
191+
/// Whether we've encountered an error region. If we have, cancel all
192+
/// outlives errors, as they are likely bogus.
193+
pub tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
189194
}
190195

191196
#[derive(Debug, PartialEq)]
@@ -408,6 +413,10 @@ impl<'tcx> UniversalRegions<'tcx> {
408413
}
409414
}
410415
}
416+
417+
pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
418+
self.indices.tainted_by_errors.get()
419+
}
411420
}
412421

413422
struct UniversalRegionsBuilder<'cx, 'tcx> {
@@ -663,7 +672,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
663672
let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
664673
let arg_mapping = iter::zip(identity_args.regions(), fr_args.regions().map(|r| r.as_var()));
665674

666-
UniversalRegionIndices { indices: global_mapping.chain(arg_mapping).collect(), fr_static }
675+
UniversalRegionIndices {
676+
indices: global_mapping.chain(arg_mapping).collect(),
677+
fr_static,
678+
tainted_by_errors: Cell::new(None),
679+
}
667680
}
668681

669682
fn compute_inputs_and_output(
@@ -868,7 +881,8 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
868881
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
869882
if let ty::ReVar(..) = *r {
870883
r.as_var()
871-
} else if r.is_error() {
884+
} else if let ty::ReError(guar) = *r {
885+
self.tainted_by_errors.set(Some(guar));
872886
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
873887
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
874888
// errors are being emitted and 2) it leaves the happy path unaffected.

Diff for: compiler/rustc_hir_analysis/src/collect/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
502502
bug!("unexpected sort of node in type_of(): {:?}", x);
503503
}
504504
};
505-
if let Err(e) = icx.check_tainted_by_errors() {
505+
if let Err(e) = icx.check_tainted_by_errors()
506+
&& !output.references_error()
507+
{
506508
ty::EarlyBinder::bind(Ty::new_error(tcx, e))
507509
} else {
508510
ty::EarlyBinder::bind(output)

Diff for: tests/rustdoc-ui/unable-fulfill-trait.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// This test ensures that it's not crashing rustdoc.
22

33
pub struct Foo<'a, 'b, T> {
4-
field1: dyn Bar<'a, 'b,>,
4+
field1: dyn Bar<'a, 'b>,
55
//~^ ERROR
66
//~| ERROR
7+
//~| ERROR
78
}
89

910
pub trait Bar<'x, 's, U>
10-
where U: 'x,
11-
Self:'x,
12-
Self:'s
13-
{}
11+
where
12+
U: 'x,
13+
Self: 'x,
14+
Self: 's,
15+
{
16+
}

Diff for: tests/rustdoc-ui/unable-fulfill-trait.stderr

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
11
error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
22
--> $DIR/unable-fulfill-trait.rs:4:17
33
|
4-
LL | field1: dyn Bar<'a, 'b,>,
4+
LL | field1: dyn Bar<'a, 'b>,
55
| ^^^ expected 1 generic argument
66
|
77
note: trait defined here, with 1 generic parameter: `U`
8-
--> $DIR/unable-fulfill-trait.rs:9:11
8+
--> $DIR/unable-fulfill-trait.rs:10:11
99
|
1010
LL | pub trait Bar<'x, 's, U>
1111
| ^^^ -
1212
help: add missing generic argument
1313
|
14-
LL | field1: dyn Bar<'a, 'b, U,>,
14+
LL | field1: dyn Bar<'a, 'b, U>,
1515
| +++
1616

1717
error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
1818
--> $DIR/unable-fulfill-trait.rs:4:13
1919
|
20-
LL | field1: dyn Bar<'a, 'b,>,
21-
| ^^^^^^^^^^^^^^^^
20+
LL | field1: dyn Bar<'a, 'b>,
21+
| ^^^^^^^^^^^^^^^
2222

23-
error: aborting due to 2 previous errors
23+
error[E0478]: lifetime bound not satisfied
24+
--> $DIR/unable-fulfill-trait.rs:4:13
25+
|
26+
LL | field1: dyn Bar<'a, 'b>,
27+
| ^^^^^^^^^^^^^^^
28+
|
29+
note: lifetime parameter instantiated with the lifetime `'b` as defined here
30+
--> $DIR/unable-fulfill-trait.rs:3:20
31+
|
32+
LL | pub struct Foo<'a, 'b, T> {
33+
| ^^
34+
note: but lifetime parameter must outlive the lifetime `'a` as defined here
35+
--> $DIR/unable-fulfill-trait.rs:3:16
36+
|
37+
LL | pub struct Foo<'a, 'b, T> {
38+
| ^^
39+
40+
error: aborting due to 3 previous errors
2441

25-
Some errors have detailed explanations: E0107, E0227.
42+
Some errors have detailed explanations: E0107, E0227, E0478.
2643
For more information about an error, try `rustc --explain E0107`.

Diff for: tests/ui/associated-inherent-types/issue-109071.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<T> Windows { //~ ERROR: missing generics for struct `Windows`
1313

1414
impl<T> Windows<T> {
1515
fn T() -> Option<Self::Item> {}
16-
//~^ ERROR: ambiguous associated type
16+
//[no_gate]~^ ERROR: ambiguous associated type
1717
}
1818

1919
fn main() {}

Diff for: tests/ui/associated-inherent-types/issue-109071.with_gate.stderr

+2-15
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,7 @@ help: add missing generic argument
2020
LL | impl<T> Windows<T> {
2121
| +++
2222

23-
error[E0223]: ambiguous associated type
24-
--> $DIR/issue-109071.rs:15:22
25-
|
26-
LL | fn T() -> Option<Self::Item> {}
27-
| ^^^^^^^^^^
28-
|
29-
help: use fully-qualified syntax
30-
|
31-
LL | fn T() -> Option<<Windows<T> as IntoAsyncIterator>::Item> {}
32-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33-
LL | fn T() -> Option<<Windows<T> as IntoIterator>::Item> {}
34-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35-
36-
error: aborting due to 3 previous errors
23+
error: aborting due to 2 previous errors
3724

38-
Some errors have detailed explanations: E0107, E0223, E0637.
25+
Some errors have detailed explanations: E0107, E0637.
3926
For more information about an error, try `rustc --explain E0107`.

Diff for: tests/ui/associated-inherent-types/issue-109299.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ impl Lexer<'d> { //~ ERROR use of undeclared lifetime name `'d`
88
}
99

1010
fn test(_: Lexer::Cursor) {}
11-
//~^ ERROR: lifetime may not live long enough
1211

1312
fn main() {}

Diff for: tests/ui/associated-inherent-types/issue-109299.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ LL | impl Lexer<'d> {
66
| |
77
| help: consider introducing lifetime `'d` here: `<'d>`
88

9-
error: lifetime may not live long enough
10-
--> $DIR/issue-109299.rs:10:1
11-
|
12-
LL | fn test(_: Lexer::Cursor) {}
13-
| ^^^^^^^^-^^^^^^^^^^^^^^^^
14-
| | |
15-
| | has type `Lexer<'1>::Cursor`
16-
| requires that `'1` must outlive `'static`
17-
18-
error: aborting due to 2 previous errors
9+
error: aborting due to 1 previous error
1910

2011
For more information about this error, try `rustc --explain E0261`.

Diff for: tests/ui/borrowck/generic_const_early_param.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ struct DataWrapper<'static> {
55
//~^ ERROR invalid lifetime parameter name: `'static`
66
data: &'a [u8; Self::SIZE],
77
//~^ ERROR use of undeclared lifetime name `'a`
8-
//~^^ ERROR lifetime may not live long enough
98
}
109

1110
impl DataWrapper<'a> {

Diff for: tests/ui/borrowck/generic_const_early_param.stderr

+2-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | data: &'a [u8; Self::SIZE],
1414
| ^^ undeclared lifetime
1515

1616
error[E0261]: use of undeclared lifetime name `'a`
17-
--> $DIR/generic_const_early_param.rs:11:18
17+
--> $DIR/generic_const_early_param.rs:10:18
1818
|
1919
LL | impl DataWrapper<'a> {
2020
| - ^^ undeclared lifetime
@@ -30,13 +30,7 @@ LL | #![feature(generic_const_exprs)]
3030
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
3131
= note: `#[warn(incomplete_features)]` on by default
3232

33-
error: lifetime may not live long enough
34-
--> $DIR/generic_const_early_param.rs:6:20
35-
|
36-
LL | data: &'a [u8; Self::SIZE],
37-
| ^^^^^^^^^^ requires that `'_` must outlive `'static`
38-
39-
error: aborting due to 4 previous errors; 1 warning emitted
33+
error: aborting due to 3 previous errors; 1 warning emitted
4034

4135
Some errors have detailed explanations: E0261, E0262.
4236
For more information about an error, try `rustc --explain E0261`.

Diff for: tests/ui/const-generics/issues/issue-71381.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
77
= note: type parameters may not be used in the type of const parameters
88

99
error[E0770]: the type of const parameters must not depend on other generic parameters
10-
--> $DIR/issue-71381.rs:22:40
10+
--> $DIR/issue-71381.rs:23:40
1111
|
1212
LL | const FN: unsafe extern "C" fn(Args),
1313
| ^^^^ the type must not depend on the parameter `Args`

Diff for: tests/ui/const-generics/issues/issue-71381.min.stderr

+18-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@ LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "
77
= note: type parameters may not be used in the type of const parameters
88

99
error[E0770]: the type of const parameters must not depend on other generic parameters
10-
--> $DIR/issue-71381.rs:22:40
10+
--> $DIR/issue-71381.rs:23:40
1111
|
1212
LL | const FN: unsafe extern "C" fn(Args),
1313
| ^^^^ the type must not depend on the parameter `Args`
1414
|
1515
= note: type parameters may not be used in the type of const parameters
1616

17-
error: aborting due to 2 previous errors
17+
error: using function pointers as const generic parameters is forbidden
18+
--> $DIR/issue-71381.rs:14:61
19+
|
20+
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
|
23+
= note: the only supported types are integers, `bool` and `char`
24+
25+
error: using function pointers as const generic parameters is forbidden
26+
--> $DIR/issue-71381.rs:23:19
27+
|
28+
LL | const FN: unsafe extern "C" fn(Args),
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: the only supported types are integers, `bool` and `char`
32+
33+
error: aborting due to 4 previous errors
1834

1935
For more information about this error, try `rustc --explain E0770`.

Diff for: tests/ui/const-generics/issues/issue-71381.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ unsafe extern "C" fn pass(args: PassArg) {
1313
impl Test {
1414
pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
1515
//~^ ERROR: the type of const parameters must not depend on other generic parameters
16+
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
1617
self.0 = Self::trampiline::<Args, IDX, FN> as _
1718
}
1819

@@ -21,6 +22,7 @@ impl Test {
2122
const IDX: usize,
2223
const FN: unsafe extern "C" fn(Args),
2324
//~^ ERROR: the type of const parameters must not depend on other generic parameters
25+
//[min]~^^ ERROR: using function pointers as const generic parameters is forbidden
2426
>(
2527
args: Args,
2628
) {

Diff for: tests/ui/const-generics/issues/issue-71611.min.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ LL | fn func<A, const F: fn(inner: A)>(outer: A) {
66
|
77
= note: type parameters may not be used in the type of const parameters
88

9-
error: aborting due to 1 previous error
9+
error: using function pointers as const generic parameters is forbidden
10+
--> $DIR/issue-71611.rs:5:21
11+
|
12+
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
13+
| ^^^^^^^^^^^^
14+
|
15+
= note: the only supported types are integers, `bool` and `char`
16+
17+
error: aborting due to 2 previous errors
1018

1119
For more information about this error, try `rustc --explain E0770`.

Diff for: tests/ui/const-generics/issues/issue-71611.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
fn func<A, const F: fn(inner: A)>(outer: A) {
66
//~^ ERROR: the type of const parameters must not depend on other generic parameters
7+
//[min]~| ERROR: using function pointers as const generic parameters is forbidden
78
F(outer);
89
}
910

Diff for: tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ impl Opcode2 {
1313
pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) {
1414
move |i| match msg_type {
1515
Opcode2::OP2 => unimplemented!(),
16+
//~^ ERROR: could not evaluate constant pattern
1617
}
1718
}
1819

Diff for: tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ help: you might be missing a type parameter
1717
LL | pub struct Opcode2<S>(&'a S);
1818
| +++
1919

20-
error: aborting due to 2 previous errors
20+
error: could not evaluate constant pattern
21+
--> $DIR/ice-type-mismatch-when-copying-112824.rs:15:9
22+
|
23+
LL | Opcode2::OP2 => unimplemented!(),
24+
| ^^^^^^^^^^^^
25+
26+
error: aborting due to 3 previous errors
2127

2228
Some errors have detailed explanations: E0261, E0412.
2329
For more information about an error, try `rustc --explain E0261`.

Diff for: tests/ui/generic-associated-types/gat-trait-path-missing-lifetime.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ impl<T> X for T { //~ ERROR: not all trait items implemented
99
//~^ ERROR missing generics for associated type
1010
//~^^ ERROR missing generics for associated type
1111
//~| ERROR method `foo` has 1 type parameter but its trait declaration has 0 type parameters
12-
//~| ERROR may not live long enough
1312
t
1413
}
1514
}

Diff for: tests/ui/generic-associated-types/gat-trait-path-missing-lifetime.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,7 @@ help: add missing lifetime argument
5151
LL | fn foo<'a, T1: X<Y<'a> = T1>>(t : T1) -> T1::Y<'a> {
5252
| ++++
5353

54-
error: lifetime may not live long enough
55-
--> $DIR/gat-trait-path-missing-lifetime.rs:8:3
56-
|
57-
LL | fn foo<'a, T1: X<Y = T1>>(t : T1) -> T1::Y<'a> {
58-
| ^^^^^^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59-
| | |
60-
| | lifetime `'a` defined here
61-
| requires that `'a` must outlive `'static`
62-
63-
error: aborting due to 5 previous errors
54+
error: aborting due to 4 previous errors
6455

6556
Some errors have detailed explanations: E0046, E0049, E0107.
6657
For more information about an error, try `rustc --explain E0046`.

Diff for: tests/ui/generic-associated-types/issue-70304.rs

-1
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,4 @@ fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
5252
pub fn main() {
5353
let doc = create_doc();
5454
let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
55-
//~^ ERROR: `doc` does not live long enough
5655
}

0 commit comments

Comments
 (0)