mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Auto merge of #11258 - Jarcho:ice_11256, r=Centri3
Resolve type aliases in `type_certainty` Fixes #11256 changelog: `unwrap_or_default`: Fix ICE when local types are declared using alias types
This commit is contained in:
commit
c0bdb3d337
4 changed files with 23 additions and 4 deletions
|
@ -12,7 +12,7 @@
|
|||
//! be considered a bug.
|
||||
|
||||
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::intravisit::{walk_qpath, walk_ty, Visitor};
|
||||
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.
|
||||
let certainty = lhs.join_clearing_def_ids(rhs);
|
||||
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 {
|
||||
certainty
|
||||
}
|
||||
|
|
|
@ -109,6 +109,10 @@ fn type_certainty(option: Option<Vec<u64>>) {
|
|||
// should not be changed: no type annotation, unconcretized initializer
|
||||
let option = None;
|
||||
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() {
|
||||
|
|
|
@ -109,6 +109,10 @@ fn type_certainty(option: Option<Vec<u64>>) {
|
|||
// should not be changed: no type annotation, unconcretized initializer
|
||||
let option = None;
|
||||
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() {
|
||||
|
|
|
@ -84,11 +84,17 @@ error: use of `unwrap_or_else` to construct default value
|
|||
LL | option.unwrap_or_else(Vec::new).push(1);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ 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
|
||||
--> $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);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `or_default()`
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue