Skip to content

Commit 1138036

Browse files
committed
Auto merge of rust-lang#126593 - matthiaskrgr:rollup-a5jfg7w, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#126568 (mark undetermined if target binding in current ns is not got) - rust-lang#126577 (const_refs_to_static test and cleanup) - rust-lang#126584 (Do not ICE in privacy when type inference fails.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9b584a6 + 592f9aa commit 1138036

14 files changed

+161
-50
lines changed

Diff for: compiler/rustc_const_eval/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ const_eval_unwind_past_top =
399399
400400
## The `front_matter`s here refer to either `const_eval_front_matter_invalid_value` or `const_eval_front_matter_invalid_value_with_path`.
401401
## (We'd love to sort this differently to make that more clear but tidy won't let us...)
402-
const_eval_validation_box_to_static = {$front_matter}: encountered a box pointing to a static variable in a constant
403402
const_eval_validation_box_to_uninhabited = {$front_matter}: encountered a box pointing to uninhabited type {$ty}
404403
405404
const_eval_validation_const_ref_to_extern = {$front_matter}: encountered reference to `extern` static in `const`
@@ -454,7 +453,6 @@ const_eval_validation_out_of_range = {$front_matter}: encountered {$value}, but
454453
const_eval_validation_partial_pointer = {$front_matter}: encountered a partial pointer or a mix of pointers
455454
const_eval_validation_pointer_as_int = {$front_matter}: encountered a pointer, but {$expected}
456455
const_eval_validation_ptr_out_of_range = {$front_matter}: encountered a pointer, but expected something that cannot possibly fail to be {$in_range}
457-
const_eval_validation_ref_to_static = {$front_matter}: encountered a reference pointing to a static variable in a constant
458456
const_eval_validation_ref_to_uninhabited = {$front_matter}: encountered a reference pointing to uninhabited type {$ty}
459457
const_eval_validation_unaligned_box = {$front_matter}: encountered an unaligned box (required {$required_bytes} byte alignment but found {$found_bytes})
460458
const_eval_validation_unaligned_ref = {$front_matter}: encountered an unaligned reference (required {$required_bytes} byte alignment but found {$found_bytes})

Diff for: compiler/rustc_const_eval/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
640640
const_eval_validation_ref_to_uninhabited
641641
}
642642

643-
PtrToStatic { ptr_kind: PointerKind::Box } => const_eval_validation_box_to_static,
644-
PtrToStatic { ptr_kind: PointerKind::Ref(_) } => const_eval_validation_ref_to_static,
645-
646643
PointerAsInt { .. } => const_eval_validation_pointer_as_int,
647644
PartialPointer => const_eval_validation_partial_pointer,
648645
ConstRefToMutable => const_eval_validation_const_ref_to_mutable,
@@ -807,7 +804,6 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
807804
);
808805
}
809806
NullPtr { .. }
810-
| PtrToStatic { .. }
811807
| ConstRefToMutable
812808
| ConstRefToExtern
813809
| MutableRefToImmutable

Diff for: compiler/rustc_middle/src/mir/interpret/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,6 @@ pub enum ValidationErrorKind<'tcx> {
438438
ptr_kind: PointerKind,
439439
ty: Ty<'tcx>,
440440
},
441-
PtrToStatic {
442-
ptr_kind: PointerKind,
443-
},
444441
ConstRefToMutable,
445442
ConstRefToExtern,
446443
MutableRefToImmutable,

Diff for: compiler/rustc_privacy/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,12 @@ impl<'tcx> NamePrivacyVisitor<'tcx> {
973973

974974
impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> {
975975
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
976-
let old_maybe_typeck_results =
977-
self.maybe_typeck_results.replace(self.tcx.typeck_body(body_id));
976+
let new_typeck_results = self.tcx.typeck_body(body_id);
977+
// Do not try reporting privacy violations if we failed to infer types.
978+
if new_typeck_results.tainted_by_errors.is_some() {
979+
return;
980+
}
981+
let old_maybe_typeck_results = self.maybe_typeck_results.replace(new_typeck_results);
978982
self.visit_body(self.tcx.hir().body(body_id));
979983
self.maybe_typeck_results = old_maybe_typeck_results;
980984
}

Diff for: compiler/rustc_resolve/src/ident.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
966966
for single_import in &resolution.single_imports {
967967
let Some(import_vis) = single_import.vis.get() else {
968968
// This branch handles a cycle in single imports, which occurs
969-
// when we've previously captured the `vis` value during an import
969+
// when we've previously **steal** the `vis` value during an import
970970
// process.
971971
//
972972
// For example:
@@ -998,21 +998,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
998998
let Some(module) = single_import.imported_module.get() else {
999999
return Err((Undetermined, Weak::No));
10001000
};
1001-
let ImportKind::Single { source: ident, target, target_bindings, .. } =
1002-
&single_import.kind
1001+
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
10031002
else {
10041003
unreachable!();
10051004
};
1006-
if (ident != target) && target_bindings.iter().all(|binding| binding.get().is_none()) {
1005+
if source != target {
10071006
// This branch allows the binding to be defined or updated later if the target name
1008-
// can hide the source but these bindings are not obtained.
1009-
// avoiding module inconsistency between the resolve process and the finalize process.
1010-
// See more details in #124840
1011-
return Err((Undetermined, Weak::No));
1007+
// can hide the source.
1008+
if target_bindings.iter().all(|binding| binding.get().is_none()) {
1009+
// None of the target bindings are available, so we can't determine
1010+
// if this binding is correct or not.
1011+
// See more details in #124840
1012+
return Err((Undetermined, Weak::No));
1013+
} else if target_bindings[ns].get().is_none() && binding.is_some() {
1014+
// `binding.is_some()` avoids the condition where the binding
1015+
// truly doesn't exist in this namespace and should return `Err(Determined)`.
1016+
return Err((Undetermined, Weak::No));
1017+
}
10121018
}
1019+
10131020
match self.resolve_ident_in_module(
10141021
module,
1015-
*ident,
1022+
*source,
10161023
ns,
10171024
&single_import.parent_scope,
10181025
None,

Diff for: tests/crashes/126376.rs

-14
This file was deleted.

Diff for: tests/crashes/126389.rs

-15
This file was deleted.

Diff for: tests/ui/imports/shadow-glob-module-resolution-3.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://github.com/rust-lang/rust/issues/126389
2+
3+
mod a {
4+
pub mod b {
5+
pub mod c {}
6+
}
7+
}
8+
9+
use a::*;
10+
11+
use b::c;
12+
//~^ ERROR: unresolved import `b::c`
13+
//~| ERROR: cannot determine resolution for the import
14+
//~| ERROR: cannot determine resolution for the import
15+
use c as b;
16+
17+
fn c() {}
18+
19+
fn main() { }
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: cannot determine resolution for the import
2+
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
3+
|
4+
LL | use b::c;
5+
| ^^^^
6+
7+
error: cannot determine resolution for the import
8+
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
9+
|
10+
LL | use b::c;
11+
| ^^^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error[E0432]: unresolved import `b::c`
16+
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
17+
|
18+
LL | use b::c;
19+
| ^^^^
20+
21+
error: aborting due to 3 previous errors
22+
23+
For more information about this error, try `rustc --explain E0432`.

Diff for: tests/ui/imports/shadow-glob-module-resolution-4.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://github.com/rust-lang/rust/issues/126376
2+
3+
mod a {
4+
pub mod b {
5+
pub trait C {}
6+
}
7+
}
8+
9+
use a::*;
10+
11+
use e as b;
12+
13+
use b::C as e;
14+
//~^ ERROR: unresolved import `b::C`
15+
//~| ERROR: cannot determine resolution for the import
16+
//~| ERROR: cannot determine resolution for the import
17+
18+
fn e() {}
19+
20+
fn main() { }
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: cannot determine resolution for the import
2+
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
3+
|
4+
LL | use b::C as e;
5+
| ^^^^^^^^^
6+
7+
error: cannot determine resolution for the import
8+
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
9+
|
10+
LL | use b::C as e;
11+
| ^^^^^^^^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error[E0432]: unresolved import `b::C`
16+
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
17+
|
18+
LL | use b::C as e;
19+
| ^^^^^^^^^
20+
21+
error: aborting due to 3 previous errors
22+
23+
For more information about this error, try `rustc --explain E0432`.

Diff for: tests/crashes/122736.rs renamed to tests/ui/privacy/no-ice-on-inference-failure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//@ known-bug: #122736
21
fn main_ref() {
32
let array = [(); {
43
let mut x = &0;
54
let mut n = 0;
65
while n < 5 {
6+
//~^ ERROR constant evaluation is taking a long time
77
x = &0;
88
}
99
0

Diff for: tests/ui/privacy/no-ice-on-inference-failure.stderr

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/no-ice-on-inference-failure.rs:5:9
3+
|
4+
LL | / while n < 5 {
5+
LL | |
6+
LL | | x = &0;
7+
LL | | }
8+
| |_________^
9+
|
10+
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
11+
If your compilation actually takes a long time, you can safely allow the lint.
12+
help: the constant being evaluated
13+
--> $DIR/no-ice-on-inference-failure.rs:2:22
14+
|
15+
LL | let array = [(); {
16+
| ______________________^
17+
LL | | let mut x = &0;
18+
LL | | let mut n = 0;
19+
LL | | while n < 5 {
20+
... |
21+
LL | | 0
22+
LL | | }];
23+
| |_____^
24+
= note: `#[deny(long_running_const_eval)]` on by default
25+
26+
error: aborting due to 1 previous error
27+

Diff for: tests/ui/statics/const_generics.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! Check that we lose the information that `BAR` points to `FOO`
2+
//! when going through a const generic.
3+
//! This is not an intentional guarantee, it just describes the status quo.
4+
5+
//@ run-pass
6+
// With optimizations, LLVM will deduplicate the constant `X` whose
7+
// value is `&42` to just be a reference to the static. This is correct,
8+
// but obscures the issue we're trying to show.
9+
//@ revisions: opt noopt
10+
//@[noopt] compile-flags: -Copt-level=0
11+
//@[opt] compile-flags: -O
12+
13+
#![feature(const_refs_to_static)]
14+
#![feature(adt_const_params)]
15+
#![allow(incomplete_features)]
16+
17+
static FOO: usize = 42;
18+
const BAR: &usize = &FOO;
19+
fn foo<const X: &'static usize>() {
20+
// Without optimizations, `X` ends up pointing to a copy of `FOO` instead of `FOO` itself.
21+
assert_eq!(cfg!(opt), std::ptr::eq(X, &FOO));
22+
}
23+
24+
fn main() {
25+
foo::<BAR>();
26+
}

0 commit comments

Comments
 (0)