Skip to content

Commit 01d8fd6

Browse files
committed
Auto merge of #146066 - jhpratt:rollup-vh43plw, r=jhpratt
Rollup of 3 pull requests Successful merges: - #145968 (Add `Bound::copied`) - #146046 (Suggest method name with maybe ty mismatch) - #146051 (Change std f32 test to pass under Miri) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 07d246f + 7372132 commit 01d8fd6

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed

compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117117
Err(Ambiguity(..)) => true,
118118
Err(PrivateMatch(..)) => false,
119119
Err(IllegalSizedBound { .. }) => true,
120-
Err(BadReturnType) => false,
120+
Err(BadReturnType) => true,
121121
Err(ErrorReported(_)) => false,
122122
}
123123
}

library/core/src/ops/range.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,31 @@ impl<T> Bound<T> {
736736
}
737737
}
738738

739+
impl<T: Copy> Bound<&T> {
740+
/// Map a `Bound<&T>` to a `Bound<T>` by copying the contents of the bound.
741+
///
742+
/// # Examples
743+
///
744+
/// ```
745+
/// #![feature(bound_copied)]
746+
///
747+
/// use std::ops::Bound::*;
748+
/// use std::ops::RangeBounds;
749+
///
750+
/// assert_eq!((1..12).start_bound(), Included(&1));
751+
/// assert_eq!((1..12).start_bound().copied(), Included(1));
752+
/// ```
753+
#[unstable(feature = "bound_copied", issue = "145966")]
754+
#[must_use]
755+
pub fn copied(self) -> Bound<T> {
756+
match self {
757+
Bound::Unbounded => Bound::Unbounded,
758+
Bound::Included(x) => Bound::Included(*x),
759+
Bound::Excluded(x) => Bound::Excluded(*x),
760+
}
761+
}
762+
}
763+
739764
impl<T: Clone> Bound<&T> {
740765
/// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound.
741766
///
@@ -745,8 +770,11 @@ impl<T: Clone> Bound<&T> {
745770
/// use std::ops::Bound::*;
746771
/// use std::ops::RangeBounds;
747772
///
748-
/// assert_eq!((1..12).start_bound(), Included(&1));
749-
/// assert_eq!((1..12).start_bound().cloned(), Included(1));
773+
/// let a1 = String::from("a");
774+
/// let (a2, a3, a4) = (a1.clone(), a1.clone(), a1.clone());
775+
///
776+
/// assert_eq!(Included(&a1), (a2..).start_bound());
777+
/// assert_eq!(Included(a3), (a4..).start_bound().cloned());
750778
/// ```
751779
#[must_use = "`self` will be dropped if the result is not used"]
752780
#[stable(feature = "bound_cloned", since = "1.55.0")]

library/std/tests/floats/f32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ fn test_log() {
7979
let nan: f32 = f32::NAN;
8080
let inf: f32 = f32::INFINITY;
8181
let neg_inf: f32 = f32::NEG_INFINITY;
82-
assert_approx_eq!(10.0f32.log(10.0), 1.0);
83-
assert_approx_eq!(2.3f32.log(3.5), 0.664858);
82+
assert_approx_eq!(10.0f32.log(10.0), 1.0, APPROX_DELTA);
83+
assert_approx_eq!(2.3f32.log(3.5), 0.664858, APPROX_DELTA);
8484
assert_approx_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0, APPROX_DELTA);
8585
assert!(1.0f32.log(1.0).is_nan());
8686
assert!(1.0f32.log(-13.9).is_nan());

tests/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0599]: no method named `test` found for opaque type `impl Future<Output =
33
|
44
LL | let x: u32 = foo().test();
55
| ^^^^ method not found in `impl Future<Output = A>`
6+
|
7+
help: consider `await`ing on the `Future` and calling the method on its `Output`
8+
|
9+
LL | let x: u32 = foo().await.test();
10+
| ++++++
611

712
error: aborting due to 1 previous error
813

tests/ui/privacy/private-field-ty-err.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error[E0616]: field `len` of struct `Foo` is private
33
|
44
LL | if x.len {
55
| ^^^ private field
6+
|
7+
help: a method `len` also exists, call it with parentheses
8+
|
9+
LL | if x.len() {
10+
| ++
611

712
error: aborting due to 1 previous error
813

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct LlamaModel;
2+
3+
impl LlamaModel {
4+
fn chat_template(&self) -> Result<&str, ()> {
5+
todo!()
6+
}
7+
}
8+
9+
fn template_from_str(_x: &str) {}
10+
11+
fn main() {
12+
let model = LlamaModel;
13+
template_from_str(&model.chat_template); //~ ERROR attempted to take value of method `chat_template` on type `LlamaModel`
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0615]: attempted to take value of method `chat_template` on type `LlamaModel`
2+
--> $DIR/suggest-method-name-with-maybe-ty-mismatch-146008.rs:13:30
3+
|
4+
LL | template_from_str(&model.chat_template);
5+
| ^^^^^^^^^^^^^ method, not a field
6+
|
7+
help: use parentheses to call the method
8+
|
9+
LL | template_from_str(&model.chat_template());
10+
| ++
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0615`.

0 commit comments

Comments
 (0)