Merge from rustc

This commit is contained in:
The Miri Cronjob Bot 2025-06-06 05:02:49 +00:00
commit c44bc10b67
291 changed files with 4610 additions and 2821 deletions

View file

@ -21,7 +21,7 @@ trait Iterator {
}
trait IteratorExt: Iterator + Sized {
fn by_ref(&mut self) -> ByRef<Self> {
fn by_ref(&mut self) -> ByRef<'_, Self> {
ByRef(self)
}
}

View file

@ -21,11 +21,11 @@ trait SliceExt2 {
impl<T> SliceExt2 for [T] {
type Item = T;
fn split2<P>(&self, pred: P) -> Splits<T, P> where P: FnMut(&T) -> bool {
fn split2<P>(&self, pred: P) -> Splits<'_, T, P> where P: FnMut(&T) -> bool {
loop {}
}
fn splitn2<P>(&self, n: u32, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
fn splitn2<P>(&self, n: u32, pred: P) -> SplitsN<Splits<'_, T, P>> where P: FnMut(&T) -> bool {
SliceExt2::split2(self, pred);
loop {}
}

View file

@ -3,32 +3,40 @@
// Test that we normalize associated types that appear in bounds; if
// we didn't, the call to `self.split2()` fails to type check.
use std::marker::PhantomData;
struct Splits<'a, T, P>(PhantomData<(&'a(),T,P)>);
struct Splits<'a, T, P>(PhantomData<(&'a (), T, P)>);
struct SplitsN<I>(PhantomData<I>);
trait SliceExt2 {
type Item;
fn split2<'a, P>(&'a self, pred: P) -> Splits<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
where
P: FnMut(&Self::Item) -> bool;
fn splitn2<'a, P>(&'a self, n: usize, pred: P) -> SplitsN<Splits<'a, Self::Item, P>>
where P: FnMut(&Self::Item) -> bool;
where
P: FnMut(&Self::Item) -> bool;
}
impl<T> SliceExt2 for [T] {
type Item = T;
fn split2<P>(&self, pred: P) -> Splits<T, P> where P: FnMut(&T) -> bool {
fn split2<P>(&self, pred: P) -> Splits<'_, T, P>
where
P: FnMut(&T) -> bool,
{
loop {}
}
fn splitn2<P>(&self, n: usize, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
fn splitn2<P>(&self, n: usize, pred: P) -> SplitsN<Splits<'_, T, P>>
where
P: FnMut(&T) -> bool,
{
self.split2(pred);
loop {}
}
}
fn main() { }
fn main() {}

View file

@ -20,7 +20,7 @@ trait Iterator {
}
trait IteratorExt: Iterator + Sized {
fn by_ref(&mut self) -> ByRef<Self> {
fn by_ref(&mut self) -> ByRef<'_, Self> {
ByRef(self)
}
}

View file

@ -14,7 +14,7 @@ pub trait UnicodeStr {
impl UnicodeStr for str {
#[inline]
fn split_whitespace(&self) -> SplitWhitespace {
fn split_whitespace(&self) -> SplitWhitespace<'_> {
unimplemented!()
}
}

View file

@ -50,7 +50,7 @@ where P: Pixel + 'static,
loop { }
}
pub fn pixels_mut(&mut self) -> PixelsMut<P> {
pub fn pixels_mut(&mut self) -> PixelsMut<'_, P> {
loop { }
}
}

View file

@ -9,7 +9,7 @@ trait Foo {}
impl Xyz {
async fn do_sth<'a>(
&'a self, foo: &dyn Foo
) -> &dyn Foo //~ WARNING elided lifetime has a name
) -> &dyn Foo
{
foo
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]

View file

@ -1,14 +1,3 @@
warning: elided lifetime has a name
--> $DIR/issue-63388-1.rs:12:10
|
LL | async fn do_sth<'a>(
| -- lifetime `'a` declared here
LL | &'a self, foo: &dyn Foo
LL | ) -> &dyn Foo
| ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error[E0621]: explicit lifetime required in the type of `foo`
--> $DIR/issue-63388-1.rs:14:9
|
@ -18,6 +7,6 @@ LL | &'a self, foo: &dyn Foo
LL | foo
| ^^^ lifetime `'a` required
error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0621`.

View file

@ -7,7 +7,7 @@ pub struct HelperStruct<'n> {
}
impl DataStruct {
pub fn f(&self) -> HelperStruct {
pub fn f(&self) -> HelperStruct<'_> {
let helpers = [vec![], vec![]];
HelperStruct { helpers: helpers.clone(), is_empty: helpers[0].is_empty() }

View file

@ -7,7 +7,7 @@ pub struct HelperStruct<'n> {
}
impl DataStruct {
pub fn f(&self) -> HelperStruct {
pub fn f(&self) -> HelperStruct<'_> {
let helpers = [vec![], vec![]];
HelperStruct { helpers, is_empty: helpers[0].is_empty() }

View file

@ -1,37 +0,0 @@
#![feature(never_type)]
fn loop_break_return() -> i32 {
let loop_value = loop { break return 0 }; // ok
}
fn loop_break_loop() -> i32 {
let loop_value = loop { break loop {} }; // ok
}
fn loop_break_break() -> i32 { //~ ERROR mismatched types
let loop_value = loop { break break };
}
fn loop_break_return_2() -> i32 {
let loop_value = loop { break { return 0; () } }; // ok
}
enum Void {}
fn get_void() -> Void {
panic!()
}
fn loop_break_void() -> i32 { //~ ERROR mismatched types
let loop_value = loop { break get_void() };
}
fn get_never() -> ! {
panic!()
}
fn loop_break_never() -> i32 {
let loop_value = loop { break get_never() }; // ok
}
fn main() {}

View file

@ -1,9 +0,0 @@
//@ run-pass
fn foo(x: &mut Box<u8>) {
*x = Box::new(5);
}
pub fn main() {
foo(&mut Box::new(4));
}

View file

@ -1,15 +0,0 @@
#![feature(unboxed_closures, tuple_trait)]
use std::io::Read;
fn to_fn_once<A:std::marker::Tuple,F:FnOnce<A>>(f: F) -> F { f }
fn main() {
let x = 1;
to_fn_once(move|| { x = 2; });
//~^ ERROR: cannot assign to `x`, as it is not declared as mutable
let s = std::io::stdin();
to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
//~^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
}

View file

@ -1,13 +0,0 @@
//@ run-pass
pub fn main() {
let c: char = 'x';
let d: char = 'x';
assert_eq!(c, 'x');
assert_eq!('x', c);
assert_eq!(c, c);
assert_eq!(c, d);
assert_eq!(d, c);
assert_eq!(d, 'x');
assert_eq!('x', d);
}

View file

@ -1,54 +0,0 @@
trait Noisy {
fn speak(&mut self);
}
struct Cat {
meows : usize,
how_hungry : isize,
name : String,
}
impl Cat {
pub fn eat(&mut self) -> bool {
if self.how_hungry > 0 {
println!("OM NOM NOM");
self.how_hungry -= 2;
return true;
}
else {
println!("Not hungry!");
return false;
}
}
}
impl Noisy for Cat {
fn speak(&mut self) { self.meow(); }
}
impl Cat {
fn meow(&mut self) {
println!("Meow");
self.meows += 1;
if self.meows % 5 == 0 {
self.how_hungry += 1;
}
}
}
fn cat(in_x : usize, in_y : isize, in_name: String) -> Cat {
Cat {
meows: in_x,
how_hungry: in_y,
name: in_name
}
}
fn main() {
let nyan: Box<dyn Noisy> = Box::new(cat(0, 2, "nyan".to_string())) as Box<dyn Noisy>;
nyan.eat(); //~ ERROR no method named `eat` found
}

View file

@ -1,9 +0,0 @@
error[E0599]: no method named `eat` found for struct `Box<dyn Noisy>` in the current scope
--> $DIR/class-cast-to-trait.rs:53:8
|
LL | nyan.eat();
| ^^^ method not found in `Box<dyn Noisy>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0599`.

View file

@ -1,21 +0,0 @@
trait Animal {
fn eat(&self);
}
struct Cat {
meows: usize,
}
impl Animal for Cat {
//~^ ERROR not all trait items implemented, missing: `eat`
}
fn cat(in_x : usize) -> Cat {
Cat {
meows: in_x
}
}
fn main() {
let nyan = cat(0);
}

View file

@ -1,12 +0,0 @@
error[E0046]: not all trait items implemented, missing: `eat`
--> $DIR/class-method-missing.rs:9:1
|
LL | fn eat(&self);
| -------------- `eat` from trait
...
LL | impl Animal for Cat {
| ^^^^^^^^^^^^^^^^^^^ missing `eat` in implementation
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0046`.

View file

@ -1,60 +0,0 @@
//@ run-pass
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
// Test that the lifetime of rvalues in for loops is extended
// to the for loop itself.
static mut FLAGS: u64 = 0;
struct Box<T> { f: T }
struct AddFlags { bits: u64 }
fn AddFlags(bits: u64) -> AddFlags {
AddFlags { bits: bits }
}
fn arg(exp: u64, _x: &AddFlags) {
check_flags(exp);
}
fn pass<T>(v: T) -> T {
v
}
fn check_flags(exp: u64) {
unsafe {
let x = FLAGS;
FLAGS = 0;
println!("flags {}, expected {}", x, exp);
assert_eq!(x, exp);
}
}
impl AddFlags {
fn check_flags(&self, exp: u64) -> &AddFlags {
check_flags(exp);
self
}
fn bits(&self) -> u64 {
self.bits
}
}
impl Drop for AddFlags {
fn drop(&mut self) {
unsafe {
FLAGS = FLAGS + self.bits;
}
}
}
pub fn main() {
// The array containing [AddFlags] should not be dropped until
// after the for loop:
for x in &[AddFlags(1)] {
check_flags(0);
}
check_flags(1);
}

View file

@ -0,0 +1,23 @@
//! Tests that mutation of captured immutable variables in closures are not permitted.
#![feature(unboxed_closures, tuple_trait)]
use std::io::Read;
fn to_fn_once<A: std::marker::Tuple, F: FnOnce<A>>(f: F) -> F {
f
}
fn main() {
let x = 1;
to_fn_once(move || {
x = 2;
//~^ ERROR: cannot assign to `x`, as it is not declared as mutable
});
let s = std::io::stdin();
to_fn_once(move || {
s.read_to_end(&mut Vec::new());
//~^ ERROR: cannot borrow `s` as mutable, as it is not declared as mutable
});
}

View file

@ -1,8 +1,8 @@
error[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25
--> $DIR/closure-immut-capture-error.rs:14:9
|
LL | to_fn_once(move|| { x = 2; });
| ^^^^^ cannot assign
LL | x = 2;
| ^^^^^ cannot assign
|
help: consider changing this to be mutable
|
@ -10,10 +10,10 @@ LL | let mut x = 1;
| +++
error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
--> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25
--> $DIR/closure-immut-capture-error.rs:20:9
|
LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
| ^ cannot borrow as mutable
LL | s.read_to_end(&mut Vec::new());
| ^ cannot borrow as mutable
|
help: consider changing this to be mutable
|

View file

@ -0,0 +1,13 @@
//! Tests cleanup of a temporary `Box` rvalue passed as a mutable reference.
//!
//! - Issue: <https://github.com/rust-lang/rust/issues/7972>.
//@ run-pass
fn foo(x: &mut Box<u8>) {
*x = Box::new(5);
}
pub fn main() {
foo(&mut Box::new(4));
}

View file

@ -1,10 +1,17 @@
warning: elided lifetime has a name
--> $DIR/issue-71348.rs:18:68
warning: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/issue-71348.rs:18:40
|
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
| ^^ -- ------------------------ the lifetimes get resolved as `'a`
| | |
| | the lifetimes get resolved as `'a`
| this lifetime flows to the output
|
= note: `#[warn(elided_named_lifetimes)]` on by default
= note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: one option is to consistently use `'a`
|
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<'a, N>>::Target
| +++
warning: 1 warning emitted

View file

@ -1,11 +1,3 @@
warning: elided lifetime has a name
--> $DIR/issue-71348.rs:18:68
|
LL | fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error: `&'static str` is forbidden as the type of a const generic parameter
--> $DIR/issue-71348.rs:10:24
|
@ -38,5 +30,5 @@ help: add `#![feature(unsized_const_params)]` to the crate attributes to enable
LL + #![feature(unsized_const_params)]
|
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

View file

@ -17,7 +17,7 @@ trait Get<'a, const N: &'static str> {
impl Foo {
fn ask<'a, const N: &'static str>(&'a self) -> &'a <Self as Get<N>>::Target
//[min]~^ ERROR `&'static str` is forbidden as the type of a const generic parameter
//~^^ WARNING elided lifetime has a name
//[full]~^^ WARNING lifetime flowing from input to output with different syntax
where
Self: Get<'a, N>,
{

View file

@ -2,7 +2,7 @@ error[E0080]: calling non-const function `<Vec<u32> as Drop>::drop`
--> $DIR/assoc_const.rs:12:31
|
LL | const F: u32 = (U::X, 42).1;
| ^ evaluation of `drop_in_place::<Vec<u32>> - shim(Some(Vec<u32>))` failed here
| ^ evaluation of `<std::string::String as Bar<std::vec::Vec<u32>, std::string::String>>::F` failed here
|
note: inside `drop_in_place::<(Vec<u32>, u32)> - shim(Some((Vec<u32>, u32)))`
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL

View file

@ -11,6 +11,7 @@ pub const unsafe fn hint_unreachable() -> ! {
trait Const {
const CONSTANT: i32 = unsafe { fake_type() }; //~ ERROR reached the configured maximum number of stack frames
//~^ NOTE evaluation of `<i32 as Const>::CONSTANT` failed here
}
impl<T> Const for T {}

View file

@ -2,7 +2,7 @@ error[E0080]: reached the configured maximum number of stack frames
--> $DIR/uninhabited-const-issue-61744.rs:13:36
|
LL | const CONSTANT: i32 = unsafe { fake_type() };
| ^^^^^^^^^^^ evaluation of `fake_type::<!>` failed here
| ^^^^^^^^^^^ evaluation of `<i32 as Const>::CONSTANT` failed here
|
note: inside `fake_type::<i32>`
--> $DIR/uninhabited-const-issue-61744.rs:5:5

View file

@ -589,7 +589,7 @@ impl Events {
Ok(LogDrop(self, m))
}
/// Return an `Err` value that logs its drop.
fn err(&self, m: u64) -> Result<LogDrop, LogDrop> {
fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> {
Err(LogDrop(self, m))
}
/// Log an event.

View file

@ -589,7 +589,7 @@ impl Events {
Ok(LogDrop(self, m))
}
/// Return an `Err` value that logs its drop.
fn err(&self, m: u64) -> Result<LogDrop, LogDrop> {
fn err(&self, m: u64) -> Result<LogDrop<'_>, LogDrop<'_>> {
Err(LogDrop(self, m))
}
/// Log an event.

View file

@ -23,11 +23,11 @@ impl Drop for LoudDrop<'_> {
}
impl DropOrderCollector {
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
Some(LoudDrop(self, n))
}
fn loud_drop(&self, n: u32) -> LoudDrop {
fn loud_drop(&self, n: u32) -> LoudDrop<'_> {
LoudDrop(self, n)
}

View file

@ -18,7 +18,7 @@ impl Drop for LoudDrop<'_> {
}
impl DropOrderCollector {
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
Some(LoudDrop(self, n))
}

View file

@ -0,0 +1,33 @@
//! Check that temporaries in the for into-iterable expr are not dropped
//! until the end of the for expr.
//@ run-pass
static mut FLAGS: u64 = 0;
struct AddFlags {
bits: u64,
}
impl Drop for AddFlags {
fn drop(&mut self) {
unsafe {
FLAGS += self.bits;
}
}
}
fn check_flags(expected: u64) {
unsafe {
let actual = FLAGS;
FLAGS = 0;
assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
}
}
fn main() {
for _ in &[AddFlags { bits: 1 }] {
check_flags(0);
}
check_flags(1);
}

View file

@ -14,7 +14,7 @@ impl<'a> Drop for defer<'a> {
}
}
fn defer(b: &Cell<bool>) -> defer {
fn defer(b: &Cell<bool>) -> defer<'_> {
defer {
b: b
}

View file

@ -14,7 +14,7 @@ impl<'a> Drop for defer<'a> {
}
}
fn defer(b: &Cell<bool>) -> defer {
fn defer(b: &Cell<bool>) -> defer<'_> {
defer {
b: b
}

View file

@ -13,7 +13,7 @@ impl<'a> Drop for r<'a> {
}
}
fn r(b: &Cell<isize>) -> r {
fn r(b: &Cell<isize>) -> r<'_> {
r {
b: b
}

View file

@ -28,11 +28,11 @@ impl Drop for LoudDrop<'_> {
}
impl DropOrderCollector {
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop> {
fn option_loud_drop(&self, n: u32) -> Option<LoudDrop<'_>> {
Some(LoudDrop(self, n))
}
fn loud_drop(&self, n: u32) -> LoudDrop {
fn loud_drop(&self, n: u32) -> LoudDrop<'_> {
LoudDrop(self, n)
}

View file

@ -1,3 +1,7 @@
//! Check that trying to cast an enum with a Drop impl to an integer is rejected.
//!
//! Issue: <https://github.com/rust-lang/rust/issues/35941>
enum E {
A = 0,
}

View file

@ -1,5 +1,5 @@
error: cannot cast enum `E` into integer `u32` because it implements `Drop`
--> $DIR/cenum_impl_drop_cast.rs:13:13
--> $DIR/enum-drop-cast-error.rs:17:13
|
LL | let i = e as u32;
| ^^^^^^^^

View file

@ -0,0 +1,10 @@
---
x ---🚧
---
// Regression test for #141483
//@check-pass
#![feature(frontmatter)]
fn main() {}

View file

@ -0,0 +1,11 @@
---
x ---y
---
// Test that hypens are allowed inside frontmatters if there is some
// non-whitespace character preceding them.
//@check-pass
#![feature(frontmatter)]
fn main() {}

View file

@ -1,5 +1,5 @@
//@ run-rustfix
#![allow(dead_code, elided_named_lifetimes)]
#![allow(dead_code, mismatched_lifetime_syntaxes)]
#![deny(no_mangle_generic_items)]
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled

View file

@ -1,5 +1,5 @@
//@ run-rustfix
#![allow(dead_code, elided_named_lifetimes)]
#![allow(dead_code, mismatched_lifetime_syntaxes)]
#![deny(no_mangle_generic_items)]
#[export_name = "foo"]

View file

@ -1,5 +1,5 @@
//@ run-rustfix
#![allow(dead_code, elided_named_lifetimes)]
#![allow(dead_code, mismatched_lifetime_syntaxes)]
#![deny(no_mangle_generic_items)]
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled

View file

@ -1,5 +1,5 @@
//@ run-rustfix
#![allow(dead_code, elided_named_lifetimes)]
#![allow(dead_code, mismatched_lifetime_syntaxes)]
#![deny(no_mangle_generic_items)]
#[no_mangle]

View file

@ -25,7 +25,7 @@ where
impl<T: 'static> Inject for RefMutFamily<T> {
type I = Self;
fn inject(_: &()) -> <Self::I as FamilyLt>::Out {
fn inject(_: &()) -> <Self::I as FamilyLt<'_>>::Out {
unimplemented!()
}
}

View file

@ -13,7 +13,6 @@ fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
//~| WARNING elided lifetime has a name
|x| x
}

View file

@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier
--> $DIR/impl-fn-hrtb-bounds.rs:20:38
--> $DIR/impl-fn-hrtb-bounds.rs:19:38
|
LL | fn d() -> impl Fn() -> (impl Debug + '_) {
| ^^ expected named lifetime parameter
@ -11,14 +11,6 @@ LL - fn d() -> impl Fn() -> (impl Debug + '_) {
LL + fn d() -> impl Fn() -> (impl Debug + 'static) {
|
warning: elided lifetime has a name
--> $DIR/impl-fn-hrtb-bounds.rs:14:52
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
--> $DIR/impl-fn-hrtb-bounds.rs:4:41
|
@ -55,7 +47,7 @@ note: lifetime declared here
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
| ^^
error: aborting due to 4 previous errors; 1 warning emitted
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0106, E0657.
For more information about an error, try `rustc --explain E0106`.

View file

@ -2,7 +2,6 @@
use std::fmt::Debug;
fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
//~^ WARNING elided lifetime has a name
|x| x
//~^ ERROR expected generic lifetime parameter, found `'_`
}

View file

@ -1,20 +1,11 @@
warning: elided lifetime has a name
--> $DIR/impl-fn-predefined-lifetimes.rs:4:48
|
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
| -- lifetime `'a` declared here ^^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error[E0792]: expected generic lifetime parameter, found `'_`
--> $DIR/impl-fn-predefined-lifetimes.rs:6:9
--> $DIR/impl-fn-predefined-lifetimes.rs:5:9
|
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) {
| -- this generic parameter must be used with a generic lifetime parameter
LL |
LL | |x| x
| ^
error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0792`.

View file

@ -1,7 +1,7 @@
//@ check-pass
pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &u32)> {
//~^ WARNING elided lifetime has a name
//~^ WARNING lifetime flowing from input to output with different syntax
v.into_iter()
}

View file

@ -1,10 +1,14 @@
warning: elided lifetime has a name
--> $DIR/rpit-assoc-pair-with-lifetime.rs:3:82
warning: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/rpit-assoc-pair-with-lifetime.rs:3:31
|
LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &u32)> {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
| ^^ this lifetime flows to the output ---- the lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
= note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: one option is to consistently use `'a`
|
LL | pub fn iter<'a>(v: Vec<(u32, &'a u32)>) -> impl DoubleEndedIterator<Item = (u32, &'a u32)> {
| ++
warning: 1 warning emitted

View file

@ -14,7 +14,7 @@ impl<'a> font<'a> {
}
}
fn font(fontbuf: &Vec<u8> ) -> font {
fn font(fontbuf: &Vec<u8> ) -> font<'_> {
font {
fontbuf: fontbuf
}

View file

@ -1,7 +1,7 @@
//@ run-pass
// Regression test for an obscure issue with the projection cache.
fn into_iter<I: Iterator>(a: &I) -> Groups<I> {
fn into_iter<I: Iterator>(a: &I) -> Groups<'_, I> {
Groups { _a: a }
}

View file

@ -25,7 +25,7 @@ struct Outer<'a> {
}
impl<'a> Outer<'a> {
fn new(inner: &dyn Inner) -> Outer {
fn new(inner: &dyn Inner) -> Outer<'_> {
Outer {
inner: inner
}

View file

@ -28,6 +28,7 @@ impl Greeter1 for FixedGreeter<'_> {
struct Greetings(pub Vec<String>);
impl Greetings {
#[expect(mismatched_lifetime_syntaxes)]
pub fn get(&self, i: usize) -> BoxedGreeter {
(Box::new(FixedGreeter(&self.0[i])), Box::new(FixedGreeter(&self.0[i])))
//~^ ERROR lifetime may not live long enough

View file

@ -28,6 +28,7 @@ impl Greeter1 for FixedGreeter<'_> {
struct Greetings(pub Vec<String>);
impl Greetings {
#[expect(mismatched_lifetime_syntaxes)]
pub fn get(&self, i: usize) -> BoxedGreeter {
(Box::new(FixedGreeter(&self.0[i])), Box::new(FixedGreeter(&self.0[i])))
//~^ ERROR lifetime may not live long enough

View file

@ -1,5 +1,5 @@
error: lifetime may not live long enough
--> $DIR/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs:32:9
--> $DIR/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs:33:9
|
LL | pub fn get(&self, i: usize) -> BoxedGreeter {
| - let's call the lifetime of this reference `'1`

View file

@ -47,6 +47,5 @@ fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
// This is ok because both `'a` are for the same parameter.
fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
//~^ WARNING elided lifetime has a name
fn main() {}

View file

@ -105,16 +105,6 @@ help: consider using the `'a` lifetime
LL | fn l<'a>(_: &'a str, _: &'a str) -> &'a str { "" }
| ++
warning: elided lifetime has a name
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:49:29
|
LL | fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
| -- ^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error: aborting due to 7 previous errors; 1 warning emitted
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0106`.

View file

@ -4,12 +4,8 @@ struct Foo {
impl Foo {
fn foo<'a>(&'a self, x: &i32) -> &i32 {
//~^ WARNING elided lifetime has a name
if true { &self.field } else { x } //~ ERROR explicit lifetime
}
}
fn main() { }

View file

@ -1,22 +1,11 @@
warning: elided lifetime has a name
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:6:36
|
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
| -- ^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:9:36
--> $DIR/ex1-return-one-existing-name-if-else-using-impl-3.rs:7:36
|
LL | fn foo<'a>(&'a self, x: &i32) -> &i32 {
| ---- help: add explicit lifetime `'a` to the type of `x`: `&'a i32`
...
LL | if true { &self.field } else { x }
| ^ lifetime `'a` required
error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0621`.

View file

@ -1,10 +1,10 @@
#![deny(elided_named_lifetimes)]
#![deny(mismatched_lifetime_syntaxes)]
struct Foo;
impl Foo {
pub fn get_mut(&'static self, x: &mut u8) -> &mut u8 {
//~^ ERROR elided lifetime has a name
//~^ ERROR lifetime flowing from input to output with different syntax
unsafe { &mut *(x as *mut _) }
}
}

View file

@ -0,0 +1,20 @@
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/example-from-issue48686.rs:6:21
|
LL | pub fn get_mut(&'static self, x: &mut u8) -> &mut u8 {
| ^^^^^^^ ------- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
note: the lint level is defined here
--> $DIR/example-from-issue48686.rs:1:9
|
LL | #![deny(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: one option is to consistently use `'static`
|
LL | pub fn get_mut(&'static self, x: &mut u8) -> &'static mut u8 {
| +++++++
error: aborting due to 1 previous error

View file

@ -0,0 +1,27 @@
#![deny(mismatched_lifetime_syntaxes)]
fn ampersand<'a>(x: &'a u8) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
x
}
struct Brackets<'a>(&'a u8);
fn brackets<'a>(x: &'a u8) -> Brackets {
//~^ ERROR lifetime flowing from input to output with different syntax
Brackets(x)
}
struct Comma<'a, T>(&'a T);
fn comma<'a>(x: &'a u8) -> Comma<u8> {
//~^ ERROR lifetime flowing from input to output with different syntax
Comma(x)
}
fn underscore<'a>(x: &'a u8) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
x
}
fn main() {}

View file

@ -0,0 +1,60 @@
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/missing-lifetime-kind.rs:3:22
|
LL | fn ampersand<'a>(x: &'a u8) -> &u8 {
| ^^ --- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
note: the lint level is defined here
--> $DIR/missing-lifetime-kind.rs:1:9
|
LL | #![deny(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: one option is to consistently use `'a`
|
LL | fn ampersand<'a>(x: &'a u8) -> &'a u8 {
| ++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/missing-lifetime-kind.rs:10:21
|
LL | fn brackets<'a>(x: &'a u8) -> Brackets {
| ^^ -------- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn brackets<'a>(x: &'a u8) -> Brackets<'a> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/missing-lifetime-kind.rs:17:18
|
LL | fn comma<'a>(x: &'a u8) -> Comma<u8> {
| ^^ --------- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn comma<'a>(x: &'a u8) -> Comma<'a, u8> {
| +++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/missing-lifetime-kind.rs:22:23
|
LL | fn underscore<'a>(x: &'a u8) -> &'_ u8 {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn underscore<'a>(x: &'a u8) -> &'_ u8 {
LL + fn underscore<'a>(x: &'a u8) -> &'a u8 {
|
error: aborting due to 4 previous errors

View file

@ -0,0 +1,20 @@
#![allow(mismatched_lifetime_syntaxes)]
//! Ensure that the lint level of `mismatched_lifetime_syntaxes` can
//! be adjusted by attributes not applied at the crate-level.
#[warn(mismatched_lifetime_syntaxes)]
mod foo {
fn bar(x: &'static u8) -> &u8 {
//~^ WARNING lifetime flowing from input to output with different syntax
x
}
#[deny(mismatched_lifetime_syntaxes)]
fn baz(x: &'static u8) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
x
}
}
fn main() {}

View file

@ -0,0 +1,38 @@
warning: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/not-tied-to-crate.rs:8:16
|
LL | fn bar(x: &'static u8) -> &u8 {
| ^^^^^^^ --- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
note: the lint level is defined here
--> $DIR/not-tied-to-crate.rs:6:8
|
LL | #[warn(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: one option is to consistently use `'static`
|
LL | fn bar(x: &'static u8) -> &'static u8 {
| +++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/not-tied-to-crate.rs:14:16
|
LL | fn baz(x: &'static u8) -> &u8 {
| ^^^^^^^ --- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
note: the lint level is defined here
--> $DIR/not-tied-to-crate.rs:13:12
|
LL | #[deny(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: one option is to consistently use `'static`
|
LL | fn baz(x: &'static u8) -> &'static u8 {
| +++++++
error: aborting due to 1 previous error; 1 warning emitted

View file

@ -1,4 +1,4 @@
#![deny(elided_named_lifetimes)]
#![deny(mismatched_lifetime_syntaxes)]
use std::borrow::Cow;
@ -14,26 +14,26 @@ impl Trait for () {
}
fn ampersand(x: &'static u8) -> &u8 {
//~^ ERROR elided lifetime has a name
//~^ ERROR lifetime flowing from input to output with different syntax
x
}
struct Brackets<'a>(&'a u8);
fn brackets(x: &'static u8) -> Brackets {
//~^ ERROR elided lifetime has a name
//~^ ERROR lifetime flowing from input to output with different syntax
Brackets(x)
}
struct Comma<'a, T>(&'a T);
fn comma(x: &'static u8) -> Comma<u8> {
//~^ ERROR elided lifetime has a name
//~^ ERROR lifetime flowing from input to output with different syntax
Comma(x)
}
fn underscore(x: &'static u8) -> &'_ u8 {
//~^ ERROR elided lifetime has a name
//~^ ERROR lifetime flowing from input to output with different syntax
x
}

View file

@ -0,0 +1,60 @@
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/static.rs:16:18
|
LL | fn ampersand(x: &'static u8) -> &u8 {
| ^^^^^^^ --- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
note: the lint level is defined here
--> $DIR/static.rs:1:9
|
LL | #![deny(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: one option is to consistently use `'static`
|
LL | fn ampersand(x: &'static u8) -> &'static u8 {
| +++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/static.rs:23:17
|
LL | fn brackets(x: &'static u8) -> Brackets {
| ^^^^^^^ -------- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL | fn brackets(x: &'static u8) -> Brackets<'static> {
| +++++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/static.rs:30:14
|
LL | fn comma(x: &'static u8) -> Comma<u8> {
| ^^^^^^^ --------- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL | fn comma(x: &'static u8) -> Comma<'static, u8> {
| ++++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/static.rs:35:19
|
LL | fn underscore(x: &'static u8) -> &'_ u8 {
| ^^^^^^^ -- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL - fn underscore(x: &'static u8) -> &'_ u8 {
LL + fn underscore(x: &'static u8) -> &'static u8 {
|
error: aborting due to 4 previous errors

View file

@ -0,0 +1,315 @@
#![deny(mismatched_lifetime_syntaxes)]
#[derive(Copy, Clone)]
struct ContainsLifetime<'a>(&'a u8);
struct S(u8);
fn explicit_bound_ref_to_implicit_ref<'a>(v: &'a u8) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
fn explicit_bound_ref_to_explicit_anonymous_ref<'a>(v: &'a u8) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
// ---
fn implicit_path_to_explicit_anonymous_path(v: ContainsLifetime) -> ContainsLifetime<'_> {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
fn explicit_anonymous_path_to_implicit_path(v: ContainsLifetime<'_>) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
fn explicit_bound_path_to_implicit_path<'a>(v: ContainsLifetime<'a>) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
fn explicit_bound_path_to_explicit_anonymous_path<'a>(
v: ContainsLifetime<'a>,
//~^ ERROR lifetime flowing from input to output with different syntax
) -> ContainsLifetime<'_> {
v
}
// ---
fn implicit_ref_to_implicit_path(v: &u8) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(v)
}
fn explicit_anonymous_ref_to_implicit_path(v: &'_ u8) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(v)
}
fn explicit_bound_ref_to_implicit_path<'a>(v: &'a u8) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(v)
}
fn explicit_bound_ref_to_explicit_anonymous_path<'a>(v: &'a u8) -> ContainsLifetime<'_> {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(v)
}
// ---
fn implicit_path_to_implicit_ref(v: ContainsLifetime) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v.0
}
fn implicit_path_to_explicit_anonymous_ref(v: ContainsLifetime) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v.0
}
fn explicit_bound_path_to_implicit_ref<'a>(v: ContainsLifetime<'a>) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v.0
}
fn explicit_bound_path_to_explicit_anonymous_ref<'a>(v: ContainsLifetime<'a>) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v.0
}
impl S {
fn method_explicit_bound_ref_to_implicit_ref<'a>(&'a self) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
&self.0
}
fn method_explicit_bound_ref_to_explicit_anonymous_ref<'a>(&'a self) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
&self.0
}
// ---
fn method_explicit_anonymous_ref_to_implicit_path(&'_ self) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(&self.0)
}
fn method_explicit_bound_ref_to_implicit_path<'a>(&'a self) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(&self.0)
}
fn method_explicit_bound_ref_to_explicit_anonymous_path<'a>(&'a self) -> ContainsLifetime<'_> {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(&self.0)
}
}
// If a function uses the `'static` lifetime, we should not suggest
// replacing it with an explicitly anonymous or implicit
// lifetime. Only suggest using `'static` everywhere.
mod static_suggestions {
#[derive(Copy, Clone)]
struct ContainsLifetime<'a>(&'a u8);
struct S(u8);
fn static_ref_to_implicit_ref(v: &'static u8) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
fn static_ref_to_explicit_anonymous_ref(v: &'static u8) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
v
}
fn static_ref_to_implicit_path(v: &'static u8) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(v)
}
fn static_ref_to_explicit_anonymous_path(v: &'static u8) -> ContainsLifetime<'_> {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(v)
}
impl S {
fn static_ref_to_implicit_ref(&'static self) -> &u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
&self.0
}
fn static_ref_to_explicit_anonymous_ref(&'static self) -> &'_ u8 {
//~^ ERROR lifetime flowing from input to output with different syntax
&self.0
}
fn static_ref_to_implicit_path(&'static self) -> ContainsLifetime {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(&self.0)
}
fn static_ref_to_explicit_anonymous_path(&'static self) -> ContainsLifetime<'_> {
//~^ ERROR lifetime flowing from input to output with different syntax
ContainsLifetime(&self.0)
}
}
}
/// `impl Trait` uses lifetimes in some additional ways.
mod impl_trait {
#[derive(Copy, Clone)]
struct ContainsLifetime<'a>(&'a u8);
fn explicit_bound_ref_to_impl_trait_bound<'a>(v: &'a u8) -> impl FnOnce() + '_ {
//~^ ERROR lifetime flowing from input to output with different syntax
move || _ = v
}
fn explicit_bound_ref_to_impl_trait_precise_capture<'a>(v: &'a u8) -> impl FnOnce() + use<'_> {
//~^ ERROR lifetime flowing from input to output with different syntax
move || _ = v
}
fn explicit_bound_path_to_impl_trait_bound<'a>(v: ContainsLifetime<'a>) -> impl FnOnce() + '_ {
//~^ ERROR lifetime flowing from input to output with different syntax
move || _ = v
}
fn explicit_bound_path_to_impl_trait_precise_capture<'a>(
v: ContainsLifetime<'a>,
//~^ ERROR lifetime flowing from input to output with different syntax
) -> impl FnOnce() + use<'_> {
move || _ = v
}
}
/// `dyn Trait` uses lifetimes in some additional ways.
mod dyn_trait {
use std::iter;
#[derive(Copy, Clone)]
struct ContainsLifetime<'a>(&'a u8);
fn explicit_bound_ref_to_dyn_trait_bound<'a>(v: &'a u8) -> Box<dyn Iterator<Item = &u8> + '_> {
//~^ ERROR lifetime flowing from input to output with different syntax
Box::new(iter::once(v))
}
fn explicit_bound_path_to_dyn_trait_bound<'a>(
v: ContainsLifetime<'a>,
//~^ ERROR lifetime flowing from input to output with different syntax
) -> Box<dyn Iterator<Item = ContainsLifetime> + '_> {
Box::new(iter::once(v))
}
}
/// These tests serve to exercise edge cases of the lint formatting
mod diagnostic_output {
fn multiple_outputs<'a>(v: &'a u8) -> (&u8, &u8) {
//~^ ERROR lifetime flowing from input to output with different syntax
(v, v)
}
}
/// These usages are expected to **not** trigger the lint
mod acceptable_uses {
#[derive(Copy, Clone)]
struct ContainsLifetime<'a>(&'a u8);
struct S(u8);
fn implicit_ref_to_implicit_ref(v: &u8) -> &u8 {
v
}
fn explicit_anonymous_ref_to_explicit_anonymous_ref(v: &'_ u8) -> &'_ u8 {
v
}
fn explicit_bound_ref_to_explicit_bound_ref<'a>(v: &'a u8) -> &'a u8 {
v
}
fn implicit_path_to_implicit_path(v: ContainsLifetime) -> ContainsLifetime {
v
}
fn explicit_anonymous_path_to_explicit_anonymous_path(
v: ContainsLifetime<'_>,
) -> ContainsLifetime<'_> {
v
}
fn explicit_bound_path_to_explicit_bound_path<'a>(
v: ContainsLifetime<'a>,
) -> ContainsLifetime<'a> {
v
}
fn explicit_anonymous_ref_to_explicit_anonymous_path(v: &'_ u8) -> ContainsLifetime<'_> {
ContainsLifetime(v)
}
fn explicit_bound_ref_to_explicit_bound_path<'a>(v: &'a u8) -> ContainsLifetime<'a> {
ContainsLifetime(v)
}
fn explicit_anonymous_path_to_explicit_anonymous_ref(v: ContainsLifetime<'_>) -> &'_ u8 {
v.0
}
fn explicit_bound_path_to_explicit_bound_ref<'a>(v: ContainsLifetime<'a>) -> &'a u8 {
v.0
}
// These may be surprising, but ampersands count as enough of a
// visual indicator that a reference exists that we treat
// references with implicit lifetimes the same as if they were
// explicitly anonymous.
fn implicit_ref_to_explicit_anonymous_ref(v: &u8) -> &'_ u8 {
v
}
fn explicit_anonymous_ref_to_implicit_ref(v: &'_ u8) -> &u8 {
v
}
fn implicit_ref_to_explicit_anonymous_path(v: &u8) -> ContainsLifetime<'_> {
ContainsLifetime(v)
}
fn explicit_anonymous_path_to_implicit_ref(v: ContainsLifetime<'_>) -> &u8 {
v.0
}
impl S {
fn method_implicit_ref_to_explicit_anonymous_ref(&self) -> &'_ u8 {
&self.0
}
fn method_explicit_anonymous_ref_to_implicit_ref(&'_ self) -> &u8 {
&self.0
}
fn method_implicit_ref_to_explicit_anonymous_path(&self) -> ContainsLifetime<'_> {
ContainsLifetime(&self.0)
}
}
// `dyn Trait` has an "embedded" lifetime that we should **not**
// lint about.
fn dyn_trait_does_not_have_a_lifetime_generic(v: &u8) -> &dyn core::fmt::Debug {
v
}
}
fn main() {}

View file

@ -0,0 +1,473 @@
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:8:47
|
LL | fn explicit_bound_ref_to_implicit_ref<'a>(v: &'a u8) -> &u8 {
| ^^ --- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
note: the lint level is defined here
--> $DIR/mismatched-lifetime-syntaxes.rs:1:9
|
LL | #![deny(mismatched_lifetime_syntaxes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: one option is to consistently use `'a`
|
LL | fn explicit_bound_ref_to_implicit_ref<'a>(v: &'a u8) -> &'a u8 {
| ++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:13:57
|
LL | fn explicit_bound_ref_to_explicit_anonymous_ref<'a>(v: &'a u8) -> &'_ u8 {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn explicit_bound_ref_to_explicit_anonymous_ref<'a>(v: &'a u8) -> &'_ u8 {
LL + fn explicit_bound_ref_to_explicit_anonymous_ref<'a>(v: &'a u8) -> &'a u8 {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:20:48
|
LL | fn implicit_path_to_explicit_anonymous_path(v: ContainsLifetime) -> ContainsLifetime<'_> {
| ^^^^^^^^^^^^^^^^ -- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'_`
|
LL | fn implicit_path_to_explicit_anonymous_path(v: ContainsLifetime<'_>) -> ContainsLifetime<'_> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:25:65
|
LL | fn explicit_anonymous_path_to_implicit_path(v: ContainsLifetime<'_>) -> ContainsLifetime {
| ^^ ---------------- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'_`
|
LL | fn explicit_anonymous_path_to_implicit_path(v: ContainsLifetime<'_>) -> ContainsLifetime<'_> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:30:65
|
LL | fn explicit_bound_path_to_implicit_path<'a>(v: ContainsLifetime<'a>) -> ContainsLifetime {
| ^^ ---------------- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn explicit_bound_path_to_implicit_path<'a>(v: ContainsLifetime<'a>) -> ContainsLifetime<'a> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:36:25
|
LL | v: ContainsLifetime<'a>,
| ^^ this lifetime flows to the output
LL |
LL | ) -> ContainsLifetime<'_> {
| -- the lifetime gets resolved as `'a`
|
help: one option is to consistently use `'a`
|
LL - ) -> ContainsLifetime<'_> {
LL + ) -> ContainsLifetime<'a> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:44:37
|
LL | fn implicit_ref_to_implicit_path(v: &u8) -> ContainsLifetime {
| ^^^ ---------------- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
|
LL | fn implicit_ref_to_implicit_path(v: &u8) -> ContainsLifetime<'_> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:49:48
|
LL | fn explicit_anonymous_ref_to_implicit_path(v: &'_ u8) -> ContainsLifetime {
| ^^ ---------------- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
|
LL - fn explicit_anonymous_ref_to_implicit_path(v: &'_ u8) -> ContainsLifetime {
LL + fn explicit_anonymous_ref_to_implicit_path(v: &u8) -> ContainsLifetime<'_> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:54:48
|
LL | fn explicit_bound_ref_to_implicit_path<'a>(v: &'a u8) -> ContainsLifetime {
| ^^ ---------------- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn explicit_bound_ref_to_implicit_path<'a>(v: &'a u8) -> ContainsLifetime<'a> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:59:58
|
LL | fn explicit_bound_ref_to_explicit_anonymous_path<'a>(v: &'a u8) -> ContainsLifetime<'_> {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn explicit_bound_ref_to_explicit_anonymous_path<'a>(v: &'a u8) -> ContainsLifetime<'_> {
LL + fn explicit_bound_ref_to_explicit_anonymous_path<'a>(v: &'a u8) -> ContainsLifetime<'a> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:66:37
|
LL | fn implicit_path_to_implicit_ref(v: ContainsLifetime) -> &u8 {
| ^^^^^^^^^^^^^^^^ --- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
|
LL | fn implicit_path_to_implicit_ref(v: ContainsLifetime<'_>) -> &u8 {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:71:47
|
LL | fn implicit_path_to_explicit_anonymous_ref(v: ContainsLifetime) -> &'_ u8 {
| ^^^^^^^^^^^^^^^^ -- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
|
LL - fn implicit_path_to_explicit_anonymous_ref(v: ContainsLifetime) -> &'_ u8 {
LL + fn implicit_path_to_explicit_anonymous_ref(v: ContainsLifetime<'_>) -> &u8 {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:76:64
|
LL | fn explicit_bound_path_to_implicit_ref<'a>(v: ContainsLifetime<'a>) -> &u8 {
| ^^ --- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn explicit_bound_path_to_implicit_ref<'a>(v: ContainsLifetime<'a>) -> &'a u8 {
| ++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:81:74
|
LL | fn explicit_bound_path_to_explicit_anonymous_ref<'a>(v: ContainsLifetime<'a>) -> &'_ u8 {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn explicit_bound_path_to_explicit_anonymous_ref<'a>(v: ContainsLifetime<'a>) -> &'_ u8 {
LL + fn explicit_bound_path_to_explicit_anonymous_ref<'a>(v: ContainsLifetime<'a>) -> &'a u8 {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:87:55
|
LL | fn method_explicit_bound_ref_to_implicit_ref<'a>(&'a self) -> &u8 {
| ^^ --- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn method_explicit_bound_ref_to_implicit_ref<'a>(&'a self) -> &'a u8 {
| ++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:92:65
|
LL | fn method_explicit_bound_ref_to_explicit_anonymous_ref<'a>(&'a self) -> &'_ u8 {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn method_explicit_bound_ref_to_explicit_anonymous_ref<'a>(&'a self) -> &'_ u8 {
LL + fn method_explicit_bound_ref_to_explicit_anonymous_ref<'a>(&'a self) -> &'a u8 {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:99:56
|
LL | fn method_explicit_anonymous_ref_to_implicit_path(&'_ self) -> ContainsLifetime {
| ^^ ---------------- the lifetime gets resolved as `'_`
| |
| this lifetime flows to the output
|
help: one option is to remove the lifetime for references and use the anonymous lifetime for paths
|
LL - fn method_explicit_anonymous_ref_to_implicit_path(&'_ self) -> ContainsLifetime {
LL + fn method_explicit_anonymous_ref_to_implicit_path(&self) -> ContainsLifetime<'_> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:104:56
|
LL | fn method_explicit_bound_ref_to_implicit_path<'a>(&'a self) -> ContainsLifetime {
| ^^ ---------------- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn method_explicit_bound_ref_to_implicit_path<'a>(&'a self) -> ContainsLifetime<'a> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:109:66
|
LL | fn method_explicit_bound_ref_to_explicit_anonymous_path<'a>(&'a self) -> ContainsLifetime<'_> {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn method_explicit_bound_ref_to_explicit_anonymous_path<'a>(&'a self) -> ContainsLifetime<'_> {
LL + fn method_explicit_bound_ref_to_explicit_anonymous_path<'a>(&'a self) -> ContainsLifetime<'a> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:124:39
|
LL | fn static_ref_to_implicit_ref(v: &'static u8) -> &u8 {
| ^^^^^^^ --- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL | fn static_ref_to_implicit_ref(v: &'static u8) -> &'static u8 {
| +++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:129:49
|
LL | fn static_ref_to_explicit_anonymous_ref(v: &'static u8) -> &'_ u8 {
| ^^^^^^^ -- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL - fn static_ref_to_explicit_anonymous_ref(v: &'static u8) -> &'_ u8 {
LL + fn static_ref_to_explicit_anonymous_ref(v: &'static u8) -> &'static u8 {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:134:40
|
LL | fn static_ref_to_implicit_path(v: &'static u8) -> ContainsLifetime {
| ^^^^^^^ ---------------- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL | fn static_ref_to_implicit_path(v: &'static u8) -> ContainsLifetime<'static> {
| +++++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:139:50
|
LL | fn static_ref_to_explicit_anonymous_path(v: &'static u8) -> ContainsLifetime<'_> {
| ^^^^^^^ -- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL - fn static_ref_to_explicit_anonymous_path(v: &'static u8) -> ContainsLifetime<'_> {
LL + fn static_ref_to_explicit_anonymous_path(v: &'static u8) -> ContainsLifetime<'static> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:145:40
|
LL | fn static_ref_to_implicit_ref(&'static self) -> &u8 {
| ^^^^^^^ --- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL | fn static_ref_to_implicit_ref(&'static self) -> &'static u8 {
| +++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:150:50
|
LL | fn static_ref_to_explicit_anonymous_ref(&'static self) -> &'_ u8 {
| ^^^^^^^ -- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL - fn static_ref_to_explicit_anonymous_ref(&'static self) -> &'_ u8 {
LL + fn static_ref_to_explicit_anonymous_ref(&'static self) -> &'static u8 {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:155:41
|
LL | fn static_ref_to_implicit_path(&'static self) -> ContainsLifetime {
| ^^^^^^^ ---------------- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL | fn static_ref_to_implicit_path(&'static self) -> ContainsLifetime<'static> {
| +++++++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:160:51
|
LL | fn static_ref_to_explicit_anonymous_path(&'static self) -> ContainsLifetime<'_> {
| ^^^^^^^ -- the lifetime gets resolved as `'static`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'static`
|
LL - fn static_ref_to_explicit_anonymous_path(&'static self) -> ContainsLifetime<'_> {
LL + fn static_ref_to_explicit_anonymous_path(&'static self) -> ContainsLifetime<'static> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:172:55
|
LL | fn explicit_bound_ref_to_impl_trait_bound<'a>(v: &'a u8) -> impl FnOnce() + '_ {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn explicit_bound_ref_to_impl_trait_bound<'a>(v: &'a u8) -> impl FnOnce() + '_ {
LL + fn explicit_bound_ref_to_impl_trait_bound<'a>(v: &'a u8) -> impl FnOnce() + 'a {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:177:65
|
LL | fn explicit_bound_ref_to_impl_trait_precise_capture<'a>(v: &'a u8) -> impl FnOnce() + use<'_> {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn explicit_bound_ref_to_impl_trait_precise_capture<'a>(v: &'a u8) -> impl FnOnce() + use<'_> {
LL + fn explicit_bound_ref_to_impl_trait_precise_capture<'a>(v: &'a u8) -> impl FnOnce() + use<'a> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:182:72
|
LL | fn explicit_bound_path_to_impl_trait_bound<'a>(v: ContainsLifetime<'a>) -> impl FnOnce() + '_ {
| ^^ -- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL - fn explicit_bound_path_to_impl_trait_bound<'a>(v: ContainsLifetime<'a>) -> impl FnOnce() + '_ {
LL + fn explicit_bound_path_to_impl_trait_bound<'a>(v: ContainsLifetime<'a>) -> impl FnOnce() + 'a {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:188:29
|
LL | v: ContainsLifetime<'a>,
| ^^ this lifetime flows to the output
LL |
LL | ) -> impl FnOnce() + use<'_> {
| -- the lifetime gets resolved as `'a`
|
help: one option is to consistently use `'a`
|
LL - ) -> impl FnOnce() + use<'_> {
LL + ) -> impl FnOnce() + use<'a> {
|
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:202:54
|
LL | fn explicit_bound_ref_to_dyn_trait_bound<'a>(v: &'a u8) -> Box<dyn Iterator<Item = &u8> + '_> {
| ^^ --- -- the lifetimes get resolved as `'a`
| | |
| | the lifetimes get resolved as `'a`
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn explicit_bound_ref_to_dyn_trait_bound<'a>(v: &'a u8) -> Box<dyn Iterator<Item = &'a u8> + '_> {
| ++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:208:29
|
LL | v: ContainsLifetime<'a>,
| ^^ this lifetime flows to the output
LL |
LL | ) -> Box<dyn Iterator<Item = ContainsLifetime> + '_> {
| ---------------- -- the lifetimes get resolved as `'a`
| |
| the lifetimes get resolved as `'a`
|
help: one option is to consistently use `'a`
|
LL | ) -> Box<dyn Iterator<Item = ContainsLifetime<'a>> + '_> {
| ++++
error: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/mismatched-lifetime-syntaxes.rs:217:33
|
LL | fn multiple_outputs<'a>(v: &'a u8) -> (&u8, &u8) {
| ^^ --- --- the lifetimes get resolved as `'a`
| | |
| | the lifetimes get resolved as `'a`
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn multiple_outputs<'a>(v: &'a u8) -> (&'a u8, &'a u8) {
| ++ ++
error: aborting due to 34 previous errors

View file

@ -1,18 +0,0 @@
error: elided lifetime has a name
--> $DIR/example-from-issue48686.rs:6:50
|
LL | pub fn get_mut(&'static self, x: &mut u8) -> &mut u8 {
| ^ this elided lifetime gets resolved as `'static`
|
note: the lint level is defined here
--> $DIR/example-from-issue48686.rs:1:9
|
LL | #![deny(elided_named_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying it explicitly
|
LL | pub fn get_mut(&'static self, x: &mut u8) -> &'static mut u8 {
| +++++++
error: aborting due to 1 previous error

View file

@ -1,27 +0,0 @@
#![deny(elided_named_lifetimes)]
fn ampersand<'a>(x: &'a u8) -> &u8 {
//~^ ERROR elided lifetime has a name
x
}
struct Brackets<'a>(&'a u8);
fn brackets<'a>(x: &'a u8) -> Brackets {
//~^ ERROR elided lifetime has a name
Brackets(x)
}
struct Comma<'a, T>(&'a T);
fn comma<'a>(x: &'a u8) -> Comma<u8> {
//~^ ERROR elided lifetime has a name
Comma(x)
}
fn underscore<'a>(x: &'a u8) -> &'_ u8 {
//~^ ERROR elided lifetime has a name
x
}
fn main() {}

View file

@ -1,40 +0,0 @@
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:3:32
|
LL | fn ampersand<'a>(x: &'a u8) -> &u8 {
| -- ^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
note: the lint level is defined here
--> $DIR/missing-lifetime-kind.rs:1:9
|
LL | #![deny(elided_named_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:10:31
|
LL | fn brackets<'a>(x: &'a u8) -> Brackets {
| -- ^^^^^^^^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:17:33
|
LL | fn comma<'a>(x: &'a u8) -> Comma<u8> {
| -- ^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
error: elided lifetime has a name
--> $DIR/missing-lifetime-kind.rs:22:34
|
LL | fn underscore<'a>(x: &'a u8) -> &'_ u8 {
| -- ^^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
error: aborting due to 4 previous errors

View file

@ -1,17 +0,0 @@
#![allow(elided_named_lifetimes)]
#[warn(elided_named_lifetimes)]
mod foo {
fn bar(x: &'static u8) -> &u8 {
//~^ WARNING elided lifetime has a name
x
}
#[deny(elided_named_lifetimes)]
fn baz(x: &'static u8) -> &u8 {
//~^ ERROR elided lifetime has a name
x
}
}
fn main() {}

View file

@ -1,34 +0,0 @@
warning: elided lifetime has a name
--> $DIR/not-tied-to-crate.rs:5:31
|
LL | fn bar(x: &'static u8) -> &u8 {
| ^ this elided lifetime gets resolved as `'static`
|
note: the lint level is defined here
--> $DIR/not-tied-to-crate.rs:3:8
|
LL | #[warn(elided_named_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying it explicitly
|
LL | fn bar(x: &'static u8) -> &'static u8 {
| +++++++
error: elided lifetime has a name
--> $DIR/not-tied-to-crate.rs:11:31
|
LL | fn baz(x: &'static u8) -> &u8 {
| ^ this elided lifetime gets resolved as `'static`
|
note: the lint level is defined here
--> $DIR/not-tied-to-crate.rs:10:12
|
LL | #[deny(elided_named_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying it explicitly
|
LL | fn baz(x: &'static u8) -> &'static u8 {
| +++++++
error: aborting due to 1 previous error; 1 warning emitted

View file

@ -1,52 +0,0 @@
error: elided lifetime has a name
--> $DIR/static.rs:16:33
|
LL | fn ampersand(x: &'static u8) -> &u8 {
| ^ this elided lifetime gets resolved as `'static`
|
note: the lint level is defined here
--> $DIR/static.rs:1:9
|
LL | #![deny(elided_named_lifetimes)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: consider specifying it explicitly
|
LL | fn ampersand(x: &'static u8) -> &'static u8 {
| +++++++
error: elided lifetime has a name
--> $DIR/static.rs:23:32
|
LL | fn brackets(x: &'static u8) -> Brackets {
| ^^^^^^^^ this elided lifetime gets resolved as `'static`
|
help: consider specifying it explicitly
|
LL | fn brackets(x: &'static u8) -> Brackets<'static> {
| +++++++++
error: elided lifetime has a name
--> $DIR/static.rs:30:34
|
LL | fn comma(x: &'static u8) -> Comma<u8> {
| ^ this elided lifetime gets resolved as `'static`
|
help: consider specifying it explicitly
|
LL | fn comma(x: &'static u8) -> Comma<'static, u8> {
| ++++++++
error: elided lifetime has a name
--> $DIR/static.rs:35:35
|
LL | fn underscore(x: &'static u8) -> &'_ u8 {
| ^^ this elided lifetime gets resolved as `'static`
|
help: consider specifying it explicitly
|
LL - fn underscore(x: &'static u8) -> &'_ u8 {
LL + fn underscore(x: &'static u8) -> &'static u8 {
|
error: aborting due to 4 previous errors

View file

@ -0,0 +1,56 @@
//! Tests type mismatches with `break` and diverging types in loops
#![feature(never_type)]
fn loop_break_return() -> i32 {
let loop_value = loop {
break return 0;
}; // ok
}
fn loop_break_loop() -> i32 {
let loop_value = loop {
break loop {};
}; // ok
}
fn loop_break_break() -> i32 {
//~^ ERROR mismatched types
let loop_value = loop {
break break;
};
}
fn loop_break_return_2() -> i32 {
let loop_value = loop {
break {
return 0;
()
};
}; // ok
}
enum Void {}
fn get_void() -> Void {
panic!()
}
fn loop_break_void() -> i32 {
//~^ ERROR mismatched types
let loop_value = loop {
break get_void();
};
}
fn get_never() -> ! {
panic!()
}
fn loop_break_never() -> i32 {
let loop_value = loop {
break get_never();
}; // ok
}
fn main() {}

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:11:26
--> $DIR/loop-break-never-type-mismatch.rs:17:26
|
LL | fn loop_break_break() -> i32 {
| ---------------- ^^^ expected `i32`, found `()`
@ -7,7 +7,7 @@ LL | fn loop_break_break() -> i32 {
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
--> $DIR/break-diverging-value.rs:25:25
--> $DIR/loop-break-never-type-mismatch.rs:39:25
|
LL | fn loop_break_void() -> i32 {
| --------------- ^^^ expected `i32`, found `()`

View file

@ -5,7 +5,7 @@ use std::fmt::{self, Display};
struct Mutex;
impl Mutex {
fn lock(&self) -> MutexGuard {
fn lock(&self) -> MutexGuard<'_> {
MutexGuard(self)
}
}

View file

@ -20,11 +20,11 @@ fn fat_ptr_via_local(a: &[u8]) -> &[u8] {
x
}
fn fat_ptr_from_struct(s: FatPtrContainer) -> &[u8] {
fn fat_ptr_from_struct(s: FatPtrContainer<'_>) -> &[u8] {
s.ptr
}
fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer {
fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer<'_> {
FatPtrContainer { ptr: a }
}

View file

@ -22,7 +22,7 @@ struct Scratchpad<'a> {
}
impl<'a> Scratchpad<'a> {
fn get<T: GenericVec<T>>(&self) -> Ref<[T]>
fn get<T: GenericVec<T>>(&self) -> Ref<'_, [T]>
where T: 'a
{
Ref::map(self.buffers.borrow(), |x| T::unwrap(x.as_ref()))

View file

@ -18,7 +18,7 @@ impl Drop for Mutex { fn drop(&mut self) { println!("Mutex::drop"); } }
impl<'a> Drop for MutexGuard<'a> { fn drop(&mut self) { println!("MutexGuard::drop"); } }
impl Mutex {
fn lock(&self) -> Result<MutexGuard, ()> { Ok(MutexGuard(self)) }
fn lock(&self) -> Result<MutexGuard<'_>, ()> { Ok(MutexGuard(self)) }
}
fn main() {

View file

@ -46,8 +46,6 @@ fn load1(ss: &dyn SomeTrait) -> &dyn SomeTrait {
}
fn load2<'a>(ss: &'a dyn SomeTrait) -> &dyn SomeTrait {
//~^ WARNING elided lifetime has a name
// Same as `load1` but with an explicit name thrown in for fun.
ss

View file

@ -1,15 +1,5 @@
warning: elided lifetime has a name
--> $DIR/object-lifetime-default-elision.rs:48:40
|
LL | fn load2<'a>(ss: &'a dyn SomeTrait) -> &dyn SomeTrait {
| -- ^ this elided lifetime gets resolved as `'a`
| |
| lifetime `'a` declared here
|
= note: `#[warn(elided_named_lifetimes)]` on by default
error: lifetime may not live long enough
--> $DIR/object-lifetime-default-elision.rs:73:5
--> $DIR/object-lifetime-default-elision.rs:71:5
|
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| -- -- lifetime `'b` defined here
@ -21,5 +11,5 @@ LL | ss
|
= help: consider adding the following bound: `'a: 'b`
error: aborting due to 1 previous error; 1 warning emitted
error: aborting due to 1 previous error

View file

@ -0,0 +1,20 @@
//! Trait objects only allow access to methods defined in the trait.
trait MyTrait {
fn trait_method(&mut self);
}
struct ImplType;
impl MyTrait for ImplType {
fn trait_method(&mut self) {}
}
impl ImplType {
fn struct_impl_method(&mut self) {}
}
fn main() {
let obj: Box<dyn MyTrait> = Box::new(ImplType);
obj.struct_impl_method(); //~ ERROR no method named `struct_impl_method` found
}

View file

@ -0,0 +1,15 @@
error[E0599]: no method named `struct_impl_method` found for struct `Box<dyn MyTrait>` in the current scope
--> $DIR/trait-object-method-error.rs:19:9
|
LL | obj.struct_impl_method();
| ^^^^^^^^^^^^^^^^^^
|
help: there is a method `trait_method` with a similar name
|
LL - obj.struct_impl_method();
LL + obj.trait_method();
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0599`.

View file

@ -20,7 +20,7 @@ impl<'a> Drop for r<'a> {
}
}
fn r(i: &Cell<isize>) -> r {
fn r(i: &Cell<isize>) -> r<'_> {
r {
i: i
}

View file

@ -7,7 +7,7 @@ enum roption<'a> {
a, b(&'a usize)
}
fn mk(cond: bool, ptr: &usize) -> roption {
fn mk(cond: bool, ptr: &usize) -> roption<'_> {
if cond {roption::a} else {roption::b(ptr)}
}

View file

@ -14,7 +14,7 @@ impl<'a> Drop for r<'a> {
}
}
fn r(i: &Cell<isize>) -> r {
fn r(i: &Cell<isize>) -> r<'_> {
r {
i: i
}

View file

@ -17,7 +17,7 @@ impl<'a> shrinky_pointer<'a> {
pub fn look_at(&self) -> isize { return self.i.get(); }
}
fn shrinky_pointer(i: &Cell<isize>) -> shrinky_pointer {
fn shrinky_pointer(i: &Cell<isize>) -> shrinky_pointer<'_> {
shrinky_pointer {
i: i
}

View file

@ -0,0 +1,25 @@
//@ run-pass
#![feature(file_with_nul)]
#[track_caller]
const fn assert_file_has_trailing_zero() {
let caller = core::panic::Location::caller();
let file_str = caller.file();
let file_with_nul = caller.file_with_nul();
if file_str.len() != file_with_nul.count_bytes() {
panic!("mismatched lengths");
}
let trailing_byte: core::ffi::c_char = unsafe {
*file_with_nul.as_ptr().offset(file_with_nul.count_bytes() as _)
};
if trailing_byte != 0 {
panic!("trailing byte was nonzero")
}
}
#[allow(dead_code)]
const _: () = assert_file_has_trailing_zero();
fn main() {
assert_file_has_trailing_zero();
}

View file

@ -10,7 +10,7 @@
struct Pd;
impl Pd {
fn it(&self) -> It {
fn it(&self) -> It<'_> {
todo!()
}
}

View file

@ -33,7 +33,7 @@ impl DropOrderCollector {
println!("{n}");
self.0.borrow_mut().push(n)
}
fn some_loud(&self, n: u32) -> Option<LoudDrop> {
fn some_loud(&self, n: u32) -> Option<LoudDrop<'_>> {
Some(LoudDrop(self, n))
}

View file

@ -8,7 +8,7 @@
struct Pd;
impl Pd {
fn it(&self) -> It {
fn it(&self) -> It<'_> {
todo!()
}
}

View file

@ -4,11 +4,11 @@ struct Foo<'a>(&'a str);
impl<'b> Foo<'b> {
fn a<'a>(self: Self, a: &'a str) -> &str {
//~^ WARNING elided lifetime has a name
//~^ WARNING lifetime flowing from input to output with different syntax
a
}
fn b<'a>(self: Foo<'b>, a: &'a str) -> &str {
//~^ WARNING elided lifetime has a name
//~^ WARNING lifetime flowing from input to output with different syntax
a
}
}

View file

@ -1,16 +1,29 @@
warning: elided lifetime has a name
--> $DIR/ignore-non-reference-lifetimes.rs:6:41
warning: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/ignore-non-reference-lifetimes.rs:6:30
|
LL | fn a<'a>(self: Self, a: &'a str) -> &str {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
| ^^ ---- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
= note: `#[warn(elided_named_lifetimes)]` on by default
= note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: one option is to consistently use `'a`
|
LL | fn a<'a>(self: Self, a: &'a str) -> &'a str {
| ++
warning: elided lifetime has a name
--> $DIR/ignore-non-reference-lifetimes.rs:10:44
warning: lifetime flowing from input to output with different syntax can be confusing
--> $DIR/ignore-non-reference-lifetimes.rs:10:33
|
LL | fn b<'a>(self: Foo<'b>, a: &'a str) -> &str {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
| ^^ ---- the lifetime gets resolved as `'a`
| |
| this lifetime flows to the output
|
help: one option is to consistently use `'a`
|
LL | fn b<'a>(self: Foo<'b>, a: &'a str) -> &'a str {
| ++
warning: 2 warnings emitted

View file

@ -1,6 +1,6 @@
//@ edition:2018
//@ run-rustfix
#![allow(non_snake_case, dead_code, elided_named_lifetimes)]
#![allow(non_snake_case, dead_code, mismatched_lifetime_syntaxes)]
use std::pin::Pin;

View file

@ -1,6 +1,6 @@
//@ edition:2018
//@ run-rustfix
#![allow(non_snake_case, dead_code, elided_named_lifetimes)]
#![allow(non_snake_case, dead_code, mismatched_lifetime_syntaxes)]
use std::pin::Pin;

Some files were not shown because too many files have changed in this diff Show more