Skip to content

Rollup of 6 pull requests #98910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
369555c
Implement `FusedIterator` for `std::net::[Into]Incoming`
ChayimFriedman2 May 23, 2022
c36572c
add AllocRange Debug impl; remove redundant AllocId Display impl
RalfJung Jul 2, 2022
d31cbb5
make AllocRef APIs more consistent
RalfJung Jul 2, 2022
0832d1d
more use of format! variable capture
RalfJung Jul 2, 2022
76c0429
Bump std::net::Incoming FusedIterator impl to Rust 1.64
dtolnay Jul 2, 2022
46ccde4
clean up the borrowing in rustc_hir_pretty
kadiwa4 Jul 3, 2022
7fc7780
fix interpreter validity check on Box
RalfJung Jul 3, 2022
d7edf66
move Box mess handling into general visitor
RalfJung Jul 4, 2022
eb80407
suggest `#[derive(Default)]` to enums with `#[default]`
TaKO8Ki Jul 4, 2022
c2ed087
remove unused function argument
lcnr Jul 1, 2022
f1836c4
update infer cost computation for types
lcnr Jul 1, 2022
eef34a6
stop suggesting things inside of macros
lcnr Jul 1, 2022
7952d2e
resolve vars in node substs
lcnr Jul 1, 2022
f475e88
`InferSource::GenericArg`, check for contains
lcnr Jul 1, 2022
d26ccf7
Rollup merge of #97300 - ChayimFriedman2:patch-1, r=dtolnay
Dylan-DPC Jul 5, 2022
6a9db39
Rollup merge of #98761 - lcnr:need_type_info-cont, r=estebank
Dylan-DPC Jul 5, 2022
522d52c
Rollup merge of #98811 - RalfJung:interpret-alloc-range, r=oli-obk
Dylan-DPC Jul 5, 2022
7702c50
Rollup merge of #98847 - RalfJung:box-is-special, r=oli-obk
Dylan-DPC Jul 5, 2022
6e5f1d4
Rollup merge of #98854 - kadiwa4:rustc_hir_pretty_clean_up_borrowing,…
Dylan-DPC Jul 5, 2022
9a2274c
Rollup merge of #98873 - TaKO8Ki:suggest-default-derive-to-enum-with-…
Dylan-DPC Jul 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
InferSource::GenericArg, check for contains
  • Loading branch information
lcnr committed Jul 4, 2022
commit f475e880a4c6b2359ebaef88c844daede9c88fc9
37 changes: 20 additions & 17 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,19 @@ enum InferSourceKind<'tcx> {
}

impl<'tcx> InferSource<'tcx> {
/// Returns the span where we're going to insert our suggestion.
///
/// Used when computing the cost of this infer source to check whether
/// we're inside of a macro expansion.
fn main_insert_span(&self) -> Span {
match self.kind {
InferSourceKind::LetBinding { insert_span, .. } => insert_span,
InferSourceKind::ClosureArg { insert_span, .. } => insert_span,
InferSourceKind::GenericArg { insert_span, .. } => insert_span,
InferSourceKind::FullyQualifiedMethodCall { receiver, .. } => receiver.span,
InferSourceKind::ClosureReturn { data, .. } => data.span(),
}
fn from_expansion(&self) -> bool {
let source_from_expansion = match self.kind {
InferSourceKind::LetBinding { insert_span, .. }
| InferSourceKind::ClosureArg { insert_span, .. }
| InferSourceKind::GenericArg { insert_span, .. } => insert_span.from_expansion(),
InferSourceKind::FullyQualifiedMethodCall { receiver, .. } => {
receiver.span.from_expansion()
}
InferSourceKind::ClosureReturn { data, should_wrap_expr, .. } => {
data.span().from_expansion() || should_wrap_expr.map_or(false, Span::from_expansion)
}
};
source_from_expansion || self.span.from_expansion()
}
}

Expand Down Expand Up @@ -631,7 +632,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
}
}
fn ty_cost(self, ty: Ty<'tcx>) -> usize {
match ty.kind() {
match *ty.kind() {
ty::Closure(..) => 1000,
ty::FnDef(..) => 150,
ty::FnPtr(..) => 30,
Expand All @@ -645,6 +646,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
.sum::<usize>()
}
ty::Tuple(args) => 5 + args.iter().map(|arg| self.ty_cost(arg)).sum::<usize>(),
ty::Ref(_, ty, _) => 2 + self.ty_cost(ty),
ty::Infer(..) => 0,
_ => 1,
}
Expand Down Expand Up @@ -673,8 +675,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
}
};

let suggestion_may_apply =
if source.main_insert_span().can_be_used_for_suggestions() { 0 } else { 10000 };
let suggestion_may_apply = if source.from_expansion() { 10000 } else { 0 };

base_cost + suggestion_may_apply
}
Expand Down Expand Up @@ -1022,8 +1023,10 @@ impl<'a, 'tcx> Visitor<'tcx> for FindInferSourceVisitor<'a, 'tcx> {
debug!(?args);
let InsertableGenericArgs { insert_span, substs, generics_def_id, def_id } = args;
let generics = tcx.generics_of(generics_def_id);
if let Some(argument_index) =
generics.own_substs(substs).iter().position(|&arg| self.generic_arg_is_target(arg))
if let Some(argument_index) = generics
.own_substs(substs)
.iter()
.position(|&arg| self.generic_arg_contains_target(arg))
{
let substs = self.infcx.resolve_vars_if_possible(substs);
let generic_args = &generics.own_substs_no_defaults(tcx, substs)
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/inference/cannot-infer-partial-try-return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fn infallible() -> Result<(), std::convert::Infallible> {

fn main() {
let x = || -> Result<_, QualifiedError<_>> {
//~^ ERROR type annotations needed for `Result<(), QualifiedError<_>>`
infallible()?;
Ok(())
//~^ ERROR type annotations needed
};
}
15 changes: 7 additions & 8 deletions src/test/ui/inference/cannot-infer-partial-try-return.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
error[E0282]: type annotations needed for `Result<(), QualifiedError<_>>`
--> $DIR/cannot-infer-partial-try-return.rs:18:13
error[E0282]: type annotations needed
--> $DIR/cannot-infer-partial-try-return.rs:20:9
|
LL | let x = || -> Result<_, QualifiedError<_>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | infallible()?;
| ------------- type must be known at this point
LL | Ok(())
| ^^ cannot infer type of the type parameter `E` declared on the enum `Result`
|
help: try giving this closure an explicit return type
help: consider specifying the generic arguments
|
LL | let x = || -> Result<(), QualifiedError<_>> {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | Ok::<(), QualifiedError<_>>(())
| +++++++++++++++++++++++++

error: aborting due to previous error

Expand Down
9 changes: 7 additions & 2 deletions src/test/ui/issues/issue-23041.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error[E0282]: type annotations needed
--> $DIR/issue-23041.rs:6:22
--> $DIR/issue-23041.rs:6:7
|
LL | b.downcast_ref::<fn(_)->_>();
| ^^^^^^^^ cannot infer type
| ^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the associated function `downcast_ref`
|
help: consider specifying the generic arguments
|
LL | b.downcast_ref::<fn(_) -> _>();
| ~~~~~~~~~~~~~~

error: aborting due to previous error

Expand Down
9 changes: 7 additions & 2 deletions src/test/ui/issues/issue-24013.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error[E0282]: type annotations needed
--> $DIR/issue-24013.rs:5:20
--> $DIR/issue-24013.rs:5:13
|
LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
| ^^^^^^ cannot infer type
| ^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `swap`
|
help: consider specifying the generic arguments
|
LL | unsafe {swap::<&mut _>(transmute(&a), transmute(&b))};
| ~~~~~~~~~~

error: aborting due to previous error

Expand Down