Skip to content

Commit 671d10e

Browse files
committed
Taint more aggressively in astconv
1 parent 4140509 commit 671d10e

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
.span_label_mv(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
@@ -972,7 +972,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
972972
}
973973
}
974974
}
975-
err.emit()
975+
let reported = err.emit();
976+
self.set_tainted_by_errors(reported);
977+
reported
976978
}
977979

978980
// Search for a bound on a type parameter which includes the associated item
@@ -1049,6 +1051,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10491051
span,
10501052
binding,
10511053
);
1054+
self.set_tainted_by_errors(reported);
10521055
return Err(reported);
10531056
};
10541057
debug!(?bound);
@@ -1126,6 +1129,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11261129
));
11271130
}
11281131
let reported = err.emit();
1132+
self.set_tainted_by_errors(reported);
11291133
if !where_bounds.is_empty() {
11301134
return Err(reported);
11311135
}
@@ -1380,6 +1384,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13801384
assoc_ident.name,
13811385
)
13821386
};
1387+
self.set_tainted_by_errors(reported);
13831388
return Err(reported);
13841389
}
13851390
};
@@ -1622,12 +1627,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16221627
let kind = tcx.def_kind_descr(kind, item);
16231628
let msg = format!("{kind} `{name}` is private");
16241629
let def_span = tcx.def_span(item);
1625-
tcx.dcx()
1630+
let reported = tcx
1631+
.dcx()
16261632
.struct_span_err(span, msg)
16271633
.code_mv(rustc_errors::error_code!(E0624))
16281634
.span_label_mv(span, format!("private {kind}"))
16291635
.span_label_mv(def_span, format!("{kind} defined here"))
16301636
.emit();
1637+
self.set_tainted_by_errors(reported);
16311638
}
16321639
tcx.check_stability(item, Some(block), span, None);
16331640
}
@@ -1868,7 +1875,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18681875
err.span_label(span, format!("not allowed on {what}"));
18691876
}
18701877
extend(&mut err);
1871-
err.emit();
1878+
self.set_tainted_by_errors(err.emit());
18721879
emitted = true;
18731880
}
18741881

@@ -2190,7 +2197,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
21902197
{
21912198
err.span_note(impl_.self_ty.span, "not a concrete type");
21922199
}
2193-
Ty::new_error(tcx, err.emit())
2200+
let reported = err.emit();
2201+
self.set_tainted_by_errors(reported);
2202+
Ty::new_error(tcx, reported)
21942203
} else {
21952204
ty
21962205
}
@@ -2592,7 +2601,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25922601
);
25932602
}
25942603

2595-
diag.emit();
2604+
self.set_tainted_by_errors(diag.emit());
25962605
}
25972606

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

2695-
err.emit();
2704+
self.set_tainted_by_errors(err.emit());
26962705
}
26972706
}
26982707

@@ -2731,7 +2740,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27312740
// error.
27322741
let r = derived_region_bounds[0];
27332742
if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
2734-
tcx.dcx().emit_err(AmbiguousLifetimeBound { span });
2743+
self.set_tainted_by_errors(tcx.dcx().emit_err(AmbiguousLifetimeBound { span }));
27352744
}
27362745
Some(r)
27372746
}

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_err!(
294+
let reported = struct_span_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)