Improve error messages for boxed trait objects in tuples
This commit is contained in:
parent
b613ef1436
commit
d066f19a79
3 changed files with 38 additions and 8 deletions
|
@ -145,8 +145,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
|||
match ty.sty {
|
||||
ty::Adt(..) if ty.is_box() => {
|
||||
let boxed_ty = ty.boxed_ty();
|
||||
let descr_pre_path = format!("{}boxed ", descr_pre_path);
|
||||
check_must_use_ty(cx, boxed_ty, expr, span, &descr_pre_path, descr_post_path)
|
||||
let descr_pre_path = &format!("{}boxed ", descr_pre_path);
|
||||
check_must_use_ty(cx, boxed_ty, expr, span, descr_pre_path, descr_post_path)
|
||||
}
|
||||
ty::Adt(def, _) => {
|
||||
check_must_use_def(cx, def.did, span, descr_pre_path, descr_post_path)
|
||||
|
@ -157,8 +157,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
|||
if let ty::Predicate::Trait(ref poly_trait_predicate) = predicate {
|
||||
let trait_ref = poly_trait_predicate.skip_binder().trait_ref;
|
||||
let def_id = trait_ref.def_id;
|
||||
let descr_pre = format!("{}implementer of ", descr_pre_path);
|
||||
if check_must_use_def(cx, def_id, span, &descr_pre, descr_post_path) {
|
||||
let descr_pre = &format!("{}implementer of ", descr_pre_path);
|
||||
if check_must_use_def(cx, def_id, span, descr_pre, descr_post_path) {
|
||||
has_emitted = true;
|
||||
break;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
|||
for predicate in binder.skip_binder().iter() {
|
||||
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate {
|
||||
let def_id = trait_ref.def_id;
|
||||
let descr_post = " trait object";
|
||||
let descr_post = &format!(" trait object{}", descr_post_path);
|
||||
if check_must_use_def(cx, def_id, span, descr_pre_path, descr_post) {
|
||||
has_emitted = true;
|
||||
break;
|
||||
|
|
|
@ -21,7 +21,19 @@ fn get_boxed_critical() -> Box<dyn Critical> {
|
|||
Box::new(Anon {})
|
||||
}
|
||||
|
||||
fn get_nested_boxed_critical() -> Box<Box<dyn Critical>> {
|
||||
Box::new(Box::new(Anon {}))
|
||||
}
|
||||
|
||||
fn get_critical_tuple() -> (u32, Box<dyn Critical>, impl Critical, ()) {
|
||||
(0, get_boxed_critical(), get_critical(), ())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
get_critical(); //~ ERROR unused implementer of `Critical` that must be used
|
||||
get_boxed_critical(); //~ ERROR unused boxed `Critical` trait object that must be used
|
||||
get_nested_boxed_critical();
|
||||
//~^ ERROR unused boxed boxed `Critical` trait object that must be used
|
||||
get_critical_tuple(); //~ ERROR unused boxed `Critical` trait object in tuple element 1
|
||||
//~^ ERROR unused implementer of `Critical` in tuple element 2
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: unused implementer of `Critical` that must be used
|
||||
--> $DIR/must_use-trait.rs:25:5
|
||||
--> $DIR/must_use-trait.rs:33:5
|
||||
|
|
||||
LL | get_critical();
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
@ -11,10 +11,28 @@ LL | #![deny(unused_must_use)]
|
|||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused boxed `Critical` trait object that must be used
|
||||
--> $DIR/must_use-trait.rs:26:5
|
||||
--> $DIR/must_use-trait.rs:34:5
|
||||
|
|
||||
LL | get_boxed_critical();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: unused boxed boxed `Critical` trait object that must be used
|
||||
--> $DIR/must_use-trait.rs:35:5
|
||||
|
|
||||
LL | get_nested_boxed_critical();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused boxed `Critical` trait object in tuple element 1 that must be used
|
||||
--> $DIR/must_use-trait.rs:37:5
|
||||
|
|
||||
LL | get_critical_tuple();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused implementer of `Critical` in tuple element 2 that must be used
|
||||
--> $DIR/must_use-trait.rs:37:5
|
||||
|
|
||||
LL | get_critical_tuple();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue