Rollup merge of #80628 - matthiaskrgr:match_ref_pats, r=varkor
reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats)
This commit is contained in:
commit
ff1f21a8fd
28 changed files with 89 additions and 91 deletions
|
@ -433,9 +433,9 @@ pub enum WherePredicate {
|
||||||
impl WherePredicate {
|
impl WherePredicate {
|
||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
&WherePredicate::BoundPredicate(ref p) => p.span,
|
WherePredicate::BoundPredicate(p) => p.span,
|
||||||
&WherePredicate::RegionPredicate(ref p) => p.span,
|
WherePredicate::RegionPredicate(p) => p.span,
|
||||||
&WherePredicate::EqPredicate(ref p) => p.span,
|
WherePredicate::EqPredicate(p) => p.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1212,11 +1212,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_pat(&mut self, pat: &'a Pat) {
|
fn visit_pat(&mut self, pat: &'a Pat) {
|
||||||
match pat.kind {
|
match &pat.kind {
|
||||||
PatKind::Lit(ref expr) => {
|
PatKind::Lit(expr) => {
|
||||||
self.check_expr_within_pat(expr, false);
|
self.check_expr_within_pat(expr, false);
|
||||||
}
|
}
|
||||||
PatKind::Range(ref start, ref end, _) => {
|
PatKind::Range(start, end, _) => {
|
||||||
if let Some(expr) = start {
|
if let Some(expr) = start {
|
||||||
self.check_expr_within_pat(expr, true);
|
self.check_expr_within_pat(expr, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ pub fn expand_deriving_hash(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P<Expr> {
|
fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P<Expr> {
|
||||||
let state_expr = match &substr.nonself_args {
|
let state_expr = match substr.nonself_args {
|
||||||
&[o_f] => o_f,
|
[o_f] => o_f,
|
||||||
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`"),
|
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`"),
|
||||||
};
|
};
|
||||||
let call_hash = |span, thing_expr| {
|
let call_hash = |span, thing_expr| {
|
||||||
|
@ -64,9 +64,9 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu
|
||||||
};
|
};
|
||||||
let mut stmts = Vec::new();
|
let mut stmts = Vec::new();
|
||||||
|
|
||||||
let fields = match *substr.fields {
|
let fields = match substr.fields {
|
||||||
Struct(_, ref fs) | EnumMatching(_, 1, .., ref fs) => fs,
|
Struct(_, fs) | EnumMatching(_, 1, .., fs) => fs,
|
||||||
EnumMatching(.., ref fs) => {
|
EnumMatching(.., fs) => {
|
||||||
let variant_value = deriving::call_intrinsic(
|
let variant_value = deriving::call_intrinsic(
|
||||||
cx,
|
cx,
|
||||||
trait_span,
|
trait_span,
|
||||||
|
|
|
@ -378,9 +378,9 @@ impl GenericBound<'_> {
|
||||||
|
|
||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
&GenericBound::Trait(ref t, ..) => t.span,
|
GenericBound::Trait(t, ..) => t.span,
|
||||||
&GenericBound::LangItemTrait(_, span, ..) => span,
|
GenericBound::LangItemTrait(_, span, ..) => *span,
|
||||||
&GenericBound::Outlives(ref l) => l.span,
|
GenericBound::Outlives(l) => l.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,9 +538,9 @@ pub enum WherePredicate<'hir> {
|
||||||
impl WherePredicate<'_> {
|
impl WherePredicate<'_> {
|
||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
&WherePredicate::BoundPredicate(ref p) => p.span,
|
WherePredicate::BoundPredicate(p) => p.span,
|
||||||
&WherePredicate::RegionPredicate(ref p) => p.span,
|
WherePredicate::RegionPredicate(p) => p.span,
|
||||||
&WherePredicate::EqPredicate(ref p) => p.span,
|
WherePredicate::EqPredicate(p) => p.span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -896,8 +896,8 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
predicate: &'v WherePredicate<'v>,
|
predicate: &'v WherePredicate<'v>,
|
||||||
) {
|
) {
|
||||||
match predicate {
|
match *predicate {
|
||||||
&WherePredicate::BoundPredicate(WhereBoundPredicate {
|
WherePredicate::BoundPredicate(WhereBoundPredicate {
|
||||||
ref bounded_ty,
|
ref bounded_ty,
|
||||||
bounds,
|
bounds,
|
||||||
bound_generic_params,
|
bound_generic_params,
|
||||||
|
@ -907,11 +907,11 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
|
||||||
walk_list!(visitor, visit_param_bound, bounds);
|
walk_list!(visitor, visit_param_bound, bounds);
|
||||||
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
||||||
}
|
}
|
||||||
&WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
|
WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
|
||||||
visitor.visit_lifetime(lifetime);
|
visitor.visit_lifetime(lifetime);
|
||||||
walk_list!(visitor, visit_param_bound, bounds);
|
walk_list!(visitor, visit_param_bound, bounds);
|
||||||
}
|
}
|
||||||
&WherePredicate::EqPredicate(WhereEqPredicate {
|
WherePredicate::EqPredicate(WhereEqPredicate {
|
||||||
hir_id, ref lhs_ty, ref rhs_ty, ..
|
hir_id, ref lhs_ty, ref rhs_ty, ..
|
||||||
}) => {
|
}) => {
|
||||||
visitor.visit_id(hir_id);
|
visitor.visit_id(hir_id);
|
||||||
|
|
|
@ -2233,19 +2233,19 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
match predicate {
|
match predicate {
|
||||||
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
|
hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
|
||||||
ref bound_generic_params,
|
bound_generic_params,
|
||||||
ref bounded_ty,
|
bounded_ty,
|
||||||
bounds,
|
bounds,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
self.print_formal_generic_params(bound_generic_params);
|
self.print_formal_generic_params(bound_generic_params);
|
||||||
self.print_type(&bounded_ty);
|
self.print_type(&bounded_ty);
|
||||||
self.print_bounds(":", bounds);
|
self.print_bounds(":", *bounds);
|
||||||
}
|
}
|
||||||
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
|
||||||
ref lifetime,
|
lifetime,
|
||||||
ref bounds,
|
bounds,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
self.print_lifetime(lifetime);
|
self.print_lifetime(lifetime);
|
||||||
|
@ -2264,10 +2264,8 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
|
||||||
ref lhs_ty,
|
lhs_ty, rhs_ty, ..
|
||||||
ref rhs_ty,
|
|
||||||
..
|
|
||||||
}) => {
|
}) => {
|
||||||
self.print_type(lhs_ty);
|
self.print_type(lhs_ty);
|
||||||
self.s.space();
|
self.s.space();
|
||||||
|
|
|
@ -310,13 +310,13 @@ fn filter_nodes<'q>(
|
||||||
sources: &Option<FxHashSet<&'q DepNode>>,
|
sources: &Option<FxHashSet<&'q DepNode>>,
|
||||||
targets: &Option<FxHashSet<&'q DepNode>>,
|
targets: &Option<FxHashSet<&'q DepNode>>,
|
||||||
) -> FxHashSet<&'q DepNode> {
|
) -> FxHashSet<&'q DepNode> {
|
||||||
if let &Some(ref sources) = sources {
|
if let Some(sources) = sources {
|
||||||
if let &Some(ref targets) = targets {
|
if let Some(targets) = targets {
|
||||||
walk_between(query, sources, targets)
|
walk_between(query, sources, targets)
|
||||||
} else {
|
} else {
|
||||||
walk_nodes(query, sources, OUTGOING)
|
walk_nodes(query, sources, OUTGOING)
|
||||||
}
|
}
|
||||||
} else if let &Some(ref targets) = targets {
|
} else if let Some(targets) = targets {
|
||||||
walk_nodes(query, targets, INCOMING)
|
walk_nodes(query, targets, INCOMING)
|
||||||
} else {
|
} else {
|
||||||
query.nodes().into_iter().collect()
|
query.nodes().into_iter().collect()
|
||||||
|
|
|
@ -915,7 +915,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
|
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
|
||||||
return Some(());
|
return Some(());
|
||||||
}
|
}
|
||||||
if let &ty::Adt(def, _) = ta.kind() {
|
if let ty::Adt(def, _) = ta.kind() {
|
||||||
let path_ = self.tcx.def_path_str(def.did);
|
let path_ = self.tcx.def_path_str(def.did);
|
||||||
if path_ == other_path {
|
if path_ == other_path {
|
||||||
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
|
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
|
||||||
|
|
|
@ -938,8 +938,8 @@ impl EarlyLintPass for DeprecatedAttr {
|
||||||
if attr.ident().map(|ident| ident.name) == Some(n) {
|
if attr.ident().map(|ident| ident.name) == Some(n) {
|
||||||
if let &AttributeGate::Gated(
|
if let &AttributeGate::Gated(
|
||||||
Stability::Deprecated(link, suggestion),
|
Stability::Deprecated(link, suggestion),
|
||||||
ref name,
|
name,
|
||||||
ref reason,
|
reason,
|
||||||
_,
|
_,
|
||||||
) = g
|
) = g
|
||||||
{
|
{
|
||||||
|
|
|
@ -412,7 +412,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
||||||
if let &PatKind::Binding(_, hid, ident, _) = &p.kind {
|
if let PatKind::Binding(_, hid, ident, _) = p.kind {
|
||||||
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
|
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
|
||||||
{
|
{
|
||||||
if let PatKind::Struct(_, field_pats, _) = &parent_pat.kind {
|
if let PatKind::Struct(_, field_pats, _) = &parent_pat.kind {
|
||||||
|
|
|
@ -862,11 +862,11 @@ impl EarlyLintPass for UnusedParens {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) {
|
||||||
if let &ast::TyKind::Paren(ref r) = &ty.kind {
|
if let ast::TyKind::Paren(r) = &ty.kind {
|
||||||
match &r.kind {
|
match &r.kind {
|
||||||
&ast::TyKind::TraitObject(..) => {}
|
ast::TyKind::TraitObject(..) => {}
|
||||||
&ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {}
|
ast::TyKind::ImplTrait(_, bounds) if bounds.len() > 1 => {}
|
||||||
&ast::TyKind::Array(_, ref len) => {
|
ast::TyKind::Array(_, len) => {
|
||||||
self.check_unused_delims_expr(
|
self.check_unused_delims_expr(
|
||||||
cx,
|
cx,
|
||||||
&len.value,
|
&len.value,
|
||||||
|
|
|
@ -192,13 +192,13 @@ impl Collector<'tcx> {
|
||||||
fn process_command_line(&mut self) {
|
fn process_command_line(&mut self) {
|
||||||
// First, check for errors
|
// First, check for errors
|
||||||
let mut renames = FxHashSet::default();
|
let mut renames = FxHashSet::default();
|
||||||
for &(ref name, ref new_name, _) in &self.tcx.sess.opts.libs {
|
for (name, new_name, _) in &self.tcx.sess.opts.libs {
|
||||||
if let &Some(ref new_name) = new_name {
|
if let Some(ref new_name) = new_name {
|
||||||
let any_duplicate = self
|
let any_duplicate = self
|
||||||
.libs
|
.libs
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|lib| lib.name.as_ref())
|
.filter_map(|lib| lib.name.as_ref())
|
||||||
.any(|n| n.as_str() == *name);
|
.any(|n| &n.as_str() == name);
|
||||||
if new_name.is_empty() {
|
if new_name.is_empty() {
|
||||||
self.tcx.sess.err(&format!(
|
self.tcx.sess.err(&format!(
|
||||||
"an empty renaming target was specified for library `{}`",
|
"an empty renaming target was specified for library `{}`",
|
||||||
|
@ -240,7 +240,7 @@ impl Collector<'tcx> {
|
||||||
if kind != NativeLibKind::Unspecified {
|
if kind != NativeLibKind::Unspecified {
|
||||||
lib.kind = kind;
|
lib.kind = kind;
|
||||||
}
|
}
|
||||||
if let &Some(ref new_name) = new_name {
|
if let Some(new_name) = new_name {
|
||||||
lib.name = Some(Symbol::intern(new_name));
|
lib.name = Some(Symbol::intern(new_name));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -245,8 +245,8 @@ pub fn suggest_constraining_type_param(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match ¶m_spans[..] {
|
match param_spans[..] {
|
||||||
&[¶m_span] => suggest_restrict(param_span.shrink_to_hi()),
|
[¶m_span] => suggest_restrict(param_span.shrink_to_hi()),
|
||||||
_ => {
|
_ => {
|
||||||
err.span_suggestion_verbose(
|
err.span_suggestion_verbose(
|
||||||
generics.where_clause.tail_span_for_suggestion(),
|
generics.where_clause.tail_span_for_suggestion(),
|
||||||
|
|
|
@ -302,7 +302,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
.find_map(|p| self.is_upvar_field_projection(p));
|
.find_map(|p| self.is_upvar_field_projection(p));
|
||||||
|
|
||||||
let deref_base = match deref_target_place.projection.as_ref() {
|
let deref_base = match deref_target_place.projection.as_ref() {
|
||||||
&[ref proj_base @ .., ProjectionElem::Deref] => {
|
[proj_base @ .., ProjectionElem::Deref] => {
|
||||||
PlaceRef { local: deref_target_place.local, projection: &proj_base }
|
PlaceRef { local: deref_target_place.local, projection: &proj_base }
|
||||||
}
|
}
|
||||||
_ => bug!("deref_target_place is not a deref projection"),
|
_ => bug!("deref_target_place is not a deref projection"),
|
||||||
|
|
|
@ -1855,8 +1855,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||||
self.assert_iscleanup(body, block_data, unwind, true);
|
self.assert_iscleanup(body, block_data, unwind, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TerminatorKind::InlineAsm { ref destination, .. } => {
|
TerminatorKind::InlineAsm { destination, .. } => {
|
||||||
if let &Some(target) = destination {
|
if let Some(target) = destination {
|
||||||
self.assert_iscleanup(body, block_data, target, is_cleanup);
|
self.assert_iscleanup(body, block_data, target, is_cleanup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
|
||||||
fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, hir_id: HirId, body: &'tcx hir::Body<'tcx>, fn_span: Span) {
|
fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, hir_id: HirId, body: &'tcx hir::Body<'tcx>, fn_span: Span) {
|
||||||
let mut this = CheckInlineAssembly { tcx, items: Vec::new() };
|
let mut this = CheckInlineAssembly { tcx, items: Vec::new() };
|
||||||
this.visit_body(body);
|
this.visit_body(body);
|
||||||
if let &[(ItemKind::Asm, _)] = &this.items[..] {
|
if let [(ItemKind::Asm, _)] = this.items[..] {
|
||||||
// Ok.
|
// Ok.
|
||||||
} else {
|
} else {
|
||||||
tcx.struct_span_lint_hir(UNSUPPORTED_NAKED_FUNCTIONS, hir_id, fn_span, |lint| {
|
tcx.struct_span_lint_hir(UNSUPPORTED_NAKED_FUNCTIONS, hir_id, fn_span, |lint| {
|
||||||
|
|
|
@ -582,7 +582,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
ref v => {
|
ref v => {
|
||||||
let mut value = format!("{}::{}", enum_data.name, name);
|
let mut value = format!("{}::{}", enum_data.name, name);
|
||||||
if let &hir::VariantData::Tuple(ref fields, _) = v {
|
if let hir::VariantData::Tuple(fields, _) = v {
|
||||||
value.push('(');
|
value.push('(');
|
||||||
value.push_str(
|
value.push_str(
|
||||||
&fields
|
&fields
|
||||||
|
@ -653,7 +653,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
let map = &self.tcx.hir();
|
let map = &self.tcx.hir();
|
||||||
self.nest_typeck_results(map.local_def_id(item.hir_id), |v| {
|
self.nest_typeck_results(map.local_def_id(item.hir_id), |v| {
|
||||||
v.visit_ty(&typ);
|
v.visit_ty(&typ);
|
||||||
if let &Some(ref trait_ref) = trait_ref {
|
if let Some(trait_ref) = trait_ref {
|
||||||
v.process_path(trait_ref.hir_ref_id, &hir::QPath::Resolved(None, &trait_ref.path));
|
v.process_path(trait_ref.hir_ref_id, &hir::QPath::Resolved(None, &trait_ref.path));
|
||||||
}
|
}
|
||||||
v.process_generic_params(generics, "", item.hir_id);
|
v.process_generic_params(generics, "", item.hir_id);
|
||||||
|
@ -1082,7 +1082,7 @@ impl<'tcx> DumpVisitor<'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let &Some(ref default_ty) = default_ty {
|
if let Some(default_ty) = default_ty {
|
||||||
self.visit_ty(default_ty)
|
self.visit_ty(default_ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -305,8 +305,8 @@ impl AutoTraitFinder<'tcx> {
|
||||||
infcx.resolve_vars_if_possible(Obligation::new(dummy_cause.clone(), new_env, pred));
|
infcx.resolve_vars_if_possible(Obligation::new(dummy_cause.clone(), new_env, pred));
|
||||||
let result = select.select(&obligation);
|
let result = select.select(&obligation);
|
||||||
|
|
||||||
match &result {
|
match result {
|
||||||
&Ok(Some(ref impl_source)) => {
|
Ok(Some(ref impl_source)) => {
|
||||||
// If we see an explicit negative impl (e.g., `impl !Send for MyStruct`),
|
// If we see an explicit negative impl (e.g., `impl !Send for MyStruct`),
|
||||||
// we immediately bail out, since it's impossible for us to continue.
|
// we immediately bail out, since it's impossible for us to continue.
|
||||||
|
|
||||||
|
@ -339,8 +339,8 @@ impl AutoTraitFinder<'tcx> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&Ok(None) => {}
|
Ok(None) => {}
|
||||||
&Err(SelectionError::Unimplemented) => {
|
Err(SelectionError::Unimplemented) => {
|
||||||
if self.is_param_no_infer(pred.skip_binder().trait_ref.substs) {
|
if self.is_param_no_infer(pred.skip_binder().trait_ref.substs) {
|
||||||
already_visited.remove(&pred);
|
already_visited.remove(&pred);
|
||||||
self.add_user_pred(
|
self.add_user_pred(
|
||||||
|
@ -863,7 +863,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx> {
|
||||||
|
|
||||||
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
|
||||||
(match r {
|
(match r {
|
||||||
&ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
|
ty::ReVar(vid) => self.vid_to_region.get(vid).cloned(),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| r.super_fold_with(self))
|
.unwrap_or_else(|| r.super_fold_with(self))
|
||||||
|
|
|
@ -1368,7 +1368,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
code: &ObligationCauseCode<'tcx>,
|
code: &ObligationCauseCode<'tcx>,
|
||||||
) -> Option<(String, Option<Span>)> {
|
) -> Option<(String, Option<Span>)> {
|
||||||
match code {
|
match code {
|
||||||
&ObligationCauseCode::BuiltinDerivedObligation(ref data) => {
|
ObligationCauseCode::BuiltinDerivedObligation(data) => {
|
||||||
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_ref);
|
||||||
match self.get_parent_trait_ref(&data.parent_code) {
|
match self.get_parent_trait_ref(&data.parent_code) {
|
||||||
Some(t) => Some(t),
|
Some(t) => Some(t),
|
||||||
|
|
|
@ -69,16 +69,16 @@ impl IntercrateAmbiguityCause {
|
||||||
|
|
||||||
pub fn intercrate_ambiguity_hint(&self) -> String {
|
pub fn intercrate_ambiguity_hint(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
&IntercrateAmbiguityCause::DownstreamCrate { ref trait_desc, ref self_desc } => {
|
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc } => {
|
||||||
let self_desc = if let &Some(ref ty) = self_desc {
|
let self_desc = if let Some(ty) = self_desc {
|
||||||
format!(" for type `{}`", ty)
|
format!(" for type `{}`", ty)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
format!("downstream crates may implement trait `{}`{}", trait_desc, self_desc)
|
format!("downstream crates may implement trait `{}`{}", trait_desc, self_desc)
|
||||||
}
|
}
|
||||||
&IntercrateAmbiguityCause::UpstreamCrateUpdate { ref trait_desc, ref self_desc } => {
|
IntercrateAmbiguityCause::UpstreamCrateUpdate { trait_desc, self_desc } => {
|
||||||
let self_desc = if let &Some(ref ty) = self_desc {
|
let self_desc = if let Some(ty) = self_desc {
|
||||||
format!(" for type `{}`", ty)
|
format!(" for type `{}`", ty)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
|
@ -89,7 +89,7 @@ impl IntercrateAmbiguityCause {
|
||||||
trait_desc, self_desc
|
trait_desc, self_desc
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
&IntercrateAmbiguityCause::ReservationImpl { ref message } => message.clone(),
|
IntercrateAmbiguityCause::ReservationImpl { message } => message.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -770,7 +770,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
// Try to find an unbound in bounds.
|
// Try to find an unbound in bounds.
|
||||||
let mut unbound = None;
|
let mut unbound = None;
|
||||||
for ab in ast_bounds {
|
for ab in ast_bounds {
|
||||||
if let &hir::GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = ab {
|
if let hir::GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = ab {
|
||||||
if unbound.is_none() {
|
if unbound.is_none() {
|
||||||
unbound = Some(&ptr.trait_ref);
|
unbound = Some(&ptr.trait_ref);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -290,16 +290,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
ty::FnPtr(sig) => (sig, None),
|
ty::FnPtr(sig) => (sig, None),
|
||||||
ref t => {
|
ref t => {
|
||||||
let mut unit_variant = None;
|
let mut unit_variant = None;
|
||||||
if let &ty::Adt(adt_def, ..) = t {
|
if let ty::Adt(adt_def, ..) = t {
|
||||||
if adt_def.is_enum() {
|
if adt_def.is_enum() {
|
||||||
if let hir::ExprKind::Call(ref expr, _) = call_expr.kind {
|
if let hir::ExprKind::Call(expr, _) = call_expr.kind {
|
||||||
unit_variant =
|
unit_variant =
|
||||||
self.tcx.sess.source_map().span_to_snippet(expr.span).ok();
|
self.tcx.sess.source_map().span_to_snippet(expr.span).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let hir::ExprKind::Call(ref callee, _) = call_expr.kind {
|
if let hir::ExprKind::Call(callee, _) = call_expr.kind {
|
||||||
let mut err = type_error_struct!(
|
let mut err = type_error_struct!(
|
||||||
self.tcx.sess,
|
self.tcx.sess,
|
||||||
callee.span,
|
callee.span,
|
||||||
|
|
|
@ -926,11 +926,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if is_capturing_closure(&prev_ty.kind()) || is_capturing_closure(&new_ty.kind()) {
|
if is_capturing_closure(prev_ty.kind()) || is_capturing_closure(new_ty.kind()) {
|
||||||
(None, None)
|
(None, None)
|
||||||
} else {
|
} else {
|
||||||
match (&prev_ty.kind(), &new_ty.kind()) {
|
match (prev_ty.kind(), new_ty.kind()) {
|
||||||
(&ty::FnDef(..), &ty::FnDef(..)) => {
|
(ty::FnDef(..), ty::FnDef(..)) => {
|
||||||
// Don't reify if the function types have a LUB, i.e., they
|
// Don't reify if the function types have a LUB, i.e., they
|
||||||
// are the same function and their parameters have a LUB.
|
// are the same function and their parameters have a LUB.
|
||||||
match self
|
match self
|
||||||
|
@ -943,21 +943,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(&ty::Closure(_, substs), &ty::FnDef(..)) => {
|
(ty::Closure(_, substs), ty::FnDef(..)) => {
|
||||||
let b_sig = new_ty.fn_sig(self.tcx);
|
let b_sig = new_ty.fn_sig(self.tcx);
|
||||||
let a_sig = self
|
let a_sig = self
|
||||||
.tcx
|
.tcx
|
||||||
.signature_unclosure(substs.as_closure().sig(), b_sig.unsafety());
|
.signature_unclosure(substs.as_closure().sig(), b_sig.unsafety());
|
||||||
(Some(a_sig), Some(b_sig))
|
(Some(a_sig), Some(b_sig))
|
||||||
}
|
}
|
||||||
(&ty::FnDef(..), &ty::Closure(_, substs)) => {
|
(ty::FnDef(..), ty::Closure(_, substs)) => {
|
||||||
let a_sig = prev_ty.fn_sig(self.tcx);
|
let a_sig = prev_ty.fn_sig(self.tcx);
|
||||||
let b_sig = self
|
let b_sig = self
|
||||||
.tcx
|
.tcx
|
||||||
.signature_unclosure(substs.as_closure().sig(), a_sig.unsafety());
|
.signature_unclosure(substs.as_closure().sig(), a_sig.unsafety());
|
||||||
(Some(a_sig), Some(b_sig))
|
(Some(a_sig), Some(b_sig))
|
||||||
}
|
}
|
||||||
(&ty::Closure(_, substs_a), &ty::Closure(_, substs_b)) => (
|
(ty::Closure(_, substs_a), ty::Closure(_, substs_b)) => (
|
||||||
Some(self.tcx.signature_unclosure(
|
Some(self.tcx.signature_unclosure(
|
||||||
substs_a.as_closure().sig(),
|
substs_a.as_closure().sig(),
|
||||||
hir::Unsafety::Normal,
|
hir::Unsafety::Normal,
|
||||||
|
|
|
@ -1125,7 +1125,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
fields,
|
fields,
|
||||||
base_expr.is_none(),
|
base_expr.is_none(),
|
||||||
);
|
);
|
||||||
if let &Some(ref base_expr) = base_expr {
|
if let Some(base_expr) = base_expr {
|
||||||
// If check_expr_struct_fields hit an error, do not attempt to populate
|
// If check_expr_struct_fields hit an error, do not attempt to populate
|
||||||
// the fields with the base_expr. This could cause us to hit errors later
|
// the fields with the base_expr. This could cause us to hit errors later
|
||||||
// when certain fields are assumed to exist that in fact do not.
|
// when certain fields are assumed to exist that in fact do not.
|
||||||
|
@ -1182,8 +1182,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// re-link the regions that EIfEO can erase.
|
// re-link the regions that EIfEO can erase.
|
||||||
self.demand_eqtype(span, adt_ty_hint, adt_ty);
|
self.demand_eqtype(span, adt_ty_hint, adt_ty);
|
||||||
|
|
||||||
let (substs, adt_kind, kind_name) = match &adt_ty.kind() {
|
let (substs, adt_kind, kind_name) = match adt_ty.kind() {
|
||||||
&ty::Adt(adt, substs) => (substs, adt.adt_kind(), adt.variant_descr()),
|
ty::Adt(adt, substs) => (substs, adt.adt_kind(), adt.variant_descr()),
|
||||||
_ => span_bug!(span, "non-ADT passed to check_expr_struct_fields"),
|
_ => span_bug!(span, "non-ADT passed to check_expr_struct_fields"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -333,7 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
ExprKind::Path(ref qpath) => {
|
ExprKind::Path(ref qpath) => {
|
||||||
// local binding
|
// local binding
|
||||||
if let &QPath::Resolved(_, ref path) = &qpath {
|
if let QPath::Resolved(_, path) = qpath {
|
||||||
if let hir::def::Res::Local(hir_id) = path.res {
|
if let hir::def::Res::Local(hir_id) = path.res {
|
||||||
let span = tcx.hir().span(hir_id);
|
let span = tcx.hir().span(hir_id);
|
||||||
let snippet = tcx.sess.source_map().span_to_snippet(span);
|
let snippet = tcx.sess.source_map().span_to_snippet(span);
|
||||||
|
|
|
@ -1920,7 +1920,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
let where_clause = &ast_generics.where_clause;
|
let where_clause = &ast_generics.where_clause;
|
||||||
for predicate in where_clause.predicates {
|
for predicate in where_clause.predicates {
|
||||||
match predicate {
|
match predicate {
|
||||||
&hir::WherePredicate::BoundPredicate(ref bound_pred) => {
|
hir::WherePredicate::BoundPredicate(bound_pred) => {
|
||||||
let ty = icx.to_ty(&bound_pred.bounded_ty);
|
let ty = icx.to_ty(&bound_pred.bounded_ty);
|
||||||
|
|
||||||
// Keep the type around in a dummy predicate, in case of no bounds.
|
// Keep the type around in a dummy predicate, in case of no bounds.
|
||||||
|
@ -1949,7 +1949,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
|
|
||||||
for bound in bound_pred.bounds.iter() {
|
for bound in bound_pred.bounds.iter() {
|
||||||
match bound {
|
match bound {
|
||||||
&hir::GenericBound::Trait(ref poly_trait_ref, modifier) => {
|
hir::GenericBound::Trait(poly_trait_ref, modifier) => {
|
||||||
let constness = match modifier {
|
let constness = match modifier {
|
||||||
hir::TraitBoundModifier::MaybeConst => hir::Constness::NotConst,
|
hir::TraitBoundModifier::MaybeConst => hir::Constness::NotConst,
|
||||||
hir::TraitBoundModifier::None => constness,
|
hir::TraitBoundModifier::None => constness,
|
||||||
|
@ -1959,7 +1959,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
let mut bounds = Bounds::default();
|
let mut bounds = Bounds::default();
|
||||||
let _ = AstConv::instantiate_poly_trait_ref(
|
let _ = AstConv::instantiate_poly_trait_ref(
|
||||||
&icx,
|
&icx,
|
||||||
poly_trait_ref,
|
&poly_trait_ref,
|
||||||
constness,
|
constness,
|
||||||
ty,
|
ty,
|
||||||
&mut bounds,
|
&mut bounds,
|
||||||
|
@ -1981,7 +1981,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
predicates.extend(bounds.predicates(tcx, ty));
|
predicates.extend(bounds.predicates(tcx, ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
&hir::GenericBound::Outlives(ref lifetime) => {
|
hir::GenericBound::Outlives(lifetime) => {
|
||||||
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
|
let region = AstConv::ast_region_to_region(&icx, lifetime, None);
|
||||||
predicates.insert((
|
predicates.insert((
|
||||||
ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
|
ty::Binder::bind(ty::PredicateAtom::TypeOutlives(
|
||||||
|
@ -1995,7 +1995,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&hir::WherePredicate::RegionPredicate(ref region_pred) => {
|
hir::WherePredicate::RegionPredicate(region_pred) => {
|
||||||
let r1 = AstConv::ast_region_to_region(&icx, ®ion_pred.lifetime, None);
|
let r1 = AstConv::ast_region_to_region(&icx, ®ion_pred.lifetime, None);
|
||||||
predicates.extend(region_pred.bounds.iter().map(|bound| {
|
predicates.extend(region_pred.bounds.iter().map(|bound| {
|
||||||
let (r2, span) = match bound {
|
let (r2, span) = match bound {
|
||||||
|
@ -2011,7 +2011,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
&hir::WherePredicate::EqPredicate(..) => {
|
hir::WherePredicate::EqPredicate(..) => {
|
||||||
// FIXME(#20041)
|
// FIXME(#20041)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,8 +351,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
if let Some(data) = ty_to_fn.get(&ty) {
|
if let Some(data) = ty_to_fn.get(&ty) {
|
||||||
let (poly_trait, output) =
|
let (poly_trait, output) =
|
||||||
(data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned());
|
(data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned());
|
||||||
let new_ty = match &poly_trait.trait_ {
|
let new_ty = match poly_trait.trait_ {
|
||||||
&Type::ResolvedPath {
|
Type::ResolvedPath {
|
||||||
ref path,
|
ref path,
|
||||||
ref param_names,
|
ref param_names,
|
||||||
ref did,
|
ref did,
|
||||||
|
|
|
@ -179,12 +179,12 @@ crate fn get_real_types(
|
||||||
if arg.is_full_generic() {
|
if arg.is_full_generic() {
|
||||||
let arg_s = Symbol::intern(&arg.print().to_string());
|
let arg_s = Symbol::intern(&arg.print().to_string());
|
||||||
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
|
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
|
||||||
&WherePredicate::BoundPredicate { ref ty, .. } => ty.def_id() == arg.def_id(),
|
WherePredicate::BoundPredicate { ty, .. } => ty.def_id() == arg.def_id(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}) {
|
}) {
|
||||||
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
|
let bounds = where_pred.get_bounds().unwrap_or_else(|| &[]);
|
||||||
for bound in bounds.iter() {
|
for bound in bounds.iter() {
|
||||||
if let GenericBound::TraitBound(ref poly_trait, _) = *bound {
|
if let GenericBound::TraitBound(poly_trait, _) = bound {
|
||||||
for x in poly_trait.generic_params.iter() {
|
for x in poly_trait.generic_params.iter() {
|
||||||
if !x.is_type() {
|
if !x.is_type() {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue