Skip to content

Commit

Permalink
Fix a bug building with Rust 1.19. (#198)
Browse files Browse the repository at this point in the history
* Add global Cargo settings for all packages.

* Fix a bug building with Rust 1.19.

Due to a bug (rust-lang/cargo#4223), Rust was
displaying the stdout of the compiler, causing the parsing code to get
confused.

Also, update tests for 1.19 message changes, and deprecation of no-trans.
  • Loading branch information
ehuss authored and Jason Williams committed Aug 19, 2017
1 parent 4ed1f6c commit 293cd54
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
12 changes: 10 additions & 2 deletions rust/rust_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import threading
import time
import shellenv
import traceback

from . import util

Expand Down Expand Up @@ -298,13 +299,20 @@ def _read_stdout(self):
try:
self.listener.on_json(self, result)
except:
self._cleanup()
raise
self.listener.on_error(self,
'Rust Enhanced Internal Error: %s' % (
traceback.format_exc(),))
else:
if self.json_stop_pattern and \
re.match(self.json_stop_pattern, line):
# Stop looking for JSON open curly bracket.
self.decode_json = False
if line.startswith('--- stderr'):
# Rust 1.19 had a bug
# (https://github.com/rust-lang/cargo/issues/4223) where
# it was incorrectly printing stdout from the compiler
# (fixed in 1.20).
self.decode_json = False
# Sublime always uses \n internally.
line = line.replace('\r\n', '\n')
self.listener.on_data(self, line)
Expand Down
1 change: 1 addition & 0 deletions tests/error-tests/benches/bench_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

#[asdf]
// ^^^^^^^ERR The attribute `asdf` is currently unknown
// ^^^^^^^HELP(>=1.21.0-nightly) add #![feature(custom_attribute)]
fn f() {}
6 changes: 4 additions & 2 deletions tests/error-tests/tests/binop-mul-bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
// error-pattern:`*` cannot be applied to type `bool`

fn main() { let x = true * false; }
// ^^^^ERR binary operation
// ^^^^NOTE an implementation of
// ^^^^ERR(<1.19.0) binary operation
// ^^^^NOTE(<1.19.0) an implementation of
// ^^^^^^^^^^^^ERR(>=1.19.0) binary operation
// ^^^^^^^^^^^^NOTE(>=1.19.0) an implementation of
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fn main() {
// ^^^^HELP &1 as &Send
Box::new(1) as Send;
// ^^^^^^^^^^^^^^^^^^^ERR cast to unsized type
// ^^^^HELP try casting to a `Box` instead:
// ^^^^HELP try casting to a `Box` instead
// ^^^^HELP Box::new(1) as Box<Send>;
}
31 changes: 25 additions & 6 deletions tests/test_syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def test_messages(self):
methods.append('check')
else:
print('Skipping check, need rust >= 1.16.')
if semver.match(self.rustc_version, '>=1.19.0'):
# -Zno-trans now requires nightly
self._override_setting('cargo_build', {
'variants': {
'no-trans': {
'toolchain': 'nightly'
}
}
})
for path in to_test:
path = os.path.join('tests', path)
self._with_open_file(path, self._test_messages,
Expand Down Expand Up @@ -134,6 +143,15 @@ def _test_messages2(self, view, phantoms, regions, method):
self._get_rust_thread().join()
expected_messages = self._collect_expected_regions(view)

# Refresh based on the toolchain used.
window = sublime.active_window()
manifest_path = util.find_cargo_manifest(view.file_name())
cs = cargo_settings.CargoSettings(window)
cs.load()
toolchain = cs.get_computed(manifest_path, method, None, 'toolchain')
self.rustc_version = util.get_rustc_version(window, manifest_path,
toolchain=toolchain)

def restriction_check(restrictions):
if not restrictions:
return True
Expand Down Expand Up @@ -162,14 +180,14 @@ def restriction_check(restrictions):
self.assertIn(emsg_info['level_text'], content)
break
else:
raise AssertionError('Did not find expected message "%s:%s" for region %r:%r for file %r' % (
raise AssertionError('Did not find expected message "%s:%s" for region %r:%r for file %r method=%r\nAvailable phantoms=%r' % (
emsg_info['level'], emsg_info['message'],
emsg_info['begin'], emsg_info['end'],
view.file_name()))
view.file_name(), method, phantoms))
del phantoms[i]
if len(phantoms):
raise AssertionError('Got extra phantoms for %r: %r' % (
view.file_name(), phantoms))
raise AssertionError('Got extra phantoms for %r (method=%s): %r' % (
view.file_name(), method, phantoms))

# Check regions.
found_regions = set()
Expand All @@ -181,8 +199,9 @@ def restriction_check(restrictions):
if r in region_set:
found_regions.add(r)
else:
raise AssertionError('Did not find expected region %r,%r for file %r' % (
emsg_info['begin'], emsg_info['end'], view.file_name()))
raise AssertionError('Did not find expected region %r,%r for file %r method %r\nActual regions=%r' % (
emsg_info['begin'], emsg_info['end'], view.file_name(),
method, region_set))
if len(region_set) != len(found_regions):
extra_regions = region_set - found_regions
raise AssertionError('Got extra regions for %r: %r' % (
Expand Down
1 change: 1 addition & 0 deletions tests/workspace/workspace1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod anothermod;
// ^^^^^^^^ERR(>=1.18.0) recursive type `S` has infinite size
// ^^^^^^^^HELP(>=1.18.0) insert indirection
recursive: S
// ^^^^^^^^^^^^ERR(>=1.19.0) recursive without indirection
}/*END*/
// ~ERR(<1.18.0) recursive type has infinite size
// ~ERR(<1.18.0) recursive type `S` has infinite size
Expand Down

0 comments on commit 293cd54

Please sign in to comment.