Skip to content

Rollup of 8 pull requests #63424

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

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0a227f3
stabilize duration_float
newpavlov Jul 17, 2019
ad36324
unconstify methods
newpavlov Jul 17, 2019
01d9e57
Stabilize checked_duration_since for 1.38.0
vi Jul 21, 2019
55ee8fe
mark div_duration methods as unstable, update tracking issue
newpavlov Jul 30, 2019
4281e61
fix tests
newpavlov Jul 30, 2019
ffa4d7e
Sort the fat LTO modules to produce deterministic output.
jgalenson Aug 7, 2019
5b2c5e1
Sort fat LTO modules later and add a test.
jgalenson Aug 8, 2019
a46e36f
Fix fat LTO determinism test so it fails without the fix.
jgalenson Aug 8, 2019
3e6a927
Explain why we're sorting the modules.
jgalenson Aug 8, 2019
3a6a29b
Use associated_type_bounds where applicable - closes #61738
iluuu1994 Jul 31, 2019
322a7d6
Add test for issue 36804
jackh726 Aug 8, 2019
36c4873
Try to fix test on Windows.
jgalenson Aug 8, 2019
3d231ac
Add missing #![feature(associated_type_bounds)]
iluuu1994 Aug 8, 2019
77bfd7f
Don't use associated type bounds in docs until it is stable
iluuu1994 Aug 9, 2019
c076392
Tweak mismatched types error on break expressions
estebank Aug 6, 2019
799b13a
Do not suggest using ! with break
estebank Aug 7, 2019
4fbbf99
Be more accurate when mentioning type of found match arms
estebank Aug 7, 2019
01a6139
Change wording for function without return value
estebank Aug 7, 2019
94fe8a3
Suggest calling function on type error when finding bare fn
estebank Aug 7, 2019
195d837
When suggesting fn call use an appropriate number of placeholder argu…
estebank Aug 8, 2019
b7f7756
Recover parser from `foo(_, _)`
estebank Aug 8, 2019
0d53f69
review comments
estebank Aug 8, 2019
efa62d6
Tweak wording of fn without explicit return
estebank Aug 8, 2019
52da091
Differentiate between tuple structs and tuple variants
estebank Aug 8, 2019
5a54945
Extend suggestion support for traits and foreign items
estebank Aug 8, 2019
33d1082
review comment: review wording or missing return error
estebank Aug 8, 2019
bc1a4f5
review comments: typo and rewording
estebank Aug 8, 2019
45a5bc7
fix tests
estebank Aug 9, 2019
7c96d90
More explicit diagnostic when using a `vec![]` in a pattern
estebank Aug 9, 2019
b6767b3
Stop test from running on Windows.
jgalenson Aug 9, 2019
75c5ad2
review comments: use structured suggestion
estebank Aug 9, 2019
4dd96d2
check against more collisions for TypeId of fn pointer
RalfJung Aug 9, 2019
ba86733
Rollup merge of #62756 - newpavlov:stabilize_dur_float, r=alexcrichton
Centril Aug 9, 2019
1b3e7fb
Rollup merge of #62860 - vi:stabilize_checked_duration_since, r=alexc…
Centril Aug 9, 2019
b20ce2b
Rollup merge of #63337 - estebank:break-ee0308, r=Centril
Centril Aug 9, 2019
fc8512a
Rollup merge of #63350 - iluuu1994:use-associated-type-bounds, r=Centril
Centril Aug 9, 2019
f4beab3
Rollup merge of #63352 - jgalenson:reproducible-lto, r=alexcrichton
Centril Aug 9, 2019
8453b43
Rollup merge of #63394 - jackh726:issue-36804, r=jonas-schievink
Centril Aug 9, 2019
a873606
Rollup merge of #63399 - estebank:vec-in-pat, r=Centril
Centril Aug 9, 2019
02980cd
Rollup merge of #63419 - RalfJung:typeid, r=alexcrichton
Centril Aug 9, 2019
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
review comments
  • Loading branch information
estebank committed Aug 9, 2019
commit 0d53f699eaa7d1fec1e6013a6a42b39992c119d3
13 changes: 7 additions & 6 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
assert!(e_ty.is_unit());
let ty = coerce.expected_ty();
coerce.coerce_forced_unit(self, &cause, &mut |err| {
let msg = "give it a value of the expected type";
let label = destination.label
.map(|l| format!(" {}", l.ident))
.unwrap_or_else(String::new);
let sugg = format!("break{} {}", label, match ty.sty {
let val = match ty.sty {
ty::Bool => "true",
ty::Char => "'a'",
ty::Int(_) | ty::Uint(_) => "42",
ty::Float(_) => "3.14159",
ty::Error | ty::Never => return,
_ => "value",
});
};
let msg = "give it a value of the expected type";
let label = destination.label
.map(|l| format!(" {}", l.ident))
.unwrap_or_else(String::new);
let sugg = format!("break{} {}", label, val);
err.span_suggestion(expr.span, msg, sugg, Applicability::HasPlaceholders);
}, false);
}
Expand Down
89 changes: 49 additions & 40 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3819,55 +3819,64 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pointing_at_return_type
}

/// When encountering an fn-like ctor that needs to unify with a value, check whether calling
/// the ctor would successfully solve the type mismatch and if so, suggest it:
/// ```
/// fn foo(x: usize) -> usize { x }
/// let x: usize = foo; // suggest calling the `foo` function: `foo(42)`
/// ```
fn suggest_fn_call(
&self,
err: &mut DiagnosticBuilder<'tcx>,
expr: &hir::Expr,
expected: Ty<'tcx>,
found: Ty<'tcx>,
) -> bool {
if let ty::FnDef(..) | ty::FnPtr(_) = &found.sty {
let sig = found.fn_sig(self.tcx);
let sig = self
.replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, &sig)
.0;
let sig = self.normalize_associated_types_in(expr.span, &sig);
if let Ok(_) = self.try_coerce(expr, sig.output(), expected, AllowTwoPhase::No) {
let (mut sugg_call, applicability) = if sig.inputs().is_empty() {
(String::new(), Applicability::MachineApplicable)
} else {
("...".to_owned(), Applicability::HasPlaceholders)
};
let mut msg = "call this function";
if let ty::FnDef(def_id, ..) = found.sty {
match self.tcx.hir().get_if_local(def_id) {
Some(Node::Item(hir::Item {
node: ItemKind::Fn(.., body_id),
..
})) => {
let body = self.tcx.hir().body(*body_id);
sugg_call = body.arguments.iter()
.map(|arg| hir::print::to_string(
hir::print::NO_ANN,
|s| s.print_pat(&arg.pat),
)).collect::<Vec<_>>().join(", ");
}
Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => {
sugg_call = field.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
msg = "instatiate this tuple struct";
}
_ => {}
match found.sty {
ty::FnDef(..) | ty::FnPtr(_) => {}
_ => return false,
}

let sig = found.fn_sig(self.tcx);
let sig = self
.replace_bound_vars_with_fresh_vars(expr.span, infer::FnCall, &sig)
.0;
let sig = self.normalize_associated_types_in(expr.span, &sig);
if let Ok(_) = self.try_coerce(expr, sig.output(), expected, AllowTwoPhase::No) {
let (mut sugg_call, applicability) = if sig.inputs().is_empty() {
(String::new(), Applicability::MachineApplicable)
} else {
("...".to_owned(), Applicability::HasPlaceholders)
};
let mut msg = "call this function";
if let ty::FnDef(def_id, ..) = found.sty {
match self.tcx.hir().get_if_local(def_id) {
Some(Node::Item(hir::Item {
node: ItemKind::Fn(.., body_id),
..
})) => {
let body = self.tcx.hir().body(*body_id);
sugg_call = body.arguments.iter()
.map(|arg| hir::print::to_string(
hir::print::NO_ANN,
|s| s.print_pat(&arg.pat),
)).collect::<Vec<_>>().join(", ");
}
};
if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) {
err.span_suggestion(
expr.span,
&format!("use parentheses to {}", msg),
format!("{}({})", code, sugg_call),
applicability,
);
return true;
Some(Node::Ctor(hir::VariantData::Tuple(field, _))) => {
sugg_call = field.iter().map(|_| "_").collect::<Vec<_>>().join(", ");
msg = "instatiate this tuple struct";
}
_ => {}
}
};
if let Ok(code) = self.sess().source_map().span_to_snippet(expr.span) {
err.span_suggestion(
expr.span,
&format!("use parentheses to {}", msg),
format!("{}({})", code, sugg_call),
applicability,
);
return true;
}
}
false
Expand Down