Rely in resolve and not on path name for &str
-> String
suggestion
This commit is contained in:
parent
bb9d720a16
commit
02bea16c08
@ -3105,15 +3105,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
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 @ Path { segments, .. }) = &ty.kind
|
if let TyKind::Path(None, path) = &ty.kind {
|
||||||
&& segments.len() == 1
|
|
||||||
{
|
|
||||||
if segments[0].ident.name == sym::str {
|
|
||||||
// Don't suggest `-> str`, suggest `-> String`.
|
|
||||||
sugg = vec![
|
|
||||||
(lt.span.with_hi(ty.span.hi()), "String".to_string()),
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
// Check if the path being borrowed is likely to be owned.
|
// Check if the path being borrowed is likely to be owned.
|
||||||
let path: Vec<_> = Segment::from_path(path);
|
let path: Vec<_> = Segment::from_path(path);
|
||||||
match self.resolve_path(&path, Some(TypeNS), None) {
|
match self.resolve_path(&path, Some(TypeNS), None) {
|
||||||
@ -3121,6 +3113,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
ModuleOrUniformRoot::Module(module),
|
ModuleOrUniformRoot::Module(module),
|
||||||
) => {
|
) => {
|
||||||
match module.res() {
|
match module.res() {
|
||||||
|
Some(Res::PrimTy(PrimTy::Str)) => {
|
||||||
|
// Don't suggest `-> str`, suggest `-> String`.
|
||||||
|
sugg = vec![(
|
||||||
|
lt.span.with_hi(ty.span.hi()),
|
||||||
|
"String".to_string(),
|
||||||
|
)];
|
||||||
|
}
|
||||||
Some(Res::PrimTy(..)) => {}
|
Some(Res::PrimTy(..)) => {}
|
||||||
Some(Res::Def(
|
Some(Res::Def(
|
||||||
DefKind::Struct
|
DefKind::Struct
|
||||||
@ -3139,6 +3138,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
}
|
}
|
||||||
PathResult::NonModule(res) => {
|
PathResult::NonModule(res) => {
|
||||||
match res.base_res() {
|
match res.base_res() {
|
||||||
|
Res::PrimTy(PrimTy::Str) => {
|
||||||
|
// Don't suggest `-> str`, suggest `-> String`.
|
||||||
|
sugg = vec![(
|
||||||
|
lt.span.with_hi(ty.span.hi()),
|
||||||
|
"String".to_string(),
|
||||||
|
)];
|
||||||
|
}
|
||||||
Res::PrimTy(..) => {}
|
Res::PrimTy(..) => {}
|
||||||
Res::Def(
|
Res::Def(
|
||||||
DefKind::Struct
|
DefKind::Struct
|
||||||
@ -3160,7 +3166,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let TyKind::Slice(inner_ty) = &ty.kind {
|
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![
|
||||||
|
Loading…
x
Reference in New Issue
Block a user