Skip to content

Commit

Permalink
Auto merge of rust-lang#109690 - matthiaskrgr:rollup-6p5m0es, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#108548 (Clarify the 'use a constant in a pattern' error message)
 - rust-lang#109565 (Improve documentation for E0223)
 - rust-lang#109661 (Fix LVI test post LLVM 16 update)
 - rust-lang#109667 (Always set `RUSTC_BOOTSTRAP` with `x doc`)
 - rust-lang#109669 (Update books)
 - rust-lang#109678 (Don't shadow the `dep_node` var in `incremental_verify_ich_failed`)
 - rust-lang#109682 (Add `#[inline]` to CStr trait implementations)
 - rust-lang#109685 (Make doc comment a little bit more accurate)
 - rust-lang#109687 (Document the heuristics IsTerminal uses on Windows)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 28, 2023
2 parents cbc064b + a694960 commit f418859
Show file tree
Hide file tree
Showing 44 changed files with 215 additions and 41 deletions.
28 changes: 15 additions & 13 deletions compiler/rustc_error_codes/src/error_codes/E0223.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@ An attempt was made to retrieve an associated type, but the type was ambiguous.
Erroneous code example:

```compile_fail,E0223
trait MyTrait {type X; }
trait Trait { type X; }
fn main() {
let foo: MyTrait::X;
let foo: Trait::X;
}
```

The problem here is that we're attempting to take the type of X from MyTrait.
Unfortunately, the type of X is not defined, because it's only made concrete in
implementations of the trait. A working version of this code might look like:
The problem here is that we're attempting to take the associated type of `X`
from `Trait`. Unfortunately, the type of `X` is not defined, because it's only
made concrete in implementations of the trait. A working version of this code
might look like:

```
trait MyTrait {type X; }
struct MyStruct;
trait Trait { type X; }
impl MyTrait for MyStruct {
struct Struct;
impl Trait for Struct {
type X = u32;
}
fn main() {
let foo: <MyStruct as MyTrait>::X;
let foo: <Struct as Trait>::X;
}
```

This syntax specifies that we want the X type from MyTrait, as made concrete in
MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct
might implement two different traits with identically-named associated types.
This syntax allows disambiguation between the two.
This syntax specifies that we want the associated type `X` from `Struct`'s
implementation of `Trait`.

Due to internal limitations of the current compiler implementation we cannot
simply use `Struct::X`.
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub type MakeBackendFn = fn() -> Box<dyn CodegenBackend>;
/// specific features (SSE, NEON etc.).
///
/// This is performed by checking whether a set of permitted features
/// is available on the target machine, by querying LLVM.
/// is available on the target machine, by querying the codegen backend.
pub fn add_configuration(
cfg: &mut CrateConfig,
sess: &mut Session,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_mir_build/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ mir_build_indirect_structural_match =
mir_build_nontrivial_structural_match =
to use a constant of type `{$non_sm_ty}` in a pattern, the constant's initializer must be trivial or `{$non_sm_ty}` must be annotated with `#[derive(PartialEq, Eq)]`
mir_build_type_not_structural_tip = the traits must be derived, manual `impl`s are not sufficient
mir_build_type_not_structural_more_info = see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
mir_build_overlapping_range_endpoints = multiple patterns overlap on their endpoints
.range = ... with this range
.note = you likely meant to write mutually exclusive ranges
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ pub struct UnionPattern {

#[derive(Diagnostic)]
#[diag(mir_build_type_not_structural)]
#[note(mir_build_type_not_structural_tip)]
#[note(mir_build_type_not_structural_more_info)]
pub struct TypeNotStructural<'tcx> {
#[primary_span]
pub span: Span,
Expand Down Expand Up @@ -695,12 +697,16 @@ pub struct PointerPattern;

#[derive(LintDiagnostic)]
#[diag(mir_build_indirect_structural_match)]
#[note(mir_build_type_not_structural_tip)]
#[note(mir_build_type_not_structural_more_info)]
pub struct IndirectStructuralMatch<'tcx> {
pub non_sm_ty: Ty<'tcx>,
}

#[derive(LintDiagnostic)]
#[diag(mir_build_nontrivial_structural_match)]
#[note(mir_build_type_not_structural_tip)]
#[note(mir_build_type_not_structural_more_info)]
pub struct NontrivialStructuralMatch<'tcx> {
pub non_sm_ty: Ty<'tcx>,
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_query_system/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,7 @@ fn incremental_verify_ich_failed<Tcx>(
};

let dep_node = tcx.dep_graph().data().unwrap().prev_node_of(prev_index);

let dep_node = tcx.sess().emit_err(crate::error::IncrementCompilation {
tcx.sess().emit_err(crate::error::IncrementCompilation {
run_cmd,
dep_node: format!("{dep_node:?}"),
});
Expand Down
5 changes: 5 additions & 0 deletions library/core/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl fmt::Debug for CStr {

#[stable(feature = "cstr_default", since = "1.10.0")]
impl Default for &CStr {
#[inline]
fn default() -> Self {
const SLICE: &[c_char] = &[0];
// SAFETY: `SLICE` is indeed pointing to a valid nul-terminated string.
Expand Down Expand Up @@ -623,6 +624,7 @@ impl CStr {

#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for CStr {
#[inline]
fn eq(&self, other: &CStr) -> bool {
self.to_bytes().eq(other.to_bytes())
}
Expand All @@ -631,12 +633,14 @@ impl PartialEq for CStr {
impl Eq for CStr {}
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialOrd for CStr {
#[inline]
fn partial_cmp(&self, other: &CStr) -> Option<Ordering> {
self.to_bytes().partial_cmp(&other.to_bytes())
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Ord for CStr {
#[inline]
fn cmp(&self, other: &CStr) -> Ordering {
self.to_bytes().cmp(&other.to_bytes())
}
Expand All @@ -646,6 +650,7 @@ impl Ord for CStr {
impl ops::Index<ops::RangeFrom<usize>> for CStr {
type Output = CStr;

#[inline]
fn index(&self, index: ops::RangeFrom<usize>) -> &CStr {
let bytes = self.to_bytes_with_nul();
// we need to manually check the starting index to account for the null
Expand Down
9 changes: 9 additions & 0 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,15 @@ pub trait IsTerminal: crate::sealed::Sealed {
/// On platforms where Rust does not know how to detect a terminal yet, this will return
/// `false`. This will also return `false` if an unexpected error occurred, such as from
/// passing an invalid file descriptor.
///
/// # Platform-specific behavior
///
/// On Windows, in addition to detecting consoles, this currently uses some heuristics to
/// detect older msys/cygwin/mingw pseudo-terminals based on device name: devices with names
/// starting with `msys-` or `cygwin-` and ending in `-pty` will be considered terminals.
/// Note that this [may change in the future][changes].
///
/// [changes]: io#platform-specific-behavior
fn is_terminal(&self) -> bool;
}

Expand Down
9 changes: 5 additions & 4 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,11 @@ impl Step for RustcBook {
if self.validate {
cmd.arg("--validate");
}
if !builder.unstable_features() {
// We need to validate nightly features, even on the stable channel.
cmd.env("RUSTC_BOOTSTRAP", "1");
}
// We need to validate nightly features, even on the stable channel.
// Set this unconditionally as the stage0 compiler may be being used to
// document.
cmd.env("RUSTC_BOOTSTRAP", "1");

// If the lib directories are in an unusual location (changed in
// config.toml), then this needs to explicitly update the dylib search
// path.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/nomicon
Submodule nomicon updated 1 files
+1 −1 src/subtyping.md
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 2 additions & 0 deletions src/tools/clippy/tests/ui/crashes/ice-6254.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LL | FOO_REF_REF => {},
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 </~https://github.com/rust-lang/rust/issues/62411>
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
= note: `-D indirect-structural-match` implied by `-D warnings`

error: aborting due to previous error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ CHECK: cc_plus_one_asm
CHECK-NEXT: movl
CHECK-NEXT: lfence
CHECK-NEXT: incl
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CHECK: lfence
CHECK: lfence
CHECK-NEXT: incl
CHECK-NEXT: jmp
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
CHECK: popq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CHECK: lfence
CHECK: lfence
CHECK-NEXT: incl
CHECK-NEXT: jmp 0x{{[[:xdigit:]]+}} <cc_plus_one_cxx_asm+0x{{[[:xdigit:]]+}}>
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
CHECK: popq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ CHECK: cmake_plus_one_asm
CHECK-NEXT: movl
CHECK-NEXT: lfence
CHECK-NEXT: incl
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CHECK: movl
CHECK: lfence
CHECK-NEXT: incl
CHECK-NEXT: jmp 0x{{[[:xdigit:]]+}} <cmake_plus_one_c_asm+0x{{[[:xdigit:]]+}}>
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
CHECK: popq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CHECK: movl
CHECK: lfence
CHECK-NEXT: incl
CHECK-NEXT: jmp 0x{{[[:xdigit:]]+}} <cmake_plus_one_cxx_asm+0x{{[[:xdigit:]]+}}>
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
CHECK: popq
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CHECK: unw_getcontext
CHECK: lfence
CHECK: lfence
CHECK: shlq $0, (%rsp)
CHECK: shlq $0x0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
6 changes: 6 additions & 0 deletions tests/ui/consts/const_in_pattern/cross-crate-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be ann
|
LL | consts::SOME => panic!(),
| ^^^^^^^^^^^^
|
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/cross-crate-fail.rs:20:9
|
LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: aborting due to 2 previous errors

2 changes: 2 additions & 0 deletions tests/ui/consts/const_in_pattern/custom-eq-branch-warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fn main() {
match Foo::Qux(CustomEq) {
BAR_BAZ => panic!(),
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details
//~| WARN this was previously accepted
//~| NOTE see issue #73448
//~| NOTE `#[warn(nontrivial_structural_match)]` on by default
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/consts/const_in_pattern/custom-eq-branch-warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LL | BAR_BAZ => panic!(),
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #73448 </~https://github.com/rust-lang/rust/issues/73448>
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
= note: `#[warn(nontrivial_structural_match)]` on by default

warning: 1 warning emitted
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/consts/const_in_pattern/incomplete-slice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ LL | E_SL => {}
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #62411 </~https://github.com/rust-lang/rust/issues/62411>
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
= note: `#[warn(indirect_structural_match)]` on by default

error[E0004]: non-exhaustive patterns: `&_` not covered
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/consts/const_in_pattern/issue-78057.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ error: to use a constant of type `Opaque` in a pattern, `Opaque` must be annotat
|
LL | FOO => {},
| ^^^
|
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: unreachable pattern
--> $DIR/issue-78057.rs:14:9
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/consts/const_in_pattern/no-eq-branch-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated wit
|
LL | BAR_BAZ => panic!(),
| ^^^^^^^
|
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: aborting due to previous error

3 changes: 3 additions & 0 deletions tests/ui/consts/const_in_pattern/reject_non_partial_eq.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ error: to use a constant of type `NoPartialEq` in a pattern, `NoPartialEq` must
|
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
| ^^^^^^^^^^^^^^^^^^
|
= note: the traits must be derived, manual `impl`s are not sufficient
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details

error: aborting due to previous error

22 changes: 22 additions & 0 deletions tests/ui/consts/const_in_pattern/reject_non_structural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,67 @@ fn main() {
const ENUM: Derive<NoDerive> = Derive::Some(NoDerive);
match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const FIELD: OND = TrivialEq(Some(NoDerive)).0;
match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const NO_DERIVE_SOME: OND = Some(NoDerive);
const INDIRECT: OND = NO_DERIVE_SOME;
match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const TUPLE: (OND, OND) = (None, Some(NoDerive));
match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const TYPE_ASCRIPTION: OND = type_ascribe!(Some(NoDerive), OND);
match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const ARRAY: [OND; 2] = [None, Some(NoDerive)];
match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const REPEAT: [OND; 2] = [Some(NoDerive); 2];
match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details
//~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

trait Trait: Sized { const ASSOC: Option<Self>; }
impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const BLOCK: OND = { NoDerive; Some(NoDerive) };
match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details

const ADDR_OF: &OND = &Some(NoDerive);
match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
//~| NOTE the traits must be derived
//~| NOTE StructuralEq.html for details
//~| WARN previously accepted by the compiler but is being phased out
//~| NOTE for more information, see issue #62411
}
Loading

0 comments on commit f418859

Please sign in to comment.