Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e645e51
Remove an outdated test
WaffleLapkin Nov 13, 2025
a37873d
add a coretest checking `TryInto`/`TryFrom` impls
WaffleLapkin Dec 1, 2025
d60f780
This statement is misleading
spastorino Nov 23, 2025
140832a
update readme wrt never type tests
WaffleLapkin Nov 13, 2025
3432ff9
remove test for `T -> !` coercion
WaffleLapkin Nov 13, 2025
e6d2b2a
refactor `Box<! -> dyn Error>` regression test
WaffleLapkin Nov 13, 2025
0cbb9e6
expand never type gate test
WaffleLapkin Nov 13, 2025
98430c4
remove unused features from some tests
WaffleLapkin Nov 13, 2025
5dec6b3
refactor test for note on `!: Tr` error
WaffleLapkin Nov 13, 2025
8c8d930
delete a duplicate test
WaffleLapkin Nov 13, 2025
109b6de
remove outdated tests
WaffleLapkin Nov 13, 2025
0104d69
move `tests/ui/{never => never_type}/*`
WaffleLapkin Nov 13, 2025
b1efa8e
stylistic test changes
WaffleLapkin Nov 13, 2025
e987343
merge `diverging-fallback-no-leak` into an existing test
WaffleLapkin Nov 13, 2025
7d33e7e
clarify purposes of tests
WaffleLapkin Nov 13, 2025
3f606fa
minor test improvements
WaffleLapkin Nov 13, 2025
cb5318d
stop using "nofallback" revision terminology
WaffleLapkin Nov 13, 2025
e833f24
Rename supertrait item shadowing lints
Amanieu Dec 2, 2025
388c42e
linker: Remove special case for `rust-lld` in `detect_self_contained_…
petrochenkov Dec 3, 2025
f6f7ddd
Rollup merge of #148918 - WaffleLapkin:tryfromwhattttt, r=jdonszelmann
matthiaskrgr Dec 3, 2025
1d3d73e
Rollup merge of #149244 - spastorino:fix-mem-drop-rustdoc, r=ChrisDenton
matthiaskrgr Dec 3, 2025
49e31cc
Rollup merge of #149532 - Amanieu:supertrait-shadowing-lints, r=lqd
matthiaskrgr Dec 3, 2025
a2aa4f0
Rollup merge of #149541 - WaffleLapkin:never-test, r=lcnr
matthiaskrgr Dec 3, 2025
2cc93b8
Rollup merge of #149590 - petrochenkov:norlld, r=mati865
matthiaskrgr Dec 3, 2025
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
4 changes: 0 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,10 +1763,6 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {

// Returns true if linker is located within sysroot
fn detect_self_contained_mingw(sess: &Session, linker: &Path) -> bool {
// Assume `-C linker=rust-lld` as self-contained mode
if linker == Path::new("rust-lld") {
return true;
}
let linker_with_extension = if cfg!(windows) && linker.extension().is_none() {
linker.with_extension("exe")
} else {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{AmbigArg, ItemKind, find_attr};
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::{self, InferCtxt, SubregionOrigin, TyCtxtInferExt};
use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
use rustc_lint_defs::builtin::SHADOWING_SUPERTRAIT_ITEMS;
use rustc_macros::LintDiagnostic;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::traits::solve::NoSolution;
Expand Down Expand Up @@ -797,7 +797,7 @@ fn lint_item_shadowing_supertrait_item<'tcx>(tcx: TyCtxt<'tcx>, trait_item_def_i
};

tcx.emit_node_span_lint(
SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
SHADOWING_SUPERTRAIT_ITEMS,
tcx.local_def_id_to_hir_id(trait_item_def_id),
tcx.def_span(trait_item_def_id),
errors::SupertraitItemShadowing {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_hir_analysis::hir_ty_lowering::{
use rustc_infer::infer::{
BoundRegionConversionTime, DefineOpaqueTypes, InferOk, RegionVariableOrigin,
};
use rustc_lint::builtin::SUPERTRAIT_ITEM_SHADOWING_USAGE;
use rustc_lint::builtin::RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS;
use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
Expand Down Expand Up @@ -709,7 +709,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
};

self.tcx.emit_node_span_lint(
SUPERTRAIT_ITEM_SHADOWING_USAGE,
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
segment.hir_id,
segment.ident.span,
SupertraitItemShadowing { shadower, shadowee, item: segment.ident.name, subtrait },
Expand Down
28 changes: 16 additions & 12 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ declare_lint_pass! {
RENAMED_AND_REMOVED_LINTS,
REPR_C_ENUMS_LARGER_THAN_INT,
REPR_TRANSPARENT_NON_ZST_FIELDS,
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
RTSAN_NONBLOCKING_ASYNC,
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
Expand All @@ -98,11 +99,10 @@ declare_lint_pass! {
RUST_2024_PRELUDE_COLLISIONS,
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
SHADOWING_SUPERTRAIT_ITEMS,
SINGLE_USE_LIFETIMES,
SOFT_UNSTABLE,
STABLE_FEATURES,
SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
SUPERTRAIT_ITEM_SHADOWING_USAGE,
TAIL_EXPR_DROP_ORDER,
TEST_UNSTABLE_LINT,
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
Expand Down Expand Up @@ -4922,15 +4922,16 @@ declare_lint! {
}

declare_lint! {
/// The `supertrait_item_shadowing_usage` lint detects when the
/// The `resolving_to_items_shadowing_supertrait_items` lint detects when the
/// usage of an item that is provided by both a subtrait and supertrait
/// is shadowed, preferring the subtrait.
///
/// ### Example
///
/// ```rust,compile_fail
#[cfg_attr(bootstrap, doc = "```ignore")]
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
/// #![feature(supertrait_item_shadowing)]
/// #![deny(supertrait_item_shadowing_usage)]
/// #![deny(resolving_to_items_shadowing_supertrait_items)]
///
/// trait Upstream {
/// fn hello(&self) {}
Expand All @@ -4944,7 +4945,8 @@ declare_lint! {
///
/// struct MyType;
/// MyType.hello();
/// ```
#[cfg_attr(bootstrap, doc = "```")]
#[cfg_attr(not(bootstrap), doc = "```")]
///
/// {{produces}}
///
Expand All @@ -4955,7 +4957,7 @@ declare_lint! {
/// selection. In order to mitigate side-effects of this happening
/// silently, this lint detects these cases when users want to deny them
/// or fix the call sites.
pub SUPERTRAIT_ITEM_SHADOWING_USAGE,
pub RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
// FIXME(supertrait_item_shadowing): It is not decided if this should
// warn by default at the call site.
Allow,
Expand All @@ -4964,15 +4966,16 @@ declare_lint! {
}

declare_lint! {
/// The `supertrait_item_shadowing_definition` lint detects when the
/// The `shadowing_supertrait_items` lint detects when the
/// definition of an item that is provided by both a subtrait and
/// supertrait is shadowed, preferring the subtrait.
///
/// ### Example
///
/// ```rust,compile_fail
#[cfg_attr(bootstrap, doc = "```ignore")]
#[cfg_attr(not(bootstrap), doc = "```rust,compile_fail")]
/// #![feature(supertrait_item_shadowing)]
/// #![deny(supertrait_item_shadowing_definition)]
/// #![deny(shadowing_supertrait_items)]
///
/// trait Upstream {
/// fn hello(&self) {}
Expand All @@ -4983,7 +4986,8 @@ declare_lint! {
/// fn hello(&self) {}
/// }
/// impl<T> Downstream for T {}
/// ```
#[cfg_attr(bootstrap, doc = "```")]
#[cfg_attr(not(bootstrap), doc = "```")]
///
/// {{produces}}
///
Expand All @@ -4994,7 +4998,7 @@ declare_lint! {
/// selection. In order to mitigate side-effects of this happening
/// silently, this lint detects these cases when users want to deny them
/// or fix their trait definitions.
pub SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
pub SHADOWING_SUPERTRAIT_ITEMS,
// FIXME(supertrait_item_shadowing): It is not decided if this should
// warn by default at the usage site.
Allow,
Expand Down
4 changes: 1 addition & 3 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,6 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {

/// Disposes of a value.
///
/// This does so by calling the argument's implementation of [`Drop`][drop].
///
/// This effectively does nothing for types which implement `Copy`, e.g.
/// integers. Such values are copied and _then_ moved into the function, so the
/// value persists after this function call.
Expand All @@ -910,7 +908,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
/// pub fn drop<T>(_x: T) {}
/// ```
///
/// Because `_x` is moved into the function, it is automatically dropped before
/// Because `_x` is moved into the function, it is automatically [dropped][drop] before
/// the function returns.
///
/// [drop]: Drop
Expand Down
17 changes: 17 additions & 0 deletions library/coretests/tests/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ fn convert() {
const BAR: Vec<String> = into(Vec::new());
assert_eq!(BAR, Vec::<String>::new());
}

#[test]
fn into_as_try_into() {
struct A;
struct B;

impl Into<B> for A {
fn into(self) -> B {
B
}
}

// This wouldn't compile if the `TryInto`/`TryFrom` blanket impls used
// `U: From<T>` instead of `T: Into<U>`
let Ok(B) = A.try_into();
let Ok(B) = B::try_from(A);
}
2 changes: 2 additions & 0 deletions tests/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ Contains a single test. It imports a massive amount of very similar types from a

## `tests/ui/never_type/`

Tests relating to the never type. Most tests are specifically about the never type fallback behavior.

See [Tracking issue for promoting `!` to a type (RFC 1216) #35121](https://github.com/rust-lang/rust/issues/35121).

## `tests/ui/new-range/`
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/coercion/coerce-issue-49593-box-never.e2021.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
--> $DIR/coerce-issue-49593-box-never.rs:28:5
|
LL | Box::new(x)
| ^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>`

error[E0277]: the trait bound `(): std::error::Error` is not satisfied
--> $DIR/coerce-issue-49593-box-never.rs:33:5
|
LL | raw_ptr(x)
| ^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()`
|
= note: required for the cast from `*mut ()` to `*mut (dyn std::error::Error + 'static)`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
62 changes: 21 additions & 41 deletions tests/ui/coercion/coerce-issue-49593-box-never.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
//@ revisions: nofallback fallback
//@[fallback] edition: 2024
//@[fallback] check-pass
// Regression test for <https://github.com/rust-lang/rust/issues/49593>.
//
// This checks that we can construct `Box<dyn Error>` by calling `Box::new`
// with a value of the never type. And similarly for raw pointers.
//
// This used to fail because we tried to coerce `! -> dyn Error`, which then
// failed because we were trying to pass an unsized value by value, etc.
//
// On edition <= 2021 this currently fails because of never type fallback to
// unit.
//
//@ revisions: e2021 e2024
//@[e2021] edition: 2021
//@[e2024] edition: 2024
//
//@[e2024] check-pass

#![feature(never_type)]

use std::error::Error;
use std::mem;

fn raw_ptr_box<T>(t: T) -> *mut T {
fn raw_ptr<T>(t: T) -> *mut T {
panic!()
}

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

fn foo_raw_ptr(x: !) -> *mut dyn Error {
/* *mut $0 is coerced to *mut Error here */
raw_ptr_box::<_ /* ! */>(x)
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied
}

fn no_coercion(d: *mut dyn Error) -> *mut dyn Error {
/* an unsize coercion won't compile here, and it is indeed not used
because there is nothing requiring the _ to be Sized */
d as *mut _
}

trait Xyz {}
struct S;
struct T;
impl Xyz for S {}
impl Xyz for T {}

fn foo_no_never() {
let mut x /* : Option<S> */ = None;
let mut first_iter = false;
loop {
if !first_iter {
let y: Box<dyn Xyz>
= /* Box<$0> is coerced to Box<Xyz> here */ Box::new(x.unwrap());
}

x = Some(S);
first_iter = true;
}

let mut y: Option<S> = None;
// assert types are equal
mem::swap(&mut x, &mut y);
raw_ptr(x)
//[e2021]~^ ERROR trait bound `(): std::error::Error` is not satisfied
}

fn main() {}
79 changes: 0 additions & 79 deletions tests/ui/coercion/coerce-to-bang.rs

This file was deleted.

Loading
Loading