Skip to content
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

Rollup of 8 pull requests #117013

Merged
merged 21 commits into from
Oct 21, 2023
Merged
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
e8d4fb8
Suggest relaxing implicit `type Assoc: Sized;` bound
estebank Oct 18, 2023
6ed2a76
Add stable Instance::body() and RustcInternal trait
celinval Oct 20, 2023
9a963e8
std: freebsd build update.
devnexen Aug 5, 2023
6e643e1
Remove obsolete comment
celinval Oct 20, 2023
b0d17f3
Typo suggestion to change bindings with leading underscore
estebank Oct 19, 2023
88bccf4
Mention `into_iter` on borrow errors suggestions when appropriate
estebank Oct 20, 2023
939a224
Point at assoc fn definition on type param divergence
estebank Oct 20, 2023
f479142
changes from feedback
devnexen Oct 20, 2023
dca4295
coverage: Add a test showing the inconsistent handling of function si…
Zalathar Oct 17, 2023
a17ff82
coverage: Handle fn signature spans more consistently near `?`
Zalathar Oct 17, 2023
e164944
coverage: Don't create an intermediate vec for each BCB's initial spans
Zalathar Oct 17, 2023
319693a
coverage: Simplify initial creation of coverage spans
Zalathar Oct 17, 2023
ff02d92
coverage: Simplify the injection of coverage statements
Zalathar Sep 22, 2023
90671a0
Rollup merge of #114521 - devnexen:std_fbsd_13_upd, r=cuviper
matthiaskrgr Oct 21, 2023
3fd7175
Rollup merge of #116911 - estebank:issue-85378, r=oli-obk
matthiaskrgr Oct 21, 2023
ad574d9
Rollup merge of #116917 - Zalathar:injection, r=cjgillot
matthiaskrgr Oct 21, 2023
c5dd84d
Rollup merge of #116961 - estebank:issue-60164, r=oli-obk
matthiaskrgr Oct 21, 2023
b703519
Rollup merge of #116964 - celinval:smir-mono-body, r=oli-obk
matthiaskrgr Oct 21, 2023
e9df0b6
Rollup merge of #116974 - Zalathar:signature-spans, r=oli-obk,cjgillot
matthiaskrgr Oct 21, 2023
dd66bc8
Rollup merge of #116990 - estebank:issue-68445, r=cjgillot
matthiaskrgr Oct 21, 2023
e9d18f5
Rollup merge of #116995 - estebank:issue-69944, r=compiler-errors
matthiaskrgr Oct 21, 2023
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
Next Next commit
Suggest relaxing implicit type Assoc: Sized; bound
Fix #85378.
  • Loading branch information
estebank committed Oct 19, 2023
commit e8d4fb8aaafa598d3021f2378705f780ee173458
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,29 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
// Check for foreign traits being reachable.
self.tcx.visible_parent_map(()).get(&def_id).is_some()
};
if Some(def_id) == self.tcx.lang_items().sized_trait()
&& let Some(hir::Node::TraitItem(hir::TraitItem {
ident,
kind: hir::TraitItemKind::Type(bounds, None),
..
})) = tcx.hir().get_if_local(item_def_id)
// Do not suggest relaxing if there is an explicit `Sized` obligation.
&& !bounds.iter()
.filter_map(|bound| bound.trait_ref())
.any(|tr| tr.trait_def_id() == self.tcx.lang_items().sized_trait())
{
let (span, separator) = if let [.., last] = bounds {
(last.span().shrink_to_hi(), " +")
} else {
(ident.span.shrink_to_hi(), ":")
};
err.span_suggestion_verbose(
span,
"consider relaxing the implicit `Sized` restriction",
format!("{separator} ?Sized"),
Applicability::MachineApplicable,
);
}
if let DefKind::Trait = tcx.def_kind(item_def_id)
&& !visible_item
{
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/object-safety/assoc_type_bounds_implicit_sized.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// run-rustfix
trait TraitWithAType {
type Item: ?Sized;
}
trait Trait {}
struct A {}
impl TraitWithAType for A {
type Item = dyn Trait; //~ ERROR E0277
}
fn main() {}
10 changes: 10 additions & 0 deletions tests/ui/object-safety/assoc_type_bounds_implicit_sized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// run-rustfix
trait TraitWithAType {
type Item;
}
trait Trait {}
struct A {}
impl TraitWithAType for A {
type Item = dyn Trait; //~ ERROR E0277
}
fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/object-safety/assoc_type_bounds_implicit_sized.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0277]: the size for values of type `(dyn Trait + 'static)` cannot be known at compilation time
--> $DIR/assoc_type_bounds_implicit_sized.rs:8:17
|
LL | type Item = dyn Trait;
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn Trait + 'static)`
note: required by a bound in `TraitWithAType::Item`
--> $DIR/assoc_type_bounds_implicit_sized.rs:3:5
|
LL | type Item;
| ^^^^^^^^^^ required by this bound in `TraitWithAType::Item`
help: consider relaxing the implicit `Sized` restriction
|
LL | type Item: ?Sized;
| ++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
4 changes: 4 additions & 0 deletions tests/ui/object-safety/assoc_type_bounds_sized_used.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ help: consider removing the `?Sized` bound to make the type parameter `Sized`
LL - fn bop<T: Bop + ?Sized>() {
LL + fn bop<T: Bop>() {
|
help: consider relaxing the implicit `Sized` restriction
|
LL | type Bar: Default + ?Sized
| ++++++++

error: aborting due to 2 previous errors

Expand Down