Skip to content
Merged
Changes from 2 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b11b705
Add test for issue #74824
aDotInTheVoid Dec 17, 2020
52b717f
Edit rustc_middle::lint::LintSource docs
pierwill Dec 19, 2020
4fffa74
docs: Edit rustc_middle::ty::query::on_disk_cache
pierwill Dec 19, 2020
c127530
Fix labels for 'Library Tracking Issue' template
camelid Dec 20, 2020
e614a72
Fix rustc-std-workspace-core documentation
GreenRecycleBin Dec 20, 2020
51d1806
docs: Fix outdated crate reference
pierwill Dec 20, 2020
9f8c8e4
Add module-level docs to rustc_middle::ty
pierwill Dec 20, 2020
32baf23
Fix typo
pierwill Dec 20, 2020
dc58fc4
Remove `I-prioritize` from Zulip topic
camelid Dec 20, 2020
dffa1e2
Remove redundant test
bugadani Dec 21, 2020
00ff7fe
rustc_span: Provide a reserved identifier check for a specific edition
petrochenkov Dec 21, 2020
1339c81
Update books
ehuss Dec 22, 2020
80aa551
docs: Edit rustc_middle::middle::privacy
pierwill Dec 22, 2020
9cd992f
Add some intra-doc links to compiler docs
jyn514 Dec 22, 2020
ef75761
Turn helper method into a closure
LingMan Dec 22, 2020
57b5f8c
Improve the code quality by using matches macro
Polkaverse Dec 22, 2020
f078f7c
docs: Update rustc_middle::middle::region::ScopeTree
pierwill Dec 22, 2020
26f2d8e
Rollup merge of #80136 - aDotInTheVoid:74824-test, r=Mark-Simulacrum
GuillaumeGomez Dec 22, 2020
f84ec97
Rollup merge of #80203 - pierwill:pierwill-rustcmiddle-lint, r=oli-obk
GuillaumeGomez Dec 22, 2020
8a35d3a
Rollup merge of #80204 - pierwill:pierwill-rustcmiddle-ondisk, r=varkor
GuillaumeGomez Dec 22, 2020
536754f
Rollup merge of #80219 - camelid:library_tracking_issue-labels, r=m-o…
GuillaumeGomez Dec 22, 2020
9446d43
Rollup merge of #80222 - GreenRecycleBin:daniel/fix-rustc-std-workspa…
GuillaumeGomez Dec 22, 2020
f9f8446
Rollup merge of #80223 - pierwill:patch-10, r=lcnr
GuillaumeGomez Dec 22, 2020
e116732
Rollup merge of #80225 - pierwill:patch-11, r=lcnr
GuillaumeGomez Dec 22, 2020
5589261
Rollup merge of #80241 - pierwill:patch-12, r=lcnr
GuillaumeGomez Dec 22, 2020
805c8ac
Rollup merge of #80248 - camelid:prioritize-zulip-topic, r=Mark-Simul…
GuillaumeGomez Dec 22, 2020
93690dc
Rollup merge of #80266 - bugadani:dup-test, r=jyn514
GuillaumeGomez Dec 22, 2020
aa7cb4f
Rollup merge of #80272 - petrochenkov:kwed, r=oli-obk
GuillaumeGomez Dec 22, 2020
4addcbc
Rollup merge of #80285 - ehuss:update-books, r=ehuss
GuillaumeGomez Dec 22, 2020
174a9fa
Rollup merge of #80286 - pierwill:rustc-middle-privacy, r=petrochenkov
GuillaumeGomez Dec 22, 2020
125156c
Rollup merge of #80297 - jyn514:more-docs, r=bjorn3
GuillaumeGomez Dec 22, 2020
5af144e
Rollup merge of #80298 - PankajChaudhary5:PankajChaudhary, r=Guillaum…
GuillaumeGomez Dec 22, 2020
f711f3f
Rollup merge of #80299 - LingMan:helper, r=lcnr
GuillaumeGomez Dec 22, 2020
67f8244
Rollup merge of #80302 - pierwill:fix-80287, r=lcnr
GuillaumeGomez Dec 22, 2020
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
40 changes: 22 additions & 18 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
}

fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
}

/// This function is used to determine potential "simple" improvements or users' errors and
/// provide them useful help. For example:
///
Expand Down Expand Up @@ -394,6 +390,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return None;
}

let replace_prefix = |s: &str, old: &str, new: &str| {
s.strip_prefix(old).map(|stripped| new.to_string() + stripped)
};

let is_struct_pat_shorthand_field =
self.is_hir_id_from_struct_pattern_shorthand_field(expr.hir_id, sp);

Expand All @@ -409,7 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
if let Some(src) = replace_prefix(&src, "b\"", "\"") {
return Some((
sp,
"consider removing the leading `b`",
Expand All @@ -423,7 +423,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
if let Some(src) = replace_prefix(&src, "\"", "b\"") {
return Some((
sp,
"consider adding a leading `b`",
Expand Down Expand Up @@ -583,23 +583,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::Mutability::Mut => {
let new_prefix = "&mut ".to_owned() + derefs;
match mutbl_a {
hir::Mutability::Mut => self
.replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable)),
hir::Mutability::Not => self
.replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::Unspecified)),
hir::Mutability::Mut => {
replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable))
}
hir::Mutability::Not => {
replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::Unspecified))
}
}
}
hir::Mutability::Not => {
let new_prefix = "&".to_owned() + derefs;
match mutbl_a {
hir::Mutability::Mut => self
.replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable)),
hir::Mutability::Not => self
.replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable)),
hir::Mutability::Mut => {
replace_prefix(&src, "&mut ", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable))
}
hir::Mutability::Not => {
replace_prefix(&src, "&", &new_prefix)
.map(|s| (s, Applicability::MachineApplicable))
}
}
}
} {
Expand Down