Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mu001999 committed Jan 15, 2024
1 parent 999a162 commit 155ca3d
Show file tree
Hide file tree
Showing 266 changed files with 1,031 additions and 230 deletions.
49 changes: 2 additions & 47 deletions compiler/rustc_span/src/source_map/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::*;

use rustc_data_structures::sync::FreezeLock;

fn init_source_map() -> SourceMap {
let sm = SourceMap::new(FilePathMapping::empty());
sm.new_source_file(PathBuf::from("blork.rs").into(), "first line.\nsecond line".to_string());
Expand Down Expand Up @@ -263,53 +265,6 @@ fn t10() {
);
}

/// Returns the span corresponding to the `n`th occurrence of `substring` in `source_text`.
trait SourceMapExtension {
fn span_substr(
&self,
file: &Lrc<SourceFile>,
source_text: &str,
substring: &str,
n: usize,
) -> Span;
}

impl SourceMapExtension for SourceMap {
fn span_substr(
&self,
file: &Lrc<SourceFile>,
source_text: &str,
substring: &str,
n: usize,
) -> Span {
eprintln!(
"span_substr(file={:?}/{:?}, substring={:?}, n={})",
file.name, file.start_pos, substring, n
);
let mut i = 0;
let mut hi = 0;
loop {
let offset = source_text[hi..].find(substring).unwrap_or_else(|| {
panic!(
"source_text `{}` does not have {} occurrences of `{}`, only {}",
source_text, n, substring, i
);
});
let lo = hi + offset;
hi = lo + substring.len();
if i == n {
let span = Span::with_root_ctxt(
BytePos(lo as u32 + file.start_pos.0),
BytePos(hi as u32 + file.start_pos.0),
);
assert_eq!(&self.span_to_snippet(span).unwrap()[..], substring);
return span;
}
i += 1;
}
}
}

// Takes a unix-style path and returns a platform specific path.
fn path(p: &str) -> PathBuf {
path_str(p).into()
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/macros.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(dead_code)]
trait Trait {
fn blah(&self);
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/fail/dyn-call-trait-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
trait T1 {
#[allow(dead_code)]
fn method1(self: Box<Self>);
}
trait T2 {
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/tests/fail/dyn-upcast-trait-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
trait Foo: PartialEq<i32> + std::fmt::Debug + Send + Sync {
#[allow(dead_code)]
fn a(&self) -> i32 {
10
}

#[allow(dead_code)]
fn z(&self) -> i32 {
11
}

#[allow(dead_code)]
fn y(&self) -> i32 {
12
}
}

trait Bar: Foo {
#[allow(dead_code)]
fn b(&self) -> i32 {
20
}

#[allow(dead_code)]
fn w(&self) -> i32 {
21
}
}

trait Baz: Bar {
#[allow(dead_code)]
fn c(&self) -> i32 {
30
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/cast-rfc0401-vtable-kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trait Foo<T> {
}
}

#[allow(dead_code)]
trait Bar {
fn bar(&self) {
println!("Bar!");
Expand Down
3 changes: 3 additions & 0 deletions src/tools/miri/tests/pass/dyn-upcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,17 @@ fn struct_() {

fn replace_vptr() {
trait A {
#[allow(dead_code)]
fn foo_a(&self);
}

trait B {
#[allow(dead_code)]
fn foo_b(&self);
}

trait C: A + B {
#[allow(dead_code)]
fn foo_c(&self);
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/miri/tests/pass/weak_memory/weak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::atomic::Ordering::*;
use std::sync::atomic::{fence, AtomicUsize};
use std::thread::spawn;

#[allow(dead_code)]
#[derive(Copy, Clone)]
struct EvilSend<T>(pub T);

Expand Down
4 changes: 2 additions & 2 deletions src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::path::{Path, PathBuf};

const ENTRY_LIMIT: usize = 900;
// FIXME: The following limits should be reduced eventually.
const ISSUES_ENTRY_LIMIT: usize = 1849;
const ROOT_ENTRY_LIMIT: usize = 870;
const ISSUES_ENTRY_LIMIT: usize = 1861;
const ROOT_ENTRY_LIMIT: usize = 872;

const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
"rs", // test source files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ fn start(_: isize, _: *const *const u8) -> isize {
//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct<u32>> - shim(None) @@ instantiation_through_vtable-cgu.0[Internal]
//~ MONO_ITEM fn <Struct<u32> as Trait>::foo
//~ MONO_ITEM fn <Struct<u32> as Trait>::bar
let _ = &s1 as &Trait;
let r1 = &s1 as &Trait;
r1.foo();
r1.bar();

let s1 = Struct { _a: 0u64 };
//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct<u64>> - shim(None) @@ instantiation_through_vtable-cgu.0[Internal]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@ fn start(_: isize, _: *const *const u8) -> isize {
//~ MONO_ITEM fn <u32 as SomeGenericTrait<i16>>::bar::<()>
0u32.bar(0i16, ());

0i8.foo();
0i32.foo();

0
}
2 changes: 2 additions & 0 deletions tests/codegen-units/item-collection/unsizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,7 @@ fn start(_: isize, _: *const *const u8) -> isize {
//~ MONO_ITEM fn <u32 as Trait>::foo
let _wrapper_sized = wrapper_sized as Wrapper<Trait>;

false.foo();

0
}
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/rustc_encodable_hygiene.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// run-pass
// check-pass

#![feature(rustc_private)]

Expand Down
1 change: 1 addition & 0 deletions tests/ui/anon-params/anon-params-deprecated.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// edition:2015
// run-rustfix

#[allow(dead_code)]
trait T {
fn foo(_: i32); //~ WARNING anonymous parameters are deprecated
//~| WARNING this is accepted in the current edition
Expand Down
1 change: 1 addition & 0 deletions tests/ui/anon-params/anon-params-deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// edition:2015
// run-rustfix

#[allow(dead_code)]
trait T {
fn foo(i32); //~ WARNING anonymous parameters are deprecated
//~| WARNING this is accepted in the current edition
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/anon-params/anon-params-deprecated.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: anonymous parameters are deprecated and will be removed in the next edition
--> $DIR/anon-params-deprecated.rs:9:12
--> $DIR/anon-params-deprecated.rs:10:12
|
LL | fn foo(i32);
| ^^^ help: try naming the parameter or explicitly ignoring it: `_: i32`
Expand All @@ -13,7 +13,7 @@ LL | #![warn(anonymous_parameters)]
| ^^^^^^^^^^^^^^^^^^^^

warning: anonymous parameters are deprecated and will be removed in the next edition
--> $DIR/anon-params-deprecated.rs:12:30
--> $DIR/anon-params-deprecated.rs:13:30
|
LL | fn bar_with_default_impl(String, String) {}
| ^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: String`
Expand All @@ -22,7 +22,7 @@ LL | fn bar_with_default_impl(String, String) {}
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>

warning: anonymous parameters are deprecated and will be removed in the next edition
--> $DIR/anon-params-deprecated.rs:12:38
--> $DIR/anon-params-deprecated.rs:13:38
|
LL | fn bar_with_default_impl(String, String) {}
| ^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: String`
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/associated-consts/associated-const-outer-ty-refs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-pass
// check-pass

trait Lattice {
const BOTTOM: Self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn sub<A: Foo, B: Foo>() -> i32 {
A::X - B::X
}

trait Bar: Foo {
trait Bar: Foo { //~ WARN trait `Bar` is never used
const Y: i32 = Self::X;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/ui/associated-consts/associated-const-type-parameters.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: trait `Bar` is never used
--> $DIR/associated-const-type-parameters.rs:30:7
|
LL | trait Bar: Foo {
| ^^^
|
= note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/associated-type-bounds/dyn-impl-trait-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::ops::Add;

trait Tr1 { type As1; fn mk(&self) -> Self::As1; }
trait Tr2<'a> { fn tr2(self) -> &'a Self; }
trait Tr2<'a> { fn tr2(self) -> &'a Self; } //~ WARN method `tr2` is never used

fn assert_copy<T: Copy>(x: T) { let _x = x; let _x = x; }
fn assert_static<T: 'static>(_: T) {}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/associated-type-bounds/dyn-impl-trait-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
warning: method `tr2` is never used
--> $DIR/dyn-impl-trait-type.rs:8:20
|
LL | trait Tr2<'a> { fn tr2(self) -> &'a Self; }
| --- ^^^
| |
| method in this trait
|
= note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/associated-type-bounds/dyn-rpit-and-let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::ops::Add;

trait Tr1 { type As1; fn mk(&self) -> Self::As1; }
trait Tr2<'a> { fn tr2(self) -> &'a Self; }
trait Tr2<'a> { fn tr2(self) -> &'a Self; } //~ WARN method `tr2` is never used

fn assert_copy<T: Copy>(x: T) { let _x = x; let _x = x; }
fn assert_static<T: 'static>(_: T) {}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/associated-type-bounds/dyn-rpit-and-let.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
warning: method `tr2` is never used
--> $DIR/dyn-rpit-and-let.rs:10:20
|
LL | trait Tr2<'a> { fn tr2(self) -> &'a Self; }
| --- ^^^
| |
| method in this trait
|
= note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/associated-type-bounds/rpit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::ops::Add;

trait Tr1 { type As1; fn mk(self) -> Self::As1; }
trait Tr2<'a> { fn tr2(self) -> &'a Self; }
trait Tr2<'a> { fn tr2(self) -> &'a Self; } //~ WARN method `tr2` is never used

fn assert_copy<T: Copy>(x: T) { let _x = x; let _x = x; }
fn assert_static<T: 'static>(_: T) {}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/associated-type-bounds/rpit.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
warning: method `tr2` is never used
--> $DIR/rpit.rs:8:20
|
LL | trait Tr2<'a> { fn tr2(self) -> &'a Self; }
| --- ^^^
| |
| method in this trait
|
= note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
#![allow(dead_code)]
trait O {
type M;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
#![allow(dead_code)]
trait O {
type M;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/suggest-contraining-assoc-type-because-of-assoc-const.rs:12:21
--> $DIR/suggest-contraining-assoc-type-because-of-assoc-const.rs:13:21
|
LL | const N: C::M = 4u8;
| ^^^ expected associated type, found `u8`
Expand Down
1 change: 1 addition & 0 deletions tests/ui/associated-type-bounds/trait-alias-impl-trait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// run-pass

#![allow(dead_code)]
#![feature(associated_type_bounds)]
#![feature(type_alias_impl_trait)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
#![allow(dead_code)]
#![allow(unused_variables)]

trait Get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
#![allow(dead_code)]
#![allow(unused_variables)]

trait Get {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `Self: Get` is not satisfied
--> $DIR/associated-types-for-unimpl-trait.rs:10:40
--> $DIR/associated-types-for-unimpl-trait.rs:11:40
|
LL | fn uhoh<U:Get>(&self, foo: U, bar: <Self as Get>::Value) {}
| ^^^^^^^^^^^^^^^^^^^^ the trait `Get` is not implemented for `Self`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// run-pass
// check-pass
// Test the case where we resolve `C::Result` and the trait bound
// itself includes a `Self::Item` shorthand.
//
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/associated-types-issue-20220.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::vec;

trait IntoIteratorX {
trait IntoIteratorX { //~ WARN trait `IntoIteratorX` is never used
type Item;
type IntoIter: Iterator<Item=Self::Item>;

Expand Down
10 changes: 10 additions & 0 deletions tests/ui/associated-types/associated-types-issue-20220.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
warning: trait `IntoIteratorX` is never used
--> $DIR/associated-types-issue-20220.rs:7:7
|
LL | trait IntoIteratorX {
| ^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/associated-types/associated-types-issue-20371.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// run-pass
// check-pass
// Test that we are able to have an impl that defines an associated type
// before the actual trait.

Expand Down
Loading

0 comments on commit 155ca3d

Please sign in to comment.