Resolve type aliases in type_certainty
This commit is contained in:
parent
4c2f460dcc
commit
caf601434b
@ -12,7 +12,7 @@
|
|||||||
//! be considered a bug.
|
//! be considered a bug.
|
||||||
|
|
||||||
use crate::def_path_res;
|
use crate::def_path_res;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_hir::intravisit::{walk_qpath, walk_ty, Visitor};
|
use rustc_hir::intravisit::{walk_qpath, walk_ty, Visitor};
|
||||||
use rustc_hir::{self as hir, Expr, ExprKind, GenericArgs, HirId, Node, PathSegment, QPath, TyKind};
|
use rustc_hir::{self as hir, Expr, ExprKind, GenericArgs, HirId, Node, PathSegment, QPath, TyKind};
|
||||||
@ -219,7 +219,12 @@ fn path_segment_certainty(
|
|||||||
// See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value.
|
// See the comment preceding `qpath_certainty`. `def_id` could refer to a type or a value.
|
||||||
let certainty = lhs.join_clearing_def_ids(rhs);
|
let certainty = lhs.join_clearing_def_ids(rhs);
|
||||||
if resolves_to_type {
|
if resolves_to_type {
|
||||||
certainty.with_def_id(def_id)
|
if cx.tcx.def_kind(def_id) == DefKind::TyAlias {
|
||||||
|
adt_def_id(cx.tcx.type_of(def_id).instantiate_identity())
|
||||||
|
.map_or(certainty, |def_id| certainty.with_def_id(def_id))
|
||||||
|
} else {
|
||||||
|
certainty.with_def_id(def_id)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
certainty
|
certainty
|
||||||
}
|
}
|
||||||
|
@ -109,6 +109,10 @@ fn type_certainty(option: Option<Vec<u64>>) {
|
|||||||
// should not be changed: no type annotation, unconcretized initializer
|
// should not be changed: no type annotation, unconcretized initializer
|
||||||
let option = None;
|
let option = None;
|
||||||
option.unwrap_or_else(Vec::new).push(1);
|
option.unwrap_or_else(Vec::new).push(1);
|
||||||
|
|
||||||
|
type Alias = Option<Vec<u32>>;
|
||||||
|
let option: Alias = Option::<Vec<u32>>::Some(Vec::new());
|
||||||
|
option.unwrap_or_default().push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn method_call_with_deref() {
|
fn method_call_with_deref() {
|
||||||
|
@ -109,6 +109,10 @@ fn type_certainty(option: Option<Vec<u64>>) {
|
|||||||
// should not be changed: no type annotation, unconcretized initializer
|
// should not be changed: no type annotation, unconcretized initializer
|
||||||
let option = None;
|
let option = None;
|
||||||
option.unwrap_or_else(Vec::new).push(1);
|
option.unwrap_or_else(Vec::new).push(1);
|
||||||
|
|
||||||
|
type Alias = Option<Vec<u32>>;
|
||||||
|
let option: Alias = Option::<Vec<u32>>::Some(Vec::new());
|
||||||
|
option.unwrap_or_else(Vec::new).push(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn method_call_with_deref() {
|
fn method_call_with_deref() {
|
||||||
|
@ -84,11 +84,17 @@ error: use of `unwrap_or_else` to construct default value
|
|||||||
LL | option.unwrap_or_else(Vec::new).push(1);
|
LL | option.unwrap_or_else(Vec::new).push(1);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
|
||||||
|
|
||||||
|
error: use of `unwrap_or_else` to construct default value
|
||||||
|
--> $DIR/unwrap_or_else_default.rs:115:12
|
||||||
|
|
|
||||||
|
LL | option.unwrap_or_else(Vec::new).push(1);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
|
||||||
|
|
||||||
error: use of `or_insert_with` to construct default value
|
error: use of `or_insert_with` to construct default value
|
||||||
--> $DIR/unwrap_or_else_default.rs:128:32
|
--> $DIR/unwrap_or_else_default.rs:132:32
|
||||||
|
|
|
|
||||||
LL | let _ = inner_map.entry(0).or_insert_with(Default::default);
|
LL | let _ = inner_map.entry(0).or_insert_with(Default::default);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
|
||||||
|
|
||||||
error: aborting due to 15 previous errors
|
error: aborting due to 16 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user