Skip to content
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

Suppress fallback and ambiguity errors #32258

Merged
merged 7 commits into from
Apr 25, 2016
Merged

Conversation

nikomatsakis
Copy link
Contributor

If the infcx has observed other errors, then suppress both default type
parameter fallback (which can be unreliable, as the full constraint set
is not available) and errors related to unresovled
variables (annoyingly, integer type variables cannot currently be
unified with error, so that has to be a separate mechanism). Also add a
flag to infcx to allow us to independently indicate when we have
observed an error and hence should trigger this suppression mode.

Fixes #31997

cc @alexcrichton
r? @arielb1

@@ -86,6 +86,7 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> {
}

(&ty::TyError, _) | (_, &ty::TyError) => {
infcx.set_tainted_by_errors();
Copy link
Contributor

Choose a reason for hiding this comment

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

When should this be hit? I can think of this causing damage in snapshots.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arielb1

"causing damage"

Yes, we could remove it. I don't think it's needed -- rather, we should set the flag at the source of the errors, as I later did. (I could also assert when setting the flag that we are not in a snapshot, just to be safe.)

@alexcrichton
Copy link
Member

🀄

@nikomatsakis
Copy link
Contributor Author

@arielb1

Casts can resolve types.

Do you see this as a problem for this patch? Can you elaborate?

I would rather change the type_is_known_to_be_sized path (both here and in the other place) to be less violent.

Hmm, ok. What would you like it to do? Just assume true?

Why are integer variables a problem here (maybe we can change ty::cast to be more allowing?).

Because I can't unify them with ty-error.

@nikomatsakis
Copy link
Contributor Author

@arielb1 I'm not really sure where you are in your review here. Do you think I should change something? If so, what you would you prefer? (Or if you're just busy, that's fine too.)

@arielb1
Copy link
Contributor

arielb1 commented Apr 6, 2016

@nikomatsakis

I would prefer to just treat type_is_known_to_be_sized as true if we are checking whether _: Sized and there are errors (for example, () as *const _ should still be an error) and to have ty::cast treat integer/float variables as actual integer/floats.

If you are doing your best attempt to break out of inference, why not just do it?

I was working on a patch that didn't do select_all_obligations_or_error but rather tried to report more specific errors if there were unresolved type variables. That's it, before I became somewhat busy.

Isn't cast checking the only thing downstream of default obligation? And I think we can solve it by being more careful with type_is_known_to_be_sized. And then we can figure out how much undefined-variable-error-reporting we want to do.

@arielb1
Copy link
Contributor

arielb1 commented Apr 6, 2016

I was also thinking about propagating TyErr, at least in method selection and for closure arguments to invalid functions. Maybe ignoring "the type of this variable must be known in this context" is more reliable and does not hide too much errors.

If the infcx has observed other errors, then suppress both default type
parameter fallback (which can be unreliable, as the full constraint set
is not available) and errors related to unresovled
variables (annoyingly, integer type variables cannot currently be
unified with error, so that has to be a separate mechanism). Also add a
flag to `infcx` to allow us to independently indicate when we have
observed an error and hence should trigger this suppression mode.
It is odd to have this logic strewn about.  This also means that all
calls to `type_is_known_to_be_sized` are encapsulated in the
cast code, in case we want to update that logic.
@nikomatsakis
Copy link
Contributor Author

@arielb1 so I removed that error suppression logic out of the casts. It didn't seem to cause any new spurious errors. I decided against modifying the logic for when a type is considered sized since it didn't seem necessary. I've also gotten make check passing and rebased. Take another look and tell me what you think. Given the changes to the errors (lots of duplicates removed) this seems like a positive step to me, and I think it no longer has the invasive quality you were concerned about.

@arielb1
Copy link
Contributor

arielb1 commented Apr 14, 2016

Does this fix let x: *const u32 = 0 as _;? If so, add an rpass test.

@arielb1
Copy link
Contributor

arielb1 commented Apr 14, 2016

Eh, it shouldn't. Maybe put that fix in a separate PR instead?

// For better error messages, we try to check whether the
// target type is known to be sized now (we will also check
// later, once inference is more complete done).
if !fcx.type_is_known_to_be_sized(cast_ty, span) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is constructor doing randomly emitting error messages?

BTW, why do we need the early error message? It causes compilation errors in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arielb1

What is constructor doing randomly emitting error messages?

As you well know, a constructor is just another function... seems like as good a time as any. And the return type (in particular, the Result with ErrorReported) clearly indicates that an error is reported.

My thinking was basically that instantiating a cast check does some checks and returns, potentially, further checks that may need to be done later. I'm happy to rename.

BTW, why do we need the early error message? It causes compilation errors in some cases.

Yes, this doesn't seem optimal, I agree. I was just preserving the existing behavior -- but it seems like it could go wrong, if only in unusual situations like x as _ or x as Bar<_>

I originally moved this check to be done at the end, but then you get derived errors later. For example:

let x = foo as SomeTrait;

will give an error because the type of x is SomeTrait, which is not Sized. (Actually, it then later gives a error about "cast to unsized type".)

Probably the best thing would be to rewrite type_is_known_to_be_sized to return "yes, no, maybe" and only error out on no. (Or, for simplicity, just check specifically for casts to traits or slices, and leave the more general function for the end.)

@nikomatsakis
Copy link
Contributor Author

@arielb1 pushed a new commit that tweaks the approach. Unfortunately, this doesn't seem to be quite enough to make that test work. I didn't dig into why, but you get a "type must be known" error.

@nikomatsakis
Copy link
Contributor Author

oh, I see, because it calls structurally_resolved_type

Do not require the target type to be fully known,
either. This allows code like `let x: *const () = 0 as _` to work
(see regression test).
@nikomatsakis
Copy link
Contributor Author

OK, @arielb1, pushed a new version that fixes the case you mentioned.

@nikomatsakis
Copy link
Contributor Author

r? @pnkfelix (@arielb1 seems busy)

@bors
Copy link
Contributor

bors commented Apr 22, 2016

💔 Test failed - auto-win-gnu-64-opt

@arielb1
Copy link
Contributor

arielb1 commented Apr 22, 2016

@bors retry

What the **** is going with our windows bots?

@bors
Copy link
Contributor

bors commented Apr 22, 2016

💔 Test failed - auto-win-gnu-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Fri, Apr 22, 2016 at 8:46 AM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-win-gnu-32-opt
http://buildbot.rust-lang.org/builders/auto-win-gnu-32-opt/builds/3924


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#32258 (comment)

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 22, 2016
Suppress fallback and ambiguity errors

If the infcx has observed other errors, then suppress both default type
parameter fallback (which can be unreliable, as the full constraint set
is not available) and errors related to unresovled
variables (annoyingly, integer type variables cannot currently be
unified with error, so that has to be a separate mechanism). Also add a
flag to `infcx` to allow us to independently indicate when we have
observed an error and hence should trigger this suppression mode.

Fixes rust-lang#31997

cc @alexcrichton
r? @arielb1
@bors
Copy link
Contributor

bors commented Apr 22, 2016

⌛ Testing commit 89bbd2c with merge d43fb29...

@bors
Copy link
Contributor

bors commented Apr 23, 2016

💔 Test failed - auto-win-msvc-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Fri, Apr 22, 2016 at 5:54 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-win-msvc-32-opt
http://buildbot.rust-lang.org/builders/auto-win-msvc-32-opt/builds/3122


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#32258 (comment)

@bors
Copy link
Contributor

bors commented Apr 23, 2016

⌛ Testing commit 89bbd2c with merge b428b62...

@bors
Copy link
Contributor

bors commented Apr 23, 2016

💔 Test failed - auto-win-msvc-32-opt

@alexcrichton
Copy link
Member

@bors: retry

On Fri, Apr 22, 2016 at 9:47 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-win-msvc-32-opt
http://buildbot.rust-lang.org/builders/auto-win-msvc-32-opt/builds/3124


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#32258 (comment)

@bors
Copy link
Contributor

bors commented Apr 23, 2016

⌛ Testing commit 89bbd2c with merge 3a44be5...

@bors
Copy link
Contributor

bors commented Apr 23, 2016

💔 Test failed - auto-mac-64-nopt-t

@nikomatsakis
Copy link
Contributor Author

@bors r=arielb1

@bors
Copy link
Contributor

bors commented Apr 25, 2016

📌 Commit b3d54a2 has been approved by arielb1

@bors
Copy link
Contributor

bors commented Apr 25, 2016

⌛ Testing commit b3d54a2 with merge 90318b8...

bors added a commit that referenced this pull request Apr 25, 2016
Suppress fallback and ambiguity errors

If the infcx has observed other errors, then suppress both default type
parameter fallback (which can be unreliable, as the full constraint set
is not available) and errors related to unresovled
variables (annoyingly, integer type variables cannot currently be
unified with error, so that has to be a separate mechanism). Also add a
flag to `infcx` to allow us to independently indicate when we have
observed an error and hence should trigger this suppression mode.

Fixes #31997

cc @alexcrichton
r? @arielb1
@bors bors merged commit b3d54a2 into rust-lang:master Apr 25, 2016
@nagisa nagisa added the relnotes Marks issues that should be documented in the release notes of the next release. label May 17, 2016
@nagisa
Copy link
Member

nagisa commented May 17, 2016

Tagging this as relnotes because of #33657

@nikomatsakis nikomatsakis deleted the fewer-errors branch October 3, 2016 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants