Skip to content

Commit 2fe1973

Browse files
authored
Unrolled build for #144142
Rollup merge of #144142 - compiler-errors:itib, r=fmease Add implicit sized bound to trait ascription types r? ```@fmease``` or reassign Thanks for catching this :) Fixes #144135
2 parents 81af9d4 + 4cebbab commit 2fe1973

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24952495
ty::List::empty(),
24962496
PredicateFilter::All,
24972497
);
2498+
self.add_sizedness_bounds(
2499+
&mut bounds,
2500+
self_ty,
2501+
hir_bounds,
2502+
None,
2503+
None,
2504+
hir_ty.span,
2505+
);
24982506
self.register_trait_ascription_bounds(bounds, hir_ty.hir_id, hir_ty.span);
24992507
self_ty
25002508
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(impl_trait_in_bindings)]
2+
3+
trait Trait {}
4+
impl<T: ?Sized> Trait for T {}
5+
6+
fn doesnt_work() {
7+
let x: &impl Trait = "hi";
8+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
9+
}
10+
11+
fn works() {
12+
let x: &(impl Trait + ?Sized) = "hi";
13+
// No implicit sized.
14+
15+
let x: &impl Trait = &();
16+
// Is actually sized.
17+
}
18+
19+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
2+
--> $DIR/implicit-sized.rs:7:13
3+
|
4+
LL | let x: &impl Trait = "hi";
5+
| ^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `str`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)