Skip to content

Rust: Rename type inference test inline expectation tag #20037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ private import codeql.util.test.InlineExpectationsTest

module Impl implements InlineExpectationsTestSig {
class ExpectationComment extends R::Comment {
ExpectationComment() { this.fromSource() }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a comment inside the standard library starting with $target, so I had to limit expectations comments to those inside the source, which seems right in any case.


/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
string getContents() { result = this.getCommentText() }
}
Expand Down
44 changes: 22 additions & 22 deletions rust/ql/test/library-tests/type-inference/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,73 +30,73 @@ impl<T> Deref for MySmartPointer<T> {
fn explicit_monomorphic_dereference() {
// Dereference with method call
let a1 = MyIntPointer { value: 34i64 };
let _b1 = a1.deref(); // $ method=MyIntPointer::deref type=_b1:&T.i64
let _b1 = a1.deref(); // $ target=MyIntPointer::deref type=_b1:&T.i64

// Dereference with overloaded dereference operator
let a2 = MyIntPointer { value: 34i64 };
let _b2 = *a2; // $ method=MyIntPointer::deref type=_b2:i64
let _b2 = *a2; // $ target=MyIntPointer::deref type=_b2:i64

// Call method on explicitly dereferenced value
let a3 = MyIntPointer { value: 34i64 };
let _b3 = (*a3).is_positive(); // $ method=MyIntPointer::deref method=is_positive type=_b3:bool
let _b3 = (*a3).is_positive(); // $ target=MyIntPointer::deref target=is_positive type=_b3:bool
}

fn explicit_polymorphic_dereference() {
// Explicit dereference with type parameter
let c1 = MySmartPointer { value: 'a' };
let _d1 = c1.deref(); // $ method=MySmartPointer::deref type=_d1:&T.char
let _d1 = c1.deref(); // $ target=MySmartPointer::deref type=_d1:&T.char

// Explicit dereference with type parameter
let c2 = MySmartPointer { value: 'a' };
let _d2 = *c2; // $ method=MySmartPointer::deref type=_d2:char
let _d2 = *c2; // $ target=MySmartPointer::deref type=_d2:char

// Call method on explicitly dereferenced value with type parameter
let c3 = MySmartPointer { value: 34i64 };
let _d3 = (*c3).is_positive(); // $ method=MySmartPointer::deref method=is_positive type=_d3:bool
let _d3 = (*c3).is_positive(); // $ target=MySmartPointer::deref target=is_positive type=_d3:bool
}

fn explicit_ref_dereference() {
// Explicit dereference with type parameter
let e1 = &'a';
let _f1 = e1.deref(); // $ method=deref MISSING: type=_f1:&T.char
let _f1 = e1.deref(); // $ target=deref MISSING: type=_f1:&T.char

// Explicit dereference with type parameter
let e2 = &'a';
let _f2 = *e2; // $ method=deref type=_f2:char
let _f2 = *e2; // $ target=deref type=_f2:char

// Call method on explicitly dereferenced value with type parameter
let e3 = &34i64;
let _f3 = (*e3).is_positive(); // $ method=deref method=is_positive type=_f3:bool
let _f3 = (*e3).is_positive(); // $ target=deref target=is_positive type=_f3:bool
}

fn explicit_box_dereference() {
// Explicit dereference with type parameter
let g1: Box<char> = Box::new('a'); // $ method=new
let _h1 = g1.deref(); // $ method=deref type=_h1:&T.char
let g1: Box<char> = Box::new('a'); // $ target=new
let _h1 = g1.deref(); // $ target=deref type=_h1:&T.char

// Explicit dereference with type parameter
let g2: Box<char> = Box::new('a'); // $ method=new
let _h2 = *g2; // $ method=deref type=_h2:char
let g2: Box<char> = Box::new('a'); // $ target=new
let _h2 = *g2; // $ target=deref type=_h2:char

// Call method on explicitly dereferenced value with type parameter
let g3: Box<i64> = Box::new(34i64); // $ method=new
let _h3 = (*g3).is_positive(); // $ method=deref method=is_positive type=_h3:bool
let g3: Box<i64> = Box::new(34i64); // $ target=new
let _h3 = (*g3).is_positive(); // $ target=deref target=is_positive type=_h3:bool
}

fn implicit_dereference() {
// Call method on implicitly dereferenced value
let x = MyIntPointer { value: 34i64 };
let _y = x.is_positive(); // $ MISSING: method=is_positive type=_y:bool
let _y = x.is_positive(); // $ MISSING: target=is_positive type=_y:bool

// Call method on implicitly dereferenced value
let x = MySmartPointer { value: 34i64 };
let _y = x.is_positive(); // $ MISSING: method=is_positive type=_y:bool
let _y = x.is_positive(); // $ MISSING: target=is_positive type=_y:bool
}

pub fn test() {
explicit_monomorphic_dereference(); // $ method=explicit_monomorphic_dereference
explicit_polymorphic_dereference(); // $ method=explicit_polymorphic_dereference
explicit_ref_dereference(); // $ method=explicit_ref_dereference
explicit_box_dereference(); // $ method=explicit_box_dereference
implicit_dereference(); // $ method=implicit_dereference
explicit_monomorphic_dereference(); // $ target=explicit_monomorphic_dereference
explicit_polymorphic_dereference(); // $ target=explicit_polymorphic_dereference
explicit_ref_dereference(); // $ target=explicit_ref_dereference
explicit_box_dereference(); // $ target=explicit_box_dereference
implicit_dereference(); // $ target=implicit_dereference
}
2 changes: 1 addition & 1 deletion rust/ql/test/library-tests/type-inference/loop/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ trait T1<T>: T2<S<T>> {

trait T2<T>: T1<S<T>> {
fn bar(self) {
self.foo() // $ method=foo
self.foo() // $ target=foo
}
}
Loading