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

Rollup of 11 pull requests #104480

Closed
wants to merge 88 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
7c56896
Feat: extracted method from trait impl is placed in existing impl
Aug 9, 2022
7402366
Avoid cloning IMPL node if we don't have to
Aug 10, 2022
d5e6aa3
Pre-cast impl nodes to ast::Impl in find_non_trait_impl
Sep 1, 2022
2484a18
Add `compile_fail` to `let_underscore_drop` example
saschanaz Oct 24, 2022
3ff010b
Update compiler/rustc_lint/src/let_underscore.rs
saschanaz Oct 24, 2022
6b5f275
Update let_underscore.rs
saschanaz Oct 24, 2022
6279d09
Make `pointer::byte_offset_from` more generic
WaffleLapkin Oct 24, 2022
8ecbb7e
fix the lint as requested
saschanaz Oct 24, 2022
30b5223
Fix failing examples
saschanaz Oct 24, 2022
c98fc53
Generalize reborrow hints as adjustment hints
Veykril Nov 4, 2022
95d20fc
Add adjustment hint tests
Veykril Nov 4, 2022
d841ad1
Fix up adjustment hints configurations
Veykril Nov 4, 2022
e468a1a
internal: Optimize `apply_document_changes` a bit
Veykril Nov 4, 2022
28afe57
Add tests for LineEndings::normalize
Veykril Nov 5, 2022
b87a23b
Rename convertor -> converter
lowr Nov 2, 2022
41b0c54
Fix `tt::Punct`'s spacing calculation
lowr Nov 5, 2022
1dcc25a
internal: Use a process group for flycheck
Veykril Nov 5, 2022
7742077
Auto merge of #13552 - Veykril:flycheck-process-group, r=Veykril
bors Nov 7, 2022
f54c313
Auto merge of #13547 - Veykril:line-index, r=Veykril
bors Nov 7, 2022
cff7ab1
Fix typos
lnicola Nov 7, 2022
364820a
Auto merge of #13566 - lnicola:therefor, r=lnicola
bors Nov 7, 2022
f24fbc2
rustfmt
Veykril Nov 7, 2022
8ad4a1d
Update sysroot crates
Veykril Nov 7, 2022
d3d3806
Auto merge of #12991 - TiddoLangerak:extract-method-from-trait-into-i…
bors Nov 7, 2022
180b4ce
Fix the length displayed for byte string literals with escaped newlines
noritada Nov 7, 2022
c0310c1
Auto merge of #13565 - Veykril:sysroot, r=Veykril
bors Nov 7, 2022
ee2dd93
Don't trigger adjustment hints in all inlay hint tests
Veykril Nov 7, 2022
ffd7bf8
Bump Cargo rust-version fields to latest stable
Veykril Nov 7, 2022
bdf8547
Clarify the intent
noritada Nov 7, 2022
3a839ea
Auto merge of #13569 - Veykril:rust-version, r=Veykril
bors Nov 7, 2022
b0e56ef
Auto merge of #13545 - Veykril:adjustment-hints, r=Veykril
bors Nov 7, 2022
2340d70
Add test code for unescaping byte strings
noritada Nov 7, 2022
b169e1e
Remove code duplication
Veykril Nov 7, 2022
8a633fe
Auto merge of #13570 - Veykril:dedup-crates-for, r=Veykril
bors Nov 7, 2022
d1c9775
Auto merge of #13568 - noritada:fix/len-of-byte-string-with-escaped-n…
bors Nov 7, 2022
6a06f6f
Deduplicate reference search results
Veykril Nov 7, 2022
a27e4da
Auto merge of #13571 - Veykril:unique-references, r=Veykril
bors Nov 7, 2022
fa70b0a
internal: Use Cancellable in favor of Result for clarity
Veykril Nov 7, 2022
0aa0da9
Auto merge of #13572 - Veykril:cancellable, r=Veykril
bors Nov 7, 2022
1cb6ab8
internal: error instead of panic on invalid file range
Veykril Nov 7, 2022
b8b1951
Auto merge of #13573 - Veykril:invalid-file-range, r=Veykril
bors Nov 7, 2022
90e2db8
fix: Fix item completions not working properly after unit structs and…
Veykril Nov 8, 2022
236c116
Auto merge of #13581 - Veykril:unit-struct-compl, r=Veykril
bors Nov 8, 2022
4403dde
Nest Cargo.lock under Cargo.toml in Code
lnicola Nov 8, 2022
977a029
Auto merge of #13582 - lnicola:nest-cargo-toml, r=lnicola
bors Nov 8, 2022
9be0615
Don't canonicalize self type when querying FnOnce signature
Nov 8, 2022
392784a
Auto merge of #13584 - jonas-schievink:fix-signature-panic, r=jonas-s…
bors Nov 8, 2022
3c35d44
Add proc-macro dependency to rustc_private crates
Veykril Nov 9, 2022
599142c
Auto merge of #13590 - Veykril:proc-macro-rustc-src, r=Veykril
bors Nov 9, 2022
4f415fc
Ignore outermost non-delimited `Subtree` when reversing fixups
lowr Nov 10, 2022
5b07061
Test `TokenTree`s' equality modulo `Punct`s' spacing
lowr Nov 10, 2022
dea49d0
fix: check visibility of each segment in path resolution
lowr Nov 11, 2022
e75afeb
Resolve invisible defs in `fix_visibility` assist
lowr Nov 11, 2022
19306c0
Fix tests that depended on loose visibility restriction
lowr Nov 11, 2022
e35836e
Send status notification if there are no found workspaces
Veykril Nov 11, 2022
ff78d24
Auto merge of #13603 - Veykril:no-workspaces, r=Veykril
bors Nov 11, 2022
6f313ce
Auto merge of #13548 - lowr:fix/tt-punct-spacing, r=Veykril
bors Nov 11, 2022
57cc2a6
Auto merge of #13602 - lowr:fix/nameres-transitive-visibility, r=Veykril
bors Nov 11, 2022
e50712c
fix: Fix hover in attributed items not preferring similar kinded tokens
Veykril Nov 11, 2022
add8539
Auto merge of #13604 - Veykril:hover-attr, r=Veykril
bors Nov 11, 2022
a143ff0
fix: Fix r-a eagerly showing no discovered workspace errors
Veykril Nov 11, 2022
d3531e8
Auto merge of #13605 - Veykril:empty-ws-error, r=Veykril
bors Nov 11, 2022
6674bd8
fix: Add trait alias grammar to rust.ungram
Veykril Nov 11, 2022
2656303
Auto merge of #13606 - Veykril:trait-alias, r=Veykril
bors Nov 11, 2022
6b4b7d8
internal: Add version info to unsupported proc macro abi error
Veykril Nov 11, 2022
45ec315
Auto merge of #13607 - Veykril:proc-macro-error, r=Veykril
bors Nov 11, 2022
5fd561d
avoid memory leak in mpsc test
RalfJung Nov 14, 2022
55746a4
Fix test/ui/issues/issue-30490.rs
Ayush1325 Nov 14, 2022
8b34675
rustdoc: remove no-op CSS `.popover { font-size: 1rem }`
notriddle Nov 14, 2022
bd84709
rustdoc: add test case for font size in help popover
notriddle Nov 14, 2022
70ad2f5
respect visibility & stability of inherent associated types
fmease Nov 13, 2022
155a553
rustdoc: remove no-op CSS `.main-header { justify-content }`
notriddle Nov 14, 2022
9857de2
shift no characters when using raw string literals
TaKO8Ki Nov 9, 2022
6211faa
Fuchsia test suite script fix
andrewpollack Nov 15, 2022
5d36be5
:arrow_up: rust-analyzer
lnicola Nov 15, 2022
0a528b1
Merge branch 'master' into patch-2
saschanaz Nov 15, 2022
e6e29a8
Update PROBLEMATIC_CONSTS in style.rs
scruss Nov 16, 2022
d8a98b1
Rollup merge of #103484 - saschanaz:patch-2, r=ehuss
matthiaskrgr Nov 16, 2022
3fd3668
Rollup merge of #103489 - WaffleLapkin:byte_offset_from_you, r=scottmcm
matthiaskrgr Nov 16, 2022
d93d8ee
Rollup merge of #104193 - TaKO8Ki:fix-104142, r=cjgillot
matthiaskrgr Nov 16, 2022
c7a86e7
Rollup merge of #104348 - fmease:iat-vis-stab, r=cjgillot
matthiaskrgr Nov 16, 2022
cdebce5
Rollup merge of #104401 - RalfJung:mpsc-leak, r=Amanieu
matthiaskrgr Nov 16, 2022
6ce20c6
Rollup merge of #104419 - Ayush1325:test-issue-30490, r=lcnr
matthiaskrgr Nov 16, 2022
d3af1ec
Rollup merge of #104424 - notriddle:notriddle/popover-font-size, r=Gu…
matthiaskrgr Nov 16, 2022
71d3d1e
Rollup merge of #104425 - notriddle:notriddle/main-heading-justify-co…
matthiaskrgr Nov 16, 2022
63760b4
Rollup merge of #104450 - andrewpollack:fix-fuchsia-compiler-docs, r=…
matthiaskrgr Nov 16, 2022
bb90116
Rollup merge of #104454 - lnicola:rust-analyzer-2022-11-15, r=lnicola
matthiaskrgr Nov 16, 2022
d3ad86b
Rollup merge of #104471 - scruss:patch-1, r=jyn514
matthiaskrgr Nov 16, 2022
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
83 changes: 46 additions & 37 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,17 +1917,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}

// see if we can satisfy using an inherent associated type
for impl_ in tcx.inherent_impls(adt_def.did()) {
let assoc_ty = tcx.associated_items(impl_).find_by_name_and_kind(
tcx,
assoc_ident,
ty::AssocKind::Type,
*impl_,
);
if let Some(assoc_ty) = assoc_ty {
let ty = tcx.type_of(assoc_ty.def_id);
return Ok((ty, DefKind::AssocTy, assoc_ty.def_id));
}
for &impl_ in tcx.inherent_impls(adt_def.did()) {
let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, impl_) else {
continue;
};
// FIXME(inherent_associated_types): This does not substitute parameters.
let ty = tcx.type_of(assoc_ty_did);
return Ok((ty, DefKind::AssocTy, assoc_ty_did));
}
}

Expand Down Expand Up @@ -2014,37 +2010,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};

let trait_did = bound.def_id();
let (assoc_ident, def_scope) =
tcx.adjust_ident_and_get_scope(assoc_ident, trait_did, hir_ref_id);

// We have already adjusted the item name above, so compare with `ident.normalize_to_macros_2_0()` instead
// of calling `filter_by_name_and_kind`.
let item = tcx.associated_items(trait_did).in_definition_order().find(|i| {
i.kind.namespace() == Namespace::TypeNS
&& i.ident(tcx).normalize_to_macros_2_0() == assoc_ident
});
// Assume that if it's not matched, there must be a const defined with the same name
// but it was used in a type position.
let Some(item) = item else {
let Some(assoc_ty_did) = self.lookup_assoc_ty(assoc_ident, hir_ref_id, span, trait_did) else {
// Assume that if it's not matched, there must be a const defined with the same name
// but it was used in a type position.
let msg = format!("found associated const `{assoc_ident}` when type was expected");
let guar = tcx.sess.struct_span_err(span, &msg).emit();
return Err(guar);
};

let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, assoc_segment, bound);
let ty = self.projected_ty_from_poly_trait_ref(span, assoc_ty_did, assoc_segment, bound);
let ty = self.normalize_ty(span, ty);

let kind = DefKind::AssocTy;
if !item.visibility(tcx).is_accessible_from(def_scope, tcx) {
let kind = kind.descr(item.def_id);
let msg = format!("{} `{}` is private", kind, assoc_ident);
tcx.sess
.struct_span_err(span, &msg)
.span_label(span, &format!("private {}", kind))
.emit();
}
tcx.check_stability(item.def_id, Some(hir_ref_id), span, None);

if let Some(variant_def_id) = variant_resolution {
tcx.struct_span_lint_hir(
AMBIGUOUS_ASSOCIATED_ITEMS,
Expand All @@ -2063,7 +2039,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};

could_refer_to(DefKind::Variant, variant_def_id, "");
could_refer_to(kind, item.def_id, " also");
could_refer_to(DefKind::AssocTy, assoc_ty_did, " also");

lint.span_suggestion(
span,
Expand All @@ -2076,7 +2052,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
},
);
}
Ok((ty, kind, item.def_id))
Ok((ty, DefKind::AssocTy, assoc_ty_did))
}

fn lookup_assoc_ty(
&self,
ident: Ident,
block: hir::HirId,
span: Span,
scope: DefId,
) -> Option<DefId> {
let tcx = self.tcx();
let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, block);

// We have already adjusted the item name above, so compare with `ident.normalize_to_macros_2_0()` instead
// of calling `find_by_name_and_kind`.
let item = tcx.associated_items(scope).in_definition_order().find(|i| {
i.kind.namespace() == Namespace::TypeNS
&& i.ident(tcx).normalize_to_macros_2_0() == ident
})?;

let kind = DefKind::AssocTy;
if !item.visibility(tcx).is_accessible_from(def_scope, tcx) {
let kind = kind.descr(item.def_id);
let msg = format!("{kind} `{ident}` is private");
let def_span = self.tcx().def_span(item.def_id);
tcx.sess
.struct_span_err_with_code(span, &msg, rustc_errors::error_code!(E0624))
.span_label(span, &format!("private {kind}"))
.span_label(def_span, &format!("{kind} defined here"))
.emit();
}
tcx.check_stability(item.def_id, Some(block), span, None);

Some(item.def_id)
}

fn qpath_to_ty(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ declare_lint! {
/// of at end of scope, which is typically incorrect.
///
/// ### Example
/// ```compile_fail
/// ```rust,compile_fail
/// use std::sync::{Arc, Mutex};
/// use std::thread;
/// let data = Arc::new(Mutex::new(0));
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@ declare_lint! {
///
/// ### Example
///
/// ```
/// ```rust
/// trait Duh {}
///
/// impl Duh for i32 {}
///
/// trait Trait {
/// type Assoc: Send;
/// type Assoc: Duh;
/// }
///
/// struct Struct;
///
/// impl Trait for Struct {
/// type Assoc = i32;
/// impl<F: Duh> Trait for F {
/// type Assoc = F;
/// }
///
/// fn test() -> impl Trait<Assoc = impl Sized> {
/// Struct
/// 42
/// }
/// ```
///
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ declare_lint! {
///
/// ### Example
///
/// ```
/// ```rust
/// #[warn(unused_tuple_struct_fields)]
/// struct S(i32, i32, i32);
/// let s = S(1, 2, 3);
Expand Down Expand Up @@ -1154,7 +1154,7 @@ declare_lint! {
///
/// ### Example
///
/// ```compile_fail
/// ```rust,compile_fail
/// #[repr(packed)]
/// pub struct Foo {
/// field1: u64,
Expand Down Expand Up @@ -2548,7 +2548,7 @@ declare_lint! {
///
/// ### Example
///
/// ```compile_fail
/// ```rust,compile_fail
/// # #![allow(unused)]
/// enum E {
/// A,
Expand Down Expand Up @@ -3918,7 +3918,7 @@ declare_lint! {
///
/// ### Example
///
/// ```
/// ```rust
/// #![allow(test_unstable_lint)]
/// ```
///
Expand Down
150 changes: 74 additions & 76 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,96 +818,94 @@ fn find_skips_from_snippet(
_ => return (vec![], false),
};

fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
let mut s = snippet.char_indices();
let mut skips = vec![];
while let Some((pos, c)) = s.next() {
match (c, s.clone().next()) {
// skip whitespace and empty lines ending in '\\'
('\\', Some((next_pos, '\n'))) if !is_raw => {
skips.push(pos);
skips.push(next_pos);
let _ = s.next();
if str_style.is_some() {
return (vec![], true);
}

while let Some((pos, c)) = s.clone().next() {
if matches!(c, ' ' | '\n' | '\t') {
skips.push(pos);
let _ = s.next();
} else {
break;
}
}
}
('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => {
skips.push(next_pos);
let _ = s.next();
}
('\\', Some((_, 'x'))) if !is_raw => {
for _ in 0..3 {
// consume `\xAB` literal
if let Some((pos, _)) = s.next() {
skips.push(pos);
} else {
break;
}
let snippet = &snippet[1..snippet.len() - 1];

let mut s = snippet.char_indices();
let mut skips = vec![];
while let Some((pos, c)) = s.next() {
match (c, s.clone().next()) {
// skip whitespace and empty lines ending in '\\'
('\\', Some((next_pos, '\n'))) => {
skips.push(pos);
skips.push(next_pos);
let _ = s.next();

while let Some((pos, c)) = s.clone().next() {
if matches!(c, ' ' | '\n' | '\t') {
skips.push(pos);
let _ = s.next();
} else {
break;
}
}
('\\', Some((_, 'u'))) if !is_raw => {
}
('\\', Some((next_pos, 'n' | 't' | 'r' | '0' | '\\' | '\'' | '\"'))) => {
skips.push(next_pos);
let _ = s.next();
}
('\\', Some((_, 'x'))) => {
for _ in 0..3 {
// consume `\xAB` literal
if let Some((pos, _)) = s.next() {
skips.push(pos);
} else {
break;
}
if let Some((next_pos, next_c)) = s.next() {
if next_c == '{' {
// consume up to 6 hexanumeric chars
let digits_len =
s.clone().take(6).take_while(|(_, c)| c.is_digit(16)).count();

let len_utf8 = s
.as_str()
.get(..digits_len)
.and_then(|digits| u32::from_str_radix(digits, 16).ok())
.and_then(char::from_u32)
.map_or(1, char::len_utf8);

// Skip the digits, for chars that encode to more than 1 utf-8 byte
// exclude as many digits as it is greater than 1 byte
//
// So for a 3 byte character, exclude 2 digits
let required_skips =
digits_len.saturating_sub(len_utf8.saturating_sub(1));

// skip '{' and '}' also
for pos in (next_pos..).take(required_skips + 2) {
skips.push(pos)
}
}
}
('\\', Some((_, 'u'))) => {
if let Some((pos, _)) = s.next() {
skips.push(pos);
}
if let Some((next_pos, next_c)) = s.next() {
if next_c == '{' {
// consume up to 6 hexanumeric chars
let digits_len =
s.clone().take(6).take_while(|(_, c)| c.is_digit(16)).count();

let len_utf8 = s
.as_str()
.get(..digits_len)
.and_then(|digits| u32::from_str_radix(digits, 16).ok())
.and_then(char::from_u32)
.map_or(1, char::len_utf8);

// Skip the digits, for chars that encode to more than 1 utf-8 byte
// exclude as many digits as it is greater than 1 byte
//
// So for a 3 byte character, exclude 2 digits
let required_skips = digits_len.saturating_sub(len_utf8.saturating_sub(1));

// skip '{' and '}' also
for pos in (next_pos..).take(required_skips + 2) {
skips.push(pos)
}

s.nth(digits_len);
} else if next_c.is_digit(16) {
skips.push(next_pos);
// We suggest adding `{` and `}` when appropriate, accept it here as if
// it were correct
let mut i = 0; // consume up to 6 hexanumeric chars
while let (Some((next_pos, c)), _) = (s.next(), i < 6) {
if c.is_digit(16) {
skips.push(next_pos);
} else {
break;
}
i += 1;
s.nth(digits_len);
} else if next_c.is_digit(16) {
skips.push(next_pos);
// We suggest adding `{` and `}` when appropriate, accept it here as if
// it were correct
let mut i = 0; // consume up to 6 hexanumeric chars
while let (Some((next_pos, c)), _) = (s.next(), i < 6) {
if c.is_digit(16) {
skips.push(next_pos);
} else {
break;
}
i += 1;
}
}
}
_ => {}
}
_ => {}
}
skips
}

let r_start = str_style.map_or(0, |r| r + 1);
let r_end = str_style.unwrap_or(0);
let s = &snippet[r_start + 1..snippet.len() - r_end - 1];
(find_skips(s, str_style.is_some()), true)
(skips, true)
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl<T: ?Sized> *const T {
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize {
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
// SAFETY: the caller must uphold the safety contract for `offset_from`.
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ impl<T: ?Sized> *mut T {
#[unstable(feature = "pointer_byte_offsets", issue = "96283")]
#[rustc_const_unstable(feature = "const_pointer_byte_offsets", issue = "96283")]
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
pub const unsafe fn byte_offset_from(self, origin: *const T) -> isize {
pub const unsafe fn byte_offset_from<U: ?Sized>(self, origin: *const U) -> isize {
// SAFETY: the caller must uphold the safety contract for `offset_from`.
unsafe { self.cast::<u8>().offset_from(origin.cast::<u8>()) }
}
Expand Down
5 changes: 3 additions & 2 deletions library/std/src/sync/mpsc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,11 @@ fn issue_39364() {
let t = thread::spawn(move || {
thread::sleep(Duration::from_millis(300));
let _ = tx.clone();
crate::mem::forget(tx);
// Don't drop; hand back to caller.
tx
});

let _ = rx.recv_timeout(Duration::from_millis(500));
t.join().unwrap();
let _tx = t.join().unwrap(); // delay dropping until end of test
let _ = rx.recv_timeout(Duration::from_millis(500));
}
Loading