Do not consider traits as ownable in suggestion
This commit is contained in:
parent
85f26ade8d
commit
bb9d720a16
@ -3105,15 +3105,63 @@ fn add_missing_lifetime_specifiers_label(
|
|||||||
owned_sugg = true;
|
owned_sugg = true;
|
||||||
}
|
}
|
||||||
if let Some(ty) = lt_finder.found {
|
if let Some(ty) = lt_finder.found {
|
||||||
if let TyKind::Path(None, Path { segments, .. }) = &ty.kind
|
if let TyKind::Path(None, path @ Path { segments, .. }) = &ty.kind
|
||||||
&& segments.len() == 1
|
&& segments.len() == 1
|
||||||
&& segments[0].ident.name == sym::str
|
|
||||||
{
|
{
|
||||||
|
if segments[0].ident.name == sym::str {
|
||||||
// Don't suggest `-> str`, suggest `-> String`.
|
// Don't suggest `-> str`, suggest `-> String`.
|
||||||
sugg = vec![
|
sugg = vec![
|
||||||
(lt.span.with_hi(ty.span.hi()), "String".to_string()),
|
(lt.span.with_hi(ty.span.hi()), "String".to_string()),
|
||||||
];
|
];
|
||||||
} else if let TyKind::Slice(inner_ty) = &ty.kind {
|
} else {
|
||||||
|
// Check if the path being borrowed is likely to be owned.
|
||||||
|
let path: Vec<_> = Segment::from_path(path);
|
||||||
|
match self.resolve_path(&path, Some(TypeNS), None) {
|
||||||
|
PathResult::Module(
|
||||||
|
ModuleOrUniformRoot::Module(module),
|
||||||
|
) => {
|
||||||
|
match module.res() {
|
||||||
|
Some(Res::PrimTy(..)) => {}
|
||||||
|
Some(Res::Def(
|
||||||
|
DefKind::Struct
|
||||||
|
| DefKind::Union
|
||||||
|
| DefKind::Enum
|
||||||
|
| DefKind::ForeignTy
|
||||||
|
| DefKind::AssocTy
|
||||||
|
| DefKind::OpaqueTy
|
||||||
|
| DefKind::TyParam,
|
||||||
|
_,
|
||||||
|
)) => {}
|
||||||
|
_ => { // Do not suggest in all other cases.
|
||||||
|
owned_sugg = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PathResult::NonModule(res) => {
|
||||||
|
match res.base_res() {
|
||||||
|
Res::PrimTy(..) => {}
|
||||||
|
Res::Def(
|
||||||
|
DefKind::Struct
|
||||||
|
| DefKind::Union
|
||||||
|
| DefKind::Enum
|
||||||
|
| DefKind::ForeignTy
|
||||||
|
| DefKind::AssocTy
|
||||||
|
| DefKind::OpaqueTy
|
||||||
|
| DefKind::TyParam,
|
||||||
|
_,
|
||||||
|
) => {}
|
||||||
|
_ => { // Do not suggest in all other cases.
|
||||||
|
owned_sugg = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => { // Do not suggest in all other cases.
|
||||||
|
owned_sugg = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let TyKind::Slice(inner_ty) = &ty.kind {
|
||||||
// Don't suggest `-> [T]`, suggest `-> Vec<T>`.
|
// Don't suggest `-> [T]`, suggest `-> Vec<T>`.
|
||||||
sugg = vec![
|
sugg = vec![
|
||||||
(lt.span.with_hi(inner_ty.span.lo()), "Vec<".to_string()),
|
(lt.span.with_hi(inner_ty.span.lo()), "Vec<".to_string()),
|
||||||
|
@ -117,11 +117,6 @@ help: consider using the `'static` lifetime, but this is uncommon unless you're
|
|||||||
|
|
|
|
||||||
LL | static f: RefCell<HashMap<i32, Vec<Vec<&'static Tar<'static, i32>>>>> = RefCell::new(HashMap::new());
|
LL | static f: RefCell<HashMap<i32, Vec<Vec<&'static Tar<'static, i32>>>>> = RefCell::new(HashMap::new());
|
||||||
| +++++++
|
| +++++++
|
||||||
help: instead, you are more likely to want to return an owned value
|
|
||||||
|
|
|
||||||
LL - static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell::new(HashMap::new());
|
|
||||||
LL + static f: RefCell<HashMap<i32, Vec<Vec<Tar<'static, i32>>>>> = RefCell::new(HashMap::new());
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
error[E0106]: missing lifetime specifier
|
||||||
--> $DIR/missing-lifetime-specifier.rs:47:44
|
--> $DIR/missing-lifetime-specifier.rs:47:44
|
||||||
|
Loading…
Reference in New Issue
Block a user