Skip to content

Commit 55cab53

Browse files
committed
Taint more aggressively in astconv
1 parent af7f8f9 commit 55cab53

File tree

14 files changed

+43
-101
lines changed

14 files changed

+43
-101
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
300300
.expect("missing associated item");
301301

302302
if !assoc_item.visibility(tcx).is_accessible_from(def_scope, tcx) {
303-
tcx.dcx()
303+
let reported = tcx
304+
.dcx()
304305
.struct_span_err(
305306
binding.span,
306307
format!("{} `{}` is private", assoc_item.kind, binding.item_name),
307308
)
308309
.with_span_label(binding.span, format!("private {}", assoc_item.kind))
309310
.emit();
311+
self.set_tainted_by_errors(reported);
310312
}
311313
tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None);
312314

compiler/rustc_hir_analysis/src/astconv/errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
354354
);
355355
err.span_label(name.span, format!("multiple `{name}` found"));
356356
self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span);
357-
err.emit()
357+
let reported = err.emit();
358+
self.set_tainted_by_errors(reported);
359+
reported
358360
}
359361

360362
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
@@ -843,7 +845,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
843845
}
844846
}
845847

846-
err.emit();
848+
self.set_tainted_by_errors(err.emit());
847849
}
848850
}
849851

compiler/rustc_hir_analysis/src/astconv/mod.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
973973
}
974974
}
975975
}
976-
err.emit()
976+
let reported = err.emit();
977+
self.set_tainted_by_errors(reported);
978+
reported
977979
}
978980

979981
// Search for a bound on a type parameter which includes the associated item
@@ -1050,6 +1052,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10501052
span,
10511053
binding,
10521054
);
1055+
self.set_tainted_by_errors(reported);
10531056
return Err(reported);
10541057
};
10551058
debug!(?bound);
@@ -1127,6 +1130,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11271130
));
11281131
}
11291132
let reported = err.emit();
1133+
self.set_tainted_by_errors(reported);
11301134
if !where_bounds.is_empty() {
11311135
return Err(reported);
11321136
}
@@ -1381,6 +1385,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13811385
assoc_ident.name,
13821386
)
13831387
};
1388+
self.set_tainted_by_errors(reported);
13841389
return Err(reported);
13851390
}
13861391
};
@@ -1623,12 +1628,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16231628
let kind = tcx.def_kind_descr(kind, item);
16241629
let msg = format!("{kind} `{name}` is private");
16251630
let def_span = tcx.def_span(item);
1626-
tcx.dcx()
1631+
let reported = tcx
1632+
.dcx()
16271633
.struct_span_err(span, msg)
16281634
.with_code(rustc_errors::error_code!(E0624))
16291635
.with_span_label(span, format!("private {kind}"))
16301636
.with_span_label(def_span, format!("{kind} defined here"))
16311637
.emit();
1638+
self.set_tainted_by_errors(reported);
16321639
}
16331640
tcx.check_stability(item, Some(block), span, None);
16341641
}
@@ -1869,7 +1876,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18691876
err.span_label(span, format!("not allowed on {what}"));
18701877
}
18711878
extend(&mut err);
1872-
err.emit();
1879+
self.set_tainted_by_errors(err.emit());
18731880
emitted = true;
18741881
}
18751882

@@ -2191,7 +2198,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21912198
{
21922199
err.span_note(impl_.self_ty.span, "not a concrete type");
21932200
}
2194-
Ty::new_error(tcx, err.emit())
2201+
let reported = err.emit();
2202+
self.set_tainted_by_errors(reported);
2203+
Ty::new_error(tcx, reported)
21952204
} else {
21962205
ty
21972206
}
@@ -2593,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25932602
);
25942603
}
25952604

2596-
diag.emit();
2605+
self.set_tainted_by_errors(diag.emit());
25972606
}
25982607

25992608
// Find any late-bound regions declared in return type that do
@@ -2693,7 +2702,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26932702
err.note("consider introducing a named lifetime parameter");
26942703
}
26952704

2696-
err.emit();
2705+
self.set_tainted_by_errors(err.emit());
26972706
}
26982707
}
26992708

@@ -2732,7 +2741,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27322741
// error.
27332742
let r = derived_region_bounds[0];
27342743
if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
2735-
tcx.dcx().emit_err(AmbiguousLifetimeBound { span });
2744+
self.set_tainted_by_errors(tcx.dcx().emit_err(AmbiguousLifetimeBound { span }));
27362745
}
27372746
Some(r)
27382747
}

compiler/rustc_hir_analysis/src/astconv/object_safety.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
116116
for more information on them, visit \
117117
<https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>",
118118
);
119-
err.emit();
119+
self.set_tainted_by_errors(err.emit());
120120
}
121121

122122
if regular_traits.is_empty() && auto_traits.is_empty() {
@@ -127,6 +127,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
127127
.map(|trait_ref| tcx.def_span(trait_ref));
128128
let reported =
129129
tcx.dcx().emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
130+
self.set_tainted_by_errors(reported);
130131
return Ty::new_error(tcx, reported);
131132
}
132133

@@ -290,7 +291,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
290291

291292
if references_self {
292293
let def_id = i.bottom().0.def_id();
293-
struct_span_code_err!(
294+
let reported = struct_span_code_err!(
294295
tcx.dcx(),
295296
i.bottom().1,
296297
E0038,
@@ -303,6 +304,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
303304
.error_msg(),
304305
)
305306
.emit();
307+
self.set_tainted_by_errors(reported);
306308
}
307309

308310
ty::ExistentialTraitRef { def_id: trait_ref.def_id, args }
@@ -389,6 +391,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
389391
} else {
390392
err.emit()
391393
};
394+
self.set_tainted_by_errors(e);
392395
ty::Region::new_error(tcx, e)
393396
})
394397
}

tests/rustdoc-ui/unable-fulfill-trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub struct Foo<'a, 'b, T> {
44
field1: dyn Bar<'a, 'b,>,
55
//~^ ERROR
66
//~| ERROR
7-
//~| ERROR
87
}
98

109
pub trait Bar<'x, 's, U>

tests/rustdoc-ui/unable-fulfill-trait.stderr

+3-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ 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:10:11
8+
--> $DIR/unable-fulfill-trait.rs:9:11
99
|
1010
LL | pub trait Bar<'x, 's, U>
1111
| ^^^ -
@@ -20,24 +20,7 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
2020
LL | field1: dyn Bar<'a, 'b,>,
2121
| ^^^^^^^^^^^^^^^^
2222

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
23+
error: aborting due to 2 previous errors
4124

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

tests/ui/associated-types/issue-23595-1.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use std::ops::Index;
55
trait Hierarchy {
66
type Value;
77
type ChildKey;
8-
type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
8+
type Children = dyn Index<Self::ChildKey, Output = dyn Hierarchy>;
99
//~^ ERROR: the value of the associated types
10-
//~| ERROR: the size for values of type
1110

1211
fn data(&self) -> Option<(Self::Value, Self::Children)>;
1312
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
error[E0191]: the value of the associated types `Value`, `ChildKey` and `Children` in `Hierarchy` must be specified
2-
--> $DIR/issue-23595-1.rs:8:58
2+
--> $DIR/issue-23595-1.rs:8:60
33
|
44
LL | type Value;
55
| ---------- `Value` defined here
66
LL | type ChildKey;
77
| ------------- `ChildKey` defined here
8-
LL | type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
9-
| ------------- `Children` defined here ^^^^^^^^^ help: specify the associated types: `Hierarchy<Value = Type, ChildKey = Type, Children = Type>`
8+
LL | type Children = dyn Index<Self::ChildKey, Output = dyn Hierarchy>;
9+
| ------------- `Children` defined here ^^^^^^^^^ help: specify the associated types: `Hierarchy<Value = Type, ChildKey = Type, Children = Type>`
1010

11-
error[E0277]: the size for values of type `(dyn Index<<Self as Hierarchy>::ChildKey, Output = (dyn Hierarchy + 'static)> + 'static)` cannot be known at compilation time
12-
--> $DIR/issue-23595-1.rs:8:21
13-
|
14-
LL | type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
16-
|
17-
= help: the trait `Sized` is not implemented for `(dyn Index<<Self as Hierarchy>::ChildKey, Output = (dyn Hierarchy + 'static)> + 'static)`
18-
note: required by a bound in `Hierarchy::Children`
19-
--> $DIR/issue-23595-1.rs:8:5
20-
|
21-
LL | type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Hierarchy::Children`
23-
24-
error: aborting due to 2 previous errors
11+
error: aborting due to 1 previous error
2512

26-
Some errors have detailed explanations: E0191, E0277.
27-
For more information about an error, try `rustc --explain E0191`.
13+
For more information about this error, try `rustc --explain E0191`.

tests/ui/derives/issue-97343.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fmt::Debug;
22

33
#[derive(Debug)]
44
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed on type parameter
5-
//~^ ERROR `Irrelevant` must be used
65
irrelevant: Irrelevant,
76
}
87

tests/ui/derives/issue-97343.stderr

+2-12
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ LL | pub struct Irrelevant<Irrelevant> {
1616
| ^^^^^^^^^^
1717
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
1818

19-
error[E0210]: type parameter `Irrelevant` must be used as the type parameter for some local type (e.g., `MyStruct<Irrelevant>`)
20-
--> $DIR/issue-97343.rs:4:23
21-
|
22-
LL | pub struct Irrelevant<Irrelevant> {
23-
| ^^^^^^^^^^ type parameter `Irrelevant` must be used as the type parameter for some local type
24-
|
25-
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
26-
= note: only traits defined in the current crate can be implemented for a type parameter
27-
28-
error: aborting due to 2 previous errors
19+
error: aborting due to 1 previous error
2920

30-
Some errors have detailed explanations: E0109, E0210.
31-
For more information about an error, try `rustc --explain E0109`.
21+
For more information about this error, try `rustc --explain E0109`.

tests/ui/error-codes/E0227.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {}
66
struct Baz<'foo, 'bar> {
77
baz: dyn FooBar<'foo, 'bar>,
88
//~^ ERROR ambiguous lifetime bound, explicit lifetime bound required
9-
//~| ERROR lifetime bound not satisfied
109
}
1110

12-
fn main() {
13-
}
11+
fn main() {}

tests/ui/error-codes/E0227.stderr

+2-20
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
44
LL | baz: dyn FooBar<'foo, 'bar>,
55
| ^^^^^^^^^^^^^^^^^^^^^^
66

7-
error[E0478]: lifetime bound not satisfied
8-
--> $DIR/E0227.rs:7:10
9-
|
10-
LL | baz: dyn FooBar<'foo, 'bar>,
11-
| ^^^^^^^^^^^^^^^^^^^^^^
12-
|
13-
note: lifetime parameter instantiated with the lifetime `'bar` as defined here
14-
--> $DIR/E0227.rs:6:18
15-
|
16-
LL | struct Baz<'foo, 'bar> {
17-
| ^^^^
18-
note: but lifetime parameter must outlive the lifetime `'foo` as defined here
19-
--> $DIR/E0227.rs:6:12
20-
|
21-
LL | struct Baz<'foo, 'bar> {
22-
| ^^^^
23-
24-
error: aborting due to 2 previous errors
7+
error: aborting due to 1 previous error
258

26-
Some errors have detailed explanations: E0227, E0478.
27-
For more information about an error, try `rustc --explain E0227`.
9+
For more information about this error, try `rustc --explain E0227`.

tests/ui/lifetimes/unusual-rib-combinations.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ fn d<const C: S>() {}
2828
trait Foo<'a> {}
2929
struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
3030
//~^ ERROR the type of const parameters must not depend on other generic parameters
31-
//~| ERROR `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
3231

3332
fn main() {}

tests/ui/lifetimes/unusual-rib-combinations.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,7 @@ LL | fn d<const C: S>() {}
5858
= note: the only supported types are integers, `bool` and `char`
5959
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
6060

61-
error: `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter
62-
--> $DIR/unusual-rib-combinations.rs:29:21
63-
|
64-
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
65-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66-
|
67-
= note: the only supported types are integers, `bool` and `char`
68-
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
69-
70-
error: aborting due to 9 previous errors
61+
error: aborting due to 8 previous errors
7162

7263
Some errors have detailed explanations: E0106, E0214, E0308, E0770.
7364
For more information about an error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)