1
Fork 0

Taint more aggressively in astconv

This commit is contained in:
Oli Scherer 2024-01-10 14:58:03 +00:00
parent af7f8f9811
commit 55cab535e7
14 changed files with 43 additions and 101 deletions

View file

@ -300,13 +300,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
.expect("missing associated item"); .expect("missing associated item");
if !assoc_item.visibility(tcx).is_accessible_from(def_scope, tcx) { if !assoc_item.visibility(tcx).is_accessible_from(def_scope, tcx) {
tcx.dcx() let reported = tcx
.dcx()
.struct_span_err( .struct_span_err(
binding.span, binding.span,
format!("{} `{}` is private", assoc_item.kind, binding.item_name), format!("{} `{}` is private", assoc_item.kind, binding.item_name),
) )
.with_span_label(binding.span, format!("private {}", assoc_item.kind)) .with_span_label(binding.span, format!("private {}", assoc_item.kind))
.emit(); .emit();
self.set_tainted_by_errors(reported);
} }
tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None); tcx.check_stability(assoc_item.def_id, Some(hir_ref_id), binding.span, None);

View file

@ -354,7 +354,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
); );
err.span_label(name.span, format!("multiple `{name}` found")); err.span_label(name.span, format!("multiple `{name}` found"));
self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span); self.note_ambiguous_inherent_assoc_type(&mut err, candidates, span);
err.emit() let reported = err.emit();
self.set_tainted_by_errors(reported);
reported
} }
// FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate. // FIXME(fmease): Heavily adapted from `rustc_hir_typeck::method::suggest`. Deduplicate.
@ -843,7 +845,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
} }
err.emit(); self.set_tainted_by_errors(err.emit());
} }
} }

View file

@ -973,7 +973,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} }
} }
} }
err.emit() let reported = err.emit();
self.set_tainted_by_errors(reported);
reported
} }
// Search for a bound on a type parameter which includes the associated item // Search for a bound on a type parameter which includes the associated item
@ -1050,6 +1052,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
span, span,
binding, binding,
); );
self.set_tainted_by_errors(reported);
return Err(reported); return Err(reported);
}; };
debug!(?bound); debug!(?bound);
@ -1127,6 +1130,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
)); ));
} }
let reported = err.emit(); let reported = err.emit();
self.set_tainted_by_errors(reported);
if !where_bounds.is_empty() { if !where_bounds.is_empty() {
return Err(reported); return Err(reported);
} }
@ -1381,6 +1385,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
assoc_ident.name, assoc_ident.name,
) )
}; };
self.set_tainted_by_errors(reported);
return Err(reported); return Err(reported);
} }
}; };
@ -1623,12 +1628,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let kind = tcx.def_kind_descr(kind, item); let kind = tcx.def_kind_descr(kind, item);
let msg = format!("{kind} `{name}` is private"); let msg = format!("{kind} `{name}` is private");
let def_span = tcx.def_span(item); let def_span = tcx.def_span(item);
tcx.dcx() let reported = tcx
.dcx()
.struct_span_err(span, msg) .struct_span_err(span, msg)
.with_code(rustc_errors::error_code!(E0624)) .with_code(rustc_errors::error_code!(E0624))
.with_span_label(span, format!("private {kind}")) .with_span_label(span, format!("private {kind}"))
.with_span_label(def_span, format!("{kind} defined here")) .with_span_label(def_span, format!("{kind} defined here"))
.emit(); .emit();
self.set_tainted_by_errors(reported);
} }
tcx.check_stability(item, Some(block), span, None); tcx.check_stability(item, Some(block), span, None);
} }
@ -1869,7 +1876,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.span_label(span, format!("not allowed on {what}")); err.span_label(span, format!("not allowed on {what}"));
} }
extend(&mut err); extend(&mut err);
err.emit(); self.set_tainted_by_errors(err.emit());
emitted = true; emitted = true;
} }
@ -2191,7 +2198,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
{ {
err.span_note(impl_.self_ty.span, "not a concrete type"); err.span_note(impl_.self_ty.span, "not a concrete type");
} }
Ty::new_error(tcx, err.emit()) let reported = err.emit();
self.set_tainted_by_errors(reported);
Ty::new_error(tcx, reported)
} else { } else {
ty ty
} }
@ -2593,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
); );
} }
diag.emit(); self.set_tainted_by_errors(diag.emit());
} }
// Find any late-bound regions declared in return type that do // Find any late-bound regions declared in return type that do
@ -2693,7 +2702,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
err.note("consider introducing a named lifetime parameter"); err.note("consider introducing a named lifetime parameter");
} }
err.emit(); self.set_tainted_by_errors(err.emit());
} }
} }
@ -2732,7 +2741,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// error. // error.
let r = derived_region_bounds[0]; let r = derived_region_bounds[0];
if derived_region_bounds[1..].iter().any(|r1| r != *r1) { if derived_region_bounds[1..].iter().any(|r1| r != *r1) {
tcx.dcx().emit_err(AmbiguousLifetimeBound { span }); self.set_tainted_by_errors(tcx.dcx().emit_err(AmbiguousLifetimeBound { span }));
} }
Some(r) Some(r)
} }

View file

@ -116,7 +116,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
for more information on them, visit \ for more information on them, visit \
<https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>", <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>",
); );
err.emit(); self.set_tainted_by_errors(err.emit());
} }
if regular_traits.is_empty() && auto_traits.is_empty() { if regular_traits.is_empty() && auto_traits.is_empty() {
@ -127,6 +127,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.map(|trait_ref| tcx.def_span(trait_ref)); .map(|trait_ref| tcx.def_span(trait_ref));
let reported = let reported =
tcx.dcx().emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span }); tcx.dcx().emit_err(TraitObjectDeclaredWithNoTraits { span, trait_alias_span });
self.set_tainted_by_errors(reported);
return Ty::new_error(tcx, reported); return Ty::new_error(tcx, reported);
} }
@ -290,7 +291,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if references_self { if references_self {
let def_id = i.bottom().0.def_id(); let def_id = i.bottom().0.def_id();
struct_span_code_err!( let reported = struct_span_code_err!(
tcx.dcx(), tcx.dcx(),
i.bottom().1, i.bottom().1,
E0038, E0038,
@ -303,6 +304,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.error_msg(), .error_msg(),
) )
.emit(); .emit();
self.set_tainted_by_errors(reported);
} }
ty::ExistentialTraitRef { def_id: trait_ref.def_id, args } ty::ExistentialTraitRef { def_id: trait_ref.def_id, args }
@ -389,6 +391,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else { } else {
err.emit() err.emit()
}; };
self.set_tainted_by_errors(e);
ty::Region::new_error(tcx, e) ty::Region::new_error(tcx, e)
}) })
} }

View file

@ -4,7 +4,6 @@ pub struct Foo<'a, 'b, T> {
field1: dyn Bar<'a, 'b,>, field1: dyn Bar<'a, 'b,>,
//~^ ERROR //~^ ERROR
//~| ERROR //~| ERROR
//~| ERROR
} }
pub trait Bar<'x, 's, U> pub trait Bar<'x, 's, U>

View file

@ -5,7 +5,7 @@ LL | field1: dyn Bar<'a, 'b,>,
| ^^^ expected 1 generic argument | ^^^ expected 1 generic argument
| |
note: trait defined here, with 1 generic parameter: `U` note: trait defined here, with 1 generic parameter: `U`
--> $DIR/unable-fulfill-trait.rs:10:11 --> $DIR/unable-fulfill-trait.rs:9:11
| |
LL | pub trait Bar<'x, 's, U> LL | pub trait Bar<'x, 's, U>
| ^^^ - | ^^^ -
@ -20,24 +20,7 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
LL | field1: dyn Bar<'a, 'b,>, LL | field1: dyn Bar<'a, 'b,>,
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error[E0478]: lifetime bound not satisfied error: aborting due to 2 previous errors
--> $DIR/unable-fulfill-trait.rs:4:13
|
LL | field1: dyn Bar<'a, 'b,>,
| ^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'b` as defined here
--> $DIR/unable-fulfill-trait.rs:3:20
|
LL | pub struct Foo<'a, 'b, T> {
| ^^
note: but lifetime parameter must outlive the lifetime `'a` as defined here
--> $DIR/unable-fulfill-trait.rs:3:16
|
LL | pub struct Foo<'a, 'b, T> {
| ^^
error: aborting due to 3 previous errors Some errors have detailed explanations: E0107, E0227.
Some errors have detailed explanations: E0107, E0227, E0478.
For more information about an error, try `rustc --explain E0107`. For more information about an error, try `rustc --explain E0107`.

View file

@ -7,7 +7,6 @@ trait Hierarchy {
type ChildKey; type ChildKey;
type Children = dyn Index<Self::ChildKey, Output = dyn Hierarchy>; type Children = dyn Index<Self::ChildKey, Output = dyn Hierarchy>;
//~^ ERROR: the value of the associated types //~^ ERROR: the value of the associated types
//~| ERROR: the size for values of type
fn data(&self) -> Option<(Self::Value, Self::Children)>; fn data(&self) -> Option<(Self::Value, Self::Children)>;
} }

View file

@ -1,5 +1,5 @@
error[E0191]: the value of the associated types `Value`, `ChildKey` and `Children` in `Hierarchy` must be specified error[E0191]: the value of the associated types `Value`, `ChildKey` and `Children` in `Hierarchy` must be specified
--> $DIR/issue-23595-1.rs:8:58 --> $DIR/issue-23595-1.rs:8:60
| |
LL | type Value; LL | type Value;
| ---------- `Value` defined here | ---------- `Value` defined here
@ -8,20 +8,6 @@ LL | type ChildKey;
LL | type Children = dyn Index<Self::ChildKey, Output = dyn Hierarchy>; LL | type Children = dyn Index<Self::ChildKey, Output = dyn Hierarchy>;
| ------------- `Children` defined here ^^^^^^^^^ help: specify the associated types: `Hierarchy<Value = Type, ChildKey = Type, Children = Type>` | ------------- `Children` defined here ^^^^^^^^^ help: specify the associated types: `Hierarchy<Value = Type, ChildKey = Type, Children = Type>`
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 error: aborting due to 1 previous error
--> $DIR/issue-23595-1.rs:8:21
|
LL | type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Index<<Self as Hierarchy>::ChildKey, Output = (dyn Hierarchy + 'static)> + 'static)`
note: required by a bound in `Hierarchy::Children`
--> $DIR/issue-23595-1.rs:8:5
|
LL | type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Hierarchy::Children`
error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0191`.
Some errors have detailed explanations: E0191, E0277.
For more information about an error, try `rustc --explain E0191`.

View file

@ -2,7 +2,6 @@ use std::fmt::Debug;
#[derive(Debug)] #[derive(Debug)]
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed on type parameter pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed on type parameter
//~^ ERROR `Irrelevant` must be used
irrelevant: Irrelevant, irrelevant: Irrelevant,
} }

View file

@ -16,16 +16,6 @@ LL | pub struct Irrelevant<Irrelevant> {
| ^^^^^^^^^^ | ^^^^^^^^^^
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0210]: type parameter `Irrelevant` must be used as the type parameter for some local type (e.g., `MyStruct<Irrelevant>`) error: aborting due to 1 previous error
--> $DIR/issue-97343.rs:4:23
|
LL | pub struct Irrelevant<Irrelevant> {
| ^^^^^^^^^^ type parameter `Irrelevant` must be used as the type parameter for some local type
|
= note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local
= note: only traits defined in the current crate can be implemented for a type parameter
error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0109`.
Some errors have detailed explanations: E0109, E0210.
For more information about an error, try `rustc --explain E0109`.

View file

@ -6,8 +6,6 @@ trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {}
struct Baz<'foo, 'bar> { struct Baz<'foo, 'bar> {
baz: dyn FooBar<'foo, 'bar>, baz: dyn FooBar<'foo, 'bar>,
//~^ ERROR ambiguous lifetime bound, explicit lifetime bound required //~^ ERROR ambiguous lifetime bound, explicit lifetime bound required
//~| ERROR lifetime bound not satisfied
} }
fn main() { fn main() {}
}

View file

@ -4,24 +4,6 @@ error[E0227]: ambiguous lifetime bound, explicit lifetime bound required
LL | baz: dyn FooBar<'foo, 'bar>, LL | baz: dyn FooBar<'foo, 'bar>,
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
error[E0478]: lifetime bound not satisfied error: aborting due to 1 previous error
--> $DIR/E0227.rs:7:10
|
LL | baz: dyn FooBar<'foo, 'bar>,
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: lifetime parameter instantiated with the lifetime `'bar` as defined here
--> $DIR/E0227.rs:6:18
|
LL | struct Baz<'foo, 'bar> {
| ^^^^
note: but lifetime parameter must outlive the lifetime `'foo` as defined here
--> $DIR/E0227.rs:6:12
|
LL | struct Baz<'foo, 'bar> {
| ^^^^
error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0227`.
Some errors have detailed explanations: E0227, E0478.
For more information about an error, try `rustc --explain E0227`.

View file

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

View file

@ -58,16 +58,7 @@ LL | fn d<const C: S>() {}
= note: the only supported types are integers, `bool` and `char` = note: the only supported types are integers, `bool` and `char`
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types = help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
error: `&dyn for<'a> Foo<'a>` is forbidden as the type of a const generic parameter error: aborting due to 8 previous errors
--> $DIR/unusual-rib-combinations.rs:29:21
|
LL | struct Bar<const N: &'a (dyn for<'a> Foo<'a>)>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0106, E0214, E0308, E0770. Some errors have detailed explanations: E0106, E0214, E0308, E0770.
For more information about an error, try `rustc --explain E0106`. For more information about an error, try `rustc --explain E0106`.