-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tweaks to invalid ctor messages #47116
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9bab0f0
Hide suggestion to use struct ctor when it is not visible
estebank a317da4
Suggest the correct syntax for different struct types
estebank ce9ef37
Readd suggestion in enum variants with incorrect args
estebank 38546ba
Add note when trying to use `Self` as a ctor
estebank 445f339
address review comments
estebank 4a76916
Further tweaks to the output
estebank 282f75a
Review comments: remove enum suggestion
estebank 0674050
Fix tests by keepeing needed suggestions
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
error[E0618]: expected function, found `Empty2` | ||
--> $DIR/empty-struct-unit-expr.rs:25:14 | ||
| | ||
25 | let e2 = Empty2(); //~ ERROR expected function, found `Empty2` | ||
| ^^^^^^^^ | ||
| | ||
note: defined here | ||
--> $DIR/empty-struct-unit-expr.rs:18:1 | ||
| | ||
18 | struct Empty2; | ||
| ^^^^^^^^^^^^^^ | ||
| -------------- `Empty2` defined here | ||
... | ||
25 | let e2 = Empty2(); //~ ERROR expected function, found `Empty2` | ||
| ^^^^^^^^ not a function | ||
|
||
error[E0618]: expected function, found `E::Empty4` | ||
error[E0618]: expected function, found enum variant `E::Empty4` | ||
--> $DIR/empty-struct-unit-expr.rs:26:14 | ||
| | ||
21 | Empty4 | ||
| ------ `E::Empty4` defined here | ||
... | ||
26 | let e4 = E::Empty4(); | ||
| ^^^^^^^^^^^ | ||
| | ||
= help: did you mean to write `E::Empty4`? | ||
note: defined here | ||
--> $DIR/empty-struct-unit-expr.rs:21:5 | ||
| ^^^^^^^^^^^ not a function | ||
help: `E::Empty4` is a unit variant, you need to write it without the parenthesis | ||
| | ||
21 | Empty4 | ||
| ^^^^^^ | ||
26 | let e4 = E::Empty4; | ||
| ^^^^^^^^^ | ||
|
||
error[E0618]: expected function, found `empty_struct::XEmpty2` | ||
--> $DIR/empty-struct-unit-expr.rs:28:15 | ||
| | ||
28 | let xe2 = XEmpty2(); //~ ERROR expected function, found `empty_struct::XEmpty2` | ||
| ^^^^^^^^^ | ||
| ^^^^^^^^^ not a function | ||
|
||
error[E0618]: expected function, found `XE::XEmpty4` | ||
error[E0618]: expected function, found enum variant `XE::XEmpty4` | ||
--> $DIR/empty-struct-unit-expr.rs:29:15 | ||
| | ||
29 | let xe4 = XE::XEmpty4(); | ||
| ^^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^^ not a function | ||
help: `XE::XEmpty4` is a unit variant, you need to write it without the parenthesis | ||
| | ||
= help: did you mean to write `XE::XEmpty4`? | ||
29 | let xe4 = XE::XEmpty4; | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
error[E0618]: expected function, found `i32` | ||
--> $DIR/issue-10969.rs:12:5 | ||
| | ||
12 | i(); //~ERROR expected function, found `i32` | ||
| ^^^ | ||
| | ||
note: defined here | ||
--> $DIR/issue-10969.rs:11:9 | ||
| | ||
11 | fn func(i: i32) { | ||
| ^ | ||
| - `i32` defined here | ||
12 | i(); //~ERROR expected function, found `i32` | ||
| ^^^ not a function | ||
|
||
error[E0618]: expected function, found `i32` | ||
--> $DIR/issue-10969.rs:16:5 | ||
| | ||
16 | i(); //~ERROR expected function, found `i32` | ||
| ^^^ | ||
| | ||
note: defined here | ||
--> $DIR/issue-10969.rs:15:9 | ||
| | ||
15 | let i = 0i32; | ||
| ^ | ||
| - `i32` defined here | ||
16 | i(); //~ERROR expected function, found `i32` | ||
| ^^^ not a function | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
mod m { | ||
pub enum E { | ||
Fn(u8), | ||
Struct { | ||
s: u8, | ||
}, | ||
Unit, | ||
} | ||
|
||
pub mod n { | ||
pub(in m) enum Z { | ||
Fn(u8), | ||
Struct { | ||
s: u8, | ||
}, | ||
Unit, | ||
} | ||
} | ||
|
||
use m::n::Z; // OK, only the type is imported | ||
|
||
fn f() { | ||
n::Z; | ||
//~^ ERROR expected value, found enum `n::Z` | ||
Z; | ||
//~^ ERROR expected value, found enum `Z` | ||
let _: Z = Z::Fn; | ||
//~^ ERROR mismatched types | ||
let _: Z = Z::Struct; | ||
//~^ ERROR expected value, found struct variant `Z::Struct` | ||
let _ = Z::Unit(); | ||
//~^ ERROR expected function, found enum variant `Z::Unit` | ||
let _ = Z::Unit {}; | ||
// This is ok, it is equivalent to not having braces | ||
} | ||
} | ||
|
||
use m::E; // OK, only the type is imported | ||
|
||
fn main() { | ||
let _: E = m::E; | ||
//~^ ERROR expected value, found enum `m::E` | ||
let _: E = m::E::Fn; | ||
//~^ ERROR mismatched types | ||
let _: E = m::E::Struct; | ||
//~^ ERROR expected value, found struct variant `m::E::Struct` | ||
let _: E = m::E::Unit(); | ||
//~^ ERROR expected function, found enum variant `m::E::Unit` | ||
let _: E = E; | ||
//~^ ERROR expected value, found enum `E` | ||
let _: E = E::Fn; | ||
//~^ ERROR mismatched types | ||
let _: E = E::Struct; | ||
//~^ ERROR expected value, found struct variant `E::Struct` | ||
let _: E = E::Unit(); | ||
//~^ ERROR expected function, found enum variant `E::Unit` | ||
let _: Z = m::n::Z; | ||
//~^ ERROR cannot find type `Z` in this scope | ||
//~| ERROR expected value, found enum `m::n::Z` | ||
//~| ERROR enum `Z` is private | ||
let _: Z = m::n::Z::Fn; | ||
//~^ ERROR cannot find type `Z` in this scope | ||
//~| ERROR enum `Z` is private | ||
let _: Z = m::n::Z::Struct; | ||
//~^ ERROR cannot find type `Z` in this scope | ||
//~| ERROR expected value, found struct variant `m::n::Z::Struct` | ||
//~| ERROR enum `Z` is private | ||
let _: Z = m::n::Z::Unit {}; | ||
//~^ ERROR cannot find type `Z` in this scope | ||
//~| ERROR enum `Z` is private | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Def::Union(..)
,Def::Variant(..)
andDef::VariantCtor(_, CtorKind::Fictive)
can be added here to restore what the previous code did (they are equivalent to structs without accessible constructors in this context).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only
CtorKind::Fictive
is relevant here because for others #47116 (comment) still holds.