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

Use typeck_results to avoid duplicate ast_ty_to_ty call #99352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 5 additions & 13 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,19 +1791,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.flat_map(|a| a.args.iter())
{
if let hir::GenericArg::Type(hir_ty) = &arg {
if let hir::TyKind::Path(hir::QPath::TypeRelative(..)) =
&hir_ty.kind
{
// Avoid ICE with associated types. As this is best
// effort only, it's ok to ignore the case. It
// would trigger in `is_send::<T::AssocType>();`
// from `typeck-default-trait-impl-assoc-type.rs`.
} else {
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, hir_ty);
let ty = self.resolve_vars_if_possible(ty);
if ty == predicate.self_ty() {
error.obligation.cause.span = hir_ty.span;
}
let ty = self.resolve_vars_if_possible(
self.typeck_results.borrow().node_type(hir_ty.hir_id),
);
if ty == predicate.self_ty() {
error.obligation.cause.span = hir_ty.span;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/kindck/kindck-copy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ LL | fn assert_copy<T:Copy>() { }
| ^^^^ required by this bound in `assert_copy`

error[E0277]: the trait bound `Box<dyn Dummy>: Copy` is not satisfied
--> $DIR/kindck-copy.rs:42:5
--> $DIR/kindck-copy.rs:42:19
|
LL | assert_copy::<Box<dyn Dummy>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy>`
| ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy>`
|
note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18
Expand All @@ -103,10 +103,10 @@ LL | fn assert_copy<T:Copy>() { }
| ^^^^ required by this bound in `assert_copy`

error[E0277]: the trait bound `Box<dyn Dummy + Send>: Copy` is not satisfied
--> $DIR/kindck-copy.rs:43:5
--> $DIR/kindck-copy.rs:43:19
|
LL | assert_copy::<Box<dyn Dummy + Send>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<dyn Dummy + Send>`
|
note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18
Expand Down
7 changes: 5 additions & 2 deletions src/test/ui/not-panic/not-panic-safe.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
error[E0277]: the type `&mut i32` may not be safely transferred across an unwind boundary
--> $DIR/not-panic-safe.rs:8:5
--> $DIR/not-panic-safe.rs:8:14
|
LL | assert::<&mut i32>();
| ^^^^^^^^^^^^^^^^^^ `&mut i32` may not be safely transferred across an unwind boundary
| -^^^^^^^
| |
| `&mut i32` may not be safely transferred across an unwind boundary
| help: consider removing the leading `&`-reference
|
= help: the trait `UnwindSafe` is not implemented for `&mut i32`
= note: `UnwindSafe` is implemented for `&i32`, but not for `&mut i32`
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/traits/issue-32963.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
fn main() {
size_of_copy::<dyn Misc + Copy>();
//~^ ERROR only auto traits can be used as additional traits in a trait object
//~| ERROR only auto traits can be used as additional traits in a trait object
//~| ERROR the trait bound `dyn Misc: Copy` is not satisfied
}
17 changes: 3 additions & 14 deletions src/test/ui/traits/issue-32963.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,19 @@ LL | size_of_copy::<dyn Misc + Copy>();
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Misc + Copy {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>

error[E0225]: only auto traits can be used as additional traits in a trait object
--> $DIR/issue-32963.rs:8:31
|
LL | size_of_copy::<dyn Misc + Copy>();
| ---- ^^^^ additional non-auto trait
| |
| first non-auto trait
|
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Misc + Copy {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>

error[E0277]: the trait bound `dyn Misc: Copy` is not satisfied
--> $DIR/issue-32963.rs:8:5
--> $DIR/issue-32963.rs:8:20
|
LL | size_of_copy::<dyn Misc + Copy>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `dyn Misc`
| ^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `dyn Misc`
|
note: required by a bound in `size_of_copy`
--> $DIR/issue-32963.rs:5:20
|
LL | fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
| ^^^^ required by this bound in `size_of_copy`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0225, E0277.
For more information about an error, try `rustc --explain E0225`.
4 changes: 2 additions & 2 deletions src/test/ui/traits/suggest-where-clause.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ LL | pub const fn size_of<T>() -> usize {
| ^ required by this bound in `std::mem::size_of`

error[E0277]: the size for values of type `[&U]` cannot be known at compilation time
--> $DIR/suggest-where-clause.rs:31:5
--> $DIR/suggest-where-clause.rs:31:20
|
LL | mem::size_of::<[&U]>();
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
| ^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `[&U]`
note: required by a bound in `std::mem::size_of`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: `<T as Trait>::AssocType` cannot be sent between threads safely
--> $DIR/typeck-default-trait-impl-assoc-type.rs:11:5
--> $DIR/typeck-default-trait-impl-assoc-type.rs:11:15
|
LL | is_send::<T::AssocType>();
| ^^^^^^^^^^^^^^^^^^^^^^^ `<T as Trait>::AssocType` cannot be sent between threads safely
| ^^^^^^^^^^^^ `<T as Trait>::AssocType` cannot be sent between threads safely
|
= help: the trait `Send` is not implemented for `<T as Trait>::AssocType`
note: required by a bound in `is_send`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `dyn Foo<(isize,), isize, Output = ()>: Eq<dyn Foo<(isize,), Output = ()>>` is not satisfied
--> $DIR/unboxed-closure-sugar-default.rs:21:5
--> $DIR/unboxed-closure-sugar-default.rs:21:10
|
LL | eq::<dyn Foo<(isize,), isize, Output=()>, dyn Foo(isize)>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq<dyn Foo<(isize,), Output = ()>>` is not implemented for `dyn Foo<(isize,), isize, Output = ()>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Eq<dyn Foo<(isize,), Output = ()>>` is not implemented for `dyn Foo<(isize,), isize, Output = ()>`
|
note: required by a bound in `eq`
--> $DIR/unboxed-closure-sugar-default.rs:14:40
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn test<'a,'b>() {
// Errors expected:
eq::< dyn Foo<(),Output=()>,
dyn Foo(char) >();
//~^^ ERROR E0277
//~^ ERROR E0277
}

fn main() { }
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
error[E0277]: the trait bound `dyn Foo<(char,), Output = ()>: Eq<dyn Foo<(), Output = ()>>` is not satisfied
--> $DIR/unboxed-closure-sugar-equiv.rs:43:5
--> $DIR/unboxed-closure-sugar-equiv.rs:44:11
|
LL | / eq::< dyn Foo<(),Output=()>,
LL | | dyn Foo(char) >();
| |_______________________________________________________________________^ the trait `Eq<dyn Foo<(), Output = ()>>` is not implemented for `dyn Foo<(char,), Output = ()>`
LL | dyn Foo(char) >();
| ^^^^^^^^^^^^^ the trait `Eq<dyn Foo<(), Output = ()>>` is not implemented for `dyn Foo<(char,), Output = ()>`
|
note: required by a bound in `eq`
--> $DIR/unboxed-closure-sugar-equiv.rs:16:28
Expand Down