Skip to content

Commit 83e49b7

Browse files
committed
Auto merge of #149591 - matthiaskrgr:rollup-b3zm9ke, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #148918 (Remove an outdated test) - #149244 (Fix std::mem::drop rustdoc misleading statement) - #149532 (Rename supertrait item shadowing lints) - #149541 (Various never type test improvements) - #149590 (linker: Remove special case for `rust-lld` in `detect_self_contained_mingw`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 568b117 + 2cc93b8 commit 83e49b7

File tree

83 files changed

+589
-823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+589
-823
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,10 +1763,6 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
17631763

17641764
// Returns true if linker is located within sysroot
17651765
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
1766-
// Assume `-C linker=rust-lld` as self-contained mode
1767-
if linker == Path::new("rust-lld") {
1768-
return true;
1769-
}
17701766
let linker_with_extension = if cfg!(windows) && linker.extension().is_none() {
17711767
linker.with_extension("exe")
17721768
} else {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::lang_items::LangItem;
1313
use rustc_hir::{AmbigArg, ItemKind, find_attr};
1414
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1515
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin, TyCtxtInferExt};
16-
use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
16+
use rustc_lint_defs::builtin::SHADOWING_SUPERTRAIT_ITEMS;
1717
use rustc_macros::LintDiagnostic;
1818
use rustc_middle::mir::interpret::ErrorHandled;
1919
use rustc_middle::traits::solve::NoSolution;
@@ -797,7 +797,7 @@ fn lint_item_shadowing_supertrait_item<'tcx>(tcx: TyCtxt<'tcx>, trait_item_def_i
797797
};
798798

799799
tcx.emit_node_span_lint(
800-
SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
800+
SHADOWING_SUPERTRAIT_ITEMS,
801801
tcx.local_def_id_to_hir_id(trait_item_def_id),
802802
tcx.def_span(trait_item_def_id),
803803
errors::SupertraitItemShadowing {

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir_analysis::hir_ty_lowering::{
1212
use rustc_infer::infer::{
1313
BoundRegionConversionTime, DefineOpaqueTypes, InferOk, RegionVariableOrigin,
1414
};
15-
use rustc_lint::builtin::SUPERTRAIT_ITEM_SHADOWING_USAGE;
15+
use rustc_lint::builtin::RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS;
1616
use rustc_middle::traits::ObligationCauseCode;
1717
use rustc_middle::ty::adjustment::{
1818
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
@@ -709,7 +709,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
709709
};
710710

711711
self.tcx.emit_node_span_lint(
712-
SUPERTRAIT_ITEM_SHADOWING_USAGE,
712+
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
713713
segment.hir_id,
714714
segment.ident.span,
715715
SupertraitItemShadowing { shadower, shadowee, item: segment.ident.name, subtrait },

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ declare_lint_pass! {
8888
RENAMED_AND_REMOVED_LINTS,
8989
REPR_C_ENUMS_LARGER_THAN_INT,
9090
REPR_TRANSPARENT_NON_ZST_FIELDS,
91+
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
9192
RTSAN_NONBLOCKING_ASYNC,
9293
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
9394
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
@@ -98,11 +99,10 @@ declare_lint_pass! {
9899
RUST_2024_PRELUDE_COLLISIONS,
99100
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
100101
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
102+
SHADOWING_SUPERTRAIT_ITEMS,
101103
SINGLE_USE_LIFETIMES,
102104
SOFT_UNSTABLE,
103105
STABLE_FEATURES,
104-
SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
105-
SUPERTRAIT_ITEM_SHADOWING_USAGE,
106106
TAIL_EXPR_DROP_ORDER,
107107
TEST_UNSTABLE_LINT,
108108
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
@@ -4922,15 +4922,16 @@ declare_lint! {
49224922
}
49234923

49244924
declare_lint! {
4925-
/// The `supertrait_item_shadowing_usage` lint detects when the
4925+
/// The `resolving_to_items_shadowing_supertrait_items` lint detects when the
49264926
/// usage of an item that is provided by both a subtrait and supertrait
49274927
/// is shadowed, preferring the subtrait.
49284928
///
49294929
/// ### Example
49304930
///
4931-
/// ```rust,compile_fail
4931+
#[cfg_attr(bootstrap, doc = "```ignore")]
4932+
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
49324933
/// #![feature(supertrait_item_shadowing)]
4933-
/// #![deny(supertrait_item_shadowing_usage)]
4934+
/// #![deny(resolving_to_items_shadowing_supertrait_items)]
49344935
///
49354936
/// trait Upstream {
49364937
/// fn hello(&self) {}
@@ -4944,7 +4945,8 @@ declare_lint! {
49444945
///
49454946
/// struct MyType;
49464947
/// MyType.hello();
4947-
/// ```
4948+
#[cfg_attr(bootstrap, doc = "```")]
4949+
#[cfg_attr(not(bootstrap), doc = "```")]
49484950
///
49494951
/// {{produces}}
49504952
///
@@ -4955,7 +4957,7 @@ declare_lint! {
49554957
/// selection. In order to mitigate side-effects of this happening
49564958
/// silently, this lint detects these cases when users want to deny them
49574959
/// or fix the call sites.
4958-
pub SUPERTRAIT_ITEM_SHADOWING_USAGE,
4960+
pub RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
49594961
// FIXME(supertrait_item_shadowing): It is not decided if this should
49604962
// warn by default at the call site.
49614963
Allow,
@@ -4964,15 +4966,16 @@ declare_lint! {
49644966
}
49654967

49664968
declare_lint! {
4967-
/// The `supertrait_item_shadowing_definition` lint detects when the
4969+
/// The `shadowing_supertrait_items` lint detects when the
49684970
/// definition of an item that is provided by both a subtrait and
49694971
/// supertrait is shadowed, preferring the subtrait.
49704972
///
49714973
/// ### Example
49724974
///
4973-
/// ```rust,compile_fail
4975+
#[cfg_attr(bootstrap, doc = "```ignore")]
4976+
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
49744977
/// #![feature(supertrait_item_shadowing)]
4975-
/// #![deny(supertrait_item_shadowing_definition)]
4978+
/// #![deny(shadowing_supertrait_items)]
49764979
///
49774980
/// trait Upstream {
49784981
/// fn hello(&self) {}
@@ -4983,7 +4986,8 @@ declare_lint! {
49834986
/// fn hello(&self) {}
49844987
/// }
49854988
/// impl<T> Downstream for T {}
4986-
/// ```
4989+
#[cfg_attr(bootstrap, doc = "```")]
4990+
#[cfg_attr(not(bootstrap), doc = "```")]
49874991
///
49884992
/// {{produces}}
49894993
///
@@ -4994,7 +4998,7 @@ declare_lint! {
49944998
/// selection. In order to mitigate side-effects of this happening
49954999
/// silently, this lint detects these cases when users want to deny them
49965000
/// or fix their trait definitions.
4997-
pub SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
5001+
pub SHADOWING_SUPERTRAIT_ITEMS,
49985002
// FIXME(supertrait_item_shadowing): It is not decided if this should
49995003
// warn by default at the usage site.
50005004
Allow,

library/core/src/mem/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,6 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
898898

899899
/// Disposes of a value.
900900
///
901-
/// This does so by calling the argument's implementation of [`Drop`][drop].
902-
///
903901
/// This effectively does nothing for types which implement `Copy`, e.g.
904902
/// integers. Such values are copied and _then_ moved into the function, so the
905903
/// value persists after this function call.
@@ -910,7 +908,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
910908
/// pub fn drop<T>(_x: T) {}
911909
/// ```
912910
///
913-
/// Because `_x` is moved into the function, it is automatically dropped before
911+
/// Because `_x` is moved into the function, it is automatically [dropped][drop] before
914912
/// the function returns.
915913
///
916914
/// [drop]: Drop

library/coretests/tests/convert.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,20 @@ fn convert() {
1414
const BAR: Vec<String> = into(Vec::new());
1515
assert_eq!(BAR, Vec::<String>::new());
1616
}
17+
18+
#[test]
19+
fn into_as_try_into() {
20+
struct A;
21+
struct B;
22+
23+
impl Into<B> for A {
24+
fn into(self) -> B {
25+
B
26+
}
27+
}
28+
29+
// This wouldn't compile if the `TryInto`/`TryFrom` blanket impls used
30+
// `U: From<T>` instead of `T: Into<U>`
31+
let Ok(B) = A.try_into();
32+
let Ok(B) = B::try_from(A);
33+
}

tests/ui/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ Contains a single test. It imports a massive amount of very similar types from a
941941

942942
## `tests/ui/never_type/`
943943

944+
Tests relating to the never type. Most tests are specifically about the never type fallback behavior.
945+
944946
See [Tracking issue for promoting `!` to a type (RFC 1216) #35121](https://github.com/rust-lang/rust/issues/35121).
945947

946948
## `tests/ui/new-range/`
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
2+
--> $DIR/coerce-issue-49593-box-never.rs:28:5
3+
|
4+
LL | Box::new(x)
5+
| ^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
6+
|
7+
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`
8+
9+
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
10+
--> $DIR/coerce-issue-49593-box-never.rs:33:5
11+
|
12+
LL | raw_ptr(x)
13+
| ^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
14+
|
15+
= note: required for the cast from `*mut ()` to `*mut (dyn std::error::Error + 'static)`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,37 @@
1-
//@ revisions: nofallback fallback
2-
//@[fallback] edition: 2024
3-
//@[fallback] check-pass
1+
// Regression test for <https://github.com/rust-lang/rust/issues/49593>.
2+
//
3+
// This checks that we can construct `Box<dyn Error>` by calling `Box::new`
4+
// with a value of the never type. And similarly for raw pointers.
5+
//
6+
// This used to fail because we tried to coerce `! -> dyn Error`, which then
7+
// failed because we were trying to pass an unsized value by value, etc.
8+
//
9+
// On edition <= 2021 this currently fails because of never type fallback to
10+
// unit.
11+
//
12+
//@ revisions: e2021 e2024
13+
//@[e2021] edition: 2021
14+
//@[e2024] edition: 2024
15+
//
16+
//@[e2024] check-pass
417

518
#![feature(never_type)]
619

720
use std::error::Error;
821
use std::mem;
922

10-
fn raw_ptr_box<T>(t: T) -> *mut T {
23+
fn raw_ptr<T>(t: T) -> *mut T {
1124
panic!()
1225
}
1326

1427
fn foo(x: !) -> Box<dyn Error> {
15-
// Method resolution will generate new inference vars and relate them.
16-
// Thus fallback will not fall back to `!`, but `()` instead.
17-
Box::<_ /* ! */>::new(x)
18-
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
28+
Box::new(x)
29+
//[e2021]~^ ERROR trait bound `(): std::error::Error` is not satisfied
1930
}
2031

2132
fn foo_raw_ptr(x: !) -> *mut dyn Error {
22-
/* *mut $0 is coerced to *mut Error here */
23-
raw_ptr_box::<_ /* ! */>(x)
24-
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
25-
}
26-
27-
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
28-
/* an unsize coercion won't compile here, and it is indeed not used
29-
because there is nothing requiring the _ to be Sized */
30-
d as *mut _
31-
}
32-
33-
trait Xyz {}
34-
struct S;
35-
struct T;
36-
impl Xyz for S {}
37-
impl Xyz for T {}
38-
39-
fn foo_no_never() {
40-
let mut x /* : Option<S> */ = None;
41-
let mut first_iter = false;
42-
loop {
43-
if !first_iter {
44-
let y: Box<dyn Xyz>
45-
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
46-
}
47-
48-
x = Some(S);
49-
first_iter = true;
50-
}
51-
52-
let mut y: Option<S> = None;
53-
// assert types are equal
54-
mem::swap(&mut x, &mut y);
33+
raw_ptr(x)
34+
//[e2021]~^ ERROR trait bound `(): std::error::Error` is not satisfied
5535
}
5636

5737
fn main() {}

tests/ui/coercion/coerce-to-bang.rs

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)