Skip to content
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
dcfe92e
add `fetch_not` method on `AtomicBool`
Jun 25, 2022
7d5f236
Add feature gate `#![atomic_bool_fetch_not]`
Jun 25, 2022
0df7364
temporarily remove tests because I'm not sure if we need them
Jun 25, 2022
3b117c4
library: fix uefi va_list type definition
dlrobertson Jun 26, 2022
9c5ae20
forgot about the feature flag in the doctest
Jun 26, 2022
6e32a16
fix box with custom allocator in miri
beepster4096 Jun 26, 2022
d317988
validate box's allocator
beepster4096 Jun 27, 2022
7533777
Remove `final_arg_types`, improve tuple wrapping suggestion
compiler-errors Jun 28, 2022
9f9c311
Validate all fields of box instead of validating allocator specifically
beepster4096 Jun 28, 2022
5fc1dd1
emit Retag for compound types with reference fields
RalfJung Jun 28, 2022
9039265
fix silly mistake
beepster4096 Jun 28, 2022
98af1bf
Migrate some rustc_borrowck diagnostics to SessionDiagnostic
compiler-errors Jun 23, 2022
23f3b0d
Don't point at another arg if we're already pointing at one
compiler-errors Jun 29, 2022
1e40200
Erase regions in new abstract consts
JulianKnodt Jun 25, 2022
d10497b
Rollup merge of #98415 - compiler-errors:rustc-borrowck-session-diagn…
Dylan-DPC Jun 29, 2022
3f2ba25
Rollup merge of #98479 - leocth:atomic-bool-fetch-not, r=joshtriplett
Dylan-DPC Jun 29, 2022
7b9a7ef
Rollup merge of #98499 - JulianKnodt:erase_lifetime, r=lcnr
Dylan-DPC Jun 29, 2022
375ab3e
Rollup merge of #98516 - dlrobertson:uefi_va_list, r=joshtriplett
Dylan-DPC Jun 29, 2022
b2836bd
Rollup merge of #98554 - DrMeepster:box_unsizing_is_not_special, r=Ra…
Dylan-DPC Jun 29, 2022
fcbb2e8
Rollup merge of #98607 - compiler-errors:tuple-wrap-suggestion, r=oli…
Dylan-DPC Jun 29, 2022
68228be
Rollup merge of #98625 - RalfJung:retag, r=oli-obk
Dylan-DPC Jun 29, 2022
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
Prev Previous commit
Next Next commit
Don't point at another arg if we're already pointing at one
  • Loading branch information
compiler-errors committed Jun 29, 2022
commit 23f3b0dfd04812b03da0df4d5dfad0fef39c6862
38 changes: 30 additions & 8 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return;
}

for error in errors {
'outer: for error in errors {
// Only if the cause is somewhere inside the expression we want try to point at arg.
// Otherwise, it means that the cause is somewhere else and we should not change
// anything because we can break the correct span.
Expand Down Expand Up @@ -1671,10 +1671,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => continue,
};
let self_ = self.resolve_vars_if_possible(self_);
let ty_matches_self = |ty: Ty<'tcx>| ty.walk().any(|arg| arg == self_);

let typeck_results = self.typeck_results.borrow();

for (idx, arg) in args.iter().enumerate() {
// Don't adjust the span if we already have a more precise span
// within one of the args.
if arg.span.contains(error.obligation.cause.span) {
let references_arg =
typeck_results.expr_ty_opt(arg).map_or(false, &ty_matches_self)
|| expected_tys.get(idx).copied().map_or(false, &ty_matches_self);
if references_arg && !arg.span.from_expansion() {
error.obligation.cause.map_code(|parent_code| {
ObligationCauseCode::FunctionArgumentObligation {
arg_hir_id: args[idx].hir_id,
call_hir_id: expr.hir_id,
parent_code,
}
})
}
continue 'outer;
}
}

// Collect the argument position for all arguments that could have caused this
// `FulfillmentError`.
let typeck_results = self.typeck_results.borrow();
let mut referenced_in: Vec<_> = std::iter::zip(expected_tys, args)
.enumerate()
.flat_map(|(idx, (expected_ty, arg))| {
Expand All @@ -1688,7 +1710,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.resolve_vars_if_possible(ty);
// We walk the argument type because the argument's type could have
// been `Option<T>`, but the `FulfillmentError` references `T`.
if ty.walk().any(|arg| arg == self_) { Some(i) } else { None }
if ty_matches_self(ty) { Some(i) } else { None }
})
.collect();

Expand All @@ -1699,18 +1721,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
referenced_in.sort_unstable();
referenced_in.dedup();

if let (Some(ref_in), None) = (referenced_in.pop(), referenced_in.pop()) {
if let &[idx] = &referenced_in[..] {
// Do not point at the inside of a macro.
// That would often result in poor error messages.
if args[ref_in].span.from_expansion() {
return;
if args[idx].span.from_expansion() {
continue;
}
// We make sure that only *one* argument matches the obligation failure
// and we assign the obligation's span to its expression's.
error.obligation.cause.span = args[ref_in].span;
error.obligation.cause.span = args[idx].span;
error.obligation.cause.map_code(|parent_code| {
ObligationCauseCode::FunctionArgumentObligation {
arg_hir_id: args[ref_in].hir_id,
arg_hir_id: args[idx].hir_id,
call_hir_id: expr.hir_id,
parent_code,
}
Expand Down
5 changes: 1 addition & 4 deletions src/test/ui/proc-macro/signature.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ LL | / pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
LL | |
LL | | loop {}
LL | | }
| | ^
| | |
| |_call the function in a closure: `|| unsafe { /* code */ }`
| required by a bound introduced by this call
| |_^ call the function in a closure: `|| unsafe { /* code */ }`
|
= help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
= note: unsafe function cannot be called generically without an unsafe block
Expand Down
16 changes: 12 additions & 4 deletions src/test/ui/unsized/unsized-fn-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
--> $DIR/unsized-fn-param.rs:11:11
|
LL | foo11("bar", &"baz");
| ^^^^^ doesn't have a size known at compile-time
| ----- ^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast to the object type `dyn AsRef<Path>`
Expand All @@ -15,7 +17,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
--> $DIR/unsized-fn-param.rs:13:19
|
LL | foo12(&"bar", "baz");
| ^^^^^ doesn't have a size known at compile-time
| ----- ^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast to the object type `dyn AsRef<Path>`
Expand All @@ -28,7 +32,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
--> $DIR/unsized-fn-param.rs:16:11
|
LL | foo21("bar", &"baz");
| ^^^^^ doesn't have a size known at compile-time
| ----- ^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast to the object type `dyn AsRef<str>`
Expand All @@ -41,7 +47,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
--> $DIR/unsized-fn-param.rs:18:19
|
LL | foo22(&"bar", "baz");
| ^^^^^ doesn't have a size known at compile-time
| ----- ^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
= help: the trait `Sized` is not implemented for `str`
= note: required for the cast to the object type `dyn AsRef<str>`
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/unsized/unsized3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn f9<X: ?Sized>(x1: Box<S<X>>) {
fn f10<X: ?Sized>(x1: Box<S<X>>) {
f5(&(32, *x1));
//~^ ERROR the size for values of type
//~| ERROR the size for values of type
}

pub fn main() {}
35 changes: 33 additions & 2 deletions src/test/ui/unsized/unsized3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ LL - fn f9<X: ?Sized>(x1: Box<S<X>>) {
LL + fn f9<X>(x1: Box<S<X>>) {
|

error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized3.rs:45:9
|
LL | fn f10<X: ?Sized>(x1: Box<S<X>>) {
| - this type parameter needs to be `std::marker::Sized`
LL | f5(&(32, *x1));
| -- ^^^^^^^^^ doesn't have a size known at compile-time
| |
| required by a bound introduced by this call
|
note: required because it appears within the type `S<X>`
--> $DIR/unsized3.rs:28:8
|
LL | struct S<X: ?Sized> {
| ^
= note: required because it appears within the type `({integer}, S<X>)`
= note: tuples must have a statically known size to be initialized
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
LL - fn f10<X: ?Sized>(x1: Box<S<X>>) {
LL + fn f10<X>(x1: Box<S<X>>) {
|

error[E0277]: the size for values of type `X` cannot be known at compilation time
--> $DIR/unsized3.rs:45:8
|
Expand All @@ -116,13 +139,21 @@ note: required because it appears within the type `S<X>`
LL | struct S<X: ?Sized> {
| ^
= note: required because it appears within the type `({integer}, S<X>)`
= note: tuples must have a statically known size to be initialized
note: required by a bound in `f5`
--> $DIR/unsized3.rs:24:7
|
LL | fn f5<Y>(x: &Y) {}
| ^ required by this bound in `f5`
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
LL - fn f10<X: ?Sized>(x1: Box<S<X>>) {
LL + fn f10<X>(x1: Box<S<X>>) {
|
help: consider relaxing the implicit `Sized` restriction
|
LL | fn f5<Y: ?Sized>(x: &Y) {}
| ++++++++

error: aborting due to 5 previous errors
error: aborting due to 6 previous errors

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