Skip to content

Commit 3dbe0ce

Browse files
committed
Fix implicit Sized relaxation when attempting to relax other, unsupported trait
1 parent 4156473 commit 3dbe0ce

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
838838
this does nothing because the given bound is not \
839839
a default; only `?Sized` is supported",
840840
);
841+
return false;
841842
}
842843
}
843844
}

src/test/ui/issues/issue-87199.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
// Check that these function definitions only emit warnings, not errors
88
fn arg<T: ?Send>(_: T) {}
99
//~^ warning: default bound relaxed for a type parameter, but this does nothing
10-
//~^^ the size for values of type `T`
1110
fn ref_arg<T: ?Send>(_: &T) {}
1211
//~^ warning: default bound relaxed for a type parameter, but this does nothing
1312
fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
1413
//~^ warning: default bound relaxed for a type parameter, but this does nothing
15-
//~^^ the size for values of type `impl Iterator+?Sized` cannot be known
1614

1715
// Check that there's no `?Sized` relaxation!
1816
fn main() {
1917
ref_arg::<i32>(&5);
2018
ref_arg::<[i32]>(&[5]);
19+
//~^ the size for values of type `[i32]` cannot be known
2120
}

src/test/ui/issues/issue-87199.stderr

+14-22
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,32 @@ LL | fn arg<T: ?Send>(_: T) {}
55
| ^
66

77
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
8-
--> $DIR/issue-87199.rs:11:12
8+
--> $DIR/issue-87199.rs:10:12
99
|
1010
LL | fn ref_arg<T: ?Send>(_: &T) {}
1111
| ^
1212

1313
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
14-
--> $DIR/issue-87199.rs:13:13
14+
--> $DIR/issue-87199.rs:12:13
1515
|
1616
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error[E0277]: the size for values of type `impl Iterator+?Sized` cannot be known at compilation time
20-
--> $DIR/issue-87199.rs:13:13
19+
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
20+
--> $DIR/issue-87199.rs:18:22
2121
|
22-
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
24-
|
25-
= help: the trait `Sized` is not implemented for `impl Iterator+?Sized`
26-
= note: the return type of a function must have a statically known size
27-
28-
error[E0277]: the size for values of type `T` cannot be known at compilation time
29-
--> $DIR/issue-87199.rs:8:18
30-
|
31-
LL | fn arg<T: ?Send>(_: T) {}
32-
| - ^ doesn't have a size known at compile-time
33-
| |
34-
| this type parameter needs to be `std::marker::Sized`
22+
LL | fn ref_arg<T: ?Send>(_: &T) {}
23+
| - required by this bound in `ref_arg`
24+
...
25+
LL | ref_arg::<[i32]>(&[5]);
26+
| ^^^^ doesn't have a size known at compile-time
3527
|
36-
= help: unsized fn params are gated as an unstable feature
37-
help: function arguments must have a statically known size, borrowed types always have a known size
28+
= help: the trait `Sized` is not implemented for `[i32]`
29+
help: consider relaxing the implicit `Sized` restriction
3830
|
39-
LL | fn arg<T: ?Send>(_: &T) {}
40-
| ^
31+
LL | fn ref_arg<T: ?Send + ?Sized>(_: &T) {}
32+
| ^^^^^^^^
4133

42-
error: aborting due to 2 previous errors; 3 warnings emitted
34+
error: aborting due to previous error; 3 warnings emitted
4335

4436
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)