Skip to content

Rollup of 12 pull requests #47734

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 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
dbb6519
NLL test for mutating &mut references
ritiek Jan 20, 2018
4121ddb
Do not suggest private traits that have missing method
estebank Jan 18, 2018
5de8e04
Remove broken redundant backtrace hint
etaoins Jan 23, 2018
06d123d
Remove similar test that does not run the result
ritiek Jan 23, 2018
e6af9eb
Point at unknown lang item attribute
estebank Jan 23, 2018
583b382
Remove workarounds for cc 1.0.3.
EdSchouten Jan 24, 2018
65b1e86
Fix into() cast paren check precedence
etaoins Jan 24, 2018
05652d2
fix for documentation error issue 47716
evelynmitchell Jan 24, 2018
e1e991d
Fix experimental text display on default theme
GuillaumeGomez Jan 24, 2018
0847ac0
Fix wrong span for nested empty groups
pietroalbini Jan 24, 2018
15899b0
Update Cargo submodule to master
alexcrichton Jan 25, 2018
147f5ce
Rollup merge of #47534 - estebank:suggest-public-traits, r=petrochenkov
GuillaumeGomez Jan 25, 2018
2afd21d
Rollup merge of #47609 - ritiek:test-mutating-references, r=nikomatsakis
GuillaumeGomez Jan 25, 2018
0a1dcd3
Rollup merge of #47679 - etaoins:remove-redundant-backtrace-hint, r=e…
GuillaumeGomez Jan 25, 2018
7550753
Rollup merge of #47691 - estebank:unknown-lang-item-sp, r=rkruppe
GuillaumeGomez Jan 25, 2018
47cb91a
Rollup merge of #47700 - EdSchouten:cc104, r=kennytm
GuillaumeGomez Jan 25, 2018
9d3d9d5
Rollup merge of #47702 - etaoins:fix-into-cast-paren-precedence, r=pe…
GuillaumeGomez Jan 25, 2018
f72d441
Rollup merge of #47717 - evelynmitchell:47716-doc-fix, r=steveklabnik
GuillaumeGomez Jan 25, 2018
a4d31fc
Rollup merge of #47721 - GuillaumeGomez:experimental-color, r=QuietMi…
GuillaumeGomez Jan 25, 2018
5d9ea4b
Rollup merge of #47726 - pietroalbini:fix-nested-empty-groups-span, r…
GuillaumeGomez Jan 25, 2018
e1fd7ca
Rollup merge of #47729 - alexcrichton:update-cargo, r=sfackler
GuillaumeGomez Jan 25, 2018
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
Fix into() cast paren check precedence
As discussed in #47699 the logic for determining if an expression needs
parenthesis when suggesting an `.into()` cast is incorrect. Two broken
examples from nightly are:

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(foo as i8);
  |          ^^^^^^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(foo as i8.into());
  |
```

```
error[E0308]: mismatched types
 --> main.rs:4:10
  |
4 |     test(*foo);
  |          ^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
  |
4 |     test(*foo.into());
  |
```

As suggested by @petrochenkov switch the precedence check to
PREC_POSTFIX. This catches both `as` and unary operators. Fixes #47699.
  • Loading branch information
etaoins committed Jan 24, 2018
commit 65b1e86aed22bfcd3a4ce27da9be2b14c7d5738e
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc::infer::InferOk;
use rustc::traits::ObligationCause;

use syntax::ast;
use syntax::util::parser::AssocOp;
use syntax::util::parser::PREC_POSTFIX;
use syntax_pos::{self, Span};
use rustc::hir;
use rustc::hir::print;
Expand Down Expand Up @@ -336,7 +336,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// For now, don't suggest casting with `as`.
let can_cast = false;

let needs_paren = expr.precedence().order() < (AssocOp::As.precedence() as i8);
let needs_paren = expr.precedence().order() < (PREC_POSTFIX as i8);

if let Ok(src) = self.tcx.sess.codemap().span_to_snippet(expr.span) {
let msg = format!("you can cast an `{}` to `{}`", checked_ty, expected_ty);
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/suggestions/numeric-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,9 @@ fn main() {
foo::<f32>(x_f64);
//~^ ERROR mismatched types
foo::<f32>(x_f32);

foo::<u32>(x_u8 as u16);
//~^ ERROR mismatched types
foo::<i32>(-x_i8);
//~^ ERROR mismatched types
}
22 changes: 21 additions & 1 deletion src/test/ui/suggestions/numeric-cast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -882,5 +882,25 @@ error[E0308]: mismatched types
312 | foo::<f32>(x_f64);
| ^^^^^ expected f32, found f64

error: aborting due to 132 previous errors
error[E0308]: mismatched types
--> $DIR/numeric-cast.rs:316:16
|
316 | foo::<u32>(x_u8 as u16);
| ^^^^^^^^^^^ expected u32, found u16
help: you can cast an `u16` to `u32`, which will zero-extend the source value
|
316 | foo::<u32>((x_u8 as u16).into());
| ^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/numeric-cast.rs:318:16
|
318 | foo::<i32>(-x_i8);
| ^^^^^ expected i32, found i8
help: you can cast an `i8` to `i32`, which will sign-extend the source value
|
318 | foo::<i32>((-x_i8).into());
| ^^^^^^^^^^^^^^

error: aborting due to 134 previous errors