diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index f83433c2bd503..2ba7e026461f3 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -563,8 +563,8 @@ pub(crate) fn reborrow_info<'tcx>( ) .is_ok() { - // Field implements Reborrow. - return Ok(()); + // Field implements Reborrow, check remaining fields. + continue; } // Field does not implement Reborrow: it must be Copy. diff --git a/tests/ui/reborrow/reborrow_multi_field_validation.rs b/tests/ui/reborrow/reborrow_multi_field_validation.rs new file mode 100644 index 0000000000000..9be4dd89f16c0 --- /dev/null +++ b/tests/ui/reborrow/reborrow_multi_field_validation.rs @@ -0,0 +1,15 @@ +#![feature(reborrow)] + +use std::marker::Reborrow; + +// Regression test: `reborrow_info` must validate ALL data fields, +// not just stop at the first Reborrow field. + +struct Bad<'a> { + first: &'a mut i32, + second: String, //~ ERROR the trait bound `String: Copy` is not satisfied +} + +impl<'a> Reborrow for Bad<'a> {} + +fn main() {} diff --git a/tests/ui/reborrow/reborrow_multi_field_validation.stderr b/tests/ui/reborrow/reborrow_multi_field_validation.stderr new file mode 100644 index 0000000000000..26d52818beeff --- /dev/null +++ b/tests/ui/reborrow/reborrow_multi_field_validation.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/reborrow_multi_field_validation.rs:10:5 + | +LL | second: String, + | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`.