Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
in which suggestions to borrow casts or binary expressions are rectified
This simple patch resolves #46756 (which was specifically about the case of casts, but it would be poor form indeed to fix a reported issue without at least a cursory attempt at answering the immortal question, "How does this bug generalize?").
- Loading branch information
1 parent
b3392f8
commit 73a9019
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(unused)] | ||
|
||
fn light_flows_our_war_of_mocking_words(and_yet: &usize) -> usize { | ||
and_yet + 1 | ||
} | ||
|
||
fn main() { | ||
let behold: isize = 2; | ||
let with_tears: usize = 3; | ||
light_flows_our_war_of_mocking_words(behold as usize); | ||
//~^ ERROR mismatched types [E0308] | ||
light_flows_our_war_of_mocking_words(with_tears + 4); | ||
//~^ ERROR mismatched types [E0308] | ||
} |
26 changes: 26 additions & 0 deletions
26
src/test/ui/suggestions/issue-46756-consider-borrowing-cast-or-binexpr.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:20:42 | ||
| | ||
20 | light_flows_our_war_of_mocking_words(behold as usize); | ||
| ^^^^^^^^^^^^^^^ | ||
| | | ||
| expected &usize, found usize | ||
| help: consider borrowing here: `&(behold as usize)` | ||
| | ||
= note: expected type `&usize` | ||
found type `usize` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-46756-consider-borrowing-cast-or-binexpr.rs:22:42 | ||
| | ||
22 | light_flows_our_war_of_mocking_words(with_tears + 4); | ||
| ^^^^^^^^^^^^^^ | ||
| | | ||
| expected &usize, found usize | ||
| help: consider borrowing here: `&(with_tears + 4)` | ||
| | ||
= note: expected type `&usize` | ||
found type `usize` | ||
|
||
error: aborting due to 2 previous errors | ||
|