Skip to content

Commit 293cd54

Browse files
ehussJayflux
authored andcommitted
Fix a bug building with Rust 1.19. (#198)
* 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.
1 parent 4ed1f6c commit 293cd54

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

rust/rust_proc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import threading
1313
import time
1414
import shellenv
15+
import traceback
1516

1617
from . import util
1718

@@ -298,13 +299,20 @@ def _read_stdout(self):
298299
try:
299300
self.listener.on_json(self, result)
300301
except:
301-
self._cleanup()
302-
raise
302+
self.listener.on_error(self,
303+
'Rust Enhanced Internal Error: %s' % (
304+
traceback.format_exc(),))
303305
else:
304306
if self.json_stop_pattern and \
305307
re.match(self.json_stop_pattern, line):
306308
# Stop looking for JSON open curly bracket.
307309
self.decode_json = False
310+
if line.startswith('--- stderr'):
311+
# Rust 1.19 had a bug
312+
# (https://github.com/rust-lang/cargo/issues/4223) where
313+
# it was incorrectly printing stdout from the compiler
314+
# (fixed in 1.20).
315+
self.decode_json = False
308316
# Sublime always uses \n internally.
309317
line = line.replace('\r\n', '\n')
310318
self.listener.on_data(self, line)

tests/error-tests/benches/bench_err.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
#[asdf]
55
// ^^^^^^^ERR The attribute `asdf` is currently unknown
6+
// ^^^^^^^HELP(>=1.21.0-nightly) add #![feature(custom_attribute)]
67
fn f() {}

tests/error-tests/tests/binop-mul-bool.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
// error-pattern:`*` cannot be applied to type `bool`
1212

1313
fn main() { let x = true * false; }
14-
// ^^^^ERR binary operation
15-
// ^^^^NOTE an implementation of
14+
// ^^^^ERR(<1.19.0) binary operation
15+
// ^^^^NOTE(<1.19.0) an implementation of
16+
// ^^^^^^^^^^^^ERR(>=1.19.0) binary operation
17+
// ^^^^^^^^^^^^NOTE(>=1.19.0) an implementation of

tests/error-tests/tests/cast-to-unsized-trait-object-suggestion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
// ^^^^HELP &1 as &Send
1616
Box::new(1) as Send;
1717
// ^^^^^^^^^^^^^^^^^^^ERR cast to unsized type
18-
// ^^^^HELP try casting to a `Box` instead:
18+
// ^^^^HELP try casting to a `Box` instead
1919
// ^^^^HELP Box::new(1) as Box<Send>;
2020
}

tests/test_syntax_check.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ def test_messages(self):
8383
methods.append('check')
8484
else:
8585
print('Skipping check, need rust >= 1.16.')
86+
if semver.match(self.rustc_version, '>=1.19.0'):
87+
# -Zno-trans now requires nightly
88+
self._override_setting('cargo_build', {
89+
'variants': {
90+
'no-trans': {
91+
'toolchain': 'nightly'
92+
}
93+
}
94+
})
8695
for path in to_test:
8796
path = os.path.join('tests', path)
8897
self._with_open_file(path, self._test_messages,
@@ -134,6 +143,15 @@ def _test_messages2(self, view, phantoms, regions, method):
134143
self._get_rust_thread().join()
135144
expected_messages = self._collect_expected_regions(view)
136145

146+
# Refresh based on the toolchain used.
147+
window = sublime.active_window()
148+
manifest_path = util.find_cargo_manifest(view.file_name())
149+
cs = cargo_settings.CargoSettings(window)
150+
cs.load()
151+
toolchain = cs.get_computed(manifest_path, method, None, 'toolchain')
152+
self.rustc_version = util.get_rustc_version(window, manifest_path,
153+
toolchain=toolchain)
154+
137155
def restriction_check(restrictions):
138156
if not restrictions:
139157
return True
@@ -162,14 +180,14 @@ def restriction_check(restrictions):
162180
self.assertIn(emsg_info['level_text'], content)
163181
break
164182
else:
165-
raise AssertionError('Did not find expected message "%s:%s" for region %r:%r for file %r' % (
183+
raise AssertionError('Did not find expected message "%s:%s" for region %r:%r for file %r method=%r\nAvailable phantoms=%r' % (
166184
emsg_info['level'], emsg_info['message'],
167185
emsg_info['begin'], emsg_info['end'],
168-
view.file_name()))
186+
view.file_name(), method, phantoms))
169187
del phantoms[i]
170188
if len(phantoms):
171-
raise AssertionError('Got extra phantoms for %r: %r' % (
172-
view.file_name(), phantoms))
189+
raise AssertionError('Got extra phantoms for %r (method=%s): %r' % (
190+
view.file_name(), method, phantoms))
173191

174192
# Check regions.
175193
found_regions = set()
@@ -181,8 +199,9 @@ def restriction_check(restrictions):
181199
if r in region_set:
182200
found_regions.add(r)
183201
else:
184-
raise AssertionError('Did not find expected region %r,%r for file %r' % (
185-
emsg_info['begin'], emsg_info['end'], view.file_name()))
202+
raise AssertionError('Did not find expected region %r,%r for file %r method %r\nActual regions=%r' % (
203+
emsg_info['begin'], emsg_info['end'], view.file_name(),
204+
method, region_set))
186205
if len(region_set) != len(found_regions):
187206
extra_regions = region_set - found_regions
188207
raise AssertionError('Got extra regions for %r: %r' % (

tests/workspace/workspace1/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod anothermod;
55
// ^^^^^^^^ERR(>=1.18.0) recursive type `S` has infinite size
66
// ^^^^^^^^HELP(>=1.18.0) insert indirection
77
recursive: S
8+
// ^^^^^^^^^^^^ERR(>=1.19.0) recursive without indirection
89
}/*END*/
910
// ~ERR(<1.18.0) recursive type has infinite size
1011
// ~ERR(<1.18.0) recursive type `S` has infinite size

0 commit comments

Comments
 (0)